Completed OGRE VFS server +test

actorid
Nicolay Korslund 15 years ago
parent b601cdff62
commit 262cb9255c

@ -0,0 +1,60 @@
#include "ogre_vfs.h"
#include "../../stream/imp_server/ogre_datastream.h"
using namespace Mangle::VFS;
OgreVFS::OgreVFS(const std::string &_group)
: group(_group)
{
hasList = true;
hasFind = true;
isCaseSensitive = true;
// Get the group manager once
gm = Ogre::ResourceGroupManager::getSingletonPtr();
// Use the default group if none was specified
if(group.empty())
group = gm->getWorldResourceGroupName();
}
Mangle::Stream::InputStream *OgreVFS::open(const std::string &name)
{
Ogre::DataStreamPtr data = gm->openResource(name, group);
return new Stream::OgreStream(data);
}
static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs)
{
int size = in.size();
out.resize(size);
for(int i=0; i<size; i++)
{
out[i].name = in[i].filename;
out[i].basename = in[i].basename;
out[i].size = in[i].uncompressedSize;
out[i].isDir = dirs;
out[i].time = 0;
}
}
FileInfoList OgreVFS::list(const std::string& dir,
bool recurse,
bool dirs) const
{
Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs);
FileInfoList res;
fill(res, *olist, dirs);
return res;
}
FileInfoList OgreVFS::find(const std::string& pattern,
bool recursive,
bool dirs) const
{
Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs);
FileInfoList res;
fill(res, *olist, dirs);
return res;
}

@ -1,20 +1,18 @@
#ifndef MANGLE_VFS_OGRECLIENT_H
#define MANGLE_VFS_OGRECLIENT_H
#ifndef MANGLE_VFS_OGRESERVER_H
#define MANGLE_VFS_OGRESERVER_H
#include <OgreArchive.h>
#include "../vfs.h"
#include <OgreResourceGroupManager.h>
namespace Mangle {
namespace VFS {
/** @brief An interface into the OGRE VFS system.
This class does not wrap a single Ogre::Archive, but rather the
entire resource set available to Ogre. You can use this class to
tap into all paths, Zip files, custom archives on so on that have
been inserted into Ogre as resource locations.
This class is currently a work in progres, it will not compile as
it stands.
This class does NOT wrap a single Ogre::Archive, but rather an
entire resource group in Ogre. You can use this class to tap into
all paths, Zip files, custom archives on so on that have been
inserted into Ogre as resource locations.
This has been built and tested against OGRE 1.6.2. You might have
to make your own modifications if you're working with newer (or
@ -22,38 +20,47 @@ namespace VFS {
*/
class OgreVFS : public VFS
{
std::string group;
Ogre::ResourceGroupManager *gm;
public:
OgreVFS()
{
hasList = false;
hasFind = false;
isCaseSensitive = true;
}
/** @brief Constructor
OGRE must be initialized (ie. you must have created an
Ogre::Root object somewhere) before calling this.
@param group Optional resource group name. If none is given,
OGRE's default (or 'World') resource group is used.
*/
OgreVFS(const std::string &_group = "");
/// Open a new data stream. Deleting the object should be enough to
/// close it.
virtual Stream::InputStream *open(const std::string &name);
/// Check for the existence of a file
virtual bool isFile(const std::string &name) const;
virtual bool isFile(const std::string &name) const
{ return gm->resourceExists(group, name); }
/// Check for the existence of a directory
virtual bool isDir(const std::string &name) const;
/// This doesn't work, always returns false.
virtual bool isDir(const std::string &name) const
{ return false; }
/// Get info about a single file
virtual FileInfo stat(const std::string &name) const;
/// This doesn't work.
virtual FileInfo stat(const std::string &name) const
{ return FileInfo(); }
/// List all entries in a given directory. A blank dir should be
/// interpreted as a the root/current directory of the archive. If
/// dirs is true, list directories instead of files.
/// dirs is true, list directories instead of files. OGRE note: The
/// ogre resource systemd does not support recursive listing of
/// files. We might make a separate filter for this later.
virtual FileInfoList list(const std::string& dir = "",
bool recurse=true,
bool dirs=false) const;
/// Find files after a given pattern. Wildcards (*) are
/// supported. Only valid if 'hasFind' is true. Don't implement your
/// own pattern matching here if the backend doesn't support it
/// natively; use a filter instead (not implemented yet.)
/// supported.
virtual FileInfoList find(const std::string& pattern,
bool recursive=true,
bool dirs=false) const;

@ -1,6 +1,6 @@
GCC=g++ -I../ -I../imp_client/
GCC=g++ -I../
all: dummy_test ogre_client_test ogre_resource_test
all: dummy_test ogre_client_test ogre_resource_test ogre_server_test
I_OGRE=$(shell pkg-config --cflags OGRE)
L_OGRE=$(shell pkg-config --libs OGRE)
@ -11,6 +11,9 @@ ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.h ../imp_client/wrap
ogre_resource_test: ogre_resource_test.cpp
$(GCC) $< -o $@ $(I_OGRE) $(L_OGRE)
ogre_server_test: ogre_server_test.cpp ../vfs.h ../imp_server/ogre_vfs.h ../imp_server/ogre_vfs.cpp
$(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) ../imp_server/ogre_vfs.cpp
dummy_test: dummy_test.cpp dummy_vfs.cpp ../vfs.h
$(GCC) $< -o $@

@ -1,5 +1,5 @@
#include "dummy_vfs.cpp"
#include "ogre_archive.h"
#include "../imp_client/ogre_archive.h"
#include <iostream>
using namespace Ogre;

@ -30,32 +30,6 @@ void find(const std::string &fileName)
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()

@ -0,0 +1,63 @@
#include "../imp_server/ogre_vfs.h"
#include <iostream>
#include <Ogre.h>
using namespace std;
using namespace Mangle::VFS;
using namespace Mangle::Stream;
Ogre::Root *root;
void setupOgre()
{
using namespace Ogre;
// Disable logging
new LogManager;
Log *log = LogManager::getSingleton().createLog("");
log->setDebugOutputEnabled(false);
// Set up Root
root = new Root("","","");
// Add a zip file and the current directory
root->addResourceLocation("test.zip", "Zip", "General");
root->addResourceLocation("./", "FileSystem", "General");
}
void find(VFS &vfs, const std::string &file)
{
cout << "\nFile: " << file << endl;
if(!vfs.isFile(file))
{
cout << "File doesn't exist\n";
return;
}
InputStream *data = vfs.open(file);
cout << "Size: " << data->size() << endl;
char buf[13];
buf[12] = 0;
data->read(buf, 12);
cout << "First 12 bytes: " << buf << "\n";
}
int main()
{
// Set up the engine
setupOgre();
// This is our entry point into the resource file system
OgreVFS vfs("General");
find(vfs, "Makefile"); // From the file system
find(vfs, "testfile.txt"); // From the zip
find(vfs, "blah_bleh"); // Doesn't exist
return 0;
}

Binary file not shown.
Loading…
Cancel
Save