r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
server.cpp
Go to the documentation of this file.
1#include <thread>
2
4#include "Server/Common.hpp"
6#include "Server/Server.hpp"
7#include "Utils/Logger.hpp"
8
10 : m_pluginLoader(std::make_unique<utl::PluginLoader>()), m_clock(std::make_unique<utl::Clock>()),
11 m_sceneManager(std::make_unique<SceneManager>()),
12 m_network(m_pluginLoader->loadPlugin<INetworkServer>(!config.network_lib_path.empty()
13 ? config.network_lib_path
14 : Path::Plugin::PLUGINS_NETWORK_ASIO_SERVER.string())),
15 m_game(m_pluginLoader->loadPlugin<gme::IGameServer>(
16 !config.game_lib_path.empty() ? config.game_lib_path : Path::Plugin::PLUGINS_GAME_RTYPE_SERVER.string()))
17{
18 utl::Logger::log("PROJECT INFO:", utl::LogLevel::INFO);
19 std::cout << "\tName: " PROJECT_NAME "\n"
20 "\tVersion: " PROJECT_VERSION "\n"
21 "\tBuild type: " BUILD_TYPE "\n"
22 "\tGit tag: " GIT_TAG "\n"
23 "\tGit commit hash: " GIT_COMMIT_HASH "\n";
24
25 m_config = setupConfig(config);
26 m_network->init(config.host, config.port);
27}
28
29void srv::Server::run() const
30{
31 m_network->start();
32 m_game->start();
33
34 auto startTime = std::chrono::steady_clock::now();
35
36 for (;;)
37 {
38 auto currentTime = std::chrono::steady_clock::now();
39 const float deltaTime =
40 std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTime).count() / 1000.0f;
41 startTime = currentTime;
42
43 m_network->update();
44 m_game->update(deltaTime);
45
46 // Print connected sessions
47 auto sessions = m_network->getConnectedSessions();
48 std::cout << "Connected sessions (" << sessions.size() << "): ";
49 for (size_t i = 0; i < sessions.size(); ++i)
50 {
51 std::cout << sessions[i];
52 if (i < sessions.size() - 1)
53 {
54 std::cout << ", ";
55 }
56 }
57 std::cout << '\n';
58
59 std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 FPS
60 }
61}
62
64{
66
67 config.host = cfg.host;
68 config.port = cfg.port;
69
70 return config;
71}
This file contains the Logger class.
This file contains the Server class declaration.
Interface for the server network.
Class for managing scenes.
void run() const
Definition server.cpp:29
Server(const ArgsConfig &config)
Definition server.cpp:9
std::shared_ptr< INetworkServer > m_network
Definition Server.hpp:50
static utl::srv::AppConfig setupConfig(const ArgsConfig &cfg)
Definition server.cpp:63
utl::srv::AppConfig m_config
Definition Server.hpp:44
static void log(const std::string &message, const LogLevel &logLevel)
Definition Logger.hpp:51
#define BUILD_TYPE
Definition Version.hpp:15
#define PROJECT_VERSION
Definition Version.hpp:8
#define GIT_TAG
Definition Version.hpp:14
#define PROJECT_NAME
Definition Version.hpp:7
#define GIT_COMMIT_HASH
Definition Version.hpp:13
This file contains the ArgsHandler class declaration.
This file contains common definitions and constants.
std::string host