Skip to content

Commit

Permalink
Fixed various bugs in examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
binary1248 committed Jun 12, 2018
1 parent 4d74cc8 commit 812c183
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions examples/Synchronization.cpp
Expand Up @@ -71,7 +71,7 @@ class Object : public sfn::SyncedObject {
}

Object& operator=( Object&& object ) {
static_cast<sfn::SyncedObject*>( this )->operator=( std::forward<sfn::SyncedObject>( object ) );
sfn::SyncedObject::operator=( std::forward<sfn::SyncedObject>( object ) );

x = object.x;
y = object.y;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions examples/SynchronizationSFML.cpp
Expand Up @@ -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<sf::Uint8>( dist( gen ) ), static_cast<sf::Uint8>( dist( gen ) ), static_cast<sf::Uint8>( dist( gen ) ), 255 } }
{
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class Coordinate : public sfn::SyncedObject {
}

Coordinate& operator=( Coordinate&& coordinate ) {
static_cast<sfn::SyncedObject*>( this )->operator=( std::forward<sfn::SyncedObject>( coordinate ) );
sfn::SyncedObject::operator=( std::forward<sfn::SyncedObject>( coordinate ) );

x = coordinate.x;
y = coordinate.y;
Expand Down Expand Up @@ -134,15 +134,15 @@ class Coordinate : public sfn::SyncedObject {
sf::CircleShape shape{ 20.f, 20 };

static std::mt19937 gen;
static std::uniform_int_distribution<sf::Uint8> dist;
static std::uniform_int_distribution<sf::Uint16> dist;
};

// Our Coordinate object type id.
const Coordinate::object_type_id_type Coordinate::type_id = 0x1337;

// Our random colour generator
std::mt19937 Coordinate::gen{};
std::uniform_int_distribution<sf::Uint8> Coordinate::dist{ 0, 255 };
std::uniform_int_distribution<sf::Uint16> Coordinate::dist{ 0, 255 };

// Of course we need to teach sfn::Message how to deal with sf::Color objects.
namespace sfn {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion examples/TestClient.cpp
Expand Up @@ -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 <cctype>
#include <cmath>
#include <iostream>
#include <list>
Expand Down Expand Up @@ -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<char>( event.text.unicode ) ) ) {
current_message += event.text.unicode;
}
} else if( ( event.type == sf::Event::KeyPressed ) && connected && !chatting ) {
Expand Down
6 changes: 3 additions & 3 deletions examples/TestServer.cpp
Expand Up @@ -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<sf::Uint8>( dist( gen ) ), static_cast<sf::Uint8>( dist( gen ) ), static_cast<sf::Uint8>( dist( gen ) ), 255 } },
m_link{ player_link }
{
}
Expand Down Expand Up @@ -319,14 +319,14 @@ class Player : public sfn::SyncedObject {
bool m_firing{ false };

static std::mt19937 gen;
static std::uniform_int_distribution<sf::Uint8> dist;
static std::uniform_int_distribution<sf::Uint16> dist;
static std::uniform_real_distribution<float> position_dist;
};

const Player::object_type_id_type Player::type_id = 0x1337;

std::mt19937 Player::gen{};
std::uniform_int_distribution<sf::Uint8> Player::dist{ 100, 255 };
std::uniform_int_distribution<sf::Uint16> Player::dist{ 100, 255 };
std::uniform_real_distribution<float> Player::position_dist{ -180.f, 180.f };

namespace sfn {
Expand Down

0 comments on commit 812c183

Please sign in to comment.