refactor project

This commit is contained in:
yyc12345 2023-09-16 18:31:25 +08:00
parent 8f960604ca
commit 1ddeeb3b68
41 changed files with 725 additions and 749 deletions

View File

@ -105,7 +105,7 @@ public class CommonHelper {
* @return The string form of its underlying type.
*/
public static String getEnumUnderlyingType(boolean canUnsigned) {
return canUnsigned ? "uint32_t" : "int32_t";
return canUnsigned ? "CKDWORD" : "CKINT";
}
// =========== Parts ===========

View File

@ -1,12 +1,12 @@
def GetTmplDecl(svars: tuple[str]) -> str:
return f'float {", ".join(svars)};'
return f'CKFLOAT {", ".join(svars)};'
def GetTmplCtor1(sname: str, svars: tuple[str]) -> str:
return f'{sname}() : {", ".join(map(lambda x: f"{x}(0.0f)", svars))} {{}}'
def GetTmplCtor2(sname: str, svars: tuple[str]) -> str:
return f'{sname}({", ".join(map(lambda x: f"float _{x}", svars))}) : {", ".join(map(lambda x: f"{x}(_{x})", svars))} {{}}'
return f'{sname}({", ".join(map(lambda x: f"CKFLOAT _{x}", svars))}) : {", ".join(map(lambda x: f"{x}(_{x})", svars))} {{}}'
def GetTmplCopyCtor(sname: str, svars: tuple[str]) -> str:
return f'{sname}(const {sname}& rhs) : {", ".join(map(lambda x: f"{x}(rhs.{x})", svars))} {{}}'
@ -30,7 +30,7 @@ def GetTmplOperAssignMove(sname: str, svars: tuple[str]) -> str:
def GetTmplOperOffset(sname: str, svars: tuple[str]) -> str:
sp: str = '\n\t\t\t'
return f"""\tfloat& operator[](size_t i) {{
return f"""\tCKFLOAT& operator[](size_t i) {{
\t\tswitch (i) {{
\t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))}
\t\t\tdefault: return {svars[0]};
@ -49,25 +49,25 @@ def GetTmplOperAddMinus(sname: str, svars: tuple[str], oper: str) -> str:
def GetTmplOperMul(sname: str, svars: tuple[str]) -> str:
sp: str = '\n\t\t'
return f"""\t{sname}& operator*=(float rhs) {{
return f"""\t{sname}& operator*=(CKFLOAT rhs) {{
\t\t{sp.join(map(lambda x: f'{x} *= rhs;', svars))}
\t\treturn *this;
\t}}
\tfriend {sname} operator*(const {sname}& lhs, float rhs) {{
\tfriend {sname} operator*(const {sname}& lhs, CKFLOAT rhs) {{
\t\treturn {sname}({', '.join(map(lambda x: f'lhs.{x} * rhs', svars))});
\t}}
\tfriend {sname} operator*(float lhs, const {sname}& rhs) {{
\tfriend {sname} operator*(CKFLOAT lhs, const {sname}& rhs) {{
\t\treturn {sname}({', '.join(map(lambda x: f'lhs * rhs.{x}', svars))});
\t}}"""
def GetTmplOperDiv(sname: str, svars: tuple[str]) -> str:
sp: str = '\n\t\t'
return f"""\t{sname}& operator/=(float rhs) {{
return f"""\t{sname}& operator/=(CKFLOAT rhs) {{
\t\tif (rhs == 0.0f) return *this;
\t\t{sp.join(map(lambda x: f'{x} /= rhs;', svars))}
\t\treturn *this;
\t}}
\tfriend {sname} operator/(const {sname}& lhs, float rhs) {{
\tfriend {sname} operator/(const {sname}& lhs, CKFLOAT rhs) {{
\t\tif (rhs == 0.0f) return {sname}({', '.join(map(lambda x: '0.0f', range(len(svars))))});
\t\treturn {sname}({', '.join(map(lambda x: f'lhs.{x} / rhs', svars))});
\t}}"""

View File

@ -220,7 +220,7 @@ namespace LibCmo::CK2 {
// read string in detail
// and try load not loaded image.
for (CKDWORD i = 0; i < slotcount; ++i) {
std::string filename;
XContainer::XString filename;
chunk->ReadString(filename);
if (filename.empty()) continue;
@ -298,7 +298,7 @@ namespace LibCmo::CK2 {
if (slot >= m_Slots.size()) return false;
// get extension of file. then get corresponding reader
std::string ext(filename);
XContainer::XString ext(filename);
m_Context->GetPathManager()->GetExtension(ext);
auto reader = DataHandlers::CKBitmapHandler::GetBitmapHandlerWrapper(CKFileExtension(ext.c_str()), CKGUID());
if (reader == nullptr) return false;
@ -320,7 +320,7 @@ namespace LibCmo::CK2 {
if (isForceThisFmt) {
savefmt = this->m_SaveProperties;
} else {
std::string ext(filename);
XContainer::XString ext(filename);
m_Context->GetPathManager()->GetExtension(ext);
if (ext.empty()) {
// fallback to this fmt

View File

@ -3,7 +3,6 @@
#include "MgrImpls/CKBaseManager.hpp"
#include "MgrImpls/CKObjectManager.hpp"
#include "MgrImpls/CKPathManager.hpp"
#include "../XContainer/XBitArray.hpp"
#include <cstdarg>
namespace LibCmo::CK2 {
@ -262,7 +261,7 @@ namespace LibCmo::CK2 {
va_list argptr;
va_start(argptr, fmt);
std::string result;
XContainer::XString result;
int count = std::vsnprintf(nullptr, 0, fmt, argptr);
result.resize(count);
int write_result = std::vsnprintf(result.data(), count, fmt, argptr);
@ -282,7 +281,7 @@ namespace LibCmo::CK2 {
#pragma region Encoding utilities
void CKContext::GetUtf8String(const std::string& native_name, std::string& u8_name) {
void CKContext::GetUtf8String(const XContainer::XString& native_name, XContainer::XString& u8_name) {
bool success = false;
for (const auto& token : this->m_NameEncoding) {
success = LibCmo::EncodingHelper::GetUtf8VirtoolsName(native_name, u8_name, token);
@ -296,7 +295,7 @@ namespace LibCmo::CK2 {
}
}
void CKContext::GetNativeString(const std::string& u8_name, std::string& native_name) {
void CKContext::GetNativeString(const XContainer::XString& u8_name, XContainer::XString& native_name) {
bool success = false;
for (const auto& token : this->m_NameEncoding) {
success = LibCmo::EncodingHelper::GetNativeVirtoolsName(u8_name, native_name, token);
@ -310,7 +309,7 @@ namespace LibCmo::CK2 {
}
}
void CKContext::SetEncoding(const std::vector<std::string> encoding_series) {
void CKContext::SetEncoding(const XContainer::XArray<XContainer::XString> encoding_series) {
// free all current series
for (const auto& encoding : this->m_NameEncoding) {
LibCmo::EncodingHelper::DestroyEncodingToken(encoding);

View File

@ -100,9 +100,9 @@ namespace LibCmo::CK2 {
// ========== Encoding utilities ==========
public:
void GetUtf8String(const std::string& native_name, std::string& u8_name);
void GetNativeString(const std::string& u8_name, std::string& native_name);
void SetEncoding(const std::vector<std::string> encoding_series);
void GetUtf8String(const XContainer::XString& native_name, XContainer::XString& u8_name);
void GetNativeString(const XContainer::XString& u8_name, XContainer::XString& native_name);
void SetEncoding(const XContainer::XArray<XContainer::XString> encoding_series);
protected:
std::vector<EncodingHelper::ENCODING_TOKEN> m_NameEncoding;

View File

@ -1,15 +1,52 @@
#pragma once
#include "../VTUtils.hpp"
#include "CKTypes.hpp"
#include "../XContainer/XTypes.hpp"
#include <string>
#include <vector>
#include <cstring>
#include <cinttypes>
#include <functional>
#include "CKGlobals.hpp"
namespace LibCmo::CK2 {
#pragma region Preregistred Managers
// Virtools Managers GUID second data is 0
constexpr const CKDWORD OBJECT_MANAGER_GUID1 = 0x7cbb3b91;
constexpr const CKDWORD ATTRIBUTE_MANAGER_GUID1 = 0x3d242466;
constexpr const CKDWORD MESSAGE_MANAGER_GUID1 = 0x466a0fac;
constexpr const CKDWORD FLOOR_MANAGER_GUID1 = 0x420936f9;
constexpr const CKDWORD COLLISION_MANAGER_GUID1 = 0x38244712;
constexpr const CKDWORD GRID_MANAGER_GUID1 = 0x7f004791;
constexpr const CKDWORD TIME_MANAGER_GUID1 = 0x89ce7b32;
constexpr const CKDWORD BEHAVIOR_MANAGER_GUID1 = 0x58d621ae;
constexpr const CKDWORD INPUT_MANAGER_GUID1 = 0xf787c904;
constexpr const CKDWORD SOUND_MANAGER_GUID1 = 0xdce135f6;
constexpr const CKDWORD MIDI_MANAGER_GUID1 = 0x594154a6;
constexpr const CKDWORD INTERFACE_MANAGER_GUID1 = 0x9a4b8e3d;
constexpr const CKDWORD RENDER_MANAGER_GUID1 = 0xa213c8d5;
constexpr const CKDWORD PARAMETER_MANAGER_GUID1 = 0x9ce57ab6;
constexpr const CKDWORD PATH_MANAGER_GUID1 = 0x15fd54b9;
constexpr const CKDWORD VARIABLE_MANAGER_GUID1 = 0x98cc3cc9;
constexpr const CKGUID OBJECT_MANAGER_GUID{ OBJECT_MANAGER_GUID1 ,0 };
constexpr const CKGUID ATTRIBUTE_MANAGER_GUID{ ATTRIBUTE_MANAGER_GUID1, 0 };
constexpr const CKGUID MESSAGE_MANAGER_GUID{ MESSAGE_MANAGER_GUID1 ,0 };
constexpr const CKGUID TIME_MANAGER_GUID{ TIME_MANAGER_GUID1 ,0 };
constexpr const CKGUID SOUND_MANAGER_GUID{ SOUND_MANAGER_GUID1 ,0 };
constexpr const CKGUID MIDI_MANAGER_GUID{ MIDI_MANAGER_GUID1 ,0 };
constexpr const CKGUID INPUT_MANAGER_GUID{ INPUT_MANAGER_GUID1 ,0 };
constexpr const CKGUID BEHAVIOR_MANAGER_GUID{ BEHAVIOR_MANAGER_GUID1 ,0 };
constexpr const CKGUID FLOOR_MANAGER_GUID{ FLOOR_MANAGER_GUID1 ,0 };
constexpr const CKGUID COLLISION_MANAGER_GUID{ COLLISION_MANAGER_GUID1 ,0 };
constexpr const CKGUID GRID_MANAGER_GUID{ GRID_MANAGER_GUID1 ,0 };
constexpr const CKGUID INTERFACE_MANAGER_GUID{ INTERFACE_MANAGER_GUID1 ,0 };
constexpr const CKGUID RENDER_MANAGER_GUID{ RENDER_MANAGER_GUID1 ,0 };
constexpr const CKGUID PARAMETER_MANAGER_GUID{ PARAMETER_MANAGER_GUID1 ,0 };
constexpr const CKGUID PATH_MANAGER_GUID{ PATH_MANAGER_GUID1 ,0 };
constexpr const CKGUID VARIABLE_MANAGER_GUID{ VARIABLE_MANAGER_GUID1 ,0 };
#pragma endregion
#pragma region Misc Constant
/**
* @brief The identifier of Virtools file.
*/
@ -25,53 +62,83 @@ namespace LibCmo::CK2 {
constexpr const CKDWORD DEVVERSION = 0u;
constexpr const CKGUID VIRTOOLS_GUID = CKGUID(0x56495254u, 0x4f4f4c53u);
// ========== Class registration utilities ==========
#pragma endregion
//using CKClassRegisterFct = std::function<void()>;
using CKClassCreationFct = std::function<ObjImpls::CKObject* (CKContext*, CK_ID, CKSTRING)>;
using CKClassReleaseFct = std::function<void(CKContext*, ObjImpls::CKObject*)>;
using CKClassNameFct = std::function<CKSTRING()>;
//using CKClassDependenciesFct = std::function<CKSTRING(CKINT, CKINT)>;
//using CKClassDependenciesCountFct = std::function<CKINT(CKINT)>;
#pragma region Common Used Struct
// a stupid forward decl to remove something
/**
* @brief Storage class for filename extensions
*/
class CKFileExtension {
public:
CKFileExtension() : m_Data() {
std::memset(m_Data, 0, c_DataLen);
}
CKFileExtension(CKSTRING s) : CKFileExtension() {
SetExt(s);
}
CKFileExtension(const CKFileExtension& rhs) : CKFileExtension() {
std::memcpy(m_Data, rhs.m_Data, c_DataLen);
}
CKFileExtension(CKFileExtension&& rhs) : CKFileExtension() {
std::memmove(m_Data, rhs.m_Data, c_DataLen);
std::memset(rhs.m_Data, 0, c_DataLen);
}
CKFileExtension& operator=(const CKFileExtension& rhs) {
std::memcpy(m_Data, rhs.m_Data, c_DataLen);
return *this;
}
CKFileExtension& operator=(CKFileExtension&& rhs) {
std::memmove(m_Data, rhs.m_Data, c_DataLen);
std::memset(rhs.m_Data, 0, c_DataLen);
return *this;
}
struct CKClassDesc {
bool IsValid; /**< True if this CKClassDesc is a valid one. Because CK_CLASSID may not be consecutive. */
bool 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...)
void SetExt(CKSTRING s) {
if (s == nullptr) {
m_Data[0] = '\0';
} else {
if (s[0] == '.') ++s; // skip dot
size_t len = std::strlen(s);
if (len > (c_DataLen - 1)) len = c_DataLen - 1;
std::memcpy(m_Data, s, len);
}
}
//// 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
CKSTRING GetExt() const {
return m_Data;
}
// 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)
bool operator==(const CKFileExtension& rhs) const {
return CKStrEqualI(m_Data, rhs.m_Data);
}
CKClassDesc() :
IsValid(false),
Done(false),
Self(CK_CLASSID::CKCID_OBJECT), Parent(CK_CLASSID::CKCID_OBJECT),
CreationFct(nullptr), ReleaseFct(nullptr), NameFct(nullptr),
DerivationLevel(0),
Parents(), Children()
{}
LIBCMO_DEFAULT_COPY_MOVE(CKClassDesc);
protected:
static constexpr size_t c_DataLen = 4u;
CKCHAR m_Data[c_DataLen];
};
/**
* The struct describe the bitmap handler's infomation,
* including its GUID and supported file extension.
* This struct also will store some parameters related to bitmap handler,
* such as jpeg compress level and etc. But currently there are no
* such parameters.
*/
class CKBitmapProperties {
public:
CKBitmapProperties() :
m_ReaderGuid(), m_Ext() {}
CKBitmapProperties(const CKGUID& guid, CKSTRING ext) :
m_ReaderGuid(guid), m_Ext(ext) {}
LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties);
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 */
};
#pragma endregion
}

View File

@ -7,46 +7,6 @@
namespace LibCmo::CK2 {
#pragma region Preregistred Managers
// Virtools Managers GUID second data is 0
constexpr const CKDWORD OBJECT_MANAGER_GUID1 = 0x7cbb3b91;
constexpr const CKDWORD ATTRIBUTE_MANAGER_GUID1 = 0x3d242466;
constexpr const CKDWORD MESSAGE_MANAGER_GUID1 = 0x466a0fac;
constexpr const CKDWORD FLOOR_MANAGER_GUID1 = 0x420936f9;
constexpr const CKDWORD COLLISION_MANAGER_GUID1 = 0x38244712;
constexpr const CKDWORD GRID_MANAGER_GUID1 = 0x7f004791;
constexpr const CKDWORD TIME_MANAGER_GUID1 = 0x89ce7b32;
constexpr const CKDWORD BEHAVIOR_MANAGER_GUID1 = 0x58d621ae;
constexpr const CKDWORD INPUT_MANAGER_GUID1 = 0xf787c904;
constexpr const CKDWORD SOUND_MANAGER_GUID1 = 0xdce135f6;
constexpr const CKDWORD MIDI_MANAGER_GUID1 = 0x594154a6;
constexpr const CKDWORD INTERFACE_MANAGER_GUID1 = 0x9a4b8e3d;
constexpr const CKDWORD RENDER_MANAGER_GUID1 = 0xa213c8d5;
constexpr const CKDWORD PARAMETER_MANAGER_GUID1 = 0x9ce57ab6;
constexpr const CKDWORD PATH_MANAGER_GUID1 = 0x15fd54b9;
constexpr const CKDWORD VARIABLE_MANAGER_GUID1 = 0x98cc3cc9;
constexpr const CKGUID OBJECT_MANAGER_GUID{ OBJECT_MANAGER_GUID1 ,0 };
constexpr const CKGUID ATTRIBUTE_MANAGER_GUID{ ATTRIBUTE_MANAGER_GUID1, 0 };
constexpr const CKGUID MESSAGE_MANAGER_GUID{ MESSAGE_MANAGER_GUID1 ,0 };
constexpr const CKGUID TIME_MANAGER_GUID{ TIME_MANAGER_GUID1 ,0 };
constexpr const CKGUID SOUND_MANAGER_GUID{ SOUND_MANAGER_GUID1 ,0 };
constexpr const CKGUID MIDI_MANAGER_GUID{ MIDI_MANAGER_GUID1 ,0 };
constexpr const CKGUID INPUT_MANAGER_GUID{ INPUT_MANAGER_GUID1 ,0 };
constexpr const CKGUID BEHAVIOR_MANAGER_GUID{ BEHAVIOR_MANAGER_GUID1 ,0 };
constexpr const CKGUID FLOOR_MANAGER_GUID{ FLOOR_MANAGER_GUID1 ,0 };
constexpr const CKGUID COLLISION_MANAGER_GUID{ COLLISION_MANAGER_GUID1 ,0 };
constexpr const CKGUID GRID_MANAGER_GUID{ GRID_MANAGER_GUID1 ,0 };
constexpr const CKGUID INTERFACE_MANAGER_GUID{ INTERFACE_MANAGER_GUID1 ,0 };
constexpr const CKGUID RENDER_MANAGER_GUID{ RENDER_MANAGER_GUID1 ,0 };
constexpr const CKGUID PARAMETER_MANAGER_GUID{ PARAMETER_MANAGER_GUID1 ,0 };
constexpr const CKGUID PATH_MANAGER_GUID{ PATH_MANAGER_GUID1 ,0 };
constexpr const CKGUID VARIABLE_MANAGER_GUID{ VARIABLE_MANAGER_GUID1 ,0 };
#pragma endregion
/**
Specify the way files are saved to disk (compression)
@remark
@ -57,7 +17,7 @@ namespace LibCmo::CK2 {
@see CKContext::SetFileWriteMode, CKContext::GetFileWriteMode, CKContext::SetCompressionLevel,
CKContext::SetGlobalImagesSaveOptions, CKContext::SetGlobalSoundsSaveOptions
*/
enum class CK_FILE_WRITEMODE : uint32_t {
enum class CK_FILE_WRITEMODE : CKDWORD {
CKFILE_UNCOMPRESSED = 0, /**< Save data uncompressed */
CKFILE_CHUNKCOMPRESSED_OLD = 1, /**< Obsolete */
CKFILE_EXTERNALTEXTURES_OLD = 2, /**< Obsolete : use CKContext::SetGlobalImagesSaveOptions instead. */
@ -75,7 +35,7 @@ namespace LibCmo::CK2 {
created CKObjects should be created as dynamic (See also Dynamic Objects)
See also : CKContext::Load, CKContext::CKSave
*/
enum class CK_LOAD_FLAGS : uint32_t {
enum class CK_LOAD_FLAGS : CKDWORD {
CK_LOAD_ANIMATION = 1 << 0, /**< Load animations */
CK_LOAD_GEOMETRY = 1 << 1, /**< Load geometry. */
CK_LOAD_DEFAULT = CK_LOAD_GEOMETRY | CK_LOAD_ANIMATION, /**< Load animations & geometry */
@ -90,7 +50,7 @@ namespace LibCmo::CK2 {
/**
Options that will be used to create this object...
*/
enum class CK_FO_OPTIONS : uint32_t {
enum class CK_FO_OPTIONS : CKDWORD {
CK_FO_DEFAULT = 0, /**< Default behavior : a new object will be created with the name stored in CKFileObject */
CK_FO_RENAMEOBJECT, /**< Renaming : a new object will be created with the name stored in CKFileObject + a integer value XXX to ensure its uniqueness */
CK_FO_REPLACEOBJECT, /**< Do not create a new object, instead use an existing one which CK_ID is given by CreatedObject to load the chunk on */
@ -99,7 +59,7 @@ namespace LibCmo::CK2 {
/**
@brief Specify the way an object just loaded should be handled when it already exists in the level.
*/
enum class CK_LOADMODE : int32_t {
enum class CK_LOADMODE : CKINT {
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) */
@ -115,7 +75,7 @@ namespace LibCmo::CK2 {
dynamic.
@see CKContext::CreateObject
*/
enum class CK_OBJECTCREATION_OPTIONS : uint32_t {
enum class CK_OBJECTCREATION_OPTIONS : CKDWORD {
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 */
@ -135,7 +95,7 @@ namespace LibCmo::CK2 {
@see CKPluginManager
*/
enum class CK_PLUGIN_TYPE : uint32_t {
enum class CK_PLUGIN_TYPE : CKDWORD {
CKPLUGIN_BITMAP_READER = 0, /**< The plugin is bitmap (textures,sprites) loader */
CKPLUGIN_SOUND_READER = 1, /**< Sound Reader Plugin */
CKPLUGIN_MODEL_READER = 2, /**< 3D Model Reader */
@ -148,7 +108,7 @@ namespace LibCmo::CK2 {
/**
@remark CHUNK_OPTIONS in original Virtools header.
*/
enum class CK_STATECHUNK_CHUNKOPTIONS : uint32_t {
enum class CK_STATECHUNK_CHUNKOPTIONS : CKDWORD {
CHNK_OPTION_IDS = 0x01, /**< IDS are stored inside chunk */
CHNK_OPTION_MAN = 0x02, /**< Managers ints are store inside chunk */
CHNK_OPTION_CHN = 0x04, /**< Sub chunk are stored inside chunk */
@ -158,14 +118,14 @@ 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_PARSER = 0x80, /**< m_Parser Ptr is not owned by CKStateChunk , it must not be deleted... */
};
enum class CK_STATECHUNK_CHUNKVERSION : uint32_t {
enum class CK_STATECHUNK_CHUNKVERSION : CKDWORD {
CHUNK_VERSIONBASE = 0,
CHUNK_VERSION1 = 4, /**< equal to file version : WriteObjectID => table */
CHUNK_VERSION2 = 5, /**< add Manager Data */
CHUNK_VERSION3 = 6, /**< New ConvertToBuffer / ReadFromBuffer (file system changed to reflect this ) */
CHUNK_VERSION4 = 7, /**< New WriteObjectID when saving to a file */
};
enum class CK_STATECHUNK_DATAVERSION : uint32_t {
enum class CK_STATECHUNK_DATAVERSION : CKDWORD {
CHUNKDATA_OLDVERSION = 0, /**< Before any version was saved */
CHUNKDATA_BASEVERSION = 1, /**< First version */
CHUNK_WAVESOUND_VERSION2 = 2, /**< Changes in wavesound format */
@ -188,7 +148,7 @@ namespace LibCmo::CK2 {
you should always use the specific acces function (given between ()) which may need to perform additionnal operations.
@see CKObject, CKObject::GetObjectFlags, CKObject::ModifyObjectFlags
*/
enum class CK_OBJECT_FLAGS : uint32_t {
enum class CK_OBJECT_FLAGS : CKDWORD {
CK_OBJECT_INTERFACEOBJ = 0x00000001, /**< Reserved for Inteface Use */
CK_OBJECT_PRIVATE = 0x00000002, /**< The object must not be displayed in interface (Lists,Level view,etc...),nor should it be saved. (CKObject::IsPrivate() */
CK_OBJECT_INTERFACEMARK = 0x00000004,
@ -230,7 +190,7 @@ namespace LibCmo::CK2 {
+ Flags give user and engine more information about the 3dEntity.
@see CK3dEntity::SetFlags,CK3dEntity::GetFlags
*/
enum class CK_3DENTITY_FLAGS : uint32_t {
enum class CK_3DENTITY_FLAGS : CKDWORD {
CK_3DENTITY_DUMMY = 0x00000001, /**< Entity is a dummy used to represent a position */
CK_3DENTITY_FRAME = 0x00000002, /**< Entity is a frame used to represent an orientation */
CK_3DENTITY_RESERVED0 = 0x00000020, /**< Obsolete Flag */
@ -258,7 +218,7 @@ namespace LibCmo::CK2 {
+ These options can be used for a specific texture (or sprite) or as a global setting.
See also: CKBitmapData::SetSaveOptions,CKSprite::SetSaveOptions,CKContext::SetGlobalImagesSaveOptions
*/
enum class CK_TEXTURE_SAVEOPTIONS : uint32_t {
enum class CK_TEXTURE_SAVEOPTIONS : CKDWORD {
CKTEXTURE_RAWDATA = 0, /**< Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format. */
CKTEXTURE_EXTERNAL = 1, /**< Store only the file name for the texture. The bitmap file must be present in the bitmap paths when loading the composition. */
CKTEXTURE_IMAGEFORMAT = 2, /**< Save using format specified. The bitmap data will be converted to the specified format by the correspondant bitmap plugin and saved inside file. */
@ -275,13 +235,13 @@ namespace LibCmo::CK2 {
+ These options can be used for a specific sound or as a global setting.
See also: CKSound::SetSaveOptions,CKContext::SetGlobalSoundSaveOptions
*/
enum class CK_SOUND_SAVEOPTIONS : uint32_t {
enum class CK_SOUND_SAVEOPTIONS : CKDWORD {
CKSOUND_EXTERNAL = 0, /**< Store only the file name for the sound. The sound file must be present in one of the sound paths when the composition is loaded. */
CKSOUND_INCLUDEORIGINALFILE = 1, /**< Insert original sound file inside the CMO file. The sound file that was used originally will be append to the composition file and extracted when the file is loaded. */
CKSOUND_USEGLOBAL = 2, /**< Use Global settings. This flag is only valid for the CKSound::SetSaveOptions method. */
};
enum class CK_BITMAPDATA_FLAGS : uint32_t {
enum class CK_BITMAPDATA_FLAGS : CKDWORD {
CKBITMAPDATA_INVALID = 1,
CKBITMAPDATA_TRANSPARENT = 2,
CKBITMAPDATA_FORCERESTORE = 4,

View File

@ -3,8 +3,8 @@
#include "../VTAll.hpp"
namespace LibCmo::XContainer {
using XIntArray = XArray<CK2::CKINT>;
using XFileObjectsTable = XHashTable<CK2::CK_ID, CK2::CKINT>;
using XIntArray = XArray<CKINT>;
using XFileObjectsTable = XHashTable<CK2::CK_ID, CKINT>;
}
namespace LibCmo::CK2 {
@ -120,7 +120,7 @@ namespace LibCmo::CK2 {
CK_ID CreatedObjectId; /**< ID of the object being created */
CK_CLASSID ObjectCid; /**< Class Identifier of the object */
ObjImpls::CKObject* ObjPtr; /**< A pointer to the object itself (as CreatedObject when loading) */
TypeHelper::MKString Name; /**< Name of the Object */
XContainer::XString Name; /**< Name of the Object */
CKStateChunk* Data; /**< A CKStateChunk that contains object information */
CKDWORD PackSize; /**< The CKStateChunk data size */
//CKINT PostPackSize; /**< When compressed chunk by chunk : size of Data after compression */

View File

@ -42,7 +42,7 @@ namespace LibCmo::CK2 {
std::unique_ptr<CKBufferParser> parser(new CKBufferParser(ParserPtr->GetBase(), ParserPtr->GetSize(), false));
parser->SetCursor(ParserPtr->GetCursor());
std::string name_conv, name_dest;
XContainer::XString name_conv;
// ========== read header ==========
// check header size
@ -129,8 +129,9 @@ namespace LibCmo::CK2 {
if (namelen != 0) {
name_conv.resize(namelen);
parser->Read(name_conv.data(), namelen);
m_Ctx->GetUtf8String(name_conv, name_dest);
fileobj.Name = name_dest;
m_Ctx->GetUtf8String(name_conv, fileobj.Name);
} else {
fileobj.Name.clear();
}
}
}
@ -196,7 +197,7 @@ namespace LibCmo::CK2 {
std::unique_ptr<CKBufferParser> parser(new CKBufferParser(ParserPtr->GetBase(), ParserPtr->GetSize(), false));
parser->SetCursor(ParserPtr->GetCursor());
std::string name_conv;
XContainer::XString name_conv;
// ========== compress feature process ==========
if (EnumsHelper::Has(this->m_FileInfo.FileWriteMode, CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD) ||
@ -314,7 +315,7 @@ namespace LibCmo::CK2 {
parser->Read(&filebodylen, sizeof(CKDWORD));
// read file body
std::string tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(file.c_str());
XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(file.c_str());
FILE* fp = EncodingHelper::U8FOpen(tempfilename.c_str(), "wb");
if (fp != nullptr) {
std::fwrite(parser->GetPtr(), sizeof(char), filebodylen, fp);
@ -349,7 +350,7 @@ namespace LibCmo::CK2 {
if (obj.Data == nullptr) continue;
// create object and assign created obj ckid
obj.ObjPtr = m_Ctx->CreateObject(obj.ObjectCid, obj.Name.toCKSTRING());
obj.ObjPtr = m_Ctx->CreateObject(obj.ObjectCid, XContainer::NSXString::ToCKSTRING(obj.Name));
if (obj.ObjPtr == nullptr) {
obj.CreatedObjectId = 0u;
} else {

View File

@ -14,7 +14,7 @@ namespace LibCmo::CK2 {
if (this->m_Done) CKERROR::CKERR_CANCELLED;
// encoding conv helper
std::string name_conv;
XContainer::XString name_conv;
// try detect filename legality
CKERROR err = PrepareFile(u8_filename);
@ -90,9 +90,9 @@ namespace LibCmo::CK2 {
for (auto& obj : m_FileObjects) {
// += 4DWORD(ObjId, ObjCid, FileIndex, NameLen)
sumHdrObjSize += 4 * CKSizeof(CKDWORD);
if (obj.Name.toCKSTRING() != nullptr) {
if (XContainer::NSXString::ToCKSTRING(obj.Name) != nullptr) {
// += Name size
m_Ctx->GetNativeString(obj.Name.toString(), name_conv);
m_Ctx->GetNativeString(obj.Name, name_conv);
sumHdrObjSize += static_cast<CKDWORD>(name_conv.size());
}
@ -177,8 +177,8 @@ namespace LibCmo::CK2 {
hdrparser->Write(&obj.ObjectCid, sizeof(CK_CLASSID));
hdrparser->Write(&obj.FileIndex, sizeof(CKDWORD));
if (obj.Name.toCKSTRING() != nullptr) {
m_Ctx->GetNativeString(obj.Name.toString(), name_conv);
if (XContainer::NSXString::ToCKSTRING(obj.Name) != nullptr) {
m_Ctx->GetNativeString(obj.Name, name_conv);
CKDWORD namelen = static_cast<CKDWORD>(name_conv.size());
hdrparser->Write(&namelen, sizeof(CKDWORD));
hdrparser->Write(name_conv.data(), namelen);
@ -316,7 +316,7 @@ namespace LibCmo::CK2 {
std::fwrite(name_conv.data(), sizeof(char), filenamelen, fs);
// try mapping file.
std::string tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(fentry.c_str());
XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(fentry.c_str());
std::unique_ptr<VxMath::VxMemoryMappedFile> mappedFile(new VxMath::VxMemoryMappedFile(tempfilename.c_str()));
if (mappedFile->IsValid()) {
// write file length

View File

@ -3,13 +3,12 @@
#define ZLIB_WINAPI
#endif
#include <zconf.h>
#include "../VTEncoding.hpp"
#include "CKGlobals.hpp"
#include <map>
#include <algorithm>
#include <zlib.h>
#include "CKGlobals.hpp"
#include <algorithm>
#include "ObjImpls/CKObject.hpp"
#include "ObjImpls/CKSceneObject.hpp"
#include "ObjImpls/CKBeObject.hpp"
@ -277,35 +276,6 @@ CKClassRegister(cid, parentCid, \
#undef EasyClassReg
/*
// 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); })},
}
*/
CKBuildClassHierarchyTable();
return CKERROR::CKERR_OK;

View File

@ -1,6 +1,8 @@
#pragma once
#include "CKDefines.hpp"
#include "CKTypes.hpp"
#include "../XContainer/XTypes.hpp"
#include <functional>
namespace LibCmo::CK2 {
@ -70,12 +72,54 @@ namespace LibCmo::CK2 {
*/
bool CKStrEmpty(CKSTRING strl);
// ========== Numberic Utilities ==========
// ========== Class registration utilities ==========
/*
The convenient sizeof which return CKDWORD, not size_t.
*/
#define CKSizeof(_Ty) (static_cast<LibCmo::CK2::CKDWORD>(sizeof(_Ty)))
//using CKClassRegisterFct = std::function<void()>;
using CKClassCreationFct = std::function<ObjImpls::CKObject* (CKContext*, CK_ID, CKSTRING)>;
using CKClassReleaseFct = std::function<void(CKContext*, ObjImpls::CKObject*)>;
using CKClassNameFct = std::function<CKSTRING()>;
//using CKClassDependenciesFct = std::function<CKSTRING(CKINT, CKINT)>;
//using CKClassDependenciesCountFct = std::function<CKINT(CKINT)>;
struct CKClassDesc {
bool IsValid; /**< True if this CKClassDesc is a valid one. Because CK_CLASSID may not be consecutive. */
bool 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() :
IsValid(false),
Done(false),
Self(CK_CLASSID::CKCID_OBJECT), Parent(CK_CLASSID::CKCID_OBJECT),
CreationFct(nullptr), ReleaseFct(nullptr), NameFct(nullptr),
DerivationLevel(0),
Parents(), Children()
{}
LIBCMO_DEFAULT_COPY_MOVE(CKClassDesc);
};
// ========== CKClass Registration ==========

View File

@ -15,7 +15,7 @@ namespace LibCmo::CK2 {
/**
Object
*/
enum class CK_STATESAVEFLAGS_OBJECT : uint32_t {
enum class CK_STATESAVEFLAGS_OBJECT : CKDWORD {
CK_STATESAVE_NAME = 0x00000001, /**< Obsolete */
CK_STATESAVE_ID = 0x00000002, /**< Obsolete */
CK_STATESAVE_OBJECTHIDDEN = 0x00000004, /**< The object is hidden */
@ -25,7 +25,7 @@ namespace LibCmo::CK2 {
/**
Be Object
*/
enum class CK_STATESAVEFLAGS_BEOBJECT : uint32_t {
enum class CK_STATESAVEFLAGS_BEOBJECT : CKDWORD {
CK_STATESAVE_ATTRIBUTES = 0x00000010, /**< Obsolete */
CK_STATESAVE_NEWATTRIBUTES = 0x00000011, /**< Save Attributes */
CK_STATESAVE_GROUPS = 0x00000020, /**< Obsolete */
@ -41,7 +41,7 @@ namespace LibCmo::CK2 {
/**
3dEntity
*/
enum class CK_STATESAVEFLAGS_3DENTITY : uint32_t {
enum class CK_STATESAVEFLAGS_3DENTITY : CKDWORD {
CK_STATESAVE_3DENTITYSKINDATANORMALS = 0x00001000, /**< Save Skin normals */
CK_STATESAVE_ANIMATION = 0x00002000, /**< Obsolete */
CK_STATESAVE_MESHS = 0x00004000, /**< Save List of mesh */
@ -58,7 +58,7 @@ namespace LibCmo::CK2 {
/**
Light
*/
enum class CK_STATESAVEFLAGS_LIGHT : uint32_t {
enum class CK_STATESAVEFLAGS_LIGHT : CKDWORD {
CK_STATESAVE_LIGHTDATA = 0x00400000, /**< Save Color,Type,Attenuation,Range and cone */
CK_STATESAVE_LIGHTDATA2 = 0x00800000, /**< Reserved for future use */
CK_STATESAVE_LIGHTRESERVED1 = 0x01000000, /**< Reserved for future use */
@ -77,7 +77,7 @@ namespace LibCmo::CK2 {
/**
Camera
*/
enum class CK_STATESAVEFLAGS_CAMERA : uint32_t {
enum class CK_STATESAVEFLAGS_CAMERA : CKDWORD {
CK_STATESAVE_CAMERAFOV = 0x00400000, /**< Save Camera Field of View */
CK_STATESAVE_CAMERAPROJTYPE = 0x00800000, /**< Save Camera projection type */
CK_STATESAVE_CAMERAOTHOZOOM = 0x01000000, /**< Save Camera orhographic zoom */
@ -95,7 +95,7 @@ namespace LibCmo::CK2 {
/**
Sprite3D
*/
enum class CK_STATESAVEFLAGS_SPRITE3D : uint32_t {
enum class CK_STATESAVEFLAGS_SPRITE3D : CKDWORD {
CK_STATESAVE_SPRITE3DDATA = 0x00400000, /**< Save offset,mapping,size and material */
CK_STATESAVE_SPRITE3DRESERVED0 = 0x00800000, /**< Reserved for future use */
CK_STATESAVE_SPRITE3DRESERVED1 = 0x01000000, /**< Reserved for future use */
@ -108,7 +108,7 @@ namespace LibCmo::CK2 {
/**
Object 3D
*/
enum class CK_STATESAVEFLAGS_3DOBJECT : uint32_t {
enum class CK_STATESAVEFLAGS_3DOBJECT : CKDWORD {
CK_STATESAVE_3DOBJECTATTRIBUTES = 0x00400000, /**< Obsolete */
CK_STATESAVE_3DOBJECTRESERVED = 0x00800000, /**< Reserved for future use */
CK_STATESAVE_3DOBJECTRONLY = 0x00C00000, /**< Save only 3dObject specific datas */
@ -117,7 +117,7 @@ namespace LibCmo::CK2 {
/**
BodyPart
*/
enum class CK_STATESAVEFLAGS_BODYPART : uint32_t {
enum class CK_STATESAVEFLAGS_BODYPART : CKDWORD {
CK_STATESAVE_BODYPARTROTJOINT = 0x01000000, /**< Save rotation joint data */
CK_STATESAVE_BODYPARTPOSJOINT = 0x02000000, /**< Save position joint data */
CK_STATESAVE_BODYPARTCHARACTER = 0x04000000, /**< Save character owning this bodypart */
@ -131,7 +131,7 @@ namespace LibCmo::CK2 {
/**
Character
*/
enum class CK_STATESAVEFLAGS_CHARACTER : uint32_t {
enum class CK_STATESAVEFLAGS_CHARACTER : CKDWORD {
CK_STATESAVE_CHARACTERBODYPARTS = 0x00400000, /**< Obsolete */
CK_STATESAVE_CHARACTERKINECHAINS = 0x00800000, /**< Obsolete */
CK_STATESAVE_CHARACTERANIMATIONS = 0x01000000, /**< Obsolete */
@ -148,7 +148,7 @@ namespace LibCmo::CK2 {
/**
CURVE && Curve Point
*/
enum class CK_STATESAVEFLAGS_CURVE : uint32_t {
enum class CK_STATESAVEFLAGS_CURVE : CKDWORD {
CK_STATESAVE_CURVEFITCOEFF = 0x00400000, /**< Save fitting coef */
CK_STATESAVE_CURVECONTROLPOINT = 0x00800000, /**< Save list of control points */
CK_STATESAVE_CURVESTEPS = 0x01000000, /**< Save number of step setting */
@ -166,7 +166,7 @@ namespace LibCmo::CK2 {
/**
2dEntity
*/
enum class CK_STATESAVEFLAGS_2DENTITY : uint32_t {
enum class CK_STATESAVEFLAGS_2DENTITY : CKDWORD {
CK_STATESAVE_2DENTITYSRCSIZE = 0x00001000, /**< Save source size */
CK_STATESAVE_2DENTITYSIZE = 0x00002000, /**< Save size */
CK_STATESAVE_2DENTITYFLAGS = 0x00004000, /**< Save Flags */
@ -180,7 +180,7 @@ namespace LibCmo::CK2 {
/**
Sprite
*/
enum class CK_STATESAVEFLAGS_SPRITE : uint32_t {
enum class CK_STATESAVEFLAGS_SPRITE : CKDWORD {
CK_STATESAVE_SPRITECURRENTIMAGE = 0x00010000, /**< Save current image */
CK_STATESAVE_SPRITETRANSPARENT = 0x00020000, /**< Save transparency settings */
CK_STATESAVE_SPRITEBITMAPS = 0x00040000, /**< Obsolete */
@ -200,7 +200,7 @@ namespace LibCmo::CK2 {
/**
Sprite Text
*/
enum class CK_STATESAVEFLAGS_SPRITETEXT : uint32_t {
enum class CK_STATESAVEFLAGS_SPRITETEXT : CKDWORD {
CK_STATESAVE_SPRITETEXT = 0x01000000, /**< Save text */
CK_STATESAVE_SPRITEFONT = 0x02000000, /**< Save font settings */
CK_STATESAVE_SPRITETEXTCOLOR = 0x04000000, /**< Save text color */
@ -213,7 +213,7 @@ namespace LibCmo::CK2 {
/**
Sound
*/
enum class CK_STATESAVEFLAGS_SOUND : uint32_t {
enum class CK_STATESAVEFLAGS_SOUND : CKDWORD {
CK_STATESAVE_SOUNDFILENAME = 0x00001000, /**< Reserved for future use */
CK_STATESAVE_SOUNDRESERVED1 = 0x00002000, /**< Reserved for future use */
CK_STATESAVE_SOUNDRESERVED2 = 0x00004000, /**< Reserved for future use */
@ -228,7 +228,7 @@ namespace LibCmo::CK2 {
/**
Wave Sound
*/
enum class CK_STATESAVEFLAGS_WAVSOUND : uint32_t {
enum class CK_STATESAVEFLAGS_WAVSOUND : CKDWORD {
CK_STATESAVE_WAVSOUNDFILE = 0x00100000, /**< Save sound filename */
CK_STATESAVE_WAVSOUNDDATA = 0x00200000, /**< Obsolete */
CK_STATESAVE_WAVSOUNDDATA2 = 0x00400000, /**< Save sound properties (3D/2D,pitch,gain,streaming,loop,etc..) */
@ -243,7 +243,7 @@ namespace LibCmo::CK2 {
/**
Wave Sound
*/
enum class CK_STATESAVEFLAGS_MIDISOUND : uint32_t {
enum class CK_STATESAVEFLAGS_MIDISOUND : CKDWORD {
CK_STATESAVE_MIDISOUNDFILE = 0x00100000, /**< Save sound filename */
CK_STATESAVE_MIDISOUNDDATA = 0x00200000, /**< Save midi data */
CK_STATESAVE_MIDISOUNDRESERVED2 = 0x00400000, /**< Reserved for future use */
@ -258,7 +258,7 @@ namespace LibCmo::CK2 {
/**
Place
*/
enum class CK_STATESAVEFLAGS_PLACE : uint32_t {
enum class CK_STATESAVEFLAGS_PLACE : CKDWORD {
CK_STATESAVE_PLACEPORTALS = 0x00001000, /**< Save level using the place */
CK_STATESAVE_PLACECAMERA = 0x00002000, /**< Save attached camera */
CK_STATESAVE_PLACEREFERENCES = 0x00004000, /**< Save list of objects in the place */
@ -268,7 +268,7 @@ namespace LibCmo::CK2 {
/**
Level CKSaveObjectState will not save any data
*/
enum class CK_STATESAVEFLAGS_LEVEL : uint32_t {
enum class CK_STATESAVEFLAGS_LEVEL : CKDWORD {
CK_STATESAVE_LEVELRESERVED0 = 0x00001000, /**< Reserved for future use */
CK_STATESAVE_LEVELINACTIVEMAN = 0x00002000, /**< Reserved for future use */
CK_STATESAVE_LEVELDUPLICATEMAN = 0x00004000, /**< Reserved for future use */
@ -279,7 +279,7 @@ namespace LibCmo::CK2 {
/**
GROUP
*/
enum class CK_STATESAVEFLAGS_GROUP : uint32_t {
enum class CK_STATESAVEFLAGS_GROUP : CKDWORD {
CK_STATESAVE_GROUPDATA = 0x00001000, /**< Save list of objects in the group */
CK_STATESAVE_GROUPRESERVED1 = 0x00002000, /**< Reserved for future use */
CK_STATESAVE_GROUPRESERVED2 = 0x00004000, /**< Reserved for future use */
@ -293,7 +293,7 @@ namespace LibCmo::CK2 {
/**
MESH CKSaveOjectSave will save all data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_MESH : uint32_t {
enum class CK_STATESAVEFLAGS_MESH : CKDWORD {
CK_STATESAVE_MESHRESERVED0 = 0x00001000, /**< Reserved for future use */
CK_STATESAVE_MESHFLAGS = 0x00002000, /**< Save flags */
CK_STATESAVE_MESHCHANNELS = 0x00004000, /**< Save Channels */
@ -312,7 +312,7 @@ namespace LibCmo::CK2 {
/**
PATCH MESH CKSaveOjectSave will save all data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_PATCHMESH : uint32_t {
enum class CK_STATESAVEFLAGS_PATCHMESH : CKDWORD {
CK_STATESAVE_PATCHMESHDATA = 0x00800000, /**< Obsolete */
CK_STATESAVE_PATCHMESHDATA2 = 0x01000000, /**< Obsolete */
CK_STATESAVE_PATCHMESHSMOOTH = 0x02000000, /**< Obsolete */
@ -324,7 +324,7 @@ namespace LibCmo::CK2 {
/**
Material
*/
enum class CK_STATESAVEFLAGS_MATERIAL : uint32_t {
enum class CK_STATESAVEFLAGS_MATERIAL : CKDWORD {
CK_STATESAVE_MATDATA = 0x00001000, /**< Save colors,blending modes,shade modes,fill modes etc... */
CK_STATESAVE_MATDATA2 = 0x00002000, /**< Additional texture objects... */
CK_STATESAVE_MATDATA3 = 0x00004000, /**< Effect Alone */
@ -339,7 +339,7 @@ namespace LibCmo::CK2 {
/**
Texture CKSaveOjectSave will save all relevant data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_TEXTURE : uint32_t {
enum class CK_STATESAVEFLAGS_TEXTURE : CKDWORD {
CK_STATESAVE_TEXAVIFILENAME = 0x00001000, /**< Save movie file name */
CK_STATESAVE_TEXCURRENTIMAGE = 0x00002000, /**< Save current slot */
CK_STATESAVE_TEXBITMAPS = 0x00004000, /**< Obsolete */
@ -359,7 +359,7 @@ namespace LibCmo::CK2 {
/**
2d CURVE && 2d Curve Point
*/
enum class CK_STATESAVEFLAGS_2DCURVE : uint32_t {
enum class CK_STATESAVEFLAGS_2DCURVE : CKDWORD {
CK_STATESAVE_2DCURVERESERVED0 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_2DCURVERESERVED4 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_2DCURVEFITCOEFF = 0x00000040, /**< Obsolete */
@ -380,7 +380,7 @@ namespace LibCmo::CK2 {
/**
Kinematic Chain
*/
enum class CK_STATESAVEFLAGS_KINEMATICCHAIN : uint32_t {
enum class CK_STATESAVEFLAGS_KINEMATICCHAIN : CKDWORD {
CK_STATESAVE_KINEMATICCHAINDATA = 0x00000010, /**< Save chain data */
CK_STATESAVE_KINEMATICCHAINRESERVED1 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_KINEMATICCHAINRESERVED2 = 0x00000040, /**< Reserved for future use */
@ -390,7 +390,7 @@ namespace LibCmo::CK2 {
/**
Animation
*/
enum class CK_STATESAVEFLAGS_ANIMATION : uint32_t {
enum class CK_STATESAVEFLAGS_ANIMATION : CKDWORD {
CK_STATESAVE_ANIMATIONDATA = 0x00000010, /**< Save Flags & Framerate data */
CK_STATESAVE_ANIMATIONRESERVED1 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_ANIMATIONLENGTH = 0x00000040, /**< Save animation Length */
@ -404,7 +404,7 @@ namespace LibCmo::CK2 {
/**
Keyed Anim
*/
enum class CK_STATESAVEFLAGS_KEYEDANIMATION : uint32_t {
enum class CK_STATESAVEFLAGS_KEYEDANIMATION : CKDWORD {
CK_STATESAVE_KEYEDANIMANIMLIST = 0x00001000, /**< Save list of object animations */
CK_STATESAVE_KEYEDANIMLENGTH = 0x00002000, /**< Obsolete */
CK_STATESAVE_KEYEDANIMPOSKEYS = 0x00004000, /**< Obsolete */
@ -423,7 +423,7 @@ namespace LibCmo::CK2 {
/**
Object Animation CKSaveOjectSave will save all relevant data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_OBJECTANIMATION : uint32_t {
enum class CK_STATESAVEFLAGS_OBJECTANIMATION : CKDWORD {
CK_STATESAVE_OBJANIMNEWDATA = 0x00001000, /**< Save all relevant data */
CK_STATESAVE_OBJANIMLENGTH = 0x00002000, /**< Not used */
CK_STATESAVE_OBJANIMPOSKEYS = 0x00004000, /**< Not used */
@ -447,7 +447,7 @@ namespace LibCmo::CK2 {
/**
IK Animation
*/
enum class CK_STATESAVEFLAGS_IKANIMATION : uint32_t {
enum class CK_STATESAVEFLAGS_IKANIMATION : CKDWORD {
CK_STATESAVE_IKANIMATIONDATA = 0x00001000, /**< Save IK data */
CK_STATESAVE_IKANIMATIONRESERVED2 = 0x00002000, /**< Reserved for future use */
CK_STATESAVE_IKANIMATIONRESERVED3 = 0x00004000, /**< Reserved for future use */
@ -462,7 +462,7 @@ namespace LibCmo::CK2 {
/**
BehaviorLink
*/
enum class CK_STATESAVEFLAGS_BEHAV_LINK : uint32_t {
enum class CK_STATESAVEFLAGS_BEHAV_LINK : CKDWORD {
CK_STATESAVE_BEHAV_LINK_CURDELAY = 0x00000004, /**< Obsolete */
CK_STATESAVE_BEHAV_LINK_IOS = 0x00000008, /**< Obsolete */
CK_STATESAVE_BEHAV_LINK_DELAY = 0x00000010, /**< Obsolete */
@ -475,7 +475,7 @@ namespace LibCmo::CK2 {
/**
BehaviorIO
*/
enum class CK_STATESAVEFLAGS_BEHAV_IO : uint32_t {
enum class CK_STATESAVEFLAGS_BEHAV_IO : CKDWORD {
CK_STATESAVE_BEHAV_IOFLAGS = 0x00000008, /**< Save IO flags */
CK_STATESAVE_BEHAV_IORESERVED3 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_BEHAV_IORESERVED4 = 0x00000020, /**< Reserved for future use */
@ -487,7 +487,7 @@ namespace LibCmo::CK2 {
/**
BehaviorPrototype
*/
enum class CK_STATESAVEFLAGS_PROTOTYPE : uint32_t {
enum class CK_STATESAVEFLAGS_PROTOTYPE : CKDWORD {
CK_STATESAVE_PROTORESERVED0 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_PROTORESERVED1 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_PROTOFLAGS = 0x00000040, /**< Save Flags */
@ -509,7 +509,7 @@ namespace LibCmo::CK2 {
/**
Behavior
*/
enum class CK_STATESAVEFLAGS_BEHAVIOR : uint32_t {
enum class CK_STATESAVEFLAGS_BEHAVIOR : CKDWORD {
CK_STATESAVE_BEHAVIORRESERVED0 = 0x00000010, /**< Reserved for internal use */
CK_STATESAVE_BEHAVIORNEWDATA = 0x00000020, /**< not used */
CK_STATESAVE_BEHAVIORFLAGS = 0x00000040, /**< not used */
@ -537,7 +537,7 @@ namespace LibCmo::CK2 {
/**
SCENE CKSaveOjectSave will save all relevant data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_SCENE : uint32_t {
enum class CK_STATESAVEFLAGS_SCENE : CKDWORD {
CK_STATESAVE_SCENERESERVED0 = 0x00001000, /**< Reserved for future use */
CK_STATESAVE_SCENERESERVED8 = 0x00002000, /**< Reserved for future use */
CK_STATESAVE_SCENEFLAGS = 0x00004000,
@ -559,7 +559,7 @@ namespace LibCmo::CK2 {
/**
ParameterIn
*/
enum class CK_STATESAVEFLAGS_PARAMETERIN : uint32_t {
enum class CK_STATESAVEFLAGS_PARAMETERIN : CKDWORD {
CK_STATESAVE_PARAMETERIN_RESERVED4 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_PARAMETERIN_RESERVED0 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_PARAMETERIN_RESERVED1 = 0x00000040, /**< Reserved for future use */
@ -575,7 +575,7 @@ namespace LibCmo::CK2 {
/**
ParameterLocal et ParameterOut
*/
enum class CK_STATESAVEFLAGS_PARAMETEROUT : uint32_t {
enum class CK_STATESAVEFLAGS_PARAMETEROUT : CKDWORD {
CK_STATESAVE_PARAMETEROUT_RESERVED0 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_PARAMETEROUT_DESTINATIONS = 0x00000020, /**< Save destinations */
CK_STATESAVE_PARAMETEROUT_VAL = 0x00000040, /**< Save value */
@ -587,7 +587,7 @@ namespace LibCmo::CK2 {
/**
Parameter Operation
*/
enum class CK_STATESAVEFLAGS_OPERATION : uint32_t {
enum class CK_STATESAVEFLAGS_OPERATION : CKDWORD {
CK_STATESAVE_OPERATIONRESERVED0 = 0x00000010, /**< Reserved for future use */
CK_STATESAVE_OPERATIONRESERVED1 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_OPERATIONINPUTS = 0x00000040,
@ -600,7 +600,7 @@ namespace LibCmo::CK2 {
/**
Synchro Object CKSaveOjectSave will save all relevant data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_SYNCHRO : uint32_t {
enum class CK_STATESAVEFLAGS_SYNCHRO : CKDWORD {
CK_STATESAVE_SYNCHRODATA = 0x00000010, /**< Save data */
CK_STATESAVE_SYNCHRORESERVED0 = 0x00000040, /**< Reserved for future use */
CK_STATESAVE_SYNCHRORESERVED1 = 0x00000080, /**< Reserved for future use */
@ -611,7 +611,7 @@ namespace LibCmo::CK2 {
/**
Grid
*/
enum class CK_STATESAVEFLAGS_GRID : uint32_t {
enum class CK_STATESAVEFLAGS_GRID : CKDWORD {
CK_STATESAVE_GRIDDATA = 0x00400000, /**< Save Grid Data */
CK_STATESAVE_GRIDRESERVED0 = 0x00800000, /**< Reserved for future use */
CK_STATESAVE_GRIDRESERVED1 = 0x01000000, /**< Reserved for future use */
@ -624,7 +624,7 @@ namespace LibCmo::CK2 {
/**
Layer (For Grids)
*/
enum class CK_STATESAVEFLAGS_LAYER : uint32_t {
enum class CK_STATESAVEFLAGS_LAYER : CKDWORD {
CK_STATESAVE_LAYERDATA = 0x00000010, /**< Save Layer Data */
CK_STATESAVE_LAYERRESERVED0 = 0x00800020, /**< Reserved for future use */
CK_STATESAVE_LAYERRESERVED1 = 0x00000040, /**< Reserved for future use */
@ -637,7 +637,7 @@ namespace LibCmo::CK2 {
/**
DataArray CKSaveOjectSave will save all relevant data and does not take flags into account
*/
enum class CK_STATESAVEFLAGS_DATAARRAY : uint32_t {
enum class CK_STATESAVEFLAGS_DATAARRAY : CKDWORD {
CK_STATESAVE_DATAARRAYFORMAT = 0x00001000, /**< Save format */
CK_STATESAVE_DATAARRAYDATA = 0x00002000, /**< Save array data */
CK_STATESAVE_DATAARRAYMEMBERS = 0x00004000, /**< Save members */
@ -646,7 +646,7 @@ namespace LibCmo::CK2 {
/**
SceneObjectDesc
*/
enum class CK_STATESAVEFLAGS_SCENEOBJECTDESC : uint32_t {
enum class CK_STATESAVEFLAGS_SCENEOBJECTDESC : CKDWORD {
CK_STATESAVE_SCENEOBJECTDESC = 0x00000010,
CK_STATESAVE_SCENEOBJECTRES1 = 0x00000020, /**< Reserved for future use */
CK_STATESAVE_SCENEOBJECTRES2 = 0x00000040, /**< Reserved for future use */

View File

@ -583,7 +583,7 @@ namespace LibCmo::CK2 {
}
}
bool CKStateChunk::ReadString(std::string* strl) {
bool CKStateChunk::ReadString(XContainer::XString* strl) {
if (strl == nullptr) return false;
// get byte based size
@ -594,7 +594,7 @@ namespace LibCmo::CK2 {
}
// read data
std::string cache;
XContainer::XString cache;
cache.resize(strByteSize);
if (!this->ReadByteData(cache.data(), strByteSize)) {
strl->clear();

View File

@ -158,8 +158,8 @@ namespace LibCmo::CK2 {
/// </summary>
/// <param name="strl"></param>
/// <returns></returns>
bool ReadString(std::string* strl);
inline bool ReadString(std::string& strl) {
bool ReadString(XContainer::XString* strl);
inline bool ReadString(XContainer::XString& strl) {
return ReadString(&strl);
}

View File

@ -1,79 +0,0 @@
#pragma once
#include "CKGlobals.hpp"
namespace LibCmo::CK2 {
// a stupid forward decl to remove something
/**
* @brief Storage class for filename extensions
*/
class CKFileExtension {
public:
CKFileExtension() : m_Data() {
std::memset(m_Data, 0, c_DataLen);
}
CKFileExtension(CKSTRING s) : CKFileExtension() {
SetExt(s);
}
CKFileExtension(const CKFileExtension& rhs) : CKFileExtension() {
std::memcpy(m_Data, rhs.m_Data, c_DataLen);
}
CKFileExtension(CKFileExtension&& rhs) : CKFileExtension() {
std::memmove(m_Data, rhs.m_Data, c_DataLen);
std::memset(rhs.m_Data, 0, c_DataLen);
}
CKFileExtension& operator=(const CKFileExtension& rhs) {
std::memcpy(m_Data, rhs.m_Data, c_DataLen);
return *this;
}
CKFileExtension& operator=(CKFileExtension&& rhs) {
std::memmove(m_Data, rhs.m_Data, c_DataLen);
std::memset(rhs.m_Data, 0, c_DataLen);
return *this;
}
void SetExt(CKSTRING s) {
if (s == nullptr) {
m_Data[0] = '\0';
} else {
if (s[0] == '.') ++s; // skip dot
size_t len = std::strlen(s);
if (len > (c_DataLen - 1)) len = c_DataLen - 1;
std::memcpy(m_Data, s, len);
}
}
CKSTRING GetExt() const {
return m_Data;
}
bool operator==(const CKFileExtension& rhs) const {
return CKStrEqualI(m_Data, rhs.m_Data);
}
protected:
static constexpr size_t c_DataLen = 4u;
CKCHAR m_Data[c_DataLen];
};
/**
* The struct describe the bitmap handler's infomation,
* including its GUID and supported file extension.
* This struct also will store some parameters related to bitmap handler,
* such as jpeg compress level and etc. But currently there are no
* such parameters.
*/
class CKBitmapProperties {
public:
CKBitmapProperties() :
m_ReaderGuid(), m_Ext() {}
CKBitmapProperties(const CKGUID& guid, CKSTRING ext) :
m_ReaderGuid(guid), m_Ext(ext) {}
LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties);
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 */
};
}

View File

@ -5,11 +5,133 @@
#include <vector>
#include <cstring>
#include <cinttypes>
#include <compare>
// ========== Basic Types Section ==========
namespace LibCmo {
// Types.
// These types is general types used in every module.
// So we declare them in LibCmo, not LibCmo::CK2 to make sure every module can use it.
/**
* @brief General Const String Type. Encoding Unrelated.
*/
using CKSTRING = const char*;
/**
* @brief Changeble CKSTRING.
* @see CKSTRING
*/
using CKMUTSTRING = char*;
/**
* @brief The Representation of Single Character (1 byte). Encoding Unrelated.
* @remark
* + Only used with string process.
* + For memory representation and moving, use CKBYTE instead.
* @see CKBYTE
*/
using CKCHAR = char;
/**
* @brief Always Represent a Byte (1 byte, unsigned). Platform Independent.
* @remark
* + This type should only be used when representing memory data or position.
* + If you want to represent a char, or a sequence of chars, use CKCHAR instead.
* @see CKCHAR
*/
using CKBYTE = uint8_t;
/**
* @brief Always Represent a WORD (2 byte, unsigned). Platform Independent.
*/
using CKWORD = uint16_t;
/**
* @brief Always Represent a DWORD (4 byte, unsigned). Platform Independent.
* @see CKINT
*/
using CKDWORD = uint32_t;
/**
* @brief Always Represent a QWORD (8 byte, unsigned). Platform Independent.
*/
using CKQWORD = uint64_t;
/**
* @brief The Int type used in LibCmo.
* @remark
* + All '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.
* @see CKDWORD
*/
using CKINT = int32_t;
/**
* @brief Always Represent a float (32 bit). Platform Independent.
*/
using CKFLOAT = float;
/**
* @brief Always Represent a double (64 bit). Platform Independent.
*/
using CKDOUBLE = double;
/**
* @brief The bool type used by LibCmo.
* Generally it is just C++ bool.
*/
using CKBOOL = bool;
/**
* @brief The True value of CKBOOL.
*/
constexpr CKBOOL CKTRUE = true;
/**
* @brief The False value of CKBOOL.
*/
constexpr CKBOOL CKFALSE = false;
/**
* @brief Represent a x86 Platform Pointer.
* @remark
* + 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.
* 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.
* + A example can be found in CKTexture::Load().
*/
using CKPTR = uint32_t;
// Format constants for the std::fprintf family of functions
#define PRI_CKSTRING "s"
#define PRI_CKCHAR "c"
#define PRIuCKBYTE PRIu8
#define PRIuCKWORD PRIu16
#define PRIuCKDWORD PRIu32
#define PRIuCKQWORD PRIu64
#define PRIxCKBYTE PRIx8
#define PRIxCKWORD PRIx16
#define PRIxCKDWORD PRIx32
#define PRIxCKQWORD PRIx64
#define PRIXCKBYTE PRIX8
#define PRIXCKWORD PRIX16
#define PRIXCKDWORD PRIX32
#define PRIXCKQWORD PRIX64
#define PRIiCKINT PRIi32
#define PRIxCKPTR PRIx32
#define PRIXCKPTR PRIX32
/*
The convenient sizeof which return CKDWORD, not size_t.
*/
#define CKSizeof(_Ty) (static_cast<LibCmo::CKDWORD>(sizeof(_Ty)))
}
// ========== CK2 Section ==========
/**
* @brief The CK2 part of LibCmo.
* These classes are prefixed with CK in original Virtools SDK.
*/
namespace LibCmo::CK2 {
/**
@ -25,9 +147,9 @@ namespace LibCmo::CK2 {
is no garanty that this ID will be the same when a level is saved and loaded back again.
@see CKObject::GetID, CKContext::GetObject
*/
using CK_ID = uint32_t;
using CK_ID = CKDWORD;
enum class CKERROR : int32_t {
enum class CKERROR : CKINT {
CKERR_OK = 0, /**< Operation successful */
CKERR_INVALIDPARAMETER = -1, /**< One of the parameter passed to the function was invalid */
CKERR_INVALIDPARAMETERTYPE = -2, /**< One of the parameter passed to the function was invalid */
@ -91,7 +213,7 @@ namespace LibCmo::CK2 {
objects, etc..
@see CKObject::GetClassID, CKIsChildClassOf, Class Identifiers
*/
enum class CK_CLASSID : int32_t {
enum class CK_CLASSID : CKINT {
CKCID_OBJECT = 1,
CKCID_PARAMETERIN = 2,
CKCID_PARAMETEROPERATION = 4,
@ -164,37 +286,16 @@ namespace LibCmo::CK2 {
// ========== Type Definition ==========
// type define
using CKMUTSTRING = char*;
using CKSTRING = const char*;
using CKCHAR = char;
using CKBYTE = uint8_t;
using CKDWORD = uint32_t;
using CKWORD = uint16_t;
using CKINT = int32_t;
using CKParameterType = int32_t;
using CKOperationType = int32_t;
using CKMessageType = int32_t;
using CKAttributeType = int32_t;
using CKAttributeCategory = int32_t;
// type print style define
#define PRIuCKID PRIu32
#define PRIiCKERROR PRIi32
#define PRIiCLASSID PRIi32
#define PRIuCKBYTE PRIu8
#define PRIuCKDWORD PRIu32
#define PRIuCKWORD PRIu16
#define PRIxCKBYTE PRIx8
#define PRIxCKDWORD PRIx32
#define PRIxCKWORD PRIx16
#define PRIXCKBYTE PRIX8
#define PRIXCKDWORD PRIX32
#define PRIXCKWORD PRIX16
#define PRIiCKINT PRIi32
using CKParameterType = CKINT;
using CKOperationType = CKINT;
using CKMessageType = CKINT;
using CKAttributeType = CKINT;
using CKAttributeCategory = CKINT;
// format constant
#define PRIuCKID PRIuCKDWORD
#define PRIiCKERROR PRIiCKINT
#define PRIiCLASSID PRIiCKINT
// ========== Class List ==========
// Objects and derivated classes
@ -300,7 +401,6 @@ namespace LibCmo::CK2 {
class CKFileWriter;
class CKFileVisitor;
/**
@brief Global Unique Identifier Struture.
@remark
@ -331,40 +431,15 @@ namespace LibCmo::CK2 {
return *this;
}
bool operator ==(const CKGUID& rhs) const {
auto operator<=>(const CKGUID& rhs) const {
auto cmp = this->d1 <=> rhs.d1;
if (cmp != 0)
return cmp;
return this->d2 <=> rhs.d2;
}
bool operator==(const CKGUID& rhs) const {
return ((this->d1 == rhs.d1) && (this->d2 == rhs.d2));
}
bool operator !=(const CKGUID& rhs) const {
return ((this->d1 != rhs.d1) || (this->d2 != rhs.d2));
}
bool operator <(const CKGUID& rhs) const {
if (this->d1 < rhs.d1) {
return true;
}
if (this->d1 == rhs.d1) {
return (this->d2 < rhs.d2);
}
return false;
}
bool operator <=(const CKGUID& rhs) const {
return (this->d1 <= rhs.d1);
}
bool operator >(const CKGUID& rhs) const {
if (this->d1 > rhs.d1) {
return true;
}
if (this->d1 == rhs.d1) {
return (this->d2 > rhs.d2);
}
return false;
}
bool operator >=(const CKGUID& rhs) const {
return (this->d1 >= rhs.d1);
}
};
}

View File

@ -1,7 +1,4 @@
#include "CKBitmapHandler.hpp"
#include "stb_image.h"
#include "stb_image_write.h"
#include "stb_image_resize.h"
namespace LibCmo::CK2::DataHandlers {
@ -14,7 +11,7 @@ namespace LibCmo::CK2::DataHandlers {
The data is placed in buffer with BGRA order.
*/
static void ABGRToARGB(CK2::CKDWORD count, const void* _abgr, void* _argb) {
static void ABGRToARGB(CKDWORD count, const void* _abgr, void* _argb) {
const char* abgr = reinterpret_cast<const char*>(_abgr);
char* argb = reinterpret_cast<char*>(_argb);
// copy R
@ -55,7 +52,7 @@ namespace LibCmo::CK2::DataHandlers {
);
}
static void ARGBToABGR(CK2::CKDWORD count, const void* _argb, void* _abgr) {
static void ARGBToABGR(CKDWORD count, const void* _argb, void* _abgr) {
const char* argb = reinterpret_cast<const char*>(_argb);
char* abgr = reinterpret_cast<char*>(_abgr);
// copy R

View File

@ -36,9 +36,9 @@ namespace LibCmo::CK2::MgrImpls {
class CKBaseManager {
public:
CKBaseManager(CKContext* ctx, CKGUID guid, CKSTRING name) :
m_ManagerGuid(guid),
m_ManagerName(name),
m_Context(ctx) {}
m_ManagerGuid(guid), m_ManagerName(), m_Context(ctx) {
XContainer::NSXString::FromCKSTRING(m_ManagerName, name);
}
virtual ~CKBaseManager() {}
LIBCMO_DISABLE_COPY_MOVE(CKBaseManager);
@ -77,7 +77,7 @@ namespace LibCmo::CK2::MgrImpls {
```
*/
CKSTRING GetName() {
return m_ManagerName.toCKSTRING();
return XContainer::NSXString::ToCKSTRING(m_ManagerName);
}
/**
@ -155,7 +155,7 @@ namespace LibCmo::CK2::MgrImpls {
protected:
CKGUID m_ManagerGuid; ///> Manager GUID
TypeHelper::MKString m_ManagerName; ///> Manager Name
XContainer::XString m_ManagerName; ///> Manager Name
CKContext* m_Context; ///> A pointer to the CKContext on which this manager is valid.
};

View File

@ -32,18 +32,18 @@ namespace LibCmo::CK2::MgrImpls {
}
}
std::string CKPathManager::GetTempFolder() {
std::string result;
XContainer::XString CKPathManager::GetTempFolder() {
XContainer::XString result;
EncodingHelper::StdPathToU8Path(result, this->m_TempFolder);
return result;
}
std::string CKPathManager::GetTempFilePath(CKSTRING u8_filename) {
XContainer::XString CKPathManager::GetTempFilePath(CKSTRING u8_filename) {
std::filesystem::path stdfilename;
EncodingHelper::U8PathToStdPath(stdfilename, u8_filename);
auto realfile = this->m_TempFolder / stdfilename;
std::string result;
XContainer::XString result;
EncodingHelper::StdPathToU8Path(result, realfile);
return result;
}
@ -64,7 +64,7 @@ namespace LibCmo::CK2::MgrImpls {
m_ExtraPathes.clear();
}
bool CKPathManager::ResolveFileName(std::string& u8_filename) {
bool CKPathManager::ResolveFileName(XContainer::XString& u8_filename) {
std::filesystem::path filepath;
EncodingHelper::U8PathToStdPath(filepath, u8_filename.c_str());
@ -94,7 +94,7 @@ namespace LibCmo::CK2::MgrImpls {
return false;
}
void CKPathManager::GetExtension(std::string& u8path) {
void CKPathManager::GetExtension(XContainer::XString& u8path) {
std::filesystem::path filepath;
EncodingHelper::U8PathToStdPath(filepath, u8path.c_str());

View File

@ -22,13 +22,13 @@ namespace LibCmo::CK2::MgrImpls {
* @brief Get current temp folder.
* @return
*/
std::string GetTempFolder();
XContainer::XString GetTempFolder();
/**
* @brief Get the path of temp file.
* @param u8_filename The relative path of file.
* @return The path of given path based on temp folder.
*/
std::string GetTempFilePath(CKSTRING u8_filename);
XContainer::XString GetTempFilePath(CKSTRING u8_filename);
/**
* @brief Add extra path for ResolveFileName
@ -51,13 +51,13 @@ namespace LibCmo::CK2::MgrImpls {
* + Virtools temp folder.
* @return true if success
*/
bool ResolveFileName(std::string& u8_filename);
bool ResolveFileName(XContainer::XString& u8_filename);
/**
* @brief Returns the file extension including period (.)
* @param u8path[inout] The given path. overwritten by the gotten extension. set to blank when failed.
*/
void GetExtension(std::string& u8path);
void GetExtension(XContainer::XString& u8path);
protected:
std::filesystem::path m_TempFolder;

View File

@ -26,7 +26,7 @@ namespace LibCmo::CK2::ObjImpls {
VxMath::VxColor m_Ambient;
VxMath::VxColor m_Specular;
VxMath::VxColor m_Emissive;
float m_SpecularPower;
CKFLOAT m_SpecularPower;
std::array<CKTexture*, 4> m_Textures;
CKDWORD m_TextureBorderColor;

View File

@ -141,7 +141,7 @@ namespace LibCmo::CK2::ObjImpls {
return m_VertexSpecularColor.data();
}
float* CKMesh::GetVertexWeights() {
CKFLOAT* CKMesh::GetVertexWeights() {
return m_VertexWeight.data();
}

View File

@ -36,7 +36,7 @@ namespace LibCmo::CK2::ObjImpls {
VxMath::VxVector2* GetVertexUVs();
CKDWORD* GetVertexColors();
CKDWORD* GetVertexSpecularColors();
float* GetVertexWeights();
CKFLOAT* GetVertexWeights();
// ===== Material Slot Section =====
public:
@ -77,10 +77,10 @@ namespace LibCmo::CK2::ObjImpls {
protected:
enum class VertexSaveFlags : CKDWORD {
SingleColor = 0x1u, /**< if not set, the VertexColor is a list£¬ otherwise a single global CKDWORD.*/
SingleSpecularColor = 0x2u, /**< if not set, the VertexSpecularColor is a list£¬ otherwise a single global CKDWORD. */
SingleColor = 0x1u, /**< if not set, the VertexColor is a list, otherwise a single global CKDWORD.*/
SingleSpecularColor = 0x2u, /**< if not set, the VertexSpecularColor is a list, otherwise a single global CKDWORD. */
NoNormal = 0x4u, /**< if set, there are no normal data for vertex. */
SingleUV = 0x8u, /**< if not set, the VertexUV is a list£¬ otherwise a single global VxVertex2. */
SingleUV = 0x8u, /**< if not set, the VertexUV is a list, otherwise a single global VxVertex2. */
NoPos = 0x10u, /**< if set, there are no position data for vertex. */
};
struct FaceData_t {
@ -118,7 +118,7 @@ namespace LibCmo::CK2::ObjImpls {
XContainer::XArray<VxMath::VxVector2> m_VertexUV;
XContainer::XArray<CKDWORD> m_VertexColor;
XContainer::XArray<CKDWORD> m_VertexSpecularColor;
XContainer::XArray<float> m_VertexWeight;
XContainer::XArray<CKFLOAT> m_VertexWeight;
XContainer::XArray<CKMaterial*> m_MaterialSlot;

View File

@ -50,10 +50,10 @@ namespace LibCmo::CK2::ObjImpls {
return m_ID;
}
CKSTRING GetName(void) {
return m_Name.toCKSTRING();
return XContainer::NSXString::ToCKSTRING(m_Name);
}
void SetName(CKSTRING u8_name) {
m_Name = u8_name;
XContainer::NSXString::FromCKSTRING(m_Name, u8_name);
}
CK_OBJECT_FLAGS GetObjectFlags(void) {
return m_ObjectFlags;
@ -75,7 +75,7 @@ namespace LibCmo::CK2::ObjImpls {
protected:
CK_ID m_ID;
TypeHelper::MKString m_Name;
XContainer::XString m_Name;
CK_OBJECT_FLAGS m_ObjectFlags;
CKContext* m_Context;
};

View File

@ -25,38 +25,38 @@ namespace LibCmo::CK2::ObjImpls {
}m_Ext;
struct {
// fake VxImageDescEx
CK2::CKINT Size; ///< Size of the structure
CK2::CKDWORD Flags; ///< Reserved for special formats (such as compressed ) 0 otherwise
CKINT Size; ///< Size of the structure
CKDWORD Flags; ///< Reserved for special formats (such as compressed ) 0 otherwise
CK2::CKINT Width; ///< Width in pixel of the image
CK2::CKINT Height; ///< Height in pixel of the image
CKINT Width; ///< Width in pixel of the image
CKINT Height; ///< Height in pixel of the image
union {
CK2::CKINT BytesPerLine; ///< Pitch (width in bytes) of the image
CK2::CKINT TotalImageSize; ///< For compressed image (DXT1...) the total size of the image
CKINT BytesPerLine; ///< Pitch (width in bytes) of the image
CKINT TotalImageSize; ///< For compressed image (DXT1...) the total size of the image
};
CK2::CKINT BitsPerPixel; ///< Number of bits per pixel
CKINT BitsPerPixel; ///< Number of bits per pixel
union {
CK2::CKDWORD RedMask; ///< Mask for Red component
CK2::CKDWORD BumpDuMask; ///< Mask for Bump Du component
CKDWORD RedMask; ///< Mask for Red component
CKDWORD BumpDuMask; ///< Mask for Bump Du component
};
union {
CK2::CKDWORD GreenMask; ///< Mask for Green component
CK2::CKDWORD BumpDvMask; ///< Mask for Bump Dv component
CKDWORD GreenMask; ///< Mask for Green component
CKDWORD BumpDvMask; ///< Mask for Bump Dv component
};
union {
CK2::CKDWORD BlueMask; ///< Mask for Blue component
CK2::CKDWORD BumpLumMask; ///< Mask for Luminance component
CKDWORD BlueMask; ///< Mask for Blue component
CKDWORD BumpLumMask; ///< Mask for Luminance component
};
CK2::CKDWORD AlphaMask; ///< Mask for Alpha component
CKDWORD AlphaMask; ///< Mask for Alpha component
CK2::CKWORD BytesPerColorEntry; ///< ColorMap Stride
CK2::CKWORD ColorMapEntries; ///< If other than 0 image is palletized
CKWORD BytesPerColorEntry; ///< ColorMap Stride
CKWORD ColorMapEntries; ///< If other than 0 image is palletized
/*CK2::CKBYTE**/CK2::CKDWORD ColorMap; ///< Palette colors
/*CK2::CKBYTE**/CK2::CKDWORD Image; ///< Image
/*CKBYTE**/CKPTR ColorMap; ///< Palette colors
/*CKBYTE**/CKPTR Image; ///< Image
}m_Format;
/*void**/CK2::CKDWORD m_Data;
/*void**/CKPTR m_Data;
};
CKTexture::CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name) :

View File

@ -200,7 +200,7 @@
<ClCompile Include="VTUtils.cpp" />
<ClCompile Include="VxMath\VxMath.cpp" />
<ClCompile Include="VxMath\VxMemoryMappedFile.cpp" />
<ClCompile Include="XContainer\XBitArray.cpp" />
<ClCompile Include="XContainer\XTypes.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CK2\CKBitmapData.hpp" />
@ -209,7 +209,6 @@
<ClInclude Include="CK2\CKFile.hpp" />
<ClInclude Include="CK2\CKGlobals.hpp" />
<ClInclude Include="CK2\CKIdentifiers.hpp" />
<ClInclude Include="CK2\CKStructs.hpp" />
<ClInclude Include="CK2\DataHandlers\CKBitmapHandler.hpp" />
<ClInclude Include="CK2\MgrImpls\CKBaseManager.hpp" />
<ClInclude Include="CK2\CKContext.hpp" />
@ -229,12 +228,12 @@
<ClInclude Include="VTAll.hpp" />
<ClInclude Include="VTEncoding.hpp" />
<ClInclude Include="CK2\ObjImpls\CKObject.hpp" />
<ClInclude Include="VTImage.hpp" />
<ClInclude Include="VTUtils.hpp" />
<ClInclude Include="VxMath\VxEnums.hpp" />
<ClInclude Include="VxMath\VxMath.hpp" />
<ClInclude Include="VxMath\VxMemoryMappedFile.hpp" />
<ClInclude Include="VxMath\VxTypes.hpp" />
<ClInclude Include="XContainer\XBitArray.hpp" />
<ClInclude Include="XContainer\XTypes.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -93,9 +93,6 @@
<ClCompile Include="CK2\ObjImpls\CKGroup.cpp">
<Filter>Sources\CK2\ObjImpls</Filter>
</ClCompile>
<ClCompile Include="XContainer\XBitArray.cpp">
<Filter>Sources\XContainer</Filter>
</ClCompile>
<ClCompile Include="CK2\ObjImpls\CKRenderObject.cpp">
<Filter>Sources\CK2\ObjImpls</Filter>
</ClCompile>
@ -129,6 +126,9 @@
<ClCompile Include="CK2\ObjImpls\CKMesh.cpp">
<Filter>Sources\CK2\ObjImpls</Filter>
</ClCompile>
<ClCompile Include="XContainer\XTypes.cpp">
<Filter>Sources\XContainer</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="VTUtils.hpp">
@ -188,9 +188,6 @@
<ClInclude Include="CK2\ObjImpls\CKGroup.hpp">
<Filter>Headers\CK2\ObjImpls</Filter>
</ClInclude>
<ClInclude Include="XContainer\XBitArray.hpp">
<Filter>Headers\XContainer</Filter>
</ClInclude>
<ClInclude Include="CK2\ObjImpls\CKRenderObject.hpp">
<Filter>Headers\CK2\ObjImpls</Filter>
</ClInclude>
@ -215,9 +212,6 @@
<ClInclude Include="CK2\DataHandlers\CKBitmapHandler.hpp">
<Filter>Headers\CK2\DataHandlers</Filter>
</ClInclude>
<ClInclude Include="CK2\CKStructs.hpp">
<Filter>Headers\CK2</Filter>
</ClInclude>
<ClInclude Include="CK2\CKBitmapData.hpp">
<Filter>Headers\CK2</Filter>
</ClInclude>
@ -230,5 +224,8 @@
<ClInclude Include="CK2\ObjImpls\CKMesh.hpp">
<Filter>Headers\CK2\ObjImpls</Filter>
</ClInclude>
<ClInclude Include="VTImage.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -10,21 +10,62 @@ 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, they should include "VTUtils.hpp" 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.
*/
/*
Including various basic define.
+ LIBCMO_OS_xxx macro to distinguish different OS and architecture
+ General types such as CKDWORD and their format constant
+ 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"
/*
System independent image loader / saver
*/
#include "VTImage.hpp"
#include "CK2/CKTypes.hpp" // the basic type of Virtools.
#include "CK2/CKDefines.hpp" // some useful define or constexpr for Virtools.
#include "CK2/CKEnums.hpp" // All CK used enums except CKStateChunk identifiers.
#include "CK2/CKIdentifiers.hpp" // CKStateChunk identifiers.
#include "CK2/CKGlobals.hpp" // CK global functions, such as CKUnPack and etc.
#include "CK2/CKStructs.hpp" // Some essential and useful classes + structs.
#include "VxMath/VxEnums.hpp"
#include "VxMath/VxTypes.hpp"
#include "VxMath/VxMath.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"

7
LibCmo/VTImage.hpp Normal file
View File

@ -0,0 +1,7 @@
#pragma once
// Bad wrapper for stb image library.
#include "stb_image.h"
#include "stb_image_write.h"
#include "stb_image_resize.h"

View File

@ -8,23 +8,4 @@ namespace LibCmo {
std::abort();
}
//namespace StreamHelper {
// static constexpr const size_t CHUNK_SIZE = 10240;
// void CopyStream(const void* src, FILE* dest, size_t len) {
// fwrite(src, sizeof(char), len, dest);
// }
// void CopyStream(FILE* src, void* dest, size_t len) {
// size_t expected_size = 0u;
// char* p = reinterpret_cast<char*>(dest);
// while (len != 0) {
// expected_size = len < CHUNK_SIZE ? len : CHUNK_SIZE;
// fread(p, sizeof(char), expected_size, src);
// p += expected_size;
// len -= expected_size;
// }
// }
//}
}

View File

@ -72,95 +72,6 @@ namespace LibCmo {
[[noreturn]] void LibPanic(int line, const char* file, const char* errmsg);
#define LIBPANIC(msg) LibCmo::LibPanic(__LINE__, __FILE__, msg);
namespace TypeHelper {
/**
* @brief MKString is a compatible type.
* In some original Virtools case, we need CKSTRING to hold string.
* But CKSTRING is just a pointer and it is very cause memory leak.
* So I invent this. It like CKSTRING but will free memory automatically.
* And it is safe in CKSTRING copying.
* It operate like std::string. Have a function called c_str() to create usable CKSTRING.
* We call it as MKString. (memory-safe CKSTRING.) :pu: =.=
*/
class MKString {
public:
MKString() : m_HasStr(false), m_Str() {}
~MKString() {}
MKString(const char* cstr) : m_HasStr(cstr != nullptr), m_Str(m_HasStr ? cstr : "") {}
MKString& operator=(const char* cstr) {
m_HasStr = cstr != nullptr;
m_Str = m_HasStr ? cstr : "";
return *this;
}
bool operator==(const char* rhs) const {
if (m_HasStr) {
return m_Str == rhs;
} else {
return rhs == nullptr;
}
}
MKString(const std::string& cstr) : m_HasStr(true), m_Str(cstr) {}
MKString& operator=(const std::string& cstr) {
m_HasStr = true;
m_Str = cstr;
return *this;
}
bool operator==(const std::string& rhs) const {
if (m_HasStr) {
return m_Str == rhs;
} else {
return false;
}
}
MKString(const MKString& rhs) : m_HasStr(rhs.m_HasStr), m_Str(rhs.m_Str) {}
MKString(MKString&& rhs) noexcept : m_HasStr(rhs.m_HasStr), m_Str(std::move(rhs.m_Str)) {
rhs.m_HasStr = false;
}
MKString& operator=(const MKString& rhs) {
m_HasStr = rhs.m_HasStr;
m_Str = rhs.m_Str;
return *this;
}
MKString& operator=(MKString&& rhs) noexcept {
m_HasStr = rhs.m_HasStr;
m_Str = std::move(rhs.m_Str);
rhs.m_HasStr = false;
return *this;
}
bool operator==(const MKString& rhs) const {
return (m_HasStr == rhs.m_HasStr && m_Str == rhs.m_Str);
}
const char* toCKSTRING() const {
return m_HasStr ? m_Str.c_str() : nullptr;
}
/**
* @brief Return the std::string format of this string.
* @remark nullptr string will return blank string.
* @return The std::string format of this string.
*/
const std::string& toString() const {
return m_Str;
}
/**
* @brief The size of this string.
* @remark Both empty string and nullptr will return 0
* @return The size of this string
*/
const size_t size() const {
return m_HasStr ? m_Str.size() : 0u;
}
private:
bool m_HasStr;
std::string m_Str;
};
}
namespace EnumsHelper {
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
inline TEnum Merge(std::initializer_list<TEnum> il) {
@ -197,10 +108,4 @@ namespace LibCmo {
}
}
//namespace StreamHelper {
// void CopyStream(const void* src, FILE* dest, size_t len);
// void CopyStream(FILE* src, void* dest, size_t len);
//}
}

View File

@ -10,7 +10,7 @@ namespace LibCmo::VxMath {
@brief Pixel format types.
@see VxImageDesc2PixelFormat, VxPixelFormat2ImageDesc
*/
enum class VX_PIXELFORMAT : uint32_t {
enum class VX_PIXELFORMAT : CKDWORD {
UNKNOWN_PF = 0, /**< Unknown pixel format */
_32_ARGB8888 = 1, /**< 32-bit ARGB pixel format with alpha */
_32_RGB888 = 2, /**< 32-bit RGB pixel format without alpha */
@ -53,7 +53,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_TEXTUREMAPBLEND texture stage state.
See Also: Using Materials,CKMaterial,CKTexture,CKMaterial::SetTextureBlendMode,CKRST_TSS_TEXTUREMAPBLEND.
*/
enum class VXTEXTURE_BLENDMODE : uint32_t {
enum class VXTEXTURE_BLENDMODE : CKDWORD {
VXTEXTUREBLEND_DECAL = 1UL, /**< Texture replace any material information */
VXTEXTUREBLEND_MODULATE = 2UL, /**< Texture and material are combine. Alpha information of the texture replace material alpha component. */
VXTEXTUREBLEND_DECALALPHA = 3UL, /**< Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. */
@ -75,7 +75,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_MAGFILTER and CKRST_TSS_MINFILTER texture stage state.
See Also: Using Materials,CKMaterial,CKTexture,CKMaterial::SetTextureMagMode,CKMaterial::SetTextureMinMode,,CKRenderContext::SetTextureStageState
*/
enum class VXTEXTURE_FILTERMODE : uint32_t {
enum class VXTEXTURE_FILTERMODE : CKDWORD {
VXTEXTUREFILTER_NEAREST = 1UL, /**< No Filter */
VXTEXTUREFILTER_LINEAR = 2UL, /**< Bilinear Interpolation */
VXTEXTUREFILTER_MIPNEAREST = 3UL, /**< Mip mapping */
@ -100,7 +100,7 @@ namespace LibCmo::VxMath {
See Also: CKMaterial,CKTexture,CKMaterial::SetSourceBlend,CKMaterial::SetDestBlend,CKRenderContext::SetState,CKSprite::SetBlending,VXRENDERSTATE_SRCBLEND,VXRENDERSTATE_DESTBLEND
*/
enum class VXBLEND_MODE : uint32_t {
enum class VXBLEND_MODE : CKDWORD {
VXBLEND_ZERO = 1UL, /**< Blend factor is (0, 0, 0, 0). */
VXBLEND_ONE = 2UL, /**< Blend factor is (1, 1, 1, 1). */
VXBLEND_SRCCOLOR = 3UL, /**< Blend factor is (Rs, Gs, Bs, As). */
@ -125,7 +125,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_ADDRESS texture stage state.
See Also: CKMaterial,CKTexture,CKRST_TSS_ADDRESS,CKRenderContext::SetTextureStageState
*/
enum class VXTEXTURE_ADDRESSMODE : uint32_t {
enum class VXTEXTURE_ADDRESSMODE : CKDWORD {
VXTEXTURE_ADDRESSWRAP = 1UL, /**< Default mesh wrap mode is used (see CKMesh::SetWrapMode) */
VXTEXTURE_ADDRESSMIRROR = 2UL, /**< Texture coordinates outside the range [0..1] are flipped evenly. */
VXTEXTURE_ADDRESSCLAMP = 3UL, /**< Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. */
@ -140,7 +140,7 @@ namespace LibCmo::VxMath {
+ Also used as value for VXRENDERSTATE_FILLMODE render state.
See Also: CKMaterial::SetFillMode,VXRENDERSTATE_FILLMODE
*/
enum class VXFILL_MODE : uint32_t {
enum class VXFILL_MODE : CKDWORD {
VXFILL_POINT = 1UL, /**< Vertices rendering */
VXFILL_WIREFRAME = 2UL, /**< Edges rendering */
VXFILL_SOLID = 3UL, /**< Face rendering */
@ -154,7 +154,7 @@ namespace LibCmo::VxMath {
+ Also used as value for VXRENDERSTATE_SHADEMODE render state.
See Also: CKMaterial::SetShadeMode,VXRENDERSTATE_SHADEMODE
*/
enum class VXSHADE_MODE : uint32_t {
enum class VXSHADE_MODE : CKDWORD {
VXSHADE_FLAT = 1UL, /**< Flat Shading */
VXSHADE_GOURAUD = 2UL, /**< Gouraud Shading */
VXSHADE_PHONG = 3UL, /**< Phong Shading (Not yet supported by most implementation) */
@ -168,7 +168,7 @@ namespace LibCmo::VxMath {
+ The comparison function is used to compare the stencil,alpha or z reference value to a stencil,z or alpha entry.
See also: CKRenderContext::SetState,VXRENDERSTATETYPE,VXRENDERSTATE_ZFUNC,VXRENDERSTATE_ALPHAFUNC
*/
enum class VXCMPFUNC : uint32_t {
enum class VXCMPFUNC : CKDWORD {
VXCMP_NEVER = 1UL, /**< Always fail the test. */
VXCMP_LESS = 2UL, /**< Accept if value if less than current value. */
VXCMP_EQUAL = 3UL, /**< Accept if value if equal than current value. */
@ -190,7 +190,7 @@ namespace LibCmo::VxMath {
o Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
See also: CKMaterial::SetEffect,CKMaterial::GetEffect,CKRenderManager::AddEffect
*/
enum class VX_EFFECT : uint32_t {
enum class VX_EFFECT : CKDWORD {
VXEFFECT_NONE = 0UL, /**< No Effect */
VXEFFECT_TEXGEN = 1UL, /**< Texture coordinate generation using current viewpoint as referential */
VXEFFECT_TEXGENREF = 2UL, /**< texture generation generation with an optionnal referential */
@ -212,7 +212,7 @@ namespace LibCmo::VxMath {
See Also: CK3dEntity::SetMoveableFlags
*/
enum class VX_MOVEABLE_FLAGS : uint32_t {
enum class VX_MOVEABLE_FLAGS : CKDWORD {
VX_MOVEABLE_PICKABLE = 0x00000001, /**< (User)If not set this entity cannot be returned by CKRenderContext::Pick() or CKRenderContext::RectPict() functions. */
VX_MOVEABLE_VISIBLE = 0x00000002, /**< (Engine) See CKObject::Show,CK3dEntity::IsVisible */
VX_MOVEABLE_UPTODATE = 0x00000004, /**< (Engine) Used to Notify change in the data of the entity. */
@ -244,7 +244,7 @@ namespace LibCmo::VxMath {
+ Most of this flags can be set or asked using the appropriate method of CKMesh (given between () in the members documentation).
See Also: CKMesh,CKMesh::SetFlags
*/
enum class VXMESH_FLAGS : uint32_t {
enum class VXMESH_FLAGS : CKDWORD {
VXMESH_BOUNDINGUPTODATE = 0x00000001, /**< If set the bounding box is up to date (internal). */
VXMESH_VISIBLE = 0x00000002, /**< If not set the mesh will not be rendered (CKMesh::Show) */
VXMESH_OPTIMIZED = 0x00000004, /**< Set by the render engine if the mesh is optimized for rendering. Unset it to force to recreate optimized structures (when changing materials or face organization ) (CKMesh::VertexMove) */
@ -277,7 +277,7 @@ namespace LibCmo::VxMath {
+ The VXMESH_LITMODE is used by CKMesh::SetLitMode to specify how lighting is done.
See Also: CKMaterial,CKMesh
*/
enum class VXMESH_LITMODE : uint32_t {
enum class VXMESH_LITMODE : CKDWORD {
VX_PRELITMESH = 0, /**< Lighting use color information store with vertices */
VX_LITMESH = 1, /**< Lighting is done by renderer using normals and face material information. */
};
@ -290,7 +290,7 @@ namespace LibCmo::VxMath {
an additional material channel.
See Also: CKMesh,CKMesh::AddChannel,CKMesh::IsChannelLit,CKMesh::IsChannelActive
*/
enum class VXCHANNEL_FLAGS : uint32_t {
enum class VXCHANNEL_FLAGS : CKDWORD {
VXCHANNEL_ACTIVE = 0x00000001, /**< This channel is active */
VXCHANNEL_SAMEUV = 0x00800000, /**< This channel should use the texture coordinates of the base mesh. */
VXCHANNEL_NOTLIT = 0x01000000, /**< Additionnal Material Channel should not be lit (some channels may not be rendered in one pass with this option) */
@ -307,7 +307,7 @@ namespace LibCmo::VxMath {
texture coordinates are interpolated.
See Also: Using Materials,CKMaterial,CKMesh::SetWrapMode.
*/
enum class VXTEXTURE_WRAPMODE : uint32_t {
enum class VXTEXTURE_WRAPMODE : CKDWORD {
VXTEXTUREWRAP_NONE = 0x00000000, /**< Flat texture addressing */
VXTEXTUREWRAP_U = 0x00000001, /**< Vertical cylinder mapping */
VXTEXTUREWRAP_V = 0x00000002, /**< Horizontal cylinder mapping */

View File

@ -1,21 +1,20 @@
#include "../VTImage.hpp"
#include "VxMath.hpp"
#include "stb_image.h"
#include "stb_image_resize.h"
namespace LibCmo::VxMath {
#pragma region Structure copying
void VxFillStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD Stride, CK2::CKDWORD SizeSrc, const void* Src) {
void VxFillStructure(CKDWORD Count, void* Dst, CKDWORD Stride, CKDWORD SizeSrc, const void* Src) {
VxCopyStructure(Count, Dst, Stride, SizeSrc, Src, SizeSrc);
}
void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride) {
void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride) {
if (Dst == nullptr || Src == nullptr) return;
char* cdst = reinterpret_cast<char*>(Dst);
const char* csrc = reinterpret_cast<const char*>(Src);
for (CK2::CKDWORD i = 0; i < Count; ++i) {
for (CKDWORD i = 0; i < Count; ++i) {
std::memcpy(cdst, csrc, SizeSrc);
cdst += OutStride;
csrc += InStride;
@ -57,9 +56,9 @@ namespace LibCmo::VxMath {
}
// copy and swap data by line
CK2::CKDWORD height = dst->GetHeight(),
CKDWORD height = dst->GetHeight(),
rowsize = VxImageDescEx::PixelSize * dst->GetWidth();
for (CK2::CKDWORD row = 0; row < height; ++row) {
for (CKDWORD row = 0; row < height; ++row) {
std::memcpy(
dst->GetMutableImage() + (row * rowsize),
origin->GetImage() + ((height - row - 1) * rowsize),
@ -68,10 +67,10 @@ namespace LibCmo::VxMath {
}
}
CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask) {
CKDWORD VxGetBitCount(CKDWORD dwMask) {
if (dwMask == 0u) return 0;
dwMask >>= VxGetBitShift(dwMask);
CK2::CKDWORD count = 0;
CKDWORD count = 0;
while ((dwMask & 1u) == 0u) {
dwMask >>= 1u;
++count;
@ -79,9 +78,9 @@ namespace LibCmo::VxMath {
return count;
}
CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask) {
CKDWORD VxGetBitShift(CKDWORD dwMask) {
if (dwMask == 0u) return 0;
CK2::CKDWORD count = 0;
CKDWORD count = 0;
while ((dwMask & 1u) != 0u) {
dwMask >>= 1u;
++count;
@ -89,7 +88,7 @@ namespace LibCmo::VxMath {
return count;
}
//CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount) {
//CKDWORD VxScaleFactor(CKDWORD val, CKDWORD srcBitCount, CKDWORD dstBitCount) {
// if (srcBitCount == dstBitCount) return val;
// if (srcBitCount > dstBitCount) {
// return val >> (srcBitCount - dstBitCount);
@ -98,52 +97,29 @@ namespace LibCmo::VxMath {
// }
//}
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue) {
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE AlphaValue) {
if (dst_desc == nullptr) return;
CK2::CKDWORD* pixels = dst_desc->GetMutablePixels();
CK2::CKDWORD pixelcount = dst_desc->GetPixelCount();
CKDWORD* pixels = dst_desc->GetMutablePixels();
CKDWORD pixelcount = dst_desc->GetPixelCount();
for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CK2::CKDWORD>(AlphaValue) << 24);
for (CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CKDWORD>(AlphaValue) << 24);
++pixels;
}
//CK2::CKDWORD* pixels = dst_desc->GetPixels();
//CK2::CKDWORD pixelcount = dst_desc->GetPixelCount(),
// alphashift = VxGetBitShift(dst_desc->m_AlphaMask),
// alphacount = VxGetBitCount(dst_desc->m_AlphaMask);
//CK2::CKDWORD av = VxScaleFactor(AlphaValue, static_cast<CK2::CKDWORD>(sizeof(CK2::CKBYTE) * 8), alphacount) << alphashift;
//for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
// *pixels = (*pixels) & (~dst_desc->m_AlphaMask) | av;
// ++pixels;
//}
}
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE* AlphaValues) {
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE* AlphaValues) {
if (dst_desc == nullptr) return;
CK2::CKDWORD* pixels = dst_desc->GetMutablePixels();
CK2::CKDWORD pixelcount = dst_desc->GetPixelCount();
CKDWORD* pixels = dst_desc->GetMutablePixels();
CKDWORD pixelcount = dst_desc->GetPixelCount();
for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CK2::CKDWORD>(*AlphaValues) << 24);
for (CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CKDWORD>(*AlphaValues) << 24);
++pixels;
++AlphaValues;
}
//CK2::CKDWORD* pixels = dst_desc->GetPixels();
//CK2::CKDWORD pixelcount = dst_desc->GetPixelCount(),
// alphashift = VxGetBitShift(dst_desc->m_AlphaMask),
// alphacount = VxGetBitCount(dst_desc->m_AlphaMask);
//for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
// *pixels = (*pixels) & (~dst_desc->m_AlphaMask) | (VxScaleFactor(*AlphaValues, static_cast<CK2::CKDWORD>(sizeof(CK2::CKBYTE) * 8), alphacount) << alphashift);
// ++pixels;
// ++AlphaValues;
//}
}
#pragma endregion

View File

@ -1,4 +1,3 @@
#include "../VTUtils.hpp"
#include "../CK2/CKTypes.hpp"
#include "VxTypes.hpp"
@ -15,7 +14,7 @@ namespace LibCmo::VxMath {
* @param Src[in] Source buffer
* @remark This function can be used to initialized an array of structure when only some members should be modified.
*/
void VxFillStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD Stride, CK2::CKDWORD SizeSrc, const void* Src);
void VxFillStructure(CKDWORD Count, void* Dst, CKDWORD Stride, CKDWORD SizeSrc, const void* Src);
/**
* @brief copies an array of elements between two memory buffers.
* @param Count[in] Number of element to copy in the destination buffer
@ -26,7 +25,7 @@ namespace LibCmo::VxMath {
* @param InStride[in] Amount in bytes between each element in the source buffer
* @remark This function can be used to initialized an array of structure when only some members should be modified.
*/
void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride);
void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride);
// ========== Graphic Utilities ==========
@ -51,11 +50,11 @@ namespace LibCmo::VxMath {
/**
* @brief Counts number of bits to representing a value in dwMask
*/
CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask);
CKDWORD VxGetBitCount(CKDWORD dwMask);
/**
* @brief Counts number of bits to shift to acces a non zero value in dwMask.
*/
CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask);
CKDWORD VxGetBitShift(CKDWORD dwMask);
///**
// * @brief scale the integer to a new range.
@ -65,7 +64,7 @@ namespace LibCmo::VxMath {
// * @remark This function usually used in image color factor assign with mask.
// * @return The result integer.
//*/
//CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount);
//CKDWORD VxScaleFactor(CKDWORD val, CKDWORD srcBitCount, CKDWORD dstBitCount);
/**
* @brief Sets the alpha component of an image.
@ -74,7 +73,7 @@ namespace LibCmo::VxMath {
* @param AlphaValue[in] A CKBYTE value containing the alpha value to set to the whole image
* @remark If the destination image does not have alpha information the function returns immediatly.
*/
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue);
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE AlphaValue);
/**
* @brief Sets the alpha component of an image.
* @remark The source image must be in a 32 bit ARGB8888 per pixel format.
@ -82,7 +81,7 @@ namespace LibCmo::VxMath {
* @param AlphaValues[in] A BYTE array containing the alpha values for each pixel. This array should be allocated to Width*Height bytes.
* @remark If the destination image does not have alpha information the function returns immediatly.
*/
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE* AlphaValues);
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE* AlphaValues);
}

View File

@ -46,7 +46,7 @@ namespace LibCmo::VxMath {
~VxMemoryMappedFile(void);
void* GetBase(void) { return this->m_pMemoryMappedFileBase; }
CK2::CKDWORD GetFileSize(void) { return static_cast<CK2::CKDWORD>(this->m_cbFile); }
CKDWORD GetFileSize(void) { return static_cast<CKDWORD>(this->m_cbFile); }
bool IsValid(void) { return this->m_bIsValid; }
};

View File

@ -25,11 +25,11 @@ namespace LibCmo::VxMath {
//---- Misc
struct VxVector2 {
float x, y;
CKFLOAT x, y;
VxVector2() : x(0.0f), y(0.0f) {}
VxVector2(float _x, float _y) : x(_x), y(_y) {}
VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector2);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -52,24 +52,24 @@ namespace LibCmo::VxMath {
friend VxVector2 operator-(const VxVector2& lhs, const VxVector2& rhs) {
return VxVector2(lhs.x - rhs.x, lhs.y - rhs.y);
}
VxVector2& operator*=(float rhs) {
VxVector2& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
return *this;
}
friend VxVector2 operator*(const VxVector2& lhs, float rhs) {
friend VxVector2 operator*(const VxVector2& lhs, CKFLOAT rhs) {
return VxVector2(lhs.x * rhs, lhs.y * rhs);
}
friend VxVector2 operator*(float lhs, const VxVector2& rhs) {
friend VxVector2 operator*(CKFLOAT lhs, const VxVector2& rhs) {
return VxVector2(lhs * rhs.x, lhs * rhs.y);
}
VxVector2& operator/=(float rhs) {
VxVector2& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
return *this;
}
friend VxVector2 operator/(const VxVector2& lhs, float rhs) {
friend VxVector2 operator/(const VxVector2& lhs, CKFLOAT rhs) {
if (rhs == 0.0f) return VxVector2(0.0f, 0.0f);
return VxVector2(lhs.x / rhs, lhs.y / rhs);
}
@ -82,11 +82,11 @@ namespace LibCmo::VxMath {
};
struct VxVector3 {
float x, y, z;
CKFLOAT x, y, z;
VxVector3() : x(0.0f), y(0.0f), z(0.0f) {}
VxVector3(float _x, float _y, float _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);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -112,26 +112,26 @@ namespace LibCmo::VxMath {
friend VxVector3 operator-(const VxVector3& lhs, const VxVector3& rhs) {
return VxVector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
}
VxVector3& operator*=(float rhs) {
VxVector3& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
z *= rhs;
return *this;
}
friend VxVector3 operator*(const VxVector3& lhs, float rhs) {
friend VxVector3 operator*(const VxVector3& lhs, CKFLOAT rhs) {
return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
}
friend VxVector3 operator*(float lhs, const VxVector3& rhs) {
friend VxVector3 operator*(CKFLOAT lhs, const VxVector3& rhs) {
return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
}
VxVector3& operator/=(float rhs) {
VxVector3& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
z /= rhs;
return *this;
}
friend VxVector3 operator/(const VxVector3& lhs, float rhs) {
friend VxVector3 operator/(const VxVector3& lhs, CKFLOAT rhs) {
if (rhs == 0.0f) return VxVector3(0.0f, 0.0f, 0.0f);
return VxVector3(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs);
}
@ -144,11 +144,11 @@ namespace LibCmo::VxMath {
};
struct VxVector4 {
float x, y, z, w;
CKFLOAT x, y, z, w;
VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
VxVector4(float _x, float _y, float _z, float _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);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -177,20 +177,20 @@ namespace LibCmo::VxMath {
friend VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs) {
return VxVector4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w);
}
VxVector4& operator*=(float rhs) {
VxVector4& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
z *= rhs;
w *= rhs;
return *this;
}
friend VxVector4 operator*(const VxVector4& lhs, float rhs) {
friend VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs) {
return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
}
friend VxVector4 operator*(float lhs, const VxVector4& rhs) {
friend VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs) {
return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w);
}
VxVector4& operator/=(float rhs) {
VxVector4& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
@ -198,7 +198,7 @@ namespace LibCmo::VxMath {
w /= rhs;
return *this;
}
friend VxVector4 operator/(const VxVector4& lhs, float rhs) {
friend VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs) {
if (rhs == 0.0f) return VxVector4(0.0f, 0.0f, 0.0f, 0.0f);
return VxVector4(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs, lhs.w / rhs);
}
@ -211,11 +211,11 @@ namespace LibCmo::VxMath {
};
struct VxQuaternion {
float 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(float _x, float _y, float _z, float _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);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -233,26 +233,26 @@ namespace LibCmo::VxMath {
};
struct VxColor {
float 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(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {}
VxColor(CK2::CKDWORD argb) { FromARGB(argb); }
VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {}
VxColor(CKDWORD argb) { FromARGB(argb); }
LIBCMO_DEFAULT_COPY_MOVE(VxColor);
void FromARGB(CK2::CKDWORD argb) {
void FromARGB(CKDWORD argb) {
a = ((argb & 0xFF000000) >> 24) / 255.0f;
r = ((argb & 0x00FF0000) >> 16) / 255.0f;
g = ((argb & 0x0000FF00) >> 8) / 255.0f;
b = ((argb & 0x000000FF) >> 0) / 255.0f;
}
CK2::CKDWORD ToARGB() const {
CK2::CKDWORD argb = 0;
argb |= static_cast<CK2::CKDWORD>(a * 255.0f);
CKDWORD ToARGB() const {
CKDWORD argb = 0;
argb |= static_cast<CKDWORD>(a * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(r * 255.0f);
argb |= static_cast<CKDWORD>(r * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(g * 255.0f);
argb |= static_cast<CKDWORD>(g * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(b * 255.0f);
argb |= static_cast<CKDWORD>(b * 255.0f);
return argb;
}
void Regulate() {
@ -265,7 +265,7 @@ namespace LibCmo::VxMath {
if (a > 1.0f) a = 1.0f;
else if (a < 0.0f) a = 0.0f;
}
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return r;
case 1: return g;
@ -283,13 +283,13 @@ namespace LibCmo::VxMath {
};
struct VxMatrix {
float m_Data[4][4];
CKFLOAT m_Data[4][4];
VxMatrix() : 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;
}
VxMatrix(float 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);
VxVector4& operator[](size_t i) {
@ -307,8 +307,8 @@ namespace LibCmo::VxMath {
template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0>
class VxStridedData {
public:
VxStridedData(_Ty ptr, CK2::CKDWORD stride) :
m_Ptr(reinterpret_cast<CK2::CKBYTE*>(m_Ptr)),
VxStridedData(_Ty ptr, CKDWORD stride) :
m_Ptr(reinterpret_cast<CKBYTE*>(m_Ptr)),
m_Stride(stride)
{}
~VxStridedData() {}
@ -318,8 +318,8 @@ namespace LibCmo::VxMath {
}
private:
CK2::CKBYTE* m_Ptr;
CK2::CKDWORD m_Stride;
CKBYTE* m_Ptr;
CKDWORD m_Stride;
};
/**
@ -332,12 +332,12 @@ namespace LibCmo::VxMath {
*/
class VxImageDescEx {
public:
static constexpr CK2::CKDWORD ColorFactorSize = 1u;
static constexpr CK2::CKDWORD PixelSize = ColorFactorSize * 4u;
static constexpr CKDWORD ColorFactorSize = 1u;
static constexpr CKDWORD PixelSize = ColorFactorSize * 4u;
public:
VxImageDescEx() :
m_Width(0), m_Height(0), m_Image(nullptr) {}
VxImageDescEx(CK2::CKDWORD width, CK2::CKDWORD height) :
VxImageDescEx(CKDWORD width, CKDWORD height) :
m_Width(width), m_Height(height), m_Image(nullptr) {
CreateImage(width, height);
}
@ -382,13 +382,13 @@ namespace LibCmo::VxMath {
FreeImage();
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height) {
void CreateImage(CKDWORD Width, CKDWORD Height) {
FreeImage();
m_Width = Width;
m_Height = Height;
m_Image = new CK2::CKBYTE[GetImageSize()];
m_Image = new CKBYTE[GetImageSize()];
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height, void* dataptr) {
void CreateImage(CKDWORD Width, CKDWORD Height, void* dataptr) {
CreateImage(Width, Height);
std::memcpy(m_Image, dataptr, GetImageSize());
}
@ -401,30 +401,30 @@ namespace LibCmo::VxMath {
}
}
CK2::CKDWORD GetImageSize() const {
return static_cast<CK2::CKDWORD>(PixelSize * m_Width * m_Height);
CKDWORD GetImageSize() const {
return static_cast<CKDWORD>(PixelSize * m_Width * m_Height);
}
const CK2::CKBYTE* GetImage() const {
const CKBYTE* GetImage() const {
return m_Image;
}
CK2::CKBYTE* GetMutableImage() {
CKBYTE* GetMutableImage() {
return m_Image;
}
CK2::CKDWORD GetPixelCount() const {
return static_cast<CK2::CKDWORD>(m_Width * m_Height);
CKDWORD GetPixelCount() const {
return static_cast<CKDWORD>(m_Width * m_Height);
}
const CK2::CKDWORD* GetPixels() const {
return reinterpret_cast<CK2::CKDWORD*>(m_Image);
const CKDWORD* GetPixels() const {
return reinterpret_cast<CKDWORD*>(m_Image);
}
CK2::CKDWORD* GetMutablePixels() {
return reinterpret_cast<CK2::CKDWORD*>(m_Image);
CKDWORD* GetMutablePixels() {
return reinterpret_cast<CKDWORD*>(m_Image);
}
CK2::CKDWORD GetWidth() const {
CKDWORD GetWidth() const {
return m_Width;
}
CK2::CKDWORD GetHeight() const {
CKDWORD GetHeight() const {
return m_Height;
}
@ -448,15 +448,15 @@ namespace LibCmo::VxMath {
// }
//public:
// CK2::CKDWORD m_RedMask;
// CK2::CKDWORD m_GreenMask;
// CK2::CKDWORD m_BlueMask;
// CK2::CKDWORD m_AlphaMask;
// CKDWORD m_RedMask;
// CKDWORD m_GreenMask;
// CKDWORD m_BlueMask;
// CKDWORD m_AlphaMask;
protected:
CK2::CKDWORD m_Width; /**< Width in pixel of the image */
CK2::CKDWORD m_Height; /**< Height in pixel of the image */
CK2::CKBYTE* m_Image; /**< A pointer point to current processing image */
CKDWORD m_Width; /**< Width in pixel of the image */
CKDWORD m_Height; /**< Height in pixel of the image */
CKBYTE* m_Image; /**< A pointer point to current processing image */
};
}

View File

@ -1,30 +0,0 @@
#include "XBitArray.hpp"
namespace LibCmo::XContainer::XBitArrayPatch {
template<bool _Cond>
bool GeneralGetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
CK2::CKDWORD counter = 0;
for (size_t i = 0; i < ba.size(); ++i) {
if (ba[i] == _Cond) {
if (counter == n) {
got = static_cast<CK2::CKDWORD>(i);
return true;
} else {
++counter;
}
}
}
return false;
}
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
return GeneralGetBitPosition<true>(ba, n, got);
}
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
return GeneralGetBitPosition<false>(ba, n, got);
}
}

View File

@ -1,17 +0,0 @@
#pragma once
#include "XTypes.hpp"
namespace LibCmo::XContainer::XBitArrayPatch {
/**
* @brief Returns the position of the n-th set(1) bit
* @return false if not found.
*/
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
/**
* @brief Returns the position of the n-th unset(0) bit
* @return false if not found.
*/
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
}

View File

@ -0,0 +1,49 @@
#pragma once
#include "XTypes.hpp"
namespace LibCmo::XContainer {
namespace NSXBitArray {
template<bool _Cond>
bool GeneralGetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
CKDWORD counter = 0;
for (size_t i = 0; i < ba.size(); ++i) {
if (ba[i] == _Cond) {
if (counter == n) {
got = static_cast<CKDWORD>(i);
return true;
} else {
++counter;
}
}
}
return false;
}
bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
return GeneralGetBitPosition<true>(ba, n, got);
}
bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
return GeneralGetBitPosition<false>(ba, n, got);
}
}
namespace NSXString {
CKSTRING ToCKSTRING(const XString& strl) {
if (strl.empty()) return nullptr;
else return strl.c_str();
}
void FromCKSTRING(XString& strl, CKSTRING s) {
if (s == nullptr) strl.clear();
else strl = s;
}
}
}

View File

@ -1,11 +1,9 @@
#pragma once
#include "../CK2/CKTypes.hpp"
#include <string>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <cinttypes>
#include "../CK2/CKTypes.hpp"
/**
* @brief The X container part of LibCmo.
@ -21,7 +19,9 @@ namespace LibCmo::XContainer {
/**
@brief Set of bit flags.
@remark This class now use specialized std::vector<bool>.
@remark
+ This class now use specialized std::vector<bool>.
+ Do not use CKBOOL, because we want make sure it enable specialized std::vector<bool>.
*/
using XBitArray = std::vector<bool>;
@ -70,5 +70,40 @@ namespace LibCmo::XContainer {
template<class K, class T, class H = std::hash<K>, class Eq = std::equal_to<K>>
using XHashTable = std::unordered_map<K, T, H, Eq>;
// ========== Patch Section ==========
namespace NSXBitArray {
/**
* @brief Returns the position of the n-th set(1) bit
* @return false if not found.
*/
bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
/**
* @brief Returns the position of the n-th unset(0) bit
* @return false if not found.
*/
bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
}
namespace NSXString {
/**
* @brief Return CKSTRING statement of XString.
* @param strl The XString need to be output.
* @return Return the CKSTRING format of XString. if XString is blank, return nullptr.
*/
CKSTRING ToCKSTRING(const XString& strl);
/**
* @brief Copy CKSTRING to XString.
* @param strl The string dest.
* @param s The CKSTRING need to be copied. Pass nullptr will clear string dest.
*/
void FromCKSTRING(XString& strl, CKSTRING s);
}
}