mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
Provide a way to expose a native class to zscript for virtual functions overriding
This commit is contained in:
parent
ad19e439a6
commit
33e2c74642
4 changed files with 24 additions and 13 deletions
|
@ -57,14 +57,15 @@
|
|||
|
||||
ClassReg DObject::RegistrationInfo =
|
||||
{
|
||||
NULL, // MyClass
|
||||
"DObject", // Name
|
||||
NULL, // ParentType
|
||||
NULL, // Pointers
|
||||
&DObject::InPlaceConstructor, // ConstructNative
|
||||
&DObject::InitNativeFields,
|
||||
sizeof(DObject), // SizeOf
|
||||
CLASSREG_PClass, // MetaClassNum
|
||||
nullptr, // MyClass
|
||||
"DObject", // Name
|
||||
nullptr, // ParentType
|
||||
&DVMObject<DObject>::RegistrationInfo, // VMExport
|
||||
nullptr, // Pointers
|
||||
&DObject::InPlaceConstructor, // ConstructNative
|
||||
&DObject::InitNativeFields, // InitNatives
|
||||
sizeof(DObject), // SizeOf
|
||||
CLASSREG_PClass, // MetaClassNum
|
||||
};
|
||||
_DECLARE_TI(DObject)
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ struct ClassReg
|
|||
PClass *MyClass;
|
||||
const char *Name;
|
||||
ClassReg *ParentType;
|
||||
ClassReg *VMExport;
|
||||
const size_t *Pointers;
|
||||
void (*ConstructNative)(void *);
|
||||
void(*InitNatives)();
|
||||
|
@ -186,11 +187,12 @@ protected: \
|
|||
# define _DECLARE_TI(cls) ClassReg * const cls::RegistrationInfoPtr __attribute__((section(SECTION_CREG))) = &cls::RegistrationInfo;
|
||||
#endif
|
||||
|
||||
#define _IMP_PCLASS(cls, ptrs, create, initn) \
|
||||
#define _IMP_PCLASS(cls, ptrs, create, initn, vmexport) \
|
||||
ClassReg cls::RegistrationInfo = {\
|
||||
nullptr, \
|
||||
#cls, \
|
||||
&cls::Super::RegistrationInfo, \
|
||||
vmexport, \
|
||||
ptrs, \
|
||||
create, \
|
||||
initn, \
|
||||
|
@ -199,9 +201,9 @@ protected: \
|
|||
_DECLARE_TI(cls) \
|
||||
PClass *cls::StaticType() const { return RegistrationInfo.MyClass; }
|
||||
|
||||
#define IMPLEMENT_CLASS(cls, isabstract, ptrs, fields) \
|
||||
#define IMPLEMENT_CLASS(cls, isabstract, ptrs, fields, vmexport) \
|
||||
_X_CONSTRUCTOR_##isabstract##(cls) \
|
||||
_IMP_PCLASS(cls, _X_POINTERS_##ptrs##(cls), _X_ABSTRACT_##isabstract##(cls), _X_FIELDS_##fields##(cls))
|
||||
_IMP_PCLASS(cls, _X_POINTERS_##ptrs##(cls), _X_ABSTRACT_##isabstract##(cls), _X_FIELDS_##fields##(cls), _X_VMEXPORT_##vmexport##(cls))
|
||||
|
||||
// Taking the address of a field in an object at address 1 instead of
|
||||
// address 0 keeps GCC from complaining about possible misuse of offsetof.
|
||||
|
@ -218,6 +220,8 @@ protected: \
|
|||
#define _X_CONSTRUCTOR_false(cls) void cls::InPlaceConstructor(void *mem) { new((EInPlace *)mem) cls; }
|
||||
#define _X_ABSTRACT_true(cls) nullptr
|
||||
#define _X_ABSTRACT_false(cls) cls::InPlaceConstructor
|
||||
#define _X_VMEXPORT_true(cls) &DVMObject<cls>::RegistrationInfo
|
||||
#define _X_VMEXPORT_false(cls) nullptr
|
||||
|
||||
enum EObjectFlags
|
||||
{
|
||||
|
@ -643,6 +647,7 @@ ClassReg DVMObject<T>::RegistrationInfo =
|
|||
DVMObject<T>::FormatClassName(),
|
||||
&DVMObject<T>::Super::RegistrationInfo,
|
||||
nullptr,
|
||||
nullptr,
|
||||
DVMObject<T>::InPlaceConstructor,
|
||||
nullptr,
|
||||
sizeof(DVMObject<T>),
|
||||
|
|
|
@ -2847,7 +2847,7 @@ PClass *ClassReg::RegisterClass()
|
|||
assert(0 && "Class registry has an invalid meta class identifier");
|
||||
}
|
||||
|
||||
if (metaclasses[MetaClassNum]->MyClass == NULL)
|
||||
if (metaclasses[MetaClassNum]->MyClass == nullptr)
|
||||
{ // Make sure the meta class is already registered before registering this one
|
||||
metaclasses[MetaClassNum]->RegisterClass();
|
||||
}
|
||||
|
@ -2855,10 +2855,14 @@ PClass *ClassReg::RegisterClass()
|
|||
|
||||
SetupClass(cls);
|
||||
cls->InsertIntoHash();
|
||||
if (ParentType != NULL)
|
||||
if (ParentType != nullptr)
|
||||
{
|
||||
cls->ParentClass = ParentType->RegisterClass();
|
||||
}
|
||||
if (VMExport != nullptr)
|
||||
{
|
||||
cls->VMExported = VMExport->RegisterClass();
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
|
||||
|
|
|
@ -769,6 +769,7 @@ public:
|
|||
|
||||
// Per-class information -------------------------------------
|
||||
PClass *ParentClass; // the class this class derives from
|
||||
PClass *VMExported; // this is here to allow script classes to override native virtual functions
|
||||
const size_t *Pointers; // object pointers defined by this class *only*
|
||||
const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default
|
||||
BYTE *Defaults;
|
||||
|
|
Loading…
Reference in a new issue