summaryrefslogtreecommitdiff
path: root/src/resources/resource.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-23 23:33:34 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-23 23:33:34 +0000
commit4b0172d1f666a12cffbdd6bd331e95a92d8f652f (patch)
treedde7ab71fd5d02200be35e041b00e5649f9cd3a8 /src/resources/resource.cpp
parent33587089cf7d87bbc2104e80746fdddc7a5498e1 (diff)
downloadmana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.gz
mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.bz2
mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.xz
mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.zip
Finishing resource manager ability to clean up resources. Still work to do on
resources other than images.
Diffstat (limited to 'src/resources/resource.cpp')
-rw-r--r--src/resources/resource.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index b3aa80f6..3ff8064d 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -22,49 +22,45 @@
*/
#include "resource.h"
+#include "resourcemanager.h"
Resource::Resource():
- referenceCount(0)
+ mRefCount(0)
{
}
Resource::~Resource()
{
- // TODO: Notify resource manager about this resource being deleted
}
-bool Resource::isLoaded() const
+void
+Resource::setIdPath(const std::string &idPath)
{
- return loaded;
+ mIdPath = idPath;
}
-void Resource::incRef()
+void
+Resource::incRef()
{
- referenceCount++;
+ mRefCount++;
}
-bool Resource::decRef()
+bool
+Resource::decRef()
{
- /* Warning: There is still a serious problem with the object deleting
- * itself and that is that the resource manager doesn't know about it
- * currently, causing it to crash while trying to clean up. Don't use
- * this function until that is solved. Probably we'll have to make it
- * so that decrementing count goes through resource manager too.
- */
- if (referenceCount > 0)
- {
- referenceCount--;
+ // Reference may not already have reached zero
+ assert(mRefCount != 0);
- if (referenceCount == 0) {
- //delete this;
- return true;
- }
- else {
- return false;
- }
+ mRefCount--;
+
+ if (mRefCount == 0) {
+ // Make sure resource manager won't refer to deleted resource
+ ResourceManager *resman = ResourceManager::getInstance();
+ resman->release(mIdPath);
+ delete this;
+ return true;
}
else {
- // Warning: Shouldn't get here!
- return true;
+ return false;
}
}