Mercurial > fife-parpg
annotate engine/core/util/resource/resource_ptr.h @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | 6e7d228def30 |
children |
rev | line source |
---|---|
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 * Lesser General Public License for more details. * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 * License along with this library; if not, write to the * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 #ifndef FIFE_RESOURE_PTR_H |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 #define FIFE_RESOURE_PTR_H |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 // Standard C++ library includes |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 // 3rd party library includes |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 // FIFE includes |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 // These includes are split up in two parts, separated by one empty line |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 // First block: files included from the FIFE root src directory |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 // Second block: files included from the same folder |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 #include "resource.h" |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 #include "pool.h" |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 namespace FIFE { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 /** A lazy loading resource. |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 */ |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 class ResourcePtr { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 public: |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 ResourcePtr(IResource* ptr = 0) : m_ptr(ptr),m_pool(0),m_index(Pool::INVALID_ID) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 if( m_ptr ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 m_ptr->addRef(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 ResourcePtr(Pool* pool,int index) : m_ptr(0),m_pool(pool),m_index(index) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 ResourcePtr(const ResourcePtr& r) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 : m_ptr(r.m_ptr),m_pool(r.m_pool),m_index(r.m_index) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 if(m_ptr) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 m_ptr->addRef(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 ResourcePtr& operator=(const ResourcePtr& r) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 if( this == &r ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 return *this; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 release(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 m_ptr = r.m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 m_pool = r.m_pool; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 m_index = r.m_index; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 if(m_ptr) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 m_ptr->addRef(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 return *this; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 ~ResourcePtr() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 release(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 IResource& operator->() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 load(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 return *m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 const IResource& operator->() const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 constLoad(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 return *m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 operator bool() const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 return isValid(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 bool isValid() const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 return m_ptr || isLoadable(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 bool isLoadable() const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 return m_pool && m_index != Pool::INVALID_ID; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 bool operator==(const ResourcePtr& r) const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 if( isLoadable() && r.isLoadable() ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 return m_index == r.m_index && m_pool == r.m_pool; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 if( !isLoadable() && !r.isLoadable() ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 return m_ptr == r.m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 return false; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 bool operator<(const ResourcePtr& r) const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 if( isLoadable() && r.isLoadable() ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 if( m_pool == r.m_pool ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 return m_index < r.m_index; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 return m_pool < r.m_pool; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 if( !isLoadable() && !r.isLoadable() ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 return m_ptr < r.m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 return isLoadable() < r.isLoadable(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 void release() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 if(m_ptr) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 m_ptr->decRef(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 m_ptr = 0; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 void load() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 constLoad(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 void unload() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 release(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 if( isLoadable() ) { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 m_pool->release(m_index); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 template<class T> |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 T* get() { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 if( isValid() ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 load(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 return dynamic_cast<T*>(m_ptr); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 private: |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 void constLoad() const { |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 if( m_ptr ) |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 return; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 m_ptr = &m_pool->get(m_index); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 m_ptr->addRef(); |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 mutable IResource* m_ptr; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 Pool* m_pool; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 int m_index; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 }; |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 } |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 #endif |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 |