Introducing KRResourceManager superclass
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -34,17 +34,22 @@
|
||||
|
||||
#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);
|
||||
void addAnimation(KRAnimation *new_animation);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRResourceManager.h"
|
||||
|
||||
#include "KRContextObject.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRAudioSource.h"
|
||||
@@ -90,11 +92,14 @@ 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<std::string, KRAudioSample *> &getSounds();
|
||||
|
||||
void add(KRAudioSample *Sound);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#ifndef KRBUNDLEMANAGER_H
|
||||
#define KRBUNDLEMANAGER_H
|
||||
|
||||
#include "KRResourceManager.h"
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "KRDataBlock.h"
|
||||
@@ -40,11 +42,14 @@
|
||||
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);
|
||||
KRBundle* createBundle(const char* szName);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<std::string, KRMaterial *> &KRMaterialManager::getMaterials()
|
||||
{
|
||||
|
||||
@@ -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,11 +43,14 @@
|
||||
|
||||
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);
|
||||
KRMaterial *getMaterial(const std::string &name);
|
||||
|
||||
@@ -61,9 +61,11 @@ 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;
|
||||
|
||||
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) {
|
||||
@@ -74,12 +76,17 @@ void KRMesh::setName(const std::string name) {
|
||||
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);
|
||||
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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<KRMesh*> 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);
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#define KRMESHMANAGER_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRResourceManager.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
@@ -40,7 +42,7 @@
|
||||
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;
|
||||
@@ -48,6 +50,9 @@ public:
|
||||
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);
|
||||
void firstFrame();
|
||||
|
||||
43
kraken/KRResourceManager.cpp
Normal file
43
kraken/KRResourceManager.cpp
Normal file
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
50
kraken/KRResourceManager.h
Normal file
50
kraken/KRResourceManager.h
Normal file
@@ -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
|
||||
@@ -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(),
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<std::string, unordered_map<std::string, KRShader *> > &KRShaderManager::getShaders()
|
||||
{
|
||||
return m_shaders;
|
||||
|
||||
@@ -34,15 +34,20 @@
|
||||
|
||||
#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);
|
||||
|
||||
KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -34,21 +34,24 @@
|
||||
|
||||
#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<std::string, KRSource *> &get(const std::string &extension);
|
||||
|
||||
unordered_map<std::string, unordered_map<std::string, KRSource *> > &getSources();
|
||||
|
||||
@@ -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; iTexture<KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
||||
@@ -115,6 +115,41 @@ void KRTextureManager::_setWrapModeT(GLuint i, GLuint wrap_mode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KRResource* KRTextureManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
||||
{
|
||||
/*
|
||||
|
||||
} else if(extension.compare("pvr") == 0) {
|
||||
resource = m_pTextureManager->loadTexture(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;
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRResourceManager.h"
|
||||
|
||||
#include "KRTexture.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "KREngine-common.h"
|
||||
@@ -41,11 +43,14 @@
|
||||
#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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -34,15 +34,20 @@
|
||||
|
||||
#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);
|
||||
|
||||
KRUnknown *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -80,7 +80,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
const char* presourceName;
|
||||
const char* pResourceName;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrMapResourceInfo;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user