widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #00147
[Merge] lp:~nomeata/widelands/bugfix536464 into lp:widelands
Joachim Breitner has proposed merging lp:~nomeata/widelands/bugfix536464 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
#536464 toggle pause with Pause key
https://bugs.launchpad.net/bugs/536464
Implements the PAUSE button, per bug #536464.
--
https://code.launchpad.net/~nomeata/widelands/bugfix536464/+merge/39200
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/bugfix536464 into lp:widelands.
=== modified file 'src/gamecontroller.cc'
--- src/gamecontroller.cc 2010-06-06 18:14:40 +0000
+++ src/gamecontroller.cc 2010-10-23 15:02:49 +0000
@@ -39,12 +39,15 @@
uint32_t realSpeed();
uint32_t desiredSpeed();
void setDesiredSpeed(uint32_t speed);
+ bool isPaused();
+ void setPaused(const bool paused);
private:
Widelands::Game & m_game;
bool m_useai;
int32_t m_lastframe;
int32_t m_time;
+ bool m_paused;
uint32_t m_speed; ///< current game speed, in milliseconds per second
uint32_t m_player_cmdserial;
Widelands::Player_Number m_local;
@@ -87,7 +90,7 @@
else if (frametime > 1000)
frametime = 1000;
- frametime = frametime * m_speed / 1000;
+ frametime = frametime * realSpeed() / 1000;
m_time = m_game.get_gametime() + frametime;
@@ -126,7 +129,10 @@
uint32_t SinglePlayerGameController::realSpeed()
{
- return m_speed;
+ if (m_paused)
+ return 0;
+ else
+ return m_speed;
}
uint32_t SinglePlayerGameController::desiredSpeed()
@@ -139,6 +145,15 @@
m_speed = speed;
}
+bool SinglePlayerGameController::isPaused()
+{
+ return m_paused;
+}
+
+void SinglePlayerGameController::setPaused(bool const paused)
+{
+ m_paused = paused;
+}
GameController * GameController::createSinglePlayer
(Widelands::Game & game,
=== modified file 'src/gamecontroller.h'
--- src/gamecontroller.h 2010-02-28 18:40:36 +0000
+++ src/gamecontroller.h 2010-10-23 15:02:49 +0000
@@ -65,6 +65,23 @@
virtual void setDesiredSpeed(uint32_t speed) = 0;
/**
+ * Whether the game is paused.
+ */
+ virtual bool isPaused() = 0;
+
+ /**
+ * Sets whether the game is paused.
+ */
+ virtual void setPaused(const bool paused) = 0;
+
+ /**
+ * Toggle pause state (convenience function)
+ */
+ void togglePaused() {
+ setPaused(not isPaused());
+ }
+
+ /**
* Allocate a new \ref GameController suitable for normal singleplayer.
* \param cpls is \c true when computer players should be generated
* \return newly allocated \ref GameController object, must be freed
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc 2010-10-17 20:04:55 +0000
+++ src/network/netclient.cc 2010-10-23 15:02:49 +0000
@@ -472,6 +472,15 @@
}
}
+// Network games cannot be paused
+bool NetClient::isPaused()
+{
+ return false;
+}
+
+void NetClient::setPaused(bool const paused)
+{
+}
void NetClient::recvOnePlayer
(uint8_t const number, Widelands::StreamRead & packet)
=== modified file 'src/network/netclient.h'
--- src/network/netclient.h 2010-09-12 11:36:33 +0000
+++ src/network/netclient.h 2010-10-23 15:02:49 +0000
@@ -54,6 +54,8 @@
uint32_t realSpeed();
uint32_t desiredSpeed();
void setDesiredSpeed(uint32_t speed);
+ bool isPaused();
+ void setPaused(const bool paused);
// End GameController interface
// GameSettingsProvider interface
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2010-09-24 22:36:40 +0000
+++ src/network/nethost.cc 2010-10-23 15:02:49 +0000
@@ -1363,6 +1363,15 @@
}
}
+// Network games cannot be paused
+bool NetHost::isPaused()
+{
+ return false;
+}
+
+void NetHost::setPaused(bool const paused)
+{
+}
// Send the packet to all properly connected clients
void NetHost::broadcast(SendPacket & packet)
@@ -1701,6 +1710,10 @@
* wished speed (e.g. without this boundary, the client might set his/her wished
* speed to 8x - even if the host sets his desired speed to PAUSE
* the median sped would be 4x).
+ *
+ * The immediate pausing (with the Pause key) is disabled completely in the
+ * network games, as sudden pauses would be distracting to other players. A
+ * hard interruption of the game can be achieved with the forced pause.
*/
void NetHost::updateNetworkSpeed()
{
=== modified file 'src/network/nethost.h'
--- src/network/nethost.h 2010-09-22 21:30:28 +0000
+++ src/network/nethost.h 2010-10-23 15:02:49 +0000
@@ -52,6 +52,8 @@
uint32_t realSpeed();
uint32_t desiredSpeed();
void setDesiredSpeed(uint32_t speed);
+ bool isPaused();
+ void setPaused(const bool paused);
// End GameController interface
// Pregame-related stuff
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2010-09-24 23:30:25 +0000
+++ src/wlapplication.cc 2010-10-23 15:02:49 +0000
@@ -2104,7 +2104,7 @@
else if (frametime > 1000)
frametime = 1000;
- frametime = frametime * m_speed / 1000;
+ frametime = frametime * realSpeed() / 1000;
m_time = m_game.get_gametime() + frametime;
@@ -2132,9 +2132,11 @@
std::string getGameDescription() {
return "replay";
}
- uint32_t realSpeed() {return m_speed;}
+ uint32_t realSpeed() {return m_paused ? 0 : m_speed;}
uint32_t desiredSpeed() {return m_speed;}
void setDesiredSpeed(uint32_t const speed) {m_speed = speed;}
+ bool isPaused() {return m_paused;}
+ void setPaused(bool const paused) { m_paused = paused;}
private:
Widelands::Game & m_game;
@@ -2142,6 +2144,7 @@
int32_t m_lastframe;
int32_t m_time;
uint32_t m_speed;
+ bool m_paused;
};
/**
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2010-10-10 14:03:26 +0000
+++ src/wui/interactive_base.cc 2010-10-23 15:02:49 +0000
@@ -859,6 +859,13 @@
if (GameController * const ctrl = game->gameController())
ctrl->setDesiredSpeed(ctrl->desiredSpeed() + 1000);
return true;
+
+ case SDLK_PAUSE:
+ if (down)
+ if (upcast(Game, game, &m_egbase))
+ if (GameController * const ctrl = game->gameController())
+ ctrl->togglePaused();
+ return true;
case SDLK_PAGEDOWN:
if (!get_display_flag(dfSpeed))
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2010-09-24 23:30:25 +0000
+++ src/wui/interactive_player.cc 2010-10-23 15:02:49 +0000
@@ -411,6 +411,7 @@
* \li s: toggle building statistics
* \li Home: go to starting position
* \li PageUp/PageDown: change game speed
+ * \li Pause: pauses the game
* \li Return: write chat message
*/
bool Interactive_Player::handle_key(bool const down, SDL_keysym const code)
=== modified file 'txts/README'
--- txts/README 2010-05-12 19:52:39 +0000
+++ txts/README 2010-10-23 15:02:49 +0000
@@ -73,6 +73,8 @@
"<br>"
_"PAGEDOWN Decrease gamespeed"
"<br>"
+_"PAUSE Pauses the game (only for local games)"
+"<br>"
"<br>"
_"F6 Shows the debug console (only in debug-builds)"
"<br>"
Follow ups