option between water plane / water trigger
authorhgn <hgodden00@gmail.com>
Thu, 28 Mar 2024 21:20:55 +0000 (21:20 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 28 Mar 2024 21:20:55 +0000 (21:20 +0000)
entity.c
maps_src/mp_line1/main.mdl
player_glide.c
player_skate.c
player_walk.c
skaterift_blender/sr_main.py
world_render.c
world_water.c
world_water.h

index ae506bd68fdc04fc39807abafc9cd1d5afaadb76..ffb5deed5d9c0c9e905e1c39335b80c8173e04fe 100644 (file)
--- a/entity.c
+++ b/entity.c
@@ -11,6 +11,9 @@
 #include "ent_region.h"
 #include "ent_glider.h"
 #include "ent_npc.h"
+#include "world_water.h"
+
+#include <string.h>
 
 void entity_call( world_instance *world, ent_call *call )
 {
@@ -30,7 +33,8 @@ void entity_call( world_instance *world, ent_call *call )
       [k_ent_miniworld] = ent_miniworld_call,
       [k_ent_region]    = ent_region_call,
       [k_ent_glider]    = ent_glider_call,
-      [k_ent_npc]       = ent_npc_call
+      [k_ent_npc]       = ent_npc_call,
+      [k_ent_water]     = ent_water_call,
    };
 
    if( type >= vg_list_size(table) ){
@@ -58,10 +62,12 @@ void entity_call( world_instance *world, ent_call *call )
 ent_marker *ent_find_marker( mdl_context *mdl, mdl_array_ptr *arr, 
                              const char *alias )
 {
-   for( u32 i=0; i<mdl_arrcount(arr); i++ ){
+   for( u32 i=0; i<mdl_arrcount(arr); i++ )
+   {
       ent_marker *marker = mdl_arritm( arr, i );
 
-      if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
+      if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) )
+      {
          return marker;
       }
    }
index bd56b3c43ebb8f81b18f572d4cedbb7b38b35df6..21dc6eed471718ae673e7b728ee5cf367d419a42 100644 (file)
Binary files a/maps_src/mp_line1/main.mdl and b/maps_src/mp_line1/main.mdl differ
index 4a5958e3cc6ad3b12be4e7fc70e22701e6a09b3b..6b5930b9c2f26bed2d4d17ad1f28d3d902303831 100644 (file)
@@ -273,11 +273,15 @@ void player_glide_update(void)
    v2f steer;
    joystick_state( k_srjoystick_steer, steer );
 
-   if( glider_physics( steer ) ){
+   if( glider_physics( steer ) )
+   {
       vg_info( "player fell off due to glider hitting ground\n" );
       player__dead_transition( k_player_die_type_generic );
       localplayer.glider_orphan = 1;
    }
+
+   if( !world_water_player_safe( world_current_instance(), 1.0f ) )
+      return;
 }
 
 void player_glide_post_update(void)
index 2dedefd47a3e99497e3b7390f6f1f327651be809..eb12d641c9ad644bd19e805ad0008a3252b0ad34 100644 (file)
@@ -2230,20 +2230,10 @@ void player__skate_update(void){
    struct player_skate_state *state = &player_skate.state;
    world_instance *world = world_current_instance();
 
-   if( state->activity == k_skate_activity_handplant ){
+   if( state->activity == k_skate_activity_handplant )
       return;
-   }
 
-   if( world->water.enabled ){
-      if( localplayer.rb.co[1]+0.25f < world->water.height ){
-         vg_info( "player fell off due to being in water\n" );
-         player__networked_sfx( k_player_subsystem_walk, 32, 
-                                k_player_walk_soundeffect_splash,
-                                localplayer.rb.co, 1.0f );
-         player__dead_transition( k_player_die_type_generic );
-         return;
-      }
-   }
+   if( !world_water_player_safe( world, 0.25f ) ) return;
 
    v3_copy( localplayer.rb.co, state->prev_pos );
    state->activity_prev = state->activity;
index b89263433b5a1522570d209e96a2840b6c41c10a..843a50e979e45ade99aedd860659264e8b639277 100644 (file)
@@ -468,17 +468,7 @@ static void player_walk_update_generic(void){
    v3_zero( localplayer.rb.w );
 
    world_instance *world = world_current_instance();
-
-   if( world->water.enabled ){
-      if( localplayer.rb.co[1]+0.4f < world->water.height ){
-         player__networked_sfx( k_player_subsystem_walk, 32, 
-                                k_player_walk_soundeffect_splash,
-                                localplayer.rb.co, 1.0f );
-         vg_info( "player fell of due to walking into walker\n" );
-         player__dead_transition( k_player_die_type_generic );
-         return;
-      }
-   }
+   if( !world_water_player_safe( world, 0.4f ) ) return;
 
    enum walk_activity prev_state = w->state.activity;
 
index 1f4910bef8aef8ef960f6d66416fdcb126c7d5b7..b715493167463135e4af8e39ea7f1c0691281261 100644 (file)
@@ -55,7 +55,7 @@ MDL_VERSION_NR = 106
 SR_TRIGGERABLE = [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
                    'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
                    'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
-                   'ent_npc' ]
+                   'ent_npc', 'ent_water' ]
 
 def get_entity_enum_id( alias ):
 #{
@@ -338,6 +338,7 @@ class ent_water(Structure):
                ("max_dist",c_float),
                ("reserved0",c_uint32),
                ("reserved1",c_uint32)]
+   sr_functions = { 0: "drown" }
 #}
 
 class volume_trigger(Structure):
@@ -1781,6 +1782,9 @@ def sr_compile( collection ):
             else:
                worldinfo.timezone = obj_data.timezone
 
+            if obj_data.water_safe:
+               flags |= 0x2
+
             worldinfo.flags = flags
             worldinfo.pstr_skybox = sr_compile_string( obj_data.skybox )
             sr_ent_push( worldinfo )
@@ -3316,8 +3320,11 @@ class SR_OBJECT_ENT_WORLD_INFO(bpy.types.PropertyGroup):
    timezone: bpy.props.FloatProperty(name="Timezone(hrs) (UTC0 +hrs)")
    fixed_time: bpy.props.FloatProperty(name="Fixed Time (0-1)")
 
+   water_safe: bpy.props.BoolProperty(name="Water is Safe")
+
    @staticmethod
-   def sr_inspector( layout, data ):#{
+   def sr_inspector( layout, data ):
+   #{
       layout.prop( data[0], 'name' )
       layout.prop( data[0], 'desc' )
       layout.prop( data[0], 'author' )
@@ -3327,6 +3334,8 @@ class SR_OBJECT_ENT_WORLD_INFO(bpy.types.PropertyGroup):
          layout.prop( data[0], 'fixed_time' )
       else:
          layout.prop( data[0], 'timezone' )
+
+      layout.prop( data[0], 'water_safe' )
    #}
 #}
 
index e1a30886b8de504afacda8052fbef4e9eba4c2ef..4b6568b2651f3247dd3bc0d638bf9418790e3d82 100644 (file)
@@ -145,15 +145,6 @@ static GLuint world_get_texture( world_instance *world, u32 id ){
    else                  return world->textures[ id ];
 }
 
-#if 0
-static void bindpoint_diffuse_texture1( world_instance *world,
-                                        struct world_surface *mat ){
-   glActiveTexture( GL_TEXTURE1 );
-   glBindTexture( GL_TEXTURE_2D, 
-                  world_get_texture(world,mat->info.tex_diffuse) );
-}
-#endif
-
 /*
  * Passes Rendering
  * ----------------------------------------------------------------------------
index 970ea22a8096111f7064eb16ecc7e8234f1ff1c1..dc8206b57218ec989891930351bb1266256e0412 100644 (file)
@@ -2,15 +2,15 @@
  * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
  */
 
-#ifndef WATER_C
-#define WATER_C
-
 #include "world_water.h"
 #include "world_render.h"
 #include "render.h"
 #include "shaders/scene_water.h"
 #include "shaders/scene_water_fast.h"
 #include "scene.h"
+#include "player.h"
+#include "player_walk.h"
+#include "player_dead.h"
 
 struct world_water world_water;
 
@@ -225,4 +225,36 @@ void render_water_surface( world_instance *world, vg_camera *cam )
    }
 }
 
-#endif /* WATER_C */
+static void world_water_drown(void)
+{
+   player__networked_sfx( k_player_subsystem_walk, 32, 
+                          k_player_walk_soundeffect_splash,
+                          localplayer.rb.co, 1.0f );
+   vg_info( "player fell of due to walking into walker\n" );
+   player__dead_transition( k_player_die_type_generic );
+}
+
+bool world_water_player_safe( world_instance *world, f32 allowance )
+{
+   if( !world->water.enabled ) return 1;
+   if( world->info.flags & 0x2 ) return 1;
+
+   if( localplayer.rb.co[1]+allowance < world->water.height )
+   {
+      world_water_drown();
+      return 0;
+   }
+
+   return 1;
+}
+
+entity_call_result ent_water_call( world_instance *world, ent_call *call )
+{
+   if( call->function == 0 )
+   {
+      world_water_drown();
+      return k_entity_call_result_OK;
+   }
+
+   return k_entity_call_result_unhandled;
+}
index 47855b22fe8a6d8b717f441e84c6c210eef78f30..7ff9af57ddf6ec34eccf6773a382debc99a46057 100644 (file)
@@ -14,3 +14,5 @@ void world_water_init(void);
 void water_set_surface( world_instance *world, f32 height );
 void render_water_texture( world_instance *world, vg_camera *cam );
 void render_water_surface( world_instance *world, vg_camera *cam );
+entity_call_result ent_water_call( world_instance *world, ent_call *call );
+bool world_water_player_safe( world_instance *world, f32 allowance );