Skip to content

Commit

Permalink
Clean up deprecated methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
clobber committed Dec 13, 2015
1 parent 17374d5 commit 69b1717
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions VecXGL/VectrexGameCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
return YES;
}

- (void)executeFrameSkippingFrame:(BOOL)skip
- (void)executeFrame
{
// late init of the overlay

Expand All @@ -84,11 +84,6 @@ - (void)executeFrameSkippingFrame:(BOOL)skip
glFlush();
}

- (void)executeFrame
{
[self executeFrameSkippingFrame:NO];
}

- (void)startEmulation
{
if(!isRunning)
Expand Down Expand Up @@ -116,52 +111,35 @@ - (void)resetEmulation
vecx_reset();
}

- (BOOL)saveStateToFileAtPath:(NSString *)fileName
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
FILE *saveFile = fopen([fileName UTF8String], "wb");

VECXState *state = saveVecxState();

long bytesWritten = fwrite(state, sizeof(char), sizeof(VECXState), saveFile);

if(bytesWritten != sizeof(VECXState))
{
NSLog(@"Couldn't write state");
return NO;
}

fclose(saveFile);

free(state);

return YES;
NSData *data = [NSData dataWithBytesNoCopy:state length:sizeof(VECXState) freeWhenDone:YES];

NSError *error;
BOOL succeeded = [data writeToFile:fileName options:0 error:&error];
block(succeeded, error);
}

- (BOOL)loadStateFromFileAtPath:(NSString *)fileName
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
FILE *saveFile = fopen([fileName UTF8String], "rb");

if(saveFile == NULL)
{
NSLog(@"Could not open state file");
return NO;
NSError *error;
NSMutableData *data = [NSMutableData dataWithContentsOfFile:fileName options:0 error:&error];

if (!data) {
block(NO, error);
return;
}

VECXState *state = malloc(sizeof(VECXState));

if(!fread(state, sizeof(char), sizeof(VECXState), saveFile))
{
NSLog(@"Couldn't read file");
return NO;

if (sizeof(VECXState) != data.length) {
block(NO, [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
NSLocalizedFailureReasonErrorKey: @"THe size of the saved file is different from the size of the state.",
}]);
return;
}

fclose(saveFile);


VECXState *state = (void *)data.bytes;
loadVecxState(state);

free(state);

return YES;
}

- (OEIntSize)aspectSize
Expand Down

0 comments on commit 69b1717

Please sign in to comment.