#include "gui.h"
#include "audio.h"
-void ent_challenge_call( world_instance *world, ent_call *call )
+entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
- if( call->function == 0 ){ /* unlock() */
- if( !challenge->status ){
+ if( call->function == 0 ) /* unlock() */
+ {
+ if( !challenge->status )
+ {
vg_info( "challenge( '%s' )\n",
mdl_pstr( &world->meta, challenge->pstr_alias) );
ent_call call;
entity_call( world, &call );
}
challenge->status = 1;
+ return k_entity_call_result_OK;
}
- else if( call->function == 1 ){ /* view() */
+ else if( call->function == 1 ) /* view() */
+ {
if( (localplayer.subsystem == k_player_subsystem_walk) &&
- (world_static.challenge_target == NULL) ){
+ (world_static.challenge_target == NULL) )
+ {
world_static.challenge_target = NULL;
world_entity_set_focus( call->id );
world_entity_focus_modal();
if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
vg_strcat( &text, "exit" );
}
+ 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;
}
void ent_challenge_preupdate( ent_challenge *challenge, int active )
#include "entity.h"
void ent_challenge_preupdate( ent_challenge *challenge, int active );
-void ent_challenge_call( world_instance *world, ent_call *call );
+entity_call_result ent_challenge_call( world_instance *world, ent_call *call );
#include "entity.h"
#include "player_glide.h"
-void ent_glider_call( world_instance *world, ent_call *call )
+entity_call_result ent_glider_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_glider *glider = mdl_arritm( &world->ent_glider, index );
- if( call->function == 0 ){
+ if( call->function == 0 )
+ {
glider->flags |= 0x1;
+ return k_entity_call_result_OK;
}
- else if( call->function == 1 ){
- if( glider->flags & 0x1 ){
+ else if( call->function == 1 )
+ {
+ if( glider->flags & 0x1 )
+ {
player_glide_equip_glider();
}
+ return k_entity_call_result_OK;
}
- else {
- vg_print_backtrace();
- vg_error( "Unhandled function id: %i\n", call->function );
- }
+ else
+ return k_entity_call_result_unhandled;
}
#pragma once
#include "entity.h"
-void ent_glider_call( world_instance *world, ent_call *call );
+entity_call_result ent_glider_call( world_instance *world, ent_call *call );
struct global_miniworld global_miniworld;
-void ent_miniworld_call( world_instance *world, ent_call *call )
+entity_call_result ent_miniworld_call( world_instance *world, ent_call *call )
{
ent_miniworld *miniworld = mdl_arritm( &world->ent_miniworld,
mdl_entity_id_id(call->id) );
int world_id = world - world_static.instances;
- if( call->function == 0 ){ /* zone() */
+ if( call->function == 0 ) /* zone() */
+ {
const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world );
skaterift_load_world_command( 1, (const char *[]){ uid } );
if( gui_new_helper( input_button_list[k_srbind_miniworld_resume], &text ))
vg_strcat( &text, "Enter World" );
+
+ return k_entity_call_result_OK;
}
- else if( call->function == 1 ){
+ else if( call->function == 1 )
+ {
global_miniworld.active = NULL;
gui_helper_clear();
- if( miniworld->proxy ){
+ if( miniworld->proxy )
+ {
ent_prop *prop = mdl_arritm( &world->ent_prop,
mdl_entity_id_id(miniworld->proxy) );
prop->flags &= ~0x1;
}
+
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
static void miniworld_icon( vg_camera *cam, enum gui_icon icon,
}
extern global_miniworld;
-void ent_miniworld_call( world_instance *world, ent_call *call );
+entity_call_result ent_miniworld_call( world_instance *world, ent_call *call );
void ent_miniworld_render( world_instance *host_world, vg_camera *cam );
void ent_miniworld_goback(void);
void ent_miniworld_preupdate(void);
else return NULL;
}
-static void npc_slowmo_call( ent_npc *npc, ent_call *call )
+static entity_call_result npc_slowmo_call( ent_npc *npc, ent_call *call )
{
if( call->function == 0 )
{
if( gui_new_helper( input_button_list[k_srbind_replay_resume], &text ))
vg_strcat( &text, "Resume" );
}
+ return k_entity_call_result_OK;
}
else if( call->function == -1 )
{
world_entity_clear_focus();
gui_helper_clear();
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
-void ent_npc_call( world_instance *world, ent_call *call )
+entity_call_result ent_npc_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_npc *npc = mdl_arritm( &world->ent_npc, index );
if( npc->id == 2 )
{
- npc_slowmo_call( npc, call );
+ return npc_slowmo_call( npc, call );
}
else if( npc->id == 3 )
{
vg_str text;
if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
vg_strcat( &text, "Preview course" );
+ return k_entity_call_result_OK;
}
else if( call->function == -1 )
{
world_entity_clear_focus();
gui_helper_clear();
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
else if( npc->id == 4 )
{
vg_str text;
if( gui_new_helper( input_button_list[k_srbind_camera], &text ))
vg_strcat( &text, "First/Thirdperson" );
+ return k_entity_call_result_OK;
}
else if( call->function == -1 )
{
gui_helper_clear();
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
else
{
vg_str text;
if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
vg_strcat( &text, "Talk to ???" );
+ return k_entity_call_result_OK;
}
else if( call->function == -1 )
{
world_entity_clear_focus();
gui_helper_clear();
+ return k_entity_call_result_OK;
}
else
- {
- vg_print_backtrace();
- vg_error( "Unhandled function id: %i\n", call->function );
- }
+ return k_entity_call_result_unhandled;
}
}
void npc_load_model( struct npc *npc, const char *path );
void ent_npc_preupdate( ent_npc *ent, int active );
-void ent_npc_call( world_instance *world, ent_call *call );
+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 );
void npc_init(void);
}
}
-void ent_objective_call( world_instance *world, ent_call *call )
+entity_call_result ent_objective_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_objective *objective = mdl_arritm( &world->ent_objective, index );
- if( call->function == 0 ){
- if( objective->flags & (k_ent_objective_hidden|
- k_ent_objective_passed)) return;
+ if( call->function == 0 )
+ {
+ if( objective->flags & (k_ent_objective_hidden|k_ent_objective_passed))
+ {
+ return k_entity_call_result_OK;
+ }
- if( world_static.challenge_target ){
+ if( world_static.challenge_target )
+ {
if( (world_static.challenge_target == objective) &&
ent_objective_check_filter( objective )){
ent_objective_pass( world, objective );
}
- else {
+ else
+ {
audio_lock();
audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
30.0f, 1.0f );
world_static.focused_entity = 0;
}
}
+
+ return k_entity_call_result_OK;
}
- else if( call->function == 2 ){
+ else if( call->function == 2 )
+ {
objective->flags &= ~k_ent_objective_hidden;
if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
call->id = objective->id_next;
entity_call( world, call );
}
+ return k_entity_call_result_OK;
}
- else if( call->function == 3 ){
+ else if( call->function == 3 )
+ {
objective->flags |= k_ent_objective_hidden;
if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
call->id = objective->id_next;
entity_call( world, call );
}
+ 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;
}
#pragma once
#include "entity.h"
#include "world.h"
-void ent_objective_call( world_instance *world, ent_call *call );
+entity_call_result ent_objective_call( world_instance *world, ent_call *call );
return 0x00;
}
-void ent_region_call( world_instance *world, ent_call *call )
+entity_call_result ent_region_call( world_instance *world, ent_call *call )
{
ent_region *region =
mdl_arritm( &world->ent_region, mdl_entity_id_id(call->id) );
if( !region->zone_volume )
- return;
+ return k_entity_call_result_invalid;
ent_volume *volume =
mdl_arritm( &world->ent_volume, mdl_entity_id_id(region->zone_volume) );
- if( call->function == 0 ){ /* enter */
- for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
+ if( call->function == 0 ) /* enter */
+ {
+ for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ )
+ {
ent_route *route = mdl_arritm( &world->ent_route, i );
v3f local;
m4x3_mulv( volume->to_local, route->board_transform[3], local );
if( (fabsf(local[0]) <= 1.0f) &&
(fabsf(local[1]) <= 1.0f) &&
- (fabsf(local[2]) <= 1.0f) ){
+ (fabsf(local[2]) <= 1.0f) )
+ {
route->flags &= ~k_ent_route_flag_out_of_zone;
}
- else {
+ else
+ {
route->flags |= k_ent_route_flag_out_of_zone;
}
}
network_send_region();
localplayer.effect_data.spark.colour = region_spark_colour(region->flags);
+ return k_entity_call_result_OK;
}
- else if( call->function == 1 ){ /* leave */
- for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
+ else if( call->function == 1 ) /* leave */
+ {
+ for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ )
+ {
ent_route *route = mdl_arritm( &world->ent_route, i );
route->flags |= k_ent_route_flag_out_of_zone;
}
localplayer.effect_data.spark.colour = 0x00;
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
/*
u32 region_spark_colour( u32 flags );
void ent_region_re_eval( world_instance *world );
-void ent_region_call( world_instance *world, ent_call *call );
+entity_call_result ent_region_call( world_instance *world, ent_call *call );
#include "ent_relay.h"
-void ent_relay_call( world_instance *world, ent_call *call )
+entity_call_result ent_relay_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_relay *relay = mdl_arritm( &world->ent_relay, index );
- if( call->function == 0 ){
- for( u32 i=0; i<vg_list_size(relay->targets); i++ ){
- if( relay->targets[i][0] ){
+ if( call->function == 0 )
+ {
+ for( u32 i=0; i<vg_list_size(relay->targets); i++ )
+ {
+ if( relay->targets[i][0] )
+ {
ent_call call;
call.data = NULL;
call.function = relay->targets[i][1];
entity_call( world, &call );
}
}
+ 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;
}
#pragma once
#include "entity.h"
-void ent_relay_call( world_instance *world, ent_call *call );
+entity_call_result ent_relay_call( world_instance *world, ent_call *call );
struct global_ent_route global_ent_route;
-void ent_route_call( world_instance *world, ent_call *call )
+entity_call_result ent_route_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_route *route = mdl_arritm( &world->ent_route, index );
- if( call->function == 0 ){ /* view() */
+ if( call->function == 0 )
+ { /* view() */
if( localplayer.subsystem == k_player_subsystem_walk )
{
world_entity_set_focus( call->id );
if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
vg_strcat( &text, "exit" );
}
+
+ return k_entity_call_result_OK;
}
- else {
- /* TODO: Comrpession */
- vg_print_backtrace();
- vg_error( "Unhandled function id: %u\n", call->function );
- }
+
+ return k_entity_call_result_unhandled;
}
/* TODO: these should recieve the world instance */
}
extern global_ent_route;
-void ent_route_call( world_instance *world, ent_call *call );
+entity_call_result ent_route_call( world_instance *world, ent_call *call );
void ent_route_preupdate( ent_route *route, int active );
/*
* Entity logic: entrance event
*/
-void ent_skateshop_call( world_instance *world, ent_call *call )
+entity_call_result ent_skateshop_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
vg_info( "skateshop_call\n" );
- if( skaterift.activity != k_skaterift_default ) return;
- if( !vg_loader_availible() ) return;
+ if( (skaterift.activity != k_skaterift_default) ||
+ !vg_loader_availible() )
+ return k_entity_call_result_invalid;
if( call->function == k_ent_function_trigger )
{
- if( localplayer.subsystem != k_player_subsystem_walk ) return;
+ if( localplayer.subsystem != k_player_subsystem_walk )
+ return k_entity_call_result_OK;
vg_info( "Entering skateshop\n" );
vg_strcat( &text, "exit" );
skateshop_server_helper_update();
}
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
void skateshop_render_nonfocused( world_instance *world, vg_camera *cam );
void skateshop_autostart_loading(void);
void skateshop_world_preupdate( world_instance *world );
-void ent_skateshop_call( world_instance *world, ent_call *call );
+entity_call_result ent_skateshop_call( world_instance *world, ent_call *call );
void skateshop_world_preview_preupdate(void);
#include "ent_glider.h"
#include "ent_npc.h"
-typedef void (*fn_entity_call_handler)( world_instance *, ent_call *);
-
void entity_call( world_instance *world, ent_call *call )
{
- u32 type = mdl_entity_id_type( call->id );
+ u32 type = mdl_entity_id_type( call->id ),
+ index = mdl_entity_id_id( call->id );
fn_entity_call_handler table[] = {
[k_ent_volume] = ent_volume_call,
fn_entity_call_handler fn = table[ type ];
- if( !fn ){
- vg_error( "call to entity type: %u is undefined\n", type );
+ if( !fn )
+ {
+ vg_error( "Entity type %u does not have a call handler, "
+ "but was called anyway\n", type );
return;
}
- fn( world, call );
+ enum entity_call_result res = fn( world, call );
+
+ if( res == k_entity_call_result_unhandled )
+ {
+ vg_warn( "Call to entity %u#%u was unhandled.\n", type, index );
+ }
}
ent_marker *ent_find_marker( mdl_context *mdl, mdl_array_ptr *arr,
typedef struct ent_glider ent_glider;
typedef struct ent_npc ent_npc;
+typedef struct ent_call ent_call;
+struct ent_call{
+ u32 id;
+ i32 function;
+ void *data;
+};
+
+typedef enum entity_call_result entity_call_result;
+enum entity_call_result
+{
+ k_entity_call_result_OK,
+ k_entity_call_result_unhandled,
+ k_entity_call_result_invalid
+};
+
+typedef enum entity_call_result
+ (*fn_entity_call_handler)( world_instance *, ent_call *);
+
+
enum entity_alias{
k_ent_none = 0,
k_ent_gate = 1,
framebuffer_id, renderbuffer_id, placeholder[2];
};
-typedef struct ent_call ent_call;
-struct ent_call{
- u32 id;
- i32 function;
- void *data;
-};
-
struct ent_miniworld {
mdl_transform transform;
u32 pstr_world;
"\n"
" float d = dot( pnorm, halfview );\n"
" float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
-" return t * g_water_fog;\n"
+"\n"
+" // TODO: Make g_water_fog a material param\n"
+" return t * 0.3;//g_water_fog;\n"
"}\n"
"\n"
"void main()\n"
"{\n"
" vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
"\n"
-" float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
+" //TODO: Make exponent a material param (default: 5.0)\n"
+" float ffresnel = pow(1.0-dot( vnorm, halfview ),0.8);\n"
"\n"
" vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
" vec3 specdir = reflect( -lightdir, vnorm );\n"
" // Surface colour composite\n"
" float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n"
"\n"
-" vec2 world_coord = aCo.xz * 0.008;\n"
-" vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
+" //TODO: Material param (default: 0.008)\n"
+" vec2 world_coord = aCo.xz * 0.12;\n"
+" //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n"
+" vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n"
" vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
" vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
"\n"
}
}
-void ent_volume_call( world_instance *world, ent_call *call )
+entity_call_result ent_volume_call( world_instance *world, ent_call *call )
{
u32 index = mdl_entity_id_id( call->id );
ent_volume *volume = mdl_arritm( &world->ent_volume, index );
- if( !volume->target ) return;
- if( call->function == k_ent_function_trigger ){
+ if( !volume->target )
+ return k_entity_call_result_OK;
+
+ if( call->function == k_ent_function_trigger )
+ {
call->id = volume->target;
- if( volume->flags & k_ent_volume_flag_particles ){
+ if( volume->flags & k_ent_volume_flag_particles )
+ {
float *co = alloca( sizeof(float)*3 );
co[0] = vg_randf64(&vg.rand)*2.0f-1.0f;
co[1] = vg_randf64(&vg.rand)*2.0f-1.0f;
call->data = co;
entity_call( world, call );
}
- else{
+ else
+ {
call->function = volume->trigger.event;
entity_call( world, call );
}
+
+ return k_entity_call_result_OK;
}
- else if( call->function == k_ent_function_trigger_leave ){
+ else if( call->function == k_ent_function_trigger_leave )
+ {
call->id = volume->target;
- if( volume->flags & k_ent_volume_flag_particles ){
+ if( volume->flags & k_ent_volume_flag_particles )
+ {
vg_warn( "Invalid condition; calling leave on particle volume.\n" );
}
- else{
+ else
+ {
call->function = volume->trigger.event_leave;
entity_call( world, call );
}
+
+ return k_entity_call_result_OK;
}
+
+ return k_entity_call_result_unhandled;
}
-void ent_audio_call( world_instance *world, ent_call *call )
+entity_call_result ent_audio_call( world_instance *world, ent_call *call )
{
- if( world->status == k_world_status_unloading ){
+ if( world->status == k_world_status_unloading )
+ {
vg_warn( "cannot modify audio while unloading world\n" );
- return;
+ return k_entity_call_result_invalid;
}
u8 world_id = (world - world_static.instances) + 1;
v3f sound_co;
- if( call->function == k_ent_function_particle_spawn ){
+ if( call->function == k_ent_function_particle_spawn )
+ {
v3_copy( call->data, sound_co );
}
- else if( call->function == k_ent_function_trigger ){
+ else if( call->function == k_ent_function_trigger )
+ {
v3_copy( audio->transform.co, sound_co );
}
else
- return;
+ return k_entity_call_result_unhandled;
float chance = vg_randf64(&vg.rand)*100.0f,
bar = 0.0f;
if( existing ){
if( existing->source == &clip->_.clip ){
audio_unlock();
- return;
+ return k_entity_call_result_OK;
}
existing->group = 0;
}
audio_unlock();
- return;
+ return k_entity_call_result_OK;
}
}
+ return k_entity_call_result_OK;
}
-void ent_ccmd_call( world_instance *world, ent_call *call )
+entity_call_result ent_ccmd_call( world_instance *world, ent_call *call )
{
- if( call->function == k_ent_function_trigger ){
+ if( call->function == k_ent_function_trigger )
+ {
u32 index = mdl_entity_id_id( call->id );
ent_ccmd *ccmd = mdl_arritm( &world->ent_ccmd, index );
- vg_execute_console_input( mdl_pstr(&world->meta, ccmd->pstr_command),
- 0 );
+ vg_execute_console_input( mdl_pstr(&world->meta, ccmd->pstr_command), 0 );
+ return k_entity_call_result_OK;
}
+ else
+ return k_entity_call_result_unhandled;
}
/*
void world_entity_start( world_instance *world, vg_msg *sav );
void world_entity_serialize( world_instance *world, vg_msg *sav );
-void ent_volume_call( world_instance *world, ent_call *call );
-void ent_audio_call( world_instance *world, ent_call *call );
-void ent_ccmd_call( world_instance *world, ent_call *call );
+entity_call_result ent_volume_call( world_instance *world, ent_call *call );
+entity_call_result ent_audio_call( world_instance *world, ent_call *call );
+entity_call_result ent_ccmd_call( world_instance *world, ent_call *call );
void entity_bh_expand_bound( void *user, boxf bound, u32 item_index );
float entity_bh_centroid( void *user, u32 item_index, int axis );
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;
}
}
*/
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;
}
}
int gate_intersect( ent_gate *gate, v3f pos, v3f last );
u32 world_intersect_gates( world_instance *world, v3f pos, v3f last );
-void ent_gate_call( world_instance *world, ent_call *call );
+entity_call_result ent_gate_call( world_instance *world, ent_call *call );
void ent_gate_get_mdl_mtx( ent_gate *gate, m4x3f mmdl );
void world_link_gates_async( void *payload, u32 size );