medfall

A super great game engine
Log | Files | Refs

commit b93548485bcbf4444b0a33e19faa1b198e88ed4e
parent aba3cc54644cb6cff2aeab2c5a300414905f1ea9
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 11 Feb 2018 22:12:40 +0200

Small cleanup

Diffstat:
clipmap.cc | 9+--------
intrinsics.h | 7+++++++
mixer.cc | 4++--
mpsc.h | 4++--
pool.h | 11++++++++++-
5 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -120,13 +120,6 @@ struct RGBA { u8 r, g, b, a; }; -template< typename T > -void swap( T & a, T & b ) { - T t = a; - a = b; - b = t; -} - GAME_INIT( game_init ) { net_init(); @@ -1079,7 +1072,7 @@ GAME_FRAME( game_frame ) { last_connection_attempt = current_time; } - for( const Player & player : players.elems ) { + for( const Player & player : players ) { if( player.sid != sid ) { v3 mins = player.pos - v3( 0.4f, 0.4f, 0.0f ); v3 maxs = player.pos + v3( 0.4f, 0.4f, EYE_HEIGHT + 0.1f ); diff --git a/intrinsics.h b/intrinsics.h @@ -88,6 +88,13 @@ char ( &ArrayCountObj( const T ( & )[ N ] ) )[ N ]; #define gigabytes( gb ) ( megabytes( gb ) * size_t( 1024 ) ) template< typename T > +void swap( T & a, T & b ) { + T t = a; + a = b; + b = t; +} + +template< typename T > constexpr T min( T a, T b ) { return a < b ? a : b; } diff --git a/mixer.cc b/mixer.cc @@ -39,7 +39,7 @@ static PlayingSoundID sound_counter; // TODO: this should really use a hash index/pool with handles static PlayingSound * find_playing_sound( PlayingSoundID sound_id ) { - for( PlayingSound & ps : playing_sounds.elems ) { + for( PlayingSound & ps : playing_sounds ) { if( ps.id == sound_id ) { return &ps; } @@ -124,7 +124,7 @@ AUDIO_OUTPUT_CALLBACK( mixer_mix ) { samples[ i ] = 0.0f; } - for( PlayingSound & ps : playing_sounds.elems ) { + for( PlayingSound & ps : playing_sounds ) { mixer_mix_sound( &ps, samples, num_output_samples ); } diff --git a/mpsc.h b/mpsc.h @@ -67,8 +67,8 @@ public: } private: - enum { EMPTY_BIT = 1 << 31 }; - enum { COUNTER_MASK = ~EMPTY_BIT }; + enum : u32 { EMPTY_BIT = 1 << 31 }; + enum : u32 { COUNTER_MASK = ~EMPTY_BIT }; struct ALIGNTO_CACHE Node { NONATOMIC( T ) data; diff --git a/pool.h b/pool.h @@ -10,7 +10,8 @@ struct Pool { } T * acquire() { - if( elems.n == N ) return NULL; + if( elems.n == N ) + return NULL; elems.n++; return &elems[ elems.n - 1 ]; @@ -27,6 +28,14 @@ struct Pool { elems.n = 0; } + T * begin() { + return elems.begin(); + } + + T * end() { + return elems.end(); + } + T memory[ N ]; array< T > elems; };