Game.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 TERMINATE = 1;
  45. inline const static unsigned char WORLD_UPDATE = 2;
  46. inline const static unsigned char API_MESSAGE = 3;
  47. inline const static unsigned char POSITION_UPDATE = 4;
  48. };
  49. };
  50. class Game : public virtual Framework::Thread
  51. {
  52. private:
  53. Framework::Text name;
  54. Framework::RCArray<Dimension>* dimensions;
  55. Framework::RCArray<WorldUpdate>* updates;
  56. Framework::RCArray<GameClient>* clients;
  57. TickOrganizer* ticker;
  58. Framework::Text path;
  59. bool stop;
  60. __int64 tickId;
  61. CriticalSection cs;
  62. int nextEntityId;
  63. WorldGenerator* generator;
  64. WorldLoader* loader;
  65. void thread() override;
  66. public:
  67. Game( Framework::Text name, Framework::Text worldsDir );
  68. ~Game();
  69. void api( Framework::StreamReader* zRequest, GameClient* zOrigin );
  70. void distributeResponse( NetworkResponse* zResponse );
  71. void requestWorldUpdate( WorldUpdate* update );
  72. GameClient* addPlayer( FCKlient* client, Framework::Text name );
  73. bool doesChunkExist( int x, int y, int dimension );
  74. bool isChunkLoaded( int x, int y, int dimension ) const;
  75. Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> location, int dimension ) const;
  76. Dimension* zDimension( int id ) const;
  77. Framework::Punkt getChunkCenter( int x, int y ) const;
  78. Area getChunckArea( Punkt center ) const;
  79. Framework::Text getWorldDirectory() const;
  80. void requestArea( Area area );
  81. void save() const;
  82. void requestStop();
  83. void addDimension( Dimension* d );
  84. int getNextEntityId();
  85. WorldGenerator* zGenerator() const;
  86. };