refactor(2/?)

This commit is contained in:
yyc12345 2023-08-23 16:04:58 +08:00
parent 1b8f2ff0d5
commit ad9d0cadce
16 changed files with 857 additions and 566 deletions

View File

@ -1,4 +1,5 @@
#include "CKContext.hpp" #include "CKContext.hpp"
#include "CKObjectImplements/CKObject.hpp"
#include <cstdarg> #include <cstdarg>
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
@ -9,59 +10,112 @@ namespace LibCmo::CK2 {
static char g_UniqueFolder[] = "LibCmo"; static char g_UniqueFolder[] = "LibCmo";
#endif #endif
#pragma region Objects Management
CKObject* CKContext::CreateCKObject(CK_CLASSID cls, CKSTRING name,
CK_OBJECTCREATION_OPTIONS options = CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECHECK,
CK_CREATIONMODE* res = nullptr) {
// todo: Process paramter options and res
// get description first
const CKClassDesc* desc = CKGetClassDesc(cls);
if (desc == nullptr) return nullptr;
// allocate a CK_ID first
CK_ID decided_id;
if (this->m_ReturnedObjectIds.empty()) {
// create new CK_ID.
decided_id = m_ObjectsList.size();
m_ObjectsList.resize(decided_id + 1);
} else {
// use returned CK_ID.
decided_id = m_ReturnedObjectIds.back();
m_ReturnedObjectIds.pop_back();
}
// create one
CKObject* obj = desc->CreationFct(this, decided_id, name);
// put into slot
m_ObjectsList[decided_id] = obj;
}
CKObject* CKContext::GetCKObject(CK_ID id) {
if (id >= m_ObjectsList.size()) return nullptr;
return m_ObjectsList[id];
}
/**
* @brief The real CKObject destroy worker shared by CKContext::DestroyCKObject and CKContext::~CKContext
* @param[in] ctx The CKContext
* @param[in] obj The CKObject need to be free.
*/
static void InternalDestroy(CKContext* ctx, CKObject* obj) {
// find desc by classid
// if really we can not find it, we only can delete it directly.
const CKClassDesc* desc = CKGetClassDesc(obj->GetClassID());
if (desc == nullptr) {
delete obj;
return;
}
// free it and return its value
desc->ReleaseFct(ctx, obj);
}
void CKContext::DestroyCKObject(CK_ID id) {
if (id >= m_ObjectsList.size()) return;
// get object and free it
CKObject* obj = m_ObjectsList[id];
if (obj == nullptr) return;
InternalDestroy(this, obj);
// return its allocated id.
m_ObjectsList[id] = nullptr;
m_ReturnedObjectIds.emplace_back(id);
}
#pragma endregion
#pragma region Ctor Dtor #pragma region Ctor Dtor
CKMinContext::CKMinContext() : CKContext::CKContext() :
m_ObjectsList(), m_ReturnedObjectIds(),
m_NameEncoding(), m_TempFolder(), m_NameEncoding(), m_TempFolder(),
m_PrintCallback(nullptr), m_OutputCallback(nullptr)
m_CKObjectMaxID(0u),
// register CKObjects
m_ObjectsCreationMap{
{CK_CLASSID::CKCID_OBJECT, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKObject(ctx, id, name); })},
{CK_CLASSID::CKCID_SCENEOBJECT, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKSceneObject(ctx, id, name); })},
{CK_CLASSID::CKCID_BEOBJECT, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBeObject(ctx, id, name); })},
{CK_CLASSID::CKCID_GROUP, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKGroup(ctx, id, name); })},
{CK_CLASSID::CKCID_MESH, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKMesh(ctx, id, name); })},
{CK_CLASSID::CKCID_TEXTURE, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKTexture(ctx, id, name); })},
{CK_CLASSID::CKCID_MATERIAL, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKMaterial(ctx, id, name); })},
{CK_CLASSID::CKCID_RENDEROBJECT, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKRenderObject(ctx, id, name); })},
{CK_CLASSID::CKCID_3DENTITY, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CK3dEntity(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETERIN, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterIn(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETER, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameter(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETEROUT, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterOut(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETERLOCAL, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterLocal(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETEROPERATION, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterOperation(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIORLINK, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehaviorLink(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIORIO, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehaviorLink(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIOR, ([](CKMinContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehavior(ctx, id, name); })}
},
// register CKBaseManagers
m_ManagersCreationMap{
{ATTRIBUTE_MANAGER_GUID, ([](CKMinContext* ctx, CK_ID id) ->CKManagerImplements::CKBaseManager* { return new(std::nothrow) CKManagerImplements::CKAttributeManager(ctx, id); })},
}
{ {
// preset for temp folder // preset for temp folder
// todo: add current CKContext pointer as the part of temp path.
// thus multiple CKContext can work.
m_TempFolder = std::filesystem::temp_directory_path(); m_TempFolder = std::filesystem::temp_directory_path();
m_TempFolder /= g_UniqueFolder; m_TempFolder /= g_UniqueFolder;
std::filesystem::create_directory(m_TempFolder); std::filesystem::create_directory(m_TempFolder);
} }
CKMinContext::~CKMinContext() {
CKContext::~CKContext() {
// free all created objects // free all created objects
for (const auto& [key, value] : this->m_ObjectsList) { for (auto& ptr : m_ObjectsList) {
delete value; if (ptr != nullptr) {
InternalDestroy(this, ptr);
} }
}
// todo: free all created managers // todo: free all created managers
} }
#pragma endregion #pragma endregion
#pragma region Print #pragma region Output utilities
void CKMinContext::Printf(CKSTRING fmt, ...) { void CKContext::OutputToConsole(CKSTRING str) {
if (m_PrintCallback == nullptr) return; if (m_OutputCallback == nullptr) return;
m_OutputCallback(str);
}
void CKContext::OutputToConsoleEx(CKSTRING fmt, ...) {
if (m_OutputCallback == nullptr) return;
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
@ -75,69 +129,34 @@ namespace LibCmo::CK2 {
va_end(argptr); va_end(argptr);
m_PrintCallback(result); m_OutputCallback(result.c_str());
} }
void CKMinContext::SetPrintCallback(PrintCallback cb) { void CKContext::SetOutputCallback(OutputCallback cb) {
m_PrintCallback = cb; m_OutputCallback = cb;
} }
#pragma endregion #pragma endregion
#pragma region Objects #pragma region Temp IO utilities
CKObjectImplements::CKObject* CKMinContext::CreateCKObject(CK_ID id, CK_CLASSID cls, CKSTRING name) { void CKContext::SetTempPath(CKSTRING u8_temp) {
// pick creation function EncodingHelper::SetStdPathFromU8Path(this->m_TempFolder, u8_temp);
const auto& creation = m_ObjectsCreationMap.find(cls);
if (creation == m_ObjectsCreationMap.end()) return nullptr;
// check ckid
if (m_ObjectsList.contains(id)) return nullptr;
// create it
return creation->second(this, id, name);
} }
CKObjectImplements::CKObject* CKMinContext::GetCKObject(CK_ID id) { FILE* CKContext::OpenTempFile(CKSTRING u8_filename, CKBOOL is_read) {
const auto& probe = m_ObjectsList.find(id); std::filesystem::path stdfilename;
if (probe == m_ObjectsList.end()) return nullptr; EncodingHelper::SetStdPathFromU8Path(stdfilename, u8_filename);
else return probe->second;
}
void CKMinContext::DestroyCKObject(CK_ID id) { auto realfile = this->m_TempFolder / stdfilename;
const auto& probe = m_ObjectsList.find(id); return EncodingHelper::OpenStdPathFile(realfile, is_read);
if (probe != m_ObjectsList.end()) {
delete (probe->second);
m_ObjectsList.erase(probe);
}
}
void CKMinContext::ClearCKObject(void) {
// free all created objects
for (const auto& [key, value] : this->m_ObjectsList) {
delete value;
}
// clear list
this->m_ObjectsList.clear();
}
CK_ID CKMinContext::GetObjectMaxID(void) {
return this->m_CKObjectMaxID;
}
void CKMinContext::SetObjectMaxID(CK_ID id) {
this->m_CKObjectMaxID = id;
} }
#pragma endregion #pragma endregion
#pragma region Managers #pragma region Encoding utilities
#pragma endregion void CKContext::GetUtf8String(const std::string& native_name, std::string& u8_name) {
#pragma region Misc Funcs
void CKMinContext::GetUtf8String(const std::string& native_name, std::string& u8_name) {
bool success = false; bool success = false;
for (const auto& token : this->m_NameEncoding) { for (const auto& token : this->m_NameEncoding) {
success = LibCmo::EncodingHelper::GetUtf8VirtoolsName(native_name, u8_name, token); success = LibCmo::EncodingHelper::GetUtf8VirtoolsName(native_name, u8_name, token);
@ -147,11 +166,11 @@ namespace LibCmo::CK2 {
// fallback // fallback
if (!success) { if (!success) {
u8_name = native_name; u8_name = native_name;
this->Printf("Error when converting to UTF8 string."); this->OutputToConsole("Error when converting to UTF8 string.");
} }
} }
void CKMinContext::GetNativeString(const std::string& u8_name, std::string& native_name) { void CKContext::GetNativeString(const std::string& u8_name, std::string& native_name) {
bool success = false; bool success = false;
for (const auto& token : this->m_NameEncoding) { for (const auto& token : this->m_NameEncoding) {
success = LibCmo::EncodingHelper::GetNativeVirtoolsName(u8_name, native_name, token); success = LibCmo::EncodingHelper::GetNativeVirtoolsName(u8_name, native_name, token);
@ -161,11 +180,11 @@ namespace LibCmo::CK2 {
// fallback // fallback
if (!success) { if (!success) {
native_name = u8_name; native_name = u8_name;
this->Printf("Error when converting to native string."); this->OutputToConsole("Error when converting to native string.");
} }
} }
void CKMinContext::SetEncoding(const std::vector<std::string> encoding_series) { void CKContext::SetEncoding(const std::vector<std::string> encoding_series) {
// free all current series // free all current series
for (const auto& encoding : this->m_NameEncoding) { for (const auto& encoding : this->m_NameEncoding) {
LibCmo::EncodingHelper::DestroyEncodingToken(encoding); LibCmo::EncodingHelper::DestroyEncodingToken(encoding);
@ -178,17 +197,6 @@ namespace LibCmo::CK2 {
} }
} }
void CKMinContext::SetTempPath(CKSTRING u8_temp) {
EncodingHelper::SetStdPathFromU8Path(this->m_TempFolder, u8_temp);
}
FILE* CKMinContext::OpenTempFile(CKSTRING u8_filename, bool is_read) {
std::filesystem::path stdfilename;
EncodingHelper::SetStdPathFromU8Path(stdfilename, u8_filename);
auto realfile = this->m_TempFolder / stdfilename;
return EncodingHelper::OpenStdPathFile(realfile, is_read);
}
#pragma endregion #pragma endregion

View File

@ -3,6 +3,7 @@
#include "../VTAll.hpp" #include "../VTAll.hpp"
#include <filesystem> #include <filesystem>
#include <map> #include <map>
#include <deque>
#include <functional> #include <functional>
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
@ -24,49 +25,72 @@ namespace LibCmo::CK2 {
CKContext& operator=(const CKContext&) = delete; CKContext& operator=(const CKContext&) = delete;
~CKContext(); ~CKContext();
using PrintCallback = std::function<void(const std::string&)>; // ========== Objects Management ==========
void Printf(CKSTRING fmt, ...);
void SetPrintCallback(PrintCallback cb);
/** /**
* @brief Creates a CKObject or derived class instance. * @brief Creates a CKObject or derived class instance.
* @param[in] cls Class Identifier (CK_CLASSID) of the object to create. * @param[in] cls Class Identifier (CK_CLASSID) of the object to create.
* @param[in] name The name of this object. * @param[in] name The name of this object.
* @param[in] options Tell CKContext how to create this object when conflict happended.
* @param[out] res The value indicate the real method how this object created.
* @return A pointer to the newly created object. * @return A pointer to the newly created object.
* @remark CKObjects must be destroy with the DestroyObject method. * @remark CKObjects must be destroy with the DestroyObject method.
* @see CKObject, DestroyObject * @see CKObject, DestroyObject
*/ */
CKObject* CreateCKObject(CK_CLASSID cls, CKSTRING name); CKObject* CreateCKObject(CK_CLASSID cls, CKSTRING name,
CK_OBJECTCREATION_OPTIONS options = CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECHECK,
CK_CREATIONMODE* res = nullptr);
CKObject* GetCKObject(CK_ID id); CKObject* GetCKObject(CK_ID id);
void DestroyCKObject(CK_ID id); void DestroyCKObject(CK_ID id);
// ========== Object Access ==========
//CKManagerImplements::CKBaseManager* CreateCKManager(CKGUID guid); //CKManagerImplements::CKBaseManager* CreateCKManager(CKGUID guid);
//CKManagerImplements::CKBaseManager* GetCKManager(CK_ID guid); //CKManagerImplements::CKBaseManager* GetCKManager(CK_ID guid);
//void DestroyCKManager(CKManagerImplements::CKBaseManager* mgr); //void DestroyCKManager(CKManagerImplements::CKBaseManager* mgr);
CK_ID GetObjectMaxID(void); //CKObject* GetObjectByName(CKSTRING name, CKObject* previous = NULL);
void SetObjectMaxID(CK_ID id); //CKObject* GetObjectByNameAndClass(CKSTRING name, CK_CLASSID cid, CKObject* previous = NULL);
//CKObject* GetObjectByNameAndParentClass(CKSTRING name, CK_CLASSID pcid, CKObject* previous);
//const XContainer::XObjectPointerArray GetObjectListByType(CK_CLASSID cid, CKBOOL derived);
//CKINT GetObjectsCountByClassID(CK_CLASSID cid);
//CK_ID* GetObjectsListByClassID(CK_CLASSID cid);
// ========== Encoding utilities ==========
void GetUtf8String(const std::string& native_name, std::string& u8_name); void GetUtf8String(const std::string& native_name, std::string& u8_name);
void GetNativeString(const std::string& u8_name, std::string& native_name); void GetNativeString(const std::string& u8_name, std::string& native_name);
void SetEncoding(const std::vector<std::string> encoding_series); void SetEncoding(const std::vector<std::string> encoding_series);
// ========== Temp IO utilities ==========
void SetTempPath(CKSTRING u8_temp); void SetTempPath(CKSTRING u8_temp);
FILE* OpenTempFile(CKSTRING u8_filename, CKBOOL is_read);
FILE* OpenTempFile(CKSTRING u8_filename, bool is_read); // ========== Print utilities ==========
public: using OutputCallback = std::function<void(CKSTRING)>;
std::map<CK_ID, CKObject*> m_ObjectsList; void OutputToConsole(CKSTRING str);
std::map<CK_ID, CKBaseManager*> m_ManagersList; void OutputToConsoleEx(CKSTRING fmt, ...);
void SetOutputCallback(OutputCallback cb);
std::map<CK_CLASSID, std::function<CKObject* (CKContext*, CK_ID, CKSTRING)>> m_ObjectsCreationMap; protected:
std::map<CKGUID, std::function<CKBaseManager* (CKContext*, CK_ID)>> m_ManagersCreationMap; // ========== Objects Management ==========
CK_ID m_CKObjectMaxID; XContainer::XArray<CKObject*> m_ObjectsList;
std::deque<CK_ID> m_ReturnedObjectIds;
// ========== Encoding utilities ==========
std::vector<EncodingHelper::ENCODING_TOKEN> m_NameEncoding; std::vector<EncodingHelper::ENCODING_TOKEN> m_NameEncoding;
// ========== Temp IO utilities ==========
std::filesystem::path m_TempFolder; std::filesystem::path m_TempFolder;
PrintCallback m_PrintCallback;
// ========== Print utilities ==========
OutputCallback m_OutputCallback;
}; };
} }

View File

@ -1,10 +1,12 @@
#pragma once #pragma once
#include "CKTypes.hpp"
#include "../XContainer/XTypes.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include <cinttypes> #include <cinttypes>
#include "CKTypes.hpp" #include <functional>
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
/** /**
@ -16,4 +18,55 @@ namespace LibCmo::CK2 {
*/ */
constexpr const CKDWORD DEVVERSION = 0x02050000u; constexpr const CKDWORD DEVVERSION = 0x02050000u;
constexpr const CKGUID VIRTOOLS_GUID = CKGUID(0x56495254u, 0x4f4f4c53u); constexpr const CKGUID VIRTOOLS_GUID = CKGUID(0x56495254u, 0x4f4f4c53u);
// ========== Class registration utilities ==========
//using CKClassRegisterFct = std::function<void()>;
using CKClassCreationFct = std::function<CKObject* (CKContext*, CK_ID, CKSTRING)>;
using CKClassReleaseFct = std::function<void(CKContext*, CKObject*)>;
using CKClassNameFct = std::function<CKSTRING()>;
//using CKClassDependenciesFct = std::function<CKSTRING(CKINT, CKINT)>;
//using CKClassDependenciesCountFct = std::function<CKINT(CKINT)>;
struct CKClassDesc {
CKBOOL Done;
// Initialized upon class registration
CK_CLASSID Self;
CK_CLASSID Parent; // Class Identifier of parent class
//CKClassRegisterFct RegisterFct; // Pointer to Class Specific Registration function
CKClassCreationFct CreationFct; // Pointer to Class instance creation function
CKClassReleaseFct ReleaseFct; // Pointer to Class instance release function
CKClassNameFct NameFct; // Pointer to Class name function
//CKClassDependenciesFct DependsFct; // Pointer to Class dependencies function (Copy,delete,replace...)
//CKClassDependenciesCountFct DependsCountFct; // Pointer to Class dependencies Count function (Copy,delete,replace...)
//// Initialized by class specific registration function
//CKDWORD DefaultOptions; // Default options for this class
//CKDWORD DefaultCopyDependencies;
//CKDWORD DefaultDeleteDependencies;
//CKDWORD DefaultReplaceDependencies;
//CKDWORD DefaultSaveDependencies;
//CKGUID Parameter; // Associated parameter GUID
// Initialized when building class hierarchy table
CKINT DerivationLevel; // O => CKObject , etc..
XContainer::XBitArray Parents; // Bit Mask of parents classes
XContainer::XBitArray Children; // Bit Mask of children classes
//XContainer::XBitArray ToBeNotify; // Mask for Classes that should warn the objects of this class when they are deleted
//XContainer::XBitArray CommonToBeNotify; // idem but merged with sub classes masks
//XContainer::XSArray<CK_CLASSID> ToNotify; // List of ClassID to notify when an object of this class is deleted (inverse of ToBeNotify)
CKClassDesc() :
Done(CKFALSE),
Self(CK_CLASSID::CKCID_OBJECT), Parent(CK_CLASSID::CKCID_OBJECT),
CreationFct(nullptr), ReleaseFct(nullptr), NameFct(nullptr),
DerivationLevel(0),
Parents(), Children()
{}
CKClassDesc(const CKClassDesc& rhs) = default;
CKClassDesc(CKClassDesc&& rhs) = default;
CKClassDesc& operator=(const CKClassDesc& rhs) = default;
CKClassDesc& operator=(CKClassDesc& rhs) = default;
};
} }

View File

@ -64,7 +64,6 @@ namespace LibCmo::CK2 {
CKFILE_FORVIEWER = 4, /**< Don't save Interface Data within the file, the level won't be editable anymore in the interface */ CKFILE_FORVIEWER = 4, /**< Don't save Interface Data within the file, the level won't be editable anymore in the interface */
CKFILE_WHOLECOMPRESSED = 8, /**< Compress the whole file */ CKFILE_WHOLECOMPRESSED = 8, /**< Compress the whole file */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_FILE_WRITEMODE);
/** /**
Load Options. Load Options.
@remark @remark
@ -88,7 +87,6 @@ namespace LibCmo::CK2 {
CK_LOAD_CHECKDEPENDENCIES = 1 << 7, /**< Check if every plugins needed are availables */ CK_LOAD_CHECKDEPENDENCIES = 1 << 7, /**< Check if every plugins needed are availables */
CK_LOAD_ONLYBEHAVIORS = 1 << 8, /**< */ CK_LOAD_ONLYBEHAVIORS = 1 << 8, /**< */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_LOAD_FLAGS);
/** /**
Options that will be used to create this object... Options that will be used to create this object...
*/ */
@ -99,6 +97,36 @@ namespace LibCmo::CK2 {
CK_FO_DONTLOADOBJECT, /**< Object chunk will not be read either because it is a reference or because the loaded object already exist in the current level and the user choose to keep the existing one. */ CK_FO_DONTLOADOBJECT, /**< Object chunk will not be read either because it is a reference or because the loaded object already exist in the current level and the user choose to keep the existing one. */
}; };
/** /**
Summary: Specify the way an object just loaded should be handled when it already exists in the level.
*/
enum class CK_LOADMODE : int32_t {
CKLOAD_INVALID = -1, /**< Use the existing object instead of loading */
CKLOAD_OK = 0, /**< Ignore ( Name unicity is broken ) */
CKLOAD_REPLACE = 1, /**< Replace the existing object (Not yet implemented) */
CKLOAD_RENAME = 2, /**< Rename the loaded object */
CKLOAD_USECURRENT = 3,/**< Use the existing object instead of loading */
};
using CK_CREATIONMODE = CK_LOADMODE;
/**
Specify the way an object is created through CKCreateObject.
@remark
+ These flag controls the way an object is created, the most important of these flags
being CK_OBJECTCREATION_DYNAMIC which, if set in CKCreateObject, make the newly created object
dynamic.
@see CKContext::CreateObject
*/
enum class CK_OBJECTCREATION_OPTIONS : uint32_t {
CK_OBJECTCREATION_NONAMECHECK = 0, /**< Do not test for name unicity (may be overriden in special case) */
CK_OBJECTCREATION_REPLACE = 1, /**< Replace the current object by the object being loaded */
CK_OBJECTCREATION_RENAME = 2, /**< Rename the created object to ensure its uniqueness */
CK_OBJECTCREATION_USECURRENT = 3, /**< Do not create a new object, use the one with the same name instead */
CK_OBJECTCREATION_ASK = 4, /**< If a duplicate name if found, opens a dialog box to ask the useror use automatic load mode if any. */
CK_OBJECTCREATION_FLAGSMASK = 0x0000000F, /**< Mask for previous values */
CK_OBJECTCREATION_DYNAMIC = 0x00000010, /**< The object must be created dynamic */
CK_OBJECTCREATION_ACTIVATE = 0x00000020, /**< The object will be copied/created active */
CK_OBJECTCREATION_NONAMECOPY = 0x00000040 /**< The object will take control of the string given to it directly, without copying it */
};
/**
Type identifier for a Virtools plugin. Type identifier for a Virtools plugin.
@remark @remark
+ Each plugin must be given a type. + Each plugin must be given a type.
@ -130,7 +158,6 @@ namespace LibCmo::CK2 {
CHNK_DONTDELETE_PTR = 0x40, /**< Data buffer stored in m_Buffer is not owned by CKStateChunk , it must not be deleted... */ CHNK_DONTDELETE_PTR = 0x40, /**< Data buffer stored in m_Buffer is not owned by CKStateChunk , it must not be deleted... */
CHNK_DONTDELETE_PARSER = 0x80, /**< m_Parser Ptr is not owned by CKStateChunk , it must not be deleted... */ CHNK_DONTDELETE_PARSER = 0x80, /**< m_Parser Ptr is not owned by CKStateChunk , it must not be deleted... */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATECHUNK_CHUNKOPTIONS);
enum class CK_STATECHUNK_CHUNKVERSION : uint32_t { enum class CK_STATECHUNK_CHUNKVERSION : uint32_t {
CHUNK_VERSIONBASE = 0, CHUNK_VERSIONBASE = 0,
CHUNK_VERSION1 = 4, /**< equal to file version : WriteObjectID => table */ CHUNK_VERSION1 = 4, /**< equal to file version : WriteObjectID => table */
@ -196,6 +223,5 @@ namespace LibCmo::CK2 {
CKBEHAVIORLINK_ACTIVATEDLASTFRAME = 0x20000000, /**< This link had been activated last frame */ CKBEHAVIORLINK_ACTIVATEDLASTFRAME = 0x20000000, /**< This link had been activated last frame */
CK_OBJECT_BEHAVIORLINKMASK = 0x30000000, CK_OBJECT_BEHAVIORLINKMASK = 0x30000000,
}; };
LIBCMO_BITFLAG_OPERATORS(CK_OBJECT_FLAGS);
} }

View File

@ -1,13 +1,19 @@
#include "VTUtils.hpp" #include "../VTUtils.hpp"
#if defined(LIBCMO_OS_WIN32) #if defined(LIBCMO_OS_WIN32)
#define ZLIB_WINAPI #define ZLIB_WINAPI
#endif #endif
#include <zconf.h> #include <zconf.h>
#include "../VTEncoding.hpp"
#include "CKGlobals.hpp" #include "CKGlobals.hpp"
#include <map>
#include <algorithm>
#include <zlib.h> #include <zlib.h>
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
#pragma region Compression utilities
void* CKPackData(const void* Data, CKINT size, CKINT& NewSize, CKINT compressionlevel) { void* CKPackData(const void* Data, CKINT size, CKINT& NewSize, CKINT compressionlevel) {
uLong boundary = compressBound(static_cast<uLong>(size)); uLong boundary = compressBound(static_cast<uLong>(size));
char* DestBuffer = new char[boundary]; char* DestBuffer = new char[boundary];
@ -40,7 +46,7 @@ namespace LibCmo::CK2 {
return DestBuffer; return DestBuffer;
} }
CKDWORD CKComputeDataCRC(const void* data, size_t size, CKDWORD PreviousCRC) { CKDWORD CKComputeDataCRC(const void* data, CKINT size, CKDWORD PreviousCRC) {
return static_cast<CKDWORD>(adler32( return static_cast<CKDWORD>(adler32(
static_cast<uLong>(PreviousCRC), static_cast<uLong>(PreviousCRC),
reinterpret_cast<const Bytef*>(data), reinterpret_cast<const Bytef*>(data),
@ -48,4 +54,183 @@ namespace LibCmo::CK2 {
)); ));
} }
#pragma endregion
#pragma region CKClass Registration
static XContainer::XArray<CKClassDesc> g_CKClassInfo;
static std::map<CK_CLASSID, size_t> g_CKClassInfoId2Idx;
static CK_CLASSID g_CKClassInfoMaxID = static_cast<CK_CLASSID>(0);
static void ComputeParentsTable(CKClassDesc& desc) {
// if it has done, do not process it again.
if (desc.Done) return;
// find direct parent
auto finder = g_CKClassInfoId2Idx.find(desc.Parent);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
CKClassDesc& parent = g_CKClassInfo[finder->second];
// if it is not self inheritance, call recursively
if (desc.Self != desc.Parent) {
ComputeParentsTable(parent);
}
// copy parent's parents
desc.Parents = parent.Parents;
// and set self as its parent
finder = g_CKClassInfoId2Idx.find(desc.Self);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
desc.Parents[finder->second] = true;
// set derivation level
desc.DerivationLevel = parent.DerivationLevel + 1;
// set done
desc.Done = CKTRUE;
}
static void CKBuildClassHierarchyTable() {
// set Done to false and resize all XBitArray
size_t classCount = g_CKClassInfo.size();
for (auto& item : g_CKClassInfo) {
item.Done = CKFALSE;
item.Parents.resize(classCount, false);
item.Children.resize(classCount, false);
}
// compute parents
for (auto& item : g_CKClassInfo) {
ComputeParentsTable(item);
}
// compute children by parents table
// iterate CKClassDesc::Parents and register it self to gotten parents
for (auto& item : g_CKClassInfo) {
auto finder = g_CKClassInfoId2Idx.find(item.Self);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
size_t selfidx = finder->second;
for (size_t idx = 0; idx < classCount; ++idx) {
// if this idx is its parent,
// add self to parent.
if (item.Parents[idx]) {
g_CKClassInfo[idx].Children[selfidx] = true;
}
}
}
}
void CKClassRegister(CK_CLASSID cid, CK_CLASSID parentCid,
CKClassCreationFct createFct, CKClassReleaseFct relFct, CKClassNameFct nameFct) {
CKClassDesc desc;
desc.Self = cid;
desc.Parent = parentCid;
desc.CreationFct = createFct;
desc.ReleaseFct = relFct;
desc.NameFct = nameFct;
g_CKClassInfoId2Idx.emplace(cid, g_CKClassInfo.size());
g_CKClassInfo.emplace_back(std::move(desc));
g_CKClassInfoMaxID = std::max(g_CKClassInfoMaxID, cid);
}
#pragma endregion
#pragma region Class Hierarchy Management
CKINT CKGetClassCount() {
return g_CKClassInfo.size();
}
const CKClassDesc* CKGetClassDesc(CK_CLASSID cid) {
auto finder = g_CKClassInfoId2Idx.find(cid);
if (finder == g_CKClassInfoId2Idx.end()) return nullptr;
return g_CKClassInfo.data() + finder->second;
}
CKSTRING CKClassIDToString(CK_CLASSID cid) {
auto finder = g_CKClassInfoId2Idx.find(cid);
if (finder == g_CKClassInfoId2Idx.end() || g_CKClassInfo[finder->second].NameFct == nullptr) return "Invalid Class Identifier";
return g_CKClassInfo[finder->second].NameFct();
}
CKBOOL CKIsChildClassOf(CK_CLASSID child, CK_CLASSID parent) {
// get corresponding index first
auto finder = g_CKClassInfoId2Idx.find(child);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
size_t child_idx = finder->second;
finder = g_CKClassInfoId2Idx.find(parent);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
size_t parent_idx = finder->second;
return g_CKClassInfo[child_idx].Parents[parent_idx];
}
CK_CLASSID CKGetParentClassID(CK_CLASSID child) {
auto finder = g_CKClassInfoId2Idx.find(child);
if (finder == g_CKClassInfoId2Idx.end()) std::abort();
return g_CKClassInfo[finder->second].Parent;
}
CK_CLASSID CKGetCommonParent(CK_CLASSID cid1, CK_CLASSID cid2) {
// I don't know algorithm, I just copy the decompiled code.
while (true) {
if (CKIsChildClassOf(cid1, cid2)) return cid2;
if (CKIsChildClassOf(cid2, cid1)) break;
cid2 = CKGetParentClassID(cid1);
cid1 = cid2;
}
return cid1;
}
#pragma endregion
#pragma region Initializations functions
CKERROR CKStartUp() {
// todo: add class type registrations
/*
// register CKObjects
m_ObjectsCreationMap{
{CK_CLASSID::CKCID_OBJECT, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKObject(ctx, id, name); })},
{CK_CLASSID::CKCID_SCENEOBJECT, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKSceneObject(ctx, id, name); })},
{CK_CLASSID::CKCID_BEOBJECT, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBeObject(ctx, id, name); })},
{CK_CLASSID::CKCID_GROUP, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKGroup(ctx, id, name); })},
{CK_CLASSID::CKCID_MESH, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKMesh(ctx, id, name); })},
{CK_CLASSID::CKCID_TEXTURE, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKTexture(ctx, id, name); })},
{CK_CLASSID::CKCID_MATERIAL, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKMaterial(ctx, id, name); })},
{CK_CLASSID::CKCID_RENDEROBJECT, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKRenderObject(ctx, id, name); })},
{CK_CLASSID::CKCID_3DENTITY, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CK3dEntity(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETERIN, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterIn(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETER, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameter(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETEROUT, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterOut(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETERLOCAL, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterLocal(ctx, id, name); })},
{CK_CLASSID::CKCID_PARAMETEROPERATION, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKParameterOperation(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIORLINK, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehaviorLink(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIORIO, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehaviorLink(ctx, id, name); })},
{CK_CLASSID::CKCID_BEHAVIOR, ([](CKContext* ctx, CK_ID id, CKSTRING name) ->CKObjectImplements::CKObject* { return new(std::nothrow) CKObjectImplements::CKBehavior(ctx, id, name); })}
},
// register CKBaseManagers
m_ManagersCreationMap{
{ATTRIBUTE_MANAGER_GUID, ([](CKContext* ctx, CK_ID id) ->CKManagerImplements::CKBaseManager* { return new(std::nothrow) CKManagerImplements::CKAttributeManager(ctx, id); })},
}
*/
return CKERROR::CKERR_OK;
}
CKERROR CKShutdown() {
// free class indo
g_CKClassInfo.clear();
g_CKClassInfoId2Idx.clear();
g_CKClassInfoMaxID = static_cast<CK_CLASSID>(0);
return CKERROR::CKERR_OK;
}
#pragma endregion
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CKTypes.hpp" #include "CkDefines.hpp"
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
@ -43,6 +43,23 @@ namespace LibCmo::CK2 {
* @return CRC of the buffer. * @return CRC of the buffer.
* @see CKPackData, CKUnPackData * @see CKPackData, CKUnPackData
*/ */
CKDWORD CKComputeDataCRC(const void* data, size_t size, CKDWORD PreviousCRC = 0); CKDWORD CKComputeDataCRC(const void* data, CKINT size, CKDWORD PreviousCRC = 0);
// ========== CKClass Registration ==========
void CKClassRegister(CK_CLASSID cid, CK_CLASSID parentCid,
CKClassCreationFct createFct, CKClassReleaseFct relFct, CKClassNameFct nameFct);
// ========== Class Hierarchy Management ==========
CKINT CKGetClassCount();
const CKClassDesc* CKGetClassDesc(CK_CLASSID cid);
CKSTRING CKClassIDToString(CK_CLASSID cid);
CKBOOL CKIsChildClassOf(CK_CLASSID child, CK_CLASSID parent);
CK_CLASSID CKGetParentClassID(CK_CLASSID child);
CK_CLASSID CKGetCommonParent(CK_CLASSID cid1, CK_CLASSID cid2);
// ========== Initializations functions ==========
CKERROR CKStartUp();
CKERROR CKShutdown();
} }

View File

@ -22,7 +22,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_OBJECTHIERAHIDDEN = 0x00000018, /**< The object is hidden hierarchically */ CK_STATESAVE_OBJECTHIERAHIDDEN = 0x00000018, /**< The object is hidden hierarchically */
CK_STATESAVE_OBJECTALL = 0x0000000F, CK_STATESAVE_OBJECTALL = 0x0000000F,
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_OBJECT);
/** /**
Be Object Be Object
*/ */
@ -39,7 +38,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_BEOBJECTONLY = 0x00000FF0, /**< Save only BeObject specific datas */ CK_STATESAVE_BEOBJECTONLY = 0x00000FF0, /**< Save only BeObject specific datas */
CK_STATESAVE_BEOBJECTALL = 0x00000FFF, /**< Save All datas */ CK_STATESAVE_BEOBJECTALL = 0x00000FFF, /**< Save All datas */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_BEOBJECT);
/** /**
3dEntity 3dEntity
*/ */
@ -57,7 +55,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_3DENTITYONLY = 0x003FF000, /**< Save only 3dEntity specific datas */ CK_STATESAVE_3DENTITYONLY = 0x003FF000, /**< Save only 3dEntity specific datas */
CK_STATESAVE_3DENTITYALL = 0x003FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_3DENTITYALL = 0x003FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_3DENTITY);
/** /**
Light Light
*/ */
@ -77,7 +74,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_TLIGHTONLY = 0xF0000000, /**< Save only Target Light specific datas */ CK_STATESAVE_TLIGHTONLY = 0xF0000000, /**< Save only Target Light specific datas */
CK_STATESAVE_TLIGHTALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_TLIGHTALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_LIGHT);
/** /**
Camera Camera
*/ */
@ -96,7 +92,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_TCAMERAONLY = 0x70000000, /**< Save only Target camera specific datas */ CK_STATESAVE_TCAMERAONLY = 0x70000000, /**< Save only Target camera specific datas */
CK_STATESAVE_TCAMERAALL = 0x7FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_TCAMERAALL = 0x7FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_CAMERA);
/** /**
Sprite3D Sprite3D
*/ */
@ -110,7 +105,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SPRITE3DONLY = 0x0FC00000, /**< Save only Sprite3D specific datas */ CK_STATESAVE_SPRITE3DONLY = 0x0FC00000, /**< Save only Sprite3D specific datas */
CK_STATESAVE_SPRITE3DALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_SPRITE3DALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SPRITE3D);
/** /**
Object 3D Object 3D
*/ */
@ -120,7 +114,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_3DOBJECTRONLY = 0x00C00000, /**< Save only 3dObject specific datas */ CK_STATESAVE_3DOBJECTRONLY = 0x00C00000, /**< Save only 3dObject specific datas */
CK_STATESAVE_3DOBJECTALL = 0x03FFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_3DOBJECTALL = 0x03FFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_3DOBJECT);
/** /**
BodyPart BodyPart
*/ */
@ -135,7 +128,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_BODYPARTONLY = 0x7F000000, /**< Save only bodypart specific datas */ CK_STATESAVE_BODYPARTONLY = 0x7F000000, /**< Save only bodypart specific datas */
CK_STATESAVE_BODYPARTALL = 0x7FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_BODYPARTALL = 0x7FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_BODYPART);
/** /**
Character Character
*/ */
@ -153,7 +145,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_CHARACTERONLY = 0xFFC00000, /**< Save only character specific datas */ CK_STATESAVE_CHARACTERONLY = 0xFFC00000, /**< Save only character specific datas */
CK_STATESAVE_CHARACTERALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_CHARACTERALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_CHARACTER);
/** /**
CURVE && Curve Point CURVE && Curve Point
*/ */
@ -172,7 +163,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_CURVEONLY = 0xFFC00000, /**< Save only curve specific data */ CK_STATESAVE_CURVEONLY = 0xFFC00000, /**< Save only curve specific data */
CK_STATESAVE_CURVEALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_CURVEALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_CURVE);
/** /**
2dEntity 2dEntity
*/ */
@ -187,7 +177,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_2DENTITYHIERARCHY = 0x00400000, /**< Save Material */ CK_STATESAVE_2DENTITYHIERARCHY = 0x00400000, /**< Save Material */
CK_STATESAVE_2DENTITYALL = 0x0070FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_2DENTITYALL = 0x0070FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_2DENTITY);
/** /**
Sprite Sprite
*/ */
@ -208,7 +197,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SPRITEONLY = 0xF0EF0000, /**< Save only sprite specific data */ CK_STATESAVE_SPRITEONLY = 0xF0EF0000, /**< Save only sprite specific data */
CK_STATESAVE_SPRITEALL = 0x70FFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_SPRITEALL = 0x70FFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SPRITE);
/** /**
Sprite Text Sprite Text
*/ */
@ -222,7 +210,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SPRITETEXTONLY = 0x0F000000, /**< Save only SpriteText specific data */ CK_STATESAVE_SPRITETEXTONLY = 0x0F000000, /**< Save only SpriteText specific data */
CK_STATESAVE_SPRITETEXTALL = 0x3FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_SPRITETEXTALL = 0x3FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SPRITETEXT);
/** /**
Sound Sound
*/ */
@ -238,7 +225,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SOUNDONLY = 0x000FF000, /**< Save only Sound specific data */ CK_STATESAVE_SOUNDONLY = 0x000FF000, /**< Save only Sound specific data */
CK_STATESAVE_SOUNDALL = 0x000FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_SOUNDALL = 0x000FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SOUND);
/** /**
Wave Sound Wave Sound
*/ */
@ -254,7 +240,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_WAVSOUNDONLY = 0x0FF00000, /**< Save All datas for sub-classes */ CK_STATESAVE_WAVSOUNDONLY = 0x0FF00000, /**< Save All datas for sub-classes */
CK_STATESAVE_WAVSOUNDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_WAVSOUNDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_WAVSOUND);
/** /**
Wave Sound Wave Sound
*/ */
@ -270,7 +255,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_MIDISOUNDONLY = 0x0FF00000, CK_STATESAVE_MIDISOUNDONLY = 0x0FF00000,
CK_STATESAVE_MIDISOUNDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_MIDISOUNDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_MIDISOUND);
/** /**
Place Place
*/ */
@ -281,7 +265,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_PLACELEVEL = 0x00008000, /**< Save level using the place */ CK_STATESAVE_PLACELEVEL = 0x00008000, /**< Save level using the place */
CK_STATESAVE_PLACEALL = 0x0000FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_PLACEALL = 0x0000FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_PLACE);
/** /**
Level CKSaveObjectState will not save any data Level CKSaveObjectState will not save any data
*/ */
@ -293,7 +276,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_LEVELSCENE = 0x80000000, /**< Default and active scene */ CK_STATESAVE_LEVELSCENE = 0x80000000, /**< Default and active scene */
CK_STATESAVE_LEVELALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_LEVELALL = 0xFFFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_LEVEL);
/** /**
GROUP GROUP
*/ */
@ -308,7 +290,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_GROUPRESERVED7 = 0x00080000, /**< Reserved for future use */ CK_STATESAVE_GROUPRESERVED7 = 0x00080000, /**< Reserved for future use */
CK_STATESAVE_GROUPALL = 0x000FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_GROUPALL = 0x000FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_GROUP);
/** /**
MESH CKSaveOjectSave will save all data and does not take flags into account MESH CKSaveOjectSave will save all data and does not take flags into account
*/ */
@ -328,7 +309,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_MESHONLY = 0x00FFF000, /**< Save All datas for sub-classes */ CK_STATESAVE_MESHONLY = 0x00FFF000, /**< Save All datas for sub-classes */
CK_STATESAVE_MESHALL = 0x00FFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_MESHALL = 0x00FFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_MESH);
/** /**
PATCH MESH CKSaveOjectSave will save all data and does not take flags into account PATCH MESH CKSaveOjectSave will save all data and does not take flags into account
*/ */
@ -341,7 +321,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_PATCHMESHONLY = 0x0FF00000, /**< Save All datas for sub-classes */ CK_STATESAVE_PATCHMESHONLY = 0x0FF00000, /**< Save All datas for sub-classes */
CK_STATESAVE_PATCHMESHALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_PATCHMESHALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_PATCHMESH);
/** /**
Material Material
*/ */
@ -357,7 +336,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_MATERIALONLY = 0x000FF000, /**< Save All datas for sub-classes */ CK_STATESAVE_MATERIALONLY = 0x000FF000, /**< Save All datas for sub-classes */
CK_STATESAVE_MATERIALALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_MATERIALALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_MATERIAL);
/** /**
Texture CKSaveOjectSave will save all relevant data and does not take flags into account Texture CKSaveOjectSave will save all relevant data and does not take flags into account
*/ */
@ -378,7 +356,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_TEXONLY = 0x00FFF000, /**< Save Only Texture Data (Dot NOT MODIFY ! Texture loading/saving relies on this value) */ CK_STATESAVE_TEXONLY = 0x00FFF000, /**< Save Only Texture Data (Dot NOT MODIFY ! Texture loading/saving relies on this value) */
CK_STATESAVE_TEXALL = 0x002FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_TEXALL = 0x002FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_TEXTURE);
/** /**
2d CURVE && 2d Curve Point 2d CURVE && 2d Curve Point
*/ */
@ -400,7 +377,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_2DCURVESAVEPOINTS = 0x0003F800, /**< Obsolete */ CK_STATESAVE_2DCURVESAVEPOINTS = 0x0003F800, /**< Obsolete */
CK_STATESAVE_2DCURVEALL = 0x0007FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_2DCURVEALL = 0x0007FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_2DCURVE);
/** /**
Kinematic Chain Kinematic Chain
*/ */
@ -411,7 +387,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_KINEMATICCHAINRESERVED3 = 0x00000080, /**< Reserved for future use */ CK_STATESAVE_KINEMATICCHAINRESERVED3 = 0x00000080, /**< Reserved for future use */
CK_STATESAVE_KINEMATICCHAINALL = 0x000000FF, /**< Save All datas for sub-classes */ CK_STATESAVE_KINEMATICCHAINALL = 0x000000FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_KINEMATICCHAIN);
/** /**
Animation Animation
*/ */
@ -426,7 +401,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_ANIMATIONRESERVED6 = 0x00000800, /**< Reserved for future use */ CK_STATESAVE_ANIMATIONRESERVED6 = 0x00000800, /**< Reserved for future use */
CK_STATESAVE_ANIMATIONALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_ANIMATIONALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_ANIMATION);
/** /**
Keyed Anim Keyed Anim
*/ */
@ -446,7 +420,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_KEYEDANIMRESERVED2 = 0x01000000, /**< Reserved for future use */ CK_STATESAVE_KEYEDANIMRESERVED2 = 0x01000000, /**< Reserved for future use */
CK_STATESAVE_KEYEDANIMRESERVED3 = 0x02000000, /**< Reserved for future use */ CK_STATESAVE_KEYEDANIMRESERVED3 = 0x02000000, /**< Reserved for future use */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_KEYEDANIMATION);
/** /**
Object Animation CKSaveOjectSave will save all relevant data and does not take flags into account Object Animation CKSaveOjectSave will save all relevant data and does not take flags into account
*/ */
@ -471,7 +444,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_KEYEDANIMONLY = 0x03FFF000, /**< Save All datas for sub-classes */ CK_STATESAVE_KEYEDANIMONLY = 0x03FFF000, /**< Save All datas for sub-classes */
CK_STATESAVE_KEYEDANIMALL = 0x03FFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_KEYEDANIMALL = 0x03FFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_OBJECTANIMATION);
/** /**
IK Animation IK Animation
*/ */
@ -487,7 +459,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_IKANIMATIONRESERVED9 = 0x00200000, /**< Reserved for future use */ CK_STATESAVE_IKANIMATIONRESERVED9 = 0x00200000, /**< Reserved for future use */
CK_STATESAVE_IKANIMATIONALL = 0x003FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_IKANIMATIONALL = 0x003FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_IKANIMATION);
/** /**
BehaviorLink BehaviorLink
*/ */
@ -501,7 +472,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_BEHAV_LINKONLY = 0x000000F0, /**< */ CK_STATESAVE_BEHAV_LINKONLY = 0x000000F0, /**< */
CK_STATESAVE_BEHAV_LINKALL = 0x000000FF, /**< Save All datas for sub-classes */ CK_STATESAVE_BEHAV_LINKALL = 0x000000FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_BEHAV_LINK);
/** /**
BehaviorIO BehaviorIO
*/ */
@ -514,7 +484,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_BEHAVIOONLY = 0x000000F0, /**< */ CK_STATESAVE_BEHAVIOONLY = 0x000000F0, /**< */
CK_STATESAVE_BEHAVIOALL = 0x000000FF, /**< Save All datas for sub-classes */ CK_STATESAVE_BEHAVIOALL = 0x000000FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_BEHAV_IO);
/** /**
BehaviorPrototype BehaviorPrototype
*/ */
@ -537,7 +506,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_PROTORESERVED14 = 0x00080000, /**< Reserved for future use */ CK_STATESAVE_PROTORESERVED14 = 0x00080000, /**< Reserved for future use */
CK_STATESAVE_PROTOALL = 0x000FFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_PROTOALL = 0x000FFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_PROTOTYPE);
/** /**
Behavior Behavior
*/ */
@ -566,7 +534,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_BEHAVIORONLY = 0x01FFFFF0, CK_STATESAVE_BEHAVIORONLY = 0x01FFFFF0,
CK_STATESAVE_BEHAVIORALL = 0x01FFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_BEHAVIORALL = 0x01FFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_BEHAVIOR);
/** /**
SCENE CKSaveOjectSave will save all relevant data and does not take flags into account SCENE CKSaveOjectSave will save all relevant data and does not take flags into account
*/ */
@ -589,7 +556,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SCENERESERVED14 = 0x08000000, /**< Reserved for future use */ CK_STATESAVE_SCENERESERVED14 = 0x08000000, /**< Reserved for future use */
CK_STATESAVE_SCENEALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_SCENEALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SCENE);
/** /**
ParameterIn ParameterIn
*/ */
@ -606,7 +572,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_PARAMETERIN_DISABLED = 0x00002000, /**< The parameter was disabled */ CK_STATESAVE_PARAMETERIN_DISABLED = 0x00002000, /**< The parameter was disabled */
CK_STATESAVE_PARAMETERIN_ALL = 0x0000FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_PARAMETERIN_ALL = 0x0000FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_PARAMETERIN);
/** /**
ParameterLocal et ParameterOut ParameterLocal et ParameterOut
*/ */
@ -619,7 +584,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_PARAMETEROUT_ISSETTING = 0x00000400, /**< Reserved for future use */ CK_STATESAVE_PARAMETEROUT_ISSETTING = 0x00000400, /**< Reserved for future use */
CK_STATESAVE_PARAMETEROUT_ALL = 0x0000FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_PARAMETEROUT_ALL = 0x0000FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_PARAMETEROUT);
/** /**
Parameter Operation Parameter Operation
*/ */
@ -633,7 +597,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_OPERATIONNEWDATA = 0x00000400, CK_STATESAVE_OPERATIONNEWDATA = 0x00000400,
CK_STATESAVE_OPERATIONALL = 0x000007FF, /**< Save All datas for sub-classes */ CK_STATESAVE_OPERATIONALL = 0x000007FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_OPERATION);
/** /**
Synchro Object CKSaveOjectSave will save all relevant data and does not take flags into account Synchro Object CKSaveOjectSave will save all relevant data and does not take flags into account
*/ */
@ -645,7 +608,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SYNCHRORESERVED3 = 0x00000200, /**< Reserved for future use */ CK_STATESAVE_SYNCHRORESERVED3 = 0x00000200, /**< Reserved for future use */
CK_STATESAVE_SYNCHRONALL = 0x000003FF, /**< Save All datas for sub-classes */ CK_STATESAVE_SYNCHRONALL = 0x000003FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SYNCHRO);
/** /**
Grid Grid
*/ */
@ -659,7 +621,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_GRIDONLY = 0x0FC00000, /**< */ CK_STATESAVE_GRIDONLY = 0x0FC00000, /**< */
CK_STATESAVE_GRIDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_GRIDALL = 0x0FFFFFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_GRID);
/** /**
Layer (For Grids) Layer (For Grids)
*/ */
@ -673,7 +634,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_LAYERONLY = 0x000003F0, /**< */ CK_STATESAVE_LAYERONLY = 0x000003F0, /**< */
CK_STATESAVE_LAYERALL = 0x000003FF, /**< Save All datas for sub-classes */ CK_STATESAVE_LAYERALL = 0x000003FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_LAYER);
/** /**
DataArray CKSaveOjectSave will save all relevant data and does not take flags into account DataArray CKSaveOjectSave will save all relevant data and does not take flags into account
*/ */
@ -683,7 +643,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_DATAARRAYMEMBERS = 0x00004000, /**< Save members */ CK_STATESAVE_DATAARRAYMEMBERS = 0x00004000, /**< Save members */
CK_STATESAVE_DATAARRAYALL = 0x0000FFFF, /**< Save All datas for sub-classes */ CK_STATESAVE_DATAARRAYALL = 0x0000FFFF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_DATAARRAY);
/** /**
SceneObjectDesc SceneObjectDesc
*/ */
@ -694,6 +653,6 @@ namespace LibCmo::CK2 {
CK_STATESAVE_SCENEOBJECTRES3 = 0x00000080, /**< Reserved for future use */ CK_STATESAVE_SCENEOBJECTRES3 = 0x00000080, /**< Reserved for future use */
CK_STATESAVE_SCENEOBJECTDESCALL = 0x000000FF, /**< Save All datas for sub-classes */ CK_STATESAVE_SCENEOBJECTDESCALL = 0x000000FF, /**< Save All datas for sub-classes */
}; };
LIBCMO_BITFLAG_OPERATORS(CK_STATESAVEFLAGS_SCENEOBJECTDESC);
} }

View File

@ -1,244 +0,0 @@
#pragma once
#include "CKDefines.hpp"
#include "CKEnums.hpp"
namespace LibCmo::CK2::CKObjectImplements {
class CKObject {
public:
CK_ID m_ID;
std::string m_Name;
CK_OBJECT_FLAGS m_ObjectFlags;
CKMinContext* m_Context;
CKObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKObject(const CKObject&) = delete;
CKObject& operator=(const CKObject&) = delete;
virtual ~CKObject();
CK_ID GetID(void) { return this->m_ID; }
CKSTRING GetName(void) { return (this->m_Name.empty() ? nullptr : this->m_Name.c_str()); }
void SetName(CKSTRING u8_name) { this->m_Name = (u8_name == nullptr ? "" : u8_name); }
CK_OBJECT_FLAGS GetObjectFlags(void) { return this->m_ObjectFlags; }
void SetObjectFlags(CK_OBJECT_FLAGS flags) { this->m_ObjectFlags = flags; }
virtual CK_CLASSID GetClassID(void) { return CK_CLASSID::CKCID_OBJECT; }
virtual bool Load(CKStateChunk* chunk, const CKFileDocument* doc);
virtual CKStateChunk* Save(const CKFileDocument* doc);
};
class CKSceneObject : public CKObject {
public:
CKSceneObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKSceneObject(const CKSceneObject&) = delete;
CKSceneObject& operator=(const CKSceneObject&) = delete;
virtual ~CKSceneObject();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_SCENEOBJECT; }
protected:
XBitArray m_Scenes;
};
class CKBeObject : public CKSceneObject {
public:
CKBeObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKBeObject(const CKBeObject&) = delete;
CKBeObject& operator=(const CKBeObject&) = delete;
virtual ~CKBeObject();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEOBJECT; }
protected:
};
#pragma region Map Related
class CKGroup : public CKBeObject {
public:
CKGroup(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKGroup(const CKGroup&) = delete;
CKGroup& operator=(const CKGroup&) = delete;
virtual ~CKGroup();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_GROUP; }
protected:
};
class CKMesh : public CKBeObject {
public:
CKMesh(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKMesh(const CKMesh&) = delete;
CKMesh& operator=(const CKMesh&) = delete;
virtual ~CKMesh();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MESH; }
protected:
};
class CKTexture : public CKBeObject {
public:
CKTexture(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKTexture(const CKTexture&) = delete;
CKTexture& operator=(const CKTexture&) = delete;
virtual ~CKTexture();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_TEXTURE; }
protected:
};
class CKMaterial : public CKBeObject {
public:
CKMaterial(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKMaterial(const CKMaterial&) = delete;
CKMaterial& operator=(const CKMaterial&) = delete;
virtual ~CKMaterial();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MATERIAL; }
protected:
};
class CKRenderObject : public CKBeObject {
public:
CKRenderObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKRenderObject(const CKRenderObject&) = delete;
CKRenderObject& operator=(const CKRenderObject&) = delete;
~CKRenderObject();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_RENDEROBJECT; }
protected:
};
class CK3dEntity : public CKRenderObject {
public:
CK3dEntity(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CK3dEntity(const CK3dEntity&) = delete;
CK3dEntity& operator=(const CK3dEntity&) = delete;
virtual ~CK3dEntity();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DENTITY; }
protected:
};
class CK3dObject :public CK3dEntity {
public:
CK3dObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CK3dObject(const CK3dObject&) = delete;
CK3dObject& operator=(const CK3dObject&) = delete;
~CK3dObject();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DOBJECT; }
protected:
};
#pragma endregion
#pragma region Behavior Related
class CKParameterIn :public CKObject {
public:
CKParameterIn(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKParameterIn(const CKParameterIn&) = delete;
CKParameterIn& operator=(const CKParameterIn&) = delete;
~CKParameterIn();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETERIN; }
protected:
};
class CKParameter :public CKObject {
public:
CKParameter(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKParameter(const CKParameter&) = delete;
CKParameter& operator=(const CKParameter&) = delete;
~CKParameter();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETER; }
protected:
};
class CKParameterOut :public CKParameter {
public:
CKParameterOut(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKParameterOut(const CKParameterOut&) = delete;
CKParameterOut& operator=(const CKParameterOut&) = delete;
~CKParameterOut();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETEROUT; }
protected:
};
class CKParameterLocal :public CKParameter {
public:
CKParameterLocal(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKParameterLocal(const CKParameterLocal&) = delete;
CKParameterLocal& operator=(const CKParameterLocal&) = delete;
~CKParameterLocal();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETERLOCAL; }
protected:
};
class CKParameterOperation :public CKObject {
public:
CKParameterOperation(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKParameterOperation(const CKParameterOperation&) = delete;
CKParameterOperation& operator=(const CKParameterOperation&) = delete;
~CKParameterOperation();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETEROPERATION; }
protected:
};
class CKBehaviorLink :public CKObject {
public:
CKBehaviorLink(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKBehaviorLink(const CKBehaviorLink&) = delete;
CKBehaviorLink& operator=(const CKBehaviorLink&) = delete;
~CKBehaviorLink();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIORLINK; }
protected:
};
class CKBehaviorIO :public CKObject {
public:
CKBehaviorIO(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKBehaviorIO(const CKBehaviorIO&) = delete;
CKBehaviorIO& operator=(const CKBehaviorIO&) = delete;
~CKBehaviorIO();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIORIO; }
protected:
};
class CKBehavior :public CKSceneObject {
public:
CKBehavior(CKMinContext* ctx, CK_ID ckid, CKSTRING name);
CKBehavior(const CKBehavior&) = delete;
CKBehavior& operator=(const CKBehavior&) = delete;
~CKBehavior();
virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIOR; }
protected:
};
#pragma endregion
}

View File

@ -1,138 +1,123 @@
#include "../CKObjects.hpp" #include "CKObject.hpp"
#include "../CKStateChunk.hpp" #include "../CKStateChunk.hpp"
#include "../CKIdentifiers.hpp"
#include "../VTUtils.hpp"
namespace LibCmo::CK2::CKObjectImplements { namespace LibCmo::CK2 {
CKObject::CKObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name) :
m_ID(ckid), m_Context(ctx), void CKObject::PreSave(CKFile* file, CKDWORD flags) {}
m_Name(name == nullptr ? "" : name),
m_ObjectFlags(CK_OBJECT_FLAGS::CK_PARAMETERIN_DISABLED) { CKStateChunk* CKObject::Save(CKFile* file, CKDWORD flags) {
; return nullptr;
} }
CKObject::~CKObject() { bool CKObject::Load(CKStateChunk* chunk, CKFile* file) {
if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIDDEN)) {
} EnumsHelper::Rm(this->m_ObjectFlags,
EnumsHelper::Merge({ CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE }));
bool CKObject::Load(CKStateChunk* chunk, const CKFileDocument* doc) {
if (chunk->SeekIdentifier(Identifiers::CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIDDEN)) {
EnumsHelper::FlagEnumRm(this->m_ObjectFlags,
{ CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE,
CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE }
);
} else { } else {
if (chunk->SeekIdentifier(Identifiers::CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIERAHIDDEN)) { if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIERAHIDDEN)) {
// != 0 // != 0
EnumsHelper::FlagEnumRm(this->m_ObjectFlags, EnumsHelper::Rm(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
{ CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE, } EnumsHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
);
EnumsHelper::FlagEnumAdd(this->m_ObjectFlags,
{ CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE, }
);
} else { } else {
// == 0 // == 0
EnumsHelper::FlagEnumAdd(this->m_ObjectFlags, EnumsHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
{ CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE, } EnumsHelper::Rm(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
);
EnumsHelper::FlagEnumRm(this->m_ObjectFlags,
{ CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE, }
);
} }
} }
return true; return true;
} }
CKStateChunk* CKObject::Save(const CKFileDocument* doc) {
return nullptr;
}
CKSceneObject::CKSceneObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { void CKObject::PostLoad() {}
}
CKSceneObject::~CKSceneObject() {
}
CKBeObject::CKBeObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKSceneObject(ctx, ckid, name) {
}
CKBeObject::~CKBeObject() {
}
CKGroup::CKGroup(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
}
CKGroup::~CKGroup() {
}
CKMesh::CKMesh(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
}
CKMesh::~CKMesh() {
}
CKTexture::CKTexture(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
}
CKTexture::~CKTexture() {
}
CKMaterial::CKMaterial(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
}
CKMaterial::~CKMaterial() {
}
CKRenderObject::CKRenderObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
}
CKRenderObject::~CKRenderObject() {
}
CK3dEntity::CK3dEntity(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKRenderObject(ctx, ckid, name) {
}
CK3dEntity::~CK3dEntity() {
}
CK3dObject::CK3dObject(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CK3dEntity(ctx, ckid, name) {
}
CK3dObject::~CK3dObject() {
}
CKParameterIn::CKParameterIn(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { //CKSceneObject::CKSceneObject(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
} //}
CKParameterIn::~CKParameterIn() { //CKSceneObject::~CKSceneObject() {
} //}
CKParameter::CKParameter(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { //CKBeObject::CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKSceneObject(ctx, ckid, name) {
} //}
CKParameter::~CKParameter() { //CKBeObject::~CKBeObject() {
} //}
CKParameterOut::CKParameterOut(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKParameter(ctx, ckid, name) { //CKGroup::CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
} //}
CKParameterOut::~CKParameterOut() { //CKGroup::~CKGroup() {
} //}
CKParameterLocal::CKParameterLocal(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKParameter(ctx, ckid, name) { //CKMesh::CKMesh(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
} //}
CKParameterLocal::~CKParameterLocal() { //CKMesh::~CKMesh() {
} //}
CKParameterOperation::CKParameterOperation(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { //CKTexture::CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
} //}
CKParameterOperation::~CKParameterOperation() { //CKTexture::~CKTexture() {
} //}
CKBehaviorLink::CKBehaviorLink(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { //CKMaterial::CKMaterial(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
} //}
CKBehaviorLink::~CKBehaviorLink() { //CKMaterial::~CKMaterial() {
} //}
CKBehaviorIO::CKBehaviorIO(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) { //CKRenderObject::CKRenderObject(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKBeObject(ctx, ckid, name) {
} //}
CKBehaviorIO::~CKBehaviorIO() { //CKRenderObject::~CKRenderObject() {
} //}
CKBehavior::CKBehavior(CKMinContext* ctx, CK_ID ckid, CKSTRING name) : CKSceneObject(ctx, ckid, name) { //CK3dEntity::CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKRenderObject(ctx, ckid, name) {
} //}
CKBehavior::~CKBehavior() { //CK3dEntity::~CK3dEntity() {
} //}
//CK3dObject::CK3dObject(CKContext* ctx, CK_ID ckid, CKSTRING name) : CK3dEntity(ctx, ckid, name) {
//}
//CK3dObject::~CK3dObject() {
//}
//CKParameterIn::CKParameterIn(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
//}
//CKParameterIn::~CKParameterIn() {
//}
//CKParameter::CKParameter(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
//}
//CKParameter::~CKParameter() {
//}
//CKParameterOut::CKParameterOut(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKParameter(ctx, ckid, name) {
//}
//CKParameterOut::~CKParameterOut() {
//}
//CKParameterLocal::CKParameterLocal(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKParameter(ctx, ckid, name) {
//}
//CKParameterLocal::~CKParameterLocal() {
//}
//CKParameterOperation::CKParameterOperation(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
//}
//CKParameterOperation::~CKParameterOperation() {
//}
//CKBehaviorLink::CKBehaviorLink(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
//}
//CKBehaviorLink::~CKBehaviorLink() {
//}
//CKBehaviorIO::CKBehaviorIO(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKObject(ctx, ckid, name) {
//}
//CKBehaviorIO::~CKBehaviorIO() {
//}
//CKBehavior::CKBehavior(CKContext* ctx, CK_ID ckid, CKSTRING name) : CKSceneObject(ctx, ckid, name) {
//}
//CKBehavior::~CKBehavior() {
//}
} }

View File

@ -0,0 +1,275 @@
#pragma once
#include "../../VTUtils.hpp"
#include "../CKContext.hpp"
namespace LibCmo::CK2 {
class CKObject {
public:
CKObject(CKContext* ctx, CK_ID ckid, CKSTRING name) :
m_ID(ckid),
m_HasName(name != nullptr ? CKTRUE : CKFALSE), m_Name(name != nullptr ? name : ""),
m_Context(ctx),
m_ObjectFlags(CK_OBJECT_FLAGS::CK_PARAMETERIN_DISABLED)
{}
virtual ~CKObject() {}
LIBCMO_DISABLE_COPY_MOVE(CKObject);
CK_ID GetID(void) {
return m_ID;
}
CKSTRING GetName(void) {
if (m_HasName) return m_Name.c_str();
else return nullptr;
}
void SetName(CKSTRING u8_name) {
if (u8_name == nullptr) {
m_HasName = false;
m_Name.clear();
} else {
m_HasName = true;
m_Name = u8_name;
}
}
CK_OBJECT_FLAGS GetObjectFlags(void) {
return m_ObjectFlags;
}
void SetObjectFlags(CK_OBJECT_FLAGS flags) {
m_ObjectFlags = flags;
}
CKContext* GetCKContext() {
return m_Context;
}
virtual CK_CLASSID GetClassID(void) {
return CK_CLASSID::CKCID_OBJECT;
}
virtual void PreSave(CKFile* file, CKDWORD flags);
virtual CKStateChunk* Save(CKFile* file, CKDWORD flags);
virtual bool Load(CKStateChunk* chunk, CKFile* file);
virtual void PostLoad();
private:
CK_ID m_ID;
CKBOOL m_HasName;
std::string m_Name;
CK_OBJECT_FLAGS m_ObjectFlags;
CKContext* m_Context;
};
//class CKSceneObject : public CKObject {
//public:
// CKSceneObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKSceneObject(const CKSceneObject&) = delete;
// CKSceneObject& operator=(const CKSceneObject&) = delete;
// virtual ~CKSceneObject();
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_SCENEOBJECT; }
//protected:
// XBitArray m_Scenes;
//};
//class CKBeObject : public CKSceneObject {
//public:
// CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKBeObject(const CKBeObject&) = delete;
// CKBeObject& operator=(const CKBeObject&) = delete;
// virtual ~CKBeObject();
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEOBJECT; }
//protected:
//};
//
//#pragma region Map Related
//
// class CKGroup : public CKBeObject {
// public:
// CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKGroup(const CKGroup&) = delete;
// CKGroup& operator=(const CKGroup&) = delete;
// virtual ~CKGroup();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_GROUP; }
// protected:
//
// };
//
// class CKMesh : public CKBeObject {
// public:
// CKMesh(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKMesh(const CKMesh&) = delete;
// CKMesh& operator=(const CKMesh&) = delete;
// virtual ~CKMesh();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MESH; }
// protected:
//
// };
//
// class CKTexture : public CKBeObject {
// public:
// CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKTexture(const CKTexture&) = delete;
// CKTexture& operator=(const CKTexture&) = delete;
// virtual ~CKTexture();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_TEXTURE; }
// protected:
//
// };
//
// class CKMaterial : public CKBeObject {
// public:
// CKMaterial(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKMaterial(const CKMaterial&) = delete;
// CKMaterial& operator=(const CKMaterial&) = delete;
// virtual ~CKMaterial();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MATERIAL; }
// protected:
//
// };
//
// class CKRenderObject : public CKBeObject {
// public:
// CKRenderObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKRenderObject(const CKRenderObject&) = delete;
// CKRenderObject& operator=(const CKRenderObject&) = delete;
// ~CKRenderObject();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_RENDEROBJECT; }
// protected:
//
// };
//
// class CK3dEntity : public CKRenderObject {
// public:
// CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CK3dEntity(const CK3dEntity&) = delete;
// CK3dEntity& operator=(const CK3dEntity&) = delete;
// virtual ~CK3dEntity();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DENTITY; }
// protected:
//
// };
//
// class CK3dObject :public CK3dEntity {
// public:
// CK3dObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CK3dObject(const CK3dObject&) = delete;
// CK3dObject& operator=(const CK3dObject&) = delete;
// ~CK3dObject();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DOBJECT; }
// protected:
//
// };
//
//#pragma endregion
//
//#pragma region Behavior Related
//
// class CKParameterIn :public CKObject {
// public:
// CKParameterIn(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKParameterIn(const CKParameterIn&) = delete;
// CKParameterIn& operator=(const CKParameterIn&) = delete;
// ~CKParameterIn();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETERIN; }
// protected:
//
// };
//
// class CKParameter :public CKObject {
// public:
// CKParameter(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKParameter(const CKParameter&) = delete;
// CKParameter& operator=(const CKParameter&) = delete;
// ~CKParameter();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETER; }
// protected:
//
// };
//
// class CKParameterOut :public CKParameter {
// public:
// CKParameterOut(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKParameterOut(const CKParameterOut&) = delete;
// CKParameterOut& operator=(const CKParameterOut&) = delete;
// ~CKParameterOut();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETEROUT; }
// protected:
//
// };
//
// class CKParameterLocal :public CKParameter {
// public:
// CKParameterLocal(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKParameterLocal(const CKParameterLocal&) = delete;
// CKParameterLocal& operator=(const CKParameterLocal&) = delete;
// ~CKParameterLocal();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETERLOCAL; }
// protected:
//
// };
//
// class CKParameterOperation :public CKObject {
// public:
// CKParameterOperation(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKParameterOperation(const CKParameterOperation&) = delete;
// CKParameterOperation& operator=(const CKParameterOperation&) = delete;
// ~CKParameterOperation();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_PARAMETEROPERATION; }
// protected:
//
// };
//
// class CKBehaviorLink :public CKObject {
// public:
// CKBehaviorLink(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKBehaviorLink(const CKBehaviorLink&) = delete;
// CKBehaviorLink& operator=(const CKBehaviorLink&) = delete;
// ~CKBehaviorLink();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIORLINK; }
// protected:
//
// };
//
// class CKBehaviorIO :public CKObject {
// public:
// CKBehaviorIO(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKBehaviorIO(const CKBehaviorIO&) = delete;
// CKBehaviorIO& operator=(const CKBehaviorIO&) = delete;
// ~CKBehaviorIO();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIORIO; }
// protected:
//
// };
//
// class CKBehavior :public CKSceneObject {
// public:
// CKBehavior(CKContext* ctx, CK_ID ckid, CKSTRING name);
// CKBehavior(const CKBehavior&) = delete;
// CKBehavior& operator=(const CKBehavior&) = delete;
// ~CKBehavior();
//
// virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEHAVIOR; }
// protected:
//
// };
//
//#pragma endregion
}

View File

@ -166,12 +166,14 @@ namespace LibCmo::CK2 {
using CKSTRING = const char*; using CKSTRING = const char*;
using CKCHAR = char; using CKCHAR = char;
using CKBOOL = int32_t; using CKBOOL = bool;
using CKBYTE = uint8_t; using CKBYTE = uint8_t;
using CKDWORD = uint32_t; using CKDWORD = uint32_t;
using CKWORD = uint16_t; using CKWORD = uint16_t;
using CKINT = int32_t; using CKINT = int32_t;
constexpr CKBOOL CKFALSE = false;
constexpr CKBOOL CKTRUE = true;
using CKParameterType = int32_t; using CKParameterType = int32_t;
using CKOperationType = int32_t; using CKOperationType = int32_t;

View File

@ -104,8 +104,6 @@
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>VTAll.hpp</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -125,8 +123,6 @@
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>VTAll.hpp</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -146,8 +142,6 @@
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>VTAll.hpp</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -169,8 +163,6 @@
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>VTAll.hpp</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -201,13 +193,13 @@
<ClInclude Include="CK2\CKFile.hpp" /> <ClInclude Include="CK2\CKFile.hpp" />
<ClInclude Include="CK2\CKGlobals.hpp" /> <ClInclude Include="CK2\CKGlobals.hpp" />
<ClInclude Include="CK2\CKIdentifiers.hpp" /> <ClInclude Include="CK2\CKIdentifiers.hpp" />
<ClInclude Include="CK2\CKBaseManager.hpp" /> <ClInclude Include="CK2\CKManagerImplements\CKBaseManager.hpp" />
<ClInclude Include="CK2\CKContext.hpp" /> <ClInclude Include="CK2\CKContext.hpp" />
<ClInclude Include="CK2\CKStateChunk.hpp" /> <ClInclude Include="CK2\CKStateChunk.hpp" />
<ClInclude Include="CK2\CKTypes.hpp" /> <ClInclude Include="CK2\CKTypes.hpp" />
<ClInclude Include="VTAll.hpp" /> <ClInclude Include="VTAll.hpp" />
<ClInclude Include="VTEncoding.hpp" /> <ClInclude Include="VTEncoding.hpp" />
<ClInclude Include="CK2\CKObject.hpp" /> <ClInclude Include="CK2\CKObjectImplements\CKObject.hpp" />
<ClInclude Include="VTUtils.hpp" /> <ClInclude Include="VTUtils.hpp" />
<ClInclude Include="VxMath\VxMemoryMappedFile.hpp" /> <ClInclude Include="VxMath\VxMemoryMappedFile.hpp" />
<ClInclude Include="VxMath\VxTypes.hpp" /> <ClInclude Include="VxMath\VxTypes.hpp" />

View File

@ -122,10 +122,10 @@
<ClInclude Include="VTAll.hpp"> <ClInclude Include="VTAll.hpp">
<Filter>Headers</Filter> <Filter>Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CK2\CKBaseManager.hpp"> <ClInclude Include="CK2\CKManagerImplements\CKBaseManager.hpp">
<Filter>Headers\CK2\CKObjectImplements</Filter> <Filter>Headers\CK2\CKObjectImplements</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CK2\CKObject.hpp"> <ClInclude Include="CK2\CKObjectImplements\CKObject.hpp">
<Filter>Headers\CK2\CKManagerImplements</Filter> <Filter>Headers\CK2\CKManagerImplements</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

View File

@ -1,6 +1,10 @@
#include "VTUtils.hpp" #include "VTUtils.hpp"
namespace LibCmo { namespace LibCmo {
void SystemPanic(const char* reason) {
}
namespace StreamHelper { namespace StreamHelper {
static constexpr const size_t CHUNK_SIZE = 10240; static constexpr const size_t CHUNK_SIZE = 10240;

View File

@ -39,6 +39,8 @@
#if defined(_WIN32) #if defined(_WIN32)
#define LIBCMO_OS_WIN32 #define LIBCMO_OS_WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#endif #endif
#include <cstdio> #include <cstdio>
@ -47,46 +49,49 @@
#include <cstdint> #include <cstdint>
#include <initializer_list> #include <initializer_list>
#pragma region Enum Helper #pragma region Batch Ctor operator= Operations
#define LIBCMO_BITFLAG_OPERATORS_BITWISE(OP, ENUM_TYPE) \ #define LIBCMO_DISABLE_COPY_MOVE(CLSNAME) \
constexpr ENUM_TYPE operator OP(ENUM_TYPE lhs, ENUM_TYPE rhs) noexcept { \ CLSNAME(const CLSNAME&) = delete; \
typedef std::underlying_type_t<ENUM_TYPE> underlying; \ CLSNAME(CLSNAME&&) = delete; \
return static_cast<ENUM_TYPE>(static_cast<underlying>(lhs) OP static_cast<underlying>(rhs)); \ CLSNAME& operator=(const CLSNAME&) = delete; \
} \ CLSNAME& operator=(CLSNAME&&) = delete;
constexpr ENUM_TYPE& operator OP ## = (ENUM_TYPE& lhs, ENUM_TYPE rhs) noexcept { \
return (lhs = lhs OP rhs); \
}
#define LIBCMO_BITFLAG_OPERATORS_BOOLEAN(OP, ENUM_TYPE) \
constexpr bool operator OP(ENUM_TYPE lhs, std::underlying_type_t<ENUM_TYPE> rhs) noexcept { \
return static_cast<std::underlying_type_t<ENUM_TYPE>>(lhs) OP rhs; \
} \
constexpr bool operator OP(std::underlying_type_t<ENUM_TYPE> lhs, ENUM_TYPE rhs) noexcept { \
return lhs OP static_cast<std::underlying_type_t<ENUM_TYPE>>(rhs); \
}
#define LIBCMO_BITFLAG_OPERATORS(ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BITWISE(|, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BITWISE(&, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BITWISE(^, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(==, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(!=, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(<, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(>, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(>=, ENUM_TYPE) \
LIBCMO_BITFLAG_OPERATORS_BOOLEAN(<=, ENUM_TYPE) \
constexpr ENUM_TYPE operator~(ENUM_TYPE e) noexcept { \
return static_cast<ENUM_TYPE>(~static_cast<std::underlying_type_t<ENUM_TYPE>>(e)); \
} \
constexpr bool operator!(ENUM_TYPE e) noexcept { \
return static_cast<bool>(static_cast<std::underlying_type_t<ENUM_TYPE>>(e)); \
}
#pragma endregion #pragma endregion
namespace LibCmo { namespace LibCmo {
namespace EnumsHelper {
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Merge(std::initializer_list<TEnum> il) {
std::underlying_type_t<TEnum> result = 0;
for (auto it = il.begin(); it != il.end(); ++it) {
result |= static_cast<std::underlying_type_t<TEnum>>(*it);
}
return static_cast<TEnum>(result);
}
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Inv(TEnum e) {
return static_cast<TEnum>(~(static_cast<std::underlying_type_t<TEnum>>(e)));
}
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Rm(TEnum& e1, TEnum e2) {
e1 = static_cast<TEnum>(static_cast<std::underlying_type_t<TEnum>>(e1) & static_cast<std::underlying_type_t<TEnum>>(Inv(e2)));
}
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Add(TEnum& e1, TEnum e2) {
e1 = static_cast<TEnum>(static_cast<std::underlying_type_t<TEnum>>(e1) | static_cast<std::underlying_type_t<TEnum>>(e2));
}
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline bool Has(TEnum e, TEnum probe) {
return static_cast<bool>(static_cast<std::underlying_type_t<TEnum>>(e) & static_cast<std::underlying_type_t<TEnum>>(probe));
}
}
namespace StreamHelper { namespace StreamHelper {
void CopyStream(const void* src, FILE* dest, size_t len); void CopyStream(const void* src, FILE* dest, size_t len);