factored out common reader behaviour

This commit is contained in:
devZoGok
2022-03-02 20:24:04 +02:00
parent 7a6588f123
commit 77e00b0a64
5 changed files with 15 additions and 12 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cp
set(MODEL modelReader.cpp assimpModelReader.cpp vbModelReader.cpp)
set(ANIM animationController.cpp animationChannel.cpp animation.cpp animatable.h keyframeChannel.cpp driver.cpp)
set(ARMATURE skeleton.cpp bone.cpp ikSolver.cpp)
set(ASSET_READERS imageReader.cpp)
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp)
set(ASSET_MANAGER assetManager.cpp textAsset.h imageAsset.h modelAsset.h fontAsset.h)
set(LIB_SRC ${RENDER} ${MATH} ${MODEL} ${UTILS} ${GUI} ${ARMATURE} ${ASSET_MANAGER} ${ASSET_READERS} ${ANIM})
+3 -7
View File
@@ -1,5 +1,5 @@
#include "assetManager.h"
#include "imageReader.h"
#include "abstractAssetReader.h"
#include "util.h"
#include <algorithm>
@@ -16,15 +16,11 @@ namespace vb01{
return assetManager;
}
void AssetManager::load(string path){
void AssetManager::load(AbstractAssetReader *assetReader, string path){
if(getAsset(path))
return;
string format = path.substr(path.find_last_of(".") + 1, string::npos);
vector<string> imageFormats = vector<string>{"png", "jpg", "jpeg"};
if(*find(imageFormats.begin(), imageFormats.end(), format) == format)
assets.push_back(ImageReader::getSingleton()->readImage(path, false));
assets.push_back(assetReader->readAsset(path));
}
Asset* AssetManager::getAsset(string path){
+3 -1
View File
@@ -6,10 +6,12 @@
#include <vector>
namespace vb01{
class AbstractAssetReader;
class AssetManager{
public:
static AssetManager* getSingleton();
void load(std::string);
void load(AbstractAssetReader*, std::string);
Asset* getAsset(std::string);
private:
AssetManager(){}
+1 -1
View File
@@ -14,7 +14,7 @@ namespace vb01{
return imageReader;
}
ImageAsset* ImageReader::readImage(string path, bool flip){
Asset* ImageReader::readAsset(string path){
stbi_set_flip_vertically_on_load(flip);
int width, height, numChannels;
u8 *data = stbi_load(path.c_str(), &width, &height, &numChannels, 0);
+7 -2
View File
@@ -3,14 +3,19 @@
#include "util.h"
#include "imageAsset.h"
#include "abstractAssetReader.h"
namespace vb01{
class ImageReader{
class ImageReader : public AbstractAssetReader{
public:
static ImageReader* getSingleton();
ImageAsset* readImage(std::string, bool);
inline void setFlip(bool flip){this->flip = flip;}
inline bool isFlip(){return flip;}
Asset* readAsset(std::string);
private:
ImageReader(){}
bool flip = false;
};
}