2023-08-22 15:30:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
2024-08-17 20:43:27 +08:00
|
|
|
#include "../VTInternal.hpp"
|
2023-08-22 15:30:26 +08:00
|
|
|
#include <map>
|
2023-08-23 16:04:58 +08:00
|
|
|
#include <deque>
|
2023-08-22 15:30:26 +08:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace LibCmo::CK2 {
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Main Interface Object
|
|
|
|
@details
|
|
|
|
+ The CKContext object is the heart of all Virtools based applications, It is the first object that should be created in order to
|
|
|
|
use Virtools SDK. A CKContext can be simply created by calling its constructor.
|
|
|
|
+ The CKContext object act as the central interface to create/destroy objects,to access managers, to load/save files.
|
|
|
|
+ Several CKContext can be created inside a same process (in multiple threads for example) but objects created
|
|
|
|
by a specific CKContext must not be used in other contextes.
|
|
|
|
@see CKContext::CreateObject, CKContext::GetObject, CKContext::DestroyObject
|
|
|
|
*/
|
|
|
|
class CKContext {
|
|
|
|
public:
|
|
|
|
CKContext();
|
|
|
|
~CKContext();
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEL_CLS_COPY_MOVE(CKContext);
|
2023-09-05 22:23:05 +08:00
|
|
|
|
|
|
|
// ========== Engine runtime ==========
|
|
|
|
public:
|
2023-08-22 15:30:26 +08:00
|
|
|
/**
|
2023-09-04 22:58:53 +08:00
|
|
|
* @brief Simply clear all CKContext to restore its status.
|
2023-08-22 15:30:26 +08:00
|
|
|
*/
|
2023-09-04 22:58:53 +08:00
|
|
|
void ClearAll();
|
2023-08-23 16:04:58 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
// ========== Objects Management / Access ==========
|
|
|
|
// These functions is a simply redirect to CKObjectManager
|
|
|
|
|
|
|
|
ObjImpls::CKObject* CreateObject(CK_CLASSID cls, CKSTRING name,
|
|
|
|
CK_OBJECTCREATION_OPTIONS options = CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECHECK,
|
|
|
|
CK_CREATIONMODE* res = nullptr);
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
ObjImpls::CKObject* GetObject(CK_ID ObjID);
|
|
|
|
CKDWORD GetObjectCount();
|
|
|
|
void DestroyObject(ObjImpls::CKObject *obj);
|
|
|
|
void DestroyObject(CK_ID id);
|
|
|
|
void DestroyObjects(CK_ID* obj_ids, CKDWORD Count);
|
|
|
|
|
|
|
|
ObjImpls::CKObject* GetObjectByName(CKSTRING name, ObjImpls::CKObject *previous = nullptr);
|
|
|
|
ObjImpls::CKObject* GetObjectByNameAndClass(CKSTRING name, CK_CLASSID cid, ObjImpls::CKObject *previous = nullptr);
|
2023-09-06 10:42:23 +08:00
|
|
|
ObjImpls::CKObject* GetObjectByNameAndParentClass(CKSTRING name, CK_CLASSID pcid, ObjImpls::CKObject* previous = nullptr);
|
2023-09-05 22:23:05 +08:00
|
|
|
const XContainer::XObjectPointerArray GetObjectListByType(CK_CLASSID cid, bool derived);
|
|
|
|
CKDWORD GetObjectsCountByClassID(CK_CLASSID cid);
|
|
|
|
CK_ID* GetObjectsListByClassID(CK_CLASSID cid);
|
|
|
|
|
2023-09-06 10:42:23 +08:00
|
|
|
protected:
|
|
|
|
XContainer::XObjectPointerArray m_ObjectPointerCache;
|
|
|
|
XContainer::XObjectArray m_ObjectCache;
|
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
// ========== Common Managers ==========
|
|
|
|
public:
|
2023-09-04 22:58:53 +08:00
|
|
|
MgrImpls::CKObjectManager* GetObjectManager();
|
|
|
|
MgrImpls::CKPathManager* GetPathManager();
|
2023-08-23 16:04:58 +08:00
|
|
|
|
2023-09-04 22:58:53 +08:00
|
|
|
CKDWORD GetManagerCount();
|
|
|
|
MgrImpls::CKBaseManager* GetManager(CKDWORD index);
|
2023-08-28 14:18:58 +08:00
|
|
|
|
2023-09-04 22:58:53 +08:00
|
|
|
void ExecuteManagersOnPreClearAll();
|
|
|
|
void ExecuteManagersOnPostClearAll();
|
2023-09-05 22:23:05 +08:00
|
|
|
void ExecuteManagersOnSequenceToBeDeleted(const CK_ID* objids, CKDWORD count);
|
|
|
|
void ExecuteManagersOnSequenceDeleted(const CK_ID* objids, CKDWORD count);
|
2023-08-28 14:18:58 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
protected:
|
|
|
|
void ExecuteManagersGeneral(std::function<void(MgrImpls::CKBaseManager*)> fct);
|
|
|
|
XContainer::XArray<MgrImpls::CKBaseManager*> m_ManagerList;
|
|
|
|
|
|
|
|
MgrImpls::CKObjectManager* m_ObjectManager;
|
|
|
|
MgrImpls::CKPathManager* m_PathManager;
|
2023-09-04 22:58:53 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
// ========== File Save/Load Options ==========
|
|
|
|
public:
|
2023-08-28 14:18:58 +08:00
|
|
|
void SetCompressionLevel(CKINT level);
|
|
|
|
CKINT GetCompressionLevel();
|
|
|
|
|
|
|
|
void SetFileWriteMode(CK_FILE_WRITEMODE mode);
|
|
|
|
CK_FILE_WRITEMODE GetFileWriteMode();
|
|
|
|
|
2023-09-04 22:58:53 +08:00
|
|
|
CK_TEXTURE_SAVEOPTIONS GetGlobalImagesSaveOptions();
|
|
|
|
void SetGlobalImagesSaveOptions(CK_TEXTURE_SAVEOPTIONS Options);
|
|
|
|
|
2023-09-07 21:57:48 +08:00
|
|
|
const CKBitmapProperties& GetGlobalImagesSaveFormat();
|
|
|
|
void SetGlobalImagesSaveFormat(const CKBitmapProperties& Format);
|
2023-09-04 22:58:53 +08:00
|
|
|
|
|
|
|
CK_SOUND_SAVEOPTIONS GetGlobalSoundsSaveOptions();
|
|
|
|
void SetGlobalSoundsSaveOptions(CK_SOUND_SAVEOPTIONS Options);
|
2023-09-05 22:23:05 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
CKINT m_CompressionLevel;
|
|
|
|
CK_FILE_WRITEMODE m_FileWriteMode;
|
|
|
|
CK_TEXTURE_SAVEOPTIONS m_GlobalImagesSaveOptions;
|
|
|
|
CK_SOUND_SAVEOPTIONS m_GlobalSoundsSaveOptions;
|
2023-09-07 21:57:48 +08:00
|
|
|
CKBitmapProperties m_GlobalImagesSaveFormat;
|
2023-09-04 22:58:53 +08:00
|
|
|
|
2023-08-23 16:04:58 +08:00
|
|
|
// ========== Encoding utilities ==========
|
2023-09-05 22:23:05 +08:00
|
|
|
public:
|
2024-08-23 11:28:49 +08:00
|
|
|
/**
|
|
|
|
* @brief Convert given ordinary string to UTF8 string.
|
|
|
|
* @param[in] native_name The input ordinary string.
|
|
|
|
* @param[out] u8_name The output UTF8 string.
|
|
|
|
* @exception RuntimeException Raised when perform this operation with a blank encoding sequence.
|
|
|
|
* @remarks
|
|
|
|
* The encoding of ordinary is specified by encoding sequence.
|
|
|
|
* If we fail to do convertion, the result will leave to blank and output a message to CKContext.
|
|
|
|
* However, if you use this function with blank encoding sequence, it will raise exception.
|
2024-08-23 17:38:45 +08:00
|
|
|
* So becore using this function, please make sure that you have checked by calling IsValidEncoding().
|
2024-08-23 11:28:49 +08:00
|
|
|
*/
|
|
|
|
void GetUTF8String(const std::string& native_name, XContainer::XString& u8_name);
|
|
|
|
/**
|
|
|
|
* @brief Convert given UTF8 string to ordinary string.
|
|
|
|
* @param[in] u8_name The input UTF8 string.
|
|
|
|
* @param[out] native_name The output ordinary string.
|
|
|
|
* @exception RuntimeException Raised when perform this operation with a blank encoding sequence.
|
|
|
|
* @remarks
|
|
|
|
* The encoding of ordinary is specified by encoding sequence.
|
|
|
|
* If we fail to do convertion, the result will leave to blank and output a message to CKContext.
|
|
|
|
* However, if you use this function with blank encoding sequence, it will raise exception.
|
2024-08-23 17:38:45 +08:00
|
|
|
* So becore using this function, please make sure that you have checked by calling IsValidEncoding().
|
2024-08-23 11:28:49 +08:00
|
|
|
*/
|
|
|
|
void GetOrdinaryString(const XContainer::XString& u8_name, std::string& native_name);
|
|
|
|
/**
|
|
|
|
* @brief Set the encoding sequence.
|
|
|
|
* @param[in] encoding_series The encoding name in this sequence.
|
|
|
|
* @remarks
|
|
|
|
* \li The order in encoding sequence is important. The encoding name with lower index will be used for convertion first.
|
|
|
|
* \li Encoding sequence will be used for performing GetUTF8String() and GetOrdinaryString().
|
|
|
|
* We will try using it to do convertion from top to bottom (if one failed we will continue trying to use next one to do convertion).
|
|
|
|
*/
|
2023-09-23 16:25:26 +08:00
|
|
|
void SetEncoding(const XContainer::XArray<XContainer::XString>& encoding_series);
|
2024-08-23 11:28:49 +08:00
|
|
|
/**
|
|
|
|
* @brief Clear specified encoding sequence.
|
|
|
|
*/
|
|
|
|
void ClearEncoding();
|
|
|
|
/**
|
|
|
|
* @brief Check whether current encoding sequence at least has one valid encoding for convertion.
|
|
|
|
* @return True if it is, otherwise false.
|
|
|
|
*/
|
|
|
|
bool IsValidEncoding();
|
2023-09-05 22:23:05 +08:00
|
|
|
|
|
|
|
protected:
|
2024-08-23 11:28:49 +08:00
|
|
|
XContainer::XArray<EncodingHelper::EncodingToken> m_NameEncoding;
|
2023-08-23 16:04:58 +08:00
|
|
|
|
|
|
|
// ========== Print utilities ==========
|
2023-09-05 22:23:05 +08:00
|
|
|
public:
|
2024-08-23 11:28:49 +08:00
|
|
|
/**
|
|
|
|
* @brief The callback prototype.
|
|
|
|
* @details It accept a CKSTRING representing the string need to be printed.
|
|
|
|
* The passed CKSTRING is guaranteen that it can not be nullptr.
|
|
|
|
*/
|
|
|
|
using OutputCallback = void(*)(CKSTRING);
|
|
|
|
/**
|
|
|
|
* @brief Output plain message.
|
|
|
|
* @param[in] str Plain message. nullptr is allowed but not suggested.
|
|
|
|
*/
|
2023-08-23 16:04:58 +08:00
|
|
|
void OutputToConsole(CKSTRING str);
|
2024-08-23 11:28:49 +08:00
|
|
|
/**
|
|
|
|
* @brief Output message with given format.
|
|
|
|
* @param[in] fmt The format string. nullptr is allowed but not suggested.
|
|
|
|
* @param[in] ... The arguments of format string.
|
|
|
|
*/
|
2023-08-23 16:04:58 +08:00
|
|
|
void OutputToConsoleEx(CKSTRING fmt, ...);
|
2024-08-23 11:28:49 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the callback for message printing.
|
|
|
|
* @param[in] cb The function pointer to callback. nullptr to remove callback.
|
|
|
|
*/
|
2023-08-23 16:04:58 +08:00
|
|
|
void SetOutputCallback(OutputCallback cb);
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-08-23 16:04:58 +08:00
|
|
|
protected:
|
|
|
|
OutputCallback m_OutputCallback;
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|