#include "server/Game.h" #include "commands/Commands.h" #include "common/network/toclient/EntityUpdatePacket.h" #include "memory/UniquePointer.h" #include "raw-terminal/RawReader.h" #include "server/GameServer.h" #include "server/packets/WorldPackets.h" #include "utils/List.h" #include "utils/Logger.h" static bool running = true; static RawReader<256, 10> reader{0, "> "}; Clock Game::ticksPerSecond; World Game::world; void Game::stop() { running = false; } bool Game::isRunning() { return running; } void Game::init() { Block::init(); } 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(); world.tick(); 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, world, x, z); } } p.setPosition(Vector3(0.0f, 32.0f, 0.0f)); world.addEntity(&p); } void Game::removePlayer(ServerPlayer& p) { LOG_INFO("player remove"); world.removeEntity(&p); }