Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for when we only have one message type #102

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions yojimbo.h
Expand Up @@ -870,11 +870,7 @@ namespace yojimbo

inline int bits_required( uint32_t min, uint32_t max )
{
#ifdef __GNUC__
return 32 - __builtin_clz( max - min );
#else // #ifdef __GNUC__
return ( min == max ) ? 0 : log2( max - min ) + 1;
#endif // #ifdef __GNUC__
}

/**
Expand Down Expand Up @@ -2098,7 +2094,7 @@ namespace yojimbo

bool SerializeInteger( int32_t value, int32_t min, int32_t max )
{
yojimbo_assert( min < max );
yojimbo_assert( min <= max );
yojimbo_assert( value >= min );
yojimbo_assert( value <= max );
const int bits = bits_required( min, max );
Expand Down Expand Up @@ -2258,7 +2254,7 @@ namespace yojimbo

bool SerializeInteger( int32_t & value, int32_t min, int32_t max )
{
yojimbo_assert( min < max );
yojimbo_assert( min <= max );
const int bits = bits_required( min, max );
if ( m_reader.WouldReadPastEnd( bits ) )
return false;
Expand Down Expand Up @@ -2410,7 +2406,7 @@ namespace yojimbo
bool SerializeInteger( int32_t value, int32_t min, int32_t max )
{
(void) value;
yojimbo_assert( min < max );
yojimbo_assert( min <= max );
yojimbo_assert( value >= min );
yojimbo_assert( value <= max );
const int bits = bits_required( min, max );
Expand Down Expand Up @@ -2753,7 +2749,7 @@ namespace yojimbo
#define serialize_int( stream, value, min, max ) \
do \
{ \
yojimbo_assert( min < max ); \
yojimbo_assert( min <= max ); \
int32_t int32_value = 0; \
if ( Stream::IsWriting ) \
{ \
Expand Down Expand Up @@ -3342,7 +3338,7 @@ namespace yojimbo
#define read_int( stream, value, min, max ) \
do \
{ \
yojimbo_assert( min < max ); \
yojimbo_assert( min <= max ); \
int32_t int32_value = 0; \
if ( !stream.SerializeInteger( int32_value, min, max ) ) \
{ \
Expand Down Expand Up @@ -3388,7 +3384,7 @@ namespace yojimbo
#define write_int( stream, value, min, max ) \
do \
{ \
yojimbo_assert( min < max ); \
yojimbo_assert( min <= max ); \
yojimbo_assert( value >= min ); \
yojimbo_assert( value <= max ); \
int32_t int32_value = (int32_t) value; \
Expand Down