Multi-tile animation for objects / CB 159

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Multi-tile animation for objects / CB 159

Post by michael blunck »

I have problems getting multi-tile animations for objects to work, and I can´t figure out if it´s a bug or depending on incomprehensible or wrong documentation. That´s why I´m posting it here.

The problem is with synchronising animation on different tiles of an object, and in fact I suppose that animations are only running for one tile of my 2-tile objects, for whatever reason.

First, let´s take a look into the specs:
action0 objects wrote: (3) - Setting this flag [bit6 - Object has animation] will allow the object's animation counter to be increased, must be set if you plan to make use of animations. Like stations you must enable animation on a per tile basis by means of the "built tile" trigger and callback 159.
The second sentence makes no sense to me. It suggests that animations won´t run on tiles were you don´t "activate" it by means of the "built tile trigger and callback 159" recipe. But IMO this interpretation would be a contradiction to what the spec says in the following:
action0 objects wrote: Since you can't have properties for individual object tiles, this property applies for every tile of the object. If you don't want to animate some tiles ...
I.e., you´ll have to "suppress" animations for tiles you don´t want to be animated, precisely because animations are run on *all* tiles, even for those you don´t want!

Suppressing "unwanted" animation is usually being done by using var40 (get tile position inside object) and returning 0xFD for CB 159.

So far so good.

Now, w/r to the original problem, Yexo and frosch told me (in bugs.openttd.org):
Yexo wrote: You should also enable the animation callback for the tiles that are updated via var63.
The actual return value from the animation callback doesn't matter, as long as it's run the
tile will be marked dirty (and therefor redrawn).
frosch wrote: In this case CB 159 has to return FE on construction for all tiles which depend on some animation state.
But this is what I don´t understand at all. I *am* using CB159 to start the animation depending on some random value, and I think in this particular way the animation is started for *all* the tiles:

Code: Select all

// start animation if on last frame (1/5 chance)
2030 * 0 02 0f 14 81 10 00 FF 01
	01 80 00 33  // start on frame1 
	fd 80     // do nothing

2031 * 0 02 0f 15 81 43 00 FF 01
	14 00 00 00   // first frame, start
	fd 80 

[...]

2036 * 0 02 0f 3c 85 0C 00 FF FF 02
	15 00 59 01  59 01	// start animation
	19 00 58 01  58 01	// handle anim frames
	12 00		// graphics
  

2037 * 0 03 0f 01 13 01
	ff  13 00  
	3c 00
As can be seen, there´s no restriction to a certain tile for CB159. From what I understand this means that CB159 is run for *both* tiles, shouldn´t it?

I.e., from my understanding of nfo, something like:

Code: Select all

2029 * 0 02 0f 1e 81 40 10 FF 01 
	01 80 00 00 // back
	fe 80	  // front

// start animation if on last frame (1/5 chance)
2030 * 0 02 0f 14 81 10 00 FF 01
	1e 00 00 33 // explicitly check which tile we are at
	fd 80	 // do nothing
I.e., checking explicitly for the other tile and returning 0xFE (start animation with its current frame) would make no sense to me at all. Since when do we have to raise a restriction to make something work in a varAction2 chain?

And even with the code above, it´s not possible getting the animation to run for a second tile, which can be easily verified from the inspection window.

Moreover, I can´t understand how it should be possible to return 0xFE for CB159 "on construction", because there doesn´t seem to exist means to get that particular event for objects? At least, there´s nothing about that in the specs. [edit: this info has now been added by frosch]

So, in conclusion, I´d like to get some clarification from a developer how multi-tile animations for objects should be handled. The information given in the specs isn´t only incomprehensible but seems also be misleading in some way. (Or there´s even a bug somewhere.)

regards
Michael
Image
User avatar
Lakie
TTDPatch Developer
TTDPatch Developer
Posts: 1799
Joined: 26 May 2004 16:37
Location: Britain
Contact:

Re: Multi-tile animation for objects / CB 159

Post by Lakie »

I don't have time to have a look now, but could you also post an Action0 for us to lok at, also which game it's failing with?
The animation system was overhauled when the specifications were changed, I believe some of the older functionality operates if the Action0 isn't correctly configured causing the conflicts in the documentation.

Hopefully I'll be able to help you later,
~ Lakie
TTDpatch Developer 2005 - 2010 ~ It all started because of shortened vehicle not loading correctly, now look where I've gone with it!
Grfs coded ~ Finnish Train Set (Teaser) | Bm73 (Release 3) | Emu 680 (Release 3)| Glass Station (Release 1) | UK Roadset (Version 1.1a) | New Water Coasts (Version 7)
Pikka: "Lakie's a good coder, but before he'll add any feature to TTDP you have to convince him that you're not going to use it to destroy the world as we know it."
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Multi-tile animation for objects / CB 159

Post by michael blunck »

Lakie wrote: [...] could you also post an Action0 for us to lok at, also which game it's failing with? [...]
The object in question is defined in this way (posted over here):

Code: Select all

1977 * 0 00 0F 0e 01 13
        08 "MC05" 
        09 03 D0 
        0A 05 D0 
        0B 01 
        0C 12 // size 2 * 1
        0D 14 
        10 40 12 // NOBUILDONLAND, HASANIMATION, RANDOMBITS
        11 11 01 // 18 frames, looping 
        12 05 
        13 05 00 // BUILT, SYNCHRONIZED
        15 12 00 // CB_AFRAME, CB_TEXT 
        0E 52 b3 0a 00
        0F 08 24 0b 00
        17 02
regards
Michael
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Multi-tile animation for objects / CB 159

Post by frosch »

Property 10 bit 6 is basically a enable-callback flag. I.e. it does not start any animation; it only allows the animation to be started via some callback.

Animation must be started per tile. This part is different for all features, some start the animation automatically on construction if some action 0 bit is set and allow stopping it using the animation start/stop callbacks. However, for objects all tiles start with animation being stopped. The construction animation trigger is especially meant for this case.

So, basically:
1) If any tile is animated, you have to set the action 0 flag. This flag will do nothing on it's own. You could just as well set it unconditionally for all objects.
2) Upon construction CB 159 is called for all tiles if the "construction" animation trigger is activated in property 13. Use this to start the animation for all tiles, which shall be animated.
3) Unless other callbacks and animation triggers are involved, all tiles will now run the animation on their own, and actually it will run synchronously without having to use the animation frame of neighboured tiles.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Multi-tile animation for objects / CB 159

Post by michael blunck »

frosch wrote: [...]
My problem seem to be the random tile bits.

I want to start a multi-tile animation (2 tiles) by some random delay, so I´ll have to access some random counter/var.

For now, I´ve been using the random bits of some object´s tile. Preferably, I should use the same tile (same random bits) to start the animation for both tiles. I´m doing this by accessing the object´s northern tile (see below).

Now, I´m getting aware that using those random tile bits is not a good idea, simply because the random bits accessible by var61 aren´t re-randomized if there´s neither a CB159 or CB158 being run after the initial CB159. Due to the structure of my code[*], there might be a proper initial value (1/5 chance) for starting the animation, but if the animation gets not started, there´ll be no new random bits (simply because there are none supplied by CB158), and hence the animation is never run.

There are however random bits supplied by var10 for all animation CBs, which might get used instead (that´s what I did instead), but unfortunately, this seems to result into different random bits for the two tiles, and hence a de-synchronisation of the animation.

Some questions:

- I´ve been under the impression that a CB when triggered would set new random bits, but this seems only to be the case when returning a certain value (i.e. not 0xFD)?

- How about the random bits by var10, how are they different from those by var61? It turned out that I cannot use them in this particular case, because they´re obviously different for the object tiles and hence generate animation de-syncs.

- What random variable to use instead for randomly starting (multi-tile) animations?

Other than this, the original problem is only with starting the animation by CB159 depending on a random value. I could easily change things so that the animation runs always, and only fake non-animation times by using CB158 displaying some special frames. But since the original idea was to stop the animation explicitly to get a smaller system load, yet another question arises:

- is there a difference in load between an animation stopped and started at various times, and an animation running continuously?

regards
Michael

[*]

Code: Select all

// animation scheme, same in x and y

2024 * 0 02 0f 14 81 40 30 FF 0D 1A 20 77 00 1A 20 11 0D 1A 20 88 0F 7B 10 00 FF 01 
	01 80 00 33 // 1/5 chance
	fd 80 // do nothing

2025 * 0 02 0f 15 81 43 00 FF 01
	14 00 00 00 // first frame
	fd 80 // do nothing
 
[...] 

2030 * 0 02 0f 3c 85 0C 00 FF FF 02
	15 00 59 01  59 01 // start animation
	19 00 58 01  58 01 // handle anim frames
	12 00 // graphics

2031 * 0 03 0f 01 13 01
	ff  13 00  
	3c 00
Image
User avatar
Lakie
TTDPatch Developer
TTDPatch Developer
Posts: 1799
Joined: 26 May 2004 16:37
Location: Britain
Contact:

Re: Multi-tile animation for objects / CB 159

Post by Lakie »

From memory the tile random bits are calculated upon construction, and variable 10 contains random bits generated at the time of the callback being executed, which is done once for each tile animated. (For TTDPatch that is, I'm unsure if he OpenTTD implementation differs).

~ Lakie
TTDpatch Developer 2005 - 2010 ~ It all started because of shortened vehicle not loading correctly, now look where I've gone with it!
Grfs coded ~ Finnish Train Set (Teaser) | Bm73 (Release 3) | Emu 680 (Release 3)| Glass Station (Release 1) | UK Roadset (Version 1.1a) | New Water Coasts (Version 7)
Pikka: "Lakie's a good coder, but before he'll add any feature to TTDP you have to convince him that you're not going to use it to destroy the world as we know it."
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Multi-tile animation for objects / CB 159

Post by frosch »

(Some addition to my post from yesterday: Animation is also started by CB 159 when returning a specific animation frame.)

Object random bits:
Random triggers and animation triggers are a completely different thing. Random bits can only be changed with a RandomAction2 when a random trigger occurs. However, objects have no random triggers at all. As such random bits of objects are only ever randomized on construction. There is currently no way to rerandomize them.

CB 159 gets 32 random bits in var 10. These are randomized on every call, i.e. there are no shared bits across synchronised callback 159 for the tiles of objects (like there is for stations). The random bits in var10 have no relation to any other random bits.

Personally I am in favour of changing the animation callbacks of objects and airport tiles to have 16 shared bits for animation triggers that trigger on multiple tiles.

About the load:
Yes, there is a difference between a started and a stopped animation. Normally tiles are only looked at every 256 ticks (periodic tile loop). Animated tiles are considered every tick to check whether the animation speed (property 12 resp. CB 15A) requires to set a new animation frame.
I don't think this causes a lot of trouble if only property 12 is used (esp. since there are usually not many object tiles on a map), but if the animation speed callback is used it is a big problem (esp. for industries and houses).

To give an example, the following two screenshots (of an unfinished patch) show statistics on how often callbacks are called on a 2k x 2k map with high industry density.
Game using FIRS (FIRS has basically no animation): http://devs.openttd.org/~frosch/profiler.png
Game using all ECS vectors (lots of animation): http://devs.openttd.org/~frosch/profile_ecs.png
In every cell of the table there are two numbers. The one at the top is the number of calls of the callback. The number below it is the CPU time spent on those callbacks (in some arbitrary CPU tick count unit).
These tables show, that it is basically irrelevant how complex your callback chains are, the biggest impact is whether you use the animation length callbacks or not :p
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Multi-tile animation for objects / CB 159

Post by michael blunck »

frosch wrote: Personally I am in favour of changing the animation callbacks of objects and airport tiles to have 16 shared bits for animation triggers that trigger on multiple tiles.
I´d second this. As it is now, there´s no possibility to start synchronized multi-tile animations in a random way. I could avoid the reported glitches by using the "general animation counter" (var 0A) but then multiple multi-tile animations would show the same pattern. :|

regards
Michael
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest