diff --git a/kraken/CMakeLists.txt b/kraken/CMakeLists.txt index 52a2fd4..4a42c5f 100644 --- a/kraken/CMakeLists.txt +++ b/kraken/CMakeLists.txt @@ -64,6 +64,7 @@ add_sources(KRResource+blend.cpp) # add_sources(KRResource+fbx.cpp) # TODO - Locate FBX SDK dependencies add_sources(KRResource+obj.cpp) add_sources(KRResource.cpp) +add_sources(KRResourceManager.cpp) add_sources(KRReverbZone.cpp) add_sources(KRScene.cpp) add_sources(KRSceneManager.cpp) diff --git a/kraken/KRAnimationCurveManager.cpp b/kraken/KRAnimationCurveManager.cpp index 08c6cbe..02c6c41 100755 --- a/kraken/KRAnimationCurveManager.cpp +++ b/kraken/KRAnimationCurveManager.cpp @@ -32,7 +32,7 @@ #include "KRAnimationCurveManager.h" #include "KRAnimationCurve.h" -KRAnimationCurveManager::KRAnimationCurveManager(KRContext &context) : KRContextObject(context) +KRAnimationCurveManager::KRAnimationCurveManager(KRContext &context) : KRResourceManager(context) { } @@ -48,6 +48,21 @@ void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve *curve) { delete curve; } +KRResource* KRAnimationCurveManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("kranimationcurve") == 0) { + return loadAnimationCurve(name, data); + } + return nullptr; +} +KRResource* KRAnimationCurveManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("kranimationcurve") == 0) { + return getAnimationCurve(name); + } + return nullptr; +} + KRAnimationCurve *KRAnimationCurveManager::loadAnimationCurve(const std::string &name, KRDataBlock *data) { KRAnimationCurve *pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data); if(pAnimationCurve) { diff --git a/kraken/KRAnimationCurveManager.h b/kraken/KRAnimationCurveManager.h index 4d59be2..0a7caa4 100755 --- a/kraken/KRAnimationCurveManager.h +++ b/kraken/KRAnimationCurveManager.h @@ -34,17 +34,22 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRAnimationCurve.h" #include "KRContextObject.h" #include "KRDataBlock.h" using std::map; -class KRAnimationCurveManager : public KRContextObject { +class KRAnimationCurveManager : public KRResourceManager { public: KRAnimationCurveManager(KRContext &context); virtual ~KRAnimationCurveManager(); - + + 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; + KRAnimationCurve *loadAnimationCurve(const std::string &name, KRDataBlock *data); KRAnimationCurve *getAnimationCurve(const std::string &name); void addAnimationCurve(KRAnimationCurve *new_animation_curve); diff --git a/kraken/KRAnimationManager.cpp b/kraken/KRAnimationManager.cpp index 40e3667..77b2dae 100755 --- a/kraken/KRAnimationManager.cpp +++ b/kraken/KRAnimationManager.cpp @@ -32,7 +32,7 @@ #include "KRAnimationManager.h" #include "KRAnimation.h" -KRAnimationManager::KRAnimationManager(KRContext &context) : KRContextObject(context) +KRAnimationManager::KRAnimationManager(KRContext &context) : KRResourceManager(context) { } @@ -81,6 +81,20 @@ void KRAnimationManager::endFrame(float deltaTime) } +KRResource* KRAnimationManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("kranimation") == 0) { + return loadAnimation(name.c_str(), data); + } + return nullptr; +} +KRResource* KRAnimationManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("kranimation") == 0) { + return getAnimation(name.c_str()); + } + return nullptr; +} KRAnimation *KRAnimationManager::loadAnimation(const char *szName, KRDataBlock *data) { KRAnimation *pAnimation = KRAnimation::Load(*m_pContext, szName, data); diff --git a/kraken/KRAnimationManager.h b/kraken/KRAnimationManager.h index 34a06f0..b1393b3 100755 --- a/kraken/KRAnimationManager.h +++ b/kraken/KRAnimationManager.h @@ -34,16 +34,21 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRAnimation.h" #include "KRContextObject.h" #include "KRDataBlock.h" -class KRAnimationManager : public KRContextObject { +class KRAnimationManager : public KRResourceManager { public: KRAnimationManager(KRContext &context); virtual ~KRAnimationManager(); + + 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; KRAnimation *loadAnimation(const char *szName, KRDataBlock *data); KRAnimation *getAnimation(const char *szName); diff --git a/kraken/KRAudioManager.cpp b/kraken/KRAudioManager.cpp index 0c20ea3..9e0f426 100755 --- a/kraken/KRAudioManager.cpp +++ b/kraken/KRAudioManager.cpp @@ -39,7 +39,7 @@ #include "KRDSP.h" KRAudioManager::KRAudioManager(KRContext &context) - : KRContextObject(context) + : KRResourceManager(context) , m_initialized(false) { m_enable_audio = true; @@ -1248,6 +1248,25 @@ void KRAudioManager::add(KRAudioSample *sound) } } +KRResource* KRAudioManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("mtl") == 0 || + extension.compare("mp3") == 0 || + extension.compare("wav") == 0) { + return load(name, extension, data); + } + return nullptr; +} +KRResource* KRAudioManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("mtl") == 0 || + extension.compare("mp3") == 0 || + extension.compare("wav") == 0) { + return get(name); + } + return nullptr; +} + KRAudioSample *KRAudioManager::load(const std::string &name, const std::string &extension, KRDataBlock *data) { KRAudioSample *Sound = new KRAudioSample(getContext(), name, extension, data); diff --git a/kraken/KRAudioManager.h b/kraken/KRAudioManager.h index 5ef7c59..52297f5 100755 --- a/kraken/KRAudioManager.h +++ b/kraken/KRAudioManager.h @@ -34,6 +34,8 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRContextObject.h" #include "KRDataBlock.h" #include "KRAudioSource.h" @@ -90,10 +92,13 @@ typedef struct { KRAudioSample *reverb_sample; } siren_reverb_zone_weight_info; -class KRAudioManager : public KRContextObject { +class KRAudioManager : public KRResourceManager { public: KRAudioManager(KRContext &context); virtual ~KRAudioManager(); + + 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; unordered_map &getSounds(); diff --git a/kraken/KRBundleManager.cpp b/kraken/KRBundleManager.cpp index 1af76e4..1465e0f 100755 --- a/kraken/KRBundleManager.cpp +++ b/kraken/KRBundleManager.cpp @@ -33,7 +33,7 @@ #include "KRBundle.h" -KRBundleManager::KRBundleManager(KRContext &context) : KRContextObject(context) { +KRBundleManager::KRBundleManager(KRContext &context) : KRResourceManager(context) { } @@ -44,6 +44,21 @@ KRBundleManager::~KRBundleManager() { m_bundles.empty(); } +KRResource* KRBundleManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("krbundle") == 0) { + return loadBundle(name.c_str() , data); + } + return nullptr; +} +KRResource* KRBundleManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("krbundle") == 0) { + return getBundle(name.c_str()); + } + return nullptr; +} + KRBundle *KRBundleManager::loadBundle(const char *szName, KRDataBlock *pData) { KRBundle *pBundle = new KRBundle(*m_pContext, szName, pData); diff --git a/kraken/KRBundleManager.h b/kraken/KRBundleManager.h index 8fe0e0d..235cb7c 100755 --- a/kraken/KRBundleManager.h +++ b/kraken/KRBundleManager.h @@ -33,6 +33,8 @@ #ifndef KRBUNDLEMANAGER_H #define KRBUNDLEMANAGER_H +#include "KRResourceManager.h" + #include "KREngine-common.h" #include "KRContextObject.h" #include "KRDataBlock.h" @@ -40,10 +42,13 @@ class KRContext; class KRBundle; -class KRBundleManager : public KRContextObject { +class KRBundleManager : public KRResourceManager { public: KRBundleManager(KRContext &context); ~KRBundleManager(); + + 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; KRBundle *loadBundle(const char *szName, KRDataBlock *pData); KRBundle *getBundle(const char *szName); diff --git a/kraken/KRContext.cpp b/kraken/KRContext.cpp index a3617c0..d7b5692 100755 --- a/kraken/KRContext.cpp +++ b/kraken/KRContext.cpp @@ -413,6 +413,22 @@ KrResult KRContext::unloadResource(const KrUnloadResourceInfo* unloadResourceInf return KR_ERROR_NOT_IMPLEMENTED; } +KrResult KRContext::mapResource(const KrMapResourceInfo* mapResourceInfo) +{ + if (mapResourceInfo->resourceHandle < 0 || mapResourceInfo->resourceHandle >= m_resourceMapSize) { + return KR_ERROR_OUT_OF_BOUNDS; + } + +/* + KRResource* resource = loadResource(loadResourceInfo->pResourcePath, data); + m_resourceMap[loadResourceInfo->resourceHandle] = resource; + return KR_SUCCESS; +*/ + + // TODO - Need to implement mapping logic + return KR_ERROR_NOT_IMPLEMENTED; +} + 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 4908f2f..eecf6c3 100755 --- a/kraken/KRContext.h +++ b/kraken/KRContext.h @@ -44,6 +44,7 @@ public: KrResult moveToBundle(const KrMoveToBundleInfo* moveToBundleInfo); KrResult loadResource(const KrLoadResourceInfo* loadResourceInfo); KrResult unloadResource(const KrUnloadResourceInfo* unloadResourceInfo); + KrResult mapResource(const KrMapResourceInfo* mapResourceInfo); KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo); KRResource* loadResource(const std::string &file_name, KRDataBlock *data); diff --git a/kraken/KRMaterialManager.cpp b/kraken/KRMaterialManager.cpp index 57892f6..59d38e2 100755 --- a/kraken/KRMaterialManager.cpp +++ b/kraken/KRMaterialManager.cpp @@ -33,7 +33,7 @@ #include "KRMaterialManager.h" -KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRPipelineManager *pPipelineManager) : KRContextObject(context) +KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRPipelineManager *pPipelineManager) : KRResourceManager(context) { m_pTextureManager = pTextureManager; m_pPipelineManager = pPipelineManager; @@ -43,6 +43,24 @@ KRMaterialManager::~KRMaterialManager() { } +KRResource* KRMaterialManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("mtl") == 0) { + return load(name.c_str(), data); + } + return nullptr; +} + +KRResource* KRMaterialManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("mtl") == 0) { + // TODO - This is not correct -- there are multiple materials emitted in a single mtl file. + // We should treat "mtl" files as source files, managed by KRSource, which output + // material resources when compiled. + return m_materials[name]; + } + return nullptr; +} unordered_map &KRMaterialManager::getMaterials() { diff --git a/kraken/KRMaterialManager.h b/kraken/KRMaterialManager.h index 686b3ef..a960a35 100755 --- a/kraken/KRMaterialManager.h +++ b/kraken/KRMaterialManager.h @@ -32,11 +32,10 @@ #ifndef KRMATERIALMANAGER_H #define KRMATERIALMANAGER_H - - - #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRMaterial.h" #include "KRTextureManager.h" #include "KRMaterialManager.h" @@ -44,10 +43,13 @@ using std::map; -class KRMaterialManager : public KRContextObject { +class KRMaterialManager : public KRResourceManager { public: KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRPipelineManager *pPipelineManager); virtual ~KRMaterialManager(); + + 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; KRMaterial* load(const char *szName, KRDataBlock *data); void add(KRMaterial *new_material); diff --git a/kraken/KRMesh.cpp b/kraken/KRMesh.cpp index 5fa218c..f92c453 100755 --- a/kraken/KRMesh.cpp +++ b/kraken/KRMesh.cpp @@ -61,25 +61,32 @@ KRMesh::KRMesh(KRContext &context, std::string name, KRDataBlock *data) : KRReso loadPack(data); } -void KRMesh::setName(const std::string name) { - m_lodCoverage = 100; - m_lodBaseName = name; - - size_t last_underscore_pos = name.find_last_of('_'); - if(last_underscore_pos != std::string::npos) { - // Found an underscore - std::string suffix = name.substr(last_underscore_pos + 1); - if(suffix.find("lod") == 0) { - std::string lod_level_string = suffix.substr(3); - char *end = NULL; - int c = (int)strtol(lod_level_string.c_str(), &end, 10); - if(c >= 0 && c <= 100 && *end == '\0') { - m_lodCoverage = c; - m_lodBaseName = name.substr(0, last_underscore_pos); - } - } - } +void KRMesh::parseName(const std::string& name, std::string& lodBaseName, int& lodCoverage) +{ + lodCoverage = 100; + lodBaseName = name; + + size_t last_underscore_pos = name.find_last_of('_'); + if (last_underscore_pos != std::string::npos) { + // Found an underscore + std::string suffix = name.substr(last_underscore_pos + 1); + if (suffix.find("lod") == 0) { + std::string lod_level_string = suffix.substr(3); + char* end = NULL; + int c = (int)strtol(lod_level_string.c_str(), &end, 10); + if (c >= 0 && c <= 100 && *end == '\0') { + lodCoverage = c; + lodBaseName = name.substr(0, last_underscore_pos); + } + } + } +} + +void KRMesh::setName(const std::string name) { + parseName(name, m_lodBaseName, m_lodCoverage); + m_lodCoverage = 100; + m_lodBaseName = name; } int KRMesh::GetLODCoverage(const std::string &name) diff --git a/kraken/KRMesh.h b/kraken/KRMesh.h index ebcac52..ce9b242 100755 --- a/kraken/KRMesh.h +++ b/kraken/KRMesh.h @@ -60,8 +60,7 @@ class KRNode; class KRMesh : public KRResource { public: - - + static void parseName(const std::string& name, std::string& lodBaseName, int& lodCoverage); KRMesh(KRContext &context, std::string name, KRDataBlock *data); KRMesh(KRContext &context, std::string name); diff --git a/kraken/KRMeshManager.cpp b/kraken/KRMeshManager.cpp index 66884d6..811c5f2 100755 --- a/kraken/KRMeshManager.cpp +++ b/kraken/KRMeshManager.cpp @@ -38,7 +38,7 @@ #include "KRMeshQuad.h" #include "KRMeshSphere.h" -KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) { +KRMeshManager::KRMeshManager(KRContext &context) : KRResourceManager(context) { m_currentVBO = NULL; m_vboMemUsed = 0; m_memoryTransferredThisFrame = 0; @@ -102,6 +102,29 @@ KRMeshManager::~KRMeshManager() { m_models.empty(); } +KRResource* KRMeshManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("krmesh") == 0) { + return loadModel(name.c_str(), data); + } + return nullptr; +} +KRResource* KRMeshManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("krmesh") == 0) { + std::string lodBaseName; + int lodCoverage; + KRMesh::parseName(name, lodBaseName, lodCoverage); + std::vector models = getModel(lodBaseName.c_str()); + for (KRMesh* mesh : models) { + if (mesh->getLODCoverage() == lodCoverage) { + return mesh; + } + } + } + return nullptr; +} + KRMesh *KRMeshManager::loadModel(const char *szName, KRDataBlock *pData) { KRMesh *pModel = new KRMesh(*m_pContext, szName, pData); addModel(pModel); diff --git a/kraken/KRMeshManager.h b/kraken/KRMeshManager.h index 74842e0..0571105 100755 --- a/kraken/KRMeshManager.h +++ b/kraken/KRMeshManager.h @@ -33,6 +33,8 @@ #define KRMESHMANAGER_H #include "KREngine-common.h" + +#include "KRResourceManager.h" #include "KRContextObject.h" #include "KRDataBlock.h" #include "KRNode.h" @@ -40,13 +42,16 @@ class KRContext; class KRMesh; -class KRMeshManager : public KRContextObject { +class KRMeshManager : public KRResourceManager { public: static const int KRENGINE_MAX_VOLUMETRIC_PLANES=500; static const int KRENGINE_MAX_RANDOM_PARTICLES=150000; KRMeshManager(KRContext &context); virtual ~KRMeshManager(); + + 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; void startFrame(float deltaTime); void endFrame(float deltaTime); diff --git a/kraken/KRResourceManager.cpp b/kraken/KRResourceManager.cpp new file mode 100644 index 0000000..68f83c4 --- /dev/null +++ b/kraken/KRResourceManager.cpp @@ -0,0 +1,43 @@ +// +// KRResourceManager.cpp +// KREngine +// +// Copyright 2019 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +#include "KRResourceManager.h" +#include "KREngine-common.h" + +KRResourceManager::KRResourceManager(KRContext &context) : KRContextObject(context) +{ + +} + +KRResourceManager::~KRResourceManager() +{ + +} diff --git a/kraken/KRResourceManager.h b/kraken/KRResourceManager.h new file mode 100644 index 0000000..130a2ff --- /dev/null +++ b/kraken/KRResourceManager.h @@ -0,0 +1,50 @@ +// +// KRResourceManager.h +// KREngine +// +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +#ifndef KRRESOURCEMANAGER_H +#define KRRESOURCEMANAGER_H +#include "KREngine-common.h" + +#include "KRResource.h" +#include "KRContextObject.h" +#include "KRDataBlock.h" + +class KRResourceManager : public KRContextObject { +public: + KRResourceManager(KRContext &context); + virtual ~KRResourceManager(); + + virtual KRResource* loadResource(const std::string &name, const std::string &extension, KRDataBlock *data) = 0; + virtual KRResource* getResource(const std::string &name, const std::string &extension) = 0; +}; + +#endif // KRRESOURCEMANAGER_H diff --git a/kraken/KRSceneManager.cpp b/kraken/KRSceneManager.cpp index 4489f05..ac91696 100755 --- a/kraken/KRSceneManager.cpp +++ b/kraken/KRSceneManager.cpp @@ -32,7 +32,7 @@ #include "KRSceneManager.h" #include "KRScene.h" -KRSceneManager::KRSceneManager(KRContext &context) : KRContextObject(context){ +KRSceneManager::KRSceneManager(KRContext &context) : KRResourceManager(context){ } KRSceneManager::~KRSceneManager() { @@ -42,6 +42,21 @@ KRSceneManager::~KRSceneManager() { m_scenes.empty(); } +KRResource* KRSceneManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("krscene") == 0) { + return loadScene(name, data); + } + return nullptr; +} +KRResource* KRSceneManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("krscene") == 0) { + return getScene(name); + } + return nullptr; +} + KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) { std::string lowerName = name; std::transform(lowerName.begin(), lowerName.end(), diff --git a/kraken/KRSceneManager.h b/kraken/KRSceneManager.h index 5bbdf8a..9387496 100755 --- a/kraken/KRSceneManager.h +++ b/kraken/KRSceneManager.h @@ -33,17 +33,22 @@ #define KRENGINE_KRSCENEMANAGER_H #include "KREngine-common.h" + +#include "KRResourceManager.h" #include "KRContextObject.h" #include "KRDataBlock.h" class KRScene; -class KRSceneManager : public KRContextObject { +class KRSceneManager : public KRResourceManager { public: KRSceneManager(KRContext &context); virtual ~KRSceneManager(); + 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; + void add(KRScene *scene); KRScene *loadScene(const std::string &name, KRDataBlock *data); diff --git a/kraken/KRShaderManager.cpp b/kraken/KRShaderManager.cpp index 068a427..fbad9ee 100644 --- a/kraken/KRShaderManager.cpp +++ b/kraken/KRShaderManager.cpp @@ -32,7 +32,7 @@ #include "KRShaderManager.h" #include "KREngine-common.h" -KRShaderManager::KRShaderManager(KRContext &context) : KRContextObject(context) +KRShaderManager::KRShaderManager(KRContext &context) : KRResourceManager(context) { } @@ -46,6 +46,21 @@ KRShaderManager::~KRShaderManager() } } +KRResource* KRShaderManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("spv") == 0) { + return load(name, extension, data); + } + return nullptr; +} +KRResource* KRShaderManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("spv") == 0) { + return get(name, extension); + } + return nullptr; +} + unordered_map > &KRShaderManager::getShaders() { return m_shaders; diff --git a/kraken/KRShaderManager.h b/kraken/KRShaderManager.h index f0117fa..d05755c 100644 --- a/kraken/KRShaderManager.h +++ b/kraken/KRShaderManager.h @@ -34,14 +34,19 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRShader.h" #include "KRContextObject.h" #include "KRDataBlock.h" -class KRShaderManager : public KRContextObject { +class KRShaderManager : public KRResourceManager { public: KRShaderManager(KRContext &context); virtual ~KRShaderManager(); + + 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; void add(KRShader *shader); diff --git a/kraken/KRSourceManager.cpp b/kraken/KRSourceManager.cpp index 05628b7..7f79770 100644 --- a/kraken/KRSourceManager.cpp +++ b/kraken/KRSourceManager.cpp @@ -32,7 +32,7 @@ #include "KRSourceManager.h" #include "KREngine-common.h" -KRSourceManager::KRSourceManager(KRContext &context) : KRContextObject(context) +KRSourceManager::KRSourceManager(KRContext &context) : KRResourceManager(context) { } @@ -74,6 +74,52 @@ void KRSourceManager::add(KRSource *source) } } +KRResource* KRSourceManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + if (extension.compare("vert") == 0 || + extension.compare("frag") == 0 || + extension.compare("tesc") == 0 || + extension.compare("tese") == 0 || + extension.compare("geom") == 0 || + extension.compare("comp") == 0 || + extension.compare("mesh") == 0 || + extension.compare("task") == 0 || + extension.compare("rgen") == 0 || + extension.compare("rint") == 0 || + extension.compare("rahit") == 0 || + extension.compare("rchit") == 0 || + extension.compare("rmiss") == 0 || + extension.compare("rcall") == 0 || + extension.compare("glsl") == 0 || + extension.compare("options") == 0) { + return load(name, extension, data); + } + return nullptr; +} + +KRResource* KRSourceManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("vert") == 0 || + extension.compare("frag") == 0 || + extension.compare("tesc") == 0 || + extension.compare("tese") == 0 || + extension.compare("geom") == 0 || + extension.compare("comp") == 0 || + extension.compare("mesh") == 0 || + extension.compare("task") == 0 || + extension.compare("rgen") == 0 || + extension.compare("rint") == 0 || + extension.compare("rahit") == 0 || + extension.compare("rchit") == 0 || + extension.compare("rmiss") == 0 || + extension.compare("rcall") == 0 || + extension.compare("glsl") == 0 || + extension.compare("options") == 0) { + return get(name, extension); + } + return nullptr; +} + KRSource *KRSourceManager::load(const std::string &name, const std::string &extension, KRDataBlock *data) { KRSource *source = new KRSource(getContext(), name, extension, data); diff --git a/kraken/KRSourceManager.h b/kraken/KRSourceManager.h index 390a1da..958e8a6 100644 --- a/kraken/KRSourceManager.h +++ b/kraken/KRSourceManager.h @@ -34,20 +34,23 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" #include "KRSource.h" #include "KRContextObject.h" #include "KRDataBlock.h" -class KRSourceManager : public KRContextObject { +class KRSourceManager : public KRResourceManager { public: KRSourceManager(KRContext &context); virtual ~KRSourceManager(); + + 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; void add(KRSource *source); KRSource *load(const std::string &name, const std::string &extension, KRDataBlock *data); KRSource *get(const std::string &name, const std::string &extension); - const unordered_map &get(const std::string &extension); diff --git a/kraken/KRTextureManager.cpp b/kraken/KRTextureManager.cpp index cb87793..1f27d89 100755 --- a/kraken/KRTextureManager.cpp +++ b/kraken/KRTextureManager.cpp @@ -40,7 +40,7 @@ #include "KRTextureAnimated.h" #include "KRContext.h" -KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) { +KRTextureManager::KRTextureManager(KRContext &context) : KRResourceManager(context) { m_textureMemUsed = 0; for(int iTexture=0; iTextureloadTexture(name.c_str(), extension.c_str(), data); + } else if(extension.compare("ktx") == 0) { + resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data); + } else if(extension.compare("tga") == 0) { + + */ + if (extension.compare("pvr") == 0 || + extension.compare("ktx") == 0 || + extension.compare("tga") == 0) { + return loadTexture(name.c_str(), extension.c_str(), data); + } + return nullptr; +} + +KRResource* KRTextureManager::getResource(const std::string& name, const std::string& extension) +{ + if (extension.compare("pvr") == 0 || + extension.compare("ktx") == 0 || + extension.compare("tga") == 0) { + // TODO - Currently textures must have a unique name, without consideration + // of extensions. When textures are compressed, the uncompressed versions + // are removed. Both compressed and un-compressed textures should co-exist + // with the renderer prioritizing as necessary. This will facilitate more + // ergonomic usage within toolchain and editor GUI. + return getTexture(name); + } + return nullptr; +} + KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szExtension, KRDataBlock *data) { KRTexture *pTexture = NULL; diff --git a/kraken/KRTextureManager.h b/kraken/KRTextureManager.h index a9e1add..138d17d 100755 --- a/kraken/KRTextureManager.h +++ b/kraken/KRTextureManager.h @@ -34,6 +34,8 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRTexture.h" #include "KRContextObject.h" #include "KREngine-common.h" @@ -41,10 +43,13 @@ #include "KRContext.h" #include "KRStreamer.h" -class KRTextureManager : public KRContextObject { +class KRTextureManager : public KRResourceManager { public: KRTextureManager(KRContext &context); virtual ~KRTextureManager(); + + 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; void selectTexture(int iTextureUnit, KRTexture *pTexture, float lod_coverage, KRTexture::texture_usage_t textureUsage); bool selectTexture(GLenum target, int iTextureUnit, int iTextureHandle); diff --git a/kraken/KRUnknownManager.cpp b/kraken/KRUnknownManager.cpp index cdfc78b..dad3287 100755 --- a/kraken/KRUnknownManager.cpp +++ b/kraken/KRUnknownManager.cpp @@ -32,7 +32,7 @@ #include "KRUnknownManager.h" #include "KREngine-common.h" -KRUnknownManager::KRUnknownManager(KRContext &context) : KRContextObject(context) +KRUnknownManager::KRUnknownManager(KRContext &context) : KRResourceManager(context) { } @@ -74,6 +74,19 @@ void KRUnknownManager::add(KRUnknown *unknown) } } + +KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) +{ + // KRUnknown's can have any extension + return load(name, extension, data); +} + +KRResource* KRUnknownManager::getResource(const std::string& name, const std::string& extension) +{ + // KRUnknown's can have any extension + return get(name, extension); +} + KRUnknown *KRUnknownManager::load(const std::string &name, const std::string &extension, KRDataBlock *data) { KRUnknown *unknown = new KRUnknown(getContext(), name, extension, data); diff --git a/kraken/KRUnknownManager.h b/kraken/KRUnknownManager.h index c2440a5..75758a9 100755 --- a/kraken/KRUnknownManager.h +++ b/kraken/KRUnknownManager.h @@ -34,14 +34,19 @@ #include "KREngine-common.h" +#include "KRResourceManager.h" + #include "KRUnknown.h" #include "KRContextObject.h" #include "KRDataBlock.h" -class KRUnknownManager : public KRContextObject { +class KRUnknownManager : public KRResourceManager { public: KRUnknownManager(KRContext &context); virtual ~KRUnknownManager(); + + 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; void add(KRUnknown *unknown); diff --git a/kraken/kraken.cpp b/kraken/kraken.cpp index 70cc0cf..eb3a22c 100644 --- a/kraken/kraken.cpp +++ b/kraken/kraken.cpp @@ -52,7 +52,10 @@ KrResult KrSaveResource(const KrSaveResourceInfo* pSaveResourceInfo) KrResult KrMapResource(const KrMapResourceInfo* pMapResourceInfo) { - return KR_ERROR_NOT_IMPLEMENTED; + if (!sContext) { + return KR_ERROR_NOT_INITIALIZED; + } + return sContext->mapResource(pMapResourceInfo); } KrResult KrUnmapResource(const KrUnmapResourceInfo* pUnmapResourceInfo) diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index d81ecbb..48788d9 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -80,7 +80,7 @@ typedef struct { typedef struct { KrStructureType sType; - const char* presourceName; + const char* pResourceName; KrResourceMapIndex resourceHandle; } KrMapResourceInfo;