Skip to content

Commit

Permalink
Unable to successfully clean up networking system, leaving debugging …
Browse files Browse the repository at this point in the history
…stuff in place. Will revisit later.
  • Loading branch information
Chukobyte committed May 16, 2021
1 parent d3db817 commit f7275cc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
9 changes: 8 additions & 1 deletion assets/game_projects/fighter/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/core/networking/network_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endif

#define ASIO_STANDALONE
//#define ASIO_ENABLE_HANDLER_TRACKING
#include <asio.hpp>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>
Expand Down
5 changes: 3 additions & 2 deletions src/core/networking/network_connection_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class NetworkConnectionContext {
std::map<NetworkConnectionId, TCPConnection*> networkConnections;
public:

TCPConnection* NewTCPConnection(asio::io_context &context, NetworkQueue<NetworkMessage> &networkQueue, NetworkConnectionHostType hostType, NetworkConnectionId connectionId) {
TCPConnection *tcpConnection = new TCPConnection(context, networkQueue, hostType, connectionId);
TCPConnection* NewTCPConnection(asio::io_context &context, NetworkQueue<NetworkMessage> &networkQueue, NetworkConnectionHostType hostType) {
static NetworkConnectionId connectionId = 0;
TCPConnection *tcpConnection = new TCPConnection(context, networkQueue, hostType, connectionId++);
networkConnections.emplace(connectionId, tcpConnection);
return tcpConnection;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/networking/network_tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/networking/network_tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f7275cc

Please sign in to comment.