12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "server/Game.h"
- #include "commands/Commands.h"
- #include "memory/UniquePointer.h"
- #include "raw-terminal/RawReader.h"
- #include "server/packets/WorldPackets.h"
- #include "server/world/WorldGenerator.h"
- #include "utils/List.h"
- #include "utils/Logger.h"
- static bool running = true;
- static RawReader<256, 10> reader{0, "> "};
- static List<UniquePointer<World>> worlds;
- Clock Game::ticksPerSecond;
- BlockRegistry Game::blocks;
- void Game::stop() {
- running = false;
- }
- bool Game::isRunning() {
- return running;
- }
- void Game::testWorld() {
- worlds.add(new World(blocks));
- WorldGenerator wg(blocks, *(worlds[0]));
- wg.generate();
- }
- World& Game::getTestWorld() {
- return *(worlds[0]);
- }
- static void handleCommands() {
- if(!reader.canRead()) {
- return;
- }
- const char* s = reader.readLine();
- if(s == nullptr) {
- return;
- }
- Commands::Raw raw(s);
- Commands::execute(raw);
- }
- void Game::tick() {
- ticksPerSecond.update();
- handleCommands();
- }
- void Game::addPlayer(ServerPlayer& p) {
- LOG_INFO("player add");
- for(int x = -1; x <= 1; x++) {
- for(int z = -1; z <= 1; z++) {
- WorldPackets::sendChunk(p, getTestWorld(), x, z);
- }
- }
- }
- void Game::removePlayer(ServerPlayer& p) {
- LOG_INFO("player remove");
- (void)p;
- }
|