update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / world_gate.c
index 7212714090f6f82a61beec225fbed109e0994e94..2a236d4391c0d8d7f67d8bcc94bcbad42151a787 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 );
 }
 
@@ -292,17 +295,19 @@ u32 world_intersect_gates( world_instance *world, v3f pos, v3f last )
    return 0;
 }
 
-void ent_gate_call( world_instance *world, ent_call *call )
+entity_call_result ent_gate_call( world_instance *world, ent_call *call )
 {
    u32 index = mdl_entity_id_id( call->id );
    ent_gate *gate = mdl_arritm( &world->ent_gate, index );
 
-   if( call->function == 0 ){ /* unlock() */
+   if( call->function == 0 ) /* unlock() */
+   { 
       gate->flags &= ~k_ent_gate_locked;
+      return k_entity_call_result_OK;
    }
-   else {
-      vg_print_backtrace();
-      vg_error( "Unhandled function id: %u\n", call->function );
+   else 
+   {
+      return k_entity_call_result_unhandled;
    }
 }
 
@@ -312,24 +317,30 @@ void ent_gate_call( world_instance *world, ent_call *call )
  */
 void world_unlink_nonlocal( world_instance *world )
 {
-   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 );
 
-      if( gate->flags & k_ent_gate_nonlocal ){
+      if( gate->flags & k_ent_gate_nonlocal )
+      {
          gate->flags &= ~k_ent_gate_linked;
       }
    }
 }
 
-/* 
- * 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 );