From f7275cc5b1064a57d5cb0d4f4fd2de593d4798a1 Mon Sep 17 00:00:00 2001 From: chukobyte Date: Sun, 16 May 2021 09:47:05 -0400 Subject: [PATCH] Unable to successfully clean up networking system, leaving debugging stuff in place. Will revisit later. --- assets/game_projects/fighter/src/main.py | 9 ++++++++- src/core/networking/network_common.h | 1 + src/core/networking/network_connection_context.h | 5 +++-- src/core/networking/network_tcp_client.cpp | 2 +- src/core/networking/network_tcp_server.cpp | 3 +-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/assets/game_projects/fighter/src/main.py b/assets/game_projects/fighter/src/main.py index c528ecaa..9ab3bca7 100644 --- a/assets/game_projects/fighter/src/main.py +++ b/assets/game_projects/fighter/src/main.py @@ -5,6 +5,7 @@ from roll.engine import Engine from roll.math import Vector2 from roll.network import Server, Client, Network +from roll.scene import SceneTree from assets.game_projects.fighter.src.fight_state import FightState, PlayerStateData from assets.game_projects.fighter.src.input_buffer import ( @@ -158,7 +159,13 @@ def _physics_process(self, delta_time: float) -> None: def _process_inputs(self) -> None: if Input.is_action_just_pressed(action_name="quit"): - Engine.exit() + # Go back to main menu + if self.game_properties.player_opponent_mode == PropertyValue.PLAYER_OPPONENT_MODE_HOST_PLAYER_VS_PLAYER: + Server.stop() + elif self.game_properties.player_opponent_mode == PropertyValue.PLAYER_OPPONENT_MODE_CLIENT_PLAYER_VS_PLAYER: + Client.disconnect() + SceneTree.change_scene(scene_path="assets/game_projects/fighter/scenes/title_screen.json") + # Engine.exit() for input_buffer in self.input_buffers: input_buffer.poll_client_inputs(frame=self.frame_counter) diff --git a/src/core/networking/network_common.h b/src/core/networking/network_common.h index 07d93d08..e610f728 100644 --- a/src/core/networking/network_common.h +++ b/src/core/networking/network_common.h @@ -17,6 +17,7 @@ #endif #define ASIO_STANDALONE +//#define ASIO_ENABLE_HANDLER_TRACKING #include #include #include diff --git a/src/core/networking/network_connection_context.h b/src/core/networking/network_connection_context.h index 9bae4edf..f69918cb 100644 --- a/src/core/networking/network_connection_context.h +++ b/src/core/networking/network_connection_context.h @@ -11,8 +11,9 @@ class NetworkConnectionContext { std::map networkConnections; public: - TCPConnection* NewTCPConnection(asio::io_context &context, NetworkQueue &networkQueue, NetworkConnectionHostType hostType, NetworkConnectionId connectionId) { - TCPConnection *tcpConnection = new TCPConnection(context, networkQueue, hostType, connectionId); + TCPConnection* NewTCPConnection(asio::io_context &context, NetworkQueue &networkQueue, NetworkConnectionHostType hostType) { + static NetworkConnectionId connectionId = 0; + TCPConnection *tcpConnection = new TCPConnection(context, networkQueue, hostType, connectionId++); networkConnections.emplace(connectionId, tcpConnection); return tcpConnection; } diff --git a/src/core/networking/network_tcp_client.cpp b/src/core/networking/network_tcp_client.cpp index 706c02ca..b4865621 100644 --- a/src/core/networking/network_tcp_client.cpp +++ b/src/core/networking/network_tcp_client.cpp @@ -15,7 +15,7 @@ void NetworkTCPClient::Connect() { if (!connection) { asio::error_code errorCode; asio::ip::tcp::endpoint endpoint(asio::ip::make_address(ipAddress.c_str(), errorCode), port); - connection = networkConnectionContext->NewTCPConnection(context, networkQueue, NetworkConnectionHostType_CLIENT, 1); + connection = networkConnectionContext->NewTCPConnection(context, networkQueue, NetworkConnectionHostType_CLIENT); connection->GetSocket().connect(endpoint, errorCode); if (!errorCode) { diff --git a/src/core/networking/network_tcp_server.cpp b/src/core/networking/network_tcp_server.cpp index 3ec6aad0..377a9aa0 100644 --- a/src/core/networking/network_tcp_server.cpp +++ b/src/core/networking/network_tcp_server.cpp @@ -30,8 +30,7 @@ void NetworkTCPServer::ProcessMessageQueue() { } void NetworkTCPServer::AcceptConnections() { - static int connectionId = 0; - TCPConnection *tcpConnection = networkConnectionContext->NewTCPConnection(context, networkQueue, NetworkConnectionHostType_SERVER, connectionId++); + TCPConnection *tcpConnection = networkConnectionContext->NewTCPConnection(context, networkQueue, NetworkConnectionHostType_SERVER); auto handleAcceptFunction = [this, tcpConnection](const asio::error_code &errorCode) { if (!errorCode) { tcpConnection->StartReadingNetworkMessages();