(ios) perform a small change about how to close the game window, should hopefully save memory and avoid crashes (who am i kidding? that's the usual PR talk...)
--- a/hedgewars/PascalExports.pas Thu Jan 20 01:27:51 2011 +0100
+++ b/hedgewars/PascalExports.pas Thu Jan 20 01:49:20 2011 +0100
@@ -22,7 +22,7 @@
interface
uses uTypes, uConsts, uVariables, GLunit, uKeys, uChat, uSound, uAmmos, uUtils,
- uCommands;
+ uCommands, uMobile;
{$INCLUDE "config.inc"}
@@ -38,6 +38,7 @@
versionStr^:= cVersionString;
end;
+// emulate mouse/keyboard input
procedure HW_click; cdecl; export;
begin
leftClick:= true;
@@ -190,12 +191,15 @@
GameState:= previousGameState;
end;
+// equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
procedure HW_terminate(closeFrontend: boolean); cdecl; export;
begin
- isTerminated:= true;
- if closeFrontend then alsoShutdownFrontend:= true;
+ {$IFDEF IPHONEOS}setGameRunning(false);{$ENDIF}
+ alsoShutdownFrontend:= closeFrontend;
+ ParseCommand('forcequit', true);
end;
+// cursor handling
procedure HW_setCursor(x,y: LongInt); cdecl; export;
begin
CursorPoint.X:= x;
@@ -208,9 +212,10 @@
y^:= CursorPoint.Y;
end;
+// ammo menu related functions
function HW_isAmmoMenuOpen: boolean; cdecl; export;
begin
- exit(bShowAmmoMenu);
+ exit( bShowAmmoMenu );
end;
function HW_isAmmoMenuNotAllowed: boolean; cdecl; export;
@@ -219,11 +224,6 @@
((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
end;
-function HW_isWaiting: boolean; cdecl; export;
-begin
- exit( ReadyTimeLeft > 0 );
-end;
-
function HW_isWeaponRequiringClick: boolean; cdecl; export;
begin
if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
--- a/hedgewars/uMobile.pas Thu Jan 20 01:27:51 2011 +0100
+++ b/hedgewars/uMobile.pas Thu Jan 20 01:49:20 2011 +0100
@@ -28,6 +28,7 @@
procedure stopSpinning; cdecl; external;
procedure replayBegan; cdecl; external;
procedure replayFinished; cdecl; external;
+procedure setGameRunning(arg: boolean); cdecl; external;
procedure updateVisualsNewTurn; cdecl; external;
function isApplePhone: Boolean; cdecl; external;
function isAppleDeviceMuted: Boolean; cdecl; external;
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Jan 20 01:49:20 2011 +0100
@@ -43,7 +43,6 @@
switch (theButton.tag) {
case 0:
- playSound(@"backSound");
if ([self.mapConfigViewController busy]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
message:NSLocalizedString(@"Before returning the preview needs to be generated",@"")
@@ -52,8 +51,10 @@
otherButtonTitles:nil];
[alert show];
[alert release];
- } else
+ } else {
+ playSound(@"backSound");
[[self parentViewController] dismissModalViewControllerAnimated:YES];
+ }
break;
case 1:
playSound(@"clickSound");
@@ -233,14 +234,14 @@
@"",@"savefile",
nil];
-
+ // also modify SavedGamesViewController.m
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
- [self presentModalViewController:statsPage animated:NO];
+ // avoid showing the stat page immediately, but wait for 3 seconds
+ [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
- // also modify SavedGamesViewController.m
NSArray *stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
if ([stats count] <= 1) {
DLog(@"%@",stats);
@@ -251,7 +252,6 @@
[statsPage viewWillAppear:YES];
}
-
[statsPage release];
}
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Jan 20 01:49:20 2011 +0100
@@ -396,8 +396,9 @@
case 'q':
// game ended, can remove the savefile
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
- // and remove + disable the overlay
- [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil];
+ break;
+ case 'Q':
+ // game exited but not completed, nothing to do (just don't save the message)
break;
default:
[self dumpRawData:buffer ofSize:msgSize];
@@ -405,14 +406,14 @@
}
}
DLog(@"Engine exited, ending thread");
- // wait a little to let the client close cleanly
- [NSThread sleepForTimeInterval:2];
+
// Close the client socket
SDLNet_TCP_Close(csd);
SDLNet_Quit();
[pool release];
- //Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution.
+ // Invoking this method should be avoided as it does not give your thread a chance
+ // to clean up any resources it allocated during its execution.
//[NSThread exit];
}
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Thu Jan 20 01:49:20 2011 +0100
@@ -194,7 +194,7 @@
}
if ([actionSheet cancelButtonIndex] != buttonIndex)
- [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil];
+ HW_terminate(NO);
}
@end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Thu Jan 20 01:49:20 2011 +0100
@@ -82,6 +82,5 @@
-(void) dismissPopover;
-(void) dimOverlay;
-(void) activateOverlay;
--(void) cleanup;
@end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Jan 20 01:49:20 2011 +0100
@@ -186,11 +186,6 @@
name:@"show help ingame"
object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(cleanup)
- name:@"remove overlay"
- object:nil];
-
// for iOS >= 3.2
if ([UIScreen respondsToSelector:@selector(screens)]) {
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -235,7 +230,7 @@
otherButtonTitles:nil];
[alert show];
[alert release];
- [self cleanup];
+ HW_terminate(NO);
}
}
@@ -257,13 +252,6 @@
doNotDim();
}
--(void) cleanup {
- [self dismissPopover];
- setGameRunning(NO);
- HW_terminate(NO);
- [self.view removeFromSuperview];
-}
-
-(void) didReceiveMemoryWarning {
if (self.popupMenu.view.superview == nil)
self.popupMenu = nil;
@@ -457,7 +445,7 @@
// present a further check before closing game
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
if ([actionSheet cancelButtonIndex] != buttonIndex)
- [self cleanup];
+ HW_terminate(NO);
else
HW_pause();
}
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Thu Jan 20 01:27:51 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Thu Jan 20 01:49:20 2011 +0100
@@ -218,13 +218,14 @@
[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:self.interfaceOrientation] forKey:@"orientation"],@"game_dictionary",
nil];
+ // also modify GameConfigViewController.m
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
- [self presentModalViewController:statsPage animated:NO];
+ // avoid showing the stat page immediately, but wait for 3 seconds
+ [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
- // also modify GameConfigViewController.m
NSArray *stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
if ([stats count] <= 1) {
DLog(@"%@",stats);