[Orxonox-commit 930] r5653 - in code/branches/resource2/src: core orxonox/objects
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Aug 17 15:42:39 CEST 2009
Author: rgrieder
Date: 2009-08-17 15:42:39 +0200 (Mon, 17 Aug 2009)
New Revision: 5653
Added:
code/branches/resource2/src/core/Resource.cc
code/branches/resource2/src/core/Resource.h
Modified:
code/branches/resource2/src/core/CMakeLists.txt
code/branches/resource2/src/core/CorePrereqs.h
code/branches/resource2/src/core/XMLFile.h
code/branches/resource2/src/orxonox/objects/Level.cc
Log:
Added class to handle handle resources more easily via Ogre::ResourceGroupManager.
And modified the XMLFile to store the resource group as well.
Modified: code/branches/resource2/src/core/CMakeLists.txt
===================================================================
--- code/branches/resource2/src/core/CMakeLists.txt 2009-08-17 13:35:34 UTC (rev 5652)
+++ code/branches/resource2/src/core/CMakeLists.txt 2009-08-17 13:42:39 UTC (rev 5653)
@@ -32,6 +32,7 @@
LuaBind.cc
ObjectListBase.cc
OrxonoxClass.cc
+ Resource.cc
WindowEventListener.cc
# command
Modified: code/branches/resource2/src/core/CorePrereqs.h
===================================================================
--- code/branches/resource2/src/core/CorePrereqs.h 2009-08-17 13:35:34 UTC (rev 5652)
+++ code/branches/resource2/src/core/CorePrereqs.h 2009-08-17 13:42:39 UTC (rev 5653)
@@ -147,6 +147,7 @@
class ObjectListIterator;
class OgreWindowEventListener;
class OrxonoxClass;
+ struct ResourceInfo;
class Shell;
class ShellListener;
template <class T>
@@ -222,6 +223,20 @@
class condition_variable;
}
+// Ogre
+namespace Ogre
+{
+ class DataStream;
+ template <class T> class SharedPtr;
+ typedef SharedPtr<DataStream> DataStreamPtr;
+}
+namespace orxonox
+{
+ // Import the Ogre::DataStream
+ using Ogre::DataStream;
+ using Ogre::DataStreamPtr;
+}
+
// CEGUI
namespace CEGUI
{
Added: code/branches/resource2/src/core/Resource.cc
===================================================================
--- code/branches/resource2/src/core/Resource.cc (rev 0)
+++ code/branches/resource2/src/core/Resource.cc 2009-08-17 13:42:39 UTC (rev 5653)
@@ -0,0 +1,69 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "Resource.h"
+#include <OgreResourceGroupManager.h>
+
+namespace orxonox
+{
+ std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+
+ DataStreamPtr Resource::open(const std::string& name, const std::string& group, bool bSearchGroupsIfNotFound)
+ {
+ return Ogre::ResourceGroupManager::getSingleton().openResource(name, group, bSearchGroupsIfNotFound);
+ }
+
+ DataStreamListPtr Resource::openMulti(const std::string& pattern, const std::string& group)
+ {
+ return Ogre::ResourceGroupManager::getSingleton().openResources(pattern, group);
+ }
+
+ bool Resource::exists(const std::string& name, const std::string& group)
+ {
+ return Ogre::ResourceGroupManager::getSingleton().resourceExists(group, name);
+ }
+
+ shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name, const std::string& group)
+ {
+ Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
+ for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it)
+ {
+ if (it->filename == name)
+ {
+ shared_ptr<ResourceInfo> ptr(new ResourceInfo());
+ ptr->filename = name;
+ ptr->path = it->path;
+ ptr->basename = it->basename;
+ ptr->group = group;
+ ptr->size = it->uncompressedSize;
+ return ptr;
+ }
+ }
+ return shared_ptr<ResourceInfo>();
+ }
+}
Property changes on: code/branches/resource2/src/core/Resource.cc
___________________________________________________________________
Added: svn:eol-style
+ native
Added: code/branches/resource2/src/core/Resource.h
===================================================================
--- code/branches/resource2/src/core/Resource.h (rev 0)
+++ code/branches/resource2/src/core/Resource.h 2009-08-17 13:42:39 UTC (rev 5653)
@@ -0,0 +1,134 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _Core_Resource_H__
+#define _Core_Resource_H__
+
+#include "CorePrereqs.h"
+
+#include <boost/shared_ptr.hpp>
+#include <OgreDataStream.h>
+
+namespace orxonox
+{
+ // Import the Ogre::DataStreamList
+ using Ogre::DataStreamList;
+ using Ogre::DataStreamListPtr;
+
+ //! Stores basic information about a Resource from Ogre
+ struct ResourceInfo
+ {
+ //! The file's fully qualified name
+ std::string filename;
+ //! Path name; separated by '/' and ending with '/'
+ std::string path;
+ //! Base filename
+ std::string basename;
+ //! Resource group the file is in
+ std::string group;
+ //! Uncompressed size
+ size_t size;
+ };
+
+ /**
+ @brief
+ Provides simple functions to easily access the Ogre::ResourceGroupManager
+ */
+ class _CoreExport Resource
+ {
+ // Docs by Ogre::ResourceGroupManager.h
+ public:
+ /**
+ @brief
+ Open a single resource by name and return a DataStream
+ pointing at the source of the data.
+ @param name
+ The name of the resource to locate.
+ Even if resource locations are added recursively, you
+ must provide a fully qualified name to this method.
+ @param groupName
+ The name of the resource group; this determines which
+ locations are searched.
+ @param searchGroupsIfNotFound
+ If true, if the resource is not found in
+ the group specified, other groups will be searched.
+ @return
+ Shared pointer to data stream containing the data. Will be
+ destroyed automatically when no longer referenced.
+ */
+ static DataStreamPtr open(const std::string& name,
+ const std::string& group = Resource::DEFAULT_GROUP,
+ bool bSearchGroupsIfNotFound = false);
+
+ /**
+ @brief
+ Open all resources matching a given pattern (which can contain
+ the character '*' as a wildcard), and return a collection of
+ DataStream objects on them.
+ @param pattern
+ The pattern to look for. If resource locations have been
+ added recursively, subdirectories will be searched too so this
+ does not need to be fully qualified.
+ @param groupName
+ The resource group; this determines which locations
+ are searched.
+ @return
+ Shared pointer to a data stream list , will be
+ destroyed automatically when no longer referenced
+ */
+ static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP);
+
+ /**
+ Find out if the named file exists in a group.
+ @param filename
+ Fully qualified name of the file to test for
+ @param group
+ The name of the resource group
+ */
+ static bool exists(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+
+ /**
+ Get struct with information about group, path and size.
+ @param filename
+ Fully qualified name of the file to test for
+ @param group
+ The name of the resource group
+ */
+ static shared_ptr<ResourceInfo> getInfo(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+
+ //! Name of the default resource group (usually "General")
+ static std::string DEFAULT_GROUP;
+
+ private:
+ Resource();
+ ~Resource();
+ Resource(const Resource& instance);
+ };
+}
+
+#endif /* _Core_Resource_H__ */
Property changes on: code/branches/resource2/src/core/Resource.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: code/branches/resource2/src/core/XMLFile.h
===================================================================
--- code/branches/resource2/src/core/XMLFile.h 2009-08-17 13:35:34 UTC (rev 5652)
+++ code/branches/resource2/src/core/XMLFile.h 2009-08-17 13:42:39 UTC (rev 5653)
@@ -39,14 +39,23 @@
class _CoreExport XMLFile
{
public:
- XMLFile(const std::string& filename) : filename_(filename) {}
- XMLFile(const std::string& filename, const ClassTreeMask& mask) : filename_(filename), mask_(mask) {};
+ XMLFile(const std::string& filename, const std::string& resourceGroup = "General")
+ : filename_(filename)
+ , group_(resourceGroup)
+ { }
+ XMLFile(const ClassTreeMask& mask, const std::string& filename, const std::string& resourceGroup = "General")
+ : filename_(filename)
+ , group_(resourceGroup)
+ , mask_(mask)
+ { }
const std::string& getFilename() const { return this->filename_; }
+ const std::string& getResourceGroup() const { return this->group_; }
const ClassTreeMask& getMask() const { return this->mask_; }
private:
std::string filename_;
+ std::string group_;
ClassTreeMask mask_;
};
}
Modified: code/branches/resource2/src/orxonox/objects/Level.cc
===================================================================
--- code/branches/resource2/src/orxonox/objects/Level.cc 2009-08-17 13:35:34 UTC (rev 5652)
+++ code/branches/resource2/src/orxonox/objects/Level.cc 2009-08-17 13:42:39 UTC (rev 5653)
@@ -100,7 +100,7 @@
mask.include(Class(Template));
mask.include(Class(OverlayGroup)); // HACK to include the ChatOverlay
- this->xmlfile_ = new XMLFile(Core::getDataPathString() + this->xmlfilename_, mask);
+ this->xmlfile_ = new XMLFile(mask, this->xmlfilename_);
Loader::open(this->xmlfile_);
}
More information about the Orxonox-commit
mailing list