17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 10:59:20 +02:00
Files
maszyna/network/manager.cpp
maj00r b8f040e6fd propagate template headers transitively, import Console where used
AnimModel.cpp reaches cParser through the simulation core, not a direct
import, so the previous pass missed it; the propagation now follows the
whole import closure. Train.cpp, drivermode.cpp and Globals.cpp call
Console:: inside _WIN32 guards without importing eu07.console - invisible
on Linux, where those blocks are skipped.
2026-09-10 01:41:24 +02:00

108 lines
2.3 KiB
C++

module;
#include <array>
#include <chrono>
#include <cstddef>
#include <deque>
#include <limits>
#include <mutex>
#include <ostream>
#include <sstream>
#include <type_traits>
#include <utility>
#include <memory>
#include <optional>
#include <unordered_map>
#include <vector>
#include <fstream>
#include <ios>
#include <string>
module eu07.network.manager;
import eu07.network.message;
import eu07.simulation.simulation;
import eu07.utilities.logs;
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
network::server_manager::server_manager()
{
backbuffer = std::make_shared<std::fstream>("backbuffer.bin", std::ios::out | std::ios::in | std::ios::trunc | std::ios::binary);
}
command_queue::commands_map network::server_manager::pop_commands()
{
command_queue::commands_map map;
for (auto srv : servers)
add_to_dequemap(map, srv->pop_commands());
return map;
}
void network::server_manager::push_delta(double render_dt, double dt, double sync, const command_queue::commands_map &commands)
{
if (dt == 0.0 && commands.empty())
return;
frame_info msg;
msg.render_dt = render_dt;
msg.dt = dt;
msg.sync = sync;
msg.commands = commands;
for (auto srv : servers)
srv->push_delta(msg);
serialize_message(msg, *backbuffer.get());
}
void network::server_manager::create_server(const std::string &backend, const std::string &conf)
{
auto it = backend_list().find(backend);
if (it == backend_list().end()) {
ErrorLog("net: unknown backend: " + backend);
return;
}
servers.emplace_back(it->second->create_server(backbuffer, conf));
}
network::manager::manager()
{
}
void network::manager::update()
{
for (auto &backend : backend_list())
backend.second->update();
if (client)
client->update();
}
void network::manager::create_server(const std::string &backend, const std::string &conf)
{
servers.emplace();
servers->create_server(backend, conf);
}
void network::manager::connect(const std::string &backend, const std::string &conf)
{
auto it = backend_list().find(backend);
if (it == backend_list().end()) {
ErrorLog("net: unknown backend: " + backend);
return;
}
client = it->second->create_client(conf);
}
//std::unordered_map<std::string, std::shared_ptr<network::backend_manager>> network::backend_list;