Game.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #pragma once
  2. #include <Console.h>
  3. #include <Critical.h>
  4. #include <Either.h>
  5. #include <InMemoryBuffer.h>
  6. #include <Network.h>
  7. #include <Punkt.h>
  8. #include <Text.h>
  9. #include <Thread.h>
  10. #include "Area.h"
  11. #include "BlockTypeNameFactory.h"
  12. #include "Constants.h"
  13. #include "GameClient.h"
  14. #include "ItemTypeNameFactory.h"
  15. #include "NetworkMessage.h"
  16. #include "TypeRegistry.h"
  17. class QuestManager;
  18. class TickOrganizer;
  19. class WorldGenerator;
  20. class WorldLoader;
  21. class RecipieLoader;
  22. class Chat;
  23. class PlayerRegister;
  24. class UIController;
  25. class EntityType;
  26. class MultiblockStructureType;
  27. class ItemStack;
  28. class BlockType;
  29. class ItemType;
  30. class Item;
  31. class Game : public virtual Framework::Thread
  32. {
  33. public:
  34. static Framework::ConsoleHandler* consoleHandler;
  35. static Framework::InputLine* consoleInput;
  36. private:
  37. Framework::Text name;
  38. TypeRegistry* typeRegistry;
  39. BlockTypeNameFactory* blockTypeNameFactory;
  40. ItemTypeNameFactory* itemTypeNameFactory;
  41. Framework::RCArray<Dimension>* dimensions;
  42. Framework::RCArray<GameClient>* clients;
  43. Framework::Array<std::function<void()>> actions;
  44. QuestManager* questManager;
  45. Framework::Critical actionsCs;
  46. TickOrganizer* ticker;
  47. Framework::Text path;
  48. bool stop;
  49. __int64 tickId;
  50. Framework::Critical cs;
  51. int nextEntityId;
  52. WorldGenerator* generator;
  53. WorldLoader* loader;
  54. RecipieLoader* recipies;
  55. Chat* chat;
  56. PlayerRegister* playerRegister;
  57. UIController* uiController;
  58. double totalTickTime;
  59. int tickCounter;
  60. double averageTickTime;
  61. int ticksPerSecond;
  62. double totalTime;
  63. BlockType** blockTypes;
  64. int blockTypeCount;
  65. ItemType** itemTypes;
  66. int itemTypeCount;
  67. EntityType** entityTypes;
  68. int entityTypeCount;
  69. MultiblockStructureType** multiblockStructureTypes;
  70. int multiblockStructureTypeCount;
  71. void thread() override;
  72. Game(Framework::Text name, Framework::Text worldsDir);
  73. public:
  74. ~Game();
  75. void initialize();
  76. void api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin);
  77. void updateLightning(int dimensionId, Framework::Vec3<int> location);
  78. void updateLightningWithoutWait(
  79. int dimensionId, Framework::Vec3<int> location);
  80. void broadcastMessage(NetworkMessage* response);
  81. void sendMessage(NetworkMessage* response, Entity* zTargetPlayer);
  82. bool checkPlayer(Framework::Text name, Framework::Text secret);
  83. bool existsPlayer(Framework::Text name);
  84. Framework::Text createPlayer(Framework::Text name);
  85. GameClient* addPlayer(FCKlient* client, Framework::Text name);
  86. bool doesChunkExist(int x, int y, int dimension);
  87. void blockTargetChanged(Block* zBlock);
  88. void entityTargetChanged(Entity* zEntity);
  89. void spawnItem(
  90. Framework::Vec3<float> location, int dimensionId, Item* stack);
  91. void spawnItem(
  92. Framework::Vec3<float> location, int dimensionId, ItemStack* stack);
  93. bool isChunkLoaded(int x, int y, int dimension) const;
  94. Framework::Either<Block*, int> zBlockAt(
  95. Framework::Vec3<int> location, int dimension, OUT Chunk** zChunk) const;
  96. Block* zRealBlockInstance(Framework::Vec3<int> location, int dimension);
  97. int getBlockType(Framework::Vec3<int> location, int dimension);
  98. Dimension* zDimension(int id) const;
  99. static Framework::Punkt getChunkCenter(int x, int y);
  100. Area getChunckArea(Framework::Punkt center) const;
  101. Framework::Text getWorldDirectory() const;
  102. void requestArea(Area area);
  103. void save() const;
  104. void requestStop();
  105. void addDimension(Dimension* d);
  106. int getNextEntityId();
  107. WorldGenerator* zGenerator() const;
  108. Entity* zEntity(int id, int dimensionId) const;
  109. Entity* zEntity(int id) const;
  110. Entity* zNearestEntity(int dimensionId,
  111. Framework::Vec3<float> pos,
  112. std::function<bool(Entity*)> filter);
  113. RecipieLoader* zRecipies() const;
  114. void doLater(std::function<void()> action);
  115. TickOrganizer* zTickOrganizer() const;
  116. Chat* zChat() const;
  117. Player* zPlayerByName(const char* name) const;
  118. void listPlayerNames(Framework::RCArray<Framework::Text>& names);
  119. TypeRegistry* zTypeRegistry() const;
  120. int getPlayerId(const char* name) const;
  121. QuestManager* zQuestManager() const;
  122. UIController* zUIController() const;
  123. double getAverageTickTime() const;
  124. int getTicksPerSecond() const;
  125. int getPlayerCount() const;
  126. int getChunkCount() const;
  127. const BlockType* zBlockType(int id) const;
  128. const ItemType* zItemType(int id) const;
  129. const EntityType* zEntityType(int id) const;
  130. int getEntityTypeId(const char* name) const;
  131. int getBlockTypeId(const char* name) const;
  132. int getItemTypeId(const char* name) const;
  133. int getBlockTypeCount() const;
  134. int getItemTypeCount() const;
  135. int getEntityTypeCount() const;
  136. const MultiblockStructureType* zMultiblockStructureType(int id) const;
  137. int getMultiblockStructureTypeCount() const;
  138. static Game* INSTANCE;
  139. static Framework::Critical INSTANCE_CS;
  140. static void initialize(Framework::Text name, Framework::Text worldsDir);
  141. };