#pragma once #include #include #include #include #include #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" class FCKlient; class GameClient : public virtual Framework::ReferenceCounter { private: Player* zPlayer; FCKlient* client; Critical background; Critical foreground; Critical other; Framework::Synchronizer updateSync; RCArray requests; Vec3 lastPos; RCArray updateQueue; int viewDistance; bool first; bool online; bool finished; public: GameClient( Player* zPlayer, FCKlient* client ); ~GameClient(); void sendWorldUpdate( WorldUpdate* update ); void reply(); void logout(); void addMessage( StreamReader* reader ); bool isOnline() const; void sendResponse( NetworkResponse* zResponse ); Player* zEntity() const; private: 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* dimensions; Framework::RCArray* updates; Framework::RCArray* clients; TickOrganizer* ticker; Framework::Text path; bool stop; __int64 tickId; Critical cs; int nextEntityId; WorldGenerator* generator; WorldLoader* loader; void thread() override; Game( Framework::Text name, Framework::Text worldsDir ); public: ~Game(); void initialize(); void api( Framework::StreamReader* zRequest, GameClient* zOrigin ); void distributeResponse( NetworkResponse* zResponse ); bool requestWorldUpdate( WorldUpdate* update ); 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 zBlockAt( Framework::Vec3 location, int dimension ) const; Block* zRealBlockInstance( Framework::Vec3 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* zNearestEntity( int dimensionId, Framework::Vec3 pos, std::function filter ); static Game* INSTANCE; static void initialize( Framework::Text name, Framework::Text worldsDir ); };