commit 36ce342010f84c48a0296b1a03425cdffb09ec35 parent 33ac52434e1103f1828017e329f4e948a09505ce Author: Michael Savage <mikejsavage@gmail.com> Date: Tue May 23 00:08:59 +0300 Really compress teres.lz4 Diffstat:
hm.cc | | | 21 | +++++++++++++++------ |
pp.cc | | | 2 | +- |
diff --git a/hm.cc b/hm.cc @@ -17,6 +17,8 @@ #include "platform_io.h" #include "platform_network.h" +#include "lz4.h" + static Socket sock; static u64 sid; static double last_connection_attempt = -5.0; // TODO @@ -33,20 +35,27 @@ static Mesh tree_mesh; static void load_trees( MemoryArena * arena ) { MEMARENA_SCOPED_CHECKPOINT( arena ); - array< v3 > trees = file_get_array< v3 >( "terrains/gta.png.parts/trees.lz4" ); - array< m4 > tree_matrices = memarena_push_array( arena, m4, trees.n ); + size_t compressed_len; + u8 * compressed_trees = file_get_contents( "terrains/gta.png.parts/trees.lz4", &compressed_len ); + + // TODO: don't hardcode this! + array< v3 > trees = memarena_push_array( arena, v3, 300000 ); + int decompressed_len = LZ4_decompress_safe( ( char * ) compressed_trees, ( char * ) trees.ptr(), compressed_len, trees.num_bytes() ); + ASSERT( decompressed_len > 0 ); + + free( compressed_trees ); + + num_trees = decompressed_len / sizeof( v3 ); + array< m4 > tree_matrices = memarena_push_array( arena, m4, num_trees ); m4 rot = m4_rotx( deg_to_rad( 90 ) ); - for( size_t i = 0; i < trees.n; i++ ) { + for( size_t i = 0; i < num_trees; i++ ) { tree_matrices[ i ] = m4_translation( trees[ i ] ) * rot; } instance_data = renderer_new_vb( tree_matrices ); - free( trees.ptr() ); - tree_mesh = load_obj( "models/trees/PineTree.obj", arena ); - num_trees = trees.n; } extern "C" GAME_INIT( game_init ) { diff --git a/pp.cc b/pp.cc @@ -332,7 +332,7 @@ int main( int argc, char ** argv ) { size_t num_trees = place_trees( &arena, heightmap, normals, trees ); printf( "writing trees\n" ); - write_file( trees_memory, num_trees * sizeof( v3 ), "{}/trees.lz4", dir.c_str() ); + write_compressed_file( &arena, trees_memory, num_trees * sizeof( v3 ), "{}/trees.lz4", dir.c_str() ); } }