From b601cdff629ddd53a236ab388f57837672f5fe24 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Sat, 26 Dec 2009 10:52:10 +0100 Subject: [PATCH] Minor changes to VFS. Updated ogre_resource test --- stream/imp_client/audiere_file.cpp | 35 +++++------- vfs/imp_client/ogre_archive.cpp | 2 + vfs/imp_server/ogre_vfs.h | 3 +- vfs/tests/Makefile | 5 +- vfs/tests/ogre_resource_test.cpp | 87 ++++++++++++++++++++++++++++++ vfs/vfs.h | 5 +- 6 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 vfs/tests/ogre_resource_test.cpp diff --git a/stream/imp_client/audiere_file.cpp b/stream/imp_client/audiere_file.cpp index ea8142eb49..53638781e3 100644 --- a/stream/imp_client/audiere_file.cpp +++ b/stream/imp_client/audiere_file.cpp @@ -8,32 +8,25 @@ bool AudiereFile::seek(int pos, SeekMode mode) assert(inp->isSeekable); assert(inp->hasPosition); - if(mode == BEGIN) - { - // Absolute position - inp->seek(pos); - return inp->tell() == pos; - } - if(mode == CURRENT) - { - // Current position - int cpos = inp->tell(); + int newPos; - // Seek to a elative position - inp->seek(cpos + pos); - return inp->tell() == (pos+cpos); - } - if(mode == END) + switch(mode) { + case BEGIN: newPos = pos; break; + case CURRENT: newPos = pos+tell(); break; + case END: // Seeking from the end. This requires that we're able to get - // the entire size of the file. The pos also has to be + // the entire size of the stream. The pos also has to be // non-positive. assert(inp->hasSize); assert(pos <= 0); - - size_t epos = inp->size(); - inp->seek(epos + pos); - return inp->tell() == (epos+pos); + newPos = inp->size() + pos; + break; + default: + assert(0 && "invalid seek mode"); } - assert(0 && "invalid seek mode"); + + inp->seek(newPos); + return inp->tell() == newPos; + } diff --git a/vfs/imp_client/ogre_archive.cpp b/vfs/imp_client/ogre_archive.cpp index c9dccab902..d7adaa07d2 100644 --- a/vfs/imp_client/ogre_archive.cpp +++ b/vfs/imp_client/ogre_archive.cpp @@ -37,6 +37,7 @@ static void fill(Ogre::StringVector &out, FileInfoList &in) Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs) { + assert(vfs->hasList); FileInfoList lst = vfs->list("", recursive, dirs); Ogre::StringVector *res = new Ogre::StringVector; @@ -47,6 +48,7 @@ Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs) Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs) { + assert(vfs->hasList); FileInfoList lst = vfs->list("", recursive, dirs); Ogre::FileInfoList *res = new Ogre::FileInfoList; diff --git a/vfs/imp_server/ogre_vfs.h b/vfs/imp_server/ogre_vfs.h index 98cf5da79b..0812114337 100644 --- a/vfs/imp_server/ogre_vfs.h +++ b/vfs/imp_server/ogre_vfs.h @@ -25,7 +25,8 @@ class OgreVFS : public VFS public: OgreVFS() { - hasFind = true; + hasList = false; + hasFind = false; isCaseSensitive = true; } diff --git a/vfs/tests/Makefile b/vfs/tests/Makefile index b1fb55f13d..135df10c65 100644 --- a/vfs/tests/Makefile +++ b/vfs/tests/Makefile @@ -1,6 +1,6 @@ GCC=g++ -I../ -I../imp_client/ -all: dummy_test ogre_client_test +all: dummy_test ogre_client_test ogre_resource_test I_OGRE=$(shell pkg-config --cflags OGRE) L_OGRE=$(shell pkg-config --libs OGRE) @@ -8,6 +8,9 @@ L_OGRE=$(shell pkg-config --libs OGRE) ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.h ../imp_client/wrapper.h ../imp_client/ogre_archive.h ../imp_client/ogre_archive.cpp $(GCC) $< ../imp_client/ogre_archive.cpp -o $@ $(I_OGRE) $(L_OGRE) +ogre_resource_test: ogre_resource_test.cpp + $(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) + dummy_test: dummy_test.cpp dummy_vfs.cpp ../vfs.h $(GCC) $< -o $@ diff --git a/vfs/tests/ogre_resource_test.cpp b/vfs/tests/ogre_resource_test.cpp new file mode 100644 index 0000000000..36f84c241e --- /dev/null +++ b/vfs/tests/ogre_resource_test.cpp @@ -0,0 +1,87 @@ +#include +#include +#include + +/* + This isn't really a test of our implementation, but a test of using + the Ogre resource system to find files. If the Ogre interface + changes and you have to change this test, you will have to change + the ogre_vfs.cpp implementation equivalently. + + */ + +using namespace std; +using namespace Ogre; + +ResourceGroupManager *gm; +String group; + +void find(const std::string &fileName) +{ + cout << "\nFile: " << fileName << endl; + + if(!gm->resourceExists(group, fileName)) + { + cout << "Does not exist\n"; + return; + } + + DataStreamPtr data = gm->openResource(fileName, group); + + cout << "Size: " << data->size() << endl; + cout << "First line: " << data->getLine() << "\n"; + + + // Alternative - not used / fixed yet + + /* This won't work, since we don't have access to Ogre + internals. That's a shame. + + LocationList::iterator li, liend; + liend = grp->locationList.end(); + for (li = grp->locationList.begin(); li != liend; ++li) + { + Archive* arch = (*li)->archive; + + // The rest is client code - using an archive. We might make a + // shared implementation, or possibly convert the archives into + // a vfs list at load time (although that isn't very flexible.) + + // Do we perform these searches in each function? I guess we + // have to. + if (arch->exists(resourceName)) + { + DataStreamPtr ptr = arch->open(resourceName); + return ptr; + } + } + */ +} + +int main() +{ + // Disable logging + new LogManager; + Log *log = LogManager::getSingleton().createLog(""); + log->setDebugOutputEnabled(false); + + // Set up Ogre + Root root("","",""); + + root.addResourceLocation("./", "FileSystem", "General"); + + gm = ResourceGroupManager::getSingletonPtr(); + group = gm->getWorldResourceGroupName(); + + find("Makefile"); + find("ogre_resource_test.cpp"); + find("bleh"); + + cout << "\nAll source files:\n"; + FileInfoListPtr list = gm->findResourceFileInfo(group, "*.cpp"); + FileInfoList::iterator it, end; + it = list->begin(); + end = list->end(); + for(; it != end; it++) + cout << " " << it->filename << endl; +} diff --git a/vfs/vfs.h b/vfs/vfs.h index 345b4ccaef..a9ffb6b622 100644 --- a/vfs/vfs.h +++ b/vfs/vfs.h @@ -37,7 +37,10 @@ class VFS public: // Feature options. These should be set in the constructor. - /// If true, the find*() functions work + /// If true, the list() function work + bool hasList; + + /// If true, the find() function work bool hasFind; /// If true, the file system is case sensitive