Game.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <Text.h>
  3. #include <Punkt.h>
  4. #include <Thread.h>
  5. #include "Dimension.h"
  6. #include "Player.h"
  7. #include "WorldGenerator.h"
  8. #include "Constants.h"
  9. #include "WorldUpdate.h"
  10. #include "WorldLoader.h"
  11. #include "TickOrganizer.h"
  12. #include "Server.h"
  13. #include "InMemoryBuffer.h"
  14. class FCKlient;
  15. class GameClient : public virtual Framework::ReferenceCounter
  16. {
  17. private:
  18. Player *zPlayer;
  19. FCKlient *client;
  20. NetworkWriter writer;
  21. CriticalSection cs;
  22. RCArray<InMemoryBuffer> requests;
  23. bool online;
  24. public:
  25. GameClient( Player *zPlayer, FCKlient *client );
  26. ~GameClient();
  27. void sendWorldUpdate( WorldUpdate *zUpdate );
  28. void reply( Game *zGame );
  29. void logout();
  30. void addMessage( StreamReader *reader );
  31. bool isOnline() const;
  32. Player *zEntity() const;
  33. private:
  34. class Message
  35. {
  36. public:
  37. static const unsigned char WORLD_UPDATE = 2;
  38. };
  39. };
  40. class Game : public virtual Framework::Thread
  41. {
  42. private:
  43. Framework::Text name;
  44. Framework::RCArray<Dimension> *dimensions;
  45. Framework::RCArray<WorldUpdate> *updates;
  46. Framework::RCArray<GameClient> *clients;
  47. WorldGenerator *generator;
  48. WorldLoader *loader;
  49. TickOrganizer *ticker;
  50. Framework::Text path;
  51. bool stop;
  52. __int64 tickId;
  53. CriticalSection cs;
  54. void thread() override;
  55. public:
  56. Game( Framework::Text name, Framework::Text worldsDir );
  57. ~Game();
  58. void requestWorldUpdate( WorldUpdate *update );
  59. GameClient *addPlayer( FCKlient *client, Framework::Text name );
  60. bool doesChunkExist( int x, int y, int dimension ) const;
  61. Block *zBlockAt( Framework::Vec3<int> location, int dimension ) const;
  62. Dimension *zDimension( int id ) const;
  63. Framework::Punkt getChunkCenter( int x, int y ) const;
  64. Framework::Text getWorldDirectory() const;
  65. void requestArea( Area area );
  66. void save() const;
  67. void requestStop();
  68. void addDimension( Dimension *d );
  69. };