123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #pragma once
- #include <InMemoryBuffer.h>
- #include <Punkt.h>
- #include <Thread.h>
- #include "Chunk.h"
- #include "DimensionMap.h"
- #include "MultiblockStructure.h"
- #include "NetworkMessage.h"
- struct RequestQueue
- {
- Framework::InMemoryBuffer* request;
- Framework::Punkt chunkCenter;
- int sourceId;
- };
- class Dimension : public Framework::Thread
- {
- private:
- __int64 nextStructureId;
- int dimensionId;
- float gravity;
- Framework::RCTrie<Chunk>* chunks;
- Framework::Array<Chunk*> chunkList;
- Framework::Critical chunkCs;
- Framework::RCArray<Entity>* entities;
- Framework::Array<RequestQueue> waitingRequests;
- Framework::Critical cs;
- Framework::Array<Framework::Vec3<int>> lightUpdateQueue;
- Framework::Array<Framework::Vec3<int>> priorizedLightUpdateQueue;
- Framework::Critical lightCs;
- Framework::Critical prioLightCs;
- Framework::Critical structurCs;
- Framework::RCArray<Chunk> removedChunks;
- Framework::Critical removedChunksCs;
- Framework::RCArray<MultiblockStructure> structures;
- DimensionMap* map;
- bool stop;
- 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 api(Framework::InMemoryBuffer* zRequest,
- NetworkMessage* zResponse,
- Entity* zSource);
- void tickEntities();
- void thread() override;
- Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);
- Block* zRealBlockInstance(Framework::Vec3<int> location);
- const Block* zBlockOrDefault(Framework::Vec3<int> location);
- void placeBlock(
- Framework::Vec3<int> location, Framework::Either<Block*, int> block);
- void sendBlockInfo(Framework::Vec3<int> 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<float> pos, std::function<bool(Entity*)> filter);
- void removeEntity(int id);
- void removeSubscriptions(Entity* zEntity);
- void updateLightning(Framework::Vec3<int> location);
- void updateLightningWithoutWait(Framework::Vec3<int> location);
- void updateLightAtChunkBorders(Framework::Punkt chunkCenter);
- __int64 getNextStructureId();
- void addStructure(MultiblockStructure* structure);
- MultiblockStructure* zStructureByPosition(
- Framework::Vec3<int> uniquePosition);
- MultiblockStructure* zStructureById(__int64 id);
- void requestStopAndWait();
- void updateMap(int x, int y, int height);
- int getChunkCount();
- inline static Framework::Vec3<int> chunkCoordinates(
- Framework::Vec3<int> worldLocation)
- {
- Framework::Vec3<int> 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;
- };
|