2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** dobject.h
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DOBJECT_H__
|
|
|
|
#define __DOBJECT_H__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "tarray.h"
|
|
|
|
#include "doomtype.h"
|
2006-05-16 02:50:18 +00:00
|
|
|
#include "m_alloc.h"
|
2006-09-27 04:56:18 +00:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
#include "autosegs.h"
|
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
struct PClass;
|
2006-05-09 22:10:43 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
class FArchive;
|
|
|
|
|
|
|
|
class DObject;
|
|
|
|
class DArgs;
|
|
|
|
class DBoundingBox;
|
|
|
|
class DCanvas;
|
|
|
|
class DConsoleCommand;
|
|
|
|
class DConsoleAlias;
|
|
|
|
class DSeqNode;
|
|
|
|
class DSeqActorNode;
|
|
|
|
class DSeqPolyNode;
|
|
|
|
class DSeqSectorNode;
|
|
|
|
class DThinker;
|
|
|
|
class AActor;
|
|
|
|
class DPolyAction;
|
|
|
|
class DMovePoly;
|
|
|
|
class DPolyDoor;
|
|
|
|
class DRotatePoly;
|
|
|
|
class DPusher;
|
|
|
|
class DScroller;
|
|
|
|
class DSectorEffect;
|
|
|
|
class DLighting;
|
|
|
|
class DFireFlicker;
|
|
|
|
class DFlicker;
|
|
|
|
class DGlow;
|
|
|
|
class DGlow2;
|
|
|
|
class DLightFlash;
|
|
|
|
class DPhased;
|
|
|
|
class DStrobe;
|
|
|
|
class DMover;
|
|
|
|
class DElevator;
|
|
|
|
class DMovingCeiling;
|
|
|
|
class DCeiling;
|
|
|
|
class DDoor;
|
|
|
|
class DMovingFloor;
|
|
|
|
class DFloor;
|
|
|
|
class DFloorWaggle;
|
|
|
|
class DPlat;
|
|
|
|
class DPillar;
|
|
|
|
|
|
|
|
struct FActorInfo;
|
|
|
|
|
|
|
|
enum EMetaType
|
|
|
|
{
|
|
|
|
META_Int, // An int
|
|
|
|
META_Fixed, // A fixed point number
|
|
|
|
META_String, // A string
|
|
|
|
};
|
|
|
|
|
|
|
|
class FMetaData
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
FMetaData (EMetaType type, DWORD id) : Type(type), ID(id) {}
|
|
|
|
|
|
|
|
FMetaData *Next;
|
|
|
|
EMetaType Type;
|
|
|
|
DWORD ID;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int Int;
|
|
|
|
char *String;
|
|
|
|
fixed_t Fixed;
|
|
|
|
} Value;
|
|
|
|
|
|
|
|
friend class FMetaTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FMetaTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FMetaTable() : Meta(NULL) {}
|
|
|
|
FMetaTable(const FMetaTable &other);
|
|
|
|
~FMetaTable();
|
|
|
|
FMetaTable &operator = (const FMetaTable &other);
|
|
|
|
|
|
|
|
void SetMetaInt (DWORD id, int parm);
|
|
|
|
void SetMetaFixed (DWORD id, fixed_t parm);
|
|
|
|
void SetMetaString (DWORD id, const char *parm); // The string is copied
|
|
|
|
|
2006-03-03 03:57:01 +00:00
|
|
|
int GetMetaInt (DWORD id, int def=0) const;
|
|
|
|
fixed_t GetMetaFixed (DWORD id, fixed_t def=0) const;
|
2006-02-24 04:48:15 +00:00
|
|
|
const char *GetMetaString (DWORD id) const;
|
|
|
|
|
|
|
|
FMetaData *FindMeta (EMetaType type, DWORD id) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FMetaData *Meta;
|
|
|
|
FMetaData *FindMetaDef (EMetaType type, DWORD id);
|
|
|
|
void FreeMeta ();
|
|
|
|
void CopyMeta (const FMetaTable *other);
|
|
|
|
};
|
|
|
|
|
2006-05-09 22:10:43 +00:00
|
|
|
#define RUNTIME_TYPE(object) (object->GetClass()) // Passed an object, returns the type of that object
|
2006-05-10 02:40:43 +00:00
|
|
|
#define RUNTIME_CLASS(cls) (&cls::_StaticType) // Passed a class name, returns a PClass representing that class
|
|
|
|
#define NATIVE_TYPE(object) (object->StaticType()) // Passed an object, returns the type of the C++ class representing the object
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-05-09 22:10:43 +00:00
|
|
|
struct ClassReg
|
|
|
|
{
|
2006-05-10 02:40:43 +00:00
|
|
|
PClass *MyClass;
|
2006-02-24 04:48:15 +00:00
|
|
|
const char *Name;
|
2006-05-10 02:40:43 +00:00
|
|
|
PClass *ParentType;
|
2006-02-24 04:48:15 +00:00
|
|
|
unsigned int SizeOf;
|
2006-05-10 02:40:43 +00:00
|
|
|
const size_t *Pointers;
|
2006-02-24 04:48:15 +00:00
|
|
|
void (*ConstructNative)(void *);
|
|
|
|
|
2006-05-09 22:10:43 +00:00
|
|
|
void RegisterClass();
|
2006-02-24 04:48:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EInPlace { EC_InPlace };
|
|
|
|
|
|
|
|
#define DECLARE_ABSTRACT_CLASS(cls,parent) \
|
|
|
|
public: \
|
2006-05-10 02:40:43 +00:00
|
|
|
static PClass _StaticType; \
|
|
|
|
virtual PClass *StaticType() const { return &_StaticType; } \
|
|
|
|
static ClassReg RegistrationInfo, *RegistrationInfoPtr; \
|
2006-02-24 04:48:15 +00:00
|
|
|
private: \
|
|
|
|
typedef parent Super; \
|
|
|
|
typedef cls ThisClass;
|
|
|
|
|
|
|
|
#define DECLARE_CLASS(cls,parent) \
|
|
|
|
DECLARE_ABSTRACT_CLASS(cls,parent) \
|
|
|
|
private: static void InPlaceConstructor (void *mem);
|
|
|
|
|
|
|
|
#define HAS_OBJECT_POINTERS \
|
|
|
|
static const size_t PointerOffsets[];
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
#define DECLARE_POINTER(field) (size_t)&((ThisClass*)1)->field - 1,
|
|
|
|
#define END_POINTERS ~0 };
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma data_seg(".creg$u")
|
|
|
|
# pragma data_seg()
|
|
|
|
# define _DECLARE_TI(cls) __declspec(allocate(".creg$u")) ClassReg *cls::RegistrationInfoPtr = &cls::RegistrationInfo;
|
2006-02-24 04:48:15 +00:00
|
|
|
#else
|
2006-09-20 00:08:22 +00:00
|
|
|
# define _DECLARE_TI(cls) ClassReg *cls::RegistrationInfoPtr __attribute__((section(CREG_SECTION))) = &cls::RegistrationInfo;
|
2006-05-10 02:40:43 +00:00
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
#define _IMP_PCLASS(cls,ptrs,create) \
|
|
|
|
PClass cls::_StaticType; \
|
|
|
|
ClassReg cls::RegistrationInfo = {\
|
|
|
|
RUNTIME_CLASS(cls), \
|
|
|
|
#cls, \
|
|
|
|
RUNTIME_CLASS(cls::Super), \
|
|
|
|
sizeof(cls), \
|
|
|
|
ptrs, \
|
|
|
|
create }; \
|
2006-02-24 04:48:15 +00:00
|
|
|
_DECLARE_TI(cls)
|
|
|
|
|
|
|
|
#define _IMP_CREATE_OBJ(cls) \
|
|
|
|
void cls::InPlaceConstructor(void *mem) { new((EInPlace *)mem) cls; }
|
|
|
|
|
|
|
|
#define IMPLEMENT_POINTY_CLASS(cls) \
|
|
|
|
_IMP_CREATE_OBJ(cls) \
|
2006-05-10 02:40:43 +00:00
|
|
|
_IMP_PCLASS(cls,cls::PointerOffsets,cls::InPlaceConstructor) \
|
2006-02-24 04:48:15 +00:00
|
|
|
const size_t cls::PointerOffsets[] = {
|
|
|
|
|
|
|
|
#define IMPLEMENT_CLASS(cls) \
|
|
|
|
_IMP_CREATE_OBJ(cls) \
|
2006-05-10 02:40:43 +00:00
|
|
|
_IMP_PCLASS(cls,NULL,cls::InPlaceConstructor)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#define IMPLEMENT_ABSTRACT_CLASS(cls) \
|
2006-05-10 02:40:43 +00:00
|
|
|
_IMP_PCLASS(cls,NULL,NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
enum EObjectFlags
|
|
|
|
{
|
|
|
|
OF_MassDestruction = 0x00000001, // Object is queued for deletion
|
|
|
|
OF_Cleanup = 0x00000002, // Object is being deconstructed as a result of a queued deletion
|
|
|
|
OF_JustSpawned = 0x00000004, // Thinker was spawned this tic
|
|
|
|
OF_SerialSuccess = 0x10000000 // For debugging Serialize() calls
|
|
|
|
};
|
|
|
|
|
|
|
|
class DObject
|
|
|
|
{
|
2006-05-10 02:40:43 +00:00
|
|
|
public:
|
|
|
|
static PClass _StaticType;
|
|
|
|
virtual PClass *StaticType() const { return &_StaticType; }
|
|
|
|
static ClassReg RegistrationInfo, *RegistrationInfoPtr;
|
2006-05-09 22:10:43 +00:00
|
|
|
static void InPlaceConstructor (void *mem);
|
2006-05-10 02:40:43 +00:00
|
|
|
private:
|
2006-02-24 04:48:15 +00:00
|
|
|
typedef DObject ThisClass;
|
|
|
|
|
2006-05-09 22:10:43 +00:00
|
|
|
// Per-instance variables. There are three.
|
2006-02-24 04:48:15 +00:00
|
|
|
public:
|
2006-05-09 22:10:43 +00:00
|
|
|
DWORD ObjectFlags; // Flags for this object
|
|
|
|
private:
|
2006-05-10 02:40:43 +00:00
|
|
|
PClass *Class; // This object's type
|
|
|
|
unsigned int Index; // This object's index in the global object table
|
2006-05-09 22:10:43 +00:00
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
public:
|
2006-02-24 04:48:15 +00:00
|
|
|
DObject ();
|
2006-05-10 02:40:43 +00:00
|
|
|
DObject (PClass *inClass);
|
2006-02-24 04:48:15 +00:00
|
|
|
virtual ~DObject ();
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
inline bool IsKindOf (const PClass *base) const;
|
|
|
|
inline bool IsA (const PClass *type) const;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
virtual void Serialize (FArchive &arc);
|
|
|
|
|
|
|
|
// For catching Serialize functions in derived classes
|
|
|
|
// that don't call their base class.
|
|
|
|
void CheckIfSerialized () const;
|
|
|
|
|
|
|
|
virtual void Destroy ();
|
|
|
|
|
|
|
|
static void BeginFrame ();
|
|
|
|
static void EndFrame ();
|
|
|
|
|
|
|
|
// If you need to replace one object with another and want to
|
|
|
|
// change any pointers from the old object to the new object,
|
|
|
|
// use this method.
|
|
|
|
static void PointerSubstitution (DObject *old, DObject *notOld);
|
|
|
|
|
2006-05-12 03:14:40 +00:00
|
|
|
static void StaticShutdown ();
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
PClass *GetClass() const
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (Class == NULL)
|
|
|
|
{
|
|
|
|
// Save a little time the next time somebody wants this object's type
|
|
|
|
// by recording it now.
|
|
|
|
const_cast<DObject *>(this)->Class = StaticType();
|
|
|
|
}
|
|
|
|
return Class;
|
|
|
|
}
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
void SetClass (PClass *inClass)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
Class = inClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *operator new(size_t len)
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
return M_Malloc(len);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete (void *mem)
|
|
|
|
{
|
|
|
|
free (mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2006-05-10 02:40:43 +00:00
|
|
|
// This form of placement new and delete is for use *only* by PClass's
|
2006-02-24 04:48:15 +00:00
|
|
|
// CreateNew() method. Do not use them for some other purpose.
|
|
|
|
void *operator new(size_t len, EInPlace *mem)
|
|
|
|
{
|
|
|
|
return (void *)mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete (void *mem, EInPlace *foo)
|
|
|
|
{
|
|
|
|
free (mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static TArray<DObject *> Objects;
|
2006-06-01 00:05:03 +00:00
|
|
|
static TArray<unsigned int> FreeIndices;
|
2006-02-24 04:48:15 +00:00
|
|
|
static TArray<DObject *> ToDestroy;
|
|
|
|
|
|
|
|
static void DestroyScan (DObject *obj);
|
|
|
|
static void DestroyScan ();
|
|
|
|
|
|
|
|
void RemoveFromArray ();
|
|
|
|
|
|
|
|
static bool Inactive;
|
|
|
|
};
|
|
|
|
|
2006-05-09 22:10:43 +00:00
|
|
|
#include "dobjtype.h"
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
inline bool DObject::IsKindOf (const PClass *base) const
|
2006-05-09 22:10:43 +00:00
|
|
|
{
|
|
|
|
return base->IsAncestorOf (GetClass ());
|
|
|
|
}
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
inline bool DObject::IsA (const PClass *type) const
|
2006-05-09 22:10:43 +00:00
|
|
|
{
|
|
|
|
return (type == GetClass());
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
#endif //__DOBJECT_H__
|