mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-30 16:40:28 +01:00
pch migration to modules [wip]
This commit is contained in:
@@ -1,7 +1,113 @@
|
||||
#include "stdafx.h"
|
||||
#include "network/backend/asio.h"
|
||||
#include "scene/sn_utils.h"
|
||||
#include "utilities/Logs.h"
|
||||
module;
|
||||
#define ASIO_DISABLE_VISIBILITY
|
||||
#include <asio.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
export module eu07.network.backend.asio;
|
||||
|
||||
import eu07.network.message;
|
||||
import eu07.network.network;
|
||||
import eu07.gl.buffer;
|
||||
import eu07.rendering.geometrybank;
|
||||
import eu07.scene.sn_utils;
|
||||
import eu07.utilities.logs;
|
||||
|
||||
|
||||
export {
|
||||
#ifdef DBG_NEW
|
||||
#undef new
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace network::tcp
|
||||
{
|
||||
const uint32_t NETWORK_MAGIC = 0x37305545;
|
||||
const uint32_t MAX_MSG_SIZE = 100000;
|
||||
|
||||
class connection : public network::connection
|
||||
{
|
||||
friend class server;
|
||||
friend class client;
|
||||
|
||||
public:
|
||||
connection(asio::io_context &io_ctx, bool client = false, size_t counter = 0);
|
||||
~connection();
|
||||
|
||||
virtual void connected() override;
|
||||
virtual void disconnect() override;
|
||||
virtual void send_messages(const std::vector<std::shared_ptr<message> > &messages) override;
|
||||
virtual void send_message(const message &msg) override;
|
||||
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
private:
|
||||
std::string m_header_buffer;
|
||||
std::string m_body_buffer;
|
||||
|
||||
void write_message(const message &msg, std::ostream &stream);
|
||||
void send_data(std::shared_ptr<std::string> buffer);
|
||||
void read_header();
|
||||
void handle_header(const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_data(const asio::error_code &err, size_t bytes_transferred);
|
||||
};
|
||||
|
||||
class server : public network::server
|
||||
{
|
||||
private:
|
||||
void accept_conn();
|
||||
void handle_accept(std::shared_ptr<connection> conn, const asio::error_code &err);
|
||||
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
asio::io_context &m_io_ctx;
|
||||
|
||||
public:
|
||||
server(std::shared_ptr<std::istream> buf, asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class client : public network::client
|
||||
{
|
||||
private:
|
||||
void handle_accept(const asio::error_code &err);
|
||||
asio::io_context &io_ctx;
|
||||
std::string host;
|
||||
uint32_t port;
|
||||
|
||||
protected:
|
||||
virtual void connect() override;
|
||||
|
||||
public:
|
||||
client(asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class asio_manager : public network::backend_manager {
|
||||
asio::io_context io_context;
|
||||
|
||||
public:
|
||||
asio_manager();
|
||||
|
||||
virtual std::shared_ptr<network::server> create_server(std::shared_ptr<std::fstream>, const std::string &conf) override;
|
||||
virtual std::shared_ptr<network::client> create_client(const std::string &conf) override;
|
||||
virtual void update() override;
|
||||
};
|
||||
|
||||
asio_manager manager;
|
||||
}
|
||||
|
||||
} // export
|
||||
|
||||
// The implementation lives here rather than in a separate implementation unit:
|
||||
// asio defines its customization points as objects in an anonymous namespace, and
|
||||
// GCC emits those a second time in any implementation unit that also includes
|
||||
// asio.hpp, which the assembler rejects as duplicate symbols. One translation unit
|
||||
// including asio is the way around it.
|
||||
|
||||
network::tcp::connection::connection(asio::io_context &io_ctx, bool client, size_t counter)
|
||||
: network::connection(client, counter),
|
||||
@@ -1,82 +0,0 @@
|
||||
#ifdef DBG_NEW
|
||||
#undef new
|
||||
#endif
|
||||
|
||||
#define ASIO_DISABLE_VISIBILITY
|
||||
#include <asio.hpp>
|
||||
|
||||
#include "network/network.h"
|
||||
|
||||
namespace network::tcp
|
||||
{
|
||||
const uint32_t NETWORK_MAGIC = 0x37305545;
|
||||
const uint32_t MAX_MSG_SIZE = 100000;
|
||||
|
||||
class connection : public network::connection
|
||||
{
|
||||
friend class server;
|
||||
friend class client;
|
||||
|
||||
public:
|
||||
connection(asio::io_context &io_ctx, bool client = false, size_t counter = 0);
|
||||
~connection();
|
||||
|
||||
virtual void connected() override;
|
||||
virtual void disconnect() override;
|
||||
virtual void send_messages(const std::vector<std::shared_ptr<message> > &messages) override;
|
||||
virtual void send_message(const message &msg) override;
|
||||
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
private:
|
||||
std::string m_header_buffer;
|
||||
std::string m_body_buffer;
|
||||
|
||||
void write_message(const message &msg, std::ostream &stream);
|
||||
void send_data(std::shared_ptr<std::string> buffer);
|
||||
void read_header();
|
||||
void handle_header(const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_data(const asio::error_code &err, size_t bytes_transferred);
|
||||
};
|
||||
|
||||
class server : public network::server
|
||||
{
|
||||
private:
|
||||
void accept_conn();
|
||||
void handle_accept(std::shared_ptr<connection> conn, const asio::error_code &err);
|
||||
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
asio::io_context &m_io_ctx;
|
||||
|
||||
public:
|
||||
server(std::shared_ptr<std::istream> buf, asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class client : public network::client
|
||||
{
|
||||
private:
|
||||
void handle_accept(const asio::error_code &err);
|
||||
asio::io_context &io_ctx;
|
||||
std::string host;
|
||||
uint32_t port;
|
||||
|
||||
protected:
|
||||
virtual void connect() override;
|
||||
|
||||
public:
|
||||
client(asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class asio_manager : public network::backend_manager {
|
||||
asio::io_context io_context;
|
||||
|
||||
public:
|
||||
asio_manager();
|
||||
|
||||
virtual std::shared_ptr<network::server> create_server(std::shared_ptr<std::fstream>, const std::string &conf) override;
|
||||
virtual std::shared_ptr<network::client> create_client(const std::string &conf) override;
|
||||
virtual void update() override;
|
||||
};
|
||||
|
||||
asio_manager manager;
|
||||
}
|
||||
@@ -1,3 +1,12 @@
|
||||
module;
|
||||
#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.
|
||||
@@ -7,10 +16,6 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "network/manager.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "utilities/Logs.h"
|
||||
|
||||
network::server_manager::server_manager()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
#pragma once
|
||||
module;
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "network/network.h"
|
||||
#include "input/command.h"
|
||||
|
||||
export module eu07.network.manager;
|
||||
import eu07.network.network;
|
||||
import eu07.input.command;
|
||||
|
||||
export {
|
||||
|
||||
namespace network
|
||||
{
|
||||
@@ -32,3 +38,5 @@ namespace network
|
||||
void update();
|
||||
};
|
||||
}
|
||||
|
||||
} // export
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "network/message.h"
|
||||
#include "scene/sn_utils.h"
|
||||
module;
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
module eu07.network.message;
|
||||
import eu07.scene.sn_utils;
|
||||
|
||||
void network::client_hello::serialize(std::ostream &stream) const
|
||||
{
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
#pragma once
|
||||
#include "network/message.h"
|
||||
#include "input/command.h"
|
||||
module;
|
||||
#include <queue>
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
export module eu07.network.message;
|
||||
import eu07.input.command;
|
||||
|
||||
export {
|
||||
|
||||
namespace network
|
||||
{
|
||||
@@ -73,3 +81,5 @@ struct frame_info : public request_command
|
||||
std::shared_ptr<message> deserialize_message(std::istream &stream);
|
||||
void serialize_message(const message &msg, std::ostream &stream);
|
||||
} // namespace network
|
||||
|
||||
} // export
|
||||
@@ -1,11 +1,23 @@
|
||||
#include "stdafx.h"
|
||||
#include "network/network.h"
|
||||
#include "network/message.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "scene/sn_utils.h"
|
||||
#include "utilities/Timer.h"
|
||||
#include "application/application.h"
|
||||
#include "utilities/Globals.h"
|
||||
module;
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include "utilities/Globals_macros.h"
|
||||
|
||||
module eu07.network.network;
|
||||
import eu07.network.message;
|
||||
import eu07.utilities.logs;
|
||||
import eu07.scene.sn_utils;
|
||||
import eu07.utilities.timer;
|
||||
import eu07.application.application;
|
||||
import eu07.utilities.globals;
|
||||
|
||||
std::uint32_t const EU07_NETWORK_VERSION = 2;
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#pragma once
|
||||
module;
|
||||
#include <memory>
|
||||
#include <istream>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <chrono>
|
||||
#include "network/message.h"
|
||||
#include "input/command.h"
|
||||
|
||||
export module eu07.network.network;
|
||||
import eu07.network.message;
|
||||
import eu07.input.command;
|
||||
|
||||
export {
|
||||
|
||||
namespace network
|
||||
{
|
||||
@@ -119,3 +125,5 @@ namespace network
|
||||
using backend_list_t = std::unordered_map<std::string, backend_manager*>;
|
||||
backend_list_t& backend_list();
|
||||
}
|
||||
|
||||
} // export
|
||||
Reference in New Issue
Block a user