Game.h 4.8 KB

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