fix regression with gate flipping
authorhgn <hgodden00@gmail.com>
Mon, 4 Mar 2024 07:17:38 +0000 (07:17 +0000)
committerhgn <hgodden00@gmail.com>
Mon, 4 Mar 2024 07:17:38 +0000 (07:17 +0000)
world_entity.c
world_gate.c
world_gate.h

index 40d6d78a58acc7684fca56ee8495e35df4673320..88e0e7e1a240815bc38bde6606efa077f919d09d 100644 (file)
@@ -182,16 +182,8 @@ void world_gen_entities_init( world_instance *world )
       light->angle_sin_cos[1] = cosf( light->angle * 0.5f );
    }
 
-   /* gates */
-   for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
-      ent_gate *gate = mdl_arritm( &world->ent_gate, j );
-
-      if( !(gate->flags & k_ent_gate_nonlocal) ) {
-         gate_transform_update( gate );
-      }
-   }
-      
-   vg_async_call( world_link_nonlocal_async, world, 0 );
+   vg_async_call( world_link_gates_async, world, 0 );
+   vg_async_stall();
 
    /* water */
    for( u32 j=0; j<mdl_arrcount(&world->ent_water); j++ ){
index 7212714090f6f82a61beec225fbed109e0994e94..26ce0924ff39dcb2f7d83fcbd472b8665750a13b 100644 (file)
@@ -17,6 +17,7 @@
 #include "world_water.h"
 #include "player_remote.h"
 #include "shaders/model_gate_unlinked.h"
+#include <string.h>
 
 struct world_gates world_gates;
 
@@ -25,21 +26,23 @@ struct world_gates world_gates;
  */
 void gate_transform_update( ent_gate *gate )
 {
-   if( gate->flags & k_ent_gate_flip ){
+   if( gate->flags & k_ent_gate_flip )
+   {
       v4f qflip;
       q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
       q_mul( gate->q[1], qflip, gate->q[1] );
+      q_normalize( gate->q[1] );
    }
 
    m4x3f to_local, recv_to_world;
 
    q_m3x3( gate->q[0], gate->to_world );
    v3_copy( gate->co[0], gate->to_world[3] );
-   
    m4x3_invert_affine( gate->to_world, to_local );
 
    q_m3x3( gate->q[1], recv_to_world );
    v3_copy( gate->co[1], recv_to_world[3] );
+
    m4x3_mul( recv_to_world, to_local, gate->transport );
 }
 
@@ -321,15 +324,19 @@ void world_unlink_nonlocal( world_instance *world )
    }
 }
 
-/* 
- * attatches nonlocal gates, to be called from main thread ONLY! 
+/*
+ * This has to be synchronous because main thread looks at gate data for 
+ * rendering, and we modify gates that the main thread has ownership of.
  */
-void world_link_nonlocal_async( void *payload, u32 size )
+void world_link_gates_async( void *payload, u32 size )
 {
+   VG_ASSERT( vg_thread_purpose() == k_thread_purpose_main );
+
    world_instance *world = payload;
    u32 world_id = world - world_static.instances;
 
-   for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
+   for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ )
+   {
       ent_gate *gate = mdl_arritm( &world->ent_gate, j );
       gate_transform_update( gate );
 
index 6339f1d98f9bd9c19bdc7757c9a036dabd814b6f..13b14785df386cef816b646800845d2741ecf6e1 100644 (file)
@@ -30,7 +30,7 @@ u32 world_intersect_gates( world_instance *world, v3f pos, v3f last );
 void ent_gate_call( world_instance *world, ent_call *call );
 void ent_gate_get_mdl_mtx( ent_gate *gate, m4x3f mmdl );
 
-void world_link_nonlocal_async( void *payload, u32 size );
+void world_link_gates_async( void *payload, u32 size );
 void world_unlink_nonlocal( world_instance *world );
 void render_gate_unlinked( world_instance *world,
                            ent_gate *gate, vg_camera *cam );