Merge lp:~qcumber-some/widelands/animations into lp:widelands

Proposed by Jens Beyer
Status: Merged
Merged at revision: 6426
Proposed branch: lp:~qcumber-some/widelands/animations
Merge into: lp:widelands
Diff against target: 99 lines (+20/-25)
2 files modified
src/graphic/graphic.cc (+16/-22)
src/graphic/graphic.h (+4/-3)
To merge this branch: bzr merge lp:~qcumber-some/widelands/animations
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+104138@code.launchpad.net

Description of the change

I'm feeling I should add a review request to further discuss this branch, instead of discussing it in the bug.
This is about bug #535806 and is an attempt to use on-demand loading of the animations, instead of preloading them upon game start.

Please note that this is not a 'merge request' per se, but a review request on the technology used and the possible outcomes. The branch in its current state is not up for merge yet.

To post a comment you must log in.
Revision history for this message
Gabriel Margiani (gamag) wrote :

I tested your branch and I am very impressed by the short loading time it takes.
If the world animations would be preloaded and only the tribes "on the fly", it
seems to me to be a very good solution for the loading-animations-time problem!

Revision history for this message
Jens Beyer (qcumber-some) wrote :

> I tested your branch and I am very impressed by the short loading time it
> takes.
> If the world animations would be preloaded and only the tribes "on the fly",
> it
> seems to me to be a very good solution for the loading-animations-time
> problem!

This would probably not be so easy since the animations are not "tagged" and there is no way to find out which animation is which.

On the other hand, why do you suggest preloading the world? From my point of view, this would not be necessary, this is fast enough right now.

Revision history for this message
Gabriel Margiani (gamag) wrote :

After autosave is initialized and the HQ is created, it takes, on my machine, approx. 3 sec to show the game. That's not much, but a little confusing because you heard already the sound of the new HQ Massage. Seems a little like windows booting :)
Because of that I thought of preloading the world.
But your right, I didn't thought of how to implement this and it could be a problem to separate world and tribe animations. So 3 sec. aren't worse enough to make loading more complex.

Revision history for this message
Tino (tino79) wrote :

I like it very much, loading times are and feel much reduced on windows.
I've uploaded a win32 build with these changes:
http://widelands.8-schuss.de/Widelands-bzr6373-nomusic-ondemandload-win32.exe

Revision history for this message
Jens Beyer (qcumber-some) wrote :

The animations which are loading after creating a map are all animations which are visible, except water animations. For example: Trees, animals, and the visible starting buildings (HQ, road and flag). Nothing else.
I'm currently trying to find a way (more theoretically) how to achieve a preloading of the visible animations before showing them, but I've not yet been successful ;-)

Revision history for this message
Chuck Wilder (chuckw20) wrote :

@Tino - Thanks as always for the Windows build. I started an upgrade from Ubuntu 11.10 to 12.04 LTS before testing a linux build of Jens' branch. That was yesterday afternoon. The upgrade is STILL running. :-| Sorry to go slightly off-topic. I'm just looking for a shoulder to cry on.

Thanks again. Now I can at least see for myself what everyone is talking about. :)

Re: tagging the graphics files - If it weren't for the initiative to pursue stacked animations, I would be happy to start tagging the graphics files. It makes a lot of sense from a purely organizational aspect.

Revision history for this message
Jens Beyer (qcumber-some) wrote :

Sorry this was not merged but I've unfortunately overwriten my branch with trunk.

I'm setting this back to Review requested once I recreated the changes.

Revision history for this message
Jens Beyer (qcumber-some) wrote :

It's up to date again. Sorry for the inconvenience...

Revision history for this message
Jens Beyer (qcumber-some) wrote :

I did some more coding, and made the system load the files at the beginning, but letting the Main thread render the animations. This revealed (at least for my system) that the slow part of this task is not reading the files from disk, but the rendering task itself.

Unfortunately, with the current architecture, there is no alternative to rendering the images in the main thread, as OpenGL is not thread-safe and you should not switch the OpenGL context between threads.

I don't know about the Windows experience. But if someone could test the following, this could be confirmed.

* Download one of Tino's patched executables.
* Switch off Antivirus protection.
* Start game, load a savegame with lots of things happening, play a bit, observe 'hanging' when you scroll quickly to parts of the map where new animations need to be loaded.
* Quit the game, load the same savegame.

If you still experience 'hangs' at the same points like before, this would be a good sign that the rendering time is the culprit, not the file loading time itself.

Revision history for this message
Nasenbaer (nasenbaer) wrote :

I merged your branch in rev.6426 into trunk. Thank you Jens for this improvement :)!!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/graphic/graphic.cc'
2--- src/graphic/graphic.cc 2012-03-09 16:57:20 +0000
3+++ src/graphic/graphic.cc 2012-06-30 20:10:27 +0000
4@@ -1066,32 +1066,25 @@
5 void Graphic::load_animations(UI::ProgressWindow & loader_ui) {
6 assert(m_animations.empty());
7
8- clock_t start = clock();
9-
10- const std::string step_description = _("Loading animations: %d%% complete");
11- uint32_t last_shown = 100;
12 const uint32_t nr_animations = g_anim.get_nranimations();
13- for (uint32_t id = 0; id < nr_animations;) {
14- const uint32_t percent = 100 * id / nr_animations;
15- if (percent != last_shown) {
16- last_shown = percent;
17- loader_ui.stepf(step_description.c_str(), percent);
18- }
19- ++id;
20- m_animations.push_back(new AnimationGfx(g_anim.get_animation(id)));
21- }
22- loader_ui.step(std::string());
23+ m_animations.reserve(nr_animations);
24+}
25
26- clock_t end = clock();
27- printf
28- ("load_animations took %f seconds\n",
29- (float(end - start) / CLOCKS_PER_SEC));
30+void Graphic::ensure_animation_loaded(uint32_t const anim) {
31+ if (anim >= m_animations.size()) {
32+ m_animations.resize(anim + 1);
33+ }
34+ if (!m_animations.at(anim - 1))
35+ {
36+ log("Loading animation %i\n", anim);
37+ m_animations.at(anim - 1) = new AnimationGfx(g_anim.get_animation(anim));
38+ }
39 }
40
41 /**
42 * Return the number of frames in this animation
43 */
44-AnimationGfx::Index Graphic::nr_frames(const uint32_t anim) const
45+AnimationGfx::Index Graphic::nr_frames(const uint32_t anim)
46 {
47 return get_animation(anim)->nr_frames();
48 }
49@@ -1100,7 +1093,7 @@
50 * writes the size of an animation frame to w and h
51 */
52 void Graphic::get_animation_size
53- (uint32_t const anim, uint32_t const time, uint32_t & w, uint32_t & h) const
54+ (uint32_t const anim, uint32_t const time, uint32_t & w, uint32_t & h)
55 {
56 AnimationData const * const data = g_anim.get_animation(anim);
57 AnimationGfx const * const gfx = get_animation(anim);
58@@ -1156,11 +1149,12 @@
59 * @param anim the number of the animation
60 * @return the AnimationGfs object of the given number
61 */
62-AnimationGfx * Graphic::get_animation(uint32_t const anim) const
63+AnimationGfx * Graphic::get_animation(uint32_t const anim)
64 {
65- if (!anim || anim > m_animations.size())
66+ if (!anim)
67 return 0;
68
69+ ensure_animation_loaded(anim);
70 return m_animations[anim - 1];
71 }
72
73
74=== modified file 'src/graphic/graphic.h'
75--- src/graphic/graphic.h 2012-02-21 13:42:13 +0000
76+++ src/graphic/graphic.h 2012-06-30 20:10:27 +0000
77@@ -178,18 +178,19 @@
78 void reset_texture_animation_reminder();
79
80 void load_animations(UI::ProgressWindow & loader_ui);
81- AnimationGfx::Index nr_frames(uint32_t const anim = 0) const;
82+ void ensure_animation_loaded(uint32_t anim);
83+ AnimationGfx::Index nr_frames(uint32_t const anim = 0);
84 uint32_t get_animation_frametime(uint32_t anim) const;
85 void get_animation_size
86 (const uint32_t anim,
87 const uint32_t time,
88 uint32_t & w,
89 uint32_t & h)
90- const;
91+ ;
92
93 void screenshot(const char & fname) const;
94 Texture * get_maptexture_data(uint32_t id);
95- AnimationGfx * get_animation(uint32_t) const;
96+ AnimationGfx * get_animation(uint32_t);
97
98 void set_world(std::string);
99 PictureID get_road_texture(int32_t roadtex);

Subscribers

People subscribed via source and target branches

to status/vote changes: