X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_gen.h;h=49ea4953480bb8b3455c3a2ce1dc2ce70cf833ce;hb=5ecf9cca8b5b9bf876d7e7c7fde03d5b187bb42b;hp=74907c62fc87c29e029e0798c82558d133abedfa;hpb=86dbcd5796ed674ca9433cce1ace8bef322cd121;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_gen.h b/world_gen.h index 74907c6..49ea495 100644 --- a/world_gen.h +++ b/world_gen.h @@ -1,8 +1,16 @@ +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + #ifndef WORLD_GEN_H #define WORLD_GEN_H -#include "world.h" +/* + * FUTURE: + * If we have multiple levels, write an unloader + */ +#include "world.h" static void world_add_all_if_material( m4x3f transform, scene *pscene, mdl_header *mdl, u32 id ) @@ -86,12 +94,14 @@ static void world_apply_procedural_foliage(void) } } } - free( mfoliage ); + + vg_free( mfoliage ); } static void world_load(void) { mdl_header *mworld = mdl_load( "models/mp_dev.mdl" ); + vg_info( "Loading world: models/mp_dev.mdl\n" ); world.spawn_count = 0; world.traffic_count = 0; @@ -127,10 +137,13 @@ static void world_load(void) if( sm ) { - glmesh surf; - mdl_unpack_submesh( mworld, &surf, sm ); - world_water_init(); - water_set_surface( &surf, pnode->co[1] ); + vg_acquire_thread_sync(); + { + glmesh surf; + mdl_unpack_submesh( mworld, &surf, sm ); + water_set_surface( &surf, pnode->co[1] ); + } + vg_release_thread_sync(); } } else if( pnode->classtype == k_classtype_car_path ) @@ -261,7 +274,10 @@ static void world_load(void) world_add_all_if_material( midentity, &world.geo,mworld,mat_vertex_blend); scene_copy_slice( &world.geo, &world.sm_geo_vb ); + vg_acquire_thread_sync(); scene_upload( &world.geo ); + vg_release_thread_sync(); + scene_bh_create( &world.geo ); @@ -279,76 +295,78 @@ static void world_load(void) world_add_all_if_material( midentity, &world.foliage, mworld, mat_graffiti ); scene_copy_slice( &world.foliage, &world.sm_graffiti ); - scene_upload( &world.foliage ); - world_routes_loadfrom( mworld ); - - for( int i=0; ig_water_plane ); + + v4f bounds; + bounds[0] = world.geo.bbx[0][0]; + bounds[1] = world.geo.bbx[0][2]; + bounds[2] = 1.0f/ (world.geo.bbx[1][0]-world.geo.bbx[0][0]); + bounds[3] = 1.0f/ (world.geo.bbx[1][2]-world.geo.bbx[0][2]); + v4_copy( bounds, winfo->g_depth_bounds ); + + winfo->g_water_fog = 0.04f; + render_update_lighting_ub(); + } - /* - * Rendering the depth map - */ - m4x4f ortho; - m4x3f camera; - - v3f extent; - v3_sub( world.geo.bbx[1], world.geo.bbx[0], extent ); - - float fl = world.geo.bbx[0][0], - fr = world.geo.bbx[1][0], - fb = world.geo.bbx[0][2], - ft = world.geo.bbx[1][2], - rl = 1.0f / (fr-fl), - tb = 1.0f / (ft-fb); - - m4x4_zero( ortho ); - ortho[0][0] = 2.0f * rl; - ortho[2][1] = 2.0f * tb; - ortho[3][0] = (fr + fl) * -rl; - ortho[3][1] = (ft + fb) * -tb; - ortho[3][3] = 1.0f; - m4x3_identity( camera ); - - glViewport( 0, 0, 1024, 1024 ); - glDisable(GL_DEPTH_TEST); - glBindFramebuffer( GL_FRAMEBUFFER, gpipeline.fb_depthmap ); - shader_fscolour_use(); - shader_fscolour_uColour( (v4f){-9999.0f,-9999.0f,-9999.0f,-9999.0f} ); - render_fsquad(); - - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - glBlendEquation(GL_MAX); - render_world_depth( ortho, camera ); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); + vg_release_thread_sync(); - /* - * TODO: World settings entity - */ - struct ub_world_lighting *winfo = &gpipeline.ub_world_lighting; - v4_copy( wrender.plane, winfo->g_water_plane ); - - v4f bounds; - bounds[0] = world.geo.bbx[0][0]; - bounds[1] = world.geo.bbx[0][2]; - bounds[2] = 1.0f/ (world.geo.bbx[1][0]-world.geo.bbx[0][0]); - bounds[3] = 1.0f/ (world.geo.bbx[1][2]-world.geo.bbx[0][2]); - v4_copy( bounds, winfo->g_depth_bounds ); - - winfo->g_water_fog = 0.04f; - render_update_lighting_ub(); - + world_routes_loadfrom( mworld ); - world.mr_ball.type = k_rb_shape_sphere; - world.mr_ball.inf.sphere.radius = 2.0f; - v3_copy( (v3f){ 0.0f, 110.0f, 0.0f }, world.mr_ball.co ); + for( int i=0; i