Added KrCreateScene API

This commit is contained in:
2020-06-11 21:41:17 -07:00
parent 592f811d71
commit 18a2bb5688
7 changed files with 63 additions and 23 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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