r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
client.cpp
Go to the documentation of this file.
1#include "Client/Client.hpp"
8#include "Utils/Logger.hpp"
10
12{
13 utl::cli::AppConfig appConfig;
14
15 appConfig.frameLimit = cfg.frameLimit;
16 appConfig.fullscreen = cfg.fullscreen;
17 appConfig.height = cfg.height;
18 appConfig.width = cfg.width;
19 appConfig.host = cfg.host;
20 appConfig.port = cfg.port;
21 appConfig.player_name = cfg.player_name;
22
27
28 return appConfig;
29}
30
32{
33 utl::Logger::log("PROJECT INFO:", utl::LogLevel::INFO);
34 std::cout << "\tName: " PROJECT_NAME "\n"
35 << "\tVersion: " PROJECT_VERSION "\n"
36 << "\tBuild type: " BUILD_TYPE "\n"
37 << "\tGit tag: " GIT_TAG "\n"
38 << "\tGit commit hash: " GIT_COMMIT_HASH "\n";
39
40 m_config = setupConfig(cfg);
41 m_pluginLoader = std::make_unique<utl::PluginLoader>();
42 m_engine = std::make_unique<eng::Engine>(
43 [this, cfg]()
44 {
45 return m_pluginLoader->loadPlugin<eng::IAudio>(
47 },
48 [this, cfg]()
49 {
50 return m_pluginLoader->loadPlugin<eng::INetworkClient>(
51 !cfg.network_lib_path.empty() ? cfg.network_lib_path
53 },
54 [this, cfg]()
55 {
56 return m_pluginLoader->loadPlugin<eng::IRenderer>(!cfg.renderer_lib_path.empty()
59 });
60 m_gameSolo = m_pluginLoader->loadPlugin<gme::IGameClient>(
62 m_gameMulti = m_pluginLoader->loadPlugin<gme::IGameClient>(
64 m_engine->getRenderer()->createWindow("R-Type Client", m_config.height, m_config.width, m_config.frameLimit,
65 m_config.fullscreen);
66 m_engine->getRenderer()->setWindowIcon(utl::Path::Texture::ICON_PATH);
67}
68
70{
71 setupScenes();
72
73 eng::Event event;
74 while (m_engine->getState() == eng::State::RUN)
75 {
76 handleEvents(event);
77 m_engine->render(m_engine->getRenderer()->getWindowSize(), utl::Config::Color::DARK, m_showDebug);
78 m_engine->getNetwork()->update();
79 m_gameSolo->update(m_engine->getClock()->getDeltaSeconds(), m_engine->getRenderer()->getWindowSize().width,
80 m_engine->getRenderer()->getWindowSize().height);
81 }
82}
83
85{
86 m_engine->getNetwork()->disconnect();
87 m_engine->stop();
88}
89
91{
92 auto menuId = m_engine->getSceneManager()->generateNextId();
93 auto menu = std::make_unique<Menu>(menuId, m_engine->getRenderer());
94 menu->addSystem(std::make_unique<ecs::AudioSystem>(m_engine->getAudio(), m_config.audioVolume, menu->getRegistry(),
95 menu->playMusic()));
96 menu->addSystem(std::make_unique<ecs::StarfieldSystem>(m_engine->getRenderer(), menu->getRegistry()));
97 menu->addSystem(std::make_unique<ecs::SpriteSystem>(m_engine->getRenderer()));
98 menu->addSystem(std::make_unique<ecs::TextSystem>(m_engine->getRenderer()));
99 menu->addSystem(std::make_unique<ecs::DebugSystem>(m_engine->getRenderer(), m_showDebug));
100
101 auto winConditionId = m_engine->getSceneManager()->generateNextId();
102 auto winCondition = std::make_unique<WinCondition>(winConditionId, m_engine->getRenderer(), m_engine->getAudio());
103 winCondition->addSystem(std::make_unique<ecs::AudioSystem>(m_engine->getAudio(), m_config.audioVolume,
104 winCondition->getRegistry(), winCondition->playMusic()));
105 winCondition->addSystem(std::make_unique<ecs::SpriteSystem>(m_engine->getRenderer()));
106 winCondition->addSystem(std::make_unique<ecs::TextSystem>(m_engine->getRenderer()));
107 winCondition->addSystem(std::make_unique<ecs::DebugSystem>(m_engine->getRenderer(), m_showDebug));
108 winCondition->onLeave = [this, menuId]() { m_engine->getSceneManager()->switchToScene(menuId); };
109 m_gameSolo->init(*m_engine, m_config, m_showDebug, menuId, winConditionId);
110 m_gameMulti->init(*m_engine, m_config, m_showDebug, menuId, winConditionId);
111 auto introId = m_engine->getSceneManager()->generateNextId();
112 auto intro = std::make_unique<Intro>(introId, m_engine->getRenderer(), m_engine->getAudio());
113 intro->addSystem(std::make_unique<ecs::AudioSystem>(m_engine->getAudio(), m_config.audioVolume,
114 intro->getRegistry(), menu->playMusic()));
115 intro->addSystem(std::make_unique<ecs::StarfieldSystem>(m_engine->getRenderer(), intro->getRegistry()));
116 intro->addSystem(std::make_unique<ecs::SpriteSystem>(m_engine->getRenderer()));
117 intro->addSystem(std::make_unique<ecs::TextSystem>(m_engine->getRenderer()));
118 intro->addSystem(std::make_unique<ecs::DebugSystem>(m_engine->getRenderer(), m_showDebug));
119 intro->onLeave = [this, menuId]() { m_engine->getSceneManager()->switchToScene(menuId); };
120
121 auto settingsId = m_engine->getSceneManager()->generateNextId();
122 auto settings = std::make_unique<Settings>(settingsId, m_engine->getRenderer(), m_config);
123 settings->addSystem(std::make_unique<ecs::AudioSystem>(m_engine->getAudio(), m_config.audioVolume,
124 settings->getRegistry(), settings->playMusic()));
125 settings->addSystem(std::make_unique<ecs::StarfieldSystem>(m_engine->getRenderer(), settings->getRegistry()));
126 settings->addSystem(std::make_unique<ecs::SpriteSystem>(m_engine->getRenderer()));
127 settings->addSystem(std::make_unique<ecs::TextSystem>(m_engine->getRenderer()));
128 settings->addSystem(std::make_unique<ecs::DebugSystem>(m_engine->getRenderer(), m_showDebug));
129 const auto configSoloId = m_gameSolo->getMainSceneId();
130 const auto serverSceneId = m_gameMulti->getMainSceneId();
131 menu->onOptionSelected = [this, configSoloId, serverSceneId, settingsId](const std::string &option)
132 {
133 if (option == "Solo")
134 {
135 m_engine->getSceneManager()->switchToScene(configSoloId);
136 }
137 else if (option == "Multi")
138 {
139 m_engine->getSceneManager()->switchToScene(serverSceneId);
140 }
141 else if (option == "Settings")
142 {
143 m_engine->getSceneManager()->switchToScene(settingsId);
144 }
145 };
146 settings->onLeave = [this, menuId]() { m_engine->getSceneManager()->switchToScene(menuId); };
147
148 m_engine->getSceneManager()->addScene(std::move(menu));
149 m_engine->getSceneManager()->addScene(std::move(intro));
150 m_engine->getSceneManager()->addScene(std::move(settings));
151 m_engine->getSceneManager()->addScene(std::move(winCondition));
152 m_engine->getSceneManager()->switchToScene(introId);
153}
This file contains the Client class declaration.
This file contains the intro scene.
This file contains the Logger class.
This file contains the menu scene.
Modern, cross-platform plugin loader.
This file contains the settings scene.
This file contains the win condition scene.
Client(const ArgsConfig &cfg)
Definition client.cpp:31
void setupScenes()
Definition client.cpp:90
void stop() const
Definition client.cpp:84
void run()
Definition client.cpp:69
static utl::cli::AppConfig setupConfig(const ArgsConfig &cfg)
Definition client.cpp:11
Interface for the audio.
Definition IAudio.hpp:29
Interface for the client network.
Interface for the renderer.
Interface for the games.
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 system definitions.
@ RUN
Definition Engine.hpp:24
constexpr auto DEFAULT_AUDIO_VOLUME
Definition Common.hpp:32
static constexpr eng::Color DARK
Definition Common.hpp:55
constexpr auto DEFAULT_VIDEO_QUALITY
Definition Common.hpp:49
constexpr auto DEFAULT_CONTROL_SCHEME
Definition Common.hpp:50
constexpr auto DEFAULT_SKIN_INDEX
Definition Common.hpp:51
auto PLUGIN_RENDERER_SFML
Definition Common.hpp:105
auto PLUGIN_NETWORK_ASIO_CLIENT
Definition Common.hpp:103
constexpr auto ICON_PATH
Definition Common.hpp:139
std::string game_multi_lib_path
unsigned int frameLimit
std::string host
std::string player_name
std::string audio_lib_path
unsigned int height
unsigned int port
unsigned int width
std::string network_lib_path
std::string game_solo_lib_path
std::string renderer_lib_path