Game.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include <Text.h>
  3. #include <Punkt.h>
  4. #include <Thread.h>
  5. #include <Network.h>
  6. #include <Critical.h>
  7. #include "Dimension.h"
  8. #include "Player.h"
  9. #include "WorldGenerator.h"
  10. #include "Constants.h"
  11. #include "WorldUpdate.h"
  12. #include "WorldLoader.h"
  13. #include "TickOrganizer.h"
  14. #include "Server.h"
  15. #include "InMemoryBuffer.h"
  16. #include "RecipieLoader.h"
  17. class FCKlient;
  18. class GameClient : public virtual Framework::ReferenceCounter
  19. {
  20. private:
  21. Player* zPlayer;
  22. FCKlient* client;
  23. Critical background;
  24. Critical foreground;
  25. Critical other;
  26. Framework::Synchronizer updateSync;
  27. RCArray<InMemoryBuffer> requests;
  28. RCArray<WorldUpdate> updateQueue;
  29. int viewDistance;
  30. bool first;
  31. bool online;
  32. bool finished;
  33. public:
  34. GameClient(Player* zPlayer, FCKlient* client);
  35. ~GameClient();
  36. void sendWorldUpdate(WorldUpdate* update);
  37. void reply();
  38. void logout();
  39. void addMessage(StreamReader* reader);
  40. bool isOnline() const;
  41. void sendResponse(NetworkMessage* zResponse);
  42. Player* zEntity() const;
  43. void sendTypes();
  44. class Message
  45. {
  46. public:
  47. inline const static unsigned char TERMINATE = 1;
  48. inline const static unsigned char WORLD_UPDATE = 2;
  49. inline const static unsigned char API_MESSAGE = 3;
  50. inline const static unsigned char POSITION_UPDATE = 4;
  51. };
  52. };
  53. class Game : public virtual Framework::Thread
  54. {
  55. private:
  56. Framework::Text name;
  57. Framework::RCArray<Dimension>* dimensions;
  58. Framework::RCArray<WorldUpdate>* updates;
  59. Framework::RCArray<GameClient>* clients;
  60. TickOrganizer* ticker;
  61. Framework::Text path;
  62. bool stop;
  63. __int64 tickId;
  64. Critical cs;
  65. int nextEntityId;
  66. WorldGenerator* generator;
  67. WorldLoader* loader;
  68. RecipieLoader recipies;
  69. double totalTickTime;
  70. int tickCounter;
  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, Vec3<int> location);
  78. void broadcastMessage(NetworkMessage* zResponse);
  79. void sendMessage(NetworkMessage* zResponse, Entity* zTargetPlayer);
  80. bool requestWorldUpdate(WorldUpdate* update);
  81. GameClient* addPlayer(FCKlient* client, Framework::Text name);
  82. bool doesChunkExist(int x, int y, int dimension);
  83. bool isChunkLoaded(int x, int y, int dimension) const;
  84. Framework::Either<Block*, int> zBlockAt(Framework::Vec3<int> location, int dimension) const;
  85. Block* zRealBlockInstance(Framework::Vec3<int> location, int dimension);
  86. Dimension* zDimension(int id) const;
  87. static Framework::Punkt getChunkCenter(int x, int y);
  88. Area getChunckArea(Punkt center) const;
  89. Framework::Text getWorldDirectory() const;
  90. void requestArea(Area area);
  91. void save() const;
  92. void requestStop();
  93. void addDimension(Dimension* d);
  94. int getNextEntityId();
  95. WorldGenerator* zGenerator() const;
  96. Entity* zEntity(int id, int dimensionId) const;
  97. Entity* zEntity(int id) const;
  98. Entity* zNearestEntity(int dimensionId, Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  99. const RecipieLoader& getRecipies() const;
  100. static Game* INSTANCE;
  101. static void initialize(Framework::Text name, Framework::Text worldsDir);
  102. };