|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: dobject.h 1788 2010-08-24 04:42:57Z russellrice $ 00005 // 00006 // Copyright (C) 1998-2006 by Randy Heit (ZDoom). 00007 // Copyright (C) 2006-2010 by The Odamex Team. 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // DESCRIPTION: 00020 // Data objects (?) 00021 // 00022 //----------------------------------------------------------------------------- 00023 00024 00025 #ifndef __DOBJECT_H__ 00026 #define __DOBJECT_H__ 00027 00028 #include <stdlib.h> 00029 #include "tarray.h" 00030 #include "doomtype.h" 00031 00032 class FArchive; 00033 00034 class DObject; 00035 class DArgs; 00036 class DBoundingBox; 00037 class DCanvas; 00038 class DConsoleCommand; 00039 class DConsoleAlias; 00040 class DSeqNode; 00041 class DSeqActorNode; 00042 class DSeqSectorNode; 00043 class DThinker; 00044 class AActor; 00045 class DPusher; 00046 class DScroller; 00047 class DSectorEffect; 00048 class DLighting; 00049 class DFireFlicker; 00050 class DFlicker; 00051 class DGlow; 00052 class DGlow2; 00053 class DLightFlash; 00054 class DPhased; 00055 class DStrobe; 00056 class DMover; 00057 class DElevator; 00058 class DMovingCeiling; 00059 class DCeiling; 00060 class DDoor; 00061 class DMovingFloor; 00062 class DFloor; 00063 class DPlat; 00064 class DPillar; 00065 00066 struct TypeInfo 00067 { 00068 TypeInfo () 00069 {} 00070 00071 TypeInfo (const char *inName, const TypeInfo *inParentType, unsigned int inSize) 00072 : Name (inName), 00073 ParentType (inParentType), 00074 SizeOf (inSize), 00075 TypeIndex(0) 00076 {} 00077 TypeInfo (const char *inName, const TypeInfo *inParentType, unsigned int inSize, DObject *(*inNew)()) 00078 : Name (inName), 00079 ParentType (inParentType), 00080 SizeOf (inSize), 00081 CreateNew (inNew), 00082 TypeIndex(0) 00083 {} 00084 00085 const char *Name; 00086 const TypeInfo *ParentType; 00087 unsigned int SizeOf; 00088 DObject *(*CreateNew)(); 00089 unsigned short TypeIndex; 00090 00091 void RegisterType (); 00092 00093 // Returns true if this type is an ansector of (or same as) the passed type. 00094 bool IsAncestorOf (const TypeInfo *ti) const 00095 { 00096 while (ti) 00097 { 00098 if (this == ti) 00099 return true; 00100 ti = ti->ParentType; 00101 } 00102 return false; 00103 } 00104 inline bool IsDescendantOf (const TypeInfo *ti) const 00105 { 00106 return ti->IsAncestorOf (this); 00107 } 00108 00109 static const TypeInfo *FindType (const char *name); 00110 00111 static unsigned short m_NumTypes, m_MaxTypes; 00112 static TypeInfo **m_Types; 00113 }; 00114 00115 struct ClassInit 00116 { 00117 ClassInit (TypeInfo *newClass); 00118 }; 00119 00120 #define RUNTIME_TYPE(object) (object->StaticType()) 00121 #define RUNTIME_CLASS(cls) (&cls::_StaticType) 00122 00123 #define _DECLARE_CLASS(cls,parent) \ 00124 virtual TypeInfo *StaticType() const { return RUNTIME_CLASS(cls); } \ 00125 private: \ 00126 typedef parent Super; \ 00127 typedef cls ThisClass; \ 00128 protected: 00129 00130 #define DECLARE_CLASS(cls,parent) \ 00131 public: \ 00132 static TypeInfo _StaticType; \ 00133 _DECLARE_CLASS(cls,parent) 00134 00135 #define _DECLARE_SERIAL(cls,parent) \ 00136 static DObject *CreateObject (); \ 00137 public: \ 00138 bool CanSerialize() { return true; } \ 00139 void Serialize (FArchive &); \ 00140 inline friend FArchive &operator>> (FArchive &arc, cls* &object) \ 00141 { \ 00142 return arc.ReadObject ((DObject* &)object, RUNTIME_CLASS(cls)); \ 00143 } 00144 00145 #define DECLARE_SERIAL(cls,parent) \ 00146 DECLARE_CLASS(cls,parent) \ 00147 _DECLARE_SERIAL(cls,parent) 00148 00149 #define _IMPLEMENT_CLASS(cls,parent,new) \ 00150 TypeInfo cls::_StaticType (#cls, RUNTIME_CLASS(parent), sizeof(cls), new); 00151 00152 #define IMPLEMENT_CLASS(cls,parent) \ 00153 _IMPLEMENT_CLASS(cls,parent,NULL) \ 00154 00155 #define _IMPLEMENT_SERIAL(cls,parent) \ 00156 _IMPLEMENT_CLASS(cls,parent,cls::CreateObject) \ 00157 DObject *cls::CreateObject() { return new cls; } \ 00158 static ClassInit _Init##cls(RUNTIME_CLASS(cls)); 00159 00160 #define IMPLEMENT_SERIAL(cls,parent) \ 00161 _IMPLEMENT_SERIAL(cls,parent) 00162 00163 enum EObjectFlags 00164 { 00165 OF_MassDestruction = 0x00000001, // Object is queued for deletion 00166 OF_Cleanup = 0x00000002 // Object is being deconstructed as a result of a queued deletion 00167 }; 00168 00169 class DObject 00170 { 00171 public: \ 00172 static TypeInfo _StaticType; \ 00173 virtual TypeInfo *StaticType() const { return &_StaticType; } \ 00174 private: \ 00175 typedef DObject ThisClass; 00176 00177 public: 00178 DObject (); 00179 virtual ~DObject (); 00180 00181 inline bool IsKindOf (const TypeInfo *base) const 00182 { 00183 return base->IsAncestorOf (StaticType ()); 00184 } 00185 00186 inline bool IsA (const TypeInfo *type) const 00187 { 00188 return (type == StaticType()); 00189 } 00190 00191 virtual void Serialize (FArchive &arc) {} 00192 virtual void Destroy (); 00193 00194 static void BeginFrame (); 00195 static void EndFrame (); 00196 00197 DWORD ObjectFlags; 00198 00199 static void STACK_ARGS StaticShutdown (); 00200 00201 private: 00202 static TArray<DObject *> Objects; 00203 static TArray<size_t> FreeIndices; 00204 static TArray<DObject *> ToDestroy; 00205 00206 void RemoveFromArray (); 00207 00208 static bool Inactive; 00209 size_t Index; 00210 }; 00211 00212 #include "farchive.h" 00213 00214 #endif //__DOBJECT_H__ 00215 00216