Cocoa Port:

- Load cheat item icons higher up in the front-end code.
- Remove CocoaDSCheatManager's and CocoaDSCheatSearch's dependence on CocoaDSCore. Just use basic mutex pointers instead.
This commit is contained in:
rogerman 2013-11-28 08:51:43 +00:00
parent f9f6a74a72
commit ddf957fcf7
4 changed files with 173 additions and 70 deletions

View File

@ -20,8 +20,6 @@
#include "../cheatSystem.h" #include "../cheatSystem.h"
#undef BOOL #undef BOOL
@class CocoaDSCore;
/******************************************************************************************** /********************************************************************************************
CocoaDSCheatItem - OBJECTIVE-C CLASS CocoaDSCheatItem - OBJECTIVE-C CLASS
@ -74,6 +72,13 @@
- (void) setDataWithDictionary:(NSDictionary *)dataDict; - (void) setDataWithDictionary:(NSDictionary *)dataDict;
- (NSDictionary *) dataDictionary; - (NSDictionary *) dataDictionary;
+ (void) setIconInternalCheat:(NSImage *)iconImage;
+ (NSImage *) iconInternalCheat;
+ (void) setIconActionReplay:(NSImage *)iconImage;
+ (NSImage *) iconActionReplay;
+ (void) setIconCodeBreaker:(NSImage *)iconImage;
+ (NSImage *) iconCodeBreaker;
@end @end
/******************************************************************************************** /********************************************************************************************
@ -89,7 +94,9 @@
CHEATS *listData; CHEATS *listData;
NSMutableArray *list; NSMutableArray *list;
CocoaDSCore *cdsCore; pthread_mutex_t *mutexCoreExecute;
BOOL isUsingDummyMutex;
NSUInteger untitledCount; NSUInteger untitledCount;
NSString *dbTitle; NSString *dbTitle;
NSString *dbDate; NSString *dbDate;
@ -97,15 +104,14 @@
@property (readonly) CHEATS *listData; @property (readonly) CHEATS *listData;
@property (readonly) NSMutableArray *list; @property (readonly) NSMutableArray *list;
@property (retain) CocoaDSCore *cdsCore; @property (assign) pthread_mutex_t *mutexCoreExecute;
@property (assign) NSUInteger untitledCount; @property (assign) NSUInteger untitledCount;
@property (copy) NSString *dbTitle; @property (copy) NSString *dbTitle;
@property (copy) NSString *dbDate; @property (copy) NSString *dbDate;
- (id) initWithCore:(CocoaDSCore *)core; - (id) initWithFileURL:(NSURL *)fileURL;
- (id) initWithCore:(CocoaDSCore *)core fileURL:(NSURL *)fileURL; - (id) initWithListData:(CHEATS *)cheatList;
- (id) initWithCore:(CocoaDSCore *)core listData:(CHEATS *)cheatList; - (id) initWithFileURL:(NSURL *)fileURL listData:(CHEATS *)cheatList;
- (id) initWithCore:(CocoaDSCore *)core fileURL:(NSURL *)fileURL listData:(CHEATS *)cheatList;
- (BOOL) add:(CocoaDSCheatItem *)cheatItem; - (BOOL) add:(CocoaDSCheatItem *)cheatItem;
- (void) remove:(CocoaDSCheatItem *)cheatItem; - (void) remove:(CocoaDSCheatItem *)cheatItem;
@ -129,17 +135,17 @@
CHEATSEARCH *listData; CHEATSEARCH *listData;
NSMutableArray *addressList; NSMutableArray *addressList;
CocoaDSCore *cdsCore; pthread_mutex_t *mutexCoreExecute;
BOOL isUsingDummyMutex;
NSUInteger searchCount; NSUInteger searchCount;
} }
@property (readonly) CHEATSEARCH *listData; @property (readonly) CHEATSEARCH *listData;
@property (readonly) NSMutableArray *addressList; @property (readonly) NSMutableArray *addressList;
@property (retain) CocoaDSCore *cdsCore; @property (assign) pthread_mutex_t *mutexCoreExecute;
@property (readonly) NSUInteger searchCount; @property (readonly) NSUInteger searchCount;
- (id) initWithCore:(CocoaDSCore *)core;
- (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType; - (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType;
- (void) runExactValueSearchOnThread:(id)object; - (void) runExactValueSearchOnThread:(id)object;
- (NSUInteger) runComparativeSearch:(NSInteger)typeID byteSize:(UInt8)byteSize signType:(NSInteger)signType; - (NSUInteger) runComparativeSearch:(NSInteger)typeID byteSize:(UInt8)byteSize signType:(NSInteger)signType;

View File

@ -17,7 +17,6 @@
*/ */
#import "cocoa_cheat.h" #import "cocoa_cheat.h"
#import "cocoa_core.h"
#import "cocoa_globals.h" #import "cocoa_globals.h"
#import "cocoa_util.h" #import "cocoa_util.h"
@ -87,13 +86,6 @@ static NSImage *iconCodeBreaker = nil;
data = cheatData; data = cheatData;
} }
if (iconInternalCheat == nil || iconActionReplay == nil || iconCodeBreaker == nil)
{
iconInternalCheat = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AppIcon_DeSmuME" ofType:@"icns"]];
iconActionReplay = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Icon_ActionReplay_128x128" ofType:@"png"]];
iconCodeBreaker = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Icon_CodeBreaker_128x128" ofType:@"png"]];
}
pthread_mutex_init(&mutexData, NULL); pthread_mutex_init(&mutexData, NULL);
willAdd = NO; willAdd = NO;
@ -132,9 +124,7 @@ static NSImage *iconCodeBreaker = nil;
} }
pthread_mutex_lock(&mutexData); pthread_mutex_lock(&mutexData);
data = cheatData; data = cheatData;
pthread_mutex_unlock(&mutexData); pthread_mutex_unlock(&mutexData);
[self update]; [self update];
@ -633,6 +623,36 @@ static NSImage *iconCodeBreaker = nil;
nil]; nil];
} }
+ (void) setIconInternalCheat:(NSImage *)iconImage
{
iconInternalCheat = iconImage;
}
+ (NSImage *) iconInternalCheat
{
return iconInternalCheat;
}
+ (void) setIconActionReplay:(NSImage *)iconImage
{
iconActionReplay = iconImage;
}
+ (NSImage *) iconActionReplay
{
return iconActionReplay;
}
+ (void) setIconCodeBreaker:(NSImage *)iconImage
{
iconCodeBreaker = iconImage;
}
+ (NSImage *) iconCodeBreaker
{
return iconCodeBreaker;
}
@end @end
@ -640,32 +660,27 @@ static NSImage *iconCodeBreaker = nil;
@synthesize listData; @synthesize listData;
@synthesize list; @synthesize list;
@synthesize cdsCore; @dynamic mutexCoreExecute;
@synthesize untitledCount; @synthesize untitledCount;
@synthesize dbTitle; @synthesize dbTitle;
@synthesize dbDate; @synthesize dbDate;
- (id)init - (id)init
{ {
return [self initWithCore:nil fileURL:nil listData:nil]; return [self initWithFileURL:nil listData:nil];
} }
- (id) initWithCore:(CocoaDSCore *)core - (id) initWithFileURL:(NSURL *)fileURL
{ {
return [self initWithCore:core fileURL:nil listData:nil]; return [self initWithFileURL:fileURL listData:nil];
} }
- (id) initWithCore:(CocoaDSCore *)core fileURL:(NSURL *)fileURL - (id) initWithListData:(CHEATS *)cheatList
{ {
return [self initWithCore:core fileURL:fileURL listData:nil]; return [self initWithFileURL:nil listData:cheatList];
} }
- (id) initWithCore:(CocoaDSCore *)core listData:(CHEATS *)cheatList - (id) initWithFileURL:(NSURL *)fileURL listData:(CHEATS *)cheatList
{
return [self initWithCore:core fileURL:nil listData:cheatList];
}
- (id) initWithCore:(CocoaDSCore *)core fileURL:(NSURL *)fileURL listData:(CHEATS *)cheatList
{ {
self = [super init]; self = [super init];
if(self == nil) if(self == nil)
@ -705,7 +720,10 @@ static NSImage *iconCodeBreaker = nil;
} }
} }
cdsCore = [core retain]; mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(mutexCoreExecute, NULL);
isUsingDummyMutex = YES;
untitledCount = 0; untitledCount = 0;
dbTitle = nil; dbTitle = nil;
dbDate = nil; dbDate = nil;
@ -717,13 +735,50 @@ static NSImage *iconCodeBreaker = nil;
{ {
self.dbTitle = nil; self.dbTitle = nil;
self.dbDate = nil; self.dbDate = nil;
self.cdsCore = nil;
[list release]; [list release];
delete (CHEATS *)self.listData; delete (CHEATS *)self.listData;
if (isUsingDummyMutex)
{
pthread_mutex_destroy(mutexCoreExecute);
free(mutexCoreExecute);
mutexCoreExecute = NULL;
}
[super dealloc]; [super dealloc];
} }
- (void) setMutexCoreExecute:(pthread_mutex_t *)theMutex
{
if (theMutex == NULL && isUsingDummyMutex)
{
return;
}
else if (theMutex == NULL && !isUsingDummyMutex)
{
mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(mutexCoreExecute, NULL);
isUsingDummyMutex = YES;
return;
}
else if (theMutex != NULL && isUsingDummyMutex)
{
pthread_mutex_destroy(mutexCoreExecute);
free(mutexCoreExecute);
isUsingDummyMutex = NO;
mutexCoreExecute = theMutex;
}
else if (theMutex != NULL && !isUsingDummyMutex)
{
mutexCoreExecute = theMutex;
}
}
- (pthread_mutex_t *) mutexCoreExecute
{
return mutexCoreExecute;
}
- (BOOL) add:(CocoaDSCheatItem *)cheatItem - (BOOL) add:(CocoaDSCheatItem *)cheatItem
{ {
BOOL result = NO; BOOL result = NO;
@ -737,7 +792,7 @@ static NSImage *iconCodeBreaker = nil;
// to check if the list got reallocated. // to check if the list got reallocated.
CHEATS_LIST *cheatListData = self.listData->getListPtr(); CHEATS_LIST *cheatListData = self.listData->getListPtr();
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
switch (cheatItem.cheatType) switch (cheatItem.cheatType)
{ {
@ -769,7 +824,7 @@ static NSImage *iconCodeBreaker = nil;
break; break;
} }
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
if (![self.list containsObject:cheatItem]) if (![self.list containsObject:cheatItem])
{ {
@ -809,9 +864,9 @@ static NSImage *iconCodeBreaker = nil;
return; return;
} }
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
self.listData->remove(selectionIndex); self.listData->remove(selectionIndex);
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
// Removing an item from the raw cheat list data shifts all higher elements // Removing an item from the raw cheat list data shifts all higher elements
// by one, so we need to do the same. // by one, so we need to do the same.
@ -840,7 +895,7 @@ static NSImage *iconCodeBreaker = nil;
return result; return result;
} }
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
switch (cheatItem.cheatType) switch (cheatItem.cheatType)
{ {
@ -872,7 +927,7 @@ static NSImage *iconCodeBreaker = nil;
break; break;
} }
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
[cheatItem update]; [cheatItem update];
@ -881,18 +936,18 @@ static NSImage *iconCodeBreaker = nil;
- (BOOL) save - (BOOL) save
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
BOOL result = self.listData->save(); BOOL result = self.listData->save();
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
return result; return result;
} }
- (NSUInteger) activeCount - (NSUInteger) activeCount
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
NSUInteger activeCheatsCount = self.listData->getActiveCount(); NSUInteger activeCheatsCount = self.listData->getActiveCount();
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
return activeCheatsCount; return activeCheatsCount;
} }
@ -944,9 +999,9 @@ static NSImage *iconCodeBreaker = nil;
return; return;
} }
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
[CocoaDSCheatManager applyInternalCheatWithItem:cheatItem]; [CocoaDSCheatManager applyInternalCheatWithItem:cheatItem];
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
} }
+ (void) setMasterCheatList:(CocoaDSCheatManager *)cheatListManager + (void) setMasterCheatList:(CocoaDSCheatManager *)cheatListManager
@ -1071,15 +1126,10 @@ static NSImage *iconCodeBreaker = nil;
@synthesize listData; @synthesize listData;
@synthesize addressList; @synthesize addressList;
@synthesize cdsCore; @dynamic mutexCoreExecute;
@synthesize searchCount; @synthesize searchCount;
- (id)init - (id)init
{
return [self initWithCore:nil];
}
- (id) initWithCore:(CocoaDSCore *)core
{ {
self = [super init]; self = [super init];
if(self == nil) if(self == nil)
@ -1094,9 +1144,12 @@ static NSImage *iconCodeBreaker = nil;
return nil; return nil;
} }
mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(mutexCoreExecute, NULL);
isUsingDummyMutex = YES;
listData = newListData; listData = newListData;
addressList = nil; addressList = nil;
cdsCore = [core retain];
searchCount = 0; searchCount = 0;
return self; return self;
@ -1104,17 +1157,54 @@ static NSImage *iconCodeBreaker = nil;
- (void)dealloc - (void)dealloc
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
self.listData->close(); self.listData->close();
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
[addressList release]; [addressList release];
self.cdsCore = nil;
delete (CHEATSEARCH *)self.listData; delete (CHEATSEARCH *)self.listData;
if (isUsingDummyMutex)
{
pthread_mutex_destroy(mutexCoreExecute);
free(mutexCoreExecute);
mutexCoreExecute = NULL;
}
[super dealloc]; [super dealloc];
} }
- (void) setMutexCoreExecute:(pthread_mutex_t *)theMutex
{
if (theMutex == NULL && isUsingDummyMutex)
{
return;
}
else if (theMutex == NULL && !isUsingDummyMutex)
{
mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(mutexCoreExecute, NULL);
isUsingDummyMutex = YES;
return;
}
else if (theMutex != NULL && isUsingDummyMutex)
{
pthread_mutex_destroy(mutexCoreExecute);
free(mutexCoreExecute);
isUsingDummyMutex = NO;
mutexCoreExecute = theMutex;
}
else if (theMutex != NULL && !isUsingDummyMutex)
{
mutexCoreExecute = theMutex;
}
}
- (pthread_mutex_t *) mutexCoreExecute
{
return mutexCoreExecute;
}
- (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType - (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType
{ {
NSUInteger itemCount = 0; NSUInteger itemCount = 0;
@ -1124,17 +1214,17 @@ static NSImage *iconCodeBreaker = nil;
{ {
byteSize--; byteSize--;
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE, (u8)byteSize, (u8)signType); listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE, (u8)byteSize, (u8)signType);
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
} }
if (listExists) if (listExists)
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
itemCount = (NSUInteger)self.listData->search((u32)value); itemCount = (NSUInteger)self.listData->search((u32)value);
NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain]; NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain];
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
[addressList release]; [addressList release];
addressList = newAddressList; addressList = newAddressList;
@ -1161,18 +1251,18 @@ static NSImage *iconCodeBreaker = nil;
{ {
byteSize--; byteSize--;
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_COMPARATIVE, (u8)byteSize, (u8)signType); listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_COMPARATIVE, (u8)byteSize, (u8)signType);
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
addressList = nil; addressList = nil;
} }
else else
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
itemCount = (NSUInteger)self.listData->search((u8)typeID); itemCount = (NSUInteger)self.listData->search((u8)typeID);
NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain]; NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain];
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
[addressList release]; [addressList release];
addressList = newAddressList; addressList = newAddressList;
@ -1196,9 +1286,9 @@ static NSImage *iconCodeBreaker = nil;
- (void) reset - (void) reset
{ {
pthread_mutex_lock(self.cdsCore.mutexCoreExecute); pthread_mutex_lock([self mutexCoreExecute]);
self.listData->close(); self.listData->close();
pthread_mutex_unlock(self.cdsCore.mutexCoreExecute); pthread_mutex_unlock([self mutexCoreExecute]);
searchCount = 0; searchCount = 0;
[addressList release]; [addressList release];

View File

@ -1454,7 +1454,7 @@
// If the ROM has an associated cheat file, load it now. // If the ROM has an associated cheat file, load it now.
NSString *cheatsPath = [[CocoaDSFile fileURLFromRomURL:[theRom fileURL] toKind:@"Cheat"] path]; NSString *cheatsPath = [[CocoaDSFile fileURLFromRomURL:[theRom fileURL] toKind:@"Cheat"] path];
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content]; CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
CocoaDSCheatManager *newCheatList = [[[CocoaDSCheatManager alloc] initWithCore:cdsCore fileURL:[NSURL fileURLWithPath:cheatsPath]] autorelease]; CocoaDSCheatManager *newCheatList = [[[CocoaDSCheatManager alloc] initWithFileURL:[NSURL fileURLWithPath:cheatsPath]] autorelease];
if (newCheatList != nil) if (newCheatList != nil)
{ {
NSMutableDictionary *cheatWindowBindings = (NSMutableDictionary *)[cheatWindowController content]; NSMutableDictionary *cheatWindowBindings = (NSMutableDictionary *)[cheatWindowController content];
@ -1518,7 +1518,7 @@
} }
[cheatWindowDelegate setCdsCheats:newCheatList]; [cheatWindowDelegate setCdsCheats:newCheatList];
[[cheatWindowDelegate cdsCheatSearch] setCdsCore:cdsCore]; [[cheatWindowDelegate cdsCheatSearch] setMutexCoreExecute:[cdsCore mutexCoreExecute]];
[cheatWindowDelegate setCheatSearchViewByStyle:CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE]; [cheatWindowDelegate setCheatSearchViewByStyle:CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE];
} }

View File

@ -94,6 +94,13 @@
[bindings setValue:[NSNumber numberWithInteger:CHEATSEARCH_UNSIGNED] forKey:@"cheatSearchSignType"]; [bindings setValue:[NSNumber numberWithInteger:CHEATSEARCH_UNSIGNED] forKey:@"cheatSearchSignType"];
[bindings setValue:@"Search not started." forKey:@"cheatSearchAddressCount"]; [bindings setValue:@"Search not started." forKey:@"cheatSearchAddressCount"];
if ([CocoaDSCheatItem iconInternalCheat] == nil || [CocoaDSCheatItem iconActionReplay] == nil || [CocoaDSCheatItem iconCodeBreaker] == nil)
{
[CocoaDSCheatItem setIconInternalCheat:[[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AppIcon_DeSmuME" ofType:@"icns"]]];
[CocoaDSCheatItem setIconActionReplay:[[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Icon_ActionReplay_128x128" ofType:@"png"]]];
[CocoaDSCheatItem setIconCodeBreaker:[[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Icon_CodeBreaker_128x128" ofType:@"png"]]];
}
return self; return self;
} }