From b3ba5bfe2c494f2737e9e8d5387173b1008e5bdd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 4 Mar 2017 12:07:45 +0100 Subject: [PATCH] - allow 'const' on class functions. This is preferable to 'clearscope' so that the UI code can call getter functions without having to declare things as 'clearscope'. Clearscope is a dangerous context and should be limited to the minimum extent possible and preferably be blocked in user code. This may still need some work on const functions but better have it in now. --- src/scripting/zscript/zcc_compile.cpp | 4 ++++ wadsrc/static/zscript/actor.txt | 8 ++++---- wadsrc/static/zscript/inventory/powerups.txt | 2 +- wadsrc/static/zscript/inventory/weapons.txt | 2 +- wadsrc/static/zscript/shared/player.txt | 8 ++++---- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 2d5838b068..2000075c91 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2141,10 +2141,14 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool // [ZZ] supporting const self for actors is quite a cumbersome task because there's no concept of a const pointer (?) // either way, it doesn't make sense, because you can call any method on a readonly class instance. + + // The above is nonsense. This needs to work and needs to be implemented properly. + /* if ((f->Flags & ZCC_FuncConst) && (c->Type()->IsKindOf(RUNTIME_CLASS(PClass)))) { Error(f, "'Const' on a method can only be used in structs"); } + */ if ((f->Flags & ZCC_VarArg) && !(f->Flags & ZCC_Native)) { diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 56d9072fa2..233f75d408 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -425,7 +425,7 @@ class Actor : Thinker native } } - clearscope virtual String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) + virtual String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) const { if (mod == 'Telefrag') { @@ -450,13 +450,13 @@ class Actor : Thinker native native static int FindUniqueTid(int start = 0, int limit = 0); native void SetShade(color col); - clearscope native string GetTag(string defstr = ""); + native string GetTag(string defstr = "") const; native void SetTag(string defstr = ""); native double GetBobOffset(double frac = 0); native void ClearCounters(); native bool GiveBody (int num, int max=0); native bool HitFloor(); - clearscope native bool isTeammate(Actor other); + native bool isTeammate(Actor other) const; native int PlayerNumber(); native void SetFriendPlayer(PlayerInfo player); native void SoundAlert(Actor target, bool splash = false, double maxdist = 0); @@ -597,7 +597,7 @@ class Actor : Thinker native native void ClearInventory(); native bool GiveInventory(class type, int amount, bool givecheat = false); native bool TakeInventory(class itemclass, int amount, bool fromdecorate = false, bool notakeinfinite = false); - clearscope native Inventory FindInventory(class itemtype, bool subclass = false); + native Inventory FindInventory(class itemtype, bool subclass = false) const; native Inventory GiveInventoryType(class itemtype); native Inventory DropInventory (Inventory item, int amt = -1); native bool UseInventory(Inventory item); diff --git a/wadsrc/static/zscript/inventory/powerups.txt b/wadsrc/static/zscript/inventory/powerups.txt index d4d78d1192..f6b14a051e 100644 --- a/wadsrc/static/zscript/inventory/powerups.txt +++ b/wadsrc/static/zscript/inventory/powerups.txt @@ -285,7 +285,7 @@ class Powerup : Inventory // //=========================================================================== - virtual clearscope bool isBlinking() + virtual bool isBlinking() const { return (EffectTics <= BLINKTHRESHOLD && (EffectTics & 8) && !bNoScreenBlink); } diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index 860d387e27..0eba93bf8f 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -89,7 +89,7 @@ class Weapon : StateProvider native return s; } - override String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) + override String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) const { // Weapons may never return HitObituary by default. Override this if it is needed. return Obituary; diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index d6ea5b8433..cbb361687d 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -119,7 +119,7 @@ class PlayerPawn : Actor native } } - override String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) + override String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) const { if (victim.player != player && victim.IsTeammate(self)) { @@ -150,7 +150,7 @@ class PlayerPawn : Actor native } // This is for SBARINFO. - clearscope int, int GetEffectTicsForItem(class item) + int, int GetEffectTicsForItem(class item) const { let pg = (class)(item); if (pg != null) @@ -167,10 +167,10 @@ class PlayerPawn : Actor native return -1, -1; } - clearscope native int GetMaxHealth(bool withupgrades = false); + native int GetMaxHealth(bool withupgrades = false) const; native bool ResetAirSupply (bool playgasp = false); native void CheckWeaponSwitch(class item); - clearscope native static String GetPrintableDisplayName(Class cls); + native clearscope static String GetPrintableDisplayName(Class cls); }