medfall

A super great game engine
Log | Files | Refs

commit 5e4efedc0a68600f7cdb2b3e4025ac933d853e27
parent e878ae9c8dbe6ab0ba45c2c44cbc18d272991ead
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat,  4 Nov 2017 15:40:15 +0200

Don't use DynamicArray when generating the clipmap tile mesh

Diffstat:
clipmap.cc | 46+++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -113,31 +113,43 @@ GAME_INIT( game_init ) { } } + // generate tile mesh { - DynamicArray< v3 > vertices; - for( u32 y = 0; y < PATCH_RESOLUTION + 1; y++ ) { - for( u32 x = 0; x < PATCH_RESOLUTION + 1; x++ ) { - vertices.append( v3( x, y, 0 ) ); + MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena ); + + array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, ( PATCH_RESOLUTION + 1 ) * ( PATCH_RESOLUTION + 1 ) ); + { + size_t i = 0; + for( u32 y = 0; y < PATCH_RESOLUTION + 1; y++ ) { + for( u32 x = 0; x < PATCH_RESOLUTION + 1; x++ ) { + vertices[ i ] = v3( x, y, 0 ); + i++; + } } } - DynamicArray< u32 > indices; - for( u32 y = 0; y < PATCH_RESOLUTION; y++ ) { - for( u32 x = 0; x < PATCH_RESOLUTION; x++ ) { - indices.append( patch2d( x, y ) ); - indices.append( patch2d( x + 1, y + 1 ) ); - indices.append( patch2d( x, y + 1 ) ); - - indices.append( patch2d( x, y ) ); - indices.append( patch2d( x + 1, y ) ); - indices.append( patch2d( x + 1, y + 1 ) ); + array< u32 > indices = alloc_array< u32 >( &mem->persistent_arena, PATCH_RESOLUTION * PATCH_RESOLUTION * 6 ); + { + size_t i = 0; + for( u32 y = 0; y < PATCH_RESOLUTION; y++ ) { + for( u32 x = 0; x < PATCH_RESOLUTION; x++ ) { + indices[ i + 0 ] = patch2d( x, y ); + indices[ i + 1 ] = patch2d( x + 1, y + 1 ); + indices[ i + 2 ] = patch2d( x, y + 1 ); + + indices[ i + 3 ] = patch2d( x, y ); + indices[ i + 4 ] = patch2d( x + 1, y ); + indices[ i + 5 ] = patch2d( x + 1, y + 1 ); + + i += 6; + } } } MeshConfig mesh_config; - mesh_config.positions = renderer_new_vb( vertices.ptr(), vertices.num_bytes() ); - mesh_config.indices = renderer_new_ib( indices.ptr(), indices.num_bytes() ); - mesh_config.num_vertices = indices.size(); + mesh_config.positions = renderer_new_vb( vertices ); + mesh_config.indices = renderer_new_ib( indices ); + mesh_config.num_vertices = indices.n; clipmap.tile = renderer_new_mesh( mesh_config ); }