Codegen integration + string enum serialization support

This commit is contained in:
Aruki 2018-07-30 20:33:51 -06:00
parent 6a72bae97a
commit 91650a2924
13 changed files with 98 additions and 32 deletions

3
.gitmodules vendored
View File

@ -10,3 +10,6 @@
[submodule "externals/nod"]
path = externals/nod
url = https://github.com/arukibree/nod
[submodule "externals/CodeGen"]
path = externals/CodeGen
url = https://github.com/arukibree/CodeGen

View File

@ -31,6 +31,7 @@ CONFIG (release, debug|release) {
# Include Paths
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/tinyxml2
# Header Files
@ -40,7 +41,6 @@ HEADERS += \
CTimer.h \
EKeyInputs.h \
EMouseInputs.h \
ETransformSpace.h \
Flags.h \
TString.h \
types.h \
@ -101,5 +101,10 @@ SOURCES += \
FileIO\CBitStreamInWrapper.cpp \
Hash/CCRC32.cpp
# Codegen
CODEGEN_OUT_PATH = $$BUILD_DIR/Common/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)
# Library Sources
SOURCES += $$EXTERNALS_DIR/tinyxml2/tinyxml2.cpp

View File

@ -17,7 +17,7 @@ class CBasicBinaryReader : public IArchive
public:
CBasicBinaryReader(const TString& rkFilename, u32 Magic)
: IArchive(true, false)
: IArchive()
, mOwnsStream(true)
{
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
@ -31,7 +31,7 @@ public:
}
CBasicBinaryReader(IInputStream *pStream, const CSerialVersion& rkVersion)
: IArchive(true, false)
: IArchive()
, mMagicValid(true)
, mOwnsStream(false)
{
@ -41,7 +41,7 @@ public:
}
CBasicBinaryReader(void *pData, u32 DataSize, const CSerialVersion& rkVersion, IOUtil::EEndianness Endian = IOUtil::kSystemEndianness)
: IArchive(true, false)
: IArchive()
, mMagicValid(true)
, mOwnsStream(true)
{
@ -57,6 +57,10 @@ public:
inline bool IsValid() const { return mpStream->IsValid(); }
// Interface
virtual bool IsReader() const { return true; }
virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char*) { return true; }
virtual void ParamEnd() { }

View File

@ -16,7 +16,7 @@ class CBasicBinaryWriter : public IArchive
public:
CBasicBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion, EGame Game)
: IArchive(false, true)
: IArchive()
, mMagic(Magic)
, mOwnsStream(true)
{
@ -31,7 +31,7 @@ public:
}
CBasicBinaryWriter(IOutputStream *pStream, u16 FileVersion, EGame Game)
: IArchive(false, true)
: IArchive()
, mOwnsStream(false)
{
ASSERT(pStream->IsValid());
@ -40,7 +40,7 @@ public:
}
CBasicBinaryWriter(IOutputStream *pStream, const CSerialVersion& rkVersion)
: IArchive(false, true)
: IArchive()
, mOwnsStream(false)
{
ASSERT(pStream->IsValid());
@ -62,6 +62,10 @@ public:
inline bool IsValid() const { return mpStream->IsValid(); }
// Interface
virtual bool IsReader() const { return false; }
virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char*) { return true; }
virtual void ParamEnd() { }

View File

@ -23,7 +23,7 @@ class CBinaryReader : public IArchive
public:
CBinaryReader(const TString& rkFilename, u32 Magic)
: IArchive(true, false)
: IArchive()
, mOwnsStream(true)
{
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
@ -39,7 +39,7 @@ public:
}
CBinaryReader(IInputStream *pStream, const CSerialVersion& rkVersion)
: IArchive(true, false)
: IArchive()
, mMagicValid(true)
, mOwnsStream(false)
{
@ -70,6 +70,10 @@ private:
public:
// Interface
virtual bool IsReader() const { return true; }
virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return false; }
u32 ReadSize()
{
return (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->ReadShort() : mpStream->ReadLong());

View File

@ -20,7 +20,7 @@ class CBinaryWriter : public IArchive
public:
CBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion, EGame Game)
: IArchive(false, true)
: IArchive()
, mMagic(Magic)
, mOwnsStream(true)
{
@ -37,7 +37,7 @@ public:
}
CBinaryWriter(IOutputStream *pStream, u16 FileVersion, EGame Game)
: IArchive(false, true)
: IArchive()
, mMagic(0)
, mOwnsStream(false)
{
@ -48,7 +48,7 @@ public:
}
CBinaryWriter(IOutputStream *pStream, const CSerialVersion& rkVersion)
: IArchive(false, true)
: IArchive()
, mMagic(0)
, mOwnsStream(false)
{
@ -88,6 +88,10 @@ private:
public:
// Interface
virtual bool IsReader() const { return false; }
virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char *pkName)
{
// Update parent param

View File

@ -12,7 +12,7 @@ class CXMLReader : public IArchive
public:
CXMLReader(const TString& rkFileName)
: IArchive(true, false)
: IArchive()
, mJustEndedParam(false)
{
// Load XML and set current element to the root element; read version
@ -38,6 +38,10 @@ public:
}
// Interface
virtual bool IsReader() const { return true; }
virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return true; }
virtual bool ParamBegin(const char *pkName)
{
ASSERT(IsValid());

View File

@ -15,7 +15,7 @@ class CXMLWriter : public IArchive
public:
CXMLWriter(const TString& rkFileName, const TString& rkRootName, u16 FileVersion, EGame Game = eUnknownGame)
: IArchive(false, true)
: IArchive()
, mOutFilename(rkFileName)
, mSaved(false)
{
@ -69,6 +69,10 @@ public:
}
// Interface
virtual bool IsReader() const { return false; }
virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return true; }
virtual bool ParamBegin(const char *pkName)
{
ASSERT(IsValid());

View File

@ -167,6 +167,8 @@ public:
None);
};
#define ENABLE_FOR_SERIAL_TYPE(SType) typename std::enable_if<SerialType<ValType, IArchive>::Type == SerialType<ValType, IArchive>::##SType, int>::type = 0
// Actual archive class
class IArchive
{
@ -174,8 +176,6 @@ protected:
u16 mArchiveVersion;
u16 mFileVersion;
EGame mGame;
bool mIsReader;
bool mIsWriter;
public:
enum EArchiveVersion
@ -187,18 +187,14 @@ public:
};
static const u32 skCurrentArchiveVersion = (eArVer_Max - 1);
IArchive(bool IsReader, bool IsWriter)
IArchive()
: mFileVersion(0)
, mArchiveVersion(skCurrentArchiveVersion)
, mGame(eUnknownGame)
, mIsReader(IsReader)
, mIsWriter(IsWriter)
{}
virtual ~IArchive() {}
#define ENABLE_FOR_SERIAL_TYPE(SType) typename std::enable_if<SerialType<ValType, IArchive>::Type == SerialType<ValType, IArchive>::##SType, int>::type = 0
// Serialize primitives
template<typename ValType, ENABLE_FOR_SERIAL_TYPE(Primitive)>
inline IArchive& operator<<(TSerialParameter<ValType> rParam)
@ -419,12 +415,15 @@ public:
BulkSerialize(InArray.data(), Size);
}
// Meta
virtual bool IsReader() const = 0;
virtual bool IsWriter() const = 0;
virtual bool IsTextFormat() const = 0;
// Accessors
inline u16 ArchiveVersion() const { return mArchiveVersion; }
inline u16 FileVersion() const { return mFileVersion; }
inline EGame Game() const { return mGame; }
inline bool IsReader() const { return mIsReader; }
inline bool IsWriter() const { return mIsWriter; }
inline void SetVersion(u16 ArchiveVersion, u16 FileVersion, EGame Game)
{
@ -446,6 +445,32 @@ public:
}
};
// Default enum serializer; can be overridden
#include <codegen/EnumReflection.h>
template<typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
inline void Serialize(IArchive& Arc, T& Val)
{
if (Arc.IsTextFormat())
{
if (Arc.IsReader())
{
TString ValueName;
Arc.SerializePrimitive(ValueName);
Val = TEnumReflection<T>::ConvertStringToValue( *ValueName );
}
else
{
TString ValueName = TEnumReflection<T>::ConvertValueToString(Val);
Arc.SerializePrimitive(ValueName);
}
}
else
{
Arc.SerializePrimitive((u32&) Val);
}
}
// Container serialize methods
#include <list>
#include <map>

View File

@ -68,6 +68,7 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.1.0/lib/Release/x64 -lglew32s \
# Include Paths
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/glew-2.1.0/include \
$$EXTERNALS_DIR/lzo-2.10/include \
$$EXTERNALS_DIR/nod/include \
@ -161,7 +162,6 @@ HEADERS += \
OpenGL/CVertexBuffer.h \
OpenGL/GLCommon.h \
ScriptExtra/CRadiusSphereExtra.h \
Resource/EGame.h \
Resource/Cooker/CAreaCooker.h \
Resource/Script/IPropertyValue.h \
Resource/Script/IPropertyTemplate.h \
@ -368,6 +368,11 @@ SOURCES += \
Resource/Script/CPropertyNameGenerator.cpp \
Resource/Script/IPropertyNew.cpp
# Codegen
CODEGEN_OUT_PATH = $$BUILD_DIR/Core/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)
# Library Sources
SOURCES += $$EXTERNALS_DIR/lzo-2.10/src/lzo_init.c \
$$EXTERNALS_DIR/lzo-2.10/src/lzo1x_9x.c \

View File

@ -63,10 +63,6 @@ enum class EPropertyTypeNew
Array = FOURCC('ARRY'),
Invalid = FOURCC('INVD')
};
inline void Serialize(IArchive& rArc, EPropertyTypeNew& rType)
{
rArc.SerializePrimitive( (CFourCC&) rType );
}
inline const char* PropEnumToHashableTypeName(EPropertyTypeNew Type)
{
@ -105,10 +101,6 @@ enum class ECookPreferenceNew
Always,
Never
};
inline void Serialize(IArchive& rArc, ECookPreferenceNew& rPref)
{
rArc.SerializePrimitive( (u32&) rPref );
}
/** New property class */
class IPropertyNew

View File

@ -80,6 +80,7 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.1.0/lib/Release/x64 -lglew32s \
# Include Paths
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/glew-2.1.0/include \
$$EXTERNALS_DIR/lzo-2.10/include \
$$EXTERNALS_DIR/nod/include \
@ -303,3 +304,8 @@ FORMS += \
CProgressDialog.ui \
Widgets/CSelectResourcePanel.ui \
CGeneratePropertyNamesDialog.ui
# Codegen
CODEGEN_OUT_PATH = $$BUILD_DIR/Editor/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)

View File

@ -47,6 +47,7 @@ CONFIG (release, debug|release) {
# Include Paths
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/tinyxml2
# Header Files
@ -77,3 +78,8 @@ SOURCES += \
CVector3f.cpp \
CVector4f.cpp \
MathUtil.cpp
# Codegen
CODEGEN_OUT_PATH = $$BUILD_DIR/Common/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)