Merge lp:~widelands-dev/widelands/bug-1830526-soldier-walk-anims into lp:widelands

Proposed by Benedikt Straub
Status: Merged
Merged at revision: 9128
Proposed branch: lp:~widelands-dev/widelands/bug-1830526-soldier-walk-anims
Merge into: lp:widelands
Diff against target: 78 lines (+18/-7)
3 files modified
src/logic/map_objects/tribes/soldier.cc (+10/-5)
src/logic/map_objects/tribes/soldier.h (+7/-1)
src/logic/map_objects/tribes/worker_descr.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1830526-soldier-walk-anims
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+367939@code.launchpad.net

Commit message

Cache soldiersĀ“ directional animations as unique_ptr to prevent memory leaks

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

Code LGTM - just 1 nit for a variable name

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

Done some testing - it's gone :)

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5066. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/537427196.
Appveyor build 4846. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1830526_soldier_walk_anims-4846.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/logic/map_objects/tribes/soldier.cc'
--- src/logic/map_objects/tribes/soldier.cc 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/tribes/soldier.cc 2019-05-26 12:22:03 +0000
@@ -280,18 +280,23 @@
280}280}
281281
282const DirAnimations& SoldierDescr::get_right_walk_anims(bool const ware,282const DirAnimations& SoldierDescr::get_right_walk_anims(bool const ware,
283 const Worker* worker) const {283 Worker* worker) const {
284 const Soldier* soldier = dynamic_cast<const Soldier*>(worker);284 Soldier* soldier = dynamic_cast<Soldier*>(worker);
285 if (!soldier) {285 if (!soldier) {
286 return WorkerDescr::get_right_walk_anims(ware, worker);286 return WorkerDescr::get_right_walk_anims(ware, worker);
287 }287 }
288 DirAnimations* anim = new DirAnimations();288 auto& cache = soldier->get_walking_animations_cache();
289 if (cache.first && cache.first->matches(soldier)) {
290 return *cache.second;
291 }
289 for (const auto& pair : walk_name_) {292 for (const auto& pair : walk_name_) {
290 if (pair.first->matches(soldier)) {293 if (pair.first->matches(soldier)) {
294 cache.first.reset(new SoldierLevelRange(*pair.first));
295 cache.second.reset(new DirAnimations());
291 for (uint8_t dir = 1; dir <= 6; ++dir) {296 for (uint8_t dir = 1; dir <= 6; ++dir) {
292 anim->set_animation(dir, get_animation(pair.second.at(dir), worker));297 cache.second->set_animation(dir, get_animation(pair.second.at(dir), worker));
293 }298 }
294 return *anim;299 return *cache.second;
295 }300 }
296 }301 }
297 throw GameDataError(302 throw GameDataError(
298303
=== modified file 'src/logic/map_objects/tribes/soldier.h'
--- src/logic/map_objects/tribes/soldier.h 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/tribes/soldier.h 2019-05-26 12:22:03 +0000
@@ -133,7 +133,7 @@
133133
134 uint32_t get_rand_anim(Game& game, const std::string& name, const Soldier* soldier) const;134 uint32_t get_rand_anim(Game& game, const std::string& name, const Soldier* soldier) const;
135135
136 const DirAnimations& get_right_walk_anims(bool const ware, const Worker* w) const override;136 const DirAnimations& get_right_walk_anims(bool const ware, Worker* w) const override;
137 uint32_t get_animation(const std::string& anim, const MapObject* mo = nullptr) const override;137 uint32_t get_animation(const std::string& anim, const MapObject* mo = nullptr) const override;
138138
139protected:139protected:
@@ -312,6 +312,10 @@
312 void start_task_move_in_battle(Game&, CombatWalkingDir);312 void start_task_move_in_battle(Game&, CombatWalkingDir);
313 void start_task_die(Game&);313 void start_task_die(Game&);
314314
315 std::pair<std::unique_ptr<SoldierLevelRange>, std::unique_ptr<DirAnimations>>& get_walking_animations_cache() {
316 return walking_animations_cache_;
317 }
318
315private:319private:
316 void attack_update(Game&, State&);320 void attack_update(Game&, State&);
317 void attack_pop(Game&, State&);321 void attack_pop(Game&, State&);
@@ -363,6 +367,8 @@
363 */367 */
364 Battle* battle_;368 Battle* battle_;
365369
370 std::pair<std::unique_ptr<SoldierLevelRange>, std::unique_ptr<DirAnimations>> walking_animations_cache_;
371
366 static constexpr uint8_t kSoldierHealthBarWidth = 13;372 static constexpr uint8_t kSoldierHealthBarWidth = 13;
367373
368 /// Number of consecutive blocked signals until the soldiers are considered permanently stuck374 /// Number of consecutive blocked signals until the soldiers are considered permanently stuck
369375
=== modified file 'src/logic/map_objects/tribes/worker_descr.h'
--- src/logic/map_objects/tribes/worker_descr.h 2019-05-19 09:21:11 +0000
+++ src/logic/map_objects/tribes/worker_descr.h 2019-05-26 12:22:03 +0000
@@ -87,7 +87,7 @@
87 default_target_quantity_ = 1;87 default_target_quantity_ = 1;
88 }88 }
8989
90 virtual const DirAnimations& get_right_walk_anims(bool const carries_ware, const Worker*) const {90 virtual const DirAnimations& get_right_walk_anims(bool const carries_ware, Worker*) const {
91 return carries_ware ? walkload_anims_ : walk_anims_;91 return carries_ware ? walkload_anims_ : walk_anims_;
92 }92 }
93 WorkerProgram const* get_program(const std::string&) const;93 WorkerProgram const* get_program(const std::string&) const;

Subscribers

People subscribed via source and target branches

to status/vote changes: