]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/oo.qh
Put pure entities in the corners of the map instead of out of bounds, fixes heavy...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / oo.qh
index 45fbb2627dd1f6d947c0aa0b61c2c1ad83ee9715..cf3a51f3aeaa10dc503b14a63dcad4c4220ec0a2 100644 (file)
@@ -6,6 +6,7 @@
 
 #ifdef MENUQC
        #define NULL (0, null_entity)
+       #define world NULL
 #else
        #define NULL (0, world)
 #endif
@@ -49,10 +50,10 @@ entity __spawn(string _classname, string _sourceLoc, bool pure)
        if (pure) {
                make_pure(this);
                #ifdef CSQC
-               setorigin(this, '0 0 10000');
+               setorigin(this, world.mins + '0 0 20');
                #endif
                #ifdef SVQC
-        setorigin(this, '0 0 -10000');
+        setorigin(this, world.maxs - '0 0 20');
         #endif
        }
        return this;
@@ -105,20 +106,38 @@ void clearentity(entity e)
 // Classes have a `spawn##cname(entity)` constructor
 // The parameter is used across [[accumulate]] functions
 
+.bool transmute;
+
 // Macros to hide this implementation detail:
 #ifdef __STDC__
        #define NEW(cname, ...) \
                OVERLOAD_(spawn##cname, new_pure(cname) P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
+
+    #define _TRANSMUTE(cname, this, ...) \
+        OVERLOAD_(spawn##cname, this P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
+
        #define CONSTRUCT(cname, ...) \
                OVERLOAD_(spawn##cname, this P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
 #else
        #define NEW(cname, ...) \
                OVERLOAD(spawn##cname, new_pure(cname),##__VA_ARGS__)
 
+    #define _TRANSMUTE(cname, this, ...) \
+        OVERLOAD(spawn##cname, this,##__VA_ARGS__)
+
        #define CONSTRUCT(cname, ...) \
                OVERLOAD(spawn##cname, this,##__VA_ARGS__)
 #endif
 
+#define TRANSMUTE(cname, this, ...) MACRO_BEGIN \
+    entity _e = (this); \
+    if (_e.vtblbase != cname##_vtbl) { \
+        _e.transmute = true; \
+        _e.classname = #cname; \
+        _TRANSMUTE(cname, _e, __VA_ARGS__); \
+    } \
+    MACRO_END
+
 #define CONSTRUCTOR(cname, ...) \
        cname OVERLOAD(spawn##cname, cname this, __VA_ARGS__) \
        { \
@@ -154,25 +173,27 @@ STATIC_INIT(RegisterClasses)
 
 #define CLASS(cname, base)                  \
        entityclass(cname, base);               \
-       class(cname).bool instanceOf##cname;   \
+       class(cname).bool instanceOf##cname;    \
     bool is_##cname(entity e) { return e.instanceOf##cname; } \
+    void isnt_##cname(entity e) { eprint(e); } \
        VTBL(cname, base)                       \
-       _INIT_STATIC(cname) \
-       {                    \
-               if (cname##_vtbl\
-               {                 \
+       _INIT_STATIC(cname)                     \
+       {                                       \
+               if (cname##_vtbl && !this.transmute)\
+               {                                   \
                        copyentity(cname##_vtbl, this); \
                        return;                         \
                }                                   \
                spawn##base##_static(this);         \
                this.instanceOf##cname = true;      \
        }                                       \
-       INIT(cname) \
-       {                           \
+       INIT(cname)                             \
+       {                                       \
                /* Only statically initialize the current class, it contains everything it inherits */ \
                if (cname##_vtbl.vtblname == this.classname) \
-               { \
+               {                                   \
                        spawn##cname##_static(this);    \
+                       this.transmute = false;         \
                        this.classname = #cname;        \
                        this.vtblname = string_null;    \
                        this.vtblbase = cname##_vtbl;   \
@@ -200,6 +221,7 @@ STATIC_INIT(RegisterClasses)
     METHOD(cname, dtor, void(cname this)) \
     { \
         METHOD_REFERENCE(cname, dtorimpl)(this); \
+        this.instanceOf##cname = false; \
         entity super = SUPER(cname); \
         if (super != cname##_vtbl) super.dtor(this); \
     } \