- put the state pointer serializer in a virtual function so that types.cpp can operate without any knowledge of Doom states.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:30:09 +02:00
parent 1ce11ff02a
commit ef8b4c7d5e
5 changed files with 78 additions and 51 deletions

View file

@ -445,6 +445,18 @@ FSerializer &FSerializer::Sprite(const char *key, int32_t &spritenum, int32_t *d
return *this;
}
//==========================================================================
//
// only here so that it can be virtually overridden. Without reference this cannot save anything.
//
//==========================================================================
FSerializer& FSerializer::StatePointer(const char* key, void* ptraddr, bool *res)
{
if (res) *res = false;
return *this;
}
//==========================================================================
//
//

View file

@ -93,6 +93,9 @@ public:
FCompressedBuffer GetCompressedOutput();
// The sprite serializer is a special case because it is needed by the VM to handle its 'spriteid' type.
virtual FSerializer &Sprite(const char *key, int32_t &spritenum, int32_t *def);
// This is only needed by the type system.
virtual FSerializer& StatePointer(const char* key, void* ptraddr, bool *res);
FSerializer &StringPtr(const char *key, const char *&charptr); // This only retrieves the address but creates no permanent copy of the string unlike the regular char* serializer.
FSerializer &AddString(const char *key, const char *charptr);
const char *GetString(const char *key);

View file

@ -38,7 +38,6 @@
#include "types.h"
#include "printf.h"
#include "textureid.h"
#include "version.h"
FTypeTable TypeTable;
@ -1079,6 +1078,46 @@ bool PName::ReadValue(FSerializer &ar, const char *key, void *addr) const
}
}
/* PStatePointer **********************************************************/
//==========================================================================
//
// PStatePointer Default Constructor
//
//==========================================================================
PStatePointer::PStatePointer()
{
mDescriptiveName = "Pointer<State>";
PointedType = NewStruct(NAME_State, nullptr, true);
IsConst = true;
}
//==========================================================================
//
// PStatePointer :: WriteValue
//
//==========================================================================
void PStatePointer::WriteValue(FSerializer& ar, const char* key, const void* addr) const
{
ar.StatePointer(key, const_cast<void*>(addr), nullptr);
}
//==========================================================================
//
// PStatePointer :: ReadValue
//
//==========================================================================
bool PStatePointer::ReadValue(FSerializer& ar, const char* key, void* addr) const
{
bool res = false;
ar.StatePointer(key, addr, &res);
return res;
}
/* PSpriteID ******************************************************************/
//==========================================================================
@ -2524,52 +2563,3 @@ CCMD(typetable)
DumpTypeTable();
}
// fixme: The VM depends on this but it's engine specific. Needs a better solution.
/* PStatePointer **********************************************************/
#ifdef GZDOOM
#include "info.h"
#include "serializer_doom.h"
#endif
//==========================================================================
//
// PStatePointer Default Constructor
//
//==========================================================================
PStatePointer::PStatePointer()
{
mDescriptiveName = "Pointer<State>";
PointedType = NewStruct(NAME_State, nullptr, true);
IsConst = true;
}
//==========================================================================
//
// PStatePointer :: WriteValue
//
//==========================================================================
void PStatePointer::WriteValue(FSerializer& ar, const char* key, const void* addr) const
{
#ifdef GZDOOM
ar(key, *(FState**)addr);
#endif
}
//==========================================================================
//
// PStatePointer :: ReadValue
//
//==========================================================================
bool PStatePointer::ReadValue(FSerializer& ar, const char* key, void* addr) const
{
bool res = false;
#ifdef GZDOOM
::Serialize(ar, key, *(FState**)addr, nullptr, &res);
#endif
return res;
}

View file

@ -165,6 +165,27 @@ FSerializer &FDoomSerializer::Sprite(const char *key, int32_t &spritenum, int32_
return *this;
}
//==========================================================================
//
//
//
//==========================================================================
FSerializer& FDoomSerializer::StatePointer(const char* key, void* ptraddr, bool *res)
{
if (isWriting())
{
if (res) *res = true;
(*this)(key, *(FState**)ptraddr);
}
else
{
::Serialize(*this, key, *(FState**)ptraddr, nullptr, res);
}
return *this;
}
template<> FSerializer &Serialize(FSerializer &ar, const char *key, FPolyObj *&value, FPolyObj **defval)
{

View file

@ -29,7 +29,8 @@ public:
{}
FSerializer &Sprite(const char *key, int32_t &spritenum, int32_t *def) override;
FSerializer& StatePointer(const char* key, void* ptraddr, bool *res) override;
};
FSerializer &SerializeArgs(FSerializer &arc, const char *key, int *args, int *defargs, int special);