Game.h 2.6 KB

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