From 1657ff3e29ca2917c2de8302407091a726790679 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Wed, 1 Sep 2021 21:30:10 +0200 Subject: [PATCH] GS-EntBase: Move I/O system into CBaseEntity, add Skin, Disable/EnableShadow inputs... --- src/gs-entbase/server/basetrigger.h | 11 --- src/gs-entbase/server/basetrigger.qc | 123 ------------------------ src/gs-entbase/shared/baseentity.h | 10 ++ src/gs-entbase/shared/baseentity.qc | 139 +++++++++++++++++++++++++++ src/shared/spectator.h | 2 +- src/shared/spectator.qc | 8 +- 6 files changed, 154 insertions(+), 139 deletions(-) diff --git a/src/gs-entbase/server/basetrigger.h b/src/gs-entbase/server/basetrigger.h index 99b15510..38c71adc 100644 --- a/src/gs-entbase/server/basetrigger.h +++ b/src/gs-entbase/server/basetrigger.h @@ -39,17 +39,6 @@ class CBaseTrigger:CBaseEntity void(void) CBaseTrigger; - /* modern trigger architecture */ - string m_strOnTrigger; - string m_strOnUser1; - string m_strOnUser2; - string m_strOnUser3; - string m_strOnUser4; - - virtual void(entity, string) UseOutput; - virtual string(string) CreateOutput; - virtual void(entity, string, string) Input; - /* legacy trigger architecture */ float m_flDelay; virtual void(entity, int) Trigger; diff --git a/src/gs-entbase/server/basetrigger.qc b/src/gs-entbase/server/basetrigger.qc index 4562f277..85384832 100644 --- a/src/gs-entbase/server/basetrigger.qc +++ b/src/gs-entbase/server/basetrigger.qc @@ -14,103 +14,6 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* modern trigger architecture */ -void -CBaseTrigger::UseOutput(entity act, string outname) -{ - if (!outname) - return; - - for (entity f = world; (f = find(f, ::targetname, outname));) { - CBaseOutput op = (CBaseOutput)f; - - /* no more tries and not -1 (infinite) */ - if (op.m_iCount == 0) { - return; - } - - op.m_eActivator = act; - op.think = CBaseOutput::TriggerOutput; - op.nextthink = time + op.m_flDelay; - } -} - -/* input is a 5 parameter, commar separated string, output is the targetname - of a minion entity that'll handle the triggering (and counting down of uses) - as defined in the Source Input/Output specs */ -string -CBaseTrigger::CreateOutput(string outmsg) -{ - static int outcount = 0; - string outname = ""; - float c; - - if (!outmsg) - return (""); - - outname = sprintf("output_%i\n", outcount); - outcount++; - - /* to make sure tokenize 'remembers' to tell us about the commonly - empty data string, we prepared the output string beforehand to - at least contain a _ symbol after the comma separator... now - we gotta clip that away using substring(). messy, but that's the - only way to keep them at 5 argv() calls per output */ - c = tokenizebyseparator(outmsg, ","); - for (float i = 1; i < c; i+=5) { - CBaseOutput new_minion = spawn(CBaseOutput); - - new_minion.classname = "triggerminion"; - new_minion.targetname = outname; - new_minion.m_strTarget = substring(argv(i), 1,-1); - new_minion.m_strInput = substring(argv(i+1), 1,-1); - new_minion.m_strData = substring(argv(i+2), 1,-1); - new_minion.m_flDelay = stof(substring(argv(i+3), 1,-1)); - new_minion.m_iCount = stoi(substring(argv(i+4), 1,-1)); - new_minion.m_iOldCount = new_minion.m_iCount; - - /* print final debug output */ - dprint(sprintf("^2%s::CreateOutput report:\n", classname)); - dprint(sprintf("Target: %s\n", new_minion.m_strTarget)); - dprint(sprintf("Input: %s\n", new_minion.m_strInput)); - dprint(sprintf("Data Message: %s\n", new_minion.m_strData)); - dprint(sprintf("Delay: %f\n", new_minion.m_flDelay)); - dprint(sprintf("Uses: %i\n\n", new_minion.m_iCount)); - } - - /* return the name that'll act as the trigger for all outputs */ - return outname; -} - -/* entities receive the inputs here and need to act on intype and data - accordingly. this is just a stub for unknown event troubleshooting */ -void -CBaseTrigger::Input(entity eAct, string strInput, string strData) -{ - switch (strInput) { - case "FireUser1": - UseOutput(eAct, m_strOnUser1); - break; - case "FireUser2": - UseOutput(eAct, m_strOnUser2); - break; - case "FireUser3": - UseOutput(eAct, m_strOnUser3); - break; - case "FireUser4": - UseOutput(eAct, m_strOnUser4); - break; - default: - if (strData != "") - print(sprintf("^2%s::^3Input^7: Receives input %s from %s with data %s\n", - this.classname, strInput, eAct.classname, strData)); - else - print(sprintf("^2%s::^3Input^7: Receives input %s from %s\n", - this.classname, strInput, eAct.classname)); - } -} - - /* legacy trigger architecture */ void CBaseTrigger::Trigger(entity act, int state) @@ -235,26 +138,6 @@ CBaseTrigger::SpawnKey(string strKey, string strValue) case "delay": m_flDelay = stof(strValue); break; - case "OnTrigger": - strValue = strreplace(",", ",_", strValue); - m_strOnTrigger = strcat(m_strOnTrigger, ",_", strValue); - break; - case "OnUser1": - strValue = strreplace(",", ",_", strValue); - m_strOnUser1 = strcat(m_strOnUser1, ",_", strValue); - break; - case "OnUser2": - strValue = strreplace(",", ",_", strValue); - m_strOnUser2 = strcat(m_strOnUser2, ",_", strValue); - break; - case "OnUser3": - strValue = strreplace(",", ",_", strValue); - m_strOnUser3 = strcat(m_strOnUser3, ",_", strValue); - break; - case "OnUser4": - strValue = strreplace(",", ",_", strValue); - m_strOnUser4 = strcat(m_strOnUser4, ",_", strValue); - break; default: CBaseEntity::SpawnKey(strKey, strValue); break; @@ -265,10 +148,4 @@ void CBaseTrigger::CBaseTrigger(void) { CBaseEntity::CBaseEntity(); - - m_strOnTrigger = CreateOutput(m_strOnTrigger); - m_strOnUser1 = CreateOutput(m_strOnUser1); - m_strOnUser2 = CreateOutput(m_strOnUser2); - m_strOnUser3 = CreateOutput(m_strOnUser3); - m_strOnUser4 = CreateOutput(m_strOnUser4); } diff --git a/src/gs-entbase/shared/baseentity.h b/src/gs-entbase/shared/baseentity.h index a061e31d..47ad157b 100644 --- a/src/gs-entbase/shared/baseentity.h +++ b/src/gs-entbase/shared/baseentity.h @@ -56,6 +56,16 @@ class CBaseEntity vector net_velocity; string m_parent; + + /* Input/Output System */ + string m_strOnTrigger; + string m_strOnUser1; + string m_strOnUser2; + string m_strOnUser3; + string m_strOnUser4; + virtual void(entity, string) UseOutput; + virtual string(string) CreateOutput; + virtual void(entity, string, string) Input; void(void) CBaseEntity; virtual void(void) Respawn; diff --git a/src/gs-entbase/shared/baseentity.qc b/src/gs-entbase/shared/baseentity.qc index 67956c10..29f09c5e 100644 --- a/src/gs-entbase/shared/baseentity.qc +++ b/src/gs-entbase/shared/baseentity.qc @@ -416,6 +416,111 @@ CBaseEntity_ParseSentence(void) } } #else +/* Input/Output system */ +void +CBaseEntity::UseOutput(entity act, string outname) +{ + if (!outname) + return; + + for (entity f = world; (f = find(f, ::targetname, outname));) { + CBaseOutput op = (CBaseOutput)f; + + /* no more tries and not -1 (infinite) */ + if (op.m_iCount == 0) { + return; + } + + op.m_eActivator = act; + op.think = CBaseOutput::TriggerOutput; + op.nextthink = time + op.m_flDelay; + } +} + +/* input is a 5 parameter, commar separated string, output is the targetname + of a minion entity that'll handle the triggering (and counting down of uses) + as defined in the Source Input/Output specs */ +string +CBaseEntity::CreateOutput(string outmsg) +{ + static int outcount = 0; + string outname = ""; + float c; + + if (!outmsg) + return (""); + + outname = sprintf("output_%i\n", outcount); + outcount++; + + /* to make sure tokenize 'remembers' to tell us about the commonly + empty data string, we prepared the output string beforehand to + at least contain a _ symbol after the comma separator... now + we gotta clip that away using substring(). messy, but that's the + only way to keep them at 5 argv() calls per output */ + c = tokenizebyseparator(outmsg, ","); + for (float i = 1; i < c; i+=5) { + CBaseOutput new_minion = spawn(CBaseOutput); + + new_minion.classname = "triggerminion"; + new_minion.targetname = outname; + new_minion.m_strTarget = substring(argv(i), 1,-1); + new_minion.m_strInput = substring(argv(i+1), 1,-1); + new_minion.m_strData = substring(argv(i+2), 1,-1); + new_minion.m_flDelay = stof(substring(argv(i+3), 1,-1)); + new_minion.m_iCount = stoi(substring(argv(i+4), 1,-1)); + new_minion.m_iOldCount = new_minion.m_iCount; + + /* print final debug output */ + dprint(sprintf("^2%s::CreateOutput report:\n", classname)); + dprint(sprintf("Target: %s\n", new_minion.m_strTarget)); + dprint(sprintf("Input: %s\n", new_minion.m_strInput)); + dprint(sprintf("Data Message: %s\n", new_minion.m_strData)); + dprint(sprintf("Delay: %f\n", new_minion.m_flDelay)); + dprint(sprintf("Uses: %i\n\n", new_minion.m_iCount)); + } + + /* return the name that'll act as the trigger for all outputs */ + return outname; +} + +/* entities receive the inputs here and need to act on intype and data + accordingly. this is just a stub for unknown event troubleshooting */ +void +CBaseEntity::Input(entity eAct, string strInput, string strData) +{ + switch (strInput) { + case "FireUser1": + UseOutput(eAct, m_strOnUser1); + break; + case "FireUser2": + UseOutput(eAct, m_strOnUser2); + break; + case "FireUser3": + UseOutput(eAct, m_strOnUser3); + break; + case "FireUser4": + UseOutput(eAct, m_strOnUser4); + break; + case "Skin": + SetSkin(stof(strData)); + break; + case "DisableShadow": + effects |= EF_NOSHADOW; + break; + case "EnableShadow": + effects &= ~EF_NOSHADOW; + break; + default: + if (strData != "") + print(sprintf("^2%s::^3Input^7: Receives input %s from %s with data %s\n", + this.classname, strInput, eAct.classname, strData)); + else + print(sprintf("^2%s::^3Input^7: Receives input %s from %s\n", + this.classname, strInput, eAct.classname)); + } +} + /* Make sure StartFrame calls this */ float CBaseEntity::SendEntity(entity ePEnt, float fChanged) @@ -665,6 +770,13 @@ CBaseEntity::CBaseEntity(void) m_oldHealth = health; m_oldModel = Util_FixModel(model); + /* Input/Output system */ + m_strOnTrigger = CreateOutput(m_strOnTrigger); + m_strOnUser1 = CreateOutput(m_strOnUser1); + m_strOnUser2 = CreateOutput(m_strOnUser2); + m_strOnUser3 = CreateOutput(m_strOnUser3); + m_strOnUser4 = CreateOutput(m_strOnUser4); + #ifdef GS_RENDERFX m_oldiRenderFX = m_iRenderFX; m_oldiRenderMode = m_iRenderMode; @@ -869,6 +981,12 @@ CBaseEntity::SpawnKey(string strKey, string strValue) effects &= ~EF_NOSHADOW; } break; + /* Source */ + case "disableshadows": + if (stof(strValue) == 1) { + effects |= EF_NOSHADOW; + } + break; case "targetname": targetname = strValue; break; @@ -919,6 +1037,27 @@ CBaseEntity::SpawnKey(string strKey, string strValue) case "ignorepvs": pvsflags = PVSF_IGNOREPVS; break; + /* Input/Output system */ + case "OnTrigger": + strValue = strreplace(",", ",_", strValue); + m_strOnTrigger = strcat(m_strOnTrigger, ",_", strValue); + break; + case "OnUser1": + strValue = strreplace(",", ",_", strValue); + m_strOnUser1 = strcat(m_strOnUser1, ",_", strValue); + break; + case "OnUser2": + strValue = strreplace(",", ",_", strValue); + m_strOnUser2 = strcat(m_strOnUser2, ",_", strValue); + break; + case "OnUser3": + strValue = strreplace(",", ",_", strValue); + m_strOnUser3 = strcat(m_strOnUser3, ",_", strValue); + break; + case "OnUser4": + strValue = strreplace(",", ",_", strValue); + m_strOnUser4 = strcat(m_strOnUser4, ",_", strValue); + break; #endif default: print(sprintf("^3%s^7::SpawnKey:: Unknown key '%s' with value '%s'\n", diff --git a/src/shared/spectator.h b/src/shared/spectator.h index 054d0086..14906dd5 100644 --- a/src/shared/spectator.h +++ b/src/shared/spectator.h @@ -40,7 +40,7 @@ class spectator virtual void(void) PreFrame; virtual void(void) PostFrame; - virtual void(void) Input; + virtual void(void) SpectatorInput; virtual void(void) WarpToTarget; diff --git a/src/shared/spectator.qc b/src/shared/spectator.qc index 3ca72f9a..7690ba1b 100644 --- a/src/shared/spectator.qc +++ b/src/shared/spectator.qc @@ -23,7 +23,7 @@ spectator::WarpToTarget(void) } void -spectator::Input(void) +spectator::SpectatorInput(void) { if (input_buttons & INPUT_BUTTON0) { InputNext(); @@ -81,7 +81,7 @@ void spectator::RunClientCommand(void) { runstandardplayerphysics(this); - Input(); + SpectatorInput(); } #else @@ -106,7 +106,7 @@ spectator::ReceiveEntity(float new) } input_sequence = i; runstandardplayerphysics(this); - Input(); + SpectatorInput(); } /* any differences in things that are read below are now @@ -308,7 +308,7 @@ spectator::PreFrame(void) /* run our custom physics */ runstandardplayerphysics(this); - Input(); + SpectatorInput(); } #endif