From 812c183a5d6a3edbc6600008050afa812943d2d6 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Tue, 12 Jun 2018 13:40:41 +0200 Subject: [PATCH] Fixed various bugs in examples. --- examples/Synchronization.cpp | 8 ++++++-- examples/SynchronizationSFML.cpp | 13 ++++++++----- examples/TestClient.cpp | 3 ++- examples/TestServer.cpp | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/examples/Synchronization.cpp b/examples/Synchronization.cpp index 02f6e23..8f4e1d0 100644 --- a/examples/Synchronization.cpp +++ b/examples/Synchronization.cpp @@ -71,7 +71,7 @@ class Object : public sfn::SyncedObject { } Object& operator=( Object&& object ) { - static_cast( this )->operator=( std::forward( object ) ); + sfn::SyncedObject::operator=( std::forward( object ) ); x = object.x; y = object.y; @@ -219,7 +219,11 @@ int main( int /*argc*/, char** argv ) { // the RemoveClient() method. for( auto iter = std::begin( links ); iter != std::end( links ); ) { auto transport = ( *iter )->GetTransport(); - if( !transport || !transport->IsConnected() || transport->RemoteHasShutdown() ) { + + if( !transport ) { + iter = links.erase( iter ); + continue; + } else if( !transport->IsConnected() || transport->RemoteHasShutdown() ) { transport->Shutdown(); iter = links.erase( iter ); continue; diff --git a/examples/SynchronizationSFML.cpp b/examples/SynchronizationSFML.cpp index 41a65af..6c46473 100644 --- a/examples/SynchronizationSFML.cpp +++ b/examples/SynchronizationSFML.cpp @@ -20,7 +20,7 @@ class Coordinate : public sfn::SyncedObject { Coordinate() : x{ this, 300.f }, y{ this, 200.f }, - color{ this, sf::Color{ dist( gen ), dist( gen ), dist( gen ), 255 } } + color{ this, sf::Color{ static_cast( dist( gen ) ), static_cast( dist( gen ) ), static_cast( dist( gen ) ), 255 } } { } @@ -70,7 +70,7 @@ class Coordinate : public sfn::SyncedObject { } Coordinate& operator=( Coordinate&& coordinate ) { - static_cast( this )->operator=( std::forward( coordinate ) ); + sfn::SyncedObject::operator=( std::forward( coordinate ) ); x = coordinate.x; y = coordinate.y; @@ -134,7 +134,7 @@ class Coordinate : public sfn::SyncedObject { sf::CircleShape shape{ 20.f, 20 }; static std::mt19937 gen; - static std::uniform_int_distribution dist; + static std::uniform_int_distribution dist; }; // Our Coordinate object type id. @@ -142,7 +142,7 @@ const Coordinate::object_type_id_type Coordinate::type_id = 0x1337; // Our random colour generator std::mt19937 Coordinate::gen{}; -std::uniform_int_distribution Coordinate::dist{ 0, 255 }; +std::uniform_int_distribution Coordinate::dist{ 0, 255 }; // Of course we need to teach sfn::Message how to deal with sf::Color objects. namespace sfn { @@ -270,7 +270,10 @@ int main( int /*argc*/, char** argv ) { // the RemoveClient() method. for( auto iter = std::begin( links ); iter != std::end( links ); ) { auto transport = ( *iter )->GetTransport(); - if( !transport || !transport->IsConnected() || transport->RemoteHasShutdown() ) { + if( !transport ) { + iter = links.erase( iter ); + continue; + } else if( !transport->IsConnected() || transport->RemoteHasShutdown() ) { transport->Shutdown(); iter = links.erase( iter ); continue; diff --git a/examples/TestClient.cpp b/examples/TestClient.cpp index b2c93b2..98e9600 100644 --- a/examples/TestClient.cpp +++ b/examples/TestClient.cpp @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include #include @@ -458,7 +459,7 @@ int main( int argc, char** argv ) { if( ( event.text.unicode == 8 ) && current_message.getSize() ) { // Backspace current_message.erase( current_message.getSize() - 1, 1 ); } - else if( std::isprint( event.text.unicode ) ) { + else if( ( event.text.unicode < 255 ) && std::isprint( static_cast( event.text.unicode ) ) ) { current_message += event.text.unicode; } } else if( ( event.type == sf::Event::KeyPressed ) && connected && !chatting ) { diff --git a/examples/TestServer.cpp b/examples/TestServer.cpp index d87e05b..8e9b70f 100644 --- a/examples/TestServer.cpp +++ b/examples/TestServer.cpp @@ -159,7 +159,7 @@ class Player : public sfn::SyncedObject { m_acceleration{ this, 0.f }, m_rotation{ this, 0.f }, m_rotational_velocity{ this, 0.f }, - m_color{ this, sf::Color{ dist( gen ), dist( gen ), dist( gen ), 255 } }, + m_color{ this, sf::Color{ static_cast( dist( gen ) ), static_cast( dist( gen ) ), static_cast( dist( gen ) ), 255 } }, m_link{ player_link } { } @@ -319,14 +319,14 @@ class Player : public sfn::SyncedObject { bool m_firing{ false }; static std::mt19937 gen; - static std::uniform_int_distribution dist; + static std::uniform_int_distribution dist; static std::uniform_real_distribution position_dist; }; const Player::object_type_id_type Player::type_id = 0x1337; std::mt19937 Player::gen{}; -std::uniform_int_distribution Player::dist{ 100, 255 }; +std::uniform_int_distribution Player::dist{ 100, 255 }; std::uniform_real_distribution Player::position_dist{ -180.f, 180.f }; namespace sfn {