Implemented KrMapResource
This commit is contained in:
@@ -419,14 +419,24 @@ KrResult KRContext::mapResource(const KrMapResourceInfo* mapResourceInfo)
|
|||||||
return KR_ERROR_OUT_OF_BOUNDS;
|
return KR_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
std::string lowerName = mapResourceInfo->pResourceName;
|
||||||
KRResource* resource = loadResource(loadResourceInfo->pResourcePath, data);
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
m_resourceMap[loadResourceInfo->resourceHandle] = resource;
|
lowerName.begin(), ::tolower);
|
||||||
return KR_SUCCESS;
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO - Need to implement mapping logic
|
KRResource* resource = nullptr;
|
||||||
return KR_ERROR_NOT_IMPLEMENTED;
|
|
||||||
|
std::pair<unordered_multimap<std::string, KRResource*>::iterator, unordered_multimap<std::string, KRResource*>::iterator> range = m_resources.equal_range(lowerName);
|
||||||
|
for (unordered_multimap<std::string, KRResource*>::iterator itr_match = range.first; itr_match != range.second; itr_match++) {
|
||||||
|
if (resource != nullptr) {
|
||||||
|
return KR_ERROR_AMBIGUOUS_MATCH;
|
||||||
|
}
|
||||||
|
resource = itr_match->second;
|
||||||
|
}
|
||||||
|
if (resource == nullptr) {
|
||||||
|
return KR_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
m_resourceMap[mapResourceInfo->resourceHandle] = resource;
|
||||||
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KRContext::unmapResource(const KrUnmapResourceInfo* unmapResourceInfo)
|
KrResult KRContext::unmapResource(const KrUnmapResourceInfo* unmapResourceInfo)
|
||||||
@@ -435,6 +445,8 @@ KrResult KRContext::unmapResource(const KrUnmapResourceInfo* unmapResourceInfo)
|
|||||||
return KR_ERROR_OUT_OF_BOUNDS;
|
return KR_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
m_resourceMap[unmapResourceInfo->resourceHandle] = nullptr;
|
m_resourceMap[unmapResourceInfo->resourceHandle] = nullptr;
|
||||||
|
// TODO - Delete objects after lass dereference
|
||||||
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KRContext::createScene(const KrCreateSceneInfo* createSceneInfo)
|
KrResult KRContext::createScene(const KrCreateSceneInfo* createSceneInfo)
|
||||||
@@ -753,3 +765,27 @@ KrResult KRContext::updateNode(const KrUpdateNodeInfo* pUpdateNodeInfo)
|
|||||||
{
|
{
|
||||||
return KR_ERROR_NOT_IMPLEMENTED;
|
return KR_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRContext::addResource(KRResource* resource, const std::string& name)
|
||||||
|
{
|
||||||
|
std::string lowerName = name;
|
||||||
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
|
lowerName.begin(), ::tolower);
|
||||||
|
|
||||||
|
m_resources.insert(std::pair<std::string, KRResource*>(lowerName, resource));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRContext::removeResource(KRResource* resource)
|
||||||
|
{
|
||||||
|
std::string lowerName = resource->getName();
|
||||||
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
|
lowerName.begin(), ::tolower);
|
||||||
|
|
||||||
|
std::pair<unordered_multimap<std::string, KRResource*>::iterator, unordered_multimap<std::string, KRResource*>::iterator> range = m_resources.equal_range(lowerName);
|
||||||
|
for (unordered_multimap<std::string, KRResource*>::iterator itr_match = range.first; itr_match != range.second; itr_match++) {
|
||||||
|
if (itr_match->second == resource) {
|
||||||
|
m_resources.erase(itr_match);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ public:
|
|||||||
#if TARGET_OS_MAC
|
#if TARGET_OS_MAC
|
||||||
static void attachToView(void *view);
|
static void attachToView(void *view);
|
||||||
#endif
|
#endif
|
||||||
|
void addResource(KRResource* resource, const std::string& name);
|
||||||
|
void removeResource(KRResource* resource);
|
||||||
private:
|
private:
|
||||||
KRBundleManager *m_pBundleManager;
|
KRBundleManager *m_pBundleManager;
|
||||||
KRSceneManager *m_pSceneManager;
|
KRSceneManager *m_pSceneManager;
|
||||||
@@ -167,6 +168,8 @@ private:
|
|||||||
|
|
||||||
void createDeviceContexts();
|
void createDeviceContexts();
|
||||||
void destroyDeviceContexts();
|
void destroyDeviceContexts();
|
||||||
|
|
||||||
|
unordered_multimap<std::string, KRResource*> m_resources;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,12 +9,14 @@
|
|||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRBundle.h"
|
#include "KRBundle.h"
|
||||||
|
#include "KRContext.h"
|
||||||
|
|
||||||
KRResource::KRResource(KRContext &context, std::string name) : KRContextObject(context) {
|
KRResource::KRResource(KRContext &context, std::string name) : KRContextObject(context) {
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
context.addResource(this, name);
|
||||||
}
|
}
|
||||||
KRResource::~KRResource() {
|
KRResource::~KRResource() {
|
||||||
|
m_pContext->removeResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KRResource::getName()
|
std::string KRResource::getName()
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ typedef enum {
|
|||||||
KR_ERROR_OUT_OF_BOUNDS = 3,
|
KR_ERROR_OUT_OF_BOUNDS = 3,
|
||||||
KR_ERROR_NOT_MAPPED = 4,
|
KR_ERROR_NOT_MAPPED = 4,
|
||||||
KR_ERROR_INCORRECT_TYPE = 5,
|
KR_ERROR_INCORRECT_TYPE = 5,
|
||||||
|
KR_ERROR_NOT_FOUND = 6,
|
||||||
|
KR_ERROR_AMBIGUOUS_MATCH = 7,
|
||||||
KR_ERROR_UNEXPECTED = 0x10000000,
|
KR_ERROR_UNEXPECTED = 0x10000000,
|
||||||
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||||
} KrResult;
|
} KrResult;
|
||||||
|
|||||||
Reference in New Issue
Block a user