URL:
  <http://gna.org/patch/?1134>

                 Summary: Optimize animations for 1.6.1
                 Project: Battle for Wesnoth
            Submitted by: alink
            Submitted on: Thursday 03/19/2009 at 22:22
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

1.6 use a lot of cpu or has a low framerate when there is many units on the
screen or when decorative animations plays(idle, standing or map). This is
mainly due to the fact that standing animations and base frame are now
allowed to not fit in a hex, which is rarely used, and almost never for base
frame. The problem is that we now always use the 72x72 rectangle and thus
consider that it overlaps on the 4 east and west hexes. This cause two
performance hits:
- A small standing animation always refresh 5 hexes, when only one is needed.
This make the standing anim almost never welcome on weaker system and make the
second problem worse.
- Each time an hex is refreshed, any unit adjacent to it will need a refresh
too and this may cause a chain reaction. Worse, these chain reactions also
happen between units only adjacent to the same lateral empty hex.

This is mainly a problem for big pack of units around a village (with a
flag), which is a common situation. But in general, a screen with a dense
network of units will need an almost complete redraw at the first little
move. Cutting all anims will help, but even mouse move or fight stay
expensive. To check these invalidations, use the :sunset command.

Here is a patch for this. The idea is to add a key 'in_hex' in standing
animation WML, to tell the engine that the sprite fit in a hex, so it can
optimize the redraw by preventing the chain reaction effect and minimizing
the cost of a small standing animation. We consider the in_hex is always
false by default, and add it in all standing anim of mainline (firring in a a
hex). This will optimize the mainline gameplay without breaking compatibility
or UMC. They can use the key too if they want the optimization for their
units. There is also a bit of work to check which sprite fit in a hex, but
most do and it's simple to verify.

The performance improvement depends of the number of units on screen and the
anim option used. But it's often important. On my system, this can go from
100% to 20% cpu usage and double the framerate.

I wanted to work on these performance problems on 1.7, underestimating their
importance in 1.6 and thinking about a clean a powerful optimization. But a
last minute talk with zookeeper complaining about the framerate reminded me
this trick to do it relatively easily.

PS: The patch is a bit rough and I didn't check all the details. It seems to
work fine, but I want some opinion about it before putting more work and
test. The main point is to show the idea, how and where to add it in WML is
less important.
The code change is minimal, but not the data change. I only changed few units
and attached a savegame using a pack of them. So, to be clear, you need to
apply both patches to have an optimization and this will only concern the 4
unit types involved.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Thursday 03/19/2009 at 22:22  Name: in_hex_src.patch  Size: 8kB   By:
alink

<http://gna.org/patch/download.php?file_id=5461>
-------------------------------------------------------
Date: Thursday 03/19/2009 at 22:22  Name: in_hex_data.patch  Size: 2kB   By:
alink

<http://gna.org/patch/download.php?file_id=5462>
-------------------------------------------------------
Date: Thursday 03/19/2009 at 22:22  Name: packofunits  Size: 277kB   By:
alink

<http://gna.org/patch/download.php?file_id=5463>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?1134>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to