source: OGRE/trunk/ogrenew/OgreMain/src/OgreResource.cpp @ 657

Revision 657, 3.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25// Ogre includes
26#include "OgreStableHeaders.h"
27
28#include "OgreResource.h"
29#include "OgreResourceManager.h"
30#include "OgreLogManager.h"
31
32namespace Ogre
33{
34        //-----------------------------------------------------------------------
35        Resource::Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
36                const String& group, bool isManual, ManualResourceLoader* loader)
37                : mCreator(creator), mName(name), mGroup(group), mHandle(handle),
38                mIsLoaded(false), mSize(0), mIsManual(isManual), mLoader(loader)
39        {
40        }
41        //-----------------------------------------------------------------------
42        Resource::~Resource()
43        {
44        }
45        //-----------------------------------------------------------------------
46        void Resource::load(void)
47        {
48                OGRE_LOCK_AUTO_MUTEX
49                if (!mIsLoaded)
50                {
51                        if (mIsManual)
52                        {
53                                // Load from manual loader
54                                if (mLoader)
55                                {
56                                        mLoader->loadResource(this);
57                                }
58                                else
59                                {
60                                        // Warn that this resource is not reloadable
61                                        LogManager::getSingleton().logMessage(
62                                                "WARNING: " + mCreator->getResourceType() +
63                                                " instance '" + mName + "' was defined as manually "
64                                                "loaded, but no manual loader was provided. This Resource "
65                                                "will be lost if it has to be reloaded.");
66                                }
67                        }
68                        else
69                        {
70                                loadImpl();
71                        }
72                        // Calculate resource size
73                        mSize = calculateSize();
74                        // Now loaded
75                        mIsLoaded = true;
76                        // Notify manager
77                        if(mCreator)
78                                mCreator->_notifyResourceLoaded(this);
79                }
80
81        }
82        //-----------------------------------------------------------------------
83        void Resource::unload(void)
84        {
85                OGRE_LOCK_AUTO_MUTEX
86                if (mIsLoaded)
87                {
88                        unloadImpl();
89                        mIsLoaded = false;
90                        // Notify manager
91                        if(mCreator)
92                                mCreator->_notifyResourceUnloaded(this);
93                }
94        }
95        //-----------------------------------------------------------------------
96        void Resource::reload(void)
97        {
98                OGRE_LOCK_AUTO_MUTEX
99                if (mIsLoaded)
100                {
101                        unload();
102                        load();
103                }
104        }
105        //-----------------------------------------------------------------------
106        void Resource::touch(void)
107        {
108                OGRE_LOCK_AUTO_MUTEX
109        // make sure loaded
110        load();
111
112                if(mCreator)
113                        mCreator->_notifyResourceTouched(this);
114        }
115        //-----------------------------------------------------------------------
116
117
118}
Note: See TracBrowser for help on using the repository browser.