You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a type-erased entity (CBaseEntity, CBattleEntity, or any entity in Lua) there is a lot of checking to find out "are you a mob, are you a character" etc. before additional logic is applied to them.
We have two mechanisms for this:
auto* entityPtr = ...; // From somewhereif (constauto* PChar = dynamic_cast<CCharEntity*>(entityPtr))
{
// Use PChar as you'd like
}
and
auto* entityPtr = ...; // From somewhereif (entityPtr && entityPtr->objtype == TYPE_CHAR)
{
constauto* PChar = static_cast<CCharEntity*>(entityPtr);
// Use PChar as you'd like
}
These are equivalent, but the objtype-based method is a lot more verbose and leaves a lot of room for people to skip a nullptr check, just go straight for the static_cast or a C-style cast, etc.
My proposal is to remove objtype from CBaseEntity and enforce the use of dynamic_cast everywhere where we're trying to determine what an entity is.
This will also be reflected in Lua where we won't check like this: caster:getObjType() == xi.objType.PC, but we'll just use a helper of: caster:isPC()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When using a type-erased entity (CBaseEntity, CBattleEntity, or any entity in Lua) there is a lot of checking to find out "are you a mob, are you a character" etc. before additional logic is applied to them.
We have two mechanisms for this:
and
These are equivalent, but the objtype-based method is a lot more verbose and leaves a lot of room for people to skip a nullptr check, just go straight for the static_cast or a C-style cast, etc.
My proposal is to remove
objtype
from CBaseEntity and enforce the use of dynamic_cast everywhere where we're trying to determine what an entity is.This will also be reflected in Lua where we won't check like this:
caster:getObjType() == xi.objType.PC
, but we'll just use a helper of:caster:isPC()
Beta Was this translation helpful? Give feedback.
All reactions