#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 "server/world/WorldGenerator.h" #include "utils/List.h" #include "utils/Logger.h" static bool running = true; static RawReader<256, 10> reader{0, "> "}; Clock Game::ticksPerSecond; BlockRegistry Game::blocks; World Game::world{blocks}; static Entity* test = nullptr; void Game::stop() { running = false; } bool Game::isRunning() { return running; } void Game::init() { WorldGenerator::generate(world); } 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(); if(test != nullptr) { EntityUpdatePacket e(*test); OutPacket out = OutPacket::sequenced(EntityUpdatePacket::getSize()); e.write(out); GameServer::sendToAll(out); } 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, 2.0f, 0.0f)); test = &p; world.addEntity(&p); } void Game::removePlayer(ServerPlayer& p) { LOG_INFO("player remove"); test = nullptr; world.removeEntity(&p); }