1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #pragma once
- #include <Array.h>
- #include <Datei.h>
- #include <Either.h>
- #include <Punkt.h>
- #include <Vec3.h>
- #include "Block.h"
- #include "DoLaterHandler.h"
- #include "Tickable.h"
- #include "Constants.h"
- #include "InformationObserver.h"
- class ChunkMap;
- class Chunk : public virtual Framework::ReferenceCounter,
- public Tickable
- {
- private:
- int dimensionId;
- Framework::Punkt location;
- Block** blocks;
- Chunk* zNeighbours[4];
- unsigned short* blockIds;
- Framework::Either<Block*, int> zBlockNeighbor(
- Framework::Vec3<int> location);
- bool added;
- Framework::Critical cs;
- Framework::RCArray<InformationObserver> observers;
- Framework::Array<int> lightSources;
- Framework::Array<Block*> tickSources;
- unsigned char* lightData;
- bool currentlyLoading;
- void addLightSource(int index);
- void removeLightSource(int index);
- void sendLightToClient(Framework::StreamWriter* zWriter);
- void broadcastLightData(int index, bool foreground);
- const Block* zBlockConst(int index) const;
- bool isVisible(int index) const;
- public:
- Chunk(Framework::Punkt location, int dimensionId);
- Chunk(Framework::Punkt location,
- int dimensionId,
- Framework::StreamReader* zReader);
- ~Chunk();
- void lock();
- void unlock();
- void tick(TickQueue* zQueue) override;
- void postTick() override;
- void notifyObservers(NetworkMessage* msg);
- void addObserver(Entity* zEntity, DoLaterHandler& laterHandler);
- void removeObserver(Entity* zEntity);
- void api(Framework::StreamReader* zRequest,
- Entity* zSource,
- DoLaterHandler& laterHandler);
- void initializeLightning();
- Framework::Either<Block*, int> zBlockAt(
- Framework::Vec3<int> cLocation) const;
- const Block* zBlockConst(Framework::Vec3<int> location) const;
- void instantiateBlock(Framework::Vec3<int> location);
- void generateBlock(Framework::Vec3<int> location);
- void putBlockAt(Framework::Vec3<int> location, Block* block);
- void putBlockTypeAt(Framework::Vec3<int> location, int type);
- void sendBlockInfo(Framework::Vec3<int> location);
- void setNeighbor(Direction dir, Chunk* zChunk);
- void load(Framework::StreamReader* zReader);
- void save(Framework::StreamWriter* zWriter);
- void sendToClient(Framework::StreamWriter* zWriter);
- void removeUnusedBlocks();
- int getDimensionId() const;
- void onLoaded();
- void onUnloaded();
- Framework::Punkt getCenter() const;
- Framework::Vec3<int> getMin() const;
- Framework::Vec3<int> getMax() const;
- void prepareRemove();
- void setAdded();
- bool hasObservers() const;
- unsigned char* getLightData(Framework::Vec3<int> location) const;
- void setLightData(
- Framework::Vec3<int> location, unsigned char* data, bool foreground);
- int getBlockTypeAt(Framework::Vec3<int> location) const;
- inline static int index(Framework::Vec3<int> localLocation)
- {
- return (localLocation.x * CHUNK_SIZE + localLocation.y) * WORLD_HEIGHT
- + localLocation.z;
- }
- friend ChunkMap;
- };
|