Permalink
Browse files

Fixes controls issues with scripted pause

Moves the pause code from pollFlightControls and pollDockedControls into Univerese pauseGame and the resume code into a new Universe method resumeGame.
Global pauseGame can now safely call Universe pauseGame.
Adds some setter methods in Ship and Player entities to restore saved state from Universe.
  • Loading branch information...
jobi-wan committed Nov 5, 2017
1 parent 8d5277d commit 4ffe59da4dc2946ac855aded0db44ec7e22b19d0
@@ -1047,6 +1047,7 @@ typedef enum
- (void) noteGUIDidChangeFrom:(OOGUIScreenID)fromScreen to:(OOGUIScreenID)toScreen;
- (void) noteViewDidChangeFrom:(OOViewID)fromView toView:(OOViewID)toView;
- (void) setGuiScreen:(OOGUIScreenID)screen;
- (OOGUIScreenID) guiScreen;
- (void) buySelectedItem;
@@ -11054,6 +11054,11 @@ - (void) showMarketCashAndLoadLine
[gui setColor:[gui colorFromSetting:kGuiMarketCashColor defaultValue:[OOColor yellowColor]] forRow:GUI_ROW_MARKET_CASH];
}
- (void) setGuiScreen:(OOGUIScreenID)screen;
{
gui_screen = screen;
}
- (OOGUIScreenID) guiScreen
{
return gui_screen;
@@ -148,10 +148,6 @@
static NSUInteger searchStringLength;
static double timeLastKeyPress;
//static OOGUIRow oldSelection;
static int saved_view_direction;
static double saved_script_time;
static int saved_gui_screen;
static OOWeaponFacing saved_weapon_facing;
static int pressedArrow = 0;
static BOOL mouse_x_axis_map_to_yaw = NO;
static NSTimeInterval time_last_frame;
@@ -665,13 +661,7 @@ - (void) pollApplicationControls
default:
{
// In all other cases we can't handle pause. Unpause immediately.
script_time = saved_script_time;
[gameView allowStringInput:NO];
if ([UNIVERSE pauseMessageVisible])
{
[UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
}
[gameController setGamePaused:NO];
[UNIVERSE resumeGame];
}
break;
}
@@ -1594,54 +1584,12 @@ - (void) pollFlightControls:(double)delta_t
{
if (paused)
{
script_time = saved_script_time;
// Reset to correct GUI screen, if we are unpausing from one.
// Don't set gui_screen here, use setGuis - they also switch backgrounds.
// No gui switching events will be triggered while still paused.
switch (saved_gui_screen)
{
case GUI_SCREEN_STATUS:
[self setGuiToStatusScreen];
break;
case GUI_SCREEN_LONG_RANGE_CHART:
[self setGuiToLongRangeChartScreen];
break;
case GUI_SCREEN_SHORT_RANGE_CHART:
[self setGuiToShortRangeChartScreen];
break;
case GUI_SCREEN_MANIFEST:
[self setGuiToManifestScreen];
break;
case GUI_SCREEN_MARKET:
[self setGuiToMarketScreen];
break;
case GUI_SCREEN_MARKETINFO:
[self setGuiToMarketInfoScreen];
break;
case GUI_SCREEN_SYSTEM_DATA:
// Do not reset planet rotation if we are already in the system info screen!
if (gui_screen != GUI_SCREEN_SYSTEM_DATA)
[self setGuiToSystemDataScreen];
break;
default:
gui_screen = saved_gui_screen; // make sure we're back to the right screen
break;
}
[gameView allowStringInput:NO];
[UNIVERSE clearPreviousMessage];
[UNIVERSE setViewDirection:saved_view_direction];
currentWeaponFacing = saved_weapon_facing;
[UNIVERSE resumeGame];
// make sure the light comes from the right direction after resuming from pause!
if (saved_gui_screen == GUI_SCREEN_SYSTEM_DATA) [UNIVERSE setMainLightPosition:_sysInfoLight];
[[UNIVERSE gui] setForegroundTextureKey:@"overlay"];
[[UNIVERSE gameController] setGamePaused:NO];
if (gui_screen == GUI_SCREEN_SYSTEM_DATA) [UNIVERSE setMainLightPosition:_sysInfoLight];
}
else
{
saved_view_direction = [UNIVERSE viewDirection];
saved_script_time = script_time;
saved_gui_screen = gui_screen;
saved_weapon_facing = currentWeaponFacing;
[UNIVERSE pauseGame]; // pause handler
}
}
@@ -4227,20 +4175,10 @@ - (void) pollDockedControls:(double)delta_t
{
if ([gameController isGamePaused])
{
script_time = saved_script_time;
[gameView allowStringInput:NO];
if ([UNIVERSE pauseMessageVisible])
{
[UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
}
[[UNIVERSE gui] setForegroundTextureKey:@"docked_overlay"];
[gameController setGamePaused:NO];
[UNIVERSE resumeGame];
}
else
{
saved_script_time = script_time;
[[UNIVERSE messageGUI] clear];
[UNIVERSE pauseGame]; // 'paused' handler
}
}
@@ -52,6 +52,7 @@ MA 02110-1301, USA.
- (void) allowMissionInterrupt;
- (OOTimeDelta) scriptTimer;
- (void) setScriptTimer:(double)time;
- (unsigned) systemPseudoRandom100;
- (unsigned) systemPseudoRandom256;
@@ -227,6 +227,12 @@ - (OOTimeDelta) scriptTimer
}
- (void) setScriptTimer:(double)time
{
script_time = time;
}
/* FIXME: these next three functions seed the RNG when called. That
* could cause unwanted effects - should save its state, and then
* reset it after generating the number. */
@@ -837,6 +837,7 @@ typedef enum
- (float) weaponRechargeRate;
- (void) setWeaponRechargeRate:(float)value;
- (void) setWeaponEnergy:(float)value;
- (void) setWeaponFacing:(OOWeaponFacing)weaponFacing;
- (OOWeaponFacing) currentWeaponFacing;
- (GLfloat) scannerRange;
@@ -7511,6 +7511,10 @@ - (void) setWeaponEnergy:(float)value
weapon_damage = value;
}
- (void) setWeaponFacing:(OOWeaponFacing)weaponFacing
{
currentWeaponFacing = weaponFacing;
}
- (OOWeaponFacing) currentWeaponFacing
{
View
@@ -364,6 +364,7 @@ enum
#endif
- (void) pauseGame;
- (void) resumeGame;
- (void) carryPlayerOn:(StationEntity*)carrier inWormhole:(WormholeEntity*)wormhole;
- (void) setUpUniverseFromStation;
View
@@ -560,17 +560,24 @@ - (NSArray *) entityList
}
#endif
static int saved_view_direction;
static double saved_script_time;
static int saved_gui_screen;
static OOWeaponFacing saved_weapon_facing;
- (void) pauseGame
{
// deal with the machine going to sleep, or player pressing 'p'.
PlayerEntity *player = PLAYER;
PlayerEntity *player = PLAYER;
NSString *pauseKey = [PLAYER keyBindingDescription:@"key_pausebutton"];
[self setPauseMessageVisible:NO];
NSString *pauseKey = [PLAYER keyBindingDescription:@"key_pausebutton"];
saved_script_time = [player scriptTimer];
if ([player status] == STATUS_DOCKED)
{
[message_gui clear];
if ([gui setForegroundTextureKey:@"paused_docked_overlay"])
{
[gui drawGUI:1.0 drawCursor:NO];
@@ -583,6 +590,10 @@ - (void) pauseGame
}
else
{
saved_view_direction = viewDirection;
saved_gui_screen = [player guiScreen];
saved_weapon_facing = [player currentWeaponFacing];
if ([player guiScreen] != GUI_SCREEN_MAIN && [gui setForegroundTextureKey:@"paused_overlay"])
{
[gui drawGUI:1.0 drawCursor:NO];
@@ -598,6 +609,66 @@ - (void) pauseGame
}
- (void) resumeGame
{
PlayerEntity *player = PLAYER;
[player setScriptTimer:saved_script_time];
if ([player status] == STATUS_DOCKED)
{
[gameView allowStringInput:NO];
if (_pauseMessage)
{
[self clearPreviousMessage]; // remove the 'paused' message.
}
[gui setForegroundTextureKey:@"docked_overlay"];
}
else
{
// Reset to correct GUI screen, if we are unpausing from one.
// Don't set gui_screen here, use setGuis - they also switch backgrounds.
// No gui switching events will be triggered while still paused.
switch (saved_gui_screen)
{
case GUI_SCREEN_STATUS:
[player setGuiToStatusScreen];
break;
case GUI_SCREEN_LONG_RANGE_CHART:
[player setGuiToLongRangeChartScreen];
break;
case GUI_SCREEN_SHORT_RANGE_CHART:
[player setGuiToShortRangeChartScreen];
break;
case GUI_SCREEN_MANIFEST:
[player setGuiToManifestScreen];
break;
case GUI_SCREEN_MARKET:
[player setGuiToMarketScreen];
break;
case GUI_SCREEN_MARKETINFO:
[player setGuiToMarketInfoScreen];
break;
case GUI_SCREEN_SYSTEM_DATA:
// Do not reset planet rotation if we are already in the system info screen!
if ([player guiScreen] != GUI_SCREEN_SYSTEM_DATA)
[player setGuiToSystemDataScreen];
break;
default:
[player setGuiScreen:saved_gui_screen]; // make sure we're back to the right screen
break;
}
[gameView allowStringInput:NO];
[self clearPreviousMessage];
[self setViewDirection:saved_view_direction];
[player setWeaponFacing:saved_weapon_facing];
[gui setForegroundTextureKey:@"overlay"];
}
[[self gameController] setGamePaused:NO];
}
- (void) carryPlayerOn:(StationEntity*)carrier inWormhole:(WormholeEntity*)wormhole
{
PlayerEntity *player = PLAYER;

0 comments on commit 4ffe59d

Please sign in to comment.