#pragma once #include #include #include #include #include #include #include "Chunk.h" #include "Constants.h" #include "MultiblockStructure.h" class DimensionMap; class NetworkMessage; class Block; class DimensionEnum { public: static const int OVERWORLD = 0; }; struct RequestQueue { Framework::InMemoryBuffer* request; Framework::Punkt chunkCenter; int sourceId; }; class Dimension : public Framework::Thread { private: __int64 nextStructureId; int dimensionId; float gravity; Framework::RCTrie* chunks; Framework::Array chunkList; Framework::Critical chunkCs; Framework::RCArray* entities; Framework::Array waitingRequests; Framework::Critical cs; Framework::Array> lightUpdateQueue; Framework::Array> priorizedLightUpdateQueue; Framework::Critical lightCs; Framework::Critical prioLightCs; Framework::Critical structurCs; Framework::RCArray removedChunks; Framework::Critical removedChunksCs; Framework::RCArray structures; DimensionMap* map; bool stop; double currentDayTime; double nightDuration; double nightTransitionDuration; double dayDuration; void getAddrOf(Framework::Punkt cPos, char* addr) const; void getAddrOfWorld(Framework::Punkt wPos, char* addr) const; void saveStructure(MultiblockStructure* zStructure) const; public: Dimension(int id); ~Dimension(); void configureDayNightCyncle(double nightDuration, double nightTransitionDuration, double dayDuration); void api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource); void tickEntities(); void thread() override; Framework::Either zBlock( Framework::Vec3 location, OUT Chunk** zChunk); Block* zRealBlockInstance(Framework::Vec3 location); const Block* zBlockOrDefault(Framework::Vec3 location); int getBlockType(Framework::Vec3 location); void placeBlock( Framework::Vec3 location, Framework::Either block); void sendBlockInfo(Framework::Vec3 location); void addEntity(Entity* entity); void setChunk(Chunk* chunk, Framework::Punkt center); void save(Framework::Text worldDir) const; int getDimensionId() const; bool hasChunck(int x, int y); bool reviveChunk(int x, int y); Chunk* zChunk(Framework::Punkt wPos) const; float getGravity() const; void removeOldChunks(); Entity* zEntity(int id); Entity* zNearestEntity( Framework::Vec3 pos, std::function filter); void removeEntity(int id); void removeSubscriptions(Entity* zEntity); void updateLightning(Framework::Vec3 location); void updateLightningWithoutWait(Framework::Vec3 location); void updateLightAtChunkBorders(Framework::Punkt chunkCenter); __int64 getNextStructureId(); void addStructure(MultiblockStructure* structure); MultiblockStructure* zStructureByPosition( Framework::Vec3 uniquePosition); MultiblockStructure* zStructureById(__int64 id); void requestStopAndWait(); void updateMap(int x, int y, int height); int getChunkCount(); double getCurrentDayTime() const; double getNightDuration() const; double getNightTransitionDuration() const; double getDayDuration() const; inline static Framework::Vec3 chunkCoordinates( Framework::Vec3 worldLocation) { Framework::Vec3 result = worldLocation; result.x = result.x % CHUNK_SIZE; result.y = result.y % CHUNK_SIZE; if (result.x < 0) result.x += CHUNK_SIZE; if (result.y < 0) result.y += CHUNK_SIZE; return result; } friend DimensionMap; };