1
0
Fork 0
Univerxel/src/main.cpp

69 lines
1.5 KiB
C++

/**
* \file main.cpp
* \brief Univerxel game
* \author Maelys Bois
* \version 0.0.1
*
* Univerxel main program.
*/
#include "client/Client.hpp"
#include "server/Server.hpp"
#include "core/config.hpp"
#include "core/utils/tracy.hpp"
/// Entry point
int main(int argc, char *argv[]){
LOG("Univerxel");
#if TRACY_ENABLE
LOG("Profiling !");
#endif
auto options = config::options(argc > 1 ? argv[1] : config::DEFAULT_FILE);
options.save();
std::optional<Server> server = options.hasServer() ? std::make_optional<Server>(options.getServer()) : std::nullopt;
std::optional<Client> client = options.hasClient() ? std::make_optional<Client>(options.getClient()) : std::nullopt;
const auto serverTask = [&] {
#if TRACY_ENABLE
tracy::SetThreadName("Server");
#endif
server.value().run();
};
const auto clientTask = [&](server_handle* const handle) {
#if TRACY_ENABLE
tracy::SetThreadName("Client");
#endif
client.value().run(handle);
};
net::Setup();
if (server.has_value()) {
if (client.has_value()) {
auto serverThread = std::thread(serverTask);
clientTask(server.value().getHandle());
if(serverThread.joinable())
serverThread.join();
} else {
serverTask();
}
} else {
if (client.has_value()) {
clientTask(nullptr);
} else {
options.save();
FATAL("Nothing to start");
}
}
net::Destroy();
options.save();
return 0;
}