medfall

A super great game engine
Log | Files | Refs

commit 9380c5e9779ddf47bdb2de06a53658702f1da846
parent 904de8a998a57bec60569c5462ff31c51f490812
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Jul  2 18:27:10 +0300

array.try_get

Diffstat:
array.h | 18++++++++++++++++++
pp.cc | 7+------
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/array.h b/array.h @@ -136,6 +136,12 @@ public: return x < w && y < h; } + T try_get( size_t x, size_t y, T def ) const { + if( !in_range( x, y ) ) + return def; + return elems[ y * w + x ]; + } + T * ptr() { return elems; } @@ -202,6 +208,12 @@ public: return i < N; } + T try_get( size_t i, T def ) const { + if( !in_range( i ) ) + return def; + return elems[ i ]; + } + T * ptr() { return elems; } @@ -320,6 +332,12 @@ public: return i < n; } + T try_get( size_t i, T def ) const { + if( !in_range( i ) ) + return def; + return elems[ i ]; + } + T * ptr() { return elems; } diff --git a/pp.cc b/pp.cc @@ -236,12 +236,7 @@ static void write_quadtree( int global_x = left + local_x; int global_y = top + local_y; - if( heightmap.in_range( global_x, global_y ) ) { - tile_heightmap( local_x, local_y ) = heightmap( global_x, global_y ); - } - else { - tile_heightmap( local_x, local_y ) = 0; - } + tile_heightmap( local_x, local_y ) = heightmap.try_get( global_x, global_y, 0 ); } }