2008-03-19 09:53:23 +00:00
|
|
|
/*
|
|
|
|
** dobjtype.cpp
|
|
|
|
** Implements the type information class
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2008 Randy Heit
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
#include "dobject.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "actor.h"
|
2006-09-27 04:56:18 +00:00
|
|
|
#include "templates.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "autosegs.h"
|
2010-02-13 08:56:08 +00:00
|
|
|
#include "v_text.h"
|
2010-03-25 20:38:00 +00:00
|
|
|
#include "a_pickups.h"
|
|
|
|
#include "d_player.h"
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
IMPLEMENT_POINTY_CLASS(PClass)
|
|
|
|
DECLARE_POINTER(ParentClass)
|
|
|
|
END_POINTERS
|
|
|
|
|
2010-03-24 02:49:37 +00:00
|
|
|
TArray<PClassActor *> PClass::m_RuntimeActors;
|
2006-05-10 02:40:43 +00:00
|
|
|
TArray<PClass *> PClass::m_Types;
|
|
|
|
PClass *PClass::TypeHash[PClass::HASH_SIZE];
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
bool PClass::bShutdown;
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2008-04-29 02:43:42 +00:00
|
|
|
// A harmless non-NULL FlatPointer for classes without pointers.
|
|
|
|
static const size_t TheEnd = ~(size_t)0;
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2006-09-27 04:56:18 +00:00
|
|
|
static int STACK_ARGS cregcmp (const void *a, const void *b)
|
|
|
|
{
|
2009-09-17 01:36:14 +00:00
|
|
|
const PClass *class1 = *(const PClass **)a;
|
|
|
|
const PClass *class2 = *(const PClass **)b;
|
|
|
|
return strcmp(class1->TypeName, class2->TypeName);
|
2006-09-27 04:56:18 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 03:14:40 +00:00
|
|
|
void PClass::StaticInit ()
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2006-05-12 03:14:40 +00:00
|
|
|
atterm (StaticShutdown);
|
|
|
|
|
2009-08-02 03:38:57 +00:00
|
|
|
FAutoSegIterator probe(CRegHead, CRegTail);
|
2006-05-12 03:14:40 +00:00
|
|
|
|
2009-08-02 03:38:57 +00:00
|
|
|
while (*++probe != NULL)
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2009-08-02 03:38:57 +00:00
|
|
|
((ClassReg *)*probe)->RegisterClass ();
|
2006-05-12 03:14:40 +00:00
|
|
|
}
|
2009-09-17 01:36:14 +00:00
|
|
|
|
|
|
|
// Keep actors in consistant order. I did this before, though I'm not
|
|
|
|
// sure if this is really necessary to maintain any sort of sync.
|
|
|
|
qsort(&m_Types[0], m_Types.Size(), sizeof(m_Types[0]), cregcmp);
|
|
|
|
for (unsigned int i = 0; i < m_Types.Size(); ++i)
|
|
|
|
{
|
|
|
|
m_Types[i]->ClassIndex = i;
|
|
|
|
}
|
2006-05-12 03:14:40 +00:00
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2006-05-12 03:14:40 +00:00
|
|
|
void PClass::StaticShutdown ()
|
|
|
|
{
|
|
|
|
TArray<size_t *> uniqueFPs(64);
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < PClass::m_Types.Size(); ++i)
|
|
|
|
{
|
|
|
|
PClass *type = PClass::m_Types[i];
|
|
|
|
PClass::m_Types[i] = NULL;
|
|
|
|
if (type->FlatPointers != &TheEnd && type->FlatPointers != type->Pointers)
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2006-05-12 03:14:40 +00:00
|
|
|
// FlatPointers are shared by many classes, so we must check for
|
|
|
|
// duplicates and only delete those that are unique.
|
|
|
|
for (j = 0; j < uniqueFPs.Size(); ++j)
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2006-05-12 03:14:40 +00:00
|
|
|
if (type->FlatPointers == uniqueFPs[j])
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2006-05-12 03:14:40 +00:00
|
|
|
break;
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-12 03:14:40 +00:00
|
|
|
if (j == uniqueFPs.Size())
|
|
|
|
{
|
|
|
|
uniqueFPs.Push(const_cast<size_t *>(type->FlatPointers));
|
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
2006-05-12 03:14:40 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < uniqueFPs.Size(); ++i)
|
|
|
|
{
|
|
|
|
delete[] uniqueFPs[i];
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
bShutdown = true;
|
2006-05-12 03:14:40 +00:00
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
PClass::PClass()
|
|
|
|
{
|
|
|
|
Size = sizeof(DObject);
|
|
|
|
ParentClass = NULL;
|
|
|
|
Pointers = NULL;
|
|
|
|
FlatPointers = NULL;
|
|
|
|
HashNext = NULL;
|
|
|
|
Defaults = NULL;
|
|
|
|
bRuntimeClass = false;
|
|
|
|
ClassIndex = ~0;
|
2010-03-25 20:38:00 +00:00
|
|
|
ConstructNative = NULL;
|
2009-09-17 01:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PClass::~PClass()
|
|
|
|
{
|
|
|
|
Symbols.ReleaseSymbols();
|
2010-03-24 02:49:37 +00:00
|
|
|
if (Defaults != NULL)
|
2008-08-12 09:57:59 +00:00
|
|
|
{
|
2010-03-24 02:49:37 +00:00
|
|
|
M_Free(Defaults);
|
|
|
|
Defaults = NULL;
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
PClass *ClassReg::RegisterClass()
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
static ClassReg *const metaclasses[] =
|
|
|
|
{
|
|
|
|
&PClass::RegistrationInfo,
|
|
|
|
&PClassActor::RegistrationInfo,
|
|
|
|
&PClassInventory::RegistrationInfo,
|
|
|
|
&PClassAmmo::RegistrationInfo,
|
|
|
|
&PClassHealth::RegistrationInfo,
|
|
|
|
&PClassPuzzleItem::RegistrationInfo,
|
|
|
|
&PClassWeapon::RegistrationInfo,
|
|
|
|
&PClassPlayerPawn::RegistrationInfo,
|
|
|
|
};
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
// MyClass may have already been created by a previous recursive call.
|
|
|
|
// Or this may be a recursive call for a previously created class.
|
|
|
|
if (MyClass != NULL)
|
|
|
|
{
|
|
|
|
return MyClass;
|
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
// Add type to list
|
2010-03-24 02:49:37 +00:00
|
|
|
PClass *cls;
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
if (MetaClassNum >= countof(metaclasses))
|
2010-03-24 02:49:37 +00:00
|
|
|
{
|
|
|
|
assert(0 && "Class registry has an invalid meta class identifier");
|
|
|
|
}
|
2010-03-25 20:38:00 +00:00
|
|
|
|
|
|
|
if (this == &PClass::RegistrationInfo)
|
|
|
|
{
|
|
|
|
cls = new PClass;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (metaclasses[MetaClassNum]->MyClass == NULL)
|
|
|
|
{ // Make sure the meta class is already registered before registering this one
|
|
|
|
metaclasses[MetaClassNum]->RegisterClass();
|
|
|
|
}
|
|
|
|
cls = static_cast<PClass *>(metaclasses[MetaClassNum]->MyClass->CreateNew());
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
MyClass = cls;
|
|
|
|
PClass::m_Types.Push(cls);
|
|
|
|
cls->TypeName = FName(Name+1);
|
|
|
|
cls->Size = SizeOf;
|
|
|
|
cls->Pointers = Pointers;
|
|
|
|
cls->ConstructNative = ConstructNative;
|
|
|
|
cls->InsertIntoHash();
|
2010-03-25 20:38:00 +00:00
|
|
|
if (ParentType != NULL)
|
|
|
|
{
|
|
|
|
cls->ParentClass = ParentType->RegisterClass();
|
|
|
|
}
|
2009-09-17 01:36:14 +00:00
|
|
|
return cls;
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PClass::InsertIntoHash ()
|
|
|
|
{
|
|
|
|
// Add class to hash table. Classes are inserted into each bucket
|
|
|
|
// in ascending order by name index.
|
|
|
|
unsigned int bucket = TypeName % HASH_SIZE;
|
|
|
|
PClass **hashpos = &TypeHash[bucket];
|
|
|
|
while (*hashpos != NULL)
|
|
|
|
{
|
|
|
|
int lexx = int(TypeName) - int((*hashpos)->TypeName);
|
|
|
|
|
|
|
|
if (lexx > 0)
|
|
|
|
{ // This type should come later in the chain
|
|
|
|
hashpos = &((*hashpos)->HashNext);
|
|
|
|
}
|
|
|
|
else if (lexx == 0)
|
|
|
|
{ // This type has already been inserted
|
2008-04-12 15:31:18 +00:00
|
|
|
// ... but there is no need whatsoever to make it a fatal error!
|
2010-02-13 08:56:08 +00:00
|
|
|
Printf (TEXTCOLOR_RED"Tried to register class '%s' more than once.\n", TypeName.GetChars());
|
2008-04-12 15:31:18 +00:00
|
|
|
break;
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Type comes right here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HashNext = *hashpos;
|
|
|
|
*hashpos = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a type, passed the name as a name
|
2010-02-12 06:04:57 +00:00
|
|
|
PClass *PClass::FindClass (FName zaname)
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
- Added the ACS commands
ReplaceTextures (str old_texture, str new_texture, optional bool not_lower,
optional bool not_mid, optional bool not_upper, optional bool not_floor,
optional bool not_ceiling); and
SectorDamage (int tag, int amount, str type, bool players_only, bool in_air,
str protection_item, bool subclasses_okay);
- Added the vid_nowidescreen cvar to disable widescreen aspect ratio
correction. When this is enabled, the only display ratio available is 4:3
(and 5:4 if vid_tft is set).
- Added support for setting an actor's damage property to an expression
through decorate. Just enclose it within parentheses, and the expression
will be evaluated exactly as-is without the normal Doom damage calculation.
So if you want something that does exactly 6 damage, use a "Damage (6)"
property. To deal normal Doom missile damage, you can use
"Damage (random(1,8)*6)" instead of "Damage 6".
- Moved InvFirst and InvSel into APlayerPawn so that they can be consistantly
maintained by ObtainInventory.
SVN r288 (trunk)
2006-08-12 02:30:57 +00:00
|
|
|
if (zaname == NAME_None)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
PClass *cls = TypeHash[zaname % HASH_SIZE];
|
|
|
|
|
|
|
|
while (cls != 0)
|
|
|
|
{
|
|
|
|
int lexx = int(zaname) - int(cls->TypeName);
|
|
|
|
if (lexx > 0)
|
|
|
|
{
|
|
|
|
cls = cls->HashNext;
|
|
|
|
}
|
|
|
|
else if (lexx == 0)
|
|
|
|
{
|
2008-12-29 23:03:38 +00:00
|
|
|
return cls->Size<0? NULL : cls;
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new object that this class represents
|
2010-03-25 20:38:00 +00:00
|
|
|
DObject *PClass::CreateNew() const
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
|
|
|
BYTE *mem = (BYTE *)M_Malloc (Size);
|
2006-07-11 04:48:10 +00:00
|
|
|
assert (mem != NULL);
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
// Set this object's defaults before constructing it.
|
2009-05-11 15:15:06 +00:00
|
|
|
if (Defaults != NULL)
|
2006-05-10 16:43:46 +00:00
|
|
|
memcpy (mem, Defaults, Size);
|
|
|
|
else
|
|
|
|
memset (mem, 0, Size);
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
ConstructNative (mem);
|
|
|
|
((DObject *)mem)->SetClass (const_cast<PClass *>(this));
|
|
|
|
return (DObject *)mem;
|
|
|
|
}
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
// Copies inheritable values into the derived class and other miscellaneous setup.
|
|
|
|
void PClass::Derive(PClass *newclass)
|
|
|
|
{
|
|
|
|
newclass->ParentClass = this;
|
|
|
|
newclass->ConstructNative = ConstructNative;
|
|
|
|
|
|
|
|
// Set up default instance of the new class.
|
|
|
|
newclass->Defaults = (BYTE *)M_Malloc(newclass->Size);
|
|
|
|
memcpy(newclass->Defaults, Defaults, Size);
|
|
|
|
if (newclass->Size > Size)
|
|
|
|
{
|
|
|
|
memset(newclass->Defaults + Size, 0, newclass->Size - Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
newclass->Symbols.SetParentTable(&this->Symbols);
|
|
|
|
}
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
// Create a new class based on an existing class
|
|
|
|
PClass *PClass::CreateDerivedClass (FName name, unsigned int size)
|
|
|
|
{
|
|
|
|
assert (size >= Size);
|
2008-12-29 23:03:38 +00:00
|
|
|
PClass *type;
|
|
|
|
bool notnew;
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2008-12-29 23:03:38 +00:00
|
|
|
const PClass *existclass = FindClass(name);
|
|
|
|
|
|
|
|
// This is a placeholder so fill it in
|
2009-01-28 05:29:41 +00:00
|
|
|
if (existclass != NULL && existclass->Size == (unsigned)-1)
|
2008-12-29 23:03:38 +00:00
|
|
|
{
|
|
|
|
type = const_cast<PClass*>(existclass);
|
|
|
|
if (!IsDescendantOf(type->ParentClass))
|
|
|
|
{
|
|
|
|
I_Error("%s must inherit from %s but doesn't.", name.GetChars(), type->ParentClass->TypeName.GetChars());
|
|
|
|
}
|
2008-12-30 14:24:55 +00:00
|
|
|
DPrintf("Defining placeholder class %s\n", name.GetChars());
|
2008-12-29 23:03:38 +00:00
|
|
|
notnew = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-24 02:49:37 +00:00
|
|
|
// Create a new type object of the same type as us. (We may be a derived class of PClass.)
|
|
|
|
type = static_cast<PClass *>(GetClass()->CreateNew());
|
2008-12-29 23:03:38 +00:00
|
|
|
notnew = false;
|
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
type->TypeName = name;
|
|
|
|
type->Size = size;
|
|
|
|
type->bRuntimeClass = true;
|
2010-03-25 20:38:00 +00:00
|
|
|
Derive(type);
|
2010-03-24 02:49:37 +00:00
|
|
|
if (!notnew)
|
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
type->ClassIndex = m_Types.Push (type);
|
2010-03-24 02:49:37 +00:00
|
|
|
type->InsertIntoHash();
|
|
|
|
}
|
2006-05-10 02:40:43 +00:00
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
// If this class is for an actor, push it onto the RuntimeActors stack.
|
2010-03-24 02:49:37 +00:00
|
|
|
if (type->IsKindOf(RUNTIME_CLASS(PClassActor)))
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2010-03-24 02:49:37 +00:00
|
|
|
m_RuntimeActors.Push(static_cast<PClassActor *>(type));
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2009-10-25 02:19:51 +00:00
|
|
|
// Add <extension> bytes to the end of this class. Returns the
|
|
|
|
// previous size of the class.
|
|
|
|
unsigned int PClass::Extend(unsigned int extension)
|
|
|
|
{
|
|
|
|
assert(this->bRuntimeClass);
|
|
|
|
|
|
|
|
unsigned int oldsize = Size;
|
|
|
|
Size += extension;
|
|
|
|
Defaults = (BYTE *)M_Realloc(Defaults, Size);
|
|
|
|
memset(Defaults + oldsize, 0, extension);
|
|
|
|
return oldsize;
|
|
|
|
}
|
|
|
|
|
2008-12-29 23:03:38 +00:00
|
|
|
// Like FindClass but creates a placeholder if no class
|
|
|
|
// is found. CreateDerivedClass will automatcally fill in
|
|
|
|
// the placeholder when the actual class is defined.
|
2010-03-24 02:49:37 +00:00
|
|
|
PClass *PClass::FindClassTentative (FName name)
|
2008-12-29 23:03:38 +00:00
|
|
|
{
|
|
|
|
if (name == NAME_None)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PClass *cls = TypeHash[name % HASH_SIZE];
|
|
|
|
|
|
|
|
while (cls != 0)
|
|
|
|
{
|
|
|
|
int lexx = int(name) - int(cls->TypeName);
|
|
|
|
if (lexx > 0)
|
|
|
|
{
|
|
|
|
cls = cls->HashNext;
|
|
|
|
}
|
|
|
|
else if (lexx == 0)
|
|
|
|
{
|
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 20:38:00 +00:00
|
|
|
PClass *type = static_cast<PClass *>(GetClass()->CreateNew());
|
2008-12-30 14:24:55 +00:00
|
|
|
DPrintf("Creating placeholder class %s : %s\n", name.GetChars(), TypeName.GetChars());
|
2008-12-29 23:03:38 +00:00
|
|
|
|
|
|
|
type->TypeName = name;
|
|
|
|
type->ParentClass = this;
|
|
|
|
type->Size = -1;
|
|
|
|
type->ClassIndex = m_Types.Push (type);
|
|
|
|
type->bRuntimeClass = true;
|
|
|
|
type->InsertIntoHash();
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
// Create the FlatPointers array, if it doesn't exist already.
|
|
|
|
// It comprises all the Pointers from superclasses plus this class's own Pointers.
|
|
|
|
// If this class does not define any new Pointers, then FlatPointers will be set
|
|
|
|
// to the same array as the super class's.
|
|
|
|
void PClass::BuildFlatPointers ()
|
|
|
|
{
|
|
|
|
if (FlatPointers != NULL)
|
|
|
|
{ // Already built: Do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ParentClass == NULL)
|
|
|
|
{ // No parent: FlatPointers is the same as Pointers.
|
|
|
|
if (Pointers == NULL)
|
|
|
|
{ // No pointers: Make FlatPointers a harmless non-NULL.
|
|
|
|
FlatPointers = &TheEnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlatPointers = Pointers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ParentClass->BuildFlatPointers ();
|
|
|
|
if (Pointers == NULL)
|
|
|
|
{ // No new pointers: Just use the same FlatPointers as the parent.
|
|
|
|
FlatPointers = ParentClass->FlatPointers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // New pointers: Create a new FlatPointers array and add them.
|
|
|
|
int numPointers, numSuperPointers;
|
|
|
|
|
|
|
|
// Count pointers defined by this class.
|
|
|
|
for (numPointers = 0; Pointers[numPointers] != ~(size_t)0; numPointers++)
|
|
|
|
{ }
|
|
|
|
// Count pointers defined by superclasses.
|
|
|
|
for (numSuperPointers = 0; ParentClass->FlatPointers[numSuperPointers] != ~(size_t)0; numSuperPointers++)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Concatenate them into a new array
|
|
|
|
size_t *flat = new size_t[numPointers + numSuperPointers + 1];
|
|
|
|
if (numSuperPointers > 0)
|
|
|
|
{
|
|
|
|
memcpy (flat, ParentClass->FlatPointers, sizeof(size_t)*numSuperPointers);
|
|
|
|
}
|
|
|
|
memcpy (flat + numSuperPointers, Pointers, sizeof(size_t)*(numPointers+1));
|
|
|
|
FlatPointers = flat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-10-31 14:53:21 +00:00
|
|
|
|
2008-08-06 22:59:24 +00:00
|
|
|
const PClass *PClass::NativeClass() const
|
|
|
|
{
|
|
|
|
const PClass *cls = this;
|
|
|
|
|
2008-08-12 09:57:59 +00:00
|
|
|
while (cls && cls->bRuntimeClass)
|
2008-08-06 22:59:24 +00:00
|
|
|
cls = cls->ParentClass;
|
|
|
|
|
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
size_t PClass::PropagateMark()
|
|
|
|
{
|
|
|
|
size_t marked;
|
|
|
|
|
|
|
|
// Mark symbols
|
|
|
|
marked = Symbols.MarkSymbols();
|
|
|
|
|
|
|
|
return marked + Super::PropagateMark();
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Symbol tables ------------------------------------------------------------
|
|
|
|
|
2009-09-16 01:39:44 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS(PSymbol);
|
|
|
|
IMPLEMENT_CLASS(PSymbolConst);
|
|
|
|
IMPLEMENT_CLASS(PSymbolVariable);
|
2010-02-12 06:04:57 +00:00
|
|
|
IMPLEMENT_POINTY_CLASS(PSymbolActionFunction)
|
|
|
|
DECLARE_POINTER(Function)
|
|
|
|
END_POINTERS
|
2009-09-23 00:24:47 +00:00
|
|
|
IMPLEMENT_POINTY_CLASS(PSymbolVMFunction)
|
|
|
|
DECLARE_POINTER(Function)
|
|
|
|
END_POINTERS
|
2009-09-16 01:39:44 +00:00
|
|
|
|
2008-06-06 02:17:28 +00:00
|
|
|
PSymbol::~PSymbol()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-16 01:39:44 +00:00
|
|
|
PSymbolTable::PSymbolTable()
|
|
|
|
: ParentSymbolTable(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
PSymbolTable::~PSymbolTable ()
|
2008-06-06 02:17:28 +00:00
|
|
|
{
|
|
|
|
ReleaseSymbols();
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
size_t PSymbolTable::MarkSymbols()
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
size_t count = 0;
|
|
|
|
MapType::Iterator it(Symbols);
|
|
|
|
MapType::Pair *pair;
|
|
|
|
|
|
|
|
while (it.NextPair(pair))
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
GC::Mark(pair->Value);
|
|
|
|
count++;
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
2010-03-31 02:43:55 +00:00
|
|
|
return count * sizeof(PSymbol*);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PSymbolTable::ReleaseSymbols()
|
|
|
|
{
|
|
|
|
// The GC will take care of deleting the symbols. We just need to
|
|
|
|
// clear our references to them.
|
2008-06-06 02:17:28 +00:00
|
|
|
Symbols.Clear();
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PSymbolTable::SetParentTable (PSymbolTable *parent)
|
|
|
|
{
|
|
|
|
ParentSymbolTable = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSymbol *PSymbolTable::FindSymbol (FName symname, bool searchparents) const
|
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
PSymbol * const *value = Symbols.CheckKey(symname);
|
|
|
|
if (value == NULL && searchparents && ParentSymbolTable != NULL)
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
return ParentSymbolTable->FindSymbol(symname, searchparents);
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
2010-03-30 04:11:16 +00:00
|
|
|
return value != NULL ? *value : NULL;
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PSymbol *PSymbolTable::AddSymbol (PSymbol *sym)
|
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
// Symbols that already exist are not inserted.
|
|
|
|
if (Symbols.CheckKey(sym->SymbolName) != NULL)
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2010-03-30 04:11:16 +00:00
|
|
|
return NULL;
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
2010-03-30 04:11:16 +00:00
|
|
|
Symbols.Insert(sym->SymbolName, sym);
|
2006-11-29 04:51:16 +00:00
|
|
|
return sym;
|
2006-12-09 00:16:10 +00:00
|
|
|
}
|