WIP async API and kraken_convert

This commit is contained in:
Kearwood Kip Gilbert
2019-08-03 18:53:05 -07:00
parent dfce8148e3
commit b9c737ac2f
7 changed files with 49 additions and 3 deletions

View File

@@ -51,6 +51,14 @@ KRBundle *KRBundleManager::loadBundle(const char *szName, KRDataBlock *pData)
return pBundle; return pBundle;
} }
KRBundle *KRBundleManager::createBundle(const char *szName)
{
// TODO: Check for name conflicts
KRBundle *pBundle = new KRBundle(*m_pContext, szName);
m_bundles[szName] = pBundle;
return pBundle;
}
KRBundle *KRBundleManager::getBundle(const char *szName) { KRBundle *KRBundleManager::getBundle(const char *szName) {
return m_bundles[szName]; return m_bundles[szName];
} }

View File

@@ -47,6 +47,7 @@ public:
KRBundle *loadBundle(const char *szName, KRDataBlock *pData); KRBundle *loadBundle(const char *szName, KRDataBlock *pData);
KRBundle *getBundle(const char *szName); KRBundle *getBundle(const char *szName);
KRBundle* createBundle(const char* szName);
std::vector<std::string> getBundleNames(); std::vector<std::string> getBundleNames();
unordered_map<std::string, KRBundle *> getBundles(); unordered_map<std::string, KRBundle *> getBundles();

View File

@@ -12,6 +12,7 @@
#include "KRCamera.h" #include "KRCamera.h"
#include "KRAudioManager.h" #include "KRAudioManager.h"
#include "KRAudioSample.h" #include "KRAudioSample.h"
#include "KRBundle.h"
#if defined(ANDROID) #if defined(ANDROID)
#include <chrono> #include <chrono>
@@ -333,6 +334,32 @@ KrResult KRContext::unloadResource(const KrUnloadResourceInfo* unloadResourceInf
return KR_ERROR_NOT_IMPLEMENTED; return KR_ERROR_NOT_IMPLEMENTED;
} }
KrResult KRContext::createBundle(const KrCreateBundleInfo* createBundleInfo)
{
if (createBundleInfo->resourceHandle < 0 || createBundleInfo->resourceHandle >= m_resourceMapSize) {
return KR_ERROR_OUT_OF_BOUNDS;
}
KRResource* bundle = m_pBundleManager->createBundle(createBundleInfo->pBundleName);
m_resourceMap[createBundleInfo->resourceHandle] = bundle;
return KR_SUCCESS;
}
KrResult KRContext::saveResource(const KrSaveResourceInfo* saveResourceInfo)
{
if (saveResourceInfo->resourceHandle < 0 || saveResourceInfo->resourceHandle >= m_resourceMapSize) {
return KR_ERROR_OUT_OF_BOUNDS;
}
KRResource* resource = m_resourceMap[saveResourceInfo->resourceHandle];
if (resource == nullptr) {
return KR_ERROR_NOT_MAPPED;
}
if (resource->save(saveResourceInfo->pResourcePath)) {
return KR_SUCCESS;
}
return KR_ERROR_UNEXPECTED;
}
void KRContext::detectExtensions() { void KRContext::detectExtensions() {
m_bDetectedExtensions = true; m_bDetectedExtensions = true;

View File

@@ -38,7 +38,9 @@ public:
KRContext(const KrInitializeInfo* initializeInfo); KRContext(const KrInitializeInfo* initializeInfo);
~KRContext(); ~KRContext();
KrResult createBundle(const KrCreateBundleInfo* createBundleInfo);
KrResult unloadResource(const KrUnloadResourceInfo* unloadResourceInfo); KrResult unloadResource(const KrUnloadResourceInfo* unloadResourceInfo);
KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo);
void loadResource(const std::string &file_name, KRDataBlock *data); void loadResource(const std::string &file_name, KRDataBlock *data);
void loadResource(std::string path); void loadResource(std::string path);

View File

@@ -1,6 +1,7 @@
#include "public/kraken.h" #include "public/kraken.h"
#include "KRContext.h" #include "KRContext.h"
#include "KRBundle.h"
namespace { namespace {
@@ -44,7 +45,10 @@ KrResult KrUnloadResource(const KrUnloadResourceInfo* pUnloadResourceInfo)
KrResult KrSaveResource(const KrSaveResourceInfo* pSaveResourceInfo) KrResult KrSaveResource(const KrSaveResourceInfo* pSaveResourceInfo)
{ {
return KR_ERROR_NOT_IMPLEMENTED; if (!sContext) {
return KR_ERROR_NOT_INITIALIZED;
}
return sContext->saveResource(pSaveResourceInfo);
} }
KrResult KrMapResource(const KrMapResourceInfo* pMapResourceInfo) KrResult KrMapResource(const KrMapResourceInfo* pMapResourceInfo)
@@ -59,7 +63,10 @@ KrResult KrUnmapResource(const KrUnmapResourceInfo* pUnmapResourceInfo)
KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo) KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo)
{ {
return KR_ERROR_NOT_IMPLEMENTED; if (!sContext) {
return KR_ERROR_NOT_INITIALIZED;
}
return sContext->createBundle(pCreateBundleInfo);
} }
KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo) KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo)

View File

@@ -41,6 +41,7 @@ typedef enum {
KR_ERROR_NOT_IMPLEMENTED = 2, KR_ERROR_NOT_IMPLEMENTED = 2,
KR_ERROR_OUT_OF_BOUNDS = 3, KR_ERROR_OUT_OF_BOUNDS = 3,
KR_ERROR_NOT_MAPPED = 4, KR_ERROR_NOT_MAPPED = 4,
KR_ERROR_UNEXPECTED = 0x10000000,
KR_RESULT_MAX_ENUM = 0x7FFFFFFF KR_RESULT_MAX_ENUM = 0x7FFFFFFF
} KrResult; } KrResult;

View File

@@ -59,7 +59,7 @@ int main( int argc, char *argv[] )
save_resource_info.pResourcePath = "output.krbundle"; save_resource_info.pResourcePath = "output.krbundle";
res = KrSaveResource(&save_resource_info); res = KrSaveResource(&save_resource_info);
if (res != KR_SUCCESS) { if (res != KR_SUCCESS) {
printf("Failed to save bundle.\n"); printf("Failed to save bundle.\nError %i\n", res);
} }
KrShutdown(); KrShutdown();