123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #pragma once
- #include <Console.h>
- #include <Critical.h>
- #include <Either.h>
- #include <InMemoryBuffer.h>
- #include <Network.h>
- #include <Punkt.h>
- #include <Text.h>
- #include <Thread.h>
- #include "Area.h"
- #include "NetworkMessage.h"
- #include "TypeRegistry.h"
- #include "WorldUpdate.h"
- class FCKlient;
- class Player;
- class QuestManager;
- class TickOrganizer;
- class WorldGenerator;
- class WorldLoader;
- class RecipieLoader;
- class Chat;
- class PlayerRegister;
- class UIController;
- class EntityType;
- class MultiblockStructureType;
- class ItemStack;
- class BlockType;
- class ItemType;
- class Item;
- class GameClient : public Framework::Thread
- {
- private:
- Player* zPlayer;
- FCKlient* client;
- Framework::Critical background;
- Framework::Critical foreground;
- Framework::Critical other;
- Framework::Synchronizer updateSync;
- Framework::RCArray<Framework::InMemoryBuffer> requests;
- Framework::RCArray<WorldUpdate> updateQueue;
- Framework::RCArray<NetworkMessage> backgroundQueue;
- Framework::RCArray<NetworkMessage> foregroundQueue;
- Framework::Synchronizer foregroundQueueSync;
- Framework::Synchronizer backgroundQueueSync;
- Framework::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(Framework::StreamReader* reader);
- bool isOnline() const;
- void sendResponse(NetworkMessage* response);
- Player* zEntity() const;
- void sendTypes();
- class Message
- {
- public:
- inline static const unsigned char TERMINATE = 1;
- inline static const unsigned char WORLD_UPDATE = 2;
- inline static const unsigned char API_MESSAGE = 3;
- inline static const unsigned char POSITION_UPDATE = 4;
- };
- };
- class Game : public virtual Framework::Thread
- {
- public:
- static Framework::ConsoleHandler* consoleHandler;
- static Framework::InputLine* consoleInput;
- private:
- Framework::Text name;
- TypeRegistry* typeRegistry;
- Framework::RCArray<Dimension>* dimensions;
- Framework::RCArray<WorldUpdate>* updates;
- Framework::RCArray<GameClient>* clients;
- Framework::Array<std::function<void()>> actions;
- QuestManager* questManager;
- Framework::Critical actionsCs;
- TickOrganizer* ticker;
- Framework::Text path;
- bool stop;
- __int64 tickId;
- Framework::Critical cs;
- int nextEntityId;
- WorldGenerator* generator;
- WorldLoader* loader;
- RecipieLoader* recipies;
- Chat* chat;
- PlayerRegister* playerRegister;
- UIController* uiController;
- double totalTickTime;
- int tickCounter;
- double averageTickTime;
- int ticksPerSecond;
- double totalTime;
- BlockType** blockTypes;
- int blockTypeCount;
- ItemType** itemTypes;
- int itemTypeCount;
- EntityType** entityTypes;
- int entityTypeCount;
- MultiblockStructureType** multiblockStructureTypes;
- int multiblockStructureTypeCount;
- 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, Framework::Vec3<int> location);
- void updateLightningWithoutWait(
- int dimensionId, Framework::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);
- void blockTargetChanged(Block* zBlock);
- void entityTargetChanged(Entity* zEntity);
- void spawnItem(
- Framework::Vec3<float> location, int dimensionId, Item* stack);
- void spawnItem(
- Framework::Vec3<float> location, int dimensionId, ItemStack* stack);
- 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);
- int getBlockType(Framework::Vec3<int> location, int dimension);
- Dimension* zDimension(int id) const;
- static Framework::Punkt getChunkCenter(int x, int y);
- Area getChunckArea(Framework::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);
- RecipieLoader* zRecipies() const;
- void doLater(std::function<void()> action);
- TickOrganizer* zTickOrganizer() const;
- Chat* zChat() const;
- Player* zPlayerByName(const char* name) const;
- TypeRegistry* zTypeRegistry() const;
- int getPlayerId(const char* name) const;
- QuestManager* zQuestManager() const;
- UIController* zUIController() const;
- double getAverageTickTime() const;
- int getTicksPerSecond() const;
- int getPlayerCount() const;
- int getChunkCount() const;
- const BlockType* zBlockType(int id) const;
- const ItemType* zItemType(int id) const;
- const EntityType* zEntityType(int id) const;
- int getBlockTypeId(const char* name) const;
- int getItemTypeId(const char* name) const;
- int getBlockTypeCount() const;
- int getItemTypeCount() const;
- int getEntityTypeCount() const;
- const MultiblockStructureType* zMultiblockStructureType(int id) const;
- int getMultiblockStructureTypeCount() const;
- static Game* INSTANCE;
- static Framework::Critical INSTANCE_CS;
- static void initialize(Framework::Text name, Framework::Text worldsDir);
- };
|