16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00
This commit is contained in:
milek7
2019-01-14 00:20:14 +01:00
parent cb106fb135
commit b2a9388fab
12 changed files with 150 additions and 120 deletions

View File

@@ -9,12 +9,13 @@ namespace network
class manager
{
asio::io_context io_context;
std::shared_ptr<network::server> server;
std::shared_ptr<network::client> client;
public:
manager();
std::shared_ptr<network::server> server;
std::shared_ptr<network::client> client;
void create_server();
void connect();
void poll();

View File

@@ -118,6 +118,11 @@ void network::connection::send_message(std::shared_ptr<message> msg)
send_data(buf);
}
network::server::server()
{
recorder.open("recorder.bin", std::ios::trunc | std::ios::out | std::ios::binary);
}
void network::server::push_delta(double dt, double sync, command_queue::commands_map commands)
{
std::shared_ptr<delta_message> msg = std::make_shared<delta_message>();
@@ -125,6 +130,12 @@ void network::server::push_delta(double dt, double sync, command_queue::commands
msg->sync = sync;
msg->commands = commands;
sn_utils::ls_uint32(recorder, 0x37305545);
sn_utils::ls_uint32(recorder, msg->get_size());
sn_utils::ls_uint16(recorder, (uint16_t)msg->type);
msg->serialize(recorder);
recorder.flush();
for (auto c : clients)
c->send_message(msg);
}
@@ -159,6 +170,9 @@ std::tuple<double, double, command_queue::commands_map> network::client::get_nex
void network::client::send_commands(command_queue::commands_map commands)
{
if (commands.empty())
return;
std::shared_ptr<command_message> msg = std::make_shared<command_message>();
msg->commands = commands;

View File

@@ -41,8 +41,10 @@ namespace network
{
protected:
std::vector<std::shared_ptr<connection>> clients;
std::fstream recorder;
public:
server();
void push_delta(double dt, double sync, command_queue::commands_map commands);
command_queue::commands_map pop_commands();
void notify_train(std::string name);