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 );
#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 );
}
}
-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) )
{
};
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 );
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 ) )
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 );
* 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,
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);
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.. */
#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 );