Improved efficiency of retrieving unique (non-merged) files in ResourceManager. Changed OOTextureLoader semantics slightly to avoid memory leak when releasing a texture which hasn't completed loading yet.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@943 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-04-20 23:51:27 +00:00
parent 9e9923f285
commit 3e240cf86c
4 changed files with 36 additions and 12 deletions

View File

@ -64,7 +64,12 @@ typedef enum
- (BOOL)isReady;
// Return value indicates success of loading.
/* Return value indicates success. This may only be called once (subsequent
attempts will return failure). This is basically necessary so that the
loader can free() the data if it's still there on dealloc - an alternative
would be to have an explicit -drop, but there's no real need to get at
data more than once, so we don't bother.
*/
- (BOOL)getResult:(void **)outData
format:(OOTextureDataFormat *)outFormat
width:(uint32_t *)outWidth

View File

@ -159,6 +159,7 @@ enum
if (EXPECT_NOT(next != nil || prev != nil)) [self unqueue];
[path release];
[completionLock release];
if (data != NULL) free(data);
[super dealloc];
}
@ -190,7 +191,7 @@ enum
width:(uint32_t *)outWidth
height:(uint32_t *)outHeight
{
if (EXPECT_NOT(completionLock != NULL))
if (completionLock != NULL)
{
/* If the lock exists, we must block on it until it is unlocked by
the loader thread, _even if the ready flag is set_, because of
@ -202,6 +203,9 @@ enum
enough about threading to optimize out this unlock. If you do, and
you're sure it can be bypassed safely, you may be right. :-)
-- Ahruman
Additional note: since it's not meaningful to call getResult...
more than once, the lock will probably be there every time.
*/
priority = YES;
@ -214,12 +218,25 @@ enum
if (block) OOLog(@"textureLoader.block.done", @"Finished waiting around.");
}
if (EXPECT(outData != NULL)) *outData = data;
if (EXPECT(outFormat != NULL)) *outFormat = format;
if (EXPECT(outWidth != NULL)) *outWidth = width;
if (EXPECT(outHeight != NULL)) *outHeight = height;
return data != nil;
if (data != NULL)
{
if (outData != NULL) *outData = data;
if (outFormat != NULL) *outFormat = format;
if (outWidth != NULL) *outWidth = width;
if (outHeight != NULL) *outHeight = height;
data = NULL;
return YES;
}
else
{
if (outData != NULL) *outData = NULL;
if (outFormat != NULL) *outFormat = kOOTextureDataInvalid;
if (outWidth != NULL) *outWidth = 0;
if (outHeight != NULL) *outHeight = 0;
return NO;
}
}

View File

@ -76,8 +76,10 @@ static void ScaleToHalf_4_x1(void *srcBytes, void *dstBytes, OOTextureDimension
#endif
OOINLINE void StretchVertically1(OOScalerPixMap srcPx, OOScalerPixMap dstPx, OOTexturePlaneCount planes) ALWAYS_INLINE_FUNC;
OOINLINE void StretchVertically(OOScalerPixMap srcPx, OOScalerPixMap dstPx, OOTexturePlaneCount planes) ALWAYS_INLINE_FUNC;
static void StretchVerticallyN_x1(OOScalerPixMap srcPx, OOScalerPixMap dstPx, OOTexturePlaneCount planes);
static void SqueezeVertically4(OOScalerPixMap srcPx, OOTextureDimension dstHeight);
static void SqueezeVertically1(OOScalerPixMap srcPx, OOTextureDimension dstHeight);
static void StretchHorizontally1(OOScalerPixMap srcPx, OOScalerPixMap dstPx);

View File

@ -486,20 +486,20 @@ static NSMutableDictionary* surface_cache;
// Search for file
fmgr = [NSFileManager defaultManager];
for (pathEnum = [[ResourceManager paths] objectEnumerator]; (path = [pathEnum nextObject]); )
for (pathEnum = [[ResourceManager paths] reverseObjectEnumerator]; (path = [pathEnum nextObject]); )
{
filePath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
if ([fmgr fileExistsAtPath:filePath])
{
result = filePath;
// break;
break;
}
filePath = [path stringByAppendingPathComponent:fileName];
if ([fmgr fileExistsAtPath:filePath])
{
result = filePath;
// break;
break;
}
}