Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/Resource.cc @ 6417

Last change on this file since 6417 was 6417, checked in by rgrieder, 14 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Resource.h"
30
31#include <OgreException.h>
32#include <OgreResourceGroupManager.h>
33
34namespace orxonox
35{
36    std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
37
38    DataStreamPtr Resource::open(const std::string& name)
39    {
40        return Ogre::ResourceGroupManager::getSingleton().openResource(name,
41            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
42    }
43
44    DataStreamListPtr Resource::openMulti(const std::string& pattern)
45    {
46        DataStreamListPtr resources(new Ogre::DataStreamList());
47        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
48        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
49        {
50            DataStreamListPtr temp = Ogre::ResourceGroupManager::getSingleton().openResources(pattern, *it);
51            resources->insert(resources->end(), temp->begin(), temp->end());
52        }
53        return resources;
54    }
55
56    bool Resource::exists(const std::string& name)
57    {
58        try
59        {
60            Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
61            return true;
62        }
63        catch (const Ogre::Exception&)
64        {
65            return false;
66        }
67    }
68
69    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name)
70    {
71        std::string group;
72        try
73        {
74            group = Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
75        }
76        catch (const Ogre::Exception&)
77        {
78            return shared_ptr<ResourceInfo>();
79        }
80        Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
81        for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it)
82        {
83            if (it->filename == name)
84            {
85                shared_ptr<ResourceInfo> ptr(new ResourceInfo());
86                ptr->filename = name;
87                ptr->path = it->path;
88                ptr->basename = it->basename;
89                ptr->group = group;
90                ptr->size = it->uncompressedSize;
91                return ptr;
92            }
93        }
94        return shared_ptr<ResourceInfo>();
95    }
96
97    StringVectorPtr Resource::findResourceNames(const std::string& pattern)
98    {
99        StringVectorPtr resourceNames(new Ogre::StringVector());
100        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
101        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
102        {
103            StringVectorPtr temp = Ogre::ResourceGroupManager::getSingleton().findResourceNames(*it, pattern);
104            resourceNames->insert(resourceNames->end(), temp->begin(), temp->end());
105        }
106        return resourceNames;
107    }
108}
Note: See TracBrowser for help on using the repository browser.