nonlocal stuff again
authorhgn <hgodden00@gmail.com>
Sat, 15 Apr 2023 04:17:10 +0000 (05:17 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 15 Apr 2023 04:17:10 +0000 (05:17 +0100)
12 files changed:
blender_export.py
entity.h
maps_src/mp_mtzero.mdl
maps_src/mp_spawn.mdl [new file with mode: 0644]
player.c
player_skate.c
skaterift.c
world.h
world_gate.h
world_gen.h
world_render.h
world_routes.h

index eed99af0d9293536fa9e43335a686fe090564069..c8639711a06a352c4a852945ea929c22e693aecd 100644 (file)
@@ -1290,13 +1290,21 @@ def sr_compile( collection ):
          #}
          elif ent_type == 'ent_gate': #{
             gate = ent_gate()
-            gate.type = 0
             obj_data = obj.SR_data.ent_gate[0]
             mesh_data = obj.data.SR_data.ent_gate[0]
-            if obj_data.target:#{
-               gate.target = sr_compile.entity_ids[obj_data.target.name]
-               gate.type = 1
+
+            if obj_data.tipo == 'default':#{
+               if obj_data.target:#{
+                  gate.target = sr_compile.entity_ids[obj_data.target.name]
+                  gate.type = 1
+               #}
+            #}
+            elif obj_data.tipo == 'nonlocal':#{
+               gate.target = sr_compile_string(obj_data.key)
+               gate.type = 2
             #}
+            else: gate.type = 0
+            
             gate.dimensions[0] = mesh_data.dimensions[0]
             gate.dimensions[1] = mesh_data.dimensions[1]
             gate.dimensions[2] = mesh_data.dimensions[2]
@@ -1926,6 +1934,20 @@ class SR_OBJECT_ENT_GATE(bpy.types.PropertyGroup):
    target: bpy.props.PointerProperty( \
                type=bpy.types.Object, name="destination", \
                poll=lambda self,obj: sr_filter_ent_type(obj,['ent_gate']))
+
+   key: bpy.props.StringProperty()
+   tipo: bpy.props.EnumProperty(items=(('default', 'Default', ""),
+                                       ('nonlocal', 'Non-Local', ""),))
+
+   @staticmethod
+   def sr_inspector( layout, data ):
+   #{
+      box = layout.box()
+      box.prop( data[0], 'tipo', text="subtype" )
+
+      if   data[0].tipo == 'default':  box.prop( data[0], 'target' )
+      elif data[0].tipo == 'nonlocal': box.prop( data[0], 'key' )
+   #}
 #}
 
 class SR_MESH_ENT_GATE(bpy.types.PropertyGroup):
index 143ad0da8428d3e49d9525ef2a30bcf8db613ae7..9bfd04aab3cb7da7328cc0e86c5f4591f3574a02 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -69,15 +69,14 @@ struct ent_light{
 enum gate_type{
    k_gate_type_unlinked = 0,
    k_gate_type_teleport = 1,
-   k_gate_type_nonlocal = 2
+   k_gate_type_nonlocal_unlinked = 2,
+   k_gate_type_nonlocel = 3
 };
 
 struct ent_gate{
    u32 type,
        target;
 
-   /* TODO: World index */
-
    v3f dimensions,
        co[2];
 
index 4eb90fc07f37f99a2e8694f9e3452809319d5e83..2b5bded00faae755df5dad593f8b9ce18bf79d31 100644 (file)
Binary files a/maps_src/mp_mtzero.mdl and b/maps_src/mp_mtzero.mdl differ
diff --git a/maps_src/mp_spawn.mdl b/maps_src/mp_spawn.mdl
new file mode 100644 (file)
index 0000000..0d6f093
Binary files /dev/null and b/maps_src/mp_spawn.mdl differ
index 48f696a163b9240d4e227ea495d609c18f222c60..b804ed14b23e71aadd9ac65d449d4332e5abaf47 100644 (file)
--- a/player.c
+++ b/player.c
@@ -352,7 +352,7 @@ void player__pass_gate( player_instance *player, ent_gate *gate )
    m4x3_mulv( gate->transport, player->cam.pos, player->cam.pos );
    player_save_rewind_frame( player );
 
-   if( gate->type == k_gate_type_nonlocal )
+   if( gate->type == k_gate_type_nonlocel )
       world_global.active_world = gate->target;
 
    world_global.in_volume = 0;
index f1670c827e3b77245d7abe521aff152094a976a7..e9a4f09f4b01cbaca4857b4b0e95c897f82218c4 100644 (file)
@@ -347,7 +347,7 @@ VG_STATIC int create_jumps_to_hit_target( player_instance *player,
 VG_STATIC 
 void player__approximate_best_trajectory( player_instance *player )
 {
-   world_instance *world = get_active_world();
+   world_instance *world0 = get_active_world();
 
    struct player_skate *s = &player->_skate;
    float k_trace_delta = k_rb_delta * 10.0f;
@@ -392,6 +392,7 @@ void player__approximate_best_trajectory( player_instance *player )
       v3_copy( player->rb.co, launch_co );
       v3_copy( player->rb.v,  launch_v );
       v3_copy( launch_co, co0 );
+      world_instance *trace_world = world0;
 
       float vt  = (float)m * (1.0f/30.0f),
             ang = vg_lerpf( angle_begin, angle_end, vt ) * 0.15f;
@@ -431,8 +432,7 @@ void player__approximate_best_trajectory( player_instance *player )
 
          v3f closest={0.0f,0.0f,0.0f};
          if( search_for_grind ){
-            if( bh_closest_point( world->geo_bh, co1, closest, 1.0f ) != -1 ){
-
+            if( bh_closest_point(trace_world->geo_bh,co1,closest,1.0f) != -1 ){
                float min_dist = 0.75f;
                      min_dist *= min_dist;
 
@@ -491,14 +491,18 @@ void player__approximate_best_trajectory( player_instance *player )
             }
          }
 
-         if( world->rendering_gate ){
-            ent_gate *gate = world->rendering_gate;
+         if( trace_world->rendering_gate ){
+            ent_gate *gate = trace_world->rendering_gate;
             if( gate_intersect( gate, co1, co0 ) ){
                m4x3_mulv( gate->transport, co0, co0 );
                m4x3_mulv( gate->transport, co1, co1 );
                m3x3_mulv( gate->transport, launch_v, launch_v);
                m4x3_mulv( gate->transport, launch_co, launch_co );
                m3x3_mul( gate->transport, basis, basis );
+
+               if( gate->type == k_gate_type_nonlocel ){
+                  trace_world = &world_global.worlds[ gate->target ];
+               }
             }
          }
 
@@ -508,15 +512,16 @@ void player__approximate_best_trajectory( player_instance *player )
          float scan_radius = k_board_radius;
                scan_radius *= vg_clampf( t, 0.02f, 1.0f );
 
-         int idx = spherecast_world( world, co0, co1, scan_radius, &t1, n );
+         int idx = spherecast_world(trace_world, co0, co1, scan_radius, &t1, n);
          if( idx != -1 ){
             v3f co;
             v3_lerp( co0, co1, t1, co );
             v3_copy( co, inf->log[ inf->log_length ++ ] ); 
 
             v3_copy( n, inf->n );
-            u32 *tri = &world->scene_geo->arrindices[ idx*3 ];
-            struct world_surface *surf = world_tri_index_surface(world, tri[0]);
+            u32 *tri = &trace_world->scene_geo->arrindices[ idx*3 ];
+            struct world_surface *surf = 
+               world_tri_index_surface( trace_world, tri[0] );
 
             inf->type = k_prediction_land;
 
@@ -591,7 +596,7 @@ void player__approximate_best_trajectory( player_instance *player )
             float t1;
             v3f n;
 
-            int idx = spherecast_world( world, co0,co1,
+            int idx = spherecast_world( world0, co0,co1,
                                         k_board_radius*0.1f, &t1, n);
             if( idx != -1 ){
                goto invalidated_grind;
index a01f67a37859aa60902dc506696832bc05930127..eb69bc7c18a1af50a71d3a9001044a3dcc9b8c3f 100644 (file)
@@ -166,7 +166,7 @@ VG_STATIC void vg_load(void)
    /* 'systems' are completely loaded now */
 
    /* load home world */
-   world_load( 0, "maps/mp_gridmap.mdl" );
+   world_load( 0, "maps/mp_spawn.mdl" );
    world_load( 1, "maps/mp_mtzero.mdl" );
 
 #if 0
diff --git a/world.h b/world.h
index c7485d17b4bf9fe7622811fdef8be3a8afa9be1a..809397151e854c64b4508ceaf139a8e0e1c40c88 100644 (file)
--- a/world.h
+++ b/world.h
@@ -62,6 +62,12 @@ struct world_instance {
 
    void *heap;
    char  world_name[ 64 ];
+   enum world_status{
+      k_world_status_unloaded = 0,
+      k_world_status_loading = 1,
+      k_world_status_loaded = 2
+   }
+   status;
 
    struct{
       boxf depthbounds;
index a073b26af051d6edcd08b7bc1e866a165ea4c882..989e918356a34e8f837d2af936e703be224c87b6 100644 (file)
@@ -231,7 +231,8 @@ VG_STATIC ent_gate *world_intersect_gates( world_instance *world,
 {
    for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
       ent_gate *gate = mdl_arritm( &world->ent_gate, i );
-      if( gate->type == k_gate_type_unlinked )
+      if( gate->type == k_gate_type_unlinked ||
+          gate->type == k_gate_type_nonlocal_unlinked )
          continue;
 
       if( gate_intersect( gate, pos, last ) ){
index 2371fa52af135755ac9e6ea54139eed6ab751cba..3f574987d3335f24af95443ca459ec414ed1d331 100644 (file)
@@ -597,6 +597,8 @@ VG_STATIC void world_free( world_instance *world )
    glDeleteTextures( world->texture_count, world->textures );
 
    vg_release_thread_sync();
+
+   world->status = k_world_status_unloaded;
 }
 
 VG_STATIC void world_init_blank( world_instance *world )
@@ -641,8 +643,10 @@ VG_STATIC void world_init_blank( world_instance *world )
    v3_copy( (v3f){1.10f, 0.89f, 0.35f}, state->g_sun_colour );
 }
 
-VG_STATIC void world_entities_init( world_instance *world )
+VG_STATIC void world_entities_init( u32 world_id )
 {
+   world_instance *world = &world_global.worlds[world_id];
+
    /* lights */
    for( u32 j=0; j<mdl_arrcount(&world->ent_light); j ++ ){
       ent_light *light = mdl_arritm( &world->ent_light, j );
@@ -659,7 +663,55 @@ VG_STATIC void world_entities_init( world_instance *world )
    /* gates */
    for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
       ent_gate *gate = mdl_arritm( &world->ent_gate, j );
-      gate_transform_update( gate );
+
+      if( gate->type == k_gate_type_teleport ){
+         gate_transform_update( gate );
+      }
+      else if( gate->type == k_gate_type_nonlocal_unlinked ){
+         const char *key = mdl_pstr( &world->meta, gate->target );
+         vg_info( "key: %s\n", key );
+
+         for( u32 i=0; i<vg_list_size(world_global.worlds); i++ ){
+            world_instance *other = &world_global.worlds[i];
+            if( other == world ) continue;
+            if( other->status != k_world_status_loaded ) continue;
+            vg_info( "Checking world %u for key matches\n", i );
+
+            for( u32 j=0; j<mdl_arrcount( &other->ent_gate ); j++ ){
+               ent_gate *gate2 = mdl_arritm( &other->ent_gate, j );
+               if( gate2->type != k_gate_type_nonlocal_unlinked ) continue;
+
+               const char *key2 = mdl_pstr( &other->meta, gate2->target );
+               vg_info( " key2: %s\n", key2 );
+
+               if( strcmp( key, key2 ) ) continue;
+
+               vg_success( "Non-local matching pair '%s' found. (%u:%u)\n",
+                            key, world_id, i );
+                  
+               gate->type = k_gate_type_nonlocel;
+               gate2->type = k_gate_type_nonlocel;
+               gate->target = i;
+               gate2->target = world_id;
+
+               v3_copy( gate->co[0], gate2->co[1] );
+               v3_copy( gate2->co[0], gate->co[1] );
+               v4_copy( gate->q[0], gate2->q[1] );
+               v4_copy( gate2->q[0], gate->q[1] );
+
+               v4f qflip;
+               q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
+               q_mul( gate->q[0], qflip, gate->q[0] );
+               q_mul( gate->q[1], qflip, gate->q[1] );
+
+               gate_transform_update( gate );
+               gate_transform_update( gate2 );
+
+               goto matched;
+            }
+         }
+matched:;
+      }
    }
 
    /* water */
@@ -723,6 +775,7 @@ VG_STATIC void world_load( u32 index, const char *path )
 {
    world_instance *world = &world_global.worlds[index];
    world_init_blank( world );
+   world->status = k_world_status_loading;
 
    vg_info( "Loading world: %s\n", path );
 
@@ -765,7 +818,7 @@ VG_STATIC void world_load( u32 index, const char *path )
    world_process_resources( world );
 
    world_routes_ent_init( world );
-   world_entities_init( world );
+   world_entities_init( index );
    world->volume_bh = bh_create( heap, &bh_system_volumes, world,
                                  mdl_arrcount( &world->ent_volume ), 1 );
    
@@ -775,6 +828,8 @@ VG_STATIC void world_load( u32 index, const char *path )
    world_post_process( world );
 
    mdl_close( meta );
+
+   world->status = k_world_status_loaded;
 }
 
 #endif /* WORLD_GEN_H */
index ad0d5c43a2d469fdb31c1650a7559241e08a7457..4e390368e9f4f51a65283e0534b5e54ef349129a 100644 (file)
@@ -359,16 +359,19 @@ VG_STATIC void render_world_gates( world_instance *world, camera *cam,
    }
    
    if( gate ){
-#if 0
-      world_instance *dest_world = &world_global.worlds[ gate->world_index ];
-      render_gate( dest_world, gate, cam, layer_depth );
-#else
-      render_gate( world, gate, cam, layer_depth );
-#endif
-
       /* should really be set in fixed update since its used in the physics
        * of most systems. too bad! */
       world->rendering_gate = gate;
+
+      if( gate->type == k_gate_type_teleport ){
+         render_gate( world, gate, cam, layer_depth );
+      }
+      else if( gate->type == k_gate_type_nonlocel ){
+         world_instance *dest_world = &world_global.worlds[ gate->target ];
+         render_gate( dest_world, gate, cam, layer_depth );
+      }
+      else
+         world->rendering_gate = NULL;
    }
 }
 
@@ -377,7 +380,6 @@ VG_STATIC void world_prerender( world_instance *world )
    static double g_time = 0.0;
    g_time += vg.time_delta * (1.0/(k_day_length*60.0));
 
-
    struct ub_world_lighting *state = &world->ub_lighting;
 
    state->g_time = g_time;
index 00dee4ea0c79d742a78ad3c023cce8d3f1ed7f65..66a4fa5c022bfd0154fc91a7f0f3086251b7cd18 100644 (file)
@@ -134,10 +134,19 @@ VG_STATIC void world_routes_time_lap( world_instance *world, ent_route *route )
 VG_STATIC void world_routes_activate_entry_gate( world_instance *world, 
                                                  ent_gate *rg )
 {
-   ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
-
    world_global.last_use = world_global.time;
 
+   /* disable all routes and leave the world */
+   if( rg->type == k_gate_type_nonlocel ){
+      for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
+         ent_route *route = mdl_arritm( &world->ent_route, i );
+         route->active_checkpoint = 0xffff;
+      }
+      return;
+   }
+
+   ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
+
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route *route = mdl_arritm( &world->ent_route, i );