]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Type check macros
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 22 Mar 2016 04:15:34 +0000 (15:15 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 22 Mar 2016 04:15:34 +0000 (15:15 +1100)
qcsrc/common/state.qh
qcsrc/lib/_all.inc
qcsrc/lib/oo.qh
qcsrc/server/_all.qh
qcsrc/server/cl_client.qc

index 64ae3e7fe62f087accb4e01d0cfd65ba428940eb..90c7029e357be1152f3fd85db8cc342d7c3b9b22 100644 (file)
@@ -24,11 +24,7 @@ CLASS(PlayerState, Object)
 ENDCLASS(PlayerState)
 
 .PlayerState _ps;
-#if NDEBUG
-       #define PS(this) (this._ps)
-#else
-       PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; }
-#endif
+#define PS(this) (this._ps)
 
 // TODO: renew on death
 void PlayerState_attach(entity this);
index 9aaf524493719d0171363d086cfd29db0944bf05..212ba4a5de566b0b0894a336f2d6dd54365dda0e 100644 (file)
        #include <dpdefs/keycodes.qh>
 #endif
 
+#include "bool.qh"
+#include "int.qh"
+
 #include "macro.qh"
 
+#ifndef NDEBUG
+    #define TC(T, sym) MACRO_BEGIN \
+        if (!is_##T(sym)) LOG_WARNINGF("Type check failed: " #sym " :: " #T); \
+    MACRO_END
+#else
+    #define TC(T, sym) MACRO_BEGIN MACRO_END
+#endif
+
+bool is_int(float f) { return f == f | 0; }
+bool is_bool(float f) { return f == true || f == false; }
+
 #include "warpzone/mathlib.qc"
 
 #include "accumulate.qh"
 #include "angle.qc"
 #include "arraylist.qh"
 #include "bits.qh"
-#include "bool.qh"
 #include "color.qh"
 #include "counting.qh"
 #include "cvar.qh"
@@ -43,7 +56,6 @@
 #include "file.qh"
 #include "functional.qh"
 #include "i18n.qh"
-#include "int.qh"
 #include "iter.qh"
 #include "lazy.qh"
 #include "linkedlist.qh"
index 0638c932b3e13fb11868a78568ebeba598b8188c..637dbe92423c36a3546ba9145a6cf25597577e62 100644 (file)
@@ -155,6 +155,7 @@ STATIC_INIT(RegisterClasses)
 #define CLASS(cname, base)                  \
        entityclass(cname, base);               \
        class(cname).bool instanceOf##cname;   \
+    bool is_##cname(entity e) { return e.instanceOf##cname; } \
        VTBL(cname, base)                       \
        INIT_STATIC(cname) \
        {                    \
index c43605435e389cb13d1cbfb893d6fac48b43dcc7..f12a715aa31c3e1bd281763a731fcaff5229f4fd 100644 (file)
@@ -11,6 +11,7 @@ const string STR_OBSERVER = "observer";
 #define IS_OBSERVER(v) ((v).classname == STR_OBSERVER)
 
 #define IS_CLIENT(v) (v.flags & FL_CLIENT)
+#define is_client IS_CLIENT
 #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT)
 #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL)
 #define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT)
index 34800eafff68fbbe54d08bdfe8f267a61d48a2ca..532868884de769afed1022addbab8e4057b73965 100644 (file)
@@ -1540,6 +1540,8 @@ spectate mode routines
 
 void SpectateCopy(entity this, entity spectatee)
 {
+    TC(Client, this); TC(Client, spectatee);
+
        MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
        PS(this) = PS(spectatee);
        this.armortype = spectatee.armortype;