From b780f22d2cab1ddaabfb76514b2fb475976cd3b0 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Tue, 21 Aug 2012 23:27:17 +0200 Subject: [PATCH] add basic think of resources --- Sources/libewol/ewol/oObject/2DTextured.h | 5 +- .../libewol/ewol/resources/ResourcesImage.cpp | 39 ++++++ .../libewol/ewol/resources/ResourcesImage.h | 52 +++++++ .../ewol/resources/ResourcesManager.cpp | 128 ++++++++++++++++++ .../libewol/ewol/resources/ResourcesManager.h | 50 +++++++ Sources/libewol/ewol/texture/Texture.h | 4 + .../libewol/ewol/texture/TextureManager.cpp | 3 - Sources/libewol/file.mk | 4 + 8 files changed, 280 insertions(+), 5 deletions(-) create mode 100644 Sources/libewol/ewol/resources/ResourcesImage.cpp create mode 100644 Sources/libewol/ewol/resources/ResourcesImage.h create mode 100644 Sources/libewol/ewol/resources/ResourcesManager.cpp create mode 100644 Sources/libewol/ewol/resources/ResourcesManager.h diff --git a/Sources/libewol/ewol/oObject/2DTextured.h b/Sources/libewol/ewol/oObject/2DTextured.h index 298bd5c4..aac4d34b 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.h +++ b/Sources/libewol/ewol/oObject/2DTextured.h @@ -26,6 +26,7 @@ #define __EWOL_O_OBJECT_2D_TEXTURED_H__ #include +#include namespace ewol { class OObject2DTextured :public ewol::OObject @@ -40,10 +41,10 @@ namespace ewol { void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0, draw::Color tmpColor=draw::color::white); void Rectangle(float x, float y, float w, float h, draw::Color tmpColor); protected: - int32_t m_textureId; //!< texture internal ID + ewol::Texture etk::Vector > m_coord; //!< internal coord of the object etk::Vector m_coordTex; //!< internal texture coordinate for every point - etk::Vector m_coordColor; //!< internal color of the different point + etk::Vector m_coordColor; //!< internal color of the different point }; }; diff --git a/Sources/libewol/ewol/resources/ResourcesImage.cpp b/Sources/libewol/ewol/resources/ResourcesImage.cpp new file mode 100644 index 00000000..49386e3f --- /dev/null +++ b/Sources/libewol/ewol/resources/ResourcesImage.cpp @@ -0,0 +1,39 @@ +/** + ******************************************************************************* + * @file ewol/resources/ResourcesImage.cpp + * @brief ewol Resources image system (sources) + * @author Edouard DUPIN + * @date 21/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include + +ewol::ResourcesImage::ResourcesImage(etk::UString fileName, Vector2D size) : + m_resourceID(0), + m_counter(1), + m_image(size) +{ + m_resourceID = ewol::resourcesManager::Add(this); +} + + +ewol::ResourcesImage::~ResourcesImage(void) +{ + ewol::resourcesManager::Rm(this); +} \ No newline at end of file diff --git a/Sources/libewol/ewol/resources/ResourcesImage.h b/Sources/libewol/ewol/resources/ResourcesImage.h new file mode 100644 index 00000000..e9d47d76 --- /dev/null +++ b/Sources/libewol/ewol/resources/ResourcesImage.h @@ -0,0 +1,52 @@ +/** + ******************************************************************************* + * @file ewol/resources/ResourcesImage.h + * @brief ewol Resources image system (header) + * @author Edouard DUPIN + * @date 21/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_RESOURCES_IMAGE_H__ +#define __EWOL_RESOURCES_IMAGE_H__ + +#include +#include + +namespace ewol +{ + class ResourcesImage + { + private: + uint32_t m_resourceID; + uint32_t m_counter; + draw::Image m_image; + etk::UString m_fileName; + public: + ResourcesImage(etk::UString fileName, Vector2D size); + ~ResourcesImage(void); + bool HasName(etk::UString& fileName) { return fileName==m_fileName; }; + void Increment(void) { m_counter++; }; + bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; }; + draw::Image& Get(void) { return m_image; }; + }; +}; + + +#endif + diff --git a/Sources/libewol/ewol/resources/ResourcesManager.cpp b/Sources/libewol/ewol/resources/ResourcesManager.cpp new file mode 100644 index 00000000..63f2abec --- /dev/null +++ b/Sources/libewol/ewol/resources/ResourcesManager.cpp @@ -0,0 +1,128 @@ +/** + ******************************************************************************* + * @file ewol/resources/ResourcesManager.cpp + * @brief ewol Resources manager system (Sources) + * @author Edouard DUPIN + * @date 21/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include +#include +#include +#include + +static etk::Vector l_imageList; + +static uint32_t l_uniqueIdResources = 0; + +void ewol::resourcesManager::Init(void) +{ + // nothing to do in théory then, we clean the buffers : + // NOTE : If we do domething here, then the system does not work corectly + l_imageList.Clear(); + l_uniqueIdResources = 0; +} + +void ewol::resourcesManager::UnInit(void) +{ + for (int32_t iii=0; iii=0; iii--) { + if (l_imageList[iii] != NULL) { + if (l_imageList[iii] == object) { + // we find the texture : + l_imageList.Erase(iii); + return; + } + } + } + EWOL_CRITICAL("Try to remove an Image resources that is not present in the resources pool"); +} + + +ewol::ResourcesImage* ewol::resourcesManager::ImageKeep(etk::UString fileName, Vector2D size) +{ + for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { + if (l_imageList[iii] != NULL) { + if( l_imageList[iii]->HasName(fileName) + && l_imageList[iii]->Get().GetSize() == size) { + l_imageList[iii]->Increment(); + return l_imageList[iii]; + } + } + } + ewol::ResourcesImage* tmpResources = new ewol::ResourcesImage(fileName, size); + if (NULL == tmpResources) { + EWOL_ERROR("allocation error of a resource Image : " << fileName); + return NULL; + } + l_imageList.PushBack(tmpResources); + return tmpResources; +} + +void ewol::resourcesManager::ImageRelease(ewol::ResourcesImage* object) +{ + for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { + if (l_imageList[iii] != NULL) { + if(l_imageList[iii] == object) { + if (true == l_imageList[iii]->Decrement()) { + delete(l_imageList[iii]); + return; + } + } + } + } +} + diff --git a/Sources/libewol/ewol/resources/ResourcesManager.h b/Sources/libewol/ewol/resources/ResourcesManager.h new file mode 100644 index 00000000..d421a101 --- /dev/null +++ b/Sources/libewol/ewol/resources/ResourcesManager.h @@ -0,0 +1,50 @@ +/** + ******************************************************************************* + * @file ewol/resources/ResourcesManager.h + * @brief ewol Resources manager system (header) + * @author Edouard DUPIN + * @date 21/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_RESOURCES_MANAGER_H__ +#define __EWOL_RESOURCES_MANAGER_H__ + +#include +#include +#include +#include + +namespace ewol +{ + namespace resourcesManager { + void Init(void); + void UnInit(void); + uint32_t Add(ewol::ResourcesImage* object); + void Rm(ewol::ResourcesImage* object); + //uint32_t Add(audio::Track* object); + //void Rm(audio::Track* object); + + ewol::ResourcesImage* ImageKeep(etk::UString fileName, Vector2D size); + void ImageRelease(ewol::ResourcesImage* object); + //audio::Track* AudioKeep(etk::UString fileName, Vector2D size); + //void AudioRelease(audio::Track* object); + }; +}; + +#endif \ No newline at end of file diff --git a/Sources/libewol/ewol/texture/Texture.h b/Sources/libewol/ewol/texture/Texture.h index d97804c1..7396ca04 100644 --- a/Sources/libewol/ewol/texture/Texture.h +++ b/Sources/libewol/ewol/texture/Texture.h @@ -31,6 +31,10 @@ #include namespace ewol { + // TODO : remove this deprecated element + namespace texture { + inline int32_t GetGLID(int32_t m_FontTextureId) { return 0; }; + }; class Texture { private: uint32_t m_uniqueId; diff --git a/Sources/libewol/ewol/texture/TextureManager.cpp b/Sources/libewol/ewol/texture/TextureManager.cpp index 4a585f4b..15e41a91 100644 --- a/Sources/libewol/ewol/texture/TextureManager.cpp +++ b/Sources/libewol/ewol/texture/TextureManager.cpp @@ -22,9 +22,6 @@ ******************************************************************************* */ -#ifndef __EWOL_TEXTURE_MANAGER_H__ -#define __EWOL_TEXTURE_MANAGER_H__ - #include #include #include diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 3663deb1..0d132338 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -6,6 +6,10 @@ FILE_LIST = ewol/ewol.cpp \ ewol/Debug.cpp \ ewol/ShortCutManager.cpp +# Resources manager +FILE_LIST+= ewol/resources/ResourcesManager.cpp \ + ewol/resources/ResourcesImage.cpp + # Gui interface FILE_LIST+= ewol/os/eSystem.cpp \ ewol/os/eSystemInput.cpp