NSEntity: .touch being assigned is being deprecated in favor of our internal Touch(entity).

This is so we can support StartTouch(entity) as well as EndTouch(entity) which are implemented
with this commit. Update your entities touch() function overrides for NSEntity sub-classes!
This commit is contained in:
Marco Cawthorne 2022-04-03 14:04:34 -07:00
parent 60e4853549
commit 75a1c8ce6c
Signed by: eukara
GPG key ID: C196CD8BA993248A
10 changed files with 268 additions and 106 deletions

View file

@ -15,7 +15,7 @@
*/ */
/* PICKUP ITEMS */ /* PICKUP ITEMS */
class item_pickup:CBaseTrigger class item_pickup:NSRenderableEntity
{ {
int m_bFloating; int m_bFloating;
int m_iClip; int m_iClip;
@ -23,7 +23,7 @@ class item_pickup:CBaseTrigger
int id; int id;
void(void) item_pickup; void(void) item_pickup;
virtual void(void) touch; virtual void(entity) Touch;
virtual void(int i) SetItem; virtual void(int i) SetItem;
virtual void(void) Respawn; virtual void(void) Respawn;
virtual void(int) SetFloating; virtual void(int) SetFloating;

View file

@ -15,20 +15,20 @@
*/ */
void void
item_pickup::touch(void) item_pickup::Touch(entity eToucher)
{ {
if (other.classname != "player") { if (eToucher.classname != "player") {
return; return;
} }
/* don't remove if AddItem fails */ /* don't remove if AddItem fails */
if (Weapons_AddItem((base_player)other, id, m_iClip) == FALSE) { if (Weapons_AddItem((base_player)eToucher, id, m_iClip) == FALSE) {
return; return;
} }
Logging_Pickup(other, this, __NULL__); Logging_Pickup(eToucher, this, __NULL__);
UseTargets(other, TRIG_TOGGLE, m_flDelay); UseTargets(eToucher, TRIG_TOGGLE, m_flDelay);
if (real_owner || m_iWasDropped == 1 || cvar("sv_playerslots") == 1) { if (real_owner || m_iWasDropped == 1 || cvar("sv_playerslots") == 1) {
remove(self); remove(self);
@ -44,8 +44,7 @@ item_pickup::SetItem(int i)
{ {
id = i; id = i;
m_oldModel = Weapons_GetWorldmodel(id); m_oldModel = Weapons_GetWorldmodel(id);
SetModel(m_oldModel); Respawn();
SetSize([-16,-16,0], [16,16,16]);
} }
void void
@ -58,7 +57,7 @@ void
item_pickup::Respawn(void) item_pickup::Respawn(void)
{ {
SetSolid(SOLID_TRIGGER); SetSolid(SOLID_TRIGGER);
SetOrigin(m_oldOrigin); SetOrigin(GetSpawnOrigin());
/* At some points, the item id might not yet be set */ /* At some points, the item id might not yet be set */
if (m_oldModel) { if (m_oldModel) {
@ -83,6 +82,6 @@ item_pickup::Respawn(void)
void void
item_pickup::item_pickup(void) item_pickup::item_pickup(void)
{ {
CBaseTrigger::CBaseTrigger(); super::NSRenderableEntity();
Respawn(); Respawn();
} }

View file

@ -105,7 +105,7 @@ class func_button:NSSurfacePropEntity
virtual void(void) Returned; virtual void(void) Returned;
virtual void(void) MoveBack; virtual void(void) MoveBack;
virtual void(void) MoveAway; virtual void(void) MoveAway;
virtual void(void) Touch; virtual void(entity) Touch;
virtual void(entity) Blocked; virtual void(entity) Blocked;
virtual void(entity, int) Trigger; virtual void(entity, int) Trigger;
virtual void(void) DeathTrigger; virtual void(void) DeathTrigger;
@ -324,14 +324,14 @@ func_button::DeathTrigger(void)
} }
void void
func_button::Touch(void) func_button::Touch(entity eToucher)
{ {
if (other.movetype == MOVETYPE_WALK) {
Trigger(other, TRIG_TOGGLE);
if (!HasSpawnFlags(SF_BTT_TOUCH_ONLY)) { if (!HasSpawnFlags(SF_BTT_TOUCH_ONLY)) {
touch = __NULL__; return;
} }
if (eToucher.movetype == MOVETYPE_WALK) {
Trigger(eToucher, TRIG_TOGGLE);
} }
} }
@ -425,10 +425,8 @@ func_button::Respawn(void)
} }
if (HasSpawnFlags(SF_BTT_TOUCH_ONLY)) { if (HasSpawnFlags(SF_BTT_TOUCH_ONLY)) {
touch = Touch;
PlayerUse = __NULL__; PlayerUse = __NULL__;
} else { } else {
touch = __NULL__;
PlayerUse = Use; PlayerUse = Use;
} }

View file

@ -111,7 +111,7 @@ class func_door:NSRenderableEntity
virtual void(void) Respawn; virtual void(void) Respawn;
virtual void(entity, int) Trigger; virtual void(entity, int) Trigger;
virtual void(entity) Blocked; virtual void(entity) Blocked;
virtual void(void) Touch; virtual void(entity) Touch;
virtual void(void) Use; virtual void(void) Use;
virtual void(float) Save; virtual void(float) Save;
virtual void(string, string) Restore; virtual void(string, string) Restore;
@ -291,8 +291,11 @@ func_door::Trigger(entity act, int state)
} }
void void
func_door::Touch(void) func_door::Touch(entity eToucher)
{ {
if (HasSpawnFlags(SF_MOV_USE))
return;
if (m_iLocked || !GetMaster()) { if (m_iLocked || !GetMaster()) {
if (m_flSoundWait < time) if (m_flSoundWait < time)
Sound_Play(this, CHAN_VOICE, m_strLockedSfx); Sound_Play(this, CHAN_VOICE, m_strLockedSfx);
@ -305,9 +308,9 @@ func_door::Touch(void)
return; return;
} }
if (other.movetype == MOVETYPE_WALK) { if (eToucher.movetype == MOVETYPE_WALK) {
if (other.absmin[2] <= maxs[2] - 2) { if (eToucher.absmin[2] <= maxs[2] - 2) {
Trigger(other, TRIG_TOGGLE); Trigger(eToucher, TRIG_TOGGLE);
} }
} }
} }
@ -420,15 +423,11 @@ func_door::Respawn(void)
} }
if (HasSpawnFlags(SF_MOV_USE)) { if (HasSpawnFlags(SF_MOV_USE)) {
touch = __NULL__;
PlayerUse = Use; PlayerUse = Use;
} else { } else {
touch = Touch;
PlayerUse = __NULL__; PlayerUse = __NULL__;
} }
touch = Touch;
m_iValue = 0; m_iValue = 0;
m_iState = DOORSTATE_LOWERED; m_iState = DOORSTATE_LOWERED;
m_vecPos1 = GetSpawnOrigin(); m_vecPos1 = GetSpawnOrigin();

View file

@ -100,7 +100,7 @@ class func_door_rotating:NSRenderableEntity
virtual void(void) Away; virtual void(void) Away;
virtual void(entity, int) Trigger; virtual void(entity, int) Trigger;
virtual void(void) Use; virtual void(void) Use;
virtual void(void) Touch; virtual void(entity) Touch;
virtual void(entity) Blocked; virtual void(entity) Blocked;
virtual void(void) SetMovementDirection; virtual void(void) SetMovementDirection;
virtual void(vector angle, void(void) func) RotToDest; virtual void(vector angle, void(void) func) RotToDest;
@ -301,7 +301,7 @@ func_door_rotating::Use(void)
} }
void void
func_door_rotating::Touch(void) func_door_rotating::Touch(entity eToucher)
{ {
if (m_iLocked || !GetMaster()) { if (m_iLocked || !GetMaster()) {
if (m_flSoundWait < time) if (m_flSoundWait < time)
@ -318,8 +318,8 @@ func_door_rotating::Touch(void)
if ((m_iState == STATE_UP) || (m_iState == STATE_DOWN)) if ((m_iState == STATE_UP) || (m_iState == STATE_DOWN))
return; return;
if (other.movetype == MOVETYPE_WALK) { if (eToucher.movetype == MOVETYPE_WALK) {
Trigger(other, TRIG_TOGGLE); Trigger(eToucher, TRIG_TOGGLE);
} }
} }
@ -405,10 +405,8 @@ func_door_rotating::Respawn(void)
m_flWait = 0.01f; m_flWait = 0.01f;
if (HasSpawnFlags(SF_ROT_USE)) { if (HasSpawnFlags(SF_ROT_USE)) {
touch = __NULL__;
PlayerUse = Use; PlayerUse = Use;
} else { } else {
touch = Touch;
PlayerUse = __NULL__; PlayerUse = __NULL__;
} }

View file

@ -33,12 +33,12 @@ class item_food:NSEntity
void(void) item_food; void(void) item_food;
virtual void(void) Setup; virtual void(void) Setup;
virtual void(void) Touch; virtual void(entity) Touch;
}; };
void item_food::Touch(void) void item_food::Touch(entity eToucher)
{ {
if (other.classname != "player") { if (eToucher.classname != "player") {
return; return;
} }
@ -47,7 +47,7 @@ void item_food::Touch(void)
bevOwner.m_iReady = TRUE; bevOwner.m_iReady = TRUE;
} }
Damage_Apply(other, this, -1, 0, DMG_GENERIC); Damage_Apply(eToucher, this, -1, 0, DMG_GENERIC);
SetSolid(SOLID_NOT); SetSolid(SOLID_NOT);
remove(this); remove(this);
} }
@ -56,7 +56,6 @@ void item_food::Setup(void)
{ {
SetSolid(SOLID_TRIGGER); SetSolid(SOLID_TRIGGER);
SetSize([-16,-16,-16], [16,16,16]); SetSize([-16,-16,-16], [16,16,16]);
touch = Touch;
if (m_iIsCan) { if (m_iIsCan) {
sound(this, CHAN_ITEM, "weapons/g_bounce3.wav", 1.0f, ATTN_NORM); sound(this, CHAN_ITEM, "weapons/g_bounce3.wav", 1.0f, ATTN_NORM);

View file

@ -50,7 +50,7 @@ class trigger_look:NSBrushTrigger
virtual void(float) Save; virtual void(float) Save;
virtual void(string, string) Restore; virtual void(string, string) Restore;
virtual void(void) Touch; virtual void(entity) Touch;
virtual void(void) Respawn; virtual void(void) Respawn;
virtual void(string, string) SpawnKey; virtual void(string, string) SpawnKey;
}; };
@ -95,7 +95,7 @@ trigger_look::Restore(string strKey, string strValue)
} }
void void
trigger_look::Touch(void) trigger_look::Touch(entity eToucher)
{ {
float dot; float dot;
entity lt; entity lt;
@ -103,7 +103,7 @@ trigger_look::Touch(void)
if (GetMaster() == FALSE) if (GetMaster() == FALSE)
return; return;
if (!(other.flags & FL_CLIENT)) { if (!(eToucher.flags & FL_CLIENT)) {
/* FIXME: could this conflict with other entities? probably. */ /* FIXME: could this conflict with other entities? probably. */
m_flLooked = 0.0f; m_flLooked = 0.0f;
return; return;
@ -118,7 +118,7 @@ trigger_look::Touch(void)
} }
/* test against the looktarget position */ /* test against the looktarget position */
makevectors(other.v_angle); makevectors(eToucher.v_angle);
vector v = normalize (lt.origin - other.origin); vector v = normalize (lt.origin - other.origin);
dot = v * v_forward; dot = v * v_forward;
@ -138,9 +138,9 @@ trigger_look::Touch(void)
SetSolid(SOLID_NOT); SetSolid(SOLID_NOT);
if (!target) if (!target)
UseOutput(other, m_strOnTrigger); UseOutput(eToucher, m_strOnTrigger);
else else
UseTargets(other, TRIG_TOGGLE, m_flDelay); UseTargets(eToucher, TRIG_TOGGLE, m_flDelay);
} }
void void

View file

@ -47,7 +47,6 @@ enumflags
class trigger_multiple:NSBrushTrigger class trigger_multiple:NSBrushTrigger
{ {
float m_flWait; float m_flWait;
entity m_eLastToucher;
/* Input/Output */ /* Input/Output */
string m_strOnStartTouch; string m_strOnStartTouch;
@ -58,31 +57,18 @@ class trigger_multiple:NSBrushTrigger
virtual void(float) Save; virtual void(float) Save;
virtual void(string, string) Restore; virtual void(string, string) Restore;
virtual void(void) touch; virtual void(entity) Touch;
virtual void(void) Respawn; virtual void(void) Respawn;
virtual void(string, string) SpawnKey; virtual void(string, string) SpawnKey;
virtual void(void) EndTouchCheck; virtual void(entity) EndTouch;
}; };
void void
trigger_multiple::EndTouchCheck(void) trigger_multiple::EndTouch(entity eToucher)
{ {
if (m_eLastToucher) { if (m_strOnEndTouchAll)
tracebox(origin, absmin, absmax, origin, MOVE_NORMAL, this); UseOutput(eToucher, m_strOnEndTouchAll);
if (!(trace_ent.flags & FL_CLIENT)) {
UseOutput(other, m_strOnEndTouchAll);
m_eLastToucher = __NULL__;
}
}
/* support for think/nextthink */
if (think && nextthink > 0.0f) {
if (nextthink < time) {
nextthink = 0.0f;
think();
}
}
} }
void void
@ -117,15 +103,15 @@ trigger_multiple::Restore(string strKey, string strValue)
} }
void void
trigger_multiple::touch(void) trigger_multiple::Touch(entity eToucher)
{ {
if (GetMaster() == FALSE) if (GetMaster() == FALSE)
return; return;
if (HasSpawnFlags(TM_NOCLIENTS) && other.flags & FL_CLIENT) if (HasSpawnFlags(TM_NOCLIENTS) && eToucher.flags & FL_CLIENT)
return; return;
if (!HasSpawnFlags(TM_MONSTERS) && other.flags & FL_MONSTER) if (!HasSpawnFlags(TM_MONSTERS) && eToucher.flags & FL_MONSTER)
return; return;
if (!HasSpawnFlags(TM_PUSHABLES) && other.classname == "func_pushable") if (!HasSpawnFlags(TM_PUSHABLES) && eToucher.classname == "func_pushable")
return; return;
if (Rules_IsTeamPlay() == TRUE) { if (Rules_IsTeamPlay() == TRUE) {
@ -136,9 +122,9 @@ trigger_multiple::touch(void)
/* if the target key isn't used, assume we're using the new I/O system */ /* if the target key isn't used, assume we're using the new I/O system */
if (!target) if (!target)
UseOutput(other, m_strOnStartTouch); UseOutput(eToucher, m_strOnStartTouch);
else else
UseTargets(other, TRIG_TOGGLE, m_flDelay); UseTargets(eToucher, TRIG_TOGGLE, m_flDelay);
/* This is effectively a trigger_once...*/ /* This is effectively a trigger_once...*/
if (m_flWait != -1) { if (m_flWait != -1) {
@ -147,17 +133,12 @@ trigger_multiple::touch(void)
} }
SetSolid(SOLID_NOT); SetSolid(SOLID_NOT);
m_eLastToucher = other;
} }
void void
trigger_multiple::Respawn(void) trigger_multiple::Respawn(void)
{ {
InitBrushTrigger(); InitBrushTrigger();
if (m_strOnEndTouchAll) {
customphysics = EndTouchCheck;
}
} }
void void

View file

@ -37,6 +37,11 @@ class NSEntity:NSTrigger
PREDICTED_FLOAT_N(flags); PREDICTED_FLOAT_N(flags);
PREDICTED_VECTOR_N(velocity); PREDICTED_VECTOR_N(velocity);
/* not needed to be saved right now */
float m_flTouchTime;
bool m_beingTouched;
entity m_eTouchLast;
#ifdef CLIENT #ifdef CLIENT
virtual void(float,float) ReceiveEntity; virtual void(float,float) ReceiveEntity;
virtual void(void) postdraw; virtual void(void) postdraw;
@ -83,6 +88,7 @@ class NSEntity:NSTrigger
nonvirtual string(void) GetSpawnModel; nonvirtual string(void) GetSpawnModel;
#endif #endif
/* sets */
virtual void(float) SetScale; virtual void(float) SetScale;
virtual void(entity) SetOwner; virtual void(entity) SetOwner;
virtual void(vector) SetVelocity; virtual void(vector) SetVelocity;
@ -92,11 +98,35 @@ class NSEntity:NSTrigger
virtual void(string) SetModel; virtual void(string) SetModel;
virtual void(float) SetModelindex; virtual void(float) SetModelindex;
virtual void(float) SetMovetype; virtual void(float) SetMovetype;
virtual void(float) SetGravity;
virtual void(vector) SetAngles; virtual void(vector) SetAngles;
virtual void(vector) SetAngularVelocity;
virtual void(vector) SetOrigin; virtual void(vector) SetOrigin;
virtual void(vector, vector) SetSize; virtual void(vector, vector) SetSize;
virtual void(float) AddFlags;
virtual void(float) RemoveFlags;
/* gets */
virtual float(void) GetScale;
virtual entity(void) GetOwner;
virtual vector(void) GetVelocity;
virtual float(void) GetSolid;
virtual string(void) GetModel;
virtual float(void) GetModelindex;
virtual float(void) GetMovetype;
virtual float(void) GetGravity;
virtual vector(void) GetAngles;
virtual vector(void) GetAngularVelocity;
virtual vector(void) GetOrigin;
virtual vector(void) GetMins;
virtual vector(void) GetMaxs;
virtual vector(void) GetRealMins;
virtual vector(void) GetRealMaxs;
virtual vector(void) GetAbsoluteMins;
virtual vector(void) GetAbsoluteMaxs;
virtual float(void) GetFlags;
virtual void(string, string) SpawnKey; virtual void(string, string) SpawnKey;
nonvirtual void(void) Destroy; virtual void(void) Destroy;
virtual void(void) UpdateBounds; virtual void(void) UpdateBounds;
/* useful methods, based on GMod's API */ /* useful methods, based on GMod's API */
@ -109,10 +139,14 @@ class NSEntity:NSTrigger
nonvirtual float(void) WaterLevel; nonvirtual float(void) WaterLevel;
nonvirtual bool(entity) Visible; nonvirtual bool(entity) Visible;
nonvirtual bool(vector) VisibleVec; nonvirtual bool(vector) VisibleVec;
nonvirtual entity(void) GetOwner;
nonvirtual bool(float) HasSpawnFlags; nonvirtual bool(float) HasSpawnFlags;
nonvirtual bool(void) IsOnGround; nonvirtual bool(void) IsOnGround;
nonvirtual entity(void) GetGroundEntity; nonvirtual entity(void) GetGroundEntity;
virtual void(entity) Blocked; virtual void(entity) Blocked;
nonvirtual void(void) _BlockedHandler; nonvirtual void(void) BlockedHandler;
virtual void(entity) StartTouch;
virtual void(entity) Touch;
virtual void(entity) EndTouch;
nonvirtual void(void) TouchHandler;
}; };

View file

@ -136,12 +136,6 @@ NSEntity::Visible(entity ent)
return (false); return (false);
} }
entity
NSEntity::GetOwner(void)
{
return owner;
}
bool bool
NSEntity::HasSpawnFlags(float sf) NSEntity::HasSpawnFlags(float sf)
{ {
@ -173,11 +167,46 @@ NSEntity::Blocked(entity eBlocker)
} }
void void
NSEntity::_BlockedHandler(void) NSEntity::BlockedHandler(void)
{ {
Blocked(other); Blocked(other);
} }
void
NSEntity::Touch(entity eToucher)
{
/* To be handled by sub-classes */
print("touched!\n");
}
void
NSEntity::StartTouch(entity eToucher)
{
/* To be handled by sub-classes */
print("start touched!\n");
}
void
NSEntity::EndTouch(entity eToucher)
{
/* To be handled by sub-classes */
print("end touched!\n");
}
void
NSEntity::TouchHandler(void)
{
/* start touch in case we haven't */
if (m_beingTouched != true)
StartTouch(other);
Touch(other);
m_flTouchTime = time;
m_beingTouched = true;
m_eTouchLast = other;
}
#ifdef CLIENT #ifdef CLIENT
/* /*
============ ============
@ -442,6 +471,14 @@ NSEntity::ParentUpdate(void)
} }
} }
} }
/* handle end-touch */
if (m_beingTouched == true)
if (m_flTouchTime < time) {
EndTouch(m_eTouchLast);
m_beingTouched = false;
m_eTouchLast = __NULL__;
}
} }
entity entity
NSEntity::GetParent(void) NSEntity::GetParent(void)
@ -486,9 +523,6 @@ NSEntity::SetOwner(entity newOwner)
void void
NSEntity::SetVelocity(vector vecNew) NSEntity::SetVelocity(vector vecNew)
{ {
if (vecNew == velocity)
return;
velocity = vecNew; velocity = vecNew;
}; };
@ -512,25 +546,23 @@ NSEntity::SetSendFlags(float flSendFlags)
void void
NSEntity::SetMovetype(float newMovetype) NSEntity::SetMovetype(float newMovetype)
{ {
if (newMovetype == movetype)
return;
movetype = newMovetype; movetype = newMovetype;
} }
void
NSEntity::SetGravity(float newGrav)
{
gravity = newGrav;
}
void void
NSEntity::SetSolid(float newSolid) NSEntity::SetSolid(float newSolid)
{ {
if (newSolid == solid)
return;
solid = newSolid; solid = newSolid;
} }
void void
NSEntity::SetScale(float newScale) NSEntity::SetScale(float newScale)
{ {
if (newScale == scale)
return;
scale = newScale; scale = newScale;
} }
@ -582,12 +614,15 @@ NSEntity::UpdateBounds(void)
void void
NSEntity::SetAngles(vector newAngles) NSEntity::SetAngles(vector newAngles)
{ {
if (newAngles == angles)
return;
angles = newAngles; angles = newAngles;
} }
void
NSEntity::SetAngularVelocity(vector newAvel)
{
avelocity = newAvel;
}
void void
NSEntity::SetSize(vector newMins, vector newMaxs) NSEntity::SetSize(vector newMins, vector newMaxs)
{ {
@ -606,9 +641,6 @@ NSEntity::SetSize(vector newMins, vector newMaxs)
void void
NSEntity::SetOrigin(vector newOrigin) NSEntity::SetOrigin(vector newOrigin)
{ {
if (newOrigin == origin)
return;
setorigin(this, newOrigin); setorigin(this, newOrigin);
} }
@ -631,6 +663,127 @@ NSEntity::SetModelindex(float newModelIndex)
SetSize(mins, maxs); SetSize(mins, maxs);
} }
void
NSEntity::AddFlags(float fl)
{
flags |= fl;
}
void
NSEntity::RemoveFlags(float fl)
{
flags &= ~fl;
}
float
NSEntity::GetScale(void)
{
return scale;
}
entity
NSEntity::GetOwner(void)
{
return owner;
}
vector
NSEntity::GetVelocity(void)
{
return velocity;
}
float
NSEntity::GetSolid(void)
{
return solid;
}
string
NSEntity::GetModel(void)
{
return model;
}
float
NSEntity::GetModelindex(void)
{
return modelindex;
}
float
NSEntity::GetMovetype(void)
{
return movetype;
}
float
NSEntity::GetGravity(void)
{
return gravity;
}
vector
NSEntity::GetAngles(void)
{
return angles;
}
vector
NSEntity::GetAngularVelocity(void)
{
return avelocity;
}
vector
NSEntity::GetOrigin(void)
{
return origin;
}
vector
NSEntity::GetMins(void)
{
return mins;
}
vector
NSEntity::GetMaxs(void)
{
return maxs;
}
vector
NSEntity::GetRealMins(void)
{
return m_vecMins;
}
vector
NSEntity::GetRealMaxs(void)
{
return m_vecMaxs;
}
vector
NSEntity::GetAbsoluteMins(void)
{
return absmin;
}
vector
NSEntity::GetAbsoluteMaxs(void)
{
return absmax;
}
float
NSEntity::GetFlags(void)
{
return flags;
}
#ifdef SERVER #ifdef SERVER
vector vector
NSEntity::GetSpawnOrigin(void) NSEntity::GetSpawnOrigin(void)
@ -870,7 +1023,8 @@ NSEntity::NSEntity(void)
m_oldOrigin = origin; m_oldOrigin = origin;
m_oldSolid = solid; m_oldSolid = solid;
m_oldModel = Util_FixModel(model); m_oldModel = Util_FixModel(model);
blocked = _BlockedHandler; blocked = BlockedHandler;
touch = TouchHandler;
/* Input/Output system */ /* Input/Output system */
m_strOnTrigger = CreateOutput(m_strOnTrigger); m_strOnTrigger = CreateOutput(m_strOnTrigger);