Game.cpp 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "server/Game.h"
  2. #include "commands/Commands.h"
  3. #include "memory/UniquePointer.h"
  4. #include "raw-terminal/RawReader.h"
  5. #include "server/world/WorldGenerator.h"
  6. #include "utils/List.h"
  7. static bool running = true;
  8. static RawReader<256, 10> reader{0, "> "};
  9. static List<UniquePointer<World>> worlds;
  10. Clock Game::ticksPerSecond;
  11. BlockRegistry Game::blocks;
  12. void Game::stop() {
  13. running = false;
  14. }
  15. bool Game::isRunning() {
  16. return running;
  17. }
  18. void Game::testWorld() {
  19. worlds.add(new World(blocks));
  20. WorldGenerator wg(blocks, *(worlds[0]));
  21. wg.generate();
  22. }
  23. World& Game::getTestWorld() {
  24. return *(worlds[0]);
  25. }
  26. static void handleCommands() {
  27. if(!reader.canRead()) {
  28. return;
  29. }
  30. const char* s = reader.readLine();
  31. if(s == nullptr) {
  32. return;
  33. }
  34. Commands::Raw raw(s);
  35. Commands::execute(raw);
  36. }
  37. void Game::tick() {
  38. ticksPerSecond.update();
  39. handleCommands();
  40. }