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