Merge lp:~widelands-dev/widelands/bug-986611-cppcheck_performance-logic into lp:widelands
- bug-986611-cppcheck_performance-logic
- Merge into trunk
Proposed by
GunChleoc
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 8041 | ||||
Proposed branch: | lp:~widelands-dev/widelands/bug-986611-cppcheck_performance-logic | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
1311 lines (+160/-169) 45 files modified
src/ai/ai_help_structs.cc (+1/-1) src/ai/ai_help_structs.h (+1/-1) src/ai/defaultai.cc (+3/-3) src/ai/defaultai.h (+3/-3) src/economy/flag.cc (+1/-1) src/economy/flag.h (+1/-1) src/economy/itransport_cost_calculator.h (+1/-1) src/economy/test/test_road.cc (+1/-1) src/economy/test/test_routing.cc (+2/-2) src/logic/cmd_delete_message.h (+1/-1) src/logic/editor_game_base.cc (+10/-10) src/logic/editor_game_base.h (+10/-10) src/logic/game.cc (+2/-2) src/logic/game.h (+2/-2) src/logic/game_settings.h (+1/-1) src/logic/map.cc (+19/-19) src/logic/map.h (+16/-16) src/logic/map_objects/checkstep.cc (+9/-9) src/logic/map_objects/checkstep.h (+8/-8) src/logic/map_objects/immovable.cc (+3/-3) src/logic/map_objects/immovable.h (+3/-3) src/logic/map_objects/tribes/building.cc (+1/-1) src/logic/map_objects/tribes/building.h (+1/-1) src/logic/map_objects/tribes/ship.h (+1/-1) src/logic/map_objects/tribes/trainingsite.cc (+6/-9) src/logic/map_objects/world/map_gen.cc (+4/-4) src/logic/maptriangleregion.h (+1/-1) src/logic/message.h (+1/-1) src/logic/player.cc (+6/-6) src/logic/player.h (+5/-5) src/logic/playercommand.cc (+11/-13) src/logic/playercommand.h (+5/-5) src/logic/single_player_game_settings_provider.cc (+1/-1) src/logic/single_player_game_settings_provider.h (+1/-1) src/logic/widelands_geometry.h (+2/-2) src/logic/widelands_geometry_io.cc (+1/-1) src/logic/widelands_geometry_io.h (+1/-1) src/map_io/map_bob_packet.cc (+1/-1) src/map_io/map_bob_packet.h (+1/-1) src/map_io/map_buildingdata_packet.cc (+5/-9) src/map_io/map_message_saver.h (+2/-2) src/network/netclient.cc (+1/-1) src/network/netclient.h (+1/-1) src/network/nethost.cc (+2/-2) src/network/nethost.h (+1/-1) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-986611-cppcheck_performance-logic | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
Review via email: mp+301007@code.launchpad.net |
Commit message
Fixed performance issues that were flagged up by cppcheck in logic, economy and map_io:
- Passing parameters per reference.
- Constructor initialization.
- Replaced postfix ++ operator with range-based for loops in Trainingsite code.
Description of the change
Fixed performance issues that were flagged up by cppcheck in logic, economy and map_io:
- Passing parameters per reference.
- Constructor initialization.
- Replaced postfix ++ operator with range-based for loops in Trainingsite code.
To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote : | # |
Revision history for this message
SirVer (sirver) : | # |
review:
Approve
Revision history for this message
GunChleoc (gunchleoc) wrote : | # |
@bunnybot merge
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/ai/ai_help_structs.cc' |
2 | --- src/ai/ai_help_structs.cc 2016-05-09 14:20:16 +0000 |
3 | +++ src/ai/ai_help_structs.cc 2016-07-24 20:00:22 +0000 |
4 | @@ -63,7 +63,7 @@ |
5 | return true; |
6 | } |
7 | |
8 | -bool CheckStepRoadAI::reachable_dest(Map& map, FCoords const dest) const { |
9 | +bool CheckStepRoadAI::reachable_dest(const Map& map, const FCoords& dest) const { |
10 | NodeCaps const caps = dest.field->nodecaps(); |
11 | |
12 | if (!(caps & movecaps)) { |
13 | |
14 | === modified file 'src/ai/ai_help_structs.h' |
15 | --- src/ai/ai_help_structs.h 2016-04-11 06:45:29 +0000 |
16 | +++ src/ai/ai_help_structs.h 2016-07-24 20:00:22 +0000 |
17 | @@ -74,7 +74,7 @@ |
18 | CheckStepRoadAI(Player* const pl, uint8_t const mc, bool const oe); |
19 | |
20 | bool allowed(Map&, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) const; |
21 | - bool reachable_dest(Map&, FCoords dest) const; |
22 | + bool reachable_dest(const Map&, const FCoords& dest) const; |
23 | |
24 | Player* player; |
25 | uint8_t movecaps; |
26 | |
27 | === modified file 'src/ai/defaultai.cc' |
28 | --- src/ai/defaultai.cc 2016-05-10 07:08:55 +0000 |
29 | +++ src/ai/defaultai.cc 2016-07-24 20:00:22 +0000 |
30 | @@ -4808,8 +4808,8 @@ |
31 | bool DefaultAI::other_player_accessible(const uint32_t max_distance, |
32 | uint32_t* tested_fields, |
33 | uint16_t* mineable_fields_count, |
34 | - const Widelands::Coords starting_spot, |
35 | - const WalkSearch type) { |
36 | + const Coords& starting_spot, |
37 | + const WalkSearch& type) { |
38 | Map& map = game().map(); |
39 | std::list<uint32_t> queue; |
40 | std::unordered_set<uint32_t> done; |
41 | @@ -5335,7 +5335,7 @@ |
42 | |
43 | // This calculates strength of vector of soldiers, f.e. soldiers in a building or |
44 | // ones ready to attack |
45 | -int32_t DefaultAI::calculate_strength(const std::vector<Widelands::Soldier*> soldiers) { |
46 | +int32_t DefaultAI::calculate_strength(const std::vector<Widelands::Soldier*>& soldiers) { |
47 | |
48 | if (soldiers.empty()) { |
49 | return 0; |
50 | |
51 | === modified file 'src/ai/defaultai.h' |
52 | --- src/ai/defaultai.h 2016-04-01 07:24:00 +0000 |
53 | +++ src/ai/defaultai.h 2016-07-24 20:00:22 +0000 |
54 | @@ -184,7 +184,7 @@ |
55 | bool check_enemy_sites(uint32_t); |
56 | void print_stats(); |
57 | // return single number of strength of vector of soldiers |
58 | - int32_t calculate_strength(const std::vector<Widelands::Soldier*>); |
59 | + int32_t calculate_strength(const std::vector<Widelands::Soldier*>&); |
60 | uint32_t get_stocklevel_by_hint(size_t); |
61 | uint32_t get_stocklevel(Widelands::BuildingObserver&); |
62 | uint32_t get_warehoused_stock(Widelands::DescriptionIndex wt); |
63 | @@ -198,8 +198,8 @@ |
64 | bool other_player_accessible(uint32_t max_distance, |
65 | uint32_t* tested_fields, |
66 | uint16_t* mineable_fields_count, |
67 | - const Widelands::Coords starting_spot, |
68 | - const WalkSearch type); |
69 | + const Widelands::Coords& starting_spot, |
70 | + const WalkSearch& type); |
71 | |
72 | int32_t recalc_with_border_range(const Widelands::BuildableField&, int32_t); |
73 | |
74 | |
75 | === modified file 'src/economy/flag.cc' |
76 | --- src/economy/flag.cc 2016-02-18 18:27:52 +0000 |
77 | +++ src/economy/flag.cc 2016-07-24 20:00:22 +0000 |
78 | @@ -111,7 +111,7 @@ |
79 | * Create a flag at the given location |
80 | */ |
81 | Flag::Flag |
82 | - (EditorGameBase & egbase, Player & owning_player, Coords const coords) |
83 | + (EditorGameBase & egbase, Player & owning_player, const Coords& coords) |
84 | : |
85 | PlayerImmovable (g_flag_descr), |
86 | building_ (nullptr), |
87 | |
88 | === modified file 'src/economy/flag.h' |
89 | --- src/economy/flag.h 2016-02-09 16:29:48 +0000 |
90 | +++ src/economy/flag.h 2016-07-24 20:00:22 +0000 |
91 | @@ -73,7 +73,7 @@ |
92 | const FlagDescr& descr() const; |
93 | |
94 | Flag(); /// empty flag for savegame loading |
95 | - Flag(EditorGameBase &, Player & owner, Coords); /// create a new flag |
96 | + Flag(EditorGameBase &, Player & owner, const Coords&); /// create a new flag |
97 | ~Flag() override; |
98 | |
99 | void load_finish(EditorGameBase &) override; |
100 | |
101 | === modified file 'src/economy/itransport_cost_calculator.h' |
102 | --- src/economy/itransport_cost_calculator.h 2014-07-14 19:44:28 +0000 |
103 | +++ src/economy/itransport_cost_calculator.h 2016-07-24 20:00:22 +0000 |
104 | @@ -37,7 +37,7 @@ |
105 | ITransportCostCalculator() = default; |
106 | virtual ~ITransportCostCalculator() {} |
107 | |
108 | - virtual int32_t calc_cost_estimate(Coords, Coords) const = 0; |
109 | + virtual int32_t calc_cost_estimate(const Coords&, const Coords&) const = 0; |
110 | |
111 | private: |
112 | DISALLOW_COPY_AND_ASSIGN(ITransportCostCalculator); |
113 | |
114 | === modified file 'src/economy/test/test_road.cc' |
115 | --- src/economy/test/test_road.cc 2015-11-29 09:43:15 +0000 |
116 | +++ src/economy/test/test_road.cc 2016-07-24 20:00:22 +0000 |
117 | @@ -38,7 +38,7 @@ |
118 | /* Helper classes */ |
119 | /******************/ |
120 | struct TestingFlag : public Flag { |
121 | - TestingFlag(EditorGameBase &, Coords const c) : Flag() { |
122 | + TestingFlag(EditorGameBase &, const Coords& c) : Flag() { |
123 | set_flag_position(c); |
124 | } |
125 | |
126 | |
127 | === modified file 'src/economy/test/test_routing.cc' |
128 | --- src/economy/test/test_routing.cc 2016-02-09 16:29:48 +0000 |
129 | +++ src/economy/test/test_routing.cc 2016-07-24 20:00:22 +0000 |
130 | @@ -85,7 +85,7 @@ |
131 | } |
132 | |
133 | class TestingTransportCostCalculator : public ITransportCostCalculator { |
134 | - int32_t calc_cost_estimate(Coords c1, Coords c2) const override { |
135 | + int32_t calc_cost_estimate(const Coords& c1, const Coords& c2) const override { |
136 | // We use an euclidian metric here. It is much easier for |
137 | // test cases |
138 | double xd = (c1.x - c2.x); |
139 | @@ -405,7 +405,7 @@ |
140 | */ |
141 | TestingRoutingNode * new_node_w_neighbour |
142 | (TestingRoutingNode * const d, |
143 | - Coords const pos = Coords(0, 0), |
144 | + const Coords& pos = Coords(0, 0), |
145 | int32_t = 1, |
146 | int32_t const waitcost = 0) |
147 | { |
148 | |
149 | === modified file 'src/logic/cmd_delete_message.h' |
150 | --- src/logic/cmd_delete_message.h 2015-11-27 12:46:45 +0000 |
151 | +++ src/logic/cmd_delete_message.h 2016-07-24 20:00:22 +0000 |
152 | @@ -37,7 +37,7 @@ |
153 | /// the savegame. |
154 | struct CmdDeleteMessage : public Command { |
155 | CmdDeleteMessage |
156 | - (uint32_t const t, PlayerNumber const p, MessageId const m) |
157 | + (uint32_t const t, PlayerNumber const p, const MessageId& m) |
158 | : Command(t), player(p), message(m) |
159 | {} |
160 | |
161 | |
162 | === modified file 'src/logic/editor_game_base.cc' |
163 | --- src/logic/editor_game_base.cc 2016-04-03 09:03:03 +0000 |
164 | +++ src/logic/editor_game_base.cc 2016-07-24 20:00:22 +0000 |
165 | @@ -260,7 +260,7 @@ |
166 | * \li former_buildings is the list of former buildings |
167 | */ |
168 | Building & EditorGameBase::warp_building |
169 | - (Coords const c, PlayerNumber const owner, DescriptionIndex const idx, |
170 | + (const Coords& c, PlayerNumber const owner, DescriptionIndex const idx, |
171 | Building::FormerBuildings former_buildings) |
172 | { |
173 | Player & plr = player(owner); |
174 | @@ -279,7 +279,7 @@ |
175 | * an enhancement. |
176 | */ |
177 | Building & EditorGameBase::warp_constructionsite |
178 | - (Coords const c, PlayerNumber const owner, |
179 | + (const Coords& c, PlayerNumber const owner, |
180 | DescriptionIndex idx, bool loading, |
181 | Building::FormerBuildings former_buildings) |
182 | { |
183 | @@ -296,7 +296,7 @@ |
184 | * except during loading. |
185 | */ |
186 | Building & EditorGameBase::warp_dismantlesite |
187 | - (Coords const c, PlayerNumber const owner, |
188 | + (const Coords& c, PlayerNumber const owner, |
189 | bool loading, Building::FormerBuildings former_buildings) |
190 | { |
191 | Player & plr = player(owner); |
192 | @@ -327,11 +327,11 @@ |
193 | * |
194 | */ |
195 | |
196 | -Bob& EditorGameBase::create_critter(Coords const c, DescriptionIndex const bob_type_idx, Player* owner) { |
197 | +Bob& EditorGameBase::create_critter(const Coords& c, DescriptionIndex const bob_type_idx, Player* owner) { |
198 | return create_bob(c, *world().get_bob_descr(bob_type_idx), owner); |
199 | } |
200 | |
201 | -Bob& EditorGameBase::create_critter(Coords c, const std::string& name, Player* owner) { |
202 | +Bob& EditorGameBase::create_critter(const Coords& c, const std::string& name, Player* owner) { |
203 | const BobDescr* descr = world().get_bob_descr(name); |
204 | if (descr == nullptr) |
205 | throw GameDataError("create_critter(%i,%i,%s,%s): critter not found", c.x, c.y, name.c_str(), |
206 | @@ -349,7 +349,7 @@ |
207 | =============== |
208 | */ |
209 | Immovable & EditorGameBase::create_immovable |
210 | - (Coords const c, DescriptionIndex const idx, MapObjectDescr::OwnerType type) |
211 | + (const Coords& c, DescriptionIndex const idx, MapObjectDescr::OwnerType type) |
212 | { |
213 | const ImmovableDescr & descr = |
214 | * |
215 | @@ -364,7 +364,7 @@ |
216 | } |
217 | |
218 | Immovable & EditorGameBase::create_immovable |
219 | - (Coords const c, const std::string & name, MapObjectDescr::OwnerType type) |
220 | + (const Coords& c, const std::string & name, MapObjectDescr::OwnerType type) |
221 | { |
222 | DescriptionIndex idx; |
223 | if (type == MapObjectDescr::OwnerType::kTribe) { |
224 | @@ -391,12 +391,12 @@ |
225 | * idx is the bob type. |
226 | */ |
227 | |
228 | -Bob& EditorGameBase::create_ship(Coords const c, int const ship_type_idx, Player* owner) { |
229 | +Bob& EditorGameBase::create_ship(const Coords& c, int const ship_type_idx, Player* owner) { |
230 | const BobDescr* descr = dynamic_cast<const BobDescr*>(tribes().get_ship_descr(ship_type_idx)); |
231 | return create_bob(c, *descr, owner); |
232 | } |
233 | |
234 | -Bob& EditorGameBase::create_ship(Coords c, const std::string& name, Player* owner) { |
235 | +Bob& EditorGameBase::create_ship(const Coords& c, const std::string& name, Player* owner) { |
236 | try { |
237 | int idx = tribes().safe_ship_index(name); |
238 | return create_ship(c, idx, owner); |
239 | @@ -482,7 +482,7 @@ |
240 | |
241 | |
242 | void EditorGameBase::set_road |
243 | - (FCoords const f, uint8_t const direction, uint8_t const roadtype) |
244 | + (const FCoords& f, uint8_t const direction, uint8_t const roadtype) |
245 | { |
246 | const Map & m = map(); |
247 | const Field & first_field = m[0]; |
248 | |
249 | === modified file 'src/logic/editor_game_base.h' |
250 | --- src/logic/editor_game_base.h 2016-04-03 09:03:03 +0000 |
251 | +++ src/logic/editor_game_base.h 2016-07-24 20:00:22 +0000 |
252 | @@ -119,35 +119,35 @@ |
253 | void load_graphics(UI::ProgressWindow& loader_ui); |
254 | virtual void cleanup_for_load(); |
255 | |
256 | - void set_road(FCoords, uint8_t direction, uint8_t roadtype); |
257 | + void set_road(const FCoords&, uint8_t direction, uint8_t roadtype); |
258 | |
259 | // warping stuff. instantly creating map_objects |
260 | Building& |
261 | - warp_building(Coords, |
262 | + warp_building(const Coords&, |
263 | PlayerNumber, |
264 | DescriptionIndex, |
265 | Building::FormerBuildings former_buildings = Building::FormerBuildings()); |
266 | Building& |
267 | - warp_constructionsite(Coords, |
268 | + warp_constructionsite(const Coords&, |
269 | PlayerNumber, |
270 | DescriptionIndex, |
271 | bool loading = false, |
272 | Building::FormerBuildings former_buildings = Building::FormerBuildings()); |
273 | Building& |
274 | - warp_dismantlesite(Coords, |
275 | + warp_dismantlesite(const Coords&, |
276 | PlayerNumber, |
277 | bool loading = false, |
278 | Building::FormerBuildings former_buildings = Building::FormerBuildings()); |
279 | - Bob& create_critter(Coords, DescriptionIndex bob_type_idx, Player* owner = nullptr); |
280 | - Bob& create_critter(Coords, const std::string& name, Player* owner = nullptr); |
281 | - Immovable& create_immovable(Coords, |
282 | + Bob& create_critter(const Coords&, DescriptionIndex bob_type_idx, Player* owner = nullptr); |
283 | + Bob& create_critter(const Coords&, const std::string& name, Player* owner = nullptr); |
284 | + Immovable& create_immovable(const Coords&, |
285 | DescriptionIndex idx, |
286 | MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld); |
287 | - Immovable& create_immovable(Coords, |
288 | + Immovable& create_immovable(const Coords&, |
289 | const std::string& name, |
290 | MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld); |
291 | - Bob& create_ship(Coords, int ship_type_idx, Player* owner = nullptr); |
292 | - Bob& create_ship(Coords, const std::string& name, Player* owner = nullptr); |
293 | + Bob& create_ship(const Coords&, int ship_type_idx, Player* owner = nullptr); |
294 | + Bob& create_ship(const Coords&, const std::string& name, Player* owner = nullptr); |
295 | |
296 | uint32_t get_gametime() const { |
297 | return gametime_; |
298 | |
299 | === modified file 'src/logic/game.cc' |
300 | --- src/logic/game.cc 2016-03-20 16:05:19 +0000 |
301 | +++ src/logic/game.cc 2016-07-24 20:00:22 +0000 |
302 | @@ -711,13 +711,13 @@ |
303 | |
304 | |
305 | void Game::send_player_build |
306 | - (int32_t const pid, Coords const coords, DescriptionIndex const id) |
307 | + (int32_t const pid, const Coords& coords, DescriptionIndex const id) |
308 | { |
309 | assert(tribes().building_exists(id)); |
310 | send_player_command (*new CmdBuild(get_gametime(), pid, coords, id)); |
311 | } |
312 | |
313 | -void Game::send_player_build_flag (int32_t const pid, Coords const coords) |
314 | +void Game::send_player_build_flag (int32_t const pid, const Coords& coords) |
315 | { |
316 | send_player_command (*new CmdBuildFlag(get_gametime(), pid, coords)); |
317 | } |
318 | |
319 | === modified file 'src/logic/game.h' |
320 | --- src/logic/game.h 2016-02-21 18:57:49 +0000 |
321 | +++ src/logic/game.h 2016-07-24 20:00:22 +0000 |
322 | @@ -170,8 +170,8 @@ |
323 | |
324 | void send_player_bulldoze (PlayerImmovable &, bool recurse = false); |
325 | void send_player_dismantle (PlayerImmovable &); |
326 | - void send_player_build (int32_t, Coords, DescriptionIndex); |
327 | - void send_player_build_flag (int32_t, Coords); |
328 | + void send_player_build (int32_t, const Coords&, DescriptionIndex); |
329 | + void send_player_build_flag (int32_t, const Coords&); |
330 | void send_player_build_road (int32_t, Path &); |
331 | void send_player_flagaction (Flag &); |
332 | void send_player_start_stop_building (Building &); |
333 | |
334 | === modified file 'src/logic/game_settings.h' |
335 | --- src/logic/game_settings.h 2016-03-19 11:47:00 +0000 |
336 | +++ src/logic/game_settings.h 2016-07-24 20:00:22 +0000 |
337 | @@ -162,7 +162,7 @@ |
338 | virtual void set_player_tribe (uint8_t number, const std::string &, bool const random_tribe = false) = 0; |
339 | virtual void set_player_init (uint8_t number, uint8_t index) = 0; |
340 | virtual void set_player_name (uint8_t number, const std::string &) = 0; |
341 | - virtual void set_player (uint8_t number, PlayerSettings) = 0; |
342 | + virtual void set_player (uint8_t number, const PlayerSettings&) = 0; |
343 | virtual void set_player_number (uint8_t number) = 0; |
344 | virtual void set_player_team (uint8_t number, Widelands::TeamNumber team) = 0; |
345 | virtual void set_player_closeable(uint8_t number, bool closeable) = 0; |
346 | |
347 | === modified file 'src/logic/map.cc' |
348 | --- src/logic/map.cc 2016-07-17 19:34:09 +0000 |
349 | +++ src/logic/map.cc 2016-07-24 20:00:22 +0000 |
350 | @@ -81,7 +81,7 @@ |
351 | cleanup(); |
352 | } |
353 | |
354 | -void Map::recalc_border(const FCoords fc) { |
355 | +void Map::recalc_border(const FCoords& fc) { |
356 | if (const PlayerNumber owner = fc.field->get_owned_by()) { |
357 | // A node that is owned by a player and has a neighbour that is not owned |
358 | // by that player is a border node. |
359 | @@ -335,7 +335,7 @@ |
360 | } |
361 | |
362 | |
363 | -void Map::set_origin(Coords const new_origin) { |
364 | +void Map::set_origin(const Coords& new_origin) { |
365 | assert(0 <= new_origin.x); |
366 | assert (new_origin.x < width_); |
367 | assert(0 <= new_origin.y); |
368 | @@ -528,7 +528,7 @@ |
369 | Set the starting coordinates of a player |
370 | =============== |
371 | */ |
372 | -void Map::set_starting_pos(PlayerNumber const plnum, Coords const c) |
373 | +void Map::set_starting_pos(PlayerNumber const plnum, const Coords& c) |
374 | { |
375 | assert(1 <= plnum && plnum <= get_nrplayers()); |
376 | starting_pos_[plnum - 1] = c; |
377 | @@ -586,7 +586,7 @@ |
378 | |
379 | |
380 | /// \returns the immovable at the given coordinate |
381 | -BaseImmovable * Map::get_immovable(const Coords coord) const |
382 | +BaseImmovable * Map::get_immovable(const Coords& coord) const |
383 | { |
384 | return operator[](coord).get_immovable(); |
385 | } |
386 | @@ -602,7 +602,7 @@ |
387 | */ |
388 | template<typename functorT> |
389 | void Map::find_reachable |
390 | - (Area<FCoords> const area, const CheckStep & checkstep, functorT & functor) |
391 | + (const Area<FCoords>& area, const CheckStep & checkstep, functorT & functor) |
392 | { |
393 | std::vector<Coords> queue; |
394 | boost::shared_ptr<Pathfields> pathfields = pathfieldmgr_->allocate(); |
395 | @@ -654,7 +654,7 @@ |
396 | =============== |
397 | */ |
398 | template<typename functorT> |
399 | -void Map::find(const Area<FCoords> area, functorT & functor) const { |
400 | +void Map::find(const Area<FCoords>& area, functorT & functor) const { |
401 | MapRegion<Area<FCoords> > mr(*this, area); |
402 | do functor(*this, mr.location()); while (mr.advance(*this)); |
403 | } |
404 | @@ -671,7 +671,7 @@ |
405 | FindBobsCallback(std::vector<Bob *> * const list, const FindBob & functor) |
406 | : list_(list), functor_(functor), found_(0) {} |
407 | |
408 | - void operator()(const Map &, const FCoords cur) { |
409 | + void operator()(const Map &, const FCoords& cur) { |
410 | for |
411 | (Bob * bob = cur.field->get_first_bob(); |
412 | bob; |
413 | @@ -758,7 +758,7 @@ |
414 | (std::vector<ImmovableFound> * const list, const FindImmovable & functor) |
415 | : list_(list), functor_(functor), found_(0) {} |
416 | |
417 | - void operator()(const Map &, const FCoords cur) { |
418 | + void operator()(const Map &, const FCoords& cur) { |
419 | BaseImmovable * const imm = cur.field->get_immovable(); |
420 | |
421 | if (!imm) |
422 | @@ -869,7 +869,7 @@ |
423 | (std::vector<Coords> * const list, const FindNode & functor) |
424 | : list_(list), functor_(functor), found_(0) {} |
425 | |
426 | - void operator()(const Map & map, const FCoords cur) { |
427 | + void operator()(const Map & map, const FCoords& cur) { |
428 | if (functor_.accept(map, cur)) { |
429 | if (list_) |
430 | list_->push_back(cur); |
431 | @@ -962,7 +962,7 @@ |
432 | Fetch the slopes to neighbours and call the actual logic in Field |
433 | =============== |
434 | */ |
435 | -void Map::recalc_brightness(FCoords const f) { |
436 | +void Map::recalc_brightness(const FCoords& f) { |
437 | int32_t left, right, top_left, top_right, bottom_left, bottom_right; |
438 | Field::Height const height = f.field->get_height(); |
439 | |
440 | @@ -1007,11 +1007,11 @@ |
441 | above recalc_brightness. |
442 | =============== |
443 | */ |
444 | -void Map::recalc_nodecaps_pass1(const World& world, FCoords const f) { |
445 | +void Map::recalc_nodecaps_pass1(const World& world, const FCoords& f) { |
446 | f.field->caps = calc_nodecaps_pass1(world, f, true); |
447 | } |
448 | |
449 | -NodeCaps Map::calc_nodecaps_pass1(const World& world, FCoords const f, bool consider_mobs) { |
450 | +NodeCaps Map::calc_nodecaps_pass1(const World& world, const FCoords& f, bool consider_mobs) { |
451 | uint8_t caps = CAPS_NONE; |
452 | |
453 | // 1a) Get all the neighbours to make life easier |
454 | @@ -1125,7 +1125,7 @@ |
455 | } |
456 | |
457 | NodeCaps Map::calc_nodecaps_pass2 |
458 | - (const World& world, FCoords const f, bool consider_mobs, NodeCaps initcaps) |
459 | + (const World& world, const FCoords& f, bool consider_mobs, NodeCaps initcaps) |
460 | { |
461 | uint8_t caps = consider_mobs ? f.field->caps : static_cast<uint8_t>(initcaps); |
462 | |
463 | @@ -1401,7 +1401,7 @@ |
464 | * Calculate the (Manhattan) distance from a to b |
465 | * a and b are expected to be normalized! |
466 | */ |
467 | -uint32_t Map::calc_distance(const Coords a, const Coords b) const |
468 | +uint32_t Map::calc_distance(const Coords& a, const Coords& b) const |
469 | { |
470 | uint32_t dist; |
471 | int32_t dy; |
472 | @@ -1475,7 +1475,7 @@ |
473 | This function is used mainly for the path-finding estimate. |
474 | =============== |
475 | */ |
476 | -int32_t Map::calc_cost_estimate(const Coords a, const Coords b) const |
477 | +int32_t Map::calc_cost_estimate(const Coords& a, const Coords& b) const |
478 | { |
479 | return calc_distance(a, b) * BASE_COST_PER_FIELD; |
480 | } |
481 | @@ -1484,7 +1484,7 @@ |
482 | /** |
483 | * \return a lower bound on the time required to walk from \p a to \p b |
484 | */ |
485 | -int32_t Map::calc_cost_lowerbound(const Coords a, const Coords b) const |
486 | +int32_t Map::calc_cost_lowerbound(const Coords& a, const Coords& b) const |
487 | { |
488 | return calc_distance(a, b) * calc_cost(-SLOPE_COST_STEPS); |
489 | } |
490 | @@ -1536,7 +1536,7 @@ |
491 | direction, in milliseconds. |
492 | =============== |
493 | */ |
494 | -int32_t Map::calc_cost(const Coords coords, const int32_t dir) const |
495 | +int32_t Map::calc_cost(const Coords& coords, const int32_t dir) const |
496 | { |
497 | FCoords f; |
498 | int32_t startheight; |
499 | @@ -1558,7 +1558,7 @@ |
500 | Calculate the average cost of walking the given step in both directions. |
501 | =============== |
502 | */ |
503 | -int32_t Map::calc_bidi_cost(const Coords coords, const int32_t dir) const |
504 | +int32_t Map::calc_bidi_cost(const Coords& coords, const int32_t dir) const |
505 | { |
506 | FCoords f; |
507 | int32_t startheight; |
508 | @@ -1820,7 +1820,7 @@ |
509 | } |
510 | |
511 | |
512 | -bool Map::can_reach_by_water(const Coords field) const |
513 | +bool Map::can_reach_by_water(const Coords& field) const |
514 | { |
515 | FCoords fc = get_fcoords(field); |
516 | |
517 | |
518 | === modified file 'src/logic/map.h' |
519 | --- src/logic/map.h 2016-05-07 18:54:04 +0000 |
520 | +++ src/logic/map.h 2016-07-24 20:00:22 +0000 |
521 | @@ -200,7 +200,7 @@ |
522 | |
523 | void set_nrplayers(PlayerNumber); |
524 | |
525 | - void set_starting_pos(PlayerNumber, Coords); |
526 | + void set_starting_pos(PlayerNumber, const Coords&); |
527 | Coords get_starting_pos(PlayerNumber const p) const { |
528 | assert(1 <= p && p <= get_nrplayers()); |
529 | return starting_pos_[p - 1]; |
530 | @@ -258,7 +258,7 @@ |
531 | /// \returns the maximum theoretical possible nodecaps (no blocking bobs, etc.) |
532 | NodeCaps get_max_nodecaps(const World& world, const FCoords &); |
533 | |
534 | - BaseImmovable * get_immovable(Coords) const; |
535 | + BaseImmovable * get_immovable(const Coords&) const; |
536 | uint32_t find_bobs |
537 | (const Area<FCoords>, |
538 | std::vector<Bob *> * list, |
539 | @@ -302,13 +302,13 @@ |
540 | FCoords get_fcoords(Field &) const; |
541 | void get_coords(Field & f, Coords & c) const; |
542 | |
543 | - uint32_t calc_distance(Coords, Coords) const; |
544 | + uint32_t calc_distance(const Coords&, const Coords&) const; |
545 | |
546 | - int32_t calc_cost_estimate(Coords, Coords) const override; |
547 | - int32_t calc_cost_lowerbound(Coords, Coords) const; |
548 | + int32_t calc_cost_estimate(const Coords&, const Coords&) const override; |
549 | + int32_t calc_cost_lowerbound(const Coords&, const Coords&) const; |
550 | int32_t calc_cost(int32_t slope) const; |
551 | - int32_t calc_cost(Coords, int32_t dir) const; |
552 | - int32_t calc_bidi_cost(Coords, int32_t dir) const; |
553 | + int32_t calc_cost(const Coords&, int32_t dir) const; |
554 | + int32_t calc_bidi_cost(const Coords&, int32_t dir) const; |
555 | void calc_cost(const Path &, int32_t * forward, int32_t * backward) const; |
556 | |
557 | void get_ln (const Coords &, Coords *) const; |
558 | @@ -353,7 +353,7 @@ |
559 | * We can reach a field by water either if it has MOVECAPS_SWIM or if it has |
560 | * MOVECAPS_WALK and at least one of the neighbours has MOVECAPS_SWIM |
561 | */ |
562 | - bool can_reach_by_water(Coords) const; |
563 | + bool can_reach_by_water(const Coords&) const; |
564 | |
565 | /// Sets the height to a value. Recalculates brightness. Changes the |
566 | /// surrounding nodes if necessary. Returns the radius that covers all |
567 | @@ -425,7 +425,7 @@ |
568 | MilitaryInfluence calc_influence(Coords, Area<>) const; |
569 | |
570 | /// Translate the whole map so that the given point becomes the new origin. |
571 | - void set_origin(Coords); |
572 | + void set_origin(const Coords&); |
573 | |
574 | /// Port space specific functions |
575 | bool is_port_space(const Coords& c) const; |
576 | @@ -441,7 +441,7 @@ |
577 | void set_size(uint32_t w, uint32_t h); |
578 | |
579 | private: |
580 | - void recalc_border(FCoords); |
581 | + void recalc_border(const FCoords&); |
582 | |
583 | /// # of players this map supports (!= Game's number of players!) |
584 | PlayerNumber nrplayers_; |
585 | @@ -474,12 +474,12 @@ |
586 | PortSpacesSet port_spaces_; |
587 | Objectives objectives_; |
588 | |
589 | - void recalc_brightness(FCoords); |
590 | - void recalc_nodecaps_pass1(const World& world, FCoords); |
591 | + void recalc_brightness(const FCoords&); |
592 | + void recalc_nodecaps_pass1(const World& world, const FCoords&); |
593 | void recalc_nodecaps_pass2(const World& world, const FCoords & f); |
594 | - NodeCaps calc_nodecaps_pass1(const World& world, FCoords, bool consider_mobs = true); |
595 | + NodeCaps calc_nodecaps_pass1(const World& world, const FCoords&, bool consider_mobs = true); |
596 | NodeCaps calc_nodecaps_pass2(const World& world, |
597 | - FCoords, |
598 | + const FCoords&, |
599 | bool consider_mobs = true, |
600 | NodeCaps initcaps = CAPS_NONE); |
601 | void check_neighbour_heights(FCoords, uint32_t & radius); |
602 | @@ -489,8 +489,8 @@ |
603 | bool is_cycle_connected |
604 | (const FCoords & start, uint32_t length, const WalkingDir * dirs); |
605 | template<typename functorT> |
606 | - void find_reachable(Area<FCoords>, const CheckStep &, functorT &); |
607 | - template<typename functorT> void find(const Area<FCoords>, functorT &) const; |
608 | + void find_reachable(const Area<FCoords>&, const CheckStep &, functorT &); |
609 | + template<typename functorT> void find(const Area<FCoords>&, functorT &) const; |
610 | |
611 | MapVersion map_version_; |
612 | }; |
613 | |
614 | === modified file 'src/logic/map_objects/checkstep.cc' |
615 | --- src/logic/map_objects/checkstep.cc 2016-02-07 09:30:20 +0000 |
616 | +++ src/logic/map_objects/checkstep.cc 2016-07-24 20:00:22 +0000 |
617 | @@ -59,7 +59,7 @@ |
618 | } |
619 | |
620 | bool CheckStepAnd::allowed |
621 | - (Map & map, FCoords const start, FCoords const end, int32_t const dir, |
622 | + (Map & map, const FCoords& start, const FCoords& end, int32_t const dir, |
623 | CheckStep::StepId const id) |
624 | const |
625 | { |
626 | @@ -71,7 +71,7 @@ |
627 | return true; |
628 | } |
629 | |
630 | -bool CheckStepAnd::reachable_dest(Map & map, FCoords const dest) const |
631 | +bool CheckStepAnd::reachable_dest(Map & map, const FCoords& dest) const |
632 | { |
633 | for (const CheckStep& checkstep : subs) { |
634 | if (!checkstep.reachable_dest(map, dest)) { |
635 | @@ -87,7 +87,7 @@ |
636 | =============== |
637 | */ |
638 | bool CheckStepDefault::allowed |
639 | - (Map &, FCoords start, FCoords end, int32_t, CheckStep::StepId) const |
640 | + (Map &, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId) const |
641 | { |
642 | NodeCaps const endcaps = end.field->nodecaps(); |
643 | |
644 | @@ -103,7 +103,7 @@ |
645 | return false; |
646 | } |
647 | |
648 | -bool CheckStepDefault::reachable_dest(Map & map, FCoords const dest) const |
649 | +bool CheckStepDefault::reachable_dest(Map & map, const FCoords& dest) const |
650 | { |
651 | NodeCaps const caps = dest.field->nodecaps(); |
652 | |
653 | @@ -126,8 +126,8 @@ |
654 | */ |
655 | bool CheckStepWalkOn::allowed |
656 | (Map &, |
657 | - FCoords const start, |
658 | - FCoords const end, |
659 | + const FCoords& start, |
660 | + const FCoords& end, |
661 | int32_t, |
662 | CheckStep::StepId const id) |
663 | const |
664 | @@ -162,7 +162,7 @@ |
665 | |
666 | |
667 | bool CheckStepRoad::allowed |
668 | - (Map & map, FCoords const start, FCoords const end, int32_t, |
669 | + (Map & map, const FCoords& start, const FCoords& end, int32_t, |
670 | CheckStep::StepId const id) |
671 | const |
672 | { |
673 | @@ -193,7 +193,7 @@ |
674 | return true; |
675 | } |
676 | |
677 | -bool CheckStepRoad::reachable_dest(Map & map, FCoords const dest) const |
678 | +bool CheckStepRoad::reachable_dest(Map & map, const FCoords& dest) const |
679 | { |
680 | NodeCaps const caps = dest.field->nodecaps(); |
681 | |
682 | @@ -210,7 +210,7 @@ |
683 | |
684 | |
685 | bool CheckStepLimited::allowed |
686 | - (Map &, FCoords, FCoords const end, int32_t, CheckStep::StepId) const |
687 | + (Map &, const FCoords&, const FCoords& end, int32_t, CheckStep::StepId) const |
688 | { |
689 | return allowed_locations_.find(end) != allowed_locations_.end(); |
690 | } |
691 | |
692 | === modified file 'src/logic/map_objects/checkstep.h' |
693 | --- src/logic/map_objects/checkstep.h 2016-02-09 16:29:48 +0000 |
694 | +++ src/logic/map_objects/checkstep.h 2016-07-24 20:00:22 +0000 |
695 | @@ -110,11 +110,11 @@ |
696 | void add(const CheckStep & sub); |
697 | |
698 | bool allowed |
699 | - (Map &, FCoords start, FCoords end, |
700 | + (Map &, const FCoords& start, const FCoords& end, |
701 | int32_t dir, |
702 | CheckStep::StepId id) |
703 | const; |
704 | - bool reachable_dest(Map &, FCoords dest) const; |
705 | + bool reachable_dest(Map &, const FCoords& dest) const; |
706 | |
707 | private: |
708 | std::vector<CheckStep> subs; |
709 | @@ -131,9 +131,9 @@ |
710 | CheckStepDefault(uint8_t const movecaps) : movecaps_(movecaps) {} |
711 | |
712 | bool allowed |
713 | - (Map &, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) |
714 | + (Map &, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) |
715 | const; |
716 | - bool reachable_dest(Map &, FCoords dest) const; |
717 | + bool reachable_dest(Map &, const FCoords& dest) const; |
718 | |
719 | private: |
720 | uint8_t movecaps_; |
721 | @@ -150,7 +150,7 @@ |
722 | movecaps_(movecaps), onlyend_(onlyend) {} |
723 | |
724 | bool allowed |
725 | - (Map &, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) |
726 | + (Map &, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) |
727 | const; |
728 | bool reachable_dest(Map &, FCoords dest) const; |
729 | |
730 | @@ -173,9 +173,9 @@ |
731 | {} |
732 | |
733 | bool allowed |
734 | - (Map &, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) |
735 | + (Map &, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) |
736 | const; |
737 | - bool reachable_dest(Map &, FCoords dest) const; |
738 | + bool reachable_dest(Map &, const FCoords& dest) const; |
739 | |
740 | private: |
741 | const Player & player_; |
742 | @@ -189,7 +189,7 @@ |
743 | struct CheckStepLimited { |
744 | void add_allowed_location(const Coords & c) {allowed_locations_.insert(c);} |
745 | bool allowed |
746 | - (Map &, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) |
747 | + (Map &, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) |
748 | const; |
749 | bool reachable_dest(Map &, FCoords dest) const; |
750 | |
751 | |
752 | === modified file 'src/logic/map_objects/immovable.cc' |
753 | --- src/logic/map_objects/immovable.cc 2016-05-17 15:02:21 +0000 |
754 | +++ src/logic/map_objects/immovable.cc 2016-07-24 20:00:22 +0000 |
755 | @@ -98,7 +98,7 @@ |
756 | * |
757 | * \note this function will remove the immovable (if existing) currently connected to this position. |
758 | */ |
759 | -void BaseImmovable::set_position(EditorGameBase & egbase, Coords const c) |
760 | +void BaseImmovable::set_position(EditorGameBase & egbase, const Coords& c) |
761 | { |
762 | assert(c); |
763 | |
764 | @@ -118,7 +118,7 @@ |
765 | * |
766 | * Only call this during cleanup. |
767 | */ |
768 | -void BaseImmovable::unset_position(EditorGameBase & egbase, Coords const c) |
769 | +void BaseImmovable::unset_position(EditorGameBase & egbase, const Coords& c) |
770 | { |
771 | Map & map = egbase.map(); |
772 | FCoords const f = map.get_fcoords(c); |
773 | @@ -333,7 +333,7 @@ |
774 | * Create an immovable of this type |
775 | */ |
776 | Immovable & ImmovableDescr::create |
777 | - (EditorGameBase & egbase, Coords const coords) const |
778 | + (EditorGameBase & egbase, const Coords& coords) const |
779 | { |
780 | assert(this != nullptr); |
781 | Immovable & result = *new Immovable(*this); |
782 | |
783 | === modified file 'src/logic/map_objects/immovable.h' |
784 | --- src/logic/map_objects/immovable.h 2016-05-12 07:51:17 +0000 |
785 | +++ src/logic/map_objects/immovable.h 2016-07-24 20:00:22 +0000 |
786 | @@ -100,8 +100,8 @@ |
787 | static std::string size_to_string(int32_t size); |
788 | |
789 | protected: |
790 | - void set_position(EditorGameBase &, Coords); |
791 | - void unset_position(EditorGameBase &, Coords); |
792 | + void set_position(EditorGameBase &, const Coords&); |
793 | + void unset_position(EditorGameBase &, const Coords&); |
794 | }; |
795 | |
796 | |
797 | @@ -126,7 +126,7 @@ |
798 | int32_t get_size() const {return size_;} |
799 | ImmovableProgram const * get_program(const std::string &) const; |
800 | |
801 | - Immovable & create(EditorGameBase &, Coords) const; |
802 | + Immovable & create(EditorGameBase &, const Coords&) const; |
803 | |
804 | MapObjectDescr::OwnerType owner_type() const {return owner_type_;} |
805 | |
806 | |
807 | === modified file 'src/logic/map_objects/tribes/building.cc' |
808 | --- src/logic/map_objects/tribes/building.cc 2016-04-01 09:29:17 +0000 |
809 | +++ src/logic/map_objects/tribes/building.cc 2016-07-24 20:00:22 +0000 |
810 | @@ -188,7 +188,7 @@ |
811 | } |
812 | |
813 | |
814 | -int32_t BuildingDescr::suitability(const Map &, FCoords const fc) const { |
815 | +int32_t BuildingDescr::suitability(const Map &, const FCoords& fc) const { |
816 | return size_ <= (fc.field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK); |
817 | } |
818 | |
819 | |
820 | === modified file 'src/logic/map_objects/tribes/building.h' |
821 | --- src/logic/map_objects/tribes/building.h 2016-03-19 09:58:41 +0000 |
822 | +++ src/logic/map_objects/tribes/building.h 2016-07-24 20:00:22 +0000 |
823 | @@ -125,7 +125,7 @@ |
824 | |
825 | WorkareaInfo workarea_info_; |
826 | |
827 | - virtual int32_t suitability(const Map &, FCoords) const; |
828 | + virtual int32_t suitability(const Map &, const FCoords&) const; |
829 | const BuildingHints & hints() const {return hints_;} |
830 | |
831 | protected: |
832 | |
833 | === modified file 'src/logic/map_objects/tribes/ship.h' |
834 | --- src/logic/map_objects/tribes/ship.h 2016-04-03 08:01:49 +0000 |
835 | +++ src/logic/map_objects/tribes/ship.h 2016-07-24 20:00:22 +0000 |
836 | @@ -52,7 +52,7 @@ |
837 | enum class Message {kLost, kGained, kWaitingForCommand}; |
838 | Message message; |
839 | |
840 | - NoteShipMessage(Ship* const init_ship, Message const init_message) |
841 | + NoteShipMessage(Ship* const init_ship, const Message& init_message) |
842 | : ship(init_ship), message(init_message) { |
843 | } |
844 | }; |
845 | |
846 | === modified file 'src/logic/map_objects/tribes/trainingsite.cc' |
847 | --- src/logic/map_objects/tribes/trainingsite.cc 2016-04-11 06:45:29 +0000 |
848 | +++ src/logic/map_objects/tribes/trainingsite.cc 2016-07-24 20:00:22 +0000 |
849 | @@ -813,18 +813,15 @@ |
850 | void |
851 | TrainingSite::training_done() |
852 | { |
853 | - TrainFailCount::iterator it; |
854 | - for (it = training_failure_count_.begin(); it != training_failure_count_.end(); it++) |
855 | - { |
856 | + for (auto& fail_and_presence : training_failure_count_) { |
857 | // If a soldier is present at this training level, deteoriate |
858 | - if (it->second.second) |
859 | + if (fail_and_presence.second.second) |
860 | { |
861 | - it->second.first++; |
862 | - it->second.second = 0; |
863 | + fail_and_presence.second.first++; |
864 | + fail_and_presence.second.second = 0; |
865 | + } else if (0 < fail_and_presence.second.first) { // If no soldier, let's become optimistic |
866 | + fail_and_presence.second.first--; |
867 | } |
868 | - else // If no soldier, let's become optimistic |
869 | - if (0 < it->second.first) |
870 | - it->second.first--; |
871 | } |
872 | } |
873 | |
874 | |
875 | === modified file 'src/logic/map_objects/world/map_gen.cc' |
876 | --- src/logic/map_objects/world/map_gen.cc 2016-01-18 19:35:25 +0000 |
877 | +++ src/logic/map_objects/world/map_gen.cc 2016-07-24 20:00:22 +0000 |
878 | @@ -30,10 +30,10 @@ |
879 | |
880 | namespace Widelands { |
881 | |
882 | -MapGenBobCategory::MapGenBobCategory(const LuaTable& table) { |
883 | - immovables_ = table.get_table("immovables")->array_entries<std::string>(); |
884 | - critters_ = table.get_table("critters")->array_entries<std::string>(); |
885 | -} |
886 | +MapGenBobCategory::MapGenBobCategory(const LuaTable& table) : |
887 | + immovables_(table.get_table("immovables")->array_entries<std::string>()), |
888 | + critters_(table.get_table("critters")->array_entries<std::string>()) |
889 | +{} |
890 | |
891 | const MapGenBobCategory* |
892 | MapGenLandResource::get_bob_category(MapGenAreaInfo::MapGenTerrainType terrType) const { |
893 | |
894 | === modified file 'src/logic/maptriangleregion.h' |
895 | --- src/logic/maptriangleregion.h 2016-02-22 07:25:15 +0000 |
896 | +++ src/logic/maptriangleregion.h 2016-07-24 20:00:22 +0000 |
897 | @@ -64,7 +64,7 @@ |
898 | bool advance(const Map &); |
899 | }; |
900 | template <> struct MapTriangleRegion<FCoords> { |
901 | - MapTriangleRegion(const Map & map, const Area<FCoords> area) : |
902 | + MapTriangleRegion(const Map & map, const Area<FCoords>& area) : |
903 | area_(TCoords<FCoords>(area, TCoords<FCoords>::D), area.radius + 1), |
904 | rowwidth_ (area_.radius * 2 + 1), |
905 | remaining_in_row_(rowwidth_), |
906 | |
907 | === modified file 'src/logic/message.h' |
908 | --- src/logic/message.h 2016-01-02 12:36:38 +0000 |
909 | +++ src/logic/message.h 2016-07-24 20:00:22 +0000 |
910 | @@ -70,7 +70,7 @@ |
911 | const std::string& init_icon_filename, |
912 | const std::string& init_heading, |
913 | const std::string& init_body, |
914 | - Widelands::Coords const c = Coords::null(), |
915 | + const Widelands::Coords& c = Coords::null(), |
916 | Widelands::Serial ser = 0, |
917 | Status s = Status::kNew) |
918 | : |
919 | |
920 | === modified file 'src/logic/player.cc' |
921 | --- src/logic/player.cc 2016-03-12 07:07:12 +0000 |
922 | +++ src/logic/player.cc 2016-07-24 20:00:22 +0000 |
923 | @@ -59,7 +59,7 @@ |
924 | |
925 | void terraform_for_building |
926 | (Widelands::EditorGameBase& egbase, const Widelands::PlayerNumber player_number, |
927 | - const Widelands::Coords location, const Widelands::BuildingDescr* descr) |
928 | + const Widelands::Coords& location, const Widelands::BuildingDescr* descr) |
929 | { |
930 | Widelands::Map & map = egbase.map(); |
931 | Widelands::FCoords c[4]; // Big buildings occupy 4 locations. |
932 | @@ -387,7 +387,7 @@ |
933 | Return filtered buildcaps that take the player's territory into account. |
934 | =============== |
935 | */ |
936 | -NodeCaps Player::get_buildcaps(FCoords const fc) const { |
937 | +NodeCaps Player::get_buildcaps(const FCoords& fc) const { |
938 | const Map & map = egbase().map(); |
939 | uint8_t buildcaps = fc.field->nodecaps(); |
940 | |
941 | @@ -421,7 +421,7 @@ |
942 | * Build a flag, checking that it's legal to do so. Returns |
943 | * the flag in case of success, else returns 0; |
944 | */ |
945 | -Flag * Player::build_flag(Coords const c) { |
946 | +Flag * Player::build_flag(const Coords& c) { |
947 | int32_t buildcaps = get_buildcaps(egbase().map().get_fcoords(c)); |
948 | |
949 | if (buildcaps & BUILDCAPS_FLAG) |
950 | @@ -430,7 +430,7 @@ |
951 | } |
952 | |
953 | |
954 | -Flag & Player::force_flag(FCoords const c) { |
955 | +Flag & Player::force_flag(const FCoords& c) { |
956 | log("Forcing flag at (%i, %i)\n", c.x, c.y); |
957 | const Map & map = egbase().map(); |
958 | if (BaseImmovable * const immovable = c.field->get_immovable()) { |
959 | @@ -983,7 +983,7 @@ |
960 | void Player::rediscover_node |
961 | (const Map & map, |
962 | const Widelands::Field & first_map_field, |
963 | - FCoords const f) |
964 | + const FCoords& f) |
965 | { |
966 | |
967 | assert(0 <= f.x); |
968 | @@ -1097,7 +1097,7 @@ |
969 | void Player::see_node |
970 | (const Map & map, |
971 | const Widelands::Field & first_map_field, |
972 | - FCoords const f, |
973 | + const FCoords& f, |
974 | Time const gametime, |
975 | bool const forward) |
976 | { |
977 | |
978 | === modified file 'src/logic/player.h' |
979 | --- src/logic/player.h 2016-05-09 14:20:16 +0000 |
980 | +++ src/logic/player.h 2016-07-24 20:00:22 +0000 |
981 | @@ -128,7 +128,7 @@ |
982 | |
983 | void create_default_infrastructure(); |
984 | |
985 | - NodeCaps get_buildcaps(FCoords) const; |
986 | + NodeCaps get_buildcaps(const FCoords&) const; |
987 | |
988 | bool is_hostile(const Player &) const; |
989 | |
990 | @@ -416,7 +416,7 @@ |
991 | void see_node |
992 | (const Map &, |
993 | const Widelands::Field & first_map_field, |
994 | - const FCoords, |
995 | + const FCoords&, |
996 | const Time, |
997 | const bool forward = false) |
998 | ; |
999 | @@ -472,8 +472,8 @@ |
1000 | |
1001 | // Player commands |
1002 | // Only to be called indirectly via CmdQueue |
1003 | - Flag & force_flag(FCoords); /// Do what it takes to create the flag. |
1004 | - Flag * build_flag(Coords); /// Build a flag if it is allowed. |
1005 | + Flag & force_flag(const FCoords&); /// Do what it takes to create the flag. |
1006 | + Flag * build_flag(const Coords&); /// Build a flag if it is allowed. |
1007 | Road & force_road(const Path &); |
1008 | Road * build_road(const Path &); /// Build a road if it is allowed. |
1009 | Building& force_building(Coords, const Building::FormerBuildings&); |
1010 | @@ -569,7 +569,7 @@ |
1011 | // Called when a node becomes seen or has changed. Discovers the node and |
1012 | // those of the 6 surrounding edges/triangles that are not seen from another |
1013 | // node. |
1014 | - void rediscover_node(const Map&, const Widelands::Field&, FCoords); |
1015 | + void rediscover_node(const Map&, const Widelands::Field&, const FCoords&); |
1016 | |
1017 | std::unique_ptr<Notifications::Subscriber<NoteImmovable>> immovable_subscriber_; |
1018 | std::unique_ptr<Notifications::Subscriber<NoteFieldTerrainChanged>> |
1019 | |
1020 | === modified file 'src/logic/playercommand.cc' |
1021 | --- src/logic/playercommand.cc 2016-03-19 12:51:22 +0000 |
1022 | +++ src/logic/playercommand.cc 2016-07-24 20:00:22 +0000 |
1023 | @@ -283,10 +283,9 @@ |
1024 | /*** class Cmd_BuildFlag ***/ |
1025 | |
1026 | CmdBuildFlag::CmdBuildFlag (StreamRead & des) : |
1027 | -PlayerCommand (0, des.unsigned_8()) |
1028 | -{ |
1029 | - coords = read_coords_32(&des); |
1030 | -} |
1031 | +PlayerCommand (0, des.unsigned_8()), |
1032 | + coords(read_coords_32(&des)) |
1033 | +{} |
1034 | |
1035 | void CmdBuildFlag::execute (Game & game) |
1036 | { |
1037 | @@ -339,17 +338,16 @@ |
1038 | {} |
1039 | |
1040 | CmdBuildRoad::CmdBuildRoad (StreamRead & des) : |
1041 | -PlayerCommand (0, des.unsigned_8()) |
1042 | +PlayerCommand (0, des.unsigned_8()), |
1043 | + // We cannot completely deserialize the path here because we don't have a Map |
1044 | + path(nullptr), |
1045 | + start(read_coords_32(&des)), |
1046 | + nsteps(des.unsigned_16()), |
1047 | + steps(new char[nsteps]) |
1048 | { |
1049 | - start = read_coords_32(&des); |
1050 | - nsteps = des.unsigned_16(); |
1051 | - |
1052 | - // we cannot completely deserialize the path here because we don't have a Map |
1053 | - path = nullptr; |
1054 | - steps = new char[nsteps]; |
1055 | - |
1056 | - for (Path::StepVector::size_type i = 0; i < nsteps; ++i) |
1057 | + for (Path::StepVector::size_type i = 0; i < nsteps; ++i) { |
1058 | steps[i] = des.unsigned_8(); |
1059 | + } |
1060 | } |
1061 | |
1062 | CmdBuildRoad::~CmdBuildRoad () |
1063 | |
1064 | === modified file 'src/logic/playercommand.h' |
1065 | --- src/logic/playercommand.h 2016-03-02 17:13:06 +0000 |
1066 | +++ src/logic/playercommand.h 2016-07-24 20:00:22 +0000 |
1067 | @@ -94,7 +94,7 @@ |
1068 | CmdBuild |
1069 | (const uint32_t init_duetime, |
1070 | const int32_t p, |
1071 | - const Coords c, |
1072 | + const Coords& c, |
1073 | const DescriptionIndex i) |
1074 | : PlayerCommand(init_duetime, p), coords(c), bi(i) |
1075 | {} |
1076 | @@ -116,7 +116,7 @@ |
1077 | |
1078 | struct CmdBuildFlag:public PlayerCommand { |
1079 | CmdBuildFlag() : PlayerCommand() {} // For savegame loading |
1080 | - CmdBuildFlag (const uint32_t t, const int32_t p, const Coords c) : |
1081 | + CmdBuildFlag (const uint32_t t, const int32_t p, const Coords& c) : |
1082 | PlayerCommand(t, p), coords(c) |
1083 | {} |
1084 | |
1085 | @@ -683,7 +683,7 @@ |
1086 | struct PlayerMessageCommand : public PlayerCommand { |
1087 | PlayerMessageCommand () : PlayerCommand() {} // for savegames |
1088 | PlayerMessageCommand |
1089 | - (const uint32_t t, const PlayerNumber p, const MessageId i) |
1090 | + (const uint32_t t, const PlayerNumber p, const MessageId& i) |
1091 | : PlayerCommand(t, p), message_id_(i) |
1092 | {} |
1093 | |
1094 | @@ -701,7 +701,7 @@ |
1095 | struct CmdMessageSetStatusRead : public PlayerMessageCommand { |
1096 | CmdMessageSetStatusRead () : PlayerMessageCommand() {} |
1097 | CmdMessageSetStatusRead |
1098 | - (const uint32_t t, const PlayerNumber p, const MessageId i) |
1099 | + (const uint32_t t, const PlayerNumber p, const MessageId& i) |
1100 | : PlayerMessageCommand(t, p, i) |
1101 | {} |
1102 | |
1103 | @@ -716,7 +716,7 @@ |
1104 | struct CmdMessageSetStatusArchived : public PlayerMessageCommand { |
1105 | CmdMessageSetStatusArchived () : PlayerMessageCommand() {} |
1106 | CmdMessageSetStatusArchived |
1107 | - (const uint32_t t, const PlayerNumber p, const MessageId i) |
1108 | + (const uint32_t t, const PlayerNumber p, const MessageId& i) |
1109 | : PlayerMessageCommand(t, p, i) |
1110 | {} |
1111 | |
1112 | |
1113 | === modified file 'src/logic/single_player_game_settings_provider.cc' |
1114 | --- src/logic/single_player_game_settings_provider.cc 2016-04-01 07:50:48 +0000 |
1115 | +++ src/logic/single_player_game_settings_provider.cc 2016-07-24 20:00:22 +0000 |
1116 | @@ -210,7 +210,7 @@ |
1117 | s.players[number].name = name; |
1118 | } |
1119 | |
1120 | -void SinglePlayerGameSettingsProvider::set_player(uint8_t const number, PlayerSettings const ps) { |
1121 | +void SinglePlayerGameSettingsProvider::set_player(uint8_t const number, const PlayerSettings& ps) { |
1122 | if (number < s.players.size()) |
1123 | s.players[number] = ps; |
1124 | } |
1125 | |
1126 | === modified file 'src/logic/single_player_game_settings_provider.h' |
1127 | --- src/logic/single_player_game_settings_provider.h 2015-03-01 09:21:20 +0000 |
1128 | +++ src/logic/single_player_game_settings_provider.h 2016-07-24 20:00:22 +0000 |
1129 | @@ -53,7 +53,7 @@ |
1130 | void set_player_closeable(uint8_t, bool) override; |
1131 | void set_player_shared(uint8_t, uint8_t) override; |
1132 | void set_player_name(uint8_t const number, const std::string & name) override; |
1133 | - void set_player(uint8_t const number, PlayerSettings const ps) override; |
1134 | + void set_player(uint8_t const number, const PlayerSettings& ps) override; |
1135 | void set_player_number(uint8_t const number) override; |
1136 | |
1137 | std::string get_win_condition_script() override; |
1138 | |
1139 | === modified file 'src/logic/widelands_geometry.h' |
1140 | --- src/logic/widelands_geometry.h 2016-02-18 17:28:50 +0000 |
1141 | +++ src/logic/widelands_geometry.h 2016-07-24 20:00:22 +0000 |
1142 | @@ -155,10 +155,10 @@ |
1143 | : node(Node), triangle(Triangle) |
1144 | {} |
1145 | |
1146 | - bool operator== (NodeAndTriangle<> const other) const { |
1147 | + bool operator== (const NodeAndTriangle<>& other) const { |
1148 | return node == other.node && triangle == other.triangle; |
1149 | } |
1150 | - bool operator!= (NodeAndTriangle<> const other) const { |
1151 | + bool operator!= (const NodeAndTriangle<>& other) const { |
1152 | return !(*this == other); |
1153 | } |
1154 | |
1155 | |
1156 | === modified file 'src/logic/widelands_geometry_io.cc' |
1157 | --- src/logic/widelands_geometry_io.cc 2015-03-01 09:21:20 +0000 |
1158 | +++ src/logic/widelands_geometry_io.cc 2016-07-24 20:00:22 +0000 |
1159 | @@ -100,7 +100,7 @@ |
1160 | wr->unsigned_16(c.y); |
1161 | } |
1162 | |
1163 | -void write_area_48(StreamWrite* wr, Area<Coords, uint16_t> const area) { |
1164 | +void write_area_48(StreamWrite* wr, const Area<Coords, uint16_t>& area) { |
1165 | write_coords_32(wr, area); |
1166 | wr->unsigned_16(area.radius); |
1167 | } |
1168 | |
1169 | === modified file 'src/logic/widelands_geometry_io.h' |
1170 | --- src/logic/widelands_geometry_io.h 2015-03-01 09:21:20 +0000 |
1171 | +++ src/logic/widelands_geometry_io.h 2016-07-24 20:00:22 +0000 |
1172 | @@ -106,7 +106,7 @@ |
1173 | void write_coords_32(StreamWrite* wr, const Coords& c); |
1174 | |
1175 | // Writes 'area' to 'wr'. |
1176 | -void write_area_48(StreamWrite* wr, Area<Coords, uint16_t> const area); |
1177 | +void write_area_48(StreamWrite* wr, const Area<Coords, uint16_t>& area); |
1178 | |
1179 | } // namespace Widelands |
1180 | |
1181 | |
1182 | === modified file 'src/map_io/map_bob_packet.cc' |
1183 | --- src/map_io/map_bob_packet.cc 2015-11-28 22:29:26 +0000 |
1184 | +++ src/map_io/map_bob_packet.cc 2016-07-24 20:00:22 +0000 |
1185 | @@ -34,7 +34,7 @@ |
1186 | void MapBobPacket::read_bob(FileRead& fr, |
1187 | EditorGameBase& egbase, |
1188 | MapObjectLoader&, |
1189 | - Coords const coords, |
1190 | + const Coords& coords, |
1191 | const WorldLegacyLookupTable& lookup_table) { |
1192 | const std::string owner = fr.c_string(); |
1193 | char const* const read_name = fr.c_string(); |
1194 | |
1195 | === modified file 'src/map_io/map_bob_packet.h' |
1196 | --- src/map_io/map_bob_packet.h 2015-09-18 18:17:01 +0000 |
1197 | +++ src/map_io/map_bob_packet.h 2016-07-24 20:00:22 +0000 |
1198 | @@ -43,7 +43,7 @@ |
1199 | void read_bob(FileRead&, |
1200 | EditorGameBase&, |
1201 | MapObjectLoader&, |
1202 | - Coords, |
1203 | + const Coords&, |
1204 | const WorldLegacyLookupTable& lookup_table); |
1205 | }; |
1206 | } |
1207 | |
1208 | === modified file 'src/map_io/map_buildingdata_packet.cc' |
1209 | --- src/map_io/map_buildingdata_packet.cc 2016-04-11 06:45:29 +0000 |
1210 | +++ src/map_io/map_buildingdata_packet.cc 2016-07-24 20:00:22 +0000 |
1211 | @@ -1308,16 +1308,12 @@ |
1212 | ("Save TrainingSite: Failure counter has ridiculously many entries! (%u)\n", |
1213 | static_cast<uint16_t>(trainingsite.training_failure_count_.size())); |
1214 | fw.unsigned_16(static_cast<uint16_t> (trainingsite.training_failure_count_.size())); |
1215 | - for |
1216 | - (TrainingSite::TrainFailCount::const_iterator i = trainingsite.training_failure_count_.begin(); |
1217 | - i != trainingsite.training_failure_count_.end(); i++) |
1218 | - { |
1219 | - fw.unsigned_8(static_cast<uint8_t>(i->first.first)); |
1220 | - fw.unsigned_16(i->first.second); |
1221 | - fw.unsigned_16(i->second.first); |
1222 | - fw.unsigned_8(i->second.second); |
1223 | + for (const auto& fail_and_presence : trainingsite.training_failure_count_) { |
1224 | + fw.unsigned_8(static_cast<uint8_t>(fail_and_presence.first.first)); |
1225 | + fw.unsigned_16(fail_and_presence.first.second); |
1226 | + fw.unsigned_16(fail_and_presence.second.first); |
1227 | + fw.unsigned_8(fail_and_presence.second.second); |
1228 | } |
1229 | - |
1230 | // DONE |
1231 | } |
1232 | } |
1233 | |
1234 | === modified file 'src/map_io/map_message_saver.h' |
1235 | --- src/map_io/map_message_saver.h 2014-09-19 12:54:54 +0000 |
1236 | +++ src/map_io/map_message_saver.h 2016-07-24 20:00:22 +0000 |
1237 | @@ -41,11 +41,11 @@ |
1238 | /// that will be used as the id of the message when the game is loaded. |
1239 | struct MapMessageSaver : private std::map<MessageId, MessageId> { |
1240 | MapMessageSaver() : counter(0) {} |
1241 | - void add(MessageId const id) { |
1242 | + void add(const MessageId& id) { |
1243 | assert(find(id) == end()); |
1244 | insert(std::pair<MessageId, MessageId>(id, ++counter)); |
1245 | } |
1246 | - MessageId operator[](MessageId const id) const { |
1247 | + MessageId operator[](const MessageId& id) const { |
1248 | return find(id) != end() ? find(id)->second : MessageId::null(); |
1249 | } |
1250 | private: |
1251 | |
1252 | === modified file 'src/network/netclient.cc' |
1253 | --- src/network/netclient.cc 2016-05-14 18:18:51 +0000 |
1254 | +++ src/network/netclient.cc 2016-07-24 20:00:22 +0000 |
1255 | @@ -417,7 +417,7 @@ |
1256 | // launchgame-menu, here properly should be a set_name function |
1257 | } |
1258 | |
1259 | -void NetClient::set_player(uint8_t, PlayerSettings) |
1260 | +void NetClient::set_player(uint8_t, const PlayerSettings&) |
1261 | { |
1262 | // do nothing here - the request for a positionchange is send in |
1263 | // set_player_number(uint8_t) to the host. |
1264 | |
1265 | === modified file 'src/network/netclient.h' |
1266 | --- src/network/netclient.h 2016-05-14 18:18:51 +0000 |
1267 | +++ src/network/netclient.h 2016-07-24 20:00:22 +0000 |
1268 | @@ -86,7 +86,7 @@ |
1269 | (uint8_t number, const std::string & tribe, bool const random_tribe = false) override; |
1270 | void set_player_init (uint8_t number, uint8_t index) override; |
1271 | void set_player_name (uint8_t number, const std::string & name) override; |
1272 | - void set_player (uint8_t number, PlayerSettings ps) override; |
1273 | + void set_player (uint8_t number, const PlayerSettings& ps) override; |
1274 | void set_player_number (uint8_t number) override; |
1275 | void set_player_team (uint8_t number, Widelands::TeamNumber team) override; |
1276 | void set_player_closeable(uint8_t number, bool closeable) override; |
1277 | |
1278 | === modified file 'src/network/nethost.cc' |
1279 | --- src/network/nethost.cc 2016-05-15 07:48:41 +0000 |
1280 | +++ src/network/nethost.cc 2016-07-24 20:00:22 +0000 |
1281 | @@ -266,7 +266,7 @@ |
1282 | host_->set_player_name(number, name); |
1283 | } |
1284 | |
1285 | - void set_player(uint8_t const number, PlayerSettings const ps) override { |
1286 | + void set_player(uint8_t const number, const PlayerSettings& ps) override { |
1287 | if (number >= host_->settings().players.size()) |
1288 | return; |
1289 | host_->set_player(number, ps); |
1290 | @@ -1409,7 +1409,7 @@ |
1291 | } |
1292 | |
1293 | |
1294 | -void NetHost::set_player(uint8_t const number, PlayerSettings const ps) |
1295 | +void NetHost::set_player(uint8_t const number, const PlayerSettings& ps) |
1296 | { |
1297 | if (number >= d->settings.players.size()) |
1298 | return; |
1299 | |
1300 | === modified file 'src/network/nethost.h' |
1301 | --- src/network/nethost.h 2016-05-14 18:18:51 +0000 |
1302 | +++ src/network/nethost.h 2016-07-24 20:00:22 +0000 |
1303 | @@ -71,7 +71,7 @@ |
1304 | void set_player_init (uint8_t number, uint8_t index); |
1305 | void set_player_ai (uint8_t number, const std::string & name, bool const random_ai = false); |
1306 | void set_player_name (uint8_t number, const std::string & name); |
1307 | - void set_player (uint8_t number, PlayerSettings); |
1308 | + void set_player (uint8_t number, const PlayerSettings&); |
1309 | void set_player_number (uint8_t number); |
1310 | void set_player_team (uint8_t number, Widelands::TeamNumber team); |
1311 | void set_player_closeable(uint8_t number, bool closeable); |
Continuous integration builds have changed state:
Travis build 1210. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 147045836. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ bug_986611_ cppcheck_ performance_ logic-1049.
Appveyor build 1049. State: failed. Details: https:/