diff --git a/SConstruct b/SConstruct index e51eb9c..e8040f3 100644 --- a/SConstruct +++ b/SConstruct @@ -5,7 +5,7 @@ # James Turk (jpt2433@rit.edu) # # Version: -# $Id: SConstruct,v 1.13 2005/06/29 04:30:40 cozman Exp $ +# $Id: SConstruct,v 1.14 2005/07/03 06:33:19 cozman Exp $ import os,os.path import glob @@ -91,6 +91,6 @@ for test_src in test_srcs: test_name = test_src.replace('_test.cpp','') tests.append(env.Program(test_name, source=test_src, CPPPATH = INC_DIRS+['/usr/include/freetype2/'], LIBPATH='./lib', CPPFLAGS = '-Wall -pedantic', - LIBS=['photon',OAL_LIB,'glfw',OGL_LIB,GLU_LIB,'physfs','corona','freetype','ftgl'])) + LIBS=['photon',OAL_LIB,'glfw',OGL_LIB,GLU_LIB,'physfs','corona','freetype'])) env.Alias('test',tests) diff --git a/include/ResourceManaged.hpp b/include/ResourceManaged.hpp index 371e388..d5c233a 100644 --- a/include/ResourceManaged.hpp +++ b/include/ResourceManaged.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: ResourceManaged.hpp,v 1.5 2005/06/27 04:24:09 cozman Exp $ +// $Id: ResourceManaged.hpp,v 1.6 2005/07/03 06:33:19 cozman Exp $ #ifndef PHOTON_RESOURCEMANAGED_HPP #define PHOTON_RESOURCEMANAGED_HPP @@ -92,7 +92,8 @@ public: // Parameters: // name - Name to give to resource. // path - Path of resource data file. - static void addResource(const std::string& name, const std::string& path); + static void addResource(const std::string& name, + const typename ResMgrT::ResDescT& desc); // Function: addResource // Define a new unaliased resource. (name == path). @@ -101,7 +102,7 @@ public: // // Parameters:. // path - Path of resource data file. - static void addResource(const std::string& path); + static void addResource(const typename ResMgrT::ResDescT& desc); private: std::string resName_; @@ -167,15 +168,15 @@ void ResourceManaged::cleanUp() template void ResourceManaged::addResource(const std::string& name, - const std::string& path) + const typename ResMgrT::ResDescT& desc) { - resMgr_.newResource(name,path); + resMgr_.newResource(name, desc); } template -void ResourceManaged::addResource(const std::string& path) +void ResourceManaged::addResource(const typename ResMgrT::ResDescT& desc) { - resMgr_.newResource(path,path); + resMgr_.newResource(desc.path, desc); } // define the resource manager static instance diff --git a/include/ResourceManager.hpp b/include/ResourceManager.hpp index 00adbe5..befb585 100644 --- a/include/ResourceManager.hpp +++ b/include/ResourceManager.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: ResourceManager.hpp,v 1.7 2005/06/27 04:24:16 cozman Exp $ +// $Id: ResourceManager.hpp,v 1.8 2005/07/03 06:33:19 cozman Exp $ #ifndef PHOTON_RESOURCEMANAGER_HPP #define PHOTON_RESOURCEMANAGER_HPP @@ -25,7 +25,15 @@ class Resource { public: uint refCount; - std::string name; +}; + +class ResourceDescriptor +{ +public: + ResourceDescriptor() { } + ResourceDescriptor(const std::string& p) : + path(p) + { } std::string path; }; @@ -34,9 +42,12 @@ public: // // All ResourceManager work is done behind the scenes, it and all classes // derived from it are therefore left without public documentation. -template +template class ResourceManager : public boost::noncopyable { +public: + typedef ResDescT_ ResDescT; + public: ResourceManager(); @@ -45,13 +56,13 @@ public: void delRef(const std::string& name); void cleanUp(); - void newResource(const std::string& name, const std::string& path); + void newResource(const std::string& name, const ResDescT& path); resT& getResource(const std::string& name); private: - virtual void loadResource(resT &res, const std::string& path)=0; - virtual void freeResource(resT &res)=0; + virtual void loadResourceData(resT &res, const ResDescT& path)=0; + virtual void freeResourceData(resT &res)=0; void deleteResource(const std::string& name); @@ -66,16 +77,16 @@ private: // implementation (damn you templor, cruel god of templates!) -template -ResourceManager::ResourceManager() +template +ResourceManager::ResourceManager() { } -template -ResourceManager::~ResourceManager() +template +ResourceManager::~ResourceManager() { } -template -void ResourceManager::delRef(const std::string& name) +template +void ResourceManager::delRef(const std::string& name) { MapIterator resource( resourceMap_.find(name) ); @@ -89,41 +100,39 @@ void ResourceManager::delRef(const std::string& name) } } -template -void ResourceManager::cleanUp() +template +void ResourceManager::cleanUp() { // delete resources, until none are left while(!resourceMap_.empty()) { - freeResource(resourceMap_.begin()->second); + freeResourceData(resourceMap_.begin()->second); } } -template -void ResourceManager::newResource(const std::string& name, - const std::string& path) +template +void ResourceManager::newResource(const std::string& name, + const ResDescT& desc) { resT resource; - resource.name = name; - resource.path = path; try { // attempt to load - loadResource(resource, path); + loadResourceData(resource, desc); } catch(ResourceException& e) { // rethrow any exceptions with specific information - throw ResourceException("Could not load " + path + " as " + name + + throw ResourceException("Could not load " + desc.path + " as " + name + ": " + e.getDesc()); } resourceMap_[name] = resource; // add the resource to resourceMap } -template -resT& ResourceManager::getResource(const std::string& name) +template +resT& ResourceManager::getResource(const std::string& name) { MapIterator resource( resourceMap_.find(name) ); @@ -139,21 +148,22 @@ resT& ResourceManager::getResource(const std::string& name) } } -template -void ResourceManager::deleteResource(const std::string& name) +template +void ResourceManager::deleteResource(const std::string& name) { MapIterator resource( resourceMap_.find(name) ); // if the resource was found if(resource != resourceMap_.end()) { - freeResource(resource->second); // free resource and remove it from the map + // free resource and remove it from the map + freeResourceData(resource->second); resourceMap_.erase(name); } } -template -void ResourceManager::printReport(std::ostream& os) +template +void ResourceManager::printReport(std::ostream& os) { MapIterator resource( resourceMap_.begin() ); diff --git a/include/video/Font.hpp b/include/video/Font.hpp index 1896224..c8146a9 100644 --- a/include/video/Font.hpp +++ b/include/video/Font.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font.hpp,v 1.2 2005/07/03 05:20:49 cozman Exp $ +// $Id: Font.hpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #ifndef PHOTON_VIDEO_FONT_HPP #define PHOTON_VIDEO_FONT_HPP @@ -34,29 +34,6 @@ std::ostream& operator<<(std::ostream& os, const StreamFlusher& rhs); // - ostream& << Font class Font: public ResourceManaged { - -// Resource Creation -public: - // Function: addResource - // Define a new named font resource, works just like - // except that it takes a size for the font. - // - // Parameters: - // name - Name to give to font resource. - // path - Path of font file. - // size - Point size for the font. - static void addResource(const std::string& name, const std::string& path, - uint size); - - // Function: addResource - // Define a new unaliased font resource (name == path). Works just like - // except that it takes a size for the font. - // - // Parameters:. - // path - Path of font file. - // size - Point size for the font. - static void addResource(const std::string& path, uint size); - // Group: (Con/De)structors public: // Function: Font diff --git a/include/video/FontResourceManager.hpp b/include/video/FontResourceManager.hpp index 3bf0de9..c63ceb2 100644 --- a/include/video/FontResourceManager.hpp +++ b/include/video/FontResourceManager.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: FontResourceManager.hpp,v 1.2 2005/07/03 05:20:49 cozman Exp $ +// $Id: FontResourceManager.hpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #ifndef PHOTON_VIDEO_FONTRESOURCEMANAGER_HPP #define PHOTON_VIDEO_FONTRESOURCEMANAGER_HPP @@ -29,7 +29,19 @@ public: ubyte height; }; -class FontResourceManager : public ResourceManager +class FontResourceDescriptor : public ResourceDescriptor +{ +public: + FontResourceDescriptor(const std::string& str, uint sz) : + ResourceDescriptor(str), size(sz) + { } + +public: + uint size; +}; + +class FontResourceManager : public ResourceManager { public: FontResourceManager(); @@ -40,15 +52,9 @@ public: private: - // defined but not implemented - virtual void loadResource(FontResource &res, const std::string& name); - - FontResource newResource(const std::string& name, const std::string& path, - uint size); - - virtual void loadResource(FontResource &res, const std::string& name, - uint size); - virtual void freeResource(FontResource &res); + virtual void loadResourceData(FontResource &res, + const FontResourceDescriptor& desc); + virtual void freeResourceData(FontResource &res); private: FT_Library library_; diff --git a/include/video/TextureResourceManager.hpp b/include/video/TextureResourceManager.hpp index cd90404..ab98123 100644 --- a/include/video/TextureResourceManager.hpp +++ b/include/video/TextureResourceManager.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: TextureResourceManager.hpp,v 1.2 2005/06/14 00:28:36 cozman Exp $ +// $Id: TextureResourceManager.hpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #ifndef PHOTON_VIDEO_TEXTURERESOURCEMANAGER_HPP #define PHOTON_VIDEO_TEXTURERESOURCEMANAGER_HPP @@ -38,8 +38,9 @@ public: uint &texID); private: - virtual void loadResource(TextureResource &res, const std::string& name); - virtual void freeResource(TextureResource &res); + virtual void loadResourceData(TextureResource &res, + const ResourceDescriptor& path); + virtual void freeResourceData(TextureResource &res); Color colorKey_; }; diff --git a/photon.mm b/photon.mm index 4d8b7d8..c8f3606 100644 --- a/photon.mm +++ b/photon.mm @@ -12,6 +12,11 @@ + + + + + @@ -69,9 +74,13 @@ + + + + diff --git a/src/video/Font.cpp b/src/video/Font.cpp index 7423480..b2a306b 100644 --- a/src/video/Font.cpp +++ b/src/video/Font.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font.cpp,v 1.2 2005/07/03 05:20:49 cozman Exp $ +// $Id: Font.cpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #include "video/Font.hpp" @@ -25,17 +25,6 @@ std::ostream& operator<<(std::ostream& os, const StreamFlusher& rhs) return os.flush(); } -void Font::addResource(const std::string& name, const std::string& path, - uint size) -{ - resMgr_.newResource(name,path,size); -} - -void Font::addResource(const std::string& path, uint size) -{ - resMgr_.newResource(path,path,size); -} - Font::Font() : texID_(0), listBase_(0), // initalize GL variables to zero widths_(FontResourceManager::NUM_CHARS), // make room for 96 widths diff --git a/src/video/FontResourceManager.cpp b/src/video/FontResourceManager.cpp index d0cd6f1..876a973 100644 --- a/src/video/FontResourceManager.cpp +++ b/src/video/FontResourceManager.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: FontResourceManager.cpp,v 1.2 2005/07/03 05:20:49 cozman Exp $ +// $Id: FontResourceManager.cpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #include "video/FontResourceManager.hpp" @@ -41,45 +41,15 @@ void FontResourceManager::getFontData(const std::string& name, uint& texID, height = resource.height; } -void FontResourceManager::loadResource(FontResource &res, - const std::string& path) -{ - throw Error("loadResource(FontResource&, const std::string& is undefined " - " for Font. A size must be specified."); -} - -FontResource FontResourceManager::newResource(const std::string& name, - const std::string& path, - uint size) -{ - FontResource resource; - resource.name = name; - resource.path = path; - - try - { - // attempt to load - loadResource(resource, path, size); - } - catch(ResourceException& e) - { - // rethrow any exceptions with specific information - throw ResourceException("Could not load " + path + " as " + name + - ": " + e.getDesc()); - } - - resourceMap_[name] = resource; // add the resource to resourceMap -} - -void FontResourceManager::loadResource(FontResource &res, - const std::string& path, uint size) +void FontResourceManager::loadResourceData(FontResource &res, + const FontResourceDescriptor& desc) { const size_t MARGIN = 3; res.widths.resize(NUM_CHARS); // Step 1: Open the font using FreeType // - util::FileBuffer buf(path); + util::FileBuffer buf(desc.path); std::vector data = buf.getData(); FT_Face face; @@ -98,7 +68,7 @@ void FontResourceManager::loadResource(FontResource &res, } // Set the font size - FT_Set_Pixel_Sizes(face, size, 0); + FT_Set_Pixel_Sizes(face, desc.size, 0); // Step 2: Find maxAscent/Descent to calculate imageHeight // size_t imageHeight = 0; @@ -216,7 +186,7 @@ void FontResourceManager::loadResource(FontResource &res, FT_Done_Face(face); // free the face data } -void FontResourceManager::freeResource(FontResource &res) +void FontResourceManager::freeResourceData(FontResource &res) { if(glIsList(res.listBase)) { diff --git a/src/video/TextureResourceManager.cpp b/src/video/TextureResourceManager.cpp index 785784f..777cac0 100644 --- a/src/video/TextureResourceManager.cpp +++ b/src/video/TextureResourceManager.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: TextureResourceManager.cpp,v 1.3 2005/06/27 04:24:16 cozman Exp $ +// $Id: TextureResourceManager.cpp,v 1.4 2005/07/03 06:33:19 cozman Exp $ #include "video/TextureResourceManager.hpp" @@ -44,11 +44,11 @@ void TextureResourceManager::getTextureData(const std::string& name, texID = resource.texID; } -void TextureResourceManager::loadResource(TextureResource &res, - const std::string& path) +void TextureResourceManager::loadResourceData(TextureResource &res, + const ResourceDescriptor& path) { corona::Image *image(0); - util::FileBuffer buf(path); + util::FileBuffer buf(path.path); corona::File *file; std::vector data = buf.getData(); @@ -108,7 +108,7 @@ void TextureResourceManager::loadResource(TextureResource &res, GL_UNSIGNED_BYTE, res.pixels); } -void TextureResourceManager::freeResource(TextureResource &res) +void TextureResourceManager::freeResourceData(TextureResource &res) { if(res.pixels) { diff --git a/test/Font_test.cpp b/test/Font_test.cpp index 3b410e0..b5a31ed 100644 --- a/test/Font_test.cpp +++ b/test/Font_test.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font_test.cpp,v 1.2 2005/07/03 05:20:49 cozman Exp $ +// $Id: Font_test.cpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #include "photon.hpp" using namespace photon; @@ -30,7 +30,7 @@ public: video.setOrthoView(800,600); - video::Font::addResource("font","data/arial.ttf"); + video::Font::addResource("font",video::FontResourceDescriptor("data/arial.ttf",32)); font.open("font"); } diff --git a/test/Image_test.cpp b/test/Image_test.cpp index c2ef0f0..b12a03a 100644 --- a/test/Image_test.cpp +++ b/test/Image_test.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Image_test.cpp,v 1.2 2005/06/29 00:02:51 cozman Exp $ +// $Id: Image_test.cpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #include "photon.hpp" using namespace photon; @@ -30,8 +30,8 @@ public: video.setOrthoView(800,600); - video::Image::addResource("data/test.png"); - video::Texture::addResource("test2","data/test2.png"); + video::Image::addResource(ResourceDescriptor("data/test.png")); + video::Texture::addResource("test2",ResourceDescriptor("data/test2.png")); img[0].open("test2"); img[0].setAlpha(128); diff --git a/test/Texture_test.cpp b/test/Texture_test.cpp index c53fc63..2447158 100644 --- a/test/Texture_test.cpp +++ b/test/Texture_test.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Texture_test.cpp,v 1.2 2005/06/27 04:24:16 cozman Exp $ +// $Id: Texture_test.cpp,v 1.3 2005/07/03 06:33:19 cozman Exp $ #include "photon.hpp" using namespace photon; @@ -30,8 +30,8 @@ public: video.setOrthoView(800,600); - video::Texture::addResource("data/test.png"); - video::Texture::addResource("test2","data/test2.png"); + video::Texture::addResource(ResourceDescriptor("data/test.png")); + video::Texture::addResource("test2",ResourceDescriptor("data/test2.png")); // Testing of errors //video::Texture::addResource("nonfile");