mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 20:45:34 +00:00
Minor changes to VFS. Updated ogre_resource test
This commit is contained in:
parent
c54301fc1c
commit
b601cdff62
6 changed files with 113 additions and 24 deletions
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ class OgreVFS : public VFS
|
|||
public:
|
||||
OgreVFS()
|
||||
{
|
||||
hasFind = true;
|
||||
hasList = false;
|
||||
hasFind = false;
|
||||
isCaseSensitive = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 $@
|
||||
|
||||
|
|
87
vfs/tests/ogre_resource_test.cpp
Normal file
87
vfs/tests/ogre_resource_test.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include <iostream>
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreResourceGroupManager.h>
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue