refactor: refactor project

- rename LIBCMO_DISABLE_COPY_MOVE -> YYCC_DEL_CLS_COPY_MOVE and LIBCMO_DEFAULT_COPY_MOVE -> YYCC_DEF_CLS_COPY_MOVE.
- fix Vector declaration generator. throw exception when operator[] face invalid index, instead of do fallback.
- rename VTAll.hpp -> VTInternal.hpp and VYUserAll -> VTAll.hpp for easy to understand.
- fix project name error in Doxygen template.
- replace all LIBCMO_OS_WIN32 to YYCC_OS == YYCC_OS_WINDOWS.
- fix some compile error (involving utf8 encoding) but not the final result.
- use correct way to include std-image library (use <> instead of "")
- finish documentation for VTUtils.hpp and VTEncoding.hpp.
This commit is contained in:
yyc12345 2024-08-17 20:43:27 +08:00
parent f870d4dde3
commit e682a87d25
43 changed files with 491 additions and 337 deletions

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <VTUserAll.hpp> #include <VTAll.hpp>
#include <vector> #include <vector>
#include <cstdint> #include <cstdint>
#include <cinttypes> #include <cinttypes>
@ -14,7 +14,7 @@ namespace BMap {
public: public:
BMFile(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, NakedOutputCallback raw_callback, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING* encodings, bool is_reader); BMFile(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, NakedOutputCallback raw_callback, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING* encodings, bool is_reader);
~BMFile(); ~BMFile();
LIBCMO_DISABLE_COPY_MOVE(BMFile); YYCC_DEL_CLS_COPY_MOVE(BMFile);
// ===== safe visit functions ===== // ===== safe visit functions =====
@ -154,7 +154,7 @@ namespace BMap {
public: public:
BMMeshTransition(); BMMeshTransition();
~BMMeshTransition(); ~BMMeshTransition();
LIBCMO_DISABLE_COPY_MOVE(BMMeshTransition); YYCC_DEL_CLS_COPY_MOVE(BMMeshTransition);
bool PrepareVertexCount(LibCmo::CKDWORD count); bool PrepareVertexCount(LibCmo::CKDWORD count);
LibCmo::VxMath::VxVector3* PrepareVertex(); LibCmo::VxMath::VxVector3* PrepareVertex();

View File

@ -33,13 +33,13 @@ def GetTmplOperOffset(sname: str, svars: tuple[str]) -> str:
return f"""\tCKFLOAT& operator[](size_t i) {{ return f"""\tCKFLOAT& operator[](size_t i) {{
\t\tswitch (i) {{ \t\tswitch (i) {{
\t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))} \t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))}
\t\t\tdefault: return {svars[0]}; \t\t\tdefault: throw LogicException("Invalid index for {sname}::operator[].");
\t\t}} \t\t}}
\t}} \t}}
\tconst CKFLOAT& operator[](size_t i) const {{ \tconst CKFLOAT& operator[](size_t i) const {{
\t\tswitch (i) {{ \t\tswitch (i) {{
\t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))} \t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))}
\t\t\tdefault: return {svars[0]}; \t\t\tdefault: throw LogicException("Invalid index for {sname}::operator[].");
\t\t}} \t\t}}
\t}}""" \t}}"""
@ -120,7 +120,7 @@ struct {sname} {{
\t{GetTmplDecl(svars)} \t{GetTmplDecl(svars)}
\t{GetTmplCtor1(sname, svars)} \t{GetTmplCtor1(sname, svars)}
\t{GetTmplCtor2(sname, svars)} \t{GetTmplCtor2(sname, svars)}
\tLIBCMO_DEFAULT_COPY_MOVE({sname}); \tYYCC_DEF_CLS_COPY_MOVE({sname});
{GetTmplOperOffset(sname, svars)} {GetTmplOperOffset(sname, svars)}
{GetTmplOperAddMinus(sname, svars, '+')} {GetTmplOperAddMinus(sname, svars, '+')}
{GetTmplOperAddMinus(sname, svars, '-')} {GetTmplOperAddMinus(sname, svars, '-')}
@ -138,13 +138,13 @@ struct {sname} {{
\t{GetTmplDecl(svars)} \t{GetTmplDecl(svars)}
\t{GetTmplCtor1(sname, svars)} // set your custom init. \t{GetTmplCtor1(sname, svars)} // set your custom init.
\t{GetTmplCtor2(sname, svars)} \t{GetTmplCtor2(sname, svars)}
\tLIBCMO_DEFAULT_COPY_MOVE({sname}); \tYYCC_DEF_CLS_COPY_MOVE({sname});
{GetTmplOperOffset(sname, svars)} {GetTmplOperOffset(sname, svars)}
{GetTmplOperEqual(sname, svars)} {GetTmplOperEqual(sname, svars)}
}}; }};
""" """
# use LIBCMO_DEFAULT_COPY_MOVE instead of these outputs. # use YYCC_DEF_CLS_COPY_MOVE instead of these outputs.
#\t{GetTmplCopyCtor(sname, svars)} #\t{GetTmplCopyCtor(sname, svars)}
#\t{GetTmplMoveCtor(sname, svars)} #\t{GetTmplMoveCtor(sname, svars)}
#{GetTmplOperAssignCopy(sname, svars)} #{GetTmplOperAssignCopy(sname, svars)}

View File

@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places. # title of most generated pages and in a few other places.
# The default value is: My Project. # The default value is: My Project.
PROJECT_NAME = YYCCommonplace PROJECT_NAME = LibCmo
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This # The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../VTAll.hpp" #include "../VTInternal.hpp"
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
@ -26,7 +26,7 @@ namespace LibCmo::CK2 {
CKBitmapSlot() : CKBitmapSlot() :
m_ImageData(), m_FileName() {} m_ImageData(), m_FileName() {}
~CKBitmapSlot() {} ~CKBitmapSlot() {}
LIBCMO_DEFAULT_COPY_MOVE(CKBitmapSlot); YYCC_DEF_CLS_COPY_MOVE(CKBitmapSlot);
VxMath::VxImageDescEx m_ImageData; VxMath::VxImageDescEx m_ImageData;
XContainer::XString m_FileName; XContainer::XString m_FileName;
@ -36,7 +36,7 @@ namespace LibCmo::CK2 {
public: public:
CKBitmapData(CKContext* ctx); CKBitmapData(CKContext* ctx);
~CKBitmapData(); ~CKBitmapData();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapData); YYCC_DEL_CLS_COPY_MOVE(CKBitmapData);
#pragma region RW Funcs #pragma region RW Funcs

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../VTAll.hpp" #include "../VTInternal.hpp"
#include <map> #include <map>
#include <deque> #include <deque>
#include <functional> #include <functional>
@ -21,7 +21,7 @@ namespace LibCmo::CK2 {
public: public:
CKContext(); CKContext();
~CKContext(); ~CKContext();
LIBCMO_DISABLE_COPY_MOVE(CKContext); YYCC_DEL_CLS_COPY_MOVE(CKContext);
// ========== Engine runtime ========== // ========== Engine runtime ==========
public: public:

View File

@ -136,7 +136,7 @@ namespace LibCmo::CK2 {
m_ReaderGuid(), m_Ext() {} m_ReaderGuid(), m_Ext() {}
CKBitmapProperties(const CKGUID& guid, CKSTRING ext) : CKBitmapProperties(const CKGUID& guid, CKSTRING ext) :
m_ReaderGuid(guid), m_Ext(ext) {} m_ReaderGuid(guid), m_Ext(ext) {}
LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties); YYCC_DEF_CLS_COPY_MOVE(CKBitmapProperties);
CKGUID m_ReaderGuid; /**< CKGUID that uniquely identifies the reader that created this properties structure */ CKGUID m_ReaderGuid; /**< CKGUID that uniquely identifies the reader that created this properties structure */
CKFileExtension m_Ext; /**< File Extension of the image being described by this structure */ CKFileExtension m_Ext; /**< File Extension of the image being described by this structure */

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../VTAll.hpp" #include "../VTInternal.hpp"
namespace LibCmo::XContainer { namespace LibCmo::XContainer {
using XIntArray = XArray<CKINT>; using XIntArray = XArray<CKINT>;
@ -40,7 +40,7 @@ namespace LibCmo::CK2 {
~CKBufferParser() { ~CKBufferParser() {
if (this->m_NeedManualFree) delete[](this->m_MemBegin); if (this->m_NeedManualFree) delete[](this->m_MemBegin);
} }
LIBCMO_DISABLE_COPY_MOVE(CKBufferParser); YYCC_DEL_CLS_COPY_MOVE(CKBufferParser);
const void* GetPtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } const void* GetPtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); }
void* GetMutablePtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } void* GetMutablePtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); }
@ -97,7 +97,7 @@ namespace LibCmo::CK2 {
ObjectCount(0u), ManagerCount(0u), MaxIDSaved(0u), Crc(0u), ObjectCount(0u), ManagerCount(0u), MaxIDSaved(0u), Crc(0u),
Hdr1PackSize(0u), Hdr1UnPackSize(0u), DataPackSize(0u), DataUnPackSize(0u) {} Hdr1PackSize(0u), Hdr1UnPackSize(0u), DataPackSize(0u), DataUnPackSize(0u) {}
~CKFileInfo() {} ~CKFileInfo() {}
LIBCMO_DEFAULT_COPY_MOVE(CKFileInfo); YYCC_DEF_CLS_COPY_MOVE(CKFileInfo);
CKDWORD ProductVersion; /**< Virtools Version (Dev/Creation). (CK_VIRTOOLS_VERSION) */ CKDWORD ProductVersion; /**< Virtools Version (Dev/Creation). (CK_VIRTOOLS_VERSION) */
CKDWORD ProductBuild; /**< Virtools Build Number. */ CKDWORD ProductBuild; /**< Virtools Build Number. */
@ -156,7 +156,7 @@ namespace LibCmo::CK2 {
CKFilePluginDependencies() : CKFilePluginDependencies() :
m_PluginCategory(CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL), m_Guids() {} m_PluginCategory(CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL), m_Guids() {}
~CKFilePluginDependencies() {} ~CKFilePluginDependencies() {}
LIBCMO_DEFAULT_COPY_MOVE(CKFilePluginDependencies); YYCC_DEF_CLS_COPY_MOVE(CKFilePluginDependencies);
CK_PLUGIN_TYPE m_PluginCategory; CK_PLUGIN_TYPE m_PluginCategory;
XContainer::XArray<CKGUID> m_Guids; XContainer::XArray<CKGUID> m_Guids;
@ -188,7 +188,7 @@ namespace LibCmo::CK2 {
public: public:
CKFileReader(CKContext* ctx); CKFileReader(CKContext* ctx);
~CKFileReader(); ~CKFileReader();
LIBCMO_DISABLE_COPY_MOVE(CKFileReader); YYCC_DEL_CLS_COPY_MOVE(CKFileReader);
// ========== Loading ========== // ========== Loading ==========
CKERROR ShallowLoad(CKSTRING u8_filename); CKERROR ShallowLoad(CKSTRING u8_filename);
@ -229,7 +229,7 @@ namespace LibCmo::CK2 {
CKFileWriter(CKContext* ctx); CKFileWriter(CKContext* ctx);
CKFileWriter(CKContext* ctx, CKFileReader* reader, bool is_shallow); CKFileWriter(CKContext* ctx, CKFileReader* reader, bool is_shallow);
~CKFileWriter(); ~CKFileWriter();
LIBCMO_DISABLE_COPY_MOVE(CKFileWriter); YYCC_DEL_CLS_COPY_MOVE(CKFileWriter);
// ========== Saving Preparing ========== // ========== Saving Preparing ==========
bool AddSavedObject(ObjImpls::CKObject* obj, CKDWORD flags = CK_STATESAVE_ALL); bool AddSavedObject(ObjImpls::CKObject* obj, CKDWORD flags = CK_STATESAVE_ALL);

View File

@ -1,5 +1,5 @@
#include "../VTUtils.hpp" #include "../VTUtils.hpp"
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
#define ZLIB_WINAPI #define ZLIB_WINAPI
#endif #endif
#include <zconf.h> #include <zconf.h>
@ -76,7 +76,10 @@ namespace LibCmo::CK2 {
} else { } else {
if (str2 == nullptr) return false; if (str2 == nullptr) return false;
else { else {
return std::strcmp(str1, str2) == 0; return std::strcmp(
YYCC::EncodingHelper::ToOrdinary(str1),
YYCC::EncodingHelper::ToOrdinary(str2)
) == 0;
} }
} }
} }
@ -90,21 +93,21 @@ namespace LibCmo::CK2 {
else { else {
// do real cmp // do real cmp
size_t i = 0; size_t i = 0;
while (str1[i] != '\0' && str2[i] != '\0') { while (str1[i] != u8'\0' && str2[i] != u8'\0') {
if (std::tolower(str1[i]) != std::tolower(str2[i])) return false; if (std::tolower(str1[i]) != std::tolower(str2[i])) return false;
++str1; ++str1;
++str2; ++str2;
} }
// !XOR the result, if both of them is zero, return true(1) // !XOR the result, if both of them is zero, return true(1)
return !((str1[i] != '\0') ^ (str2[i] != '\0')); return !((str1[i] != u8'\0') ^ (str2[i] != u8'\0'));
} }
} }
} }
bool CKStrEmpty(CKSTRING strl) { bool CKStrEmpty(CKSTRING strl) {
if (strl == nullptr) return true; if (strl == nullptr) return true;
return strl[0] == '\0'; return strl[0] == u8'\0';
} }
#pragma endregion #pragma endregion
@ -173,7 +176,7 @@ namespace LibCmo::CK2 {
CKSTRING CKClassIDToString(CK_CLASSID cid) { CKSTRING CKClassIDToString(CK_CLASSID cid) {
const CKClassDesc* desc = CKGetClassDesc(cid); const CKClassDesc* desc = CKGetClassDesc(cid);
if (desc == nullptr) return "Undefined Type"; if (desc == nullptr) return u8"Undefined Type";
else return desc->NameFct(); else return desc->NameFct();
} }
@ -267,7 +270,7 @@ namespace LibCmo::CK2 {
// find direct parent // find direct parent
CKClassDesc& parent = g_CKClassInfo[static_cast<size_t>(desc.Parent)]; CKClassDesc& parent = g_CKClassInfo[static_cast<size_t>(desc.Parent)];
if (!parent.IsValid) LIBCMO_PANIC("No such CK_CLASSID."); if (!parent.IsValid) throw LogicException("No such CK_CLASSID.");
// if it is not self inheritance, call recursively // if it is not self inheritance, call recursively
if (desc.Self != desc.Parent) { if (desc.Self != desc.Parent) {
@ -291,7 +294,7 @@ namespace LibCmo::CK2 {
// find direct parent // find direct parent
CKClassDesc& parent = g_CKClassInfo[static_cast<size_t>(desc.Parent)]; CKClassDesc& parent = g_CKClassInfo[static_cast<size_t>(desc.Parent)];
if (!parent.IsValid) LIBCMO_PANIC("No such CK_CLASSID."); if (!parent.IsValid) throw LogicException("No such CK_CLASSID.");
// if it is not self inheritance, call recursively // if it is not self inheritance, call recursively
if (desc.Self != desc.Parent) { if (desc.Self != desc.Parent) {
@ -398,13 +401,13 @@ CKClassRegister(cid, parentCid, \
nullptr, \ nullptr, \
[](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \ [](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \
[](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \ [](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \
[]() -> CKSTRING { return strName; }); []() -> CKSTRING { return u8 ## strName; });
#define EasyClassRegWithNotify(clsname, cid, parentCid, strName, notifyCids) \ #define EasyClassRegWithNotify(clsname, cid, parentCid, strName, notifyCids) \
CKClassRegister(cid, parentCid, \ CKClassRegister(cid, parentCid, \
[]() -> void { NeedNotificationWrapper(cid, notifyCids); }, \ []() -> void { NeedNotificationWrapper(cid, notifyCids); }, \
[](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \ [](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \
[](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \ [](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \
[]() -> CKSTRING { return strName; }); []() -> CKSTRING { return u8 ## strName; });
EasyClassReg(ObjImpls::CKObject, CK_CLASSID::CKCID_OBJECT, CK_CLASSID::CKCID_OBJECT, "Basic Object"); EasyClassReg(ObjImpls::CKObject, CK_CLASSID::CKCID_OBJECT, CK_CLASSID::CKCID_OBJECT, "Basic Object");
EasyClassReg(ObjImpls::CKSceneObject, CK_CLASSID::CKCID_SCENEOBJECT, CK_CLASSID::CKCID_OBJECT, "Scene Object"); EasyClassReg(ObjImpls::CKSceneObject, CK_CLASSID::CKCID_SCENEOBJECT, CK_CLASSID::CKCID_OBJECT, "Scene Object");

View File

@ -118,7 +118,7 @@ namespace LibCmo::CK2 {
DerivationLevel(0), DerivationLevel(0),
Parents(), Children(), ToBeNotify(), CommonToBeNotify() Parents(), Children(), ToBeNotify(), CommonToBeNotify()
{} {}
LIBCMO_DEFAULT_COPY_MOVE(CKClassDesc); YYCC_DEF_CLS_COPY_MOVE(CKClassDesc);
}; };
// ========== CKClass Registration ========== // ========== CKClass Registration ==========

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../VTAll.hpp" #include "../VTInternal.hpp"
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <type_traits> #include <type_traits>
@ -54,7 +54,7 @@ namespace LibCmo::CK2 {
LockedReadBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {} LockedReadBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {}
LockedReadBufferDeleter(CKStateChunk* host, CKDWORD init_size) : LockedReadBufferDeleter(CKStateChunk* host, CKDWORD init_size) :
m_Host(host), m_ConsumedSize(init_size) {} m_Host(host), m_ConsumedSize(init_size) {}
LIBCMO_DEFAULT_COPY_MOVE(LockedReadBufferDeleter); YYCC_DEF_CLS_COPY_MOVE(LockedReadBufferDeleter);
void operator()(LIBCMO_UNUSED const void* buf); void operator()(LIBCMO_UNUSED const void* buf);
void SetConsumedSize(CKDWORD newsize); void SetConsumedSize(CKDWORD newsize);
@ -68,7 +68,7 @@ namespace LibCmo::CK2 {
LockedWriteBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {} LockedWriteBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {}
LockedWriteBufferDeleter(CKStateChunk* host, CKDWORD init_size) : LockedWriteBufferDeleter(CKStateChunk* host, CKDWORD init_size) :
m_Host(host), m_ConsumedSize(init_size) {} m_Host(host), m_ConsumedSize(init_size) {}
LIBCMO_DEFAULT_COPY_MOVE(LockedWriteBufferDeleter); YYCC_DEF_CLS_COPY_MOVE(LockedWriteBufferDeleter);
void operator()(LIBCMO_UNUSED const void* buf); void operator()(LIBCMO_UNUSED const void* buf);
void SetConsumedSize(CKDWORD newsize); void SetConsumedSize(CKDWORD newsize);
@ -82,7 +82,7 @@ namespace LibCmo::CK2 {
BufferDeleter() : m_Host(nullptr), m_BufSize(0) {} BufferDeleter() : m_Host(nullptr), m_BufSize(0) {}
BufferDeleter(CKStateChunk* host, CKDWORD bufsize) : BufferDeleter(CKStateChunk* host, CKDWORD bufsize) :
m_Host(host), m_BufSize(bufsize) {} m_Host(host), m_BufSize(bufsize) {}
LIBCMO_DEFAULT_COPY_MOVE(BufferDeleter); YYCC_DEF_CLS_COPY_MOVE(BufferDeleter);
void operator()(const void* buf); void operator()(const void* buf);
CKDWORD GetBufferSize() const; CKDWORD GetBufferSize() const;

View File

@ -16,22 +16,22 @@ namespace LibCmo {
// So we declare them in LibCmo, not LibCmo::CK2 to make sure every module can use it. // So we declare them in LibCmo, not LibCmo::CK2 to make sure every module can use it.
/** /**
* @brief General Const String Type. Encoding Unrelated. * @brief General constant UTF8 string type.
*/ */
using CKSTRING = const char*; using CKSTRING = const char8_t*;
/** /**
* @brief Changeble CKSTRING. * @brief Changeble CKSTRING.
* @see CKSTRING * @see CKSTRING
*/ */
using CKMUTSTRING = char*; using CKMUTSTRING = char8_t*;
/** /**
* @brief The Representation of Single Character (1 byte). Encoding Unrelated. * @brief The representation of single UTF8 code unit (1 byte).
* @remark * @remarks
* + Only used with string process. * \li Only used with string process.
* + For memory representation and moving, use CKBYTE instead. * \li For memory representation and moving, use CKBYTE instead.
* @see CKBYTE * @see CKBYTE
*/ */
using CKCHAR = char; using CKCHAR = char8_t;
/** /**
* @brief Always Represent a Byte (1 byte, unsigned). Platform Independent. * @brief Always Represent a Byte (1 byte, unsigned). Platform Independent.
@ -58,8 +58,8 @@ namespace LibCmo {
/** /**
* @brief The Int type used in LibCmo. * @brief The Int type used in LibCmo.
* @remark * @remark
* + All 'int' type in original Virtools SDK should be replaced with CKINT in this project if needed. * \i All \c int type in original Virtools SDK should be replaced with CKINT in this project if needed.
* + This type also can be seen as the equvalent of signed CKDWORD. * \li This type also can be seen as the equvalent of signed CKDWORD.
* @see CKDWORD * @see CKDWORD
*/ */
using CKINT = int32_t; using CKINT = int32_t;
@ -76,15 +76,15 @@ namespace LibCmo {
/** /**
* @brief Represent a x86 Platform Pointer. * @brief Represent a x86 Platform Pointer.
* @remark * @remark
* + This type only can be used when replacing pointer in old Virtools struct / class. * \li This type only can be used when replacing pointer in old Virtools struct / class.
* + Due to Virtools shitty design, in some cases we need read data with x86 memory layout from file. * \li Due to Virtools shitty design, in some cases we need read data with x86 memory layout from file.
* So we use this type to replace native pointer in struct existed in Virtools SDK to make sure this * So we use this type to replace native pointer in struct existed in Virtools SDK to make sure this
* program can run perfectly on x64 and more architectures. * program can run perfectly on x64 and more architectures.
* + A example can be found in CKTexture::Load(). * \li A example usage can be found in CK2::ObjImpls::CKTexture::Load().
*/ */
using CKPTR = uint32_t; using CKPTR = uint32_t;
// Format constants for the std::fprintf family of functions // Format macro for \c std::printf family of functions
#define PRI_CKSTRING "s" #define PRI_CKSTRING "s"
#define PRI_CKCHAR "c" #define PRI_CKCHAR "c"
@ -114,10 +114,11 @@ namespace LibCmo {
#define PRIxCKPTR PRIx32 #define PRIxCKPTR PRIx32
#define PRIXCKPTR PRIX32 #define PRIXCKPTR PRIX32
/* /**
The convenient sizeof which return CKDWORD, not size_t. * @brief The convenient sizeof macro which return \c CKDWORD instead of \c size_t.
* This is usually used in LibCmo because LibCmo use \c CKDWORD, not \c size_t everywhere.
*/ */
#define CKSizeof(_Ty) (static_cast<LibCmo::CKDWORD>(sizeof(_Ty))) #define CKSizeof(_Ty) (static_cast<::LibCmo::CKDWORD>(sizeof(_Ty)))
} }
@ -126,17 +127,17 @@ namespace LibCmo {
namespace LibCmo::CK2 { namespace LibCmo::CK2 {
/** /**
@brief Unique Identifier for all Objects instanciated in a given CKContext * @brief Unique Identifier for all Objects instanciated in a given CKContext
@remarks * @remarks
+ Each instance of CKObject and derived classes are automatically given a global unique * \li Each instance of CKObject and derived classes are automatically given a global unique
ID at creation time. This ID can be accessed through the CKObject::GetID method. * ID at creation time. This ID can be accessed through the CKObject::GetID method.
It is safer, though a bit slower, to reference object through their global ID than through * It is safer, though a bit slower, to reference object through their global ID than through
a direct pointer reference. In any case the referenced object may be deleted even though * a direct pointer reference. In any case the referenced object may be deleted even though
the client object has a ID for it. The client object should verify that the referenced object * the client object has a ID for it. The client object should verify that the referenced object
still exists when used with the CKGetObject function. * still exists when used with the CKGetObject function.
+ The global ID for an instance remains unique and unchanged through a application session, but there * \li The global ID for an instance remains unique and unchanged through a application session, but there
is no garanty that this ID will be the same when a level is saved and loaded back again. * is no garanty that this ID will be the same when a level is saved and loaded back again.
@see CKObject::GetID, CKContext::GetObject * @see CKObject::GetID, CKContext::GetObject
*/ */
using CK_ID = CKDWORD; using CK_ID = CKDWORD;
@ -195,14 +196,14 @@ namespace LibCmo::CK2 {
}; };
/** /**
@brief Per Class Unique Identifier. * @brief Per Class Unique Identifier.
@remark * @remark
+ Each class derived from the CKObject class has a unique class ID. * \li Each class derived from the CKObject class has a unique class ID.
+ This ID can be accessed through each instance of these classes, with the * \li This ID can be accessed through each instance of these classes, with the
CKObject::GetClassID method. * CKObject::GetClassID method.
+ This class ID is used internally for various matching operations, like matching behaviors on * \li This class ID is used internally for various matching operations, like matching behaviors on
objects, etc.. * objects, etc..
@see CKObject::GetClassID, CKIsChildClassOf, Class Identifiers * @see CKObject::GetClassID, CKIsChildClassOf, Class Identifiers
*/ */
enum class CK_CLASSID : CKINT { enum class CK_CLASSID : CKINT {
CKCID_OBJECT = 1, CKCID_OBJECT = 1,
@ -289,8 +290,10 @@ namespace LibCmo::CK2 {
#define PRIiCLASSID PRIiCKINT #define PRIiCLASSID PRIiCKINT
// ========== Class List ========== // ========== Class List ==========
// Objects and derivated classes // We declare these classes in there to make sure that
// following code can refer their pointer type safely.
// Objects and derivated classes
namespace ObjImpls { namespace ObjImpls {
class CKObject; class CKObject;
class CKInterfaceObjectManager; class CKInterfaceObjectManager;
@ -345,7 +348,7 @@ namespace LibCmo::CK2 {
class CKGrid; class CKGrid;
} }
//---- Misc // Misc
class CKBehaviorPrototype; class CKBehaviorPrototype;
class CKMessage; class CKMessage;
class CK2dCurvePoint; class CK2dCurvePoint;
@ -362,7 +365,7 @@ namespace LibCmo::CK2 {
class CKFileExtension; class CKFileExtension;
class CKVertexBuffer; class CKVertexBuffer;
//--- Managers // Managers
namespace MgrImpls { namespace MgrImpls {
class CKBaseManager; class CKBaseManager;
class CKObjectManager; class CKObjectManager;
@ -379,13 +382,14 @@ namespace LibCmo::CK2 {
class CKPluginManager; class CKPluginManager;
} }
// Data Handlers
namespace DataHandlers { namespace DataHandlers {
class CKBitmapHandler; class CKBitmapHandler;
class CKMovieHandler; class CKMovieHandler;
class CKSoundHandler; class CKSoundHandler;
} }
//--- Important classes // Important classes
class CKContext; class CKContext;
class CKStateChunk; class CKStateChunk;
class CKFileReader; class CKFileReader;
@ -393,22 +397,20 @@ namespace LibCmo::CK2 {
class CKFileVisitor; class CKFileVisitor;
/** /**
@brief Global Unique Identifier Struture. * @brief Global Unique Identifier Struture.
@remark * @remark
+ Guids are used to uniquely identify plugins,operation types, parameter types and behavior prototypes. * \li Guids are used to uniquely identify plugins,operation types, parameter types and behavior prototypes.
+ Its defined as * \li Comparison operators are defined so CKGUID can be compared with ==, != , <, > operators.
``` * \li Its defined as following code
typedef struct CKGUID { * \code
union { * typedef struct CKGUID {
struct { CKDWORD d1,d2; }; * union {
CKDWORD d[2]; * struct { CKDWORD d1,d2; };
}; * CKDWORD d[2];
}; * };
``` * };
+ Comparison operators are defined so CKGUIDS can be compared with * \endcode
==, != , <, > operators. * @see Pre-Registred Parameter Types, ParameterOperation Types
@see Pre-Registred Parameter Types, ParameterOperation Types
*/ */
struct CKGUID { struct CKGUID {
CKDWORD d1, d2; CKDWORD d1, d2;

View File

@ -1,6 +1,6 @@
#include "CKBitmapHandler.hpp" #include "CKBitmapHandler.hpp"
#include "stb_image.h" #include <stb_image.h>
#include "stb_image_write.h" #include <stb_image_write.h>
namespace LibCmo::CK2::DataHandlers { namespace LibCmo::CK2::DataHandlers {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include <memory> #include <memory>
#include <functional> #include <functional>
@ -30,7 +30,7 @@ namespace LibCmo::CK2::DataHandlers {
public: public:
CKBitmapHandler() {} CKBitmapHandler() {}
virtual ~CKBitmapHandler() {} virtual ~CKBitmapHandler() {}
LIBCMO_DISABLE_COPY_MOVE(CKBitmapHandler); YYCC_DEL_CLS_COPY_MOVE(CKBitmapHandler);
/** /**
* @brief General CKBitmapHandler getter. * @brief General CKBitmapHandler getter.
@ -102,7 +102,7 @@ namespace LibCmo::CK2::DataHandlers {
public: public:
CKBitmapBMPHandler(); CKBitmapBMPHandler();
virtual ~CKBitmapBMPHandler(); virtual ~CKBitmapBMPHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapBMPHandler); YYCC_DEL_CLS_COPY_MOVE(CKBitmapBMPHandler);
static const CKBitmapProperties& GetBitmapDefaultProperties(); static const CKBitmapProperties& GetBitmapDefaultProperties();
@ -118,7 +118,7 @@ namespace LibCmo::CK2::DataHandlers {
public: public:
CKBitmapTGAHandler(); CKBitmapTGAHandler();
virtual ~CKBitmapTGAHandler(); virtual ~CKBitmapTGAHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapTGAHandler); YYCC_DEL_CLS_COPY_MOVE(CKBitmapTGAHandler);
static const CKBitmapProperties& GetBitmapDefaultProperties(); static const CKBitmapProperties& GetBitmapDefaultProperties();
@ -134,7 +134,7 @@ namespace LibCmo::CK2::DataHandlers {
public: public:
CKBitmapJPGHandler(); CKBitmapJPGHandler();
virtual ~CKBitmapJPGHandler(); virtual ~CKBitmapJPGHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapJPGHandler); YYCC_DEL_CLS_COPY_MOVE(CKBitmapJPGHandler);
static const CKBitmapProperties& GetBitmapDefaultProperties(); static const CKBitmapProperties& GetBitmapDefaultProperties();
@ -150,7 +150,7 @@ namespace LibCmo::CK2::DataHandlers {
public: public:
CKBitmapPNGHandler(); CKBitmapPNGHandler();
virtual ~CKBitmapPNGHandler(); virtual ~CKBitmapPNGHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapPNGHandler); YYCC_DEL_CLS_COPY_MOVE(CKBitmapPNGHandler);
static const CKBitmapProperties& GetBitmapDefaultProperties(); static const CKBitmapProperties& GetBitmapDefaultProperties();

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
/** /**
CKBaseManager virtual functions implementations help CKBaseManager virtual functions implementations help
@ -40,7 +40,7 @@ namespace LibCmo::CK2::MgrImpls {
XContainer::NSXString::FromCKSTRING(m_ManagerName, name); XContainer::NSXString::FromCKSTRING(m_ManagerName, name);
} }
virtual ~CKBaseManager() {} virtual ~CKBaseManager() {}
LIBCMO_DISABLE_COPY_MOVE(CKBaseManager); YYCC_DEL_CLS_COPY_MOVE(CKBaseManager);
/** /**
@brief Acces to Manager GUID @brief Acces to Manager GUID

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBaseManager.hpp" #include "CKBaseManager.hpp"
#include <deque> #include <deque>
@ -10,7 +10,7 @@ namespace LibCmo::CK2::MgrImpls {
public: public:
CKObjectManager(CKContext* ctx); CKObjectManager(CKContext* ctx);
virtual ~CKObjectManager(); virtual ~CKObjectManager();
LIBCMO_DISABLE_COPY_MOVE(CKObjectManager); YYCC_DEL_CLS_COPY_MOVE(CKObjectManager);
// ========== Objects Management ========== // ========== Objects Management ==========

View File

@ -2,7 +2,7 @@
namespace LibCmo::CK2::MgrImpls { namespace LibCmo::CK2::MgrImpls {
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
static wchar_t g_UniqueFolder[] = L"LibCmo"; static wchar_t g_UniqueFolder[] = L"LibCmo";
#else #else
static char g_UniqueFolder[] = "LibCmo"; static char g_UniqueFolder[] = "LibCmo";

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBaseManager.hpp" #include "CKBaseManager.hpp"
#include <filesystem> #include <filesystem>
@ -10,7 +10,7 @@ namespace LibCmo::CK2::MgrImpls {
public: public:
CKPathManager(CKContext* ctx); CKPathManager(CKContext* ctx);
virtual ~CKPathManager(); virtual ~CKPathManager();
LIBCMO_DISABLE_COPY_MOVE(CKPathManager); YYCC_DEL_CLS_COPY_MOVE(CKPathManager);
/** /**
* @brief Set the temp folder of current context. * @brief Set the temp folder of current context.

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKRenderObject.hpp" #include "CKRenderObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name); CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CK3dEntity(); virtual ~CK3dEntity();
LIBCMO_DISABLE_COPY_MOVE(CK3dEntity); YYCC_DEL_CLS_COPY_MOVE(CK3dEntity);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_3DENTITY; return CK_CLASSID::CKCID_3DENTITY;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CK3dEntity.hpp" #include "CK3dEntity.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls {
CK3dEntity(ctx, ckid, name) CK3dEntity(ctx, ckid, name)
{} {}
virtual ~CK3dObject() {} virtual ~CK3dObject() {}
LIBCMO_DISABLE_COPY_MOVE(CK3dObject); YYCC_DEL_CLS_COPY_MOVE(CK3dObject);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_3DOBJECT; return CK_CLASSID::CKCID_3DOBJECT;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKSceneObject.hpp" #include "CKSceneObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name); CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKBeObject(); virtual ~CKBeObject();
LIBCMO_DISABLE_COPY_MOVE(CKBeObject); YYCC_DEL_CLS_COPY_MOVE(CKBeObject);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_BEOBJECT; return CK_CLASSID::CKCID_BEOBJECT;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBeObject.hpp" #include "CKBeObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name); CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKGroup(); virtual ~CKGroup();
LIBCMO_DISABLE_COPY_MOVE(CKGroup); YYCC_DEL_CLS_COPY_MOVE(CKGroup);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_GROUP; return CK_CLASSID::CKCID_GROUP;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBeObject.hpp" #include "CKBeObject.hpp"
#include <array> #include <array>
@ -10,7 +10,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKMaterial(CKContext* ctx, CK_ID ckid, CKSTRING name); CKMaterial(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKMaterial(); virtual ~CKMaterial();
LIBCMO_DISABLE_COPY_MOVE(CKMaterial); YYCC_DEL_CLS_COPY_MOVE(CKMaterial);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_MATERIAL; return CK_CLASSID::CKCID_MATERIAL;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBeObject.hpp" #include "CKBeObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -19,7 +19,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKMesh(CKContext* ctx, CK_ID ckid, CKSTRING name); CKMesh(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKMesh(); virtual ~CKMesh();
LIBCMO_DISABLE_COPY_MOVE(CKMesh); YYCC_DEL_CLS_COPY_MOVE(CKMesh);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_MESH; return CK_CLASSID::CKCID_MESH;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
/** /**
CKObject virtual functions implementations help CKObject virtual functions implementations help
@ -40,7 +40,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKObject(CKContext* ctx, CK_ID ckid, CKSTRING name); CKObject(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKObject(); virtual ~CKObject();
LIBCMO_DISABLE_COPY_MOVE(CKObject); YYCC_DEL_CLS_COPY_MOVE(CKObject);
CK_ID GetID(void) const; CK_ID GetID(void) const;
CKSTRING GetName(void) const; CKSTRING GetName(void) const;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKBeObject.hpp" #include "CKBeObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls {
CKBeObject(ctx, ckid, name) CKBeObject(ctx, ckid, name)
{} {}
virtual ~CKRenderObject() {} virtual ~CKRenderObject() {}
LIBCMO_DISABLE_COPY_MOVE(CKRenderObject); YYCC_DEL_CLS_COPY_MOVE(CKRenderObject);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_RENDEROBJECT; return CK_CLASSID::CKCID_RENDEROBJECT;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "CKObject.hpp" #include "CKObject.hpp"
namespace LibCmo::CK2::ObjImpls { namespace LibCmo::CK2::ObjImpls {
@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls {
CKObject(ctx, ckid, name), CKObject(ctx, ckid, name),
m_Scenes() {} m_Scenes() {}
virtual ~CKSceneObject() {} virtual ~CKSceneObject() {}
LIBCMO_DISABLE_COPY_MOVE(CKSceneObject); YYCC_DEL_CLS_COPY_MOVE(CKSceneObject);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_SCENEOBJECT; return CK_CLASSID::CKCID_SCENEOBJECT;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../VTAll.hpp" #include "../../VTInternal.hpp"
#include "../CKBitmapData.hpp" #include "../CKBitmapData.hpp"
#include "CKBeObject.hpp" #include "CKBeObject.hpp"
@ -10,7 +10,7 @@ namespace LibCmo::CK2::ObjImpls {
public: public:
CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name); CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name);
virtual ~CKTexture(); virtual ~CKTexture();
LIBCMO_DISABLE_COPY_MOVE(CKTexture); YYCC_DEL_CLS_COPY_MOVE(CKTexture);
virtual CK_CLASSID GetClassID(void) override { virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_TEXTURE; return CK_CLASSID::CKCID_TEXTURE;

View File

@ -42,10 +42,10 @@ PUBLIC
FILE_SET HEADERS FILE_SET HEADERS
FILES FILES
# Asststant header files # Asststant header files
VTAll.hpp VTInternal.hpp
VTEncoding.hpp VTEncoding.hpp
VTUserAll.hpp
VTUtils.hpp VTUtils.hpp
VTAll.hpp
# CK2 # CK2
CK2/CKDefines.hpp CK2/CKDefines.hpp
CK2/CKEnums.hpp CK2/CKEnums.hpp

View File

@ -1,67 +1,32 @@
#pragma once #pragma once
/* /*
The general including header for LibCom self developer. This file is provided for user of LibCmo.
Every hpp or cpp file should include this first except This file should not be included in LibCmo project inside.
the headers including this file. Use VTInternal.hpp for project internal including.
This header only fulfill type requirements. If you want
some implement based operations, such as calling
CKStateChunk or CKContext function. You should include them manually.
All header or cpp file should include this file first.
Except the file listed in there.
The include list of all files list in there should be carefully managed,
to make sure there are no including loop and each header can fufill its functions.
All 'VT' started file is not a part of Virtools SDK.
They just assist Virtools SDK. So they will use native type, not CK type for decl and impl.
Take VTEncoding.hpp for example, All string is std::string, not XContainer::XString.
The file starts with 'CK', 'Vx', and 'X' is a part of Virtools SDK.
They should use Virtools type anywhere, except with one situation,
Virtools type can not fulfill its requirement.
*/ */
/* #include "VTInternal.hpp"
Including various basic define. #include "CK2/CKContext.hpp"
+ LIBCMO_OS_xxx macro to distinguish different OS and architecture #include "CK2/CKStateChunk.hpp"
+ General types such as CKDWORD and their format constant #include "CK2/CKFile.hpp"
+ Class / struct ctor helper: LIBCMO_DISABLE_COPY_MOVE and LIBCMO_DEFAULT_COPY_MOVE
+ Library panic function
+ Enum helper for add, remove flags for enum.
*/
#include "VTUtils.hpp"
/*
System independent encoding system.
Use native Win32 function in Windows.
And use iconv under other OS.
*/
#include "VTEncoding.hpp"
// Define the basic type of CK2.
#include "CK2/CKTypes.hpp"
// Then we include all XContainer types.
#include "XContainer/XTypes.hpp"
// Then we include all Vx types.
#include "VxMath/VxTypes.hpp"
// Thus all basic type is OK.
// Include CKGlobals which including various essential functions
#include "CK2/CKGlobals.hpp"
// Then load VxMath functions
#include "VxMath/VxMath.hpp"
// OK, all essential functions loaded.
// Load various enums, const value
// Load CK2 first
#include "CK2/CKEnums.hpp"
#include "CK2/CKIdentifiers.hpp"
// load Vx
#include "VxMath/VxEnums.hpp"
// Last, load some custom struct used in program.
#include "CK2/CKDefines.hpp"
// Data handlers
#include "CK2/DataHandlers/CKBitmapHandler.hpp"
// Objects
#include "CK2/ObjImpls/CKObject.hpp"
#include "CK2/ObjImpls/CKSceneObject.hpp"
#include "CK2/ObjImpls/CKBeObject.hpp"
#include "CK2/ObjImpls/CKGroup.hpp"
#include "CK2/ObjImpls/CKRenderObject.hpp"
#include "CK2/ObjImpls/CK3dEntity.hpp"
#include "CK2/ObjImpls/CK3dObject.hpp"
#include "CK2/ObjImpls/CKTexture.hpp"
#include "CK2/ObjImpls/CKMaterial.hpp"
#include "CK2/ObjImpls/CKMesh.hpp"
// Managers
#include "CK2/MgrImpls/CKBaseManager.hpp"
#include "CK2/MgrImpls/CKObjectManager.hpp"
#include "CK2/MgrImpls/CKPathManager.hpp"

View File

@ -3,22 +3,155 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
/**
* @brief The namespace providing platform independent encoding convertion solution.
* @details
* LibCmo is a cross-platform library.
* In different platform, they have their own encoding solution.
* So we create a universal encoding solution in this namespace like Python does.
* User only need input our universal language name,
* then they can convert same strings in different platforms.
*/
namespace LibCmo::EncodingHelper { namespace LibCmo::EncodingHelper {
/**
* @brief The token for encoding convertion.
* @details
* If you want to use any encoding function provided by this namespace,
* you should fetch a proper token for it.
* This token records the encoding which you want to convert from / to.
*
* In underlying implementation, this token type is a pointer
* pointing to an allocated memory space recording you specified encoding infomations.
* So this token should only be fetched from CreateEncodingToken()
* and must be freed by DestroyEncodingToken() if you don't need it.
* Otherwise it will cause memory leak.
*/
using EncodingToken = void*; using EncodingToken = void*;
/**
* @brief The invalid value of #EncodingToken.
* @details
* It represents an invalid encoding token.
* Any encoding token which equals to this value should not be used.
* In underlying implementation, it actually is \c nullptr.
* Because EncodingToken is just a raw pointer.
*/
constexpr EncodingToken INVALID_ENCODING_TOKEN = nullptr; constexpr EncodingToken INVALID_ENCODING_TOKEN = nullptr;
/**
* @brief Create encoding token by given universal encoding name.
* @param[in] enc_name Universal encoding name.
* @return
* The generated encoding token.
* #INVALID_ENCODING_TOKEN if fail to generate encoding token.
* Usually it means that your given encoding name is invalid.
* Please note any successfully generated encoding token must be freed by DestroyEncodingToken().
*/
EncodingToken CreateEncodingToken(const std::u8string_view& enc_name); EncodingToken CreateEncodingToken(const std::u8string_view& enc_name);
/**
* @brief Destroy given encoding token and free its associated resources.
* @param[in] token
* The encoding token to be destroyed.
* If token is #INVALID_ENCODING_TOKEN, this function does nothing.
*/
void DestroyEncodingToken(EncodingToken token); void DestroyEncodingToken(EncodingToken token);
/**
* @brief Convert native string to UTF8 string by given encoding.
* @param[in] src The native string view to be converted.
* @param[out] dst The variable holding converted UTF8 string result.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return True if success, otherwise false.
*/
bool ToOrdinary(const std::u8string_view& src, std::string& dst, EncodingToken token); bool ToOrdinary(const std::u8string_view& src, std::string& dst, EncodingToken token);
/**
* @brief Convert native string to UTF8 string by given encoding.
* @param[in] src
* The pointer to native string to be converted.
* nullptr is allowed but it will result in that function returns false.
* @param[out] dst The variable holding converted UTF8 string result.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return True if success, otherwise false.
*/
bool ToOrdinary(const char8_t* src, std::string& dst, EncodingToken token); bool ToOrdinary(const char8_t* src, std::string& dst, EncodingToken token);
/**
* @brief Convert native string to UTF8 string by given encoding.
* @param[in] src The native string view to be converted.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return
* Converted UTF8 string result. Empty string if function failed.
* Please note empty input will also produce empty result.
* For preventing this ambiguity, please use other overloads.
*/
std::string ToOrdinary(const std::u8string_view& src, EncodingToken token); std::string ToOrdinary(const std::u8string_view& src, EncodingToken token);
/**
* @brief Convert native string to UTF8 string by given encoding.
* @param[in] src
* The pointer to native string to be converted.
* nullptr is allowed but it will result in that function returns false.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return
* Converted UTF8 string result. Empty string if function failed.
* Please note empty input will also produce empty result.
* For preventing this ambiguity, please use other overloads.
*/
std::string ToOrdinary(const char8_t* src, EncodingToken token); std::string ToOrdinary(const char8_t* src, EncodingToken token);
/**
* @brief Convert UTF8 string to native string by given encoding.
* @param[in] src The UTF8 string view to be converted.
* @param[out] dst The variable holding converted native string result.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return True if success, otherwise false.
*/
bool ToUTF8(const std::string_view& src, std::u8string& dst, EncodingToken token); bool ToUTF8(const std::string_view& src, std::u8string& dst, EncodingToken token);
/**
* @brief Convert UTF8 string to native string by given encoding.
* @param[in] src
* The pointer to UTF8 string to be converted.
* nullptr is allowed but it will result in that function returns false.
* @param[out] dst The variable holding converted native string result.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return True if success, otherwise false.
*/
bool ToUTF8(const char* src, std::u8string& dst, EncodingToken token); bool ToUTF8(const char* src, std::u8string& dst, EncodingToken token);
/**
* @brief Convert UTF8 string to native string by given encoding.
* @param[in] src The UTF8 string view to be converted.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return
* Converted native string result. Empty string if function failed.
* Please note empty input will also produce empty result.
* For preventing this ambiguity, please use other overloads.
*/
std::u8string ToUTF8(const std::string_view& src, EncodingToken token); std::u8string ToUTF8(const std::string_view& src, EncodingToken token);
/**
* @brief Convert UTF8 string to native string by given encoding.
* @param[in] src
* The pointer to UTF8 string to be converted.
* nullptr is allowed but it will result in that function returns false.
* @param[in] token
* The encoding used when converting.
* #INVALID_ENCODING_TOKEN causes function returns false.
* @return
* Converted native string result. Empty string if function failed.
* Please note empty input will also produce empty result.
* For preventing this ambiguity, please use other overloads.
*/
std::u8string ToUTF8(const char* src, EncodingToken token); std::u8string ToUTF8(const char* src, EncodingToken token);
} }

59
LibCmo/VTInternal.hpp Normal file
View File

@ -0,0 +1,59 @@
#pragma once
/**
* \file
* The top header file for LibCom self development.
* Every C++ header or source file located in this project should include this first
* except the headers including this file.
* The header files included by this header should be carefully managed,
* to make sure there are no include loop and each header files can works correctly.
*
* This header should only be used as internal header file.
* It only contains all necessary stuff used by this project self.
* Any other program linked to this library should not include this header file directly.
* The best way to include this library is include VTAll.hpp which include this header file at the first position.
*
* All \c VT started files are not a part of Virtools SDK. They just assist Virtools SDK.
* So they will use native type, not CK type for declaration and implementation.
* Take VTEncoding.hpp for example, All string used in it is \c std::u8string, not LibCmo::XContainer::XString.
* The file starts with \c CK, \c Vx, and \c X is a part of Virtools SDK.
* They should use Virtools type anywhere, except that Virtools type can not fulfill their requirement.
*/
// The base header of LibCmo.
// It provides various convenient stuff, for example:
// - General LibCmo specific custom exception.
// - Enum Helper for convenient C++ enum class type logic operations.
#include "VTUtils.hpp"
// Platform independent encoding system.
// Use native Win32 functions in Windows,
// or Iconv in non-Windows to provide encoding convertion services.
#include "VTEncoding.hpp"
// Include CK2 types first.
// Because it also include some types or structs used by other module.
#include "CK2/CKTypes.hpp"
// Then include all XContainer types.
#include "XContainer/XTypes.hpp"
// Then include all VxMath types.
#include "VxMath/VxTypes.hpp"
// Now all basic types are included.
// Include CKGlobals which including various essential functions
#include "CK2/CKGlobals.hpp"
// Then load VxMath functions
#include "VxMath/VxMath.hpp"
// OK, all essential functions loaded.
// Load various enums, constant values
// Load CK2 Enums and CKStateChunk Identifier.
#include "CK2/CKEnums.hpp"
#include "CK2/CKIdentifiers.hpp"
// Load VxMath Enums
#include "VxMath/VxEnums.hpp"
// Last, load some custom struct used in program.
#include "CK2/CKDefines.hpp"

View File

@ -1,32 +0,0 @@
#pragma once
/*
This file is provided for user of LibCmo.
This file should not be included in LibCmo project inside.
Use VTAll.hpp for project internal including.
*/
#include "VTAll.hpp"
#include "CK2/CKContext.hpp"
#include "CK2/CKStateChunk.hpp"
#include "CK2/CKFile.hpp"
// Data handlers
#include "CK2/DataHandlers/CKBitmapHandler.hpp"
// Objects
#include "CK2/ObjImpls/CKObject.hpp"
#include "CK2/ObjImpls/CKSceneObject.hpp"
#include "CK2/ObjImpls/CKBeObject.hpp"
#include "CK2/ObjImpls/CKGroup.hpp"
#include "CK2/ObjImpls/CKRenderObject.hpp"
#include "CK2/ObjImpls/CK3dEntity.hpp"
#include "CK2/ObjImpls/CK3dObject.hpp"
#include "CK2/ObjImpls/CKTexture.hpp"
#include "CK2/ObjImpls/CKMaterial.hpp"
#include "CK2/ObjImpls/CKMesh.hpp"
// Managers
#include "CK2/MgrImpls/CKBaseManager.hpp"
#include "CK2/MgrImpls/CKObjectManager.hpp"
#include "CK2/MgrImpls/CKPathManager.hpp"

View File

@ -13,12 +13,16 @@
#include <type_traits> #include <type_traits>
#include <initializer_list> #include <initializer_list>
/**
* @brief The core namespace of LibCmo project.
* @details All functions and classes involving LibCmo are located in this namespace.
*/
namespace LibCmo { namespace LibCmo {
#pragma region LibCmo Exceptions #pragma region LibCmo Exceptions
/** /**
* @brief The exception raised when library entering unreachable scope. * @brief The exception thrown when library entering unreachable scope.
* @details This exception usually used in \c switch syntax. * @details This exception usually used in \c switch syntax.
* It means that program enter the scope which it definitely can not enter. * It means that program enter the scope which it definitely can not enter.
*/ */
@ -33,7 +37,7 @@ namespace LibCmo {
}; };
/** /**
* @brief The exception raised when library entering logic error. * @brief The exception thrown when library entering logic error.
* @details In theory, this exception can be found by reading code. * @details In theory, this exception can be found by reading code.
* It usually caused by programmer use functions in a wrong way. * It usually caused by programmer use functions in a wrong way.
* For example, pass invalid argument to function and etc. * For example, pass invalid argument to function and etc.
@ -49,7 +53,7 @@ namespace LibCmo {
}; };
/** /**
* @brief The exception raised when library entering runtime error. * @brief The exception thrown when library entering runtime error.
* @details In theory, this exception can not be found by reading code. * @details In theory, this exception can not be found by reading code.
* It may caused by user input or anything else. * It may caused by user input or anything else.
*/ */
@ -65,13 +69,23 @@ namespace LibCmo {
#pragma endregion #pragma endregion
/**
* @brief The namespace for convenient C++ enum class logic operations.
* @details
* C++ enum class statement is a modern way to declare enum in C++.
* But it lack essential logic operations which is commonly used by programmer.
* So we create this helper to resolve this issue.
*/
namespace EnumsHelper { namespace EnumsHelper {
/** /**
* @brief Return 'e1 | e2 | ... | en' * @brief Merge given enum flags like performing <TT>e1 | e2 | ... | en</TT>
* @tparam TEnum Enum type for processing.
* @param[in] il The list of enum flags to be merged.
* @return The merged enum flag.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Merge(std::initializer_list<TEnum> il) { constexpr TEnum Merge(std::initializer_list<TEnum> il) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
ut result = 0; ut result = 0;
for (auto it = il.begin(); it != il.end(); ++it) { for (auto it = il.begin(); it != il.end(); ++it) {
@ -81,48 +95,64 @@ namespace LibCmo {
} }
/** /**
* @brief Return '~(e)' * @brief Reverse given enum flags like performing <TT>~(e)</TT>
* @tparam TEnum Enum type for processing.
* @param[in] il The list of enum flags to be inversed.
* @return The inversed enum flag.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Inv(TEnum e) { constexpr TEnum Inv(TEnum e) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
return static_cast<TEnum>(~(static_cast<ut>(e))); return static_cast<TEnum>(~(static_cast<ut>(e)));
} }
/** /**
* @brief Operate e1 &= (~e2) * @brief Remove specified enum flags from given enum flags like performing <TT>e1 &= (~e2)</TT>
* @tparam TEnum Enum type for processing.
* @param[in,out] e1 The enum flags to be processed.
* @param[in] e2 The enum flag to be removed.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline void Rm(TEnum& e1, TEnum e2) { constexpr void Rm(TEnum& e1, TEnum e2) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(Inv(e2))); e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(Inv(e2)));
} }
/** /**
* @brief Operate e1 &= e2 * @brief Use specified enum flags to mask given enum flags like performing <TT>e1 &= e2</TT>
* @tparam TEnum Enum type for processing.
* @param[in,out] e1 The enum flags to be masked.
* @param[in] e2 The mask enum flag.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline void Mask(TEnum& e1, TEnum e2) { constexpr void Mask(TEnum& e1, TEnum e2) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(e2)); e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(e2));
} }
/** /**
* @brief Operate e1 |= e2 * @brief Add specified enum flags to given enum flags like performing <TT>e1 |= e2</TT>
* @tparam TEnum Enum type for processing.
* @param[in,out] e1 The enum flags to be processed.
* @param[in] e2 The enum flag to be added.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline void Add(TEnum& e1, TEnum e2) { constexpr void Add(TEnum& e1, TEnum e2) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
e1 = static_cast<TEnum>(static_cast<ut>(e1) | static_cast<ut>(e2)); e1 = static_cast<TEnum>(static_cast<ut>(e1) | static_cast<ut>(e2));
} }
/** /**
* @brief Return 'bool(e1 & e2)' * @brief Check whether given enum flags has specified enum flag like performing <TT>bool(e & probe)</TT>
* @tparam TEnum Enum type for processing.
* @param[in] e1 The enum flags to be checked.
* @param[in] e2 The enum flag for checking.
* @return True if it has, otherwise false.
*/ */
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0> template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline bool Has(TEnum e, TEnum probe) { constexpr bool Has(TEnum e1, TEnum e2) {
using ut = std::underlying_type_t<TEnum>; using ut = std::underlying_type_t<TEnum>;
return static_cast<bool>(static_cast<ut>(e) & static_cast<ut>(probe)); return static_cast<bool>(static_cast<ut>(e1) & static_cast<ut>(e2));
} }
} }

View File

@ -1,6 +1,6 @@
#include "VxMath.hpp" #include "VxMath.hpp"
#include <cmath> #include <cmath>
#include "stb_image_resize.h" #include <stb_image_resize.h>
namespace LibCmo::VxMath { namespace LibCmo::VxMath {

View File

@ -5,7 +5,7 @@ namespace LibCmo::VxMath {
VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) : VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) :
// init members // init members
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL), m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL),
m_dwFileSizeLow(0), m_dwFileSizeHigh(0), m_dwFileSizeLow(0), m_dwFileSizeHigh(0),
#else #else
@ -15,14 +15,14 @@ namespace LibCmo::VxMath {
m_bIsValid(false), m_pMemoryMappedFileBase(nullptr), m_cbFile(0u) { m_bIsValid(false), m_pMemoryMappedFileBase(nullptr), m_cbFile(0u) {
// save file path // save file path
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
EncodingHelper::U8PathToStdPath(m_szFilePath, u8_filepath); EncodingHelper::U8PathToStdPath(m_szFilePath, u8_filepath);
#else #else
this->m_szFilePath = u8_filepath; this->m_szFilePath = u8_filepath;
#endif #endif
// real mapping work // real mapping work
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
// open file // open file
this->m_hFile = CreateFileW( this->m_hFile = CreateFileW(
@ -124,7 +124,7 @@ namespace LibCmo::VxMath {
m_cbFile = 0; m_cbFile = 0;
m_pMemoryMappedFileBase = nullptr; m_pMemoryMappedFileBase = nullptr;
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
UnmapViewOfFile(this->m_hFileMapView); UnmapViewOfFile(this->m_hFileMapView);
CloseHandle(m_hFileMapping); CloseHandle(m_hFileMapping);
CloseHandle(m_hFile); CloseHandle(m_hFile);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../VTAll.hpp" #include "../VTInternal.hpp"
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
// disable annoy macro at the same time // disable annoy macro at the same time
#undef GetObject #undef GetObject
@ -24,7 +24,7 @@ namespace LibCmo::VxMath {
class VxMemoryMappedFile { class VxMemoryMappedFile {
private: private:
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
HANDLE m_hFile; HANDLE m_hFile;
DWORD m_dwFileSizeLow, m_dwFileSizeHigh; DWORD m_dwFileSizeLow, m_dwFileSizeHigh;
HANDLE m_hFileMapping; HANDLE m_hFileMapping;

View File

@ -19,29 +19,28 @@ namespace LibCmo::VxMath {
// ========== Class List ========== // ========== Class List ==========
//--- Important classes // Important classes
class VxMemoryMappedFile; class VxMemoryMappedFile;
//---- Misc // Misc
struct VxVector2 { struct VxVector2 {
CKFLOAT x, y; CKFLOAT x, y;
VxVector2() : x(0.0f), y(0.0f) {} VxVector2() : x(0.0f), y(0.0f) {}
VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {} VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector2); YYCC_DEF_CLS_COPY_MOVE(VxVector2);
CKFLOAT& operator[](size_t i) { CKFLOAT& operator[](size_t i) {
switch (i) { switch (i) {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return x; default: throw LogicException("Invalid index for VxVector2::operator[].");
} }
} }
const CKFLOAT& operator[](size_t i) const { const CKFLOAT& operator[](size_t i) const {
switch (i) { switch (i) {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return x; default: throw LogicException("Invalid index for VxVector2::operator[].");
} }
} }
VxVector2& operator+=(const VxVector2& rhs) { VxVector2& operator+=(const VxVector2& rhs) {
@ -87,9 +86,6 @@ namespace LibCmo::VxMath {
bool operator==(const VxVector2& rhs) const { bool operator==(const VxVector2& rhs) const {
return (x == rhs.x && y == rhs.y); return (x == rhs.x && y == rhs.y);
} }
bool operator!=(const VxVector2& rhs) const {
return !(*this == rhs);
}
CKFLOAT SquaredLength() const { CKFLOAT SquaredLength() const {
return (x * x + y * y); return (x * x + y * y);
} }
@ -113,13 +109,13 @@ namespace LibCmo::VxMath {
CKFLOAT x, y, z; CKFLOAT x, y, z;
VxVector3() : x(0.0f), y(0.0f), z(0.0f) {} VxVector3() : x(0.0f), y(0.0f), z(0.0f) {}
VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {} VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector3); YYCC_DEF_CLS_COPY_MOVE(VxVector3);
CKFLOAT& operator[](size_t i) { CKFLOAT& operator[](size_t i) {
switch (i) { switch (i) {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return x; default: throw LogicException("Invalid index for VxVector3::operator[].");
} }
} }
const CKFLOAT& operator[](size_t i) const { const CKFLOAT& operator[](size_t i) const {
@ -127,7 +123,7 @@ namespace LibCmo::VxMath {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return x; default: throw LogicException("Invalid index for VxVector3::operator[].");
} }
} }
VxVector3& operator+=(const VxVector3& rhs) { VxVector3& operator+=(const VxVector3& rhs) {
@ -177,9 +173,6 @@ namespace LibCmo::VxMath {
bool operator==(const VxVector3& rhs) const { bool operator==(const VxVector3& rhs) const {
return (x == rhs.x && y == rhs.y && z == rhs.z); return (x == rhs.x && y == rhs.y && z == rhs.z);
} }
bool operator!=(const VxVector3& rhs) const {
return !(*this == rhs);
}
CKFLOAT SquaredLength() const { CKFLOAT SquaredLength() const {
return (x * x + y * y + z * z); return (x * x + y * y + z * z);
} }
@ -204,14 +197,14 @@ namespace LibCmo::VxMath {
CKFLOAT x, y, z, w; CKFLOAT x, y, z, w;
VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector4); YYCC_DEF_CLS_COPY_MOVE(VxVector4);
CKFLOAT& operator[](size_t i) { CKFLOAT& operator[](size_t i) {
switch (i) { switch (i) {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return x; default: throw LogicException("Invalid index for VxVector4::operator[].");
} }
} }
const CKFLOAT& operator[](size_t i) const { const CKFLOAT& operator[](size_t i) const {
@ -220,7 +213,7 @@ namespace LibCmo::VxMath {
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return x; default: throw LogicException("Invalid index for VxVector4::operator[].");
} }
} }
VxVector4& operator+=(const VxVector4& rhs) { VxVector4& operator+=(const VxVector4& rhs) {
@ -274,9 +267,6 @@ namespace LibCmo::VxMath {
bool operator==(const VxVector4& rhs) const { bool operator==(const VxVector4& rhs) const {
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
} }
bool operator!=(const VxVector4& rhs) const {
return !(*this == rhs);
}
CKFLOAT SquaredLength() const { CKFLOAT SquaredLength() const {
return (x * x + y * y + z * z + w * w); return (x * x + y * y + z * z + w * w);
} }
@ -300,32 +290,38 @@ namespace LibCmo::VxMath {
struct VxQuaternion { struct VxQuaternion {
CKFLOAT x, y, z, w; CKFLOAT x, y, z, w;
VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(1.0f) {} // set your custom init. VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} // set your custom init.
VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
LIBCMO_DEFAULT_COPY_MOVE(VxQuaternion); YYCC_DEF_CLS_COPY_MOVE(VxQuaternion);
CKFLOAT& operator[](size_t i) { CKFLOAT& operator[](size_t i) {
switch (i) { switch (i) {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return x; default: throw LogicException("Invalid index for VxQuaternion::operator[].");
}
}
const CKFLOAT& operator[](size_t i) const {
switch (i) {
case 0: return x;
case 1: return y;
case 2: return z;
case 3: return w;
default: throw LogicException("Invalid index for VxQuaternion::operator[].");
} }
} }
bool operator==(const VxQuaternion& rhs) const { bool operator==(const VxQuaternion& rhs) const {
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
} }
bool operator!=(const VxQuaternion& rhs) const {
return !(*this == rhs);
}
}; };
struct VxColor { struct VxColor {
CKFLOAT r, g, b, a; CKFLOAT r, g, b, a;
VxColor() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {} // set your custom init. VxColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} // set your custom init.
VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {} VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {}
VxColor(CKDWORD argb) { FromARGB(argb); } VxColor(CKDWORD argb) { FromARGB(argb); }
LIBCMO_DEFAULT_COPY_MOVE(VxColor); YYCC_DEF_CLS_COPY_MOVE(VxColor);
void FromARGB(CKDWORD argb) { void FromARGB(CKDWORD argb) {
a = ((argb & 0xFF000000) >> 24) / 255.0f; a = ((argb & 0xFF000000) >> 24) / 255.0f;
r = ((argb & 0x00FF0000) >> 16) / 255.0f; r = ((argb & 0x00FF0000) >> 16) / 255.0f;
@ -359,43 +355,43 @@ namespace LibCmo::VxMath {
case 1: return g; case 1: return g;
case 2: return b; case 2: return b;
case 3: return a; case 3: return a;
default: return r; default: throw LogicException("Invalid index for VxColor::operator[].");
}
}
const CKFLOAT& operator[](size_t i) const {
switch (i) {
case 0: return r;
case 1: return g;
case 2: return b;
case 3: return a;
default: throw LogicException("Invalid index for VxColor::operator[].");
} }
} }
bool operator==(const VxColor& rhs) const { bool operator==(const VxColor& rhs) const {
return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a);
} }
bool operator!=(const VxColor& rhs) const {
return !(*this == rhs);
}
}; };
struct VxMatrix { struct VxMatrix {
CKFLOAT m_Data[4][4]; CKFLOAT m_Data[4][4];
VxMatrix() : m_Data() { ResetToIdentity(); }
VxMatrix() : m_Data() {
ResetToIdentity();
}
VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); } VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
LIBCMO_DEFAULT_COPY_MOVE(VxMatrix); YYCC_DEF_CLS_COPY_MOVE(VxMatrix);
void ResetToIdentity() { void ResetToIdentity() {
std::memset(m_Data, 0, sizeof(m_Data)); std::memset(m_Data, 0, sizeof(m_Data));
m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f; m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f;
} }
VxVector4& operator[](size_t i) { VxVector4& operator[](size_t i) {
if (i >= 4) i = 0; if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[].");
return *(reinterpret_cast<VxVector4*>(m_Data) + i); return *(reinterpret_cast<VxVector4*>(m_Data) + i);
} }
const VxVector4& operator[](size_t i) const { const VxVector4& operator[](size_t i) const {
if (i >= 4) i = 0; if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[].");
return *(reinterpret_cast<const VxVector4*>(m_Data) + i); return *(reinterpret_cast<const VxVector4*>(m_Data) + i);
} }
bool operator==(const VxMatrix& rhs) const { bool operator==(const VxMatrix& rhs) const {
return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0; return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0;
} }
bool operator!=(const VxMatrix& rhs) const {
return !(*this == rhs);
}
}; };
template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0> template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0>

View File

@ -16,7 +16,7 @@ namespace LibCmo::XContainer {
@brief Class representation of a string (an array of character ended by NULL). @brief Class representation of a string (an array of character ended by NULL).
@remark This class now use std::string. @remark This class now use std::string.
*/ */
using XString = std::string; using XString = std::u8string;
/** /**
@brief Set of bit flags. @brief Set of bit flags.

View File

@ -26,7 +26,7 @@ namespace Unvirt::CmdHelper {
mCmdChar(0), mBuffer(nullptr), mResult(nullptr), mCmdChar(0), mBuffer(nullptr), mResult(nullptr),
mState(StateType::NORMAL), mPreState(StateType::NORMAL) {} mState(StateType::NORMAL), mPreState(StateType::NORMAL) {}
~CmdSplitter() {} ~CmdSplitter() {}
LIBCMO_DISABLE_COPY_MOVE(CmdSplitter); YYCC_DEL_CLS_COPY_MOVE(CmdSplitter);
std::deque<std::string> Convert(const std::string& u8cmd); std::deque<std::string> Convert(const std::string& u8cmd);
protected: protected:
@ -47,7 +47,7 @@ namespace Unvirt::CmdHelper {
public: public:
HelpDocument(); HelpDocument();
~HelpDocument(); ~HelpDocument();
LIBCMO_DISABLE_COPY_MOVE(HelpDocument); YYCC_DEL_CLS_COPY_MOVE(HelpDocument);
void Push(const std::string& arg_name, const std::string& arg_desc); void Push(const std::string& arg_name, const std::string& arg_desc);
void Pop(); void Pop();
@ -58,7 +58,7 @@ namespace Unvirt::CmdHelper {
struct StackItem { struct StackItem {
StackItem() : m_Name(), m_Desc() {} StackItem() : m_Name(), m_Desc() {}
StackItem(const std::string& name, const std::string& desc) : m_Name(name), m_Desc(desc) {} StackItem(const std::string& name, const std::string& desc) : m_Name(name), m_Desc(desc) {}
LIBCMO_DEFAULT_COPY_MOVE(StackItem); YYCC_DEF_CLS_COPY_MOVE(StackItem);
std::string m_Name; std::string m_Name;
std::string m_Desc; std::string m_Desc;
}; };
@ -66,7 +66,7 @@ namespace Unvirt::CmdHelper {
struct ResultItem { struct ResultItem {
ResultItem() : m_CmdDesc(), m_ArgDesc() {} ResultItem() : m_CmdDesc(), m_ArgDesc() {}
ResultItem(const std::string& desc) : m_CmdDesc(desc), m_ArgDesc() {} ResultItem(const std::string& desc) : m_CmdDesc(desc), m_ArgDesc() {}
LIBCMO_DEFAULT_COPY_MOVE(ResultItem); YYCC_DEF_CLS_COPY_MOVE(ResultItem);
std::string m_CmdDesc; std::string m_CmdDesc;
std::vector<StackItem> m_ArgDesc; std::vector<StackItem> m_ArgDesc;
}; };
@ -82,7 +82,7 @@ namespace Unvirt::CmdHelper {
public: public:
AbstractNode(); AbstractNode();
virtual ~AbstractNode(); virtual ~AbstractNode();
LIBCMO_DISABLE_COPY_MOVE(AbstractNode); YYCC_DEL_CLS_COPY_MOVE(AbstractNode);
AbstractNode* Then(AbstractNode*); AbstractNode* Then(AbstractNode*);
AbstractNode* Executes(ExecutionFct, const char* = nullptr); AbstractNode* Executes(ExecutionFct, const char* = nullptr);
@ -110,7 +110,7 @@ namespace Unvirt::CmdHelper {
public: public:
CommandRoot(); CommandRoot();
virtual ~CommandRoot(); virtual ~CommandRoot();
LIBCMO_DISABLE_COPY_MOVE(CommandRoot); YYCC_DEL_CLS_COPY_MOVE(CommandRoot);
// Root use special consume and help functions. // Root use special consume and help functions.
bool RootConsume(std::deque<std::string>&); bool RootConsume(std::deque<std::string>&);
@ -131,7 +131,7 @@ namespace Unvirt::CmdHelper {
public: public:
Literal(const char* words); Literal(const char* words);
virtual ~Literal(); virtual ~Literal();
LIBCMO_DISABLE_COPY_MOVE(Literal); YYCC_DEL_CLS_COPY_MOVE(Literal);
public: public:
virtual NodeType GetNodeType() override; virtual NodeType GetNodeType() override;
@ -151,7 +151,7 @@ namespace Unvirt::CmdHelper {
using vType = size_t; using vType = size_t;
Choice(const char* argname, const std::initializer_list<std::string>& vocabulary); Choice(const char* argname, const std::initializer_list<std::string>& vocabulary);
virtual ~Choice(); virtual ~Choice();
LIBCMO_DISABLE_COPY_MOVE(Choice); YYCC_DEL_CLS_COPY_MOVE(Choice);
vType* GetIndex(); vType* GetIndex();
@ -175,7 +175,7 @@ namespace Unvirt::CmdHelper {
public: public:
AbstractArgument(const char* argname); AbstractArgument(const char* argname);
virtual ~AbstractArgument(); virtual ~AbstractArgument();
LIBCMO_DISABLE_COPY_MOVE(AbstractArgument); YYCC_DEL_CLS_COPY_MOVE(AbstractArgument);
template<class T> template<class T>
T GetData() { T GetData() {
@ -208,7 +208,7 @@ namespace Unvirt::CmdHelper {
IntArgument(const char* argname, IntLimit limit = nullptr) : IntArgument(const char* argname, IntLimit limit = nullptr) :
AbstractArgument(argname), m_IntLimit(limit) {} AbstractArgument(argname), m_IntLimit(limit) {}
virtual ~IntArgument() {} virtual ~IntArgument() {}
LIBCMO_DISABLE_COPY_MOVE(IntArgument); YYCC_DEL_CLS_COPY_MOVE(IntArgument);
protected: protected:
virtual bool BeginParse(const std::string&) override; virtual bool BeginParse(const std::string&) override;
@ -223,7 +223,7 @@ namespace Unvirt::CmdHelper {
StringArgument(const char* argname) : StringArgument(const char* argname) :
AbstractArgument(argname) {} AbstractArgument(argname) {}
virtual ~StringArgument() {} virtual ~StringArgument() {}
LIBCMO_DISABLE_COPY_MOVE(StringArgument); YYCC_DEL_CLS_COPY_MOVE(StringArgument);
protected: protected:
virtual bool BeginParse(const std::string&) override; virtual bool BeginParse(const std::string&) override;
@ -236,7 +236,7 @@ namespace Unvirt::CmdHelper {
EncodingArgument(const char* argname) : EncodingArgument(const char* argname) :
AbstractArgument(argname) {} AbstractArgument(argname) {}
virtual ~EncodingArgument() {} virtual ~EncodingArgument() {}
LIBCMO_DISABLE_COPY_MOVE(EncodingArgument); YYCC_DEL_CLS_COPY_MOVE(EncodingArgument);
protected: protected:
virtual bool BeginParse(const std::string&) override; virtual bool BeginParse(const std::string&) override;
@ -247,7 +247,7 @@ namespace Unvirt::CmdHelper {
public: public:
ArgumentsMap() : m_Data() {} ArgumentsMap() : m_Data() {}
~ArgumentsMap() {} ~ArgumentsMap() {}
LIBCMO_DISABLE_COPY_MOVE(ArgumentsMap); YYCC_DEL_CLS_COPY_MOVE(ArgumentsMap);
void Add(const std::string& k, AbstractNode* v); void Add(const std::string& k, AbstractNode* v);
void Remove(const std::string& k); void Remove(const std::string& k);

View File

@ -1,4 +1,3 @@
#include <VTUserAll.hpp>
#include "StructFormatter.hpp" #include "StructFormatter.hpp"
#include "AccessibleValue.hpp" #include "AccessibleValue.hpp"
#include "TerminalHelper.hpp" #include "TerminalHelper.hpp"

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <VTAll.hpp> #include <VTAll.hpp>
#include <CK2/CKFile.hpp>
namespace Unvirt::StructFormatter { namespace Unvirt::StructFormatter {

View File

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#include <cstdio> #include <cstdio>
#include <io.h> #include <io.h>
@ -19,7 +19,7 @@ namespace Unvirt {
// due to shitty Windows implementations. // due to shitty Windows implementations.
bool EnsureTerminalColor(void) { bool EnsureTerminalColor(void) {
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
if (_isatty(_fileno(stdout))) { if (_isatty(_fileno(stdout))) {
HANDLE h_output; HANDLE h_output;
DWORD dw_mode; DWORD dw_mode;
@ -36,7 +36,7 @@ namespace Unvirt {
} }
bool EnsureTerminalEncoding(void) { bool EnsureTerminalEncoding(void) {
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
if (!SetConsoleCP(CP_UTF8)) return false; if (!SetConsoleCP(CP_UTF8)) return false;
if (!SetConsoleOutputCP(CP_UTF8)) return false; if (!SetConsoleOutputCP(CP_UTF8)) return false;
@ -48,7 +48,7 @@ namespace Unvirt {
void GetCmdLine(std::string& u8cmd) { void GetCmdLine(std::string& u8cmd) {
fputs(UNVIRT_TERMCOL_LIGHT_GREEN(("Unvirt> ")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_GREEN(("Unvirt> ")), stdout);
#if defined(LIBCMO_OS_WIN32) #if YYCC_OS == YYCC_OS_WINDOWS
std::wstring wcmd; std::wstring wcmd;
std::getline(std::wcin, wcmd); std::getline(std::wcin, wcmd);
LibCmo::EncodingHelper::WcharToChar(wcmd, u8cmd, CP_UTF8); LibCmo::EncodingHelper::WcharToChar(wcmd, u8cmd, CP_UTF8);

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <VTAll.hpp>
#include "AccessibleValue.hpp" #include "AccessibleValue.hpp"
#include "TerminalHelper.hpp" #include "TerminalHelper.hpp"
#include "StructFormatter.hpp" #include "StructFormatter.hpp"
#include "CmdHelper.hpp" #include "CmdHelper.hpp"
#include <VTUserAll.hpp>
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
@ -15,7 +15,7 @@ namespace Unvirt::Context {
public: public:
UnvirtContext(); UnvirtContext();
~UnvirtContext(); ~UnvirtContext();
LIBCMO_DISABLE_COPY_MOVE(UnvirtContext); YYCC_DEL_CLS_COPY_MOVE(UnvirtContext);
void Run(); void Run();