- world_routes_register();
- world_sfd_register();
-}
-
-static void world_free(void)
-{
- /* TODO.. */
-
- world_sfd_free();
-}
-
-static void render_world_depth( m4x4f projection, m4x3f camera );
-
-static void add_all_if_material( m4x3f transform, scene *pscene,
- mdl_header *mdl, u32 id )
-{
- for( int i=0; i<mdl->node_count; i++ )
- {
- mdl_node *pnode = mdl_node_from_id( mdl, i );
-
- for( int j=0; j<pnode->submesh_count; j++ )
- {
- mdl_submesh *sm = mdl_node_submesh( mdl, pnode, j );
-
- if( sm->material_id == id )
- {
- m4x3f transform2;
- mdl_node_transform( pnode, transform2 );
- m4x3_mul( transform, transform2, transform2 );
-
- scene_add_submesh( pscene, mdl, sm, transform2 );
- }
- }
-
- if( pnode->classtype == k_classtype_instance )
- {
- if( pnode->sub_uid )
- {
- u32 instance_id = pnode->sub_uid -1;
- struct instance_cache *cache = &world.instance_cache[instance_id];
- mdl_header *mdl2 = cache->mdl;
-
- m4x3f transform2;
- mdl_node_transform( pnode, transform2 );
- m4x3_mul( transform, transform2, transform2 );
-
- add_all_if_material( transform2, pscene, mdl2, id );
- }
- }
- }
-}
-
-static void world_apply_procedural_foliage(void)
-{
- mdl_header *mfoliage = mdl_load("models/rs_foliage.mdl");
-
- v3f volume;
- v3_sub( world.geo.bbx[1], world.geo.bbx[0], volume );
- volume[1] = 1.0f;
-
- m4x3f transform;
- mdl_node *mblob = mdl_node_from_name( mfoliage, "blob" );
- mdl_submesh *sm_blob = mdl_node_submesh( mfoliage, mblob, 0 );
-
- for( int i=0;i<100000;i++ )
- {
- v3f pos;
- v3_mul( volume, (v3f){ vg_randf(), 1000.0f, vg_randf() }, pos );
- pos[1] = 1000.0f;
- v3_add( pos, world.geo.bbx[0], pos );
-
- ray_hit hit;
- hit.dist = INFINITY;
-
- if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit ))
- {
- if( (hit.normal[1] > 0.8f) && ray_hit_is_terrain(&hit) &&
- (hit.pos[1] > water_height()+10.0f) )
- {
- v4f qsurface, qrandom;
- v3f axis;
-
- v3_cross( (v3f){0.0f,1.0f,0.0f}, hit.normal, axis );
-
- float angle = v3_dot(hit.normal,(v3f){0.0f,1.0f,0.0f});
- q_axis_angle( qsurface, axis, angle );
- q_axis_angle( qrandom, (v3f){0.0f,1.0f,0.0f}, vg_randf()*VG_TAUf );
- q_mul( qsurface, qrandom, qsurface );
- q_m3x3( qsurface, transform );
-
- v3_copy( hit.pos, transform[3] );
- scene_add_submesh( &world.foliage, mfoliage, sm_blob, transform);
- }
- }
- }
- free( mfoliage );
-}
-
-static void world_load(void)
-{
- mdl_header *mworld = mdl_load( "models/mp_dev.mdl" );
-
- world.spawn_count = 0;
- world.traffic_count = 0;
- world.instance_cache = NULL;
-
- /*
- * Process entities
- */
- for( int i=0; i<mworld->node_count; i++ )
- {
- mdl_node *pnode = mdl_node_from_id( mworld, i );
-
- if( pnode->classtype == k_classtype_none )
- {}
- else if( pnode->classtype == k_classtype_spawn )
- {
- struct respawn_point *rp = &world.spawns[ world.spawn_count ++ ];
-
- v3_copy( pnode->co, rp->co );
- v4_copy( pnode->q, rp->q );
- strcpy( rp->name, mdl_pstr( mworld, pnode->pstr_name ) );
- }
- else if( pnode->classtype == k_classtype_water )
- {
- if( wrender.enabled )
- {
- vg_warn( "Multiple water surfaces in level! ('%s')\n",
- mdl_pstr( mworld, pnode->pstr_name ));
- continue;
- }
-
- mdl_submesh *sm = mdl_node_submesh( mworld, pnode, 0 );
-
- if( sm )
- {
- glmesh surf;
- mdl_unpack_submesh( mworld, &surf, sm );
- water_init();
- water_set_surface( &surf, pnode->co[1] );
- }
- }
- else if( pnode->classtype == k_classtype_car_path )
- {
- struct classtype_car_path *p = mdl_get_entdata( mworld, pnode );
- traffic_node *tn = &world.traffic[ world.traffic_count ];
- tn->mn_next = NULL;
- tn->mn_next1 = NULL;
-
- if( p->target ) tn->mn_next = mdl_node_from_id( mworld, p->target );
- if( p->target1 ) tn->mn_next1 = mdl_node_from_id( mworld, p->target1 );
-
- m4x3f transform;
- mdl_node_transform( pnode, transform );
- m3x3_mulv( transform, (v3f){1.0f,0.0f,0.0f}, tn->h );
- v3_copy( transform[3], tn->co );
-
- pnode->sub_uid = world.traffic_count ++;
- }
- else if( pnode->classtype == k_classtype_instance )
- {
- struct classtype_instance *inst = mdl_get_entdata( mworld, pnode );
- pnode->sub_uid = 0;
-
- int cached = 0;
- for( int i=0; i<world.instance_cache_count; i++ )
- {
- struct instance_cache *cache = &world.instance_cache[i];
- if( inst->pstr_file == cache->pstr_file )
- {
- cached = 1;
- pnode->sub_uid = i+1;
- break;
- }
- }
-
- if( !cached )
- {
- world.instance_cache = buffer_reserve(
- world.instance_cache, world.instance_cache_count,
- &world.instance_cache_cap, 1,
- sizeof(struct instance_cache) );
-
- struct instance_cache *cache =
- &world.instance_cache[world.instance_cache_count];
-
- const char *filename = mdl_pstr(mworld, inst->pstr_file);
-
- cache->pstr_file = inst->pstr_file;
- cache->mdl = mdl_load( filename );
-
- if( cache->mdl )
- {
- world.instance_cache_count ++;
- pnode->sub_uid = world.instance_cache_count;
- mdl_link_materials( mworld, cache->mdl );
- vg_success( "Cached %s\n", filename );
- }
- else
- {
- vg_warn( "Failed to cache %s\n", filename );
- }
- }
- }
- }
-
- world.instance_cache = buffer_fix( world.instance_cache,
- world.instance_cache_count,
- &world.instance_cache_cap,
- sizeof( struct instance_cache ) );
-
-#if 0
- traffic_finalize( world.traffic, world.traffic_count );
- for( int i=0; i<vg_list_size(world.van_man); i++ )
- world.van_man[i].current =&world.traffic[vg_randint(world.traffic_count)];
-#endif