123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #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};
- 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();
- 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, 1.0f, 0.0f));
- world.addEntity(&p);
- }
- void Game::removePlayer(ServerPlayer& p) {
- LOG_INFO("player remove");
- world.removeEntity(&p);
- }
|