commit 704e0d934ced7a39f4e8f23f20654fa48a6174c5
parent 4c0e3666cae59eab0f982550338f6a19e785a9eb
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sun, 19 Nov 2017 15:41:19 +0200
Add a few named constants to help clean things up a bit
Diffstat:
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/clipmap.cc b/clipmap.cc
@@ -72,8 +72,10 @@ static VB trees_instance_data;
static u32 num_trees;
static Mesh tree_mesh;
-// PATCH_RESOLUTION is the number of squares per dimension, PATCH_RESOLUTION + 1 is the number of verts per dimension
static constexpr u32 PATCH_RESOLUTION = 48;
+static constexpr u32 PATCH_VERT_RESOLUTION = PATCH_RESOLUTION + 1;
+static constexpr u32 CLIPMAP_RESOLUTION = PATCH_RESOLUTION * 4 + 1;
+static constexpr u32 CLIPMAP_VERT_RESOLUTION = CLIPMAP_RESOLUTION + 1;
static constexpr u32 NUM_LODS = 7;
static void load_trees( MemoryArena * arena ) {
@@ -103,7 +105,7 @@ static void load_trees( MemoryArena * arena ) {
}
static size_t patch2d( size_t x, size_t y ) {
- return y * ( PATCH_RESOLUTION + 1 ) + x;
+ return y * PATCH_VERT_RESOLUTION + x;
}
static void file_get_contents_and_decompress( const char * path, u8 * decompressed, size_t decompressed_size ) {
@@ -196,11 +198,11 @@ GAME_INIT( game_init ) {
{
MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
- array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION + 1 ) * ( PATCH_RESOLUTION + 1 ) );
+ array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, PATCH_VERT_RESOLUTION * PATCH_VERT_RESOLUTION );
size_t n = 0;
- for( u32 y = 0; y < PATCH_RESOLUTION + 1; y++ ) {
- for( u32 x = 0; x < PATCH_RESOLUTION + 1; x++ ) {
+ for( u32 y = 0; y < PATCH_VERT_RESOLUTION; y++ ) {
+ for( u32 x = 0; x < PATCH_VERT_RESOLUTION; x++ ) {
vertices[ n++ ] = v3( x, y, 0 );
}
}
@@ -265,10 +267,10 @@ GAME_INIT( game_init ) {
{
MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
- array< v3 > horizontal_vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION + 1 ) * 2 );
- array< v3 > vertical_vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION + 1 ) * 2 );
+ array< v3 > horizontal_vertices = alloc_array< v3 >( &mem->persistent_arena, PATCH_VERT_RESOLUTION * 2 );
+ array< v3 > vertical_vertices = alloc_array< v3 >( &mem->persistent_arena, PATCH_VERT_RESOLUTION * 2 );
- for( u32 i = 0; i < PATCH_RESOLUTION + 1; i++ ) {
+ for( u32 i = 0; i < PATCH_VERT_RESOLUTION; i++ ) {
horizontal_vertices[ i * 2 + 0 ] = v3( i, 0, 0 );
horizontal_vertices[ i * 2 + 1 ] = v3( i, 1, 0 );
@@ -317,28 +319,28 @@ GAME_INIT( game_init ) {
{
MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
- array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION * 4 + 2 ) * 4 );
+ array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION * 4 + 2 ) * 4 - 2 );
size_t n = 0;
- for( u32 i = 0; i < PATCH_RESOLUTION * 4 + 2; i++ ) {
+ for( u32 i = 0; i < CLIPMAP_VERT_RESOLUTION; i++ ) {
vertices[ n++ ] = v3( 0, PATCH_RESOLUTION * 4 + 1 - i, 0 );
vertices[ n++ ] = v3( 1, PATCH_RESOLUTION * 4 + 1 - i, 0 );
}
size_t start_of_second_set = n;
- for( u32 i = 0; i < PATCH_RESOLUTION * 4 + 2; i++ ) {
+ for( u32 i = 0; i < CLIPMAP_VERT_RESOLUTION - 1; i++ ) {
vertices[ n++ ] = v3( i + 1, 0, 0 );
vertices[ n++ ] = v3( i + 1, 1, 0 );
}
for( v3 & v : vertices ) {
- v -= v3( 0.5f * v2( PATCH_RESOLUTION * 4.0f + 3.0f ), 0 );
+ v -= v3( 0.5f * v2( CLIPMAP_VERT_RESOLUTION + 1 ), 0 );
}
- array< u32 > indices = alloc_array< u32 >( &mem->persistent_arena, ( PATCH_RESOLUTION * 8 + 3 ) * 6 );
+ array< u32 > indices = alloc_array< u32 >( &mem->persistent_arena, ( CLIPMAP_VERT_RESOLUTION * 2 - 1 ) * 6 );
n = 0;
- for( u32 i = 0; i < PATCH_RESOLUTION * 4 + 2; i++ ) {
+ for( u32 i = 0; i < CLIPMAP_VERT_RESOLUTION; i++ ) {
indices[ n++ ] = ( i + 0 ) * 2 + 1;
indices[ n++ ] = ( i + 0 ) * 2 + 0;
indices[ n++ ] = ( i + 1 ) * 2 + 0;
@@ -348,7 +350,7 @@ GAME_INIT( game_init ) {
indices[ n++ ] = ( i + 1 ) * 2 + 0;
}
- for( u32 i = 0; i < PATCH_RESOLUTION * 4 + 1; i++ ) {
+ for( u32 i = 0; i < CLIPMAP_VERT_RESOLUTION - 1; i++ ) {
indices[ n++ ] = start_of_second_set + ( i + 0 ) * 2 + 1;
indices[ n++ ] = start_of_second_set + ( i + 0 ) * 2 + 0;
indices[ n++ ] = start_of_second_set + ( i + 1 ) * 2 + 0;
@@ -371,7 +373,7 @@ GAME_INIT( game_init ) {
v2 base = -v2( checked_cast< float >( PATCH_RESOLUTION << NUM_LODS ) );
v2 clipmap_tl = base;
- v2 clipmap_br = clipmap_tl + v2( ( 4.0f * PATCH_RESOLUTION + 1.0f ) * scale );
+ v2 clipmap_br = clipmap_tl + v2( CLIPMAP_RESOLUTION * scale );
StaticArray< v3, 8 > vertices;
float big = 10000000.0;