1
0
Fork 0
Univerxel/src/server/Server.cpp

37 lines
1.1 KiB
C++

#include "Server.hpp"
#include "world/StandaloneUniverse.hpp"
#ifndef STANDALONE
#include "world/SharedUniverse.hpp"
#endif
#include <signal.h>
Server::Server(config::server::options& options): options(options) {
//MAYBE: if allow local
localHandle = options.allowLocal ? new server_handle() : nullptr;
}
Server::~Server() { }
const auto TPS = 10;
static bool running = true;
void handle_signal(int) { running = false; }
void Server::run() {
universe = [&]() -> std::unique_ptr<world::server::Universe> {
#ifndef STANDALONE
if(options.allowLocal)
return std::make_unique<world::server::SharedUniverse>(options.world, localHandle);
#endif
return std::make_unique<world::server::StandaloneUniverse>(options.world);
}();
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
while(running && (localHandle == nullptr || localHandle->running)) {
universe->update(1. / TPS); //FIXME: use chrono
FrameMarkNamed("Server");
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / TPS));
}
}