Merge lp:~nomeata/widelands/bugfix536464 into lp:widelands

Proposed by Joachim Breitner
Status: Merged
Merged at revision: 5596
Proposed branch: lp:~nomeata/widelands/bugfix536464
Merge into: lp:widelands
Diff against target: 238 lines (+75/-4)
10 files modified
src/gamecontroller.cc (+17/-2)
src/gamecontroller.h (+17/-0)
src/network/netclient.cc (+9/-0)
src/network/netclient.h (+2/-0)
src/network/nethost.cc (+13/-0)
src/network/nethost.h (+2/-0)
src/wlapplication.cc (+5/-2)
src/wui/interactive_base.cc (+7/-0)
src/wui/interactive_player.cc (+1/-0)
txts/README (+2/-0)
To merge this branch: bzr merge lp:~nomeata/widelands/bugfix536464
Reviewer Review Type Date Requested Status
Nasenbaer Approve
Review via email: mp+39200@code.launchpad.net

Description of the change

Implements the PAUSE button, per bug #536464.

To post a comment you must log in.
Revision history for this message
Nasenbaer (nasenbaer) wrote :

looks good to me! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/gamecontroller.cc'
2--- src/gamecontroller.cc 2010-06-06 18:14:40 +0000
3+++ src/gamecontroller.cc 2010-10-23 15:03:13 +0000
4@@ -39,12 +39,15 @@
5 uint32_t realSpeed();
6 uint32_t desiredSpeed();
7 void setDesiredSpeed(uint32_t speed);
8+ bool isPaused();
9+ void setPaused(const bool paused);
10
11 private:
12 Widelands::Game & m_game;
13 bool m_useai;
14 int32_t m_lastframe;
15 int32_t m_time;
16+ bool m_paused;
17 uint32_t m_speed; ///< current game speed, in milliseconds per second
18 uint32_t m_player_cmdserial;
19 Widelands::Player_Number m_local;
20@@ -87,7 +90,7 @@
21 else if (frametime > 1000)
22 frametime = 1000;
23
24- frametime = frametime * m_speed / 1000;
25+ frametime = frametime * realSpeed() / 1000;
26
27 m_time = m_game.get_gametime() + frametime;
28
29@@ -126,7 +129,10 @@
30
31 uint32_t SinglePlayerGameController::realSpeed()
32 {
33- return m_speed;
34+ if (m_paused)
35+ return 0;
36+ else
37+ return m_speed;
38 }
39
40 uint32_t SinglePlayerGameController::desiredSpeed()
41@@ -139,6 +145,15 @@
42 m_speed = speed;
43 }
44
45+bool SinglePlayerGameController::isPaused()
46+{
47+ return m_paused;
48+}
49+
50+void SinglePlayerGameController::setPaused(bool const paused)
51+{
52+ m_paused = paused;
53+}
54
55 GameController * GameController::createSinglePlayer
56 (Widelands::Game & game,
57
58=== modified file 'src/gamecontroller.h'
59--- src/gamecontroller.h 2010-02-28 18:40:36 +0000
60+++ src/gamecontroller.h 2010-10-23 15:03:13 +0000
61@@ -65,6 +65,23 @@
62 virtual void setDesiredSpeed(uint32_t speed) = 0;
63
64 /**
65+ * Whether the game is paused.
66+ */
67+ virtual bool isPaused() = 0;
68+
69+ /**
70+ * Sets whether the game is paused.
71+ */
72+ virtual void setPaused(const bool paused) = 0;
73+
74+ /**
75+ * Toggle pause state (convenience function)
76+ */
77+ void togglePaused() {
78+ setPaused(not isPaused());
79+ }
80+
81+ /**
82 * Allocate a new \ref GameController suitable for normal singleplayer.
83 * \param cpls is \c true when computer players should be generated
84 * \return newly allocated \ref GameController object, must be freed
85
86=== modified file 'src/network/netclient.cc'
87--- src/network/netclient.cc 2010-10-17 20:04:55 +0000
88+++ src/network/netclient.cc 2010-10-23 15:03:13 +0000
89@@ -472,6 +472,15 @@
90 }
91 }
92
93+// Network games cannot be paused
94+bool NetClient::isPaused()
95+{
96+ return false;
97+}
98+
99+void NetClient::setPaused(bool const paused)
100+{
101+}
102
103 void NetClient::recvOnePlayer
104 (uint8_t const number, Widelands::StreamRead & packet)
105
106=== modified file 'src/network/netclient.h'
107--- src/network/netclient.h 2010-09-12 11:36:33 +0000
108+++ src/network/netclient.h 2010-10-23 15:03:13 +0000
109@@ -54,6 +54,8 @@
110 uint32_t realSpeed();
111 uint32_t desiredSpeed();
112 void setDesiredSpeed(uint32_t speed);
113+ bool isPaused();
114+ void setPaused(const bool paused);
115 // End GameController interface
116
117 // GameSettingsProvider interface
118
119=== modified file 'src/network/nethost.cc'
120--- src/network/nethost.cc 2010-09-24 22:36:40 +0000
121+++ src/network/nethost.cc 2010-10-23 15:03:13 +0000
122@@ -1363,6 +1363,15 @@
123 }
124 }
125
126+// Network games cannot be paused
127+bool NetHost::isPaused()
128+{
129+ return false;
130+}
131+
132+void NetHost::setPaused(bool const paused)
133+{
134+}
135
136 // Send the packet to all properly connected clients
137 void NetHost::broadcast(SendPacket & packet)
138@@ -1701,6 +1710,10 @@
139 * wished speed (e.g. without this boundary, the client might set his/her wished
140 * speed to 8x - even if the host sets his desired speed to PAUSE
141 * the median sped would be 4x).
142+ *
143+ * The immediate pausing (with the Pause key) is disabled completely in the
144+ * network games, as sudden pauses would be distracting to other players. A
145+ * hard interruption of the game can be achieved with the forced pause.
146 */
147 void NetHost::updateNetworkSpeed()
148 {
149
150=== modified file 'src/network/nethost.h'
151--- src/network/nethost.h 2010-09-22 21:30:28 +0000
152+++ src/network/nethost.h 2010-10-23 15:03:13 +0000
153@@ -52,6 +52,8 @@
154 uint32_t realSpeed();
155 uint32_t desiredSpeed();
156 void setDesiredSpeed(uint32_t speed);
157+ bool isPaused();
158+ void setPaused(const bool paused);
159 // End GameController interface
160
161 // Pregame-related stuff
162
163=== modified file 'src/wlapplication.cc'
164--- src/wlapplication.cc 2010-09-24 23:30:25 +0000
165+++ src/wlapplication.cc 2010-10-23 15:03:13 +0000
166@@ -2104,7 +2104,7 @@
167 else if (frametime > 1000)
168 frametime = 1000;
169
170- frametime = frametime * m_speed / 1000;
171+ frametime = frametime * realSpeed() / 1000;
172
173 m_time = m_game.get_gametime() + frametime;
174
175@@ -2132,9 +2132,11 @@
176 std::string getGameDescription() {
177 return "replay";
178 }
179- uint32_t realSpeed() {return m_speed;}
180+ uint32_t realSpeed() {return m_paused ? 0 : m_speed;}
181 uint32_t desiredSpeed() {return m_speed;}
182 void setDesiredSpeed(uint32_t const speed) {m_speed = speed;}
183+ bool isPaused() {return m_paused;}
184+ void setPaused(bool const paused) { m_paused = paused;}
185
186 private:
187 Widelands::Game & m_game;
188@@ -2142,6 +2144,7 @@
189 int32_t m_lastframe;
190 int32_t m_time;
191 uint32_t m_speed;
192+ bool m_paused;
193 };
194
195 /**
196
197=== modified file 'src/wui/interactive_base.cc'
198--- src/wui/interactive_base.cc 2010-10-10 14:03:26 +0000
199+++ src/wui/interactive_base.cc 2010-10-23 15:03:13 +0000
200@@ -859,6 +859,13 @@
201 if (GameController * const ctrl = game->gameController())
202 ctrl->setDesiredSpeed(ctrl->desiredSpeed() + 1000);
203 return true;
204+
205+ case SDLK_PAUSE:
206+ if (down)
207+ if (upcast(Game, game, &m_egbase))
208+ if (GameController * const ctrl = game->gameController())
209+ ctrl->togglePaused();
210+ return true;
211
212 case SDLK_PAGEDOWN:
213 if (!get_display_flag(dfSpeed))
214
215=== modified file 'src/wui/interactive_player.cc'
216--- src/wui/interactive_player.cc 2010-09-24 23:30:25 +0000
217+++ src/wui/interactive_player.cc 2010-10-23 15:03:13 +0000
218@@ -411,6 +411,7 @@
219 * \li s: toggle building statistics
220 * \li Home: go to starting position
221 * \li PageUp/PageDown: change game speed
222+ * \li Pause: pauses the game
223 * \li Return: write chat message
224 */
225 bool Interactive_Player::handle_key(bool const down, SDL_keysym const code)
226
227=== modified file 'txts/README'
228--- txts/README 2010-05-12 19:52:39 +0000
229+++ txts/README 2010-10-23 15:03:13 +0000
230@@ -73,6 +73,8 @@
231 "<br>"
232 _"PAGEDOWN Decrease gamespeed"
233 "<br>"
234+_"PAUSE Pauses the game (only for local games)"
235+"<br>"
236 "<br>"
237 _"F6 Shows the debug console (only in debug-builds)"
238 "<br>"

Subscribers

People subscribed via source and target branches

to status/vote changes: