widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01432
[Merge] lp:~widelands-dev/widelands/lua_mapview_persistence into lp:widelands
cghislai has proposed merging lp:~widelands-dev/widelands/lua_mapview_persistence into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1203329 in widelands: "Possible to trigger a crash by saving between story dialogs"
https://bugs.launchpad.net/widelands/+bug/1203329
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/lua_mapview_persistence/+merge/177251
This is first attempt to persist the mapview. I thought that census and statistics test failed, but after merging trunk and testing again the test seems to pass now - I have no idea why.
I also tried to reproduce the bug as explained in the report, and could not trigger the crash, even on empire 2.
--
https://code.launchpad.net/~widelands-dev/widelands/lua_mapview_persistence/+merge/177251
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/lua_mapview_persistence into lp:widelands.
=== modified file 'src/scripting/lua_ui.cc'
--- src/scripting/lua_ui.cc 2013-07-26 20:19:36 +0000
+++ src/scripting/lua_ui.cc 2013-07-27 11:13:29 +0000
@@ -25,6 +25,7 @@
#include "logic/player.h"
#include "scripting/c_utils.h"
#include "scripting/lua_map.h"
+#include "scripting/luna.h"
#include "upcast.h"
#include "wui/interactive_player.h"
@@ -525,6 +526,39 @@
L_Panel(get_egbase(L).get_ibase()) {
}
+void L_MapView::__persist(lua_State* L)
+{
+ Interactive_Base* ibase = get();
+ PERS_INT32("vp_x", ibase->get_viewpoint().x);
+ PERS_INT32("vp_y", ibase->get_viewpoint().y);
+ bool buildhelp = ibase->buildhelp();
+ PERS_INT32("buildhelp", buildhelp ? 1 : 0);
+ PERS_INT32("census", ibase->get_display_flag(Interactive_Base::dfShowCensus) ? 1 : 0);
+ PERS_INT32("statistics", ibase->get_display_flag(Interactive_Base::dfShowStatistics) ? 1 : 0);
+ PERS_INT32("buildroad", ibase->is_building_road() ? 1 : 0);
+}
+void L_MapView::__unpersist(lua_State* L)
+{
+ Interactive_Base* ibase = get_egbase(L).get_ibase();
+ m_panel = ibase;
+ uint32_t tmp;
+ Point vp = ibase->get_viewpoint();
+ UNPERS_INT32("vp_x", tmp);
+ vp.x = tmp;
+ UNPERS_INT32("vp_y", tmp);
+ vp.y = tmp;
+ ibase->set_viewpoint(vp, true);
+ UNPERS_INT32("buildhelp", tmp);
+ ibase->show_buildhelp(tmp == 1 ? true : false);
+ UNPERS_INT32("census", tmp);
+ ibase->set_display_flag(Interactive_Base::dfShowCensus, tmp == 1 ? true : false);
+ UNPERS_INT32("statistics", tmp);
+ ibase->set_display_flag(Interactive_Base::dfShowStatistics, tmp == 1 ? true : false);
+ UNPERS_INT32("buildroad", tmp);
+ if (tmp) {
+ abort_road_building(L);
+ }
+}
/*
* Properties
=== modified file 'src/scripting/lua_ui.h'
--- src/scripting/lua_ui.h 2013-07-26 20:19:36 +0000
+++ src/scripting/lua_ui.h 2013-07-27 11:13:29 +0000
@@ -179,6 +179,9 @@
L_MapView(lua_State * L);
virtual ~L_MapView() {}
+ virtual void __persist(lua_State * L);
+ virtual void __unpersist(lua_State * L);
+
/*
* Properties
*/
=== modified file 'test/lua/persistence.wmf/scripting/init.lua'
--- test/lua/persistence.wmf/scripting/init.lua 2013-07-19 17:07:41 +0000
+++ test/lua/persistence.wmf/scripting/init.lua 2013-07-27 11:13:29 +0000
@@ -51,6 +51,12 @@
map:get_field(10,10), map:get_field(10,10), map:get_field(10,11)
}
+ mapview = wl.ui.MapView()
+ mapview.viewpoint_x = 10
+ mapview.viewpoint_y = 40
+ mapview.statistics = false
+ mapview.census = true
+
game:save("lua_persistence")
print("Save requested\n");
@@ -121,6 +127,11 @@
assert_equal(2, myset.size)
assert_true(myset:contains(map:get_field(10,10)))
assert_true(myset:contains(map:get_field(10,11)))
+ mapview = wl.ui.MapView()
+ assert_equal(mapview.viewpoint_x, 10)
+ assert_equal(mapview.viewpoint_y, 40)
+ assert_equal(false, mapview.statistics)
+ assert_equal(true, mapview.census)
print("################### ALL TEST PASS!")
Follow ups