TODO about preupdate call style
authorhgn <hgodden00@gmail.com>
Wed, 20 Mar 2024 10:55:16 +0000 (10:55 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 20 Mar 2024 10:55:56 +0000 (10:55 +0000)
ent_challenge.c
ent_challenge.h
ent_npc.c
ent_npc.h
ent_route.c
ent_route.h
ent_skateshop.c
ent_skateshop.h
world_entity.c
world_entity.h

index 9499d0fed8e7b0e6ce9f51fcd1cf0a161d373c55..861edbd6f60e10f9bac4b8ed9c12e093c9fee37a 100644 (file)
@@ -46,15 +46,18 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
       return k_entity_call_result_unhandled;
 }
 
-void ent_challenge_preupdate( ent_challenge *challenge, int active )
+void ent_challenge_preupdate( ent_focus_context *ctx )
 {
-   world_instance *world = world_current_instance();
+   world_instance *world = ctx->world;
+   ent_challenge *challenge = mdl_arritm( &world->ent_challenge, ctx->index );
 
    /* maximum distance from active challenge */
-   if( !active ){
+   if( !ctx->active )
+   {
       f32 min_dist2 = 999999.9f;
 
-      if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
+      if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
+      {
          u32 next = challenge->first;
          while( mdl_entity_id_type(next) == k_ent_objective ){
             u32 index = mdl_entity_id_id( next );
index d5108a8c9bb5b2a4993ab074bec69a815481789d..f53c95664b47e97bcb5fff1e69d8efe6a8ee6664 100644 (file)
@@ -1,5 +1,5 @@
 #pragma once
 #include "entity.h"
 
-void ent_challenge_preupdate( ent_challenge *challenge, int active );
+void ent_challenge_preupdate( ent_focus_context *ctx );
 entity_call_result ent_challenge_call( world_instance *world, ent_call *call );
index 8fccd29552bab08f21344dba4951cdc848a7496f..7a4b484b534f22d389e3e3793cc15739a311109f 100644 (file)
--- a/ent_npc.c
+++ b/ent_npc.c
@@ -177,11 +177,12 @@ entity_call_result ent_npc_call( world_instance *world, ent_call *call )
    }
 }
 
-void ent_npc_preupdate( ent_npc *ent, int active )
+void ent_npc_preupdate( ent_focus_context *ctx )
 {
-   world_instance *world = world_current_instance();
+   world_instance *world = ctx->world;
+   ent_npc *ent = mdl_arritm( &world->ent_npc, ctx->index );
 
-   if( !active )
+   if( !ctx->active )
    {
       if( button_down(k_srbind_maccept) )
       {
index 648f44775db3a729cfad4bff10558604c12bc286..c20cc970f51d6526e3a62c9b2dc089180a1c3ba7 100644 (file)
--- a/ent_npc.h
+++ b/ent_npc.h
@@ -21,7 +21,7 @@ enum npc_id
 };
 
 void npc_load_model( struct npc *npc, const char *path );
-void ent_npc_preupdate( ent_npc *ent, int active );
+void ent_npc_preupdate( ent_focus_context *context );
 entity_call_result ent_npc_call( world_instance *world, ent_call *call );
 void npc_update( ent_npc *ent );
 void npc_render( ent_npc *ent, world_instance *world, vg_camera *cam );
index 026bf7048ac01237a55526ebceb827f53a99c155..f5b51c5ec2ce520c74860ee04897d88ca214ef89 100644 (file)
@@ -37,12 +37,14 @@ entity_call_result ent_route_call( world_instance *world, ent_call *call )
    return k_entity_call_result_unhandled;
 }
 
-/* TODO: these should recieve the world instance */
-void ent_route_preupdate( ent_route *route, int active )
+void ent_route_preupdate( ent_focus_context *ctx )
 {
-   if( !active ) return;
+   if( !ctx->active ) 
+      return;
+
+   world_instance *world = ctx->world;
+   ent_route *route = mdl_arritm( &world->ent_route, ctx->index );
 
-   world_instance *world = world_current_instance();
    u32 cam_id = 0;
    
    if( __builtin_expect( world->meta.info.version >= 103, 1 ) )
index 7c5dfa3785bef6c42b7d3cc833fee5f36e391b95..cbf61b29740239833652fdafe49df9bfa927d2f8 100644 (file)
@@ -8,4 +8,4 @@ struct global_ent_route
 extern global_ent_route;
 
 entity_call_result ent_route_call( world_instance *world, ent_call *call );
-void ent_route_preupdate( ent_route *route, int active );
+void ent_route_preupdate( ent_focus_context *ctx );
index 1065d4b58ab6a1095cd7d3d7f26e2cf1a5261780..05999f9322c5793df9cccb00c7e547f14c03b460 100644 (file)
@@ -209,12 +209,13 @@ static void skateshop_server_helper_update(void){
  * VG event preupdate 
  */
 void temp_update_playermodel(void);
-void ent_skateshop_preupdate( ent_skateshop *shop, int active )
+void ent_skateshop_preupdate( ent_focus_context *ctx )
 {
-   if( !active ) return;
+   if( !ctx->active ) 
+      return;
 
-   /* input filter */
-   world_instance *world = world_current_instance();
+   world_instance *world = ctx->world;
+   ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, ctx->index );
 
    /* camera positioning */
    ent_camera *ref = mdl_arritm( &world->ent_camera, 
index ed03ecdb74ec3095a6c8078d09e2c80ad718afc7..2f8e3a64917bb885b2671b78573c6185ea31e466 100644 (file)
@@ -45,7 +45,7 @@ struct global_skateshop
 extern global_skateshop;
 
 void skateshop_init(void);
-void ent_skateshop_preupdate( ent_skateshop *shop, int active );
+void ent_skateshop_preupdate( ent_focus_context *ctx );
 void skateshop_render( ent_skateshop *shop );
 void skateshop_render_nonfocused( world_instance *world, vg_camera *cam );
 void skateshop_autostart_loading(void);
index 13c89a025da827f4382dddd0830040f8074d083e..d525572f1e7dd548b791ef50ad472bf998fd3b21 100644 (file)
@@ -115,31 +115,32 @@ void world_entity_focus_preupdate(void)
    vg_slewf( &world_static.focus_strength, active, 
              vg.time_frame_delta * (1.0f/0.5f) );
 
+   if( world_static.focused_entity == 0 )
+      return;
+
    u32 type = mdl_entity_id_type( world_static.focused_entity ),
        index = mdl_entity_id_id( world_static.focused_entity );
+
    world_instance *world = world_current_instance();
 
-   /* TODO: Table. */
-   if( type == k_ent_skateshop )
-   {
-      ent_skateshop *skateshop = mdl_arritm( &world->ent_skateshop, index );
-      ent_skateshop_preupdate( skateshop, active );
-   }
-   else if( type == k_ent_challenge )
-   {
-      ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
-      ent_challenge_preupdate( challenge, active );
-   }
-   else if( type == k_ent_route )
+   static void (*table[])( ent_focus_context *ctx ) =
    {
-      ent_route *route = mdl_arritm( &world->ent_route, index );
-      ent_route_preupdate( route, active );
-   }
-   else if( type == k_ent_npc )
+      [ k_ent_skateshop ] = ent_skateshop_preupdate,
+      [ k_ent_challenge ] = ent_challenge_preupdate,
+      [ k_ent_route ] = ent_route_preupdate,
+      [ k_ent_npc ] = ent_npc_preupdate,
+   };
+
+   if( (type > vg_list_size(table)) || (table[type] == NULL) )
    {
-      ent_npc *npc = mdl_arritm( &world->ent_npc, index );
-      ent_npc_preupdate( npc, active );
+      vg_fatal_error( "No pre-update method set for entity (%u#%u)\n",
+                      type, index );
    }
+
+   table[type]( &(ent_focus_context){
+                  .world = world,
+                  .index = index,
+                  .active = active } );
 }
 
 /* additional renderings like text etc.. */
index 5f784d200aa3fc9c92eac920dc2d89ef377eb8d6..c954052a4149ff924c0ddef42588e723c8630dac 100644 (file)
@@ -4,6 +4,14 @@
 #include "vg/vg_bvh.h"
 #include "vg/vg_msg.h"
 
+typedef struct ent_focus_context ent_focus_context;
+struct ent_focus_context
+{
+   world_instance *world;
+   u32 index; /* Array index of the focused entity */
+   bool active;
+};
+
 void world_gen_entities_init( world_instance *world );
 ent_spawn *world_find_spawn_by_name( world_instance *world, 
                                         const char *name );