libcmo21/LibCmo/CK2/CKContext.hpp

122 lines
4.3 KiB
C++
Raw Normal View History

2023-08-22 15:30:26 +08:00
#pragma once
#include "../VTAll.hpp"
#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();
2023-09-04 22:58:53 +08:00
LIBCMO_DISABLE_COPY_MOVE(CKContext);
// ========== 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
// ========== 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
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);
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;
// ========== 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();
void ExecuteManagersOnSequenceToBeDeleted(const CK_ID* objids, CKDWORD count);
void ExecuteManagersOnSequenceDeleted(const CK_ID* objids, CKDWORD count);
2023-08-28 14:18:58 +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
// ========== 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);
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);
protected:
CKINT m_CompressionLevel;
CK_FILE_WRITEMODE m_FileWriteMode;
CK_TEXTURE_SAVEOPTIONS m_GlobalImagesSaveOptions;
CK_SOUND_SAVEOPTIONS m_GlobalSoundsSaveOptions;
CKBitmapProperties m_GlobalImagesSaveFormat;
2023-09-04 22:58:53 +08:00
2023-08-23 16:04:58 +08:00
// ========== Encoding utilities ==========
public:
2023-09-16 18:31:25 +08:00
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:
2023-09-16 22:42:08 +08:00
XContainer::XArray<EncodingHelper::ENCODING_TOKEN> m_NameEncoding;
2023-08-23 16:04:58 +08:00
// ========== Print utilities ==========
public:
2023-08-23 16:04:58 +08:00
using OutputCallback = std::function<void(CKSTRING)>;
void OutputToConsole(CKSTRING str);
void OutputToConsoleEx(CKSTRING fmt, ...);
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
};
}