Merge lp:~widelands-dev/widelands/economy_tutorial_fix into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7501
Proposed branch: lp:~widelands-dev/widelands/economy_tutorial_fix
Merge into: lp:widelands
Diff against target: 73 lines (+26/-1)
4 files modified
campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua (+1/-1)
src/scripting/lua_root.cc (+13/-0)
src/scripting/lua_root.h (+1/-0)
test/maps/plain.wmf/scripting/test_gamespeed.lua (+11/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/economy_tutorial_fix
Reviewer Review Type Date Requested Status
wl-zocker Approve
Review via email: mp+266519@code.launchpad.net

Description of the change

Economy tutorial: the building statistics window needs some time to build its contents.

To post a comment you must log in.
Revision history for this message
wl-zocker (wl-zocker) wrote :

This seems to work fine at speed 1.0, but if I increase the game speed, the window still has too little time to build up. Maybe using sleep(game_speed) helps? Also, you can remove sleep(500) three lines above. I think that was enough time to build up the old buildings statistics menu.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Good idea - done :)

Revision history for this message
wl-zocker (wl-zocker) wrote :

You also could have used wl.Game().desired_speed ... Or is there a difference?

Revision history for this message
GunChleoc (gunchleoc) wrote :

desired_speed sets the speed instead of just reading it.

Revision history for this message
wl-zocker (wl-zocker) wrote :
Revision history for this message
GunChleoc (gunchleoc) wrote :

I see. Now I'm wondering if we would have a use for the real speed as well though, because it makes a difference in multiplayer. Of course, for this branch, it doesn't matter.

Revision history for this message
wl-zocker (wl-zocker) wrote :

I tested your change and when using desired_speed, it works fine with speeds up to 50.

Regarding real_speed: I do not know if we want to introduce a new function that serves little purpose. Changing the speed in multiplayer scenarios might have strange effects (I guess desired_speed only works for player 1).

Revision history for this message
GunChleoc (gunchleoc) wrote :

real_speed is read-only, and it's the speed that the game is actually using. Desired speed is set by each user (read/write). In single player games, they are identical, but in multiplayer games, the real_speed is some form of arithmetic mean of the desired speeds of each player.

Revision history for this message
wl-zocker (wl-zocker) wrote :

I understand the difference between real and desired speed. I was just wondering whether we need more code (to maintain etc.). I'll approve the changes you made because the building statistics window is now always shown correctly. If you think it is necessary to keep the new function, then do so.

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Merged. Thanks for the review :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua'
--- campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2015-06-10 13:01:28 +0000
+++ campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2015-08-02 10:36:19 +0000
@@ -20,9 +20,9 @@
20 sleep(2000)20 sleep(2000)
21 local o = message_box_objective(plr, building_stat)21 local o = message_box_objective(plr, building_stat)
22 while not mv.windows.building_statistics do sleep(100) end22 while not mv.windows.building_statistics do sleep(100) end
23 sleep(500)
24 o.done = true23 o.done = true
2524
25 sleep(wl.Game().real_speed) -- The building statistics window needs some time to build up
26 o = message_box_objective(plr,explain_building_stat)26 o = message_box_objective(plr,explain_building_stat)
27 -- We cannot create several objectives with the same name. Therefore, we create o2 here once and change its visibility27 -- We cannot create several objectives with the same name. Therefore, we create o2 here once and change its visibility
28 local o2 = add_campaign_objective(reopen_building_stat_obj)28 local o2 = add_campaign_objective(reopen_building_stat_obj)
2929
=== modified file 'src/scripting/lua_root.cc'
--- src/scripting/lua_root.cc 2015-01-31 16:03:59 +0000
+++ src/scripting/lua_root.cc 2015-08-02 10:36:19 +0000
@@ -83,6 +83,7 @@
83 {nullptr, nullptr},83 {nullptr, nullptr},
84};84};
85const PropertyType<LuaGame> LuaGame::Properties[] = {85const PropertyType<LuaGame> LuaGame::Properties[] = {
86 PROP_RO(LuaGame, real_speed),
86 PROP_RO(LuaGame, time),87 PROP_RO(LuaGame, time),
87 PROP_RW(LuaGame, desired_speed),88 PROP_RW(LuaGame, desired_speed),
88 PROP_RW(LuaGame, allow_autosaving),89 PROP_RW(LuaGame, allow_autosaving),
@@ -107,6 +108,18 @@
107 */108 */
108109
109/* RST110/* RST
111 .. attribute:: real_speed
112
113 (RO) The speed that the current game is running at in ms.
114 For example, for game speed = 2x, this returns 2000.
115*/
116int LuaGame::get_real_speed(lua_State * L) {
117 lua_pushinteger(L, get_game(L).game_controller()->real_speed());
118 return 1;
119}
120
121
122/* RST
110 .. attribute:: time123 .. attribute:: time
111124
112 (RO) The absolute time elapsed since the game was started in milliseconds.125 (RO) The absolute time elapsed since the game was started in milliseconds.
113126
=== modified file 'src/scripting/lua_root.h'
--- src/scripting/lua_root.h 2015-01-31 16:03:59 +0000
+++ src/scripting/lua_root.h 2015-08-02 10:36:19 +0000
@@ -48,6 +48,7 @@
48 /*48 /*
49 * Properties49 * Properties
50 */50 */
51 int get_real_speed(lua_State * L);
51 int get_time(lua_State *);52 int get_time(lua_State *);
52 int get_desired_speed(lua_State *);53 int get_desired_speed(lua_State *);
53 int set_desired_speed(lua_State *);54 int set_desired_speed(lua_State *);
5455
=== added file 'test/maps/plain.wmf/scripting/test_gamespeed.lua'
--- test/maps/plain.wmf/scripting/test_gamespeed.lua 1970-01-01 00:00:00 +0000
+++ test/maps/plain.wmf/scripting/test_gamespeed.lua 2015-08-02 10:36:19 +0000
@@ -0,0 +1,11 @@
1run(function()
2 sleep(1000)
3
4 game.desired_speed = 5000
5 assert_equal(game.real_speed, 5000)
6 assert_equal(game.desired_speed, 5000)
7 assert_equal(game.real_speed, 5000)
8
9 print("# All Tests passed.")
10 wl.ui.MapView():close()
11end)

Subscribers

People subscribed via source and target branches

to status/vote changes: