Game.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include <Text.h>
  3. #include <Punkt.h>
  4. #include <Thread.h>
  5. #include <Network.h>
  6. #include "Dimension.h"
  7. #include "Player.h"
  8. #include "WorldGenerator.h"
  9. #include "Constants.h"
  10. #include "WorldUpdate.h"
  11. #include "WorldLoader.h"
  12. #include "TickOrganizer.h"
  13. #include "Server.h"
  14. #include "InMemoryBuffer.h"
  15. class FCKlient;
  16. class GameClient : public virtual Framework::ReferenceCounter
  17. {
  18. private:
  19. Player* zPlayer;
  20. FCKlient* client;
  21. CriticalSection background;
  22. CriticalSection foreground;
  23. CriticalSection other;
  24. RCArray<InMemoryBuffer> requests;
  25. Vec3<float> lastPos;
  26. RCArray<WorldUpdate> updateQueue;
  27. int viewDistance;
  28. bool first;
  29. bool online;
  30. public:
  31. GameClient( Player* zPlayer, FCKlient* client );
  32. ~GameClient();
  33. void sendWorldUpdate( WorldUpdate* update );
  34. void reply( Game* zGame );
  35. void logout();
  36. void addMessage( StreamReader* reader );
  37. bool isOnline() const;
  38. void sendResponse( NetworkResponse* zResponse );
  39. Player* zEntity() const;
  40. private:
  41. class Message
  42. {
  43. public:
  44. inline const static unsigned char INGAME_MESSAGE = 0;
  45. inline const static unsigned char TERMINATE = 1;
  46. inline const static unsigned char WORLD_UPDATE = 2;
  47. inline const static unsigned char API_MESSAGE = 3;
  48. inline const static unsigned char POSITION_UPDATE = 4;
  49. };
  50. };
  51. class Game : public virtual Framework::Thread
  52. {
  53. private:
  54. Framework::Text name;
  55. Framework::RCArray<Dimension>* dimensions;
  56. Framework::RCArray<WorldUpdate>* updates;
  57. Framework::RCArray<GameClient>* clients;
  58. TickOrganizer* ticker;
  59. Framework::Text path;
  60. bool stop;
  61. __int64 tickId;
  62. CriticalSection cs;
  63. int nextEntityId;
  64. WorldGenerator* generator;
  65. WorldLoader* loader;
  66. void thread() override;
  67. public:
  68. Game( Framework::Text name, Framework::Text worldsDir );
  69. ~Game();
  70. void api( Framework::StreamReader* zRequest, GameClient* zOrigin );
  71. void distributeResponse( NetworkResponse* zResponse );
  72. void requestWorldUpdate( WorldUpdate* update );
  73. GameClient* addPlayer( FCKlient* client, Framework::Text name );
  74. bool doesChunkExist( int x, int y, int dimension );
  75. bool isChunkLoaded( int x, int y, int dimension ) const;
  76. Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> location, int dimension ) const;
  77. Dimension* zDimension( int id ) const;
  78. Framework::Punkt getChunkCenter( int x, int y ) const;
  79. Area getChunckArea( Punkt center ) const;
  80. Framework::Text getWorldDirectory() const;
  81. void requestArea( Area area );
  82. void save() const;
  83. void requestStop();
  84. void addDimension( Dimension* d );
  85. int getNextEntityId();
  86. WorldGenerator* zGenerator() const;
  87. };