mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
work
This commit is contained in:
@@ -11,6 +11,10 @@ include(cotire)
|
||||
set(DEPS_DIR ${DEPS_DIR} "${CMAKE_SOURCE_DIR}/ref")
|
||||
project("eu07")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
include_directories("."
|
||||
"Console"
|
||||
@@ -258,7 +262,3 @@ target_link_libraries(${PROJECT_NAME} ASIO::ASIO)
|
||||
if (WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} ws2_32)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -fsanitize=address -fsanitize=undefined")
|
||||
|
||||
@@ -169,7 +169,6 @@ void network::tcp::server::handle_accept(std::shared_ptr<connection> conn, const
|
||||
network::tcp::client::client(asio::io_context &io_ctxx, const std::string &hostarg, uint32_t portarg)
|
||||
: host(hostarg), port(portarg), io_ctx(io_ctxx)
|
||||
{
|
||||
connect();
|
||||
}
|
||||
|
||||
void network::tcp::client::connect()
|
||||
@@ -178,24 +177,20 @@ void network::tcp::client::connect()
|
||||
return;
|
||||
|
||||
std::cout << "create sock" << std::endl;
|
||||
connection *sockr = new connection(io_ctx, false, 0);
|
||||
//std::cout << "sock crt" << std::endl;
|
||||
//std::unique_ptr<connection> sock(sockr);
|
||||
//this->conn = sock;
|
||||
//connection *sockr = new connection(io_ctx, true, delta_count);
|
||||
|
||||
std::shared_ptr<connection> sock(sockr);
|
||||
this->conn = sock;
|
||||
sock->set_handler(std::bind(&client::handle_message, this, sock, std::placeholders::_1));
|
||||
std::shared_ptr<connection> conn = std::make_shared<connection>(io_ctx, true, resume_frame_counter);
|
||||
conn->set_handler(std::bind(&client::handle_message, this, conn, std::placeholders::_1));
|
||||
|
||||
asio::ip::tcp::endpoint endpoint(
|
||||
asio::ip::address::from_string(host), port);
|
||||
sock->m_socket.open(endpoint.protocol());
|
||||
sock->m_socket.set_option(asio::ip::tcp::no_delay(true));
|
||||
sock->m_socket.async_connect(endpoint,
|
||||
conn->m_socket.open(endpoint.protocol());
|
||||
conn->m_socket.set_option(asio::ip::tcp::no_delay(true));
|
||||
conn->m_socket.async_connect(endpoint,
|
||||
std::bind(&client::handle_accept, this, std::placeholders::_1));
|
||||
std::cout << "connect start" <<std::endl;
|
||||
|
||||
this->conn = conn;
|
||||
|
||||
}
|
||||
|
||||
void network::tcp::client::handle_accept(const asio::error_code &err)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "network/network.h"
|
||||
//#define ASIO_ENABLE_HANDLER_TRACKING
|
||||
#define ASIO_DISABLE_THREADS
|
||||
|
||||
#include <asio.hpp>
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ network::manager::manager()
|
||||
|
||||
void network::manager::poll()
|
||||
{
|
||||
io_context.restart();
|
||||
io_context.poll();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,48 +70,6 @@ void network::connection::send_complete(std::shared_ptr<std::string> buf)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (msg->type == message::TYPE_MAX)
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_client) {
|
||||
if (msg->type == message::SERVER_HELLO) {
|
||||
auto cmd = std::dynamic_pointer_cast<server_hello>(msg);
|
||||
|
||||
state = ACTIVE;
|
||||
Global.random_seed = cmd->seed;
|
||||
Global.random_engine.seed(Global.random_seed);
|
||||
|
||||
WriteLog("net: accept received", logtype::net);
|
||||
}
|
||||
else if (msg->type == message::FRAME_INFO) {
|
||||
auto delta = std::dynamic_pointer_cast<frame_info>(msg);
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
delta_queue.push(std::make_pair(now, delta));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (msg->type == message::CLIENT_HELLO) {
|
||||
server_hello reply;
|
||||
reply.seed = Global.random_seed;
|
||||
state = ACTIVE;
|
||||
|
||||
send_message(reply);
|
||||
|
||||
WriteLog("net: client accepted", logtype::net);
|
||||
}
|
||||
else if (msg->type == message::REQUEST_COMMAND) {
|
||||
auto cmd = std::dynamic_pointer_cast<request_command>(msg);
|
||||
|
||||
for (auto const &kv : cmd->commands)
|
||||
client_commands_queue.emplace(kv);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// --------------
|
||||
|
||||
/*
|
||||
@@ -141,12 +99,6 @@ std::tuple<double, double, command_queue::commands_map> network::connection::get
|
||||
//}
|
||||
}
|
||||
|
||||
command_queue::commands_map network::connection::pop_commands()
|
||||
{
|
||||
command_queue::commands_map map(client_commands_queue);
|
||||
client_commands_queue.clear();
|
||||
return map;
|
||||
}
|
||||
*/
|
||||
|
||||
// server
|
||||
@@ -216,14 +168,12 @@ void network::server::handle_message(std::shared_ptr<connection> conn, const mes
|
||||
// ------------
|
||||
|
||||
// client
|
||||
int zzz = 10;
|
||||
int zzz = 20;
|
||||
std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta()
|
||||
{
|
||||
/*
|
||||
if (conn && conn->state == connection::DEAD) {
|
||||
conn = nullptr;
|
||||
conn.reset();
|
||||
}
|
||||
*/
|
||||
|
||||
if (!conn) {
|
||||
zzz--;
|
||||
@@ -272,7 +222,7 @@ void network::client::handle_message(std::shared_ptr<connection> conn, const mes
|
||||
WriteLog("net: accept received", logtype::net);
|
||||
}
|
||||
else if (msg.type == message::FRAME_INFO) {
|
||||
delta_count++;
|
||||
resume_frame_counter++;
|
||||
|
||||
auto delta = dynamic_cast<const frame_info&>(msg);
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace network
|
||||
virtual void connect() = 0;
|
||||
void handle_message(std::shared_ptr<connection> conn, const message &msg);
|
||||
std::shared_ptr<connection> conn;
|
||||
size_t delta_count = 0;
|
||||
size_t resume_frame_counter = 0;
|
||||
|
||||
std::queue<
|
||||
std::pair<std::chrono::high_resolution_clock::time_point,
|
||||
|
||||
Reference in New Issue
Block a user