Skip to content
Browse files

Added static reference counting and removal of cache to SpriteSheetCo…

…mponent so there is never persistent cache if its not being used.
  • Loading branch information...
1 parent 363501d commit cdce6f7fe15db9e7f202822bbb79de0f1ad6450e @hybridmindset committed Nov 8, 2011
Showing with 28 additions and 21 deletions.
  1. +28 −21 src/com/pblabs/rendering2D/spritesheet/SpriteSheetComponent.as
View
49 src/com/pblabs/rendering2D/spritesheet/SpriteSheetComponent.as
@@ -123,7 +123,7 @@ package com.pblabs.rendering2D.spritesheet
_failed = false;
_image = value;
- _imageFilename = _image ? _image.filename : "";
+ if(_image) _imageFilename = _image.filename;
deleteFrames();
}
@@ -174,14 +174,6 @@ package com.pblabs.rendering2D.spritesheet
protected override function deleteFrames():void
{
- if(getCachedFrames()){
- getCachedFrames().referenceCount--;
- if(getCachedFrames().referenceCount < 0){
- /*_frameCache[getFramesCacheKey()].destroy();
- delete _frameCache[getFramesCacheKey()];*/
- getCachedFrames().referenceCount = 0;
- }
- }
super.deleteFrames();
}
@@ -198,10 +190,10 @@ package com.pblabs.rendering2D.spritesheet
return null;
var cachedFrames : CachedFramesData = getCachedFrames();
- if (cachedFrames)
+ if (cached && cachedFrames)
{
- cachedFrames.referenceCount++;
- _divider = cachedFrames.divider;
+ cachedFrames.referenceCount += 1;
+ _divider = cachedFrames.divider ? cachedFrames.divider : _divider;
return cachedFrames.frames;
}
@@ -223,9 +215,11 @@ package com.pblabs.rendering2D.spritesheet
}
}
- var frameCache : CachedFramesData = new CachedFramesData(_frames, image.filename, _divider);
- frameCache.referenceCount++;
- setCachedFrames(frameCache);
+ if(cached){
+ var frameCache : CachedFramesData = new CachedFramesData(_frames, imageFilename, _divider);
+ frameCache.referenceCount += 1;
+ setCachedFrames(frameCache);
+ }
return _frames;
}
@@ -255,13 +249,26 @@ package com.pblabs.rendering2D.spritesheet
}
this.deleteFrames();
- //TODO Add reference count check here to decide if we want to delete cache
- delete _frameCache[getFramesCacheKey()];
+ if(getCachedFrames() && getCachedFrames().referenceCount != 0){
+ getCachedFrames().referenceCount -= 1;
+ }
- if(_divider){
- _divider.owningSheet = null;
- _divider = null;
+ if(cached && getCachedFrames() && getCachedFrames().referenceCount <= 0){
+ getCachedFrames().destroy();
+ delete _frameCache[getFramesCacheKey()];
+ //Divider is cleaned up in the CachedFramesData.destroy()
+ }else{
+ if(_divider){
+ _divider.destroy();
+ _divider.owningSheet = null;
+ _divider = null;
+ }
}
+ //TODO Add reference count check here to decide if we want to delete cache
+ /*if(getCachedFrames() && getCachedFrames().referenceCount <= 0){
+ Logger.print(this, "Deleting SpriteSheet With Key ["+getFramesCacheKey()+"]");
+ }*/
+
if(_imageData) _imageData = null;
image = null;
@@ -328,7 +335,7 @@ package com.pblabs.rendering2D.spritesheet
protected function getFramesCacheKey():String
{
- return _image ? _image.filename : "";
+ return imageFilename;
}

0 comments on commit cdce6f7

Please sign in to comment.
Something went wrong with that request. Please try again.