#ifdef MENUQC
#define NULL (0, null_entity)
+ #define world NULL
#else
#define NULL (0, world)
#endif
.vector origin;
.bool pure_data;
-/** @deprecated, use new_pure or NEW(class) */
+/** @deprecated use new_pure or NEW(class) */
#define make_pure(e) \
MACRO_BEGIN \
{ \
#define EVAL_entityclass(...) __VA_ARGS__
#define entityclass_1(name) entityclass_2(name, Object)
#ifndef QCC_SUPPORT_ENTITYCLASS
- #define entityclass_2(name, base) typedef entity name
+ #define entityclass_2(name, base) USING(name, entity)
#define class(name)
#define _new(class, pure) __spawn( #class, __FILE__ ":" STR(__LINE__), pure)
#else
// 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__) \
{ \
}
#define VTBL(cname, base) \
- INIT_STATIC(cname); \
+ _INIT_STATIC(cname); \
entity cname##_vtbl; \
void cname##_vtbl_init() \
{ \
} \
ACCUMULATE_FUNCTION(RegisterClasses, cname##_vtbl_init)
-#define INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this)
+#define _INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this)
#define INIT(cname) [[accumulate]] cname spawn##cname##_1(cname this)
#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; } \
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; \
#define METHOD(cname, name, prototype) \
STATIC_METHOD(cname, name, prototype); \
class(cname) .prototype name; \
- INIT_STATIC(cname) \
+ _INIT_STATIC(cname) \
{ \
this.name = METHOD_REFERENCE(cname, name); \
} \
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); \
} \
this.name = val; \
}
+#define STATIC_ATTRIB(cname, name, type, val) \
+ type cname##_##name; \
+ _INIT_STATIC(cname) \
+ { \
+ noref bool strzone; /* Error on strzone() calls. */ \
+ cname##_##name = val; \
+ }
+
+// cleanup potentially zoned strings from base classes
+
#define ATTRIB_STRZONE(cname, name, type, val) \
class(cname).type name; \
INIT(cname) \
this.name = strzone(val); \
}
+#define STATIC_ATTRIB_STRZONE(cname, name, type, val) \
+ type cname##_##name; \
+ _INIT_STATIC(cname) \
+ { \
+ if (cname##_##name) \
+ strunzone(cname##_##name); \
+ cname##_##name = val; \
+ }
+
#define ATTRIBARRAY(cname, name, type, cnt) \
class(cname).type name[cnt];