123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #pragma once
- #include <Text.h>
- #include <Punkt.h>
- #include <Thread.h>
- #include <Network.h>
- #include <Critical.h>
- #include "Dimension.h"
- #include "Player.h"
- #include "WorldGenerator.h"
- #include "Constants.h"
- #include "WorldUpdate.h"
- #include "WorldLoader.h"
- #include "TickOrganizer.h"
- #include "Server.h"
- #include "InMemoryBuffer.h"
- #include "RecipieLoader.h"
- class FCKlient;
- char* randomKey(int& len);
- class GameClient : public Framework::Thread
- {
- private:
- Player* zPlayer;
- FCKlient* client;
- Critical background;
- Critical foreground;
- Critical other;
- Framework::Synchronizer updateSync;
- RCArray<InMemoryBuffer> requests;
- RCArray<WorldUpdate> updateQueue;
- RCArray<NetworkMessage> backgroundQueue;
- RCArray<NetworkMessage> foregroundQueue;
- Framework::Synchronizer foregroundQueueSync;
- Framework::Synchronizer backgroundQueueSync;
- Critical queueCs;
- Framework::Synchronizer emptyForegroundQueueSync;
- Framework::Synchronizer emptyBackgroundQueueSync;
- int viewDistance;
- bool first;
- bool online;
- bool finished;
- bool backgroundFinished;
- bool foregroundFinished;
- public:
- GameClient(Player* zPlayer, FCKlient* client);
- ~GameClient();
- void thread() override;
- void sendWorldUpdate(WorldUpdate* update);
- void reply();
- void logout();
- void addMessage(StreamReader* reader);
- bool isOnline() const;
- void sendResponse(NetworkMessage* response);
- Player* zEntity() const;
- void sendTypes();
- class Message
- {
- public:
- inline const static unsigned char TERMINATE = 1;
- inline const static unsigned char WORLD_UPDATE = 2;
- inline const static unsigned char API_MESSAGE = 3;
- inline const static unsigned char POSITION_UPDATE = 4;
- };
- };
- class Game : public virtual Framework::Thread
- {
- private:
- Framework::Text name;
- Framework::RCArray<Dimension>* dimensions;
- Framework::RCArray<WorldUpdate>* updates;
- Framework::RCArray<GameClient>* clients;
- Framework::Array<std::function<void()>> actions;
- Critical actionsCs;
- TickOrganizer* ticker;
- Framework::Text path;
- bool stop;
- __int64 tickId;
- Critical cs;
- int nextEntityId;
- WorldGenerator* generator;
- WorldLoader* loader;
- RecipieLoader recipies;
- double totalTickTime;
- int tickCounter;
- void thread() override;
- Game(Framework::Text name, Framework::Text worldsDir);
-
- public:
- ~Game();
- void initialize();
- void api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin);
- void updateLightning(int dimensionId, Vec3<int> location);
- void updateLightningWithoutWait(int dimensionId, Vec3<int> location);
- void broadcastMessage(NetworkMessage* response);
- void sendMessage(NetworkMessage* response, Entity* zTargetPlayer);
- bool requestWorldUpdate(WorldUpdate* update);
- bool checkPlayer(Framework::Text name, Framework::Text secret);
- bool existsPlayer(Framework::Text name);
- Framework::Text createPlayer(Framework::Text name);
- GameClient* addPlayer(FCKlient* client, Framework::Text name);
- bool doesChunkExist(int x, int y, int dimension);
- bool isChunkLoaded(int x, int y, int dimension) const;
- Framework::Either<Block*, int> zBlockAt(Framework::Vec3<int> location, int dimension) const;
- Block* zRealBlockInstance(Framework::Vec3<int> location, int dimension);
- Dimension* zDimension(int id) const;
- static Framework::Punkt getChunkCenter(int x, int y);
- Area getChunckArea(Punkt center) const;
- Framework::Text getWorldDirectory() const;
- void requestArea(Area area);
- void save() const;
- void requestStop();
- void addDimension(Dimension* d);
- int getNextEntityId();
- WorldGenerator* zGenerator() const;
- Entity* zEntity(int id, int dimensionId) const;
- Entity* zEntity(int id) const;
- Entity* zNearestEntity(int dimensionId, Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
- const RecipieLoader& getRecipies() const;
- void doLater(std::function<void()> action);
- static Game* INSTANCE;
- static void initialize(Framework::Text name, Framework::Text worldsDir);
- };
|