medfall

A super great game engine
Log | Files | Refs

commit 5db3a20a4396d2dd2cefcc55f20c799d4363778d
parent a8e05a0ee6d4918ab40b2e326f1471c182ffc040
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat, 11 Nov 2017 21:18:27 +0200

Fix trees being placed too low. Fix trees using the original terrain instead of BC5 terrain

Diffstat:
pp.cc | 27++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/pp.cc b/pp.cc @@ -215,7 +215,7 @@ static bool ok_tree_position( RNGWell512 * rng, const array2d< u16 > heightmap, if( !rng_p( rng, p ) ) return false; - *tree = v3( pos.x * heightmap.w, pos.y * heightmap.h, height / 256 ); + *tree = v3( pos.x * heightmap.w, pos.y * heightmap.h, height / 256.0f ); return true; } @@ -273,12 +273,13 @@ int main( int argc, char ** argv ) { ASSERT( png != NULL ); array2d< u16 > heightmap( png, w, h ); - u8 * bc5_heightmap; + array2d< u16 > bc5_heightmap = alloc_array2d< u16 >( &arena, heightmap.w, heightmap.h ); mkdir( "terrains", 0755 ); mkdir( output_path.c_str(), 0755 ); { + MEMARENA_SCOPED_CHECKPOINT( &arena ); printf( "computing heightmaps\n" ); array2d< RGBA > heightmap_split = alloc_array2d< RGBA >( &arena, w, h ); @@ -294,7 +295,9 @@ int main( int argc, char ** argv ) { printf( "compressing\n" ); DynamicString heightmap_path( "{}/heightmap.bc5.lz4", output_path ); - bc5_heightmap = write_compressed_texture( &arena, heightmap_path, heightmap_split, squish::kBc5 ); + u8 * bc5 = write_compressed_texture( &arena, heightmap_path, heightmap_split, squish::kBc5 ); + + bc5_to_heightmap( &arena, bc5_heightmap, bc5 ); } { @@ -322,7 +325,7 @@ int main( int argc, char ** argv ) { printf( "planting trees\n" ); array< v3 > trees = alloc_array< v3 >( &arena, MAX_TREES ); - size_t num_trees = place_trees( &arena, heightmap, normalmap_v3, trees ); + size_t num_trees = place_trees( &arena, bc5_heightmap, normalmap_v3, trees ); printf( "compressing\n" ); DynamicString trees_path( "{}/trees.lz4", output_path ); @@ -357,20 +360,18 @@ int main( int argc, char ** argv ) { MEMARENA_SCOPED_CHECKPOINT( &arena ); printf( "computing quadtree\n" ); - array2d< u16 > decoded = alloc_array2d< u16 >( &arena, heightmap.w, heightmap.h ); - bc5_to_heightmap( &arena, decoded, bc5_heightmap ); - - array2d< u16 > decoded1 = alloc_array2d< u16 >( &arena, heightmap.w + 1, heightmap.h + 1 ); - for( size_t y = 0; y < decoded1.h; y++ ) { - for( size_t x = 0; x < decoded1.w; x++ ) { - decoded1( x, y ) = decoded.try_get( x, y, 0 ); + // quadtree needs POT+1 heightmap, so pad with zeroes + array2d< u16 > heightmap1 = alloc_array2d< u16 >( &arena, heightmap.w + 1, heightmap.h + 1 ); + for( size_t y = 0; y < heightmap1.h; y++ ) { + for( size_t x = 0; x < heightmap1.w; x++ ) { + heightmap1( x, y ) = bc5_heightmap.try_get( x, y, 0 ); } } - size_t num_nodes = quadtree_max_nodes( decoded1.w, decoded1.h ); + size_t num_nodes = quadtree_max_nodes( heightmap1.w, heightmap1.h ); array< QuadTreeNode > nodes = alloc_array< QuadTreeNode >( &arena, num_nodes ); - build_quadtree( decoded1, nodes ); + build_quadtree( heightmap1, nodes ); printf( "compressing\n" ); DynamicString quadtree_path( "{}/quadtree.lz4", output_path );