Merge lp:~widelands-dev/widelands/allows_seafaring_performance into lp:widelands
- allows_seafaring_performance
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8653 |
Proposed branch: | lp:~widelands-dev/widelands/allows_seafaring_performance |
Merge into: | lp:widelands |
Diff against target: |
324 lines (+71/-22) 6 files modified
src/logic/map.cc (+19/-5) src/logic/map.h (+8/-3) src/map_io/s2map.cc (+1/-0) src/scripting/lua_map.cc (+30/-14) src/scripting/lua_map.h (+1/-0) test/maps/two_ponds.wmf/scripting/test_seafaring.lua (+12/-0) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/allows_seafaring_performance |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Klaus Halfmann | review, compile, automated test | Approve | |
Review via email: mp+342987@code.launchpad.net |
Commit message
Only recalculate whether a map allows seafaring when something has changed
- New function Map::recalculat
- Map::allows_
- On map load
- On editor save
- When a port space is changed via Lua scripting
- When it is triggered by LuaMap:
- Added test
- Some documentation tweaks to lua_map.cc.
- Fixed the check for invalid terrains in LuaField::get_terr.
Description of the change
Only recalculate whether a map allows seafaring when something has changed. This new design is a bit more fragile, but I think the performance gain is worth it, because the AI needs this function.
bunnybot (widelandsofficial) wrote : | # |
Klaus Halfmann (klaus-halfmann) wrote : | # |
This is a prerequisite for the smaller_
checking this out now ...
Code is reasonable.
As this change carries its own testcase it can go in
once the test works for me.
GunChleoc (gunchleoc) wrote : | # |
Thanks for the review :)
Can you trigger the merge once your testing is done?
Klaus Halfmann (klaus-halfmann) wrote : | # |
allows_
...
test/maps/
Running Widelands ... done.
Loading savegame: port_spaces ... done.
ok
...
Ran 41 tests in 1204.108s
@bunnybot merge
kaputtnik (franku) wrote : | # |
wow, finally i can play debug builds again without stuttering, even on big maps.
Thanks :-)
Preview Diff
1 | === modified file 'src/logic/map.cc' | |||
2 | --- src/logic/map.cc 2018-04-07 16:59:00 +0000 | |||
3 | +++ src/logic/map.cc 2018-04-11 07:16:58 +0000 | |||
4 | @@ -70,7 +70,8 @@ | |||
5 | 70 | scenario_types_(NO_SCENARIO), | 70 | scenario_types_(NO_SCENARIO), |
6 | 71 | width_(0), | 71 | width_(0), |
7 | 72 | height_(0), | 72 | height_(0), |
9 | 73 | pathfieldmgr_(new PathfieldManager) { | 73 | pathfieldmgr_(new PathfieldManager), |
10 | 74 | allows_seafaring_(false) { | ||
11 | 74 | } | 75 | } |
12 | 75 | 76 | ||
13 | 76 | Map::~Map() { | 77 | Map::~Map() { |
14 | @@ -157,6 +158,7 @@ | |||
15 | 157 | f = get_fcoords(Coords(x, y)); | 158 | f = get_fcoords(Coords(x, y)); |
16 | 158 | recalc_nodecaps_pass2(world, f); | 159 | recalc_nodecaps_pass2(world, f); |
17 | 159 | } | 160 | } |
18 | 161 | recalculate_allows_seafaring(); | ||
19 | 160 | } | 162 | } |
20 | 161 | 163 | ||
21 | 162 | void Map::recalc_default_resources(const World& world) { | 164 | void Map::recalc_default_resources(const World& world) { |
22 | @@ -278,6 +280,7 @@ | |||
23 | 278 | objectives_.clear(); | 280 | objectives_.clear(); |
24 | 279 | 281 | ||
25 | 280 | port_spaces_.clear(); | 282 | port_spaces_.clear(); |
26 | 283 | allows_seafaring_ = false; | ||
27 | 281 | 284 | ||
28 | 282 | // TODO(meitis): should be done here ... but WidelandsMapLoader::preload_map calls | 285 | // TODO(meitis): should be done here ... but WidelandsMapLoader::preload_map calls |
29 | 283 | // this cleanup AFTER assigning filesystem_ in WidelandsMapLoader::WidelandsMapLoader | 286 | // this cleanup AFTER assigning filesystem_ in WidelandsMapLoader::WidelandsMapLoader |
30 | @@ -1316,7 +1319,7 @@ | |||
31 | 1316 | return port_spaces_.count(c); | 1319 | return port_spaces_.count(c); |
32 | 1317 | } | 1320 | } |
33 | 1318 | 1321 | ||
35 | 1319 | bool Map::set_port_space(const World& world, const Coords& c, bool set, bool force) { | 1322 | bool Map::set_port_space(const World& world, const Coords& c, bool set, bool force, bool recalculate_seafaring) { |
36 | 1320 | bool success = false; | 1323 | bool success = false; |
37 | 1321 | if (set) { | 1324 | if (set) { |
38 | 1322 | success = force || is_port_space_allowed(world, get_fcoords(c)); | 1325 | success = force || is_port_space_allowed(world, get_fcoords(c)); |
39 | @@ -1327,6 +1330,9 @@ | |||
40 | 1327 | port_spaces_.erase(c); | 1330 | port_spaces_.erase(c); |
41 | 1328 | success = true; | 1331 | success = true; |
42 | 1329 | } | 1332 | } |
43 | 1333 | if (recalculate_seafaring) { | ||
44 | 1334 | recalculate_allows_seafaring(); | ||
45 | 1335 | } | ||
46 | 1330 | return success; | 1336 | return success; |
47 | 1331 | } | 1337 | } |
48 | 1332 | 1338 | ||
49 | @@ -1973,10 +1979,16 @@ | |||
50 | 1973 | } | 1979 | } |
51 | 1974 | 1980 | ||
52 | 1975 | bool Map::allows_seafaring() const { | 1981 | bool Map::allows_seafaring() const { |
53 | 1982 | return allows_seafaring_; | ||
54 | 1983 | } | ||
55 | 1984 | |||
56 | 1985 | // This check can become very expensive, so we only recalculate this on relevant map changes. | ||
57 | 1986 | void Map::recalculate_allows_seafaring() { | ||
58 | 1976 | 1987 | ||
59 | 1977 | // There need to be at least 2 port spaces for seafaring to make sense | 1988 | // There need to be at least 2 port spaces for seafaring to make sense |
60 | 1978 | if (get_port_spaces().size() < 2) { | 1989 | if (get_port_spaces().size() < 2) { |
62 | 1979 | return false; | 1990 | allows_seafaring_ = false; |
63 | 1991 | return; | ||
64 | 1980 | } | 1992 | } |
65 | 1981 | 1993 | ||
66 | 1982 | std::set<Coords> reachable_from_previous_ports; | 1994 | std::set<Coords> reachable_from_previous_ports; |
67 | @@ -2000,7 +2012,8 @@ | |||
68 | 2000 | 2012 | ||
69 | 2001 | // Found one | 2013 | // Found one |
70 | 2002 | if (reachable_from_previous_ports.count(current_position) > 0) { | 2014 | if (reachable_from_previous_ports.count(current_position) > 0) { |
72 | 2003 | return true; | 2015 | allows_seafaring_ = true; |
73 | 2016 | return; | ||
74 | 2004 | } | 2017 | } |
75 | 2005 | 2018 | ||
76 | 2006 | // Adding the neighbors to the list | 2019 | // Adding the neighbors to the list |
77 | @@ -2021,7 +2034,7 @@ | |||
78 | 2021 | reachable_from_previous_ports.insert(reachable_coord); | 2034 | reachable_from_previous_ports.insert(reachable_coord); |
79 | 2022 | } | 2035 | } |
80 | 2023 | } | 2036 | } |
82 | 2024 | return false; | 2037 | allows_seafaring_ = false; |
83 | 2025 | } | 2038 | } |
84 | 2026 | 2039 | ||
85 | 2027 | void Map::cleanup_port_spaces(const World& world) { | 2040 | void Map::cleanup_port_spaces(const World& world) { |
86 | @@ -2031,6 +2044,7 @@ | |||
87 | 2031 | continue; | 2044 | continue; |
88 | 2032 | } | 2045 | } |
89 | 2033 | } | 2046 | } |
90 | 2047 | recalculate_allows_seafaring(); | ||
91 | 2034 | } | 2048 | } |
92 | 2035 | 2049 | ||
93 | 2036 | bool Map::has_artifacts() { | 2050 | bool Map::has_artifacts() { |
94 | 2037 | 2051 | ||
95 | === modified file 'src/logic/map.h' | |||
96 | --- src/logic/map.h 2018-04-07 16:59:00 +0000 | |||
97 | +++ src/logic/map.h 2018-04-11 07:16:58 +0000 | |||
98 | @@ -408,7 +408,8 @@ | |||
99 | 408 | /*** | 408 | /*** |
100 | 409 | * Changes the given triangle's terrain. This happens in the editor and might | 409 | * Changes the given triangle's terrain. This happens in the editor and might |
101 | 410 | * happen in the game too if some kind of land increasement is implemented (like | 410 | * happen in the game too if some kind of land increasement is implemented (like |
103 | 411 | * drying swamps). The nodecaps need to be recalculated | 411 | * drying swamps). The nodecaps need to be recalculated. If terrain was changed from |
104 | 412 | * or to water, we need to recalculate_allows_seafaring too, depending on the situation. | ||
105 | 412 | * | 413 | * |
106 | 413 | * @return the radius of changes. | 414 | * @return the radius of changes. |
107 | 414 | */ | 415 | */ |
108 | @@ -448,14 +449,16 @@ | |||
109 | 448 | /// 'force' sets the port space even if it isn't viable, and is to be used for map loading only. | 449 | /// 'force' sets the port space even if it isn't viable, and is to be used for map loading only. |
110 | 449 | /// Returns whether the port space was set/unset successfully. | 450 | /// Returns whether the port space was set/unset successfully. |
111 | 450 | bool | 451 | bool |
113 | 451 | set_port_space(const World& world, const Widelands::Coords& c, bool set, bool force = false); | 452 | set_port_space(const World& world, const Widelands::Coords& c, bool set, bool force = false, bool recalculate_seafaring = false); |
114 | 452 | const PortSpacesSet& get_port_spaces() const { | 453 | const PortSpacesSet& get_port_spaces() const { |
115 | 453 | return port_spaces_; | 454 | return port_spaces_; |
116 | 454 | } | 455 | } |
117 | 455 | std::vector<Coords> find_portdock(const Widelands::Coords& c) const; | 456 | std::vector<Coords> find_portdock(const Widelands::Coords& c) const; |
118 | 456 | 457 | ||
120 | 457 | /// Check whether there are at least 2 port spaces that can be reached from each other by water | 458 | /// Return true if there are at least 2 port spaces that can be reached from each other by water |
121 | 458 | bool allows_seafaring() const; | 459 | bool allows_seafaring() const; |
122 | 460 | /// Calculate whether there are at least 2 port spaces that can be reached from each other by water and set the allows_seafaring property | ||
123 | 461 | void recalculate_allows_seafaring(); | ||
124 | 459 | /// Remove all port spaces that are not valid (Buildcap < big or not enough space for a | 462 | /// Remove all port spaces that are not valid (Buildcap < big or not enough space for a |
125 | 460 | /// portdock). | 463 | /// portdock). |
126 | 461 | void cleanup_port_spaces(const World& world); | 464 | void cleanup_port_spaces(const World& world); |
127 | @@ -518,6 +521,8 @@ | |||
128 | 518 | std::unique_ptr<FileSystem> filesystem_; | 521 | std::unique_ptr<FileSystem> filesystem_; |
129 | 519 | 522 | ||
130 | 520 | PortSpacesSet port_spaces_; | 523 | PortSpacesSet port_spaces_; |
131 | 524 | bool allows_seafaring_; | ||
132 | 525 | |||
133 | 521 | Objectives objectives_; | 526 | Objectives objectives_; |
134 | 522 | 527 | ||
135 | 523 | MapVersion map_version_; | 528 | MapVersion map_version_; |
136 | 524 | 529 | ||
137 | === modified file 'src/map_io/s2map.cc' | |||
138 | --- src/map_io/s2map.cc 2018-04-07 16:59:00 +0000 | |||
139 | +++ src/map_io/s2map.cc 2018-04-11 07:16:58 +0000 | |||
140 | @@ -1065,4 +1065,5 @@ | |||
141 | 1065 | log("SUCCESS! Port buildspace set for (%i, %i) \n", fc.x, fc.y); | 1065 | log("SUCCESS! Port buildspace set for (%i, %i) \n", fc.x, fc.y); |
142 | 1066 | } | 1066 | } |
143 | 1067 | } | 1067 | } |
144 | 1068 | map_.recalculate_allows_seafaring(); | ||
145 | 1068 | } | 1069 | } |
146 | 1069 | 1070 | ||
147 | === modified file 'src/scripting/lua_map.cc' | |||
148 | --- src/scripting/lua_map.cc 2018-04-07 16:59:00 +0000 | |||
149 | +++ src/scripting/lua_map.cc 2018-04-11 07:16:58 +0000 | |||
150 | @@ -1145,6 +1145,7 @@ | |||
151 | 1145 | const char LuaMap::className[] = "Map"; | 1145 | const char LuaMap::className[] = "Map"; |
152 | 1146 | const MethodType<LuaMap> LuaMap::Methods[] = { | 1146 | const MethodType<LuaMap> LuaMap::Methods[] = { |
153 | 1147 | METHOD(LuaMap, place_immovable), METHOD(LuaMap, get_field), METHOD(LuaMap, recalculate), | 1147 | METHOD(LuaMap, place_immovable), METHOD(LuaMap, get_field), METHOD(LuaMap, recalculate), |
154 | 1148 | METHOD(LuaMap, recalculate_seafaring), | ||
155 | 1148 | METHOD(LuaMap, set_port_space), {nullptr, nullptr}, | 1149 | METHOD(LuaMap, set_port_space), {nullptr, nullptr}, |
156 | 1149 | }; | 1150 | }; |
157 | 1150 | const PropertyType<LuaMap> LuaMap::Properties[] = { | 1151 | const PropertyType<LuaMap> LuaMap::Properties[] = { |
158 | @@ -1170,8 +1171,7 @@ | |||
159 | 1170 | /* RST | 1171 | /* RST |
160 | 1171 | .. attribute:: allows_seafaring | 1172 | .. attribute:: allows_seafaring |
161 | 1172 | 1173 | ||
164 | 1173 | (RO) Whether the map currently allows seafaring. This will calculate a path between port spaces, | 1174 | (RO) Whether the map currently allows seafaring. |
163 | 1174 | so it's more accurate but less efficient than :any:`number_of_port_spaces`. | ||
165 | 1175 | 1175 | ||
166 | 1176 | :returns: True if there are at least two port spaces that can be reached from each other. | 1176 | :returns: True if there are at least two port spaces that can be reached from each other. |
167 | 1177 | */ | 1177 | */ |
168 | @@ -1182,9 +1182,7 @@ | |||
169 | 1182 | /* RST | 1182 | /* RST |
170 | 1183 | .. attribute:: number_of_port_spaces | 1183 | .. attribute:: number_of_port_spaces |
171 | 1184 | 1184 | ||
175 | 1185 | (RO) The amount of port spaces on the map. If this is >= 2, one can assume that the map | 1185 | (RO) The amount of port spaces on the map. |
173 | 1186 | allows seafaring. This is checked very quickly and is more efficient than :any:`allows_seafaring`, | ||
174 | 1187 | but it won't detect whether the port spaces can be reached from each other, so it's less accurate. | ||
176 | 1188 | 1186 | ||
177 | 1189 | :returns: An integer with the number of port spaces. | 1187 | :returns: An integer with the number of port spaces. |
178 | 1190 | */ | 1188 | */ |
179 | @@ -1312,9 +1310,9 @@ | |||
180 | 1312 | /* RST | 1310 | /* RST |
181 | 1313 | .. method:: recalculate() | 1311 | .. method:: recalculate() |
182 | 1314 | 1312 | ||
186 | 1315 | This map recalculates the whole map state: height of fields, buildcaps | 1313 | This map recalculates the whole map state: height of fields, buildcaps, |
187 | 1316 | and so on. You only need to call this function if you changed | 1314 | whether the map allows seafaring and so on. You only need to call this |
188 | 1317 | Field.raw_height in any way. | 1315 | function if you changed :any:`raw_height` in any way. |
189 | 1318 | */ | 1316 | */ |
190 | 1319 | // TODO(unknown): do we really want this function? | 1317 | // TODO(unknown): do we really want this function? |
191 | 1320 | int LuaMap::recalculate(lua_State* L) { | 1318 | int LuaMap::recalculate(lua_State* L) { |
192 | @@ -1324,6 +1322,18 @@ | |||
193 | 1324 | } | 1322 | } |
194 | 1325 | 1323 | ||
195 | 1326 | /* RST | 1324 | /* RST |
196 | 1325 | .. method:: recalculate_seafaring() | ||
197 | 1326 | |||
198 | 1327 | This method recalculates whether the map allows seafaring. | ||
199 | 1328 | You only need to call this function if you have been changing terrains to/from | ||
200 | 1329 | water and wanted to defer recalculating whether the map allows seafaring. | ||
201 | 1330 | */ | ||
202 | 1331 | int LuaMap::recalculate_seafaring(lua_State* L) { | ||
203 | 1332 | get_egbase(L).mutable_map()->recalculate_allows_seafaring(); | ||
204 | 1333 | return 0; | ||
205 | 1334 | } | ||
206 | 1335 | |||
207 | 1336 | /* RST | ||
208 | 1327 | .. method:: set_port_space(x, y, allowed) | 1337 | .. method:: set_port_space(x, y, allowed) |
209 | 1328 | 1338 | ||
210 | 1329 | Sets whether a port space is allowed at the coordinates (x, y). | 1339 | Sets whether a port space is allowed at the coordinates (x, y). |
211 | @@ -1344,7 +1354,7 @@ | |||
212 | 1344 | const int y = luaL_checkint32(L, 3); | 1354 | const int y = luaL_checkint32(L, 3); |
213 | 1345 | const bool allowed = luaL_checkboolean(L, 4); | 1355 | const bool allowed = luaL_checkboolean(L, 4); |
214 | 1346 | const bool success = get_egbase(L).mutable_map()->set_port_space( | 1356 | const bool success = get_egbase(L).mutable_map()->set_port_space( |
216 | 1347 | get_egbase(L).world(), Widelands::Coords(x, y), allowed); | 1357 | get_egbase(L).world(), Widelands::Coords(x, y), allowed, false, true); |
217 | 1348 | lua_pushboolean(L, success); | 1358 | lua_pushboolean(L, success); |
218 | 1349 | return 1; | 1359 | return 1; |
219 | 1350 | } | 1360 | } |
220 | @@ -5932,7 +5942,9 @@ | |||
221 | 5932 | (RW) The height of this field. The default height is 10, you can increase | 5942 | (RW) The height of this field. The default height is 10, you can increase |
222 | 5933 | or decrease this value to build mountains. Note though that if you change | 5943 | or decrease this value to build mountains. Note though that if you change |
223 | 5934 | this value too much, all surrounding fields will also change their | 5944 | this value too much, all surrounding fields will also change their |
225 | 5935 | heights because the slope is constrained. | 5945 | heights because the slope is constrained. If you are changing the height |
226 | 5946 | of many terrains at once, use :attr:`raw_height` instead and then call | ||
227 | 5947 | :any:`recalculate` afterwards. | ||
228 | 5936 | */ | 5948 | */ |
229 | 5937 | int LuaField::get_height(lua_State* L) { | 5949 | int LuaField::get_height(lua_State* L) { |
230 | 5938 | lua_pushuint32(L, fcoords(L).field->get_height()); | 5950 | lua_pushuint32(L, fcoords(L).field->get_height()); |
231 | @@ -5957,10 +5969,10 @@ | |||
232 | 5957 | /* RST | 5969 | /* RST |
233 | 5958 | .. attribute:: raw_height | 5970 | .. attribute:: raw_height |
234 | 5959 | 5971 | ||
236 | 5960 | (RW The same as :attr:`height`, but setting this will not trigger a | 5972 | (RW) The same as :attr:`height`, but setting this will not trigger a |
237 | 5961 | recalculation of the surrounding fields. You can use this field to | 5973 | recalculation of the surrounding fields. You can use this field to |
238 | 5962 | change the height of many fields on a map quickly, then use | 5974 | change the height of many fields on a map quickly, then use |
240 | 5963 | :func:`wl.map.recalculate()` to make sure that everything is in order. | 5975 | :any:`recalculate` to make sure that everything is in order. |
241 | 5964 | */ | 5976 | */ |
242 | 5965 | // UNTESTED | 5977 | // UNTESTED |
243 | 5966 | int LuaField::get_raw_height(lua_State* L) { | 5978 | int LuaField::get_raw_height(lua_State* L) { |
244 | @@ -6119,7 +6131,11 @@ | |||
245 | 6119 | (RW) The terrain of the right/down triangle. This is a string value | 6131 | (RW) The terrain of the right/down triangle. This is a string value |
246 | 6120 | containing the name of the terrain as it is defined in the world | 6132 | containing the name of the terrain as it is defined in the world |
247 | 6121 | configuration. You can change the terrain by simply assigning another | 6133 | configuration. You can change the terrain by simply assigning another |
249 | 6122 | valid name to these variables. | 6134 | valid name to these variables. If you are changing the terrain from or to |
250 | 6135 | water, the map will not recalculate whether it allows seafaring, because | ||
251 | 6136 | this recalculation can take up a lot of performance. If you need this | ||
252 | 6137 | recalculated, you can do so by calling :any:`recalculate_seafaring` after | ||
253 | 6138 | you're done changing terrains. | ||
254 | 6123 | */ | 6139 | */ |
255 | 6124 | int LuaField::get_terr(lua_State* L) { | 6140 | int LuaField::get_terr(lua_State* L) { |
256 | 6125 | TerrainDescription& td = get_egbase(L).world().terrain_descr(fcoords(L).field->terrain_r()); | 6141 | TerrainDescription& td = get_egbase(L).world().terrain_descr(fcoords(L).field->terrain_r()); |
257 | @@ -6131,7 +6147,7 @@ | |||
258 | 6131 | EditorGameBase& egbase = get_egbase(L); | 6147 | EditorGameBase& egbase = get_egbase(L); |
259 | 6132 | const World& world = egbase.world(); | 6148 | const World& world = egbase.world(); |
260 | 6133 | const DescriptionIndex td = world.terrains().get_index(name); | 6149 | const DescriptionIndex td = world.terrains().get_index(name); |
262 | 6134 | if (td == static_cast<DescriptionIndex>(-1)) | 6150 | if (td == static_cast<DescriptionIndex>(Widelands::INVALID_INDEX)) |
263 | 6135 | report_error(L, "Unknown terrain '%s'", name); | 6151 | report_error(L, "Unknown terrain '%s'", name); |
264 | 6136 | 6152 | ||
265 | 6137 | egbase.mutable_map()->change_terrain(world, TCoords<FCoords>(fcoords(L), TriangleIndex::R), td); | 6153 | egbase.mutable_map()->change_terrain(world, TCoords<FCoords>(fcoords(L), TriangleIndex::R), td); |
266 | 6138 | 6154 | ||
267 | === modified file 'src/scripting/lua_map.h' | |||
268 | --- src/scripting/lua_map.h 2018-04-07 16:59:00 +0000 | |||
269 | +++ src/scripting/lua_map.h 2018-04-11 07:16:58 +0000 | |||
270 | @@ -98,6 +98,7 @@ | |||
271 | 98 | int place_immovable(lua_State*); | 98 | int place_immovable(lua_State*); |
272 | 99 | int get_field(lua_State*); | 99 | int get_field(lua_State*); |
273 | 100 | int recalculate(lua_State*); | 100 | int recalculate(lua_State*); |
274 | 101 | int recalculate_seafaring(lua_State*); | ||
275 | 101 | int set_port_space(lua_State*); | 102 | int set_port_space(lua_State*); |
276 | 102 | 103 | ||
277 | 103 | /* | 104 | /* |
278 | 104 | 105 | ||
279 | === modified file 'test/maps/two_ponds.wmf/scripting/test_seafaring.lua' | |||
280 | --- test/maps/two_ponds.wmf/scripting/test_seafaring.lua 2017-11-08 15:53:57 +0000 | |||
281 | +++ test/maps/two_ponds.wmf/scripting/test_seafaring.lua 2018-04-11 07:16:58 +0000 | |||
282 | @@ -3,30 +3,42 @@ | |||
283 | 3 | -- not allow seafaring. One of the port spaces has trees on top of it. | 3 | -- not allow seafaring. One of the port spaces has trees on top of it. |
284 | 4 | assert_equal(2, map.number_of_port_spaces) | 4 | assert_equal(2, map.number_of_port_spaces) |
285 | 5 | assert_equal(false, map.allows_seafaring) | 5 | assert_equal(false, map.allows_seafaring) |
286 | 6 | map:recalculate_seafaring() | ||
287 | 7 | assert_equal(false, map.allows_seafaring) | ||
288 | 6 | 8 | ||
289 | 7 | -- Now try to add a port space on a medium buildcap, it should fail | 9 | -- Now try to add a port space on a medium buildcap, it should fail |
290 | 8 | assert_equal(false, map:set_port_space(11, 9, true)) | 10 | assert_equal(false, map:set_port_space(11, 9, true)) |
291 | 9 | assert_equal(2, map.number_of_port_spaces) | 11 | assert_equal(2, map.number_of_port_spaces) |
292 | 10 | assert_equal(false, map.allows_seafaring) | 12 | assert_equal(false, map.allows_seafaring) |
293 | 13 | map:recalculate_seafaring() | ||
294 | 14 | assert_equal(false, map.allows_seafaring) | ||
295 | 11 | 15 | ||
296 | 12 | -- Now try to add a port space away from water, it should fail | 16 | -- Now try to add a port space away from water, it should fail |
297 | 13 | assert_equal(false, map:set_port_space(18, 9, true)) | 17 | assert_equal(false, map:set_port_space(18, 9, true)) |
298 | 14 | assert_equal(2, map.number_of_port_spaces) | 18 | assert_equal(2, map.number_of_port_spaces) |
299 | 15 | assert_equal(false, map.allows_seafaring) | 19 | assert_equal(false, map.allows_seafaring) |
300 | 20 | map:recalculate_seafaring() | ||
301 | 21 | assert_equal(false, map.allows_seafaring) | ||
302 | 16 | 22 | ||
303 | 17 | -- Now add a connecting port space - it should succeed and we should have seafaring then | 23 | -- Now add a connecting port space - it should succeed and we should have seafaring then |
304 | 18 | assert_equal(true, map:set_port_space(0, 2, true)) | 24 | assert_equal(true, map:set_port_space(0, 2, true)) |
305 | 19 | assert_equal(3, map.number_of_port_spaces) | 25 | assert_equal(3, map.number_of_port_spaces) |
306 | 20 | assert_equal(true, map.allows_seafaring) | 26 | assert_equal(true, map.allows_seafaring) |
307 | 27 | map:recalculate_seafaring() | ||
308 | 28 | assert_equal(true, map.allows_seafaring) | ||
309 | 21 | 29 | ||
310 | 22 | stable_save(game, "port_spaces") | 30 | stable_save(game, "port_spaces") |
311 | 23 | assert_equal(3, map.number_of_port_spaces) | 31 | assert_equal(3, map.number_of_port_spaces) |
312 | 24 | assert_equal(true, map.allows_seafaring) | 32 | assert_equal(true, map.allows_seafaring) |
313 | 33 | map:recalculate_seafaring() | ||
314 | 34 | assert_equal(true, map.allows_seafaring) | ||
315 | 25 | 35 | ||
316 | 26 | -- Remove the port space again | 36 | -- Remove the port space again |
317 | 27 | assert_equal(true, map:set_port_space(0, 2, false)) | 37 | assert_equal(true, map:set_port_space(0, 2, false)) |
318 | 28 | assert_equal(2, map.number_of_port_spaces) | 38 | assert_equal(2, map.number_of_port_spaces) |
319 | 29 | assert_equal(false, map.allows_seafaring) | 39 | assert_equal(false, map.allows_seafaring) |
320 | 40 | map:recalculate_seafaring() | ||
321 | 41 | assert_equal(false, map.allows_seafaring) | ||
322 | 30 | 42 | ||
323 | 31 | print("# All Tests passed.") | 43 | print("# All Tests passed.") |
324 | 32 | wl.ui.MapView():close() | 44 | wl.ui.MapView():close() |
Continuous integration builds have changed state:
Travis build 3369. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 364989186. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ allows_ seafaring_ performance- 3175.
Appveyor build 3175. State: success. Details: https:/