Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/src/orxonox/tools/ResourceCollection.cc @ 5653

Last change on this file since 5653 was 5652, checked in by rgrieder, 15 years ago

Modified ResourceLocation to actually find the given paths.
Plus a few small changes.

  • Property svn:eol-style set to native
File size: 3.1 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 "ResourceCollection.h"
30
31#include "util/Exception.h"
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "ResourceLocation.h"
35
36namespace orxonox
37{
38    CreateFactory(ResourceCollection);
39
40    ResourceCollection::ResourceCollection(BaseObject* creator)
41        : BaseObject(creator)
42    {
43        RegisterObject(ResourceCollection);
44
45        // Default group is "General"
46        this->setResourceGroup(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
47    }
48
49    ResourceCollection::~ResourceCollection()
50    {
51    }
52
53    void ResourceCollection::XMLPort(Element& xmlElement, XMLPort::Mode mode)
54    {
55        XMLPortParam(ResourceCollection, "resourceGroup", setResourceGroup, getResourceGroup, xmlElement, mode);
56        XMLPortObject(ResourceCollection, ResourceLocation, "", addResourceLocation, getResourceLocation, xmlElement, mode);
57    }
58
59    void ResourceCollection::setResourceGroup(const std::string& resourceGroup)
60    {
61        if (resourceGroup.empty())
62        {
63            COUT(2) << "Warning: \"\" is not a valid resource group." << std::endl;
64            return;
65        }
66        if (!resourceLocations_.empty())
67            ThrowException(InitialisationFailed, "ResourceGroup: Group change not allowed with locations already added!");
68        resourceGroup_ = resourceGroup;
69    }
70
71    void ResourceCollection::addResourceLocation(ResourceLocation* location)
72    {
73        location->load(resourceGroup_);
74        this->resourceLocations_.push_back(location);
75    }
76
77    void ResourceCollection::removeResourceLocation(ResourceLocation* location)
78    {
79        for (std::vector<ResourceLocation*>::iterator it = resourceLocations_.begin(); it != resourceLocations_.end(); )
80        {
81            if (*it == location)
82            {
83                it = resourceLocations_.erase(it);
84                location->unload(); // doesn't throw
85            }
86            else
87                ++it;
88        }
89    }
90
91    ResourceLocation* ResourceCollection::getResourceLocation(unsigned int index) const
92    {
93        if (index >= resourceLocations_.size())
94            return NULL;
95        else
96            return resourceLocations_[index];
97    }
98}
Note: See TracBrowser for help on using the repository browser.