1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://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 |
|
---|
32 | namespace 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 | if (mGroup == ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
|
---|
71 | {
|
---|
72 | // Derive resource group
|
---|
73 | changeGroupOwnership(
|
---|
74 | ResourceGroupManager::getSingleton()
|
---|
75 | .findGroupContainingResource(mName));
|
---|
76 | }
|
---|
77 | loadImpl();
|
---|
78 | }
|
---|
79 | // Calculate resource size
|
---|
80 | mSize = calculateSize();
|
---|
81 | // Now loaded
|
---|
82 | mIsLoaded = true;
|
---|
83 | // Notify manager
|
---|
84 | if(mCreator)
|
---|
85 | mCreator->_notifyResourceLoaded(this);
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|
89 | //-----------------------------------------------------------------------
|
---|
90 | void Resource::changeGroupOwnership(const String& newGroup)
|
---|
91 | {
|
---|
92 | if (mGroup != newGroup)
|
---|
93 | {
|
---|
94 | String oldGroup = mGroup;
|
---|
95 | mGroup = newGroup;
|
---|
96 | ResourceGroupManager::getSingleton()
|
---|
97 | ._notifyResourceGroupChanged(oldGroup, this);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | //-----------------------------------------------------------------------
|
---|
101 | void Resource::unload(void)
|
---|
102 | {
|
---|
103 | OGRE_LOCK_AUTO_MUTEX
|
---|
104 | if (mIsLoaded)
|
---|
105 | {
|
---|
106 | unloadImpl();
|
---|
107 | mIsLoaded = false;
|
---|
108 | // Notify manager
|
---|
109 | if(mCreator)
|
---|
110 | mCreator->_notifyResourceUnloaded(this);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | //-----------------------------------------------------------------------
|
---|
114 | void Resource::reload(void)
|
---|
115 | {
|
---|
116 | OGRE_LOCK_AUTO_MUTEX
|
---|
117 | if (mIsLoaded)
|
---|
118 | {
|
---|
119 | unload();
|
---|
120 | load();
|
---|
121 | }
|
---|
122 | }
|
---|
123 | //-----------------------------------------------------------------------
|
---|
124 | void Resource::touch(void)
|
---|
125 | {
|
---|
126 | OGRE_LOCK_AUTO_MUTEX
|
---|
127 | // make sure loaded
|
---|
128 | load();
|
---|
129 |
|
---|
130 | if(mCreator)
|
---|
131 | mCreator->_notifyResourceTouched(this);
|
---|
132 | }
|
---|
133 | //-----------------------------------------------------------------------
|
---|
134 |
|
---|
135 |
|
---|
136 | }
|
---|