- more cleanup to reduce references to FArchive.
This commit is contained in:
parent
af6404f763
commit
42e38f6cc1
9 changed files with 151 additions and 557 deletions
268
src/farchive.cpp
268
src/farchive.cpp
|
|
@ -1021,267 +1021,6 @@ FArchive &FArchive::operator<< (FName &n)
|
|||
return *this;
|
||||
}
|
||||
|
||||
FArchive &FArchive::SerializePointer (void *ptrbase, BYTE **ptr, DWORD elemSize)
|
||||
{
|
||||
DWORD w;
|
||||
|
||||
if (m_Storing)
|
||||
{
|
||||
if (*(void **)ptr)
|
||||
{
|
||||
w = DWORD(((size_t)*ptr - (size_t)ptrbase) / elemSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
w = ~0u;
|
||||
}
|
||||
WriteCount (w);
|
||||
}
|
||||
else
|
||||
{
|
||||
w = ReadCount ();
|
||||
if (w != ~0u)
|
||||
{
|
||||
*(void **)ptr = (BYTE *)ptrbase + w * elemSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(void **)ptr = NULL;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
FArchive &FArchive::SerializeObject (DObject *&object, PClass *type)
|
||||
{
|
||||
if (!m_ThinkersAllowed && type->IsDescendantOf(RUNTIME_CLASS(DThinker)))
|
||||
{
|
||||
assert(true);
|
||||
I_Error("Tried to serialize a thinker before P_SerializeThinkers");
|
||||
}
|
||||
|
||||
if (!type->IsDescendantOf(RUNTIME_CLASS(PClass)))
|
||||
{ // a regular object
|
||||
if (IsStoring())
|
||||
{
|
||||
return WriteObject(object);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ReadObject(object, type);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // a class object
|
||||
if (IsStoring())
|
||||
{
|
||||
UserWriteClass((PClass *)object);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserReadClass(object);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
FArchive &FArchive::ReadObject (DObject* &obj, PClass *wanttype)
|
||||
{
|
||||
#if 0
|
||||
BYTE objHead;
|
||||
const PClass *type;
|
||||
BYTE playerNum;
|
||||
DWORD index;
|
||||
DObject *newobj;
|
||||
|
||||
operator<< (objHead);
|
||||
|
||||
switch (objHead)
|
||||
{
|
||||
case NULL_OBJ:
|
||||
obj = NULL;
|
||||
break;
|
||||
|
||||
case M1_OBJ:
|
||||
obj = (DObject *)~0;
|
||||
break;
|
||||
|
||||
case OLD_OBJ:
|
||||
index = ReadCount();
|
||||
if (index >= ArchiveToObject.Size())
|
||||
{
|
||||
I_Error ("Object reference too high (%u; max is %u)\n", index, ArchiveToObject.Size());
|
||||
}
|
||||
obj = ArchiveToObject[index];
|
||||
break;
|
||||
|
||||
case NEW_PLYR_CLS_OBJ:
|
||||
operator<< (playerNum);
|
||||
if (m_HubTravel)
|
||||
{
|
||||
// If travelling inside a hub, use the existing player actor
|
||||
type = ReadClass (wanttype);
|
||||
// Printf ("New player class: %s (%u)\n", type->Name, m_File->Tell());
|
||||
obj = players[playerNum].mo;
|
||||
|
||||
// But also create a new one so that we can get past the one
|
||||
// stored in the archive.
|
||||
AActor *tempobj = static_cast<AActor *>(type->CreateNew ());
|
||||
MapObject (obj != NULL ? obj : tempobj);
|
||||
tempobj->SerializeUserVars (*this);
|
||||
tempobj->Serialize (*this);
|
||||
tempobj->CheckIfSerialized ();
|
||||
// If this player is not present anymore, keep the new body
|
||||
// around just so that the load will succeed.
|
||||
if (obj != NULL)
|
||||
{
|
||||
// When the temporary player's inventory items were loaded,
|
||||
// they became owned by the real player. Undo that now.
|
||||
for (AInventory *item = tempobj->Inventory; item != NULL; item = item->Inventory)
|
||||
{
|
||||
item->Owner = tempobj;
|
||||
}
|
||||
tempobj->Destroy ();
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = tempobj;
|
||||
players[playerNum].mo = static_cast<APlayerPawn *>(obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* fallthrough when not travelling to a previous level */
|
||||
case NEW_CLS_OBJ:
|
||||
type = ReadClass (wanttype);
|
||||
// Printf ("New class: %s (%u)\n", type->Name, m_File->Tell());
|
||||
newobj = obj = type->CreateNew ();
|
||||
MapObject (obj);
|
||||
newobj->SerializeUserVars (*this);
|
||||
newobj->Serialize (*this);
|
||||
newobj->CheckIfSerialized ();
|
||||
break;
|
||||
|
||||
case NEW_PLYR_OBJ:
|
||||
operator<< (playerNum);
|
||||
if (m_HubTravel)
|
||||
{
|
||||
type = ReadStoredClass (wanttype);
|
||||
// Printf ("Use player class: %s (%u)\n", type->Name, m_File->Tell());
|
||||
obj = players[playerNum].mo;
|
||||
|
||||
AActor *tempobj = static_cast<AActor *>(type->CreateNew ());
|
||||
MapObject (obj != NULL ? obj : tempobj);
|
||||
tempobj->SerializeUserVars (*this);
|
||||
tempobj->Serialize (*this);
|
||||
tempobj->CheckIfSerialized ();
|
||||
if (obj != NULL)
|
||||
{
|
||||
for (AInventory *item = tempobj->Inventory;
|
||||
item != NULL; item = item->Inventory)
|
||||
{
|
||||
item->Owner = tempobj;
|
||||
}
|
||||
tempobj->Destroy ();
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = tempobj;
|
||||
players[playerNum].mo = static_cast<APlayerPawn *>(obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* fallthrough when not travelling to a previous level */
|
||||
case NEW_OBJ:
|
||||
type = ReadStoredClass (wanttype);
|
||||
// Printf ("Use class: %s (%u)\n", type->Name, m_File->Tell());
|
||||
obj = type->CreateNew ();
|
||||
MapObject (obj);
|
||||
obj->SerializeUserVars (*this);
|
||||
obj->Serialize (*this);
|
||||
obj->CheckIfSerialized ();
|
||||
break;
|
||||
|
||||
default:
|
||||
I_Error ("Unknown object code (%d) in archive\n", objHead);
|
||||
}
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
void FArchive::WriteSprite (int spritenum)
|
||||
{
|
||||
BYTE id;
|
||||
|
||||
if ((unsigned)spritenum >= (unsigned)sprites.Size())
|
||||
{
|
||||
spritenum = 0;
|
||||
}
|
||||
|
||||
if (m_SpriteMap[spritenum] < 0)
|
||||
{
|
||||
m_SpriteMap[spritenum] = (int)(m_NumSprites++);
|
||||
id = NEW_SPRITE;
|
||||
Write (&id, 1);
|
||||
Write (sprites[spritenum].name, 4);
|
||||
|
||||
// Write the current sprite number as a hint, because
|
||||
// these will only change between different versions.
|
||||
WriteCount (spritenum);
|
||||
}
|
||||
else
|
||||
{
|
||||
id = OLD_SPRITE;
|
||||
Write (&id, 1);
|
||||
WriteCount (m_SpriteMap[spritenum]);
|
||||
}
|
||||
}
|
||||
|
||||
int FArchive::ReadSprite ()
|
||||
{
|
||||
BYTE id;
|
||||
|
||||
Read (&id, 1);
|
||||
if (id == OLD_SPRITE)
|
||||
{
|
||||
DWORD index = ReadCount ();
|
||||
if (index >= m_NumSprites)
|
||||
{
|
||||
I_Error ("Sprite %u has not been read yet\n", index);
|
||||
}
|
||||
return m_SpriteMap[index];
|
||||
}
|
||||
else if (id == NEW_SPRITE)
|
||||
{
|
||||
DWORD name;
|
||||
DWORD hint;
|
||||
|
||||
Read (&name, 4);
|
||||
hint = ReadCount ();
|
||||
|
||||
if (hint >= NumStdSprites || sprites[hint].dwName != name)
|
||||
{
|
||||
for (hint = NumStdSprites; hint-- != 0; )
|
||||
{
|
||||
if (sprites[hint].dwName == name)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hint >= sprites.Size())
|
||||
{ // Don't know this sprite, so just use the first one
|
||||
hint = 0;
|
||||
}
|
||||
}
|
||||
m_SpriteMap[m_NumSprites++] = hint;
|
||||
return hint;
|
||||
}
|
||||
else
|
||||
{
|
||||
I_Error ("Expected a sprite but got something else\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD FArchive::AddName (const char *name)
|
||||
{
|
||||
DWORD index;
|
||||
|
|
@ -1388,13 +1127,6 @@ PClass *FArchive::ReadStoredClass (const PClass *wanttype)
|
|||
return type;
|
||||
}
|
||||
|
||||
DWORD FArchive::MapObject (DObject *obj)
|
||||
{
|
||||
DWORD i = ArchiveToObject.Push(obj);
|
||||
ObjectToArchive[obj] = i;
|
||||
return i;
|
||||
}
|
||||
|
||||
void FArchive::UserWriteClass (PClass *type)
|
||||
{
|
||||
BYTE id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue