From 18a2bb56887ec03012faa250e54e527ece6fcd52 Mon Sep 17 00:00:00 2001 From: Kearwood Date: Thu, 11 Jun 2020 21:41:17 -0700 Subject: [PATCH] Added KrCreateScene API --- kraken/KRContext.cpp | 10 +++++++++ kraken/KRContext.h | 2 ++ kraken/KRDataBlock.cpp | 46 +++++++++++++++++++-------------------- kraken/KRSceneManager.cpp | 9 ++++++++ kraken/KRSceneManager.h | 2 ++ kraken/kraken.cpp | 8 +++++++ kraken/public/kraken.h | 9 ++++++++ 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/kraken/KRContext.cpp b/kraken/KRContext.cpp index d7b5692..cb0a0f6 100755 --- a/kraken/KRContext.cpp +++ b/kraken/KRContext.cpp @@ -429,6 +429,16 @@ KrResult KRContext::mapResource(const KrMapResourceInfo* mapResourceInfo) return KR_ERROR_NOT_IMPLEMENTED; } +KrResult KRContext::createScene(const KrCreateSceneInfo* createSceneInfo) +{ + if (createSceneInfo->resourceHandle < 0 || createSceneInfo->resourceHandle >= m_resourceMapSize) { + return KR_ERROR_OUT_OF_BOUNDS; + } + KRScene* scene = m_pSceneManager->createScene(createSceneInfo->pSceneName); + m_resourceMap[createSceneInfo->resourceHandle] = scene; + return KR_SUCCESS; +} + KrResult KRContext::createBundle(const KrCreateBundleInfo* createBundleInfo) { if (createBundleInfo->resourceHandle < 0 || createBundleInfo->resourceHandle >= m_resourceMapSize) { diff --git a/kraken/KRContext.h b/kraken/KRContext.h index eecf6c3..5a1fdfe 100755 --- a/kraken/KRContext.h +++ b/kraken/KRContext.h @@ -47,6 +47,8 @@ public: KrResult mapResource(const KrMapResourceInfo* mapResourceInfo); KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo); + KrResult createScene(const KrCreateSceneInfo* createSceneInfo); + KRResource* loadResource(const std::string &file_name, KRDataBlock *data); diff --git a/kraken/KRDataBlock.cpp b/kraken/KRDataBlock.cpp index 505fbee..e348801 100755 --- a/kraken/KRDataBlock.cpp +++ b/kraken/KRDataBlock.cpp @@ -419,29 +419,29 @@ std::string KRDataBlock::getString() #if defined(_WIN32) || defined(_WIN64) void ReportWindowsLastError(LPCTSTR lpszFunction) { - LPVOID lpMsgBuf; - LPVOID lpDisplayBuf; - DWORD dw = GetLastError(); - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, - 0, NULL); - - // Display the error message and exit the process - - lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, - (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); - fprintf(stderr, - TEXT("%s failed with error %d: %s\n"), - lpszFunction, dw, lpMsgBuf); - - LocalFree(lpMsgBuf); + LPVOID lpMsgBuf; + LPVOID lpDisplayBuf; + DWORD dw = GetLastError(); + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&lpMsgBuf, + 0, NULL); + + // Display the error message and exit the process + + lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, + (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); + fprintf(stderr, + TEXT("%s failed with error %d: %s\n"), + lpszFunction, dw, lpMsgBuf); + + LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); } #endif diff --git a/kraken/KRSceneManager.cpp b/kraken/KRSceneManager.cpp index ac91696..104ed87 100755 --- a/kraken/KRSceneManager.cpp +++ b/kraken/KRSceneManager.cpp @@ -67,6 +67,15 @@ KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) { return pScene; } + +KRScene* KRSceneManager::createScene(const std::string& name) +{ + // TODO: Check for name conflicts + KRScene* pScene = new KRScene(*m_pContext, name); + add(pScene); + return pScene; +} + void KRSceneManager::add(KRScene *scene) { std::string lowerName = scene->getName(); diff --git a/kraken/KRSceneManager.h b/kraken/KRSceneManager.h index 9387496..6027eaf 100755 --- a/kraken/KRSceneManager.h +++ b/kraken/KRSceneManager.h @@ -49,6 +49,8 @@ public: virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override; virtual KRResource* getResource(const std::string& name, const std::string& extension) override; + KRScene* createScene(const std::string& name); + void add(KRScene *scene); KRScene *loadScene(const std::string &name, KRDataBlock *data); diff --git a/kraken/kraken.cpp b/kraken/kraken.cpp index eb3a22c..6f097cb 100644 --- a/kraken/kraken.cpp +++ b/kraken/kraken.cpp @@ -78,3 +78,11 @@ KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo) } return sContext->moveToBundle(pMoveToBundleInfo); } + +KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo) +{ + if (!sContext) { + return KR_ERROR_NOT_INITIALIZED; + } + return sContext->createScene(pCreateSceneInfo); +} diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 48788d9..36838ec 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -56,6 +56,7 @@ typedef enum { KR_STRUCTURE_TYPE_UNMAP_RESOURCE = 0x00010004, KR_STRUCTURE_TYPE_CREATE_BUNDLE = 0x00010005, KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE = 0x00010006, + KR_STRUCTURE_TYPE_CREATE_SCENE = 0x00020000, KR_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF } KrStructureType; @@ -107,6 +108,12 @@ typedef struct { KrResourceMapIndex bundleHandle; } KrMoveToBundleInfo; +typedef struct { + KrStructureType sType; + const char* pSceneName; + KrResourceMapIndex resourceHandle; +} KrCreateSceneInfo; + KrResult KrInitialize(const KrInitializeInfo* pInitializeInfo); KrResult KrShutdown(); KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo); @@ -117,4 +124,6 @@ KrResult KrUnmapResource(const KrUnmapResourceInfo* pUnmapResourceInfo); KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo); KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo); +KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo); + #endif // KRAKEN_H