Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands/src/libraries/core/Resource.h @ 7040

Last change on this file since 7040 was 6203, checked in by rgrieder, 15 years ago

Added buffer buffering: Sounds are only loaded into one buffer and then reused.

  • Property svn:eol-style set to native
File size: 4.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#ifndef _Core_Resource_H__
30#define _Core_Resource_H__
31
32#include "CorePrereqs.h"
33
34#include <boost/shared_ptr.hpp>
35#include <OgreDataStream.h>
36
37namespace orxonox
38{
39    // Import the Ogre::DataStreamList
40    using Ogre::DataStreamList;
41    using Ogre::DataStreamListPtr;
42
43    //! Stores basic information about a Resource from Ogre
44    struct ResourceInfo
45    {
46        //! The file's fully qualified name
47        std::string filename;
48        //! Path name; separated by '/' and ending with '/'
49        std::string path;
50        //! Base filename
51        std::string basename;
52        //! Resource group the file is in
53        std::string group;
54        //! Uncompressed size
55        size_t size;
56    };
57
58    /**
59    @brief
60        Provides simple functions to easily access the Ogre::ResourceGroupManager
61    */
62    class _CoreExport Resource
63    {
64        // Docs by Ogre::ResourceGroupManager.h
65    public:
66        /**
67        @brief
68            Open a single resource by name and return a DataStream
69            pointing at the source of the data.
70        @param name
71            The name of the resource to locate.
72            Even if resource locations are added recursively, you
73            must provide a fully qualified name to this method.
74        @param groupName
75            The name of the resource group; this determines which
76            locations are searched.
77        @param searchGroupsIfNotFound
78            If true, if the resource is not found in
79            the group specified, other groups will be searched.
80        @return
81            Shared pointer to data stream containing the data. Will be
82            destroyed automatically when no longer referenced.
83        */
84        static DataStreamPtr open(const std::string& name,
85            const std::string& group = Resource::DEFAULT_GROUP,
86            bool bSearchGroupsIfNotFound = false);
87
88        //! Similar to open(string, string, bool), but with a fileInfo struct
89        static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo,
90            bool bSearchGroupsIfNotFound = false)
91        {
92            return open(fileInfo->filename, fileInfo->group, bSearchGroupsIfNotFound);
93        }
94
95        /**
96        @brief
97            Open all resources matching a given pattern (which can contain
98            the character '*' as a wildcard), and return a collection of
99            DataStream objects on them.
100        @param pattern
101            The pattern to look for. If resource locations have been
102            added recursively, subdirectories will be searched too so this
103            does not need to be fully qualified.
104        @param groupName
105            The resource group; this determines which locations
106            are searched.
107        @return
108            Shared pointer to a data stream list , will be
109            destroyed automatically when no longer referenced
110        */
111        static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP);
112
113        /**
114            Find out if the named file exists in a group.
115        @param filename
116            Fully qualified name of the file to test for
117        @param group
118            The name of the resource group
119        */
120        static bool exists(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
121
122        /**
123            Get struct with information about group, path and size.
124        @param filename
125            Fully qualified name of the file to test for
126        @param group
127            The name of the resource group
128        */
129        static shared_ptr<ResourceInfo> getInfo(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
130
131        //! Name of the default resource group (usually "General")
132        static std::string DEFAULT_GROUP;
133
134    private:
135        Resource();
136        ~Resource();
137        Resource(const Resource& instance);
138    };
139}
140
141#endif /* _Core_Resource_H__ */
Note: See TracBrowser for help on using the repository browser.