Game.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. class FCKlient;
  17. class GameClient : public virtual Framework::ReferenceCounter
  18. {
  19. private:
  20. Player* zPlayer;
  21. FCKlient* client;
  22. Critical background;
  23. Critical foreground;
  24. Critical other;
  25. Framework::Synchronizer updateSync;
  26. RCArray<InMemoryBuffer> requests;
  27. Vec3<float> lastPos;
  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( Game* zGame );
  38. void logout();
  39. void addMessage( StreamReader* reader );
  40. bool isOnline() const;
  41. void sendResponse( NetworkResponse* zResponse );
  42. Player* zEntity() const;
  43. private:
  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. void thread() override;
  69. public:
  70. Game( Framework::Text name, Framework::Text worldsDir );
  71. ~Game();
  72. void api( Framework::StreamReader* zRequest, GameClient* zOrigin );
  73. void distributeResponse( NetworkResponse* zResponse );
  74. void requestWorldUpdate( WorldUpdate* update );
  75. GameClient* addPlayer( FCKlient* client, Framework::Text name );
  76. bool doesChunkExist( int x, int y, int dimension );
  77. bool isChunkLoaded( int x, int y, int dimension ) const;
  78. Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> location, int dimension ) const;
  79. Dimension* zDimension( int id ) const;
  80. Framework::Punkt getChunkCenter( int x, int y ) const;
  81. Area getChunckArea( Punkt center ) const;
  82. Framework::Text getWorldDirectory() const;
  83. void requestArea( Area area );
  84. void save() const;
  85. void requestStop();
  86. void addDimension( Dimension* d );
  87. int getNextEntityId();
  88. WorldGenerator* zGenerator() const;
  89. };