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

Proposed by cghislai on 2013-07-28
Status: Merged
Merged at revision: 6694
Proposed branch: lp:~widelands-dev/widelands/debug_window
Merge into: lp:widelands
Diff against target: 42 lines (+28/-3)
1 file modified
src/wui/game_debug_ui.cc (+28/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/debug_window
Reviewer Review Type Date Requested Status
SirVer 2013-07-28 Approve on 2013-08-03
Review via email: mp+177282@code.launchpad.net

Description of the change

The bob list in debug window was cleared and fileld each frame. It was not possible to scroll down. Even by saving the scroll position before the clearing and restoring after it, it wasn't working correctly.

With this change, the displayed list is parsed. If an item is found in the list of bob at that position, nothing is done. Otherwise, it is removed. The remaining bobs are added to the list.

It involves two nested loops. I couldn't figure out a better way and thought that, since it won't be released, it is better than a non working list. Furthermore, I didn't experience any slowdowns, even with hundreds of bobs.

To post a comment you must log in.
SirVer (sirver) wrote :

Seems fine to me. This is really only for debugging. Merging this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/game_debug_ui.cc'
2--- src/wui/game_debug_ui.cc 2013-07-26 20:19:36 +0000
3+++ src/wui/game_debug_ui.cc 2013-07-28 16:24:27 +0000
4@@ -399,10 +399,35 @@
5
6 // Bobs information
7 std::vector<Widelands::Bob *> bobs;
8-
9- m_ui_bobs.clear();
10-
11 m_map.find_bobs(Widelands::Area<Widelands::FCoords>(m_coords, 0), &bobs);
12+
13+ // Do not clear the list. Instead parse all bobs and sync lists
14+ for (uint32_t idx = 0; idx < m_ui_bobs.size(); idx++) {
15+ Widelands::Map_Object* mo =
16+ ibase().egbase().objects().get_object(m_ui_bobs[idx]);
17+ bool toremove = false;
18+ std::vector<Widelands::Bob *>::iterator removeIt;
19+ // Nested loop :(
20+ container_iterate(std::vector<Widelands::Bob *>, bobs, j) {
21+ if ((*j.current) && mo
22+ && (*j.current)->serial() == mo->serial()) {
23+ // Remove from the bob list if we already
24+ // have it in our list
25+ toremove = true;
26+ removeIt = j.current;
27+ break;
28+ }
29+ }
30+ if (toremove) {
31+ bobs.erase(removeIt);
32+ continue;
33+ }
34+ // Remove from our list if its not in the bobs
35+ // list, or if it doesn't seem to exist anymore
36+ m_ui_bobs.remove(idx);
37+ idx--; //reiter the same index
38+ }
39+ // Add remaining
40 container_iterate_const(std::vector<Widelands::Bob *>, bobs, j) {
41 snprintf
42 (buffer, sizeof(buffer),