]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
patch from Dresk which adds DP_SV_ENTITYCONTENTSTRANSITION extension which calls...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 Nov 2006 01:28:12 +0000 (01:28 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 Nov 2006 01:28:12 +0000 (01:28 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6627 d7cf8633-e32d-0410-b094-e92efae38249

progs.h
sv_main.c
sv_phys.c
svvm_cmds.c

diff --git a/progs.h b/progs.h
index 0eda5274f8c01998d9b7b90942b7e60e8ed1eb2e..1d6e6b972ef1f107ade57e0312297929c78d7832 100644 (file)
--- a/progs.h
+++ b/progs.h
@@ -130,6 +130,8 @@ extern int eval_SendEntity;
 extern int eval_Version;
 extern int eval_customizeentityforclient;
 extern int eval_dphitcontentsmask;
+// DRESK - Support for Entity Contents Transition Event
+extern int eval_contentstransition;
 
 extern int gval_trace_dpstartcontents;
 extern int gval_trace_dphitcontents;
index 0eaba842d06d120606ad102dad57aadb219884ee..6f8d95d39d6cf61cc26a27112e3c663027b4f4cf 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2191,6 +2191,8 @@ int eval_SendEntity;
 int eval_Version;
 int eval_customizeentityforclient;
 int eval_dphitcontentsmask;
+// DRESK - Support for Entity Contents Transition Event
+int eval_contentstransition;
 
 int gval_trace_dpstartcontents;
 int gval_trace_dphitcontents;
@@ -2267,6 +2269,8 @@ void SV_VM_FindEdictFieldOffsets(void)
        eval_Version = PRVM_ED_FindFieldOffset("Version");
        eval_customizeentityforclient = PRVM_ED_FindFieldOffset("customizeentityforclient");
        eval_dphitcontentsmask = PRVM_ED_FindFieldOffset("dphitcontentsmask");
+       // DRESK - Support for Entity Contents Transition Event
+       eval_contentstransition = PRVM_ED_FindFieldOffset("contentstransition");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = PRVM_ED_FindFunction ("SV_PlayerPhysics");
@@ -2346,6 +2350,8 @@ prvm_required_field_t reqfields[] =
        {ev_string, "playerskin"},
        {ev_function, "SendEntity"},
        {ev_function, "customizeentityforclient"},
+       // DRESK - Support for Entity Contents Transition Event
+       {ev_function, "contentstransition"},
 };
 
 void SV_VM_Setup(void)
index 2c7cd21042389968f33e53af1dafaa51a31aa472..c00abe7f267f5acc19b46dd372058667b6705fa8 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -121,6 +121,46 @@ void SV_CheckAllEnts (void)
        }
 }
 
+// DRESK - Support for Entity Contents Transition Event
+/*
+================
+SV_CheckContentsTransition
+
+returns true if entity had a valid contentstransition function call
+================
+*/
+int SV_CheckContentsTransition(prvm_edict_t *ent, const int nContents)
+{
+       int bValidFunctionCall;
+       prvm_eval_t *contentstransition;
+
+       // Default Valid Function Call to False
+       bValidFunctionCall = false;
+
+       if(ent->fields.server->watertype != nContents)
+       { // Changed Contents
+               // Acquire Contents Transition Function from QC
+               contentstransition = PRVM_GETEDICTFIELDVALUE(ent, eval_contentstransition);
+
+               if(contentstransition->function)
+               { // Valid Function; Execute
+                       // Assign Valid Function
+                       bValidFunctionCall = true;
+                       // Prepare Parameters (Original Contents, New Contents)
+                               // Original Contents
+                               PRVM_G_FLOAT(OFS_PARM0) = ent->fields.server->watertype;
+                               // New Contents
+                               PRVM_G_FLOAT(OFS_PARM1) = nContents;
+                       // Execute VM Function
+                       PRVM_ExecuteProgram(contentstransition->function, "contentstransition: NULL function");
+               }
+       }
+
+       // Return if Function Call was Valid
+       return bValidFunctionCall;
+}
+
+
 /*
 ================
 SV_CheckVelocity
@@ -974,18 +1014,34 @@ SV_CheckWater
 qboolean SV_CheckWater (prvm_edict_t *ent)
 {
        int cont;
+       int nNativeContents;
        vec3_t point;
 
        point[0] = ent->fields.server->origin[0];
        point[1] = ent->fields.server->origin[1];
        point[2] = ent->fields.server->origin[2] + ent->fields.server->mins[2] + 1;
 
+       // DRESK - Support for Entity Contents Transition Event
+       // NOTE: Some logic needed to be slightly re-ordered
+       // to not affect performance and allow for the feature.
+
+       // Acquire Super Contents Prior to Resets
+       cont = SV_PointSuperContents(point);
+       // Acquire Native Contents Here
+       nNativeContents = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, cont);
+
+       // DRESK - Support for Entity Contents Transition Event
+       if(ent->fields.server->watertype)
+               // Entity did NOT Spawn; Check
+               SV_CheckContentsTransition(ent, nNativeContents);
+
+
        ent->fields.server->waterlevel = 0;
        ent->fields.server->watertype = CONTENTS_EMPTY;
        cont = SV_PointSuperContents(point);
        if (cont & (SUPERCONTENTS_LIQUIDSMASK))
        {
-               ent->fields.server->watertype = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, cont);
+               ent->fields.server->watertype = nNativeContents;
                ent->fields.server->waterlevel = 1;
                point[2] = ent->fields.server->origin[2] + (ent->fields.server->mins[2] + ent->fields.server->maxs[2])*0.5;
                if (SV_PointSuperContents(point) & (SUPERCONTENTS_LIQUIDSMASK))
@@ -1294,9 +1350,16 @@ void SV_CheckWaterTransition (prvm_edict_t *ent)
                return;
        }
 
-       // check if the entity crossed into or out of water
-       if (sv_sound_watersplash.string && ((ent->fields.server->watertype == CONTENTS_WATER || ent->fields.server->watertype == CONTENTS_SLIME) != (cont == CONTENTS_WATER || cont == CONTENTS_SLIME)))
-               SV_StartSound (ent, 0, sv_sound_watersplash.string, 255, 1);
+       // DRESK - Support for Entity Contents Transition Event
+       // NOTE: Call here BEFORE updating the watertype below,
+       // and suppress watersplash sound if a valid function
+       // call was made to allow for custom "splash" sounds.
+       if( !SV_CheckContentsTransition(ent, cont) )
+       { // Contents Transition Function Invalid; Potentially Play Water Sound
+               // check if the entity crossed into or out of water
+               if (sv_sound_watersplash.string && ((ent->fields.server->watertype == CONTENTS_WATER || ent->fields.server->watertype == CONTENTS_SLIME) != (cont == CONTENTS_WATER || cont == CONTENTS_SLIME)))
+                       SV_StartSound (ent, 0, sv_sound_watersplash.string, 255, 1);
+       }
 
        if (cont <= CONTENTS_WATER)
        {
index 89760f551885a1ab34e2fc1fbb994262f451500c..e35564bbde6b6166976db3df7b6eb89ef3deaca6 100644 (file)
@@ -91,6 +91,7 @@ char *vm_sv_extensions =
 "DP_SV_DRAWONLYTOCLIENT "
 "DP_SV_DROPCLIENT "
 "DP_SV_EFFECT "
+"DP_SV_ENTITYCONTENTSTRANSITION "
 "DP_SV_NODRAWTOCLIENT "
 "DP_SV_PING "
 "DP_SV_PLAYERPHYSICS "
@@ -2858,7 +2859,7 @@ VM_atan,                                  // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
 VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
 VM_strlennocol,                                // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
-VM_strdecolorize,                      // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
+VM_strdecolorize,                      // #477 string(string s) : DRESK - Decolorized String (DP_SV_STRINGCOLORFUNCTIONS)
 NULL,                                          // #478
 NULL,                                          // #479
 e10, e10                                       // #480-499 (LordHavoc)