12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #pragma once
- #include <Text.h>
- #include <Punkt.h>
- #include <Thread.h>
- #include <Network.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"
- class FCKlient;
- class GameClient : public virtual Framework::ReferenceCounter
- {
- private:
- Player* zPlayer;
- FCKlient* client;
- Network::NetworkWriter writer;
- CriticalSection cs;
- RCArray<InMemoryBuffer> requests;
- Vec3<float> lastPos;
- int viewDistance;
- bool first;
- bool online;
- public:
- GameClient( Player* zPlayer, FCKlient* client );
- ~GameClient();
- void sendWorldUpdate( WorldUpdate* zUpdate );
- void reply( Game* zGame );
- 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 INGAME_MESSAGE = 0;
- 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;
- TickOrganizer* ticker;
- Framework::Text path;
- bool stop;
- __int64 tickId;
- CriticalSection cs;
- int nextEntityId;
- WorldGenerator* generator;
- WorldLoader* loader;
- void thread() override;
- public:
- Game( Framework::Text name, Framework::Text worldsDir );
- ~Game();
- void api( Framework::StreamReader* zRequest, GameClient* zOrigin );
- void distributeResponse( NetworkResponse* zResponse );
- void requestWorldUpdate( WorldUpdate* update );
- GameClient* addPlayer( FCKlient* client, Framework::Text name );
- bool doesChunkExist( int x, int y, int dimension ) const;
- bool isChunkLoaded( int x, int y, int dimension ) const;
- Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> location, int dimension ) const;
- Dimension* zDimension( int id ) const;
- Framework::Punkt getChunkCenter( int x, int y ) const;
- 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;
- };
|