Author Topic: Animated Vehicles  (Read 4401 times)

0 Members and 1 Guest are viewing this topic.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Animated Vehicles
« on: February 03, 2017, 03:37:34 PM »
Just wanted to search for the earlier proposals about animated vehicles to see why it was dismissed - and did not find any. Seems odd. Since vehicles have to be redrawn while they move anyway, shouldn't it be easier for them to be animated then other graphics, without extra computation time even?

(personally, I think everything should be able to be animated. Even old games like Settlers2 had animated trees and stuff, and there is no object type I could think of without some use for animation)

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4812
  • Total likes: 191
  • Helpful: 108
  • Languages: EN, NO
Re: Animated Vehicles
« Reply #1 on: February 03, 2017, 04:28:31 PM »
I don't remember playing Settlers 2 in anything higher than 1024x768, and whenever there were a lot a animated things on screen (typically after a storehouse went to pieces), it did slow the computer down a lot.

I think there are two issues with animating vehicles:
  • Should the animation be time-based like the others, or motion-based? If the latter, how exactly?
  • Vehicles require a lot of images already, since they have eight orientations. Are there enough artists willing to make that many images to make the programming effort worthwhile?

I guess the lower limit on total number of images also put a damper on things earlier.

Offline Ves

Re: Animated Vehicles
« Reply #2 on: February 03, 2017, 05:05:38 PM »
I certainly would do it if I got the possibility!
I think it was discussed somewhere some time ago to let vehicles have both front images and back images, then when you make i.e. A steam engine, you only paint the engine once and let the animated parts, i.e. The coupling rods, be front images. With that, you can even use the same coupling rod animation on multiple steam engines. 

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #3 on: February 03, 2017, 09:05:11 PM »
I don't remember playing Settlers 2 in anything higher than 1024x768, and whenever there were a lot a animated things on screen (typically after a storehouse went to pieces), it did slow the computer down a lot.
That would be a lot of free-running entities though. I'd assume the same thing would happen if the settlers moved without animation, but that's pure speculation and does not really advance us, seeing as we talk about slowdowns in a 20-year-old game.


I think there are two issues with animating vehicles:
  • Should the animation be time-based like the others, or motion-based? If the latter, how exactly?
I'd go with motion-based. Most animations one could do in a vehicle are directly related to it's speed, be it spinning wheels, some kind of piston moving up and down, or even a waving flag. Some others might not, like orange blinking lights on long trucks or a helicopter rotor, but I think those would be more specific.

In the end, it depends on how it's programmed. If you can tie animation to actual 'redraws' of the vehicle, so the graphical movement decides animation speed, it would be perfect. But if you would have to check the calculated vehicle speed at any given time to check how quickly the next frame should be shown, I don't think it would be worth it, and a stable animation speed like for everything else would be fine as well.

  • Vehicles require a lot of images already, since they have eight orientations. Are there enough artists willing to make that many images to make the programming effort worthwhile?
I mostly do buildings. But I do buildings with eight orientations and five seasons...
Depending on what it is, it might be very hard to paint. I think I wouldn't start with a 10-frame-horse-animation for each direction. But there is easier stuff. Especially with Ves frontimage-suggestion, you would not even have to paint any more images, you would just have the coupling rods on a seperate image and use it with different offsets. I'm not entirely sure, but it should be possible to define the offset via formula and only use one line per direction. Honestly, even if it's just coupling rods for all steam locos, I think it would already be paid off.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8799
  • Total likes: 320
  • Helpful: 229
  • Languages: De,EN,JP
Re: Animated Vehicles
« Reply #4 on: February 04, 2017, 08:53:30 AM »
Animation uses fix time frames. I may look funny, if the tires turn not in sync with the actual speed ... so there are certainly more issues to fix here. Not too difficult, but this requires also a new format of images management for vehicles. Especially larger pak size would profit from it.

Here goes the challenge. Make a vehile with a visible animation, and I will try to implement it.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #5 on: February 04, 2017, 10:58:44 AM »
Just as a quick proof of concept, the animation is easy, but I have to pixel the back of the truck since we had no cement truck before, and I don't think I would get away with just the pedestrian - even though these alone would be quite awesome (in pak192.comic, probably not in any other pak - and they would really need this to shine: http://forum.simutrans.com/index.php?topic=15200.msg149939#msg149939)

Offline Vladki

Re: Animated Vehicles
« Reply #6 on: February 04, 2017, 11:06:19 AM »
Really nice. I just have the feeling that the wheels are rotating backwards. And you fantastically hit a case when part of the animation should be based on speed/movement - wheels, while other part (flashlight and mixer), should not depend on the speed of vehicle.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #7 on: February 04, 2017, 11:14:19 AM »
Well, the animation of the wheels IS backwards. That is because they are moving forward so fast it appears backwards - https://en.wikipedia.org/wiki/Stroboscopic_effect

Offline Ves

Re: Animated Vehicles
« Reply #8 on: February 04, 2017, 11:25:15 AM »
Wow amazing looking! The rotation of the cement container could even be tied to wether the truck is loaded or not, using cargo image.
And the man is brilliant!

If both animation types are implemented, I think the benefits from having both front image and back image  is essential to separate the animations. Maybe even a front-front image (so picture is three layers)?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8799
  • Total likes: 320
  • Helpful: 229
  • Languages: De,EN,JP
Re: Animated Vehicles
« Reply #9 on: February 04, 2017, 01:25:52 PM »
Well, I would need eight view. And pedestrians are probably a bad idea (performancewise) to be animated, at least on bigger ganes

Offline Yona-TYT

Re: Animated Vehicles
« Reply #10 on: February 04, 2017, 06:40:16 PM »
Well, I would need eight view. And pedestrians are probably a bad idea (performancewise) to be animated, at least on bigger ganes
Leartin may be thinking of an future for Hardware accelerated, or more powerful in computers.
Also the option to deactivate the animations when the equipment is very slow.  ;)


No doubt, animated vehicles / pedestrians will look very nice at pak192.comic.  8)
« Last Edit: February 04, 2017, 07:05:20 PM by Yona-TYT »

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8799
  • Total likes: 320
  • Helpful: 229
  • Languages: De,EN,JP
Re: Animated Vehicles
« Reply #11 on: February 05, 2017, 02:22:25 AM »
As long as there are not vehicles, I am kind of reluctant to put much work in for eyecandy. Especially the pedestrian is a good example of animations making the appearance worse, if they are not synchronised with the movement.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #12 on: February 05, 2017, 02:57:27 PM »
Well, I would need eight view.

Despite being Austrian, I don't hold some pixel slaves in my basement, so I can't present result instantly :) I thought the first view would be enough to show it is possible, and to test implementation I would rather use something where the difference is even more appearant, eg. animating through different cargos of an existing vehicle. But here it goes:


A complete animated vehicle, using 6 frames.

As long as there are not vehicles, I am kind of reluctant to put much work in for eyecandy.
That cat bites it's own tail.
If a feature does not exist, people won't put work into creating graphics for it, since there is no guarantee they would ever be usable. Except as a proof of concept of what they even want to do.
Once you promise to do it if people (or at least someone) will use it, you should not need to wait for them to exist either. Unless you don't trust the artists to deliver, but if so, why would the artist trust you to deliver the code?
It's the features of the game that define what graphics will be created, not the other way around. (And if it actually was the other way around, where are liveries in Standard? Graphics certainly exist...)

Especially the pedestrian is a good example of animations making the appearance worse, if they are not synchronised with the movement.

I disagree. I did not even synchronize the movement when I created it, I just made the frames and spaced them out. I attached 4 different speeds for them, and I think all of them look better than hovering ghosts. But since all pedestrians walk at the same speed, and changing game speed changes animation speed, they would fit anyway.
As for the performance issues - isn't that why we have settings for how many of them are on the streets?

Offline Vladki

Re: Animated Vehicles
« Reply #13 on: February 05, 2017, 04:08:35 PM »
I think speed 2 looks best.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #14 on: February 05, 2017, 05:40:10 PM »
I do not see, why animated images for pedestrians could have an large impact on performance: if animation is based on speed, then the image only changes on movement. But then a new images has to be drawn anyway.

And non-animated pedestrians are not nice in close view in pak192.

Leartin, could you provide a png file containing these animation frames? Best would be to have animation frames for a complete walk across a tile. Then the image of the animation can be determined by the position of the pedestrian on the tile.
Parsley, sage, rosemary, and maggikraut.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4812
  • Total likes: 191
  • Helpful: 108
  • Languages: EN, NO
Re: Animated Vehicles
« Reply #15 on: February 05, 2017, 06:46:49 PM »
Animated moving objects will in theory only be slowed down by the extra logic required for calculating the frame and the extra cache misses caused by the fact that there will be even more different images. That will likely not be noticeable.

Animating buildings or, even worse, trees would have a greater impact, but it should be comparable to panning the map. Maybe animations could be turned off when zooming out, because that tends to be when drawing gets too slow today.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #16 on: February 05, 2017, 06:48:42 PM »
I do not see, why animated images for pedestrians could have an large impact on performance: if animation is based on speed, then the image only changes on movement. But then a new images has to be drawn anyway.
Exactly what I was thinking.

Leartin, could you provide a png file containing these animation frames? Best would be to have animation frames for a complete walk across a tile. Then the image of the animation can be determined by the position of the pedestrian on the tile.

Currently I only have this one direction.
But just to be sure: Currently, pedestrians have some variable that indicates their advance on a tile, and their position within the tile is based on that variable. Your suggestion is that instead of iterating through positions based on that variable, you iterate through the frames of the animation?
At speed two, that would mean 48 frames for a straight walk. Which are the same 6 frames every time, just with an offset. Would you like the complete 48 images, or just the 6 different ones, which would then be repeated in the dat-file with offset?
Code: [Select]
Image[E][0-47]=pedestrian.0.<$0%6>,<$0*2>,<$0>(if done like this, each image would have the pedestrian in the same position, but the offset in the definition moves him)
How about diagonals? Just the same teleporting stuff for now, with 48 frames as well?

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #17 on: February 05, 2017, 07:34:24 PM »
There is an internal variable to count steps of a vehicle on a tile: walking straight n/s or e/w is 256 steps, walking diagonal takes 181 steps (no matter how the vehicle is positioned to the imagined middle line of the way/track).

The easiest approach would we to couple this internal steps to the animations: if N animation frames are provided, then every 256/N steps the image changes. Or the other way round: after N steps the animation repeats (with offset).

The movement is then done by the program, the provided images are always placed at the same point in the graphics.
Parsley, sage, rosemary, and maggikraut.

Offline Ves

Re: Animated Vehicles
« Reply #18 on: February 05, 2017, 09:02:05 PM »
I would like to add another example of animation to show how 128 pixel size steam engines would come more to live with animation. Save for I dont know how to exactly to calibrate the speed to look right, 6 frames are used for the animation in this example.

Offline DrSuperGood

Re: Animated Vehicles
« Reply #19 on: February 06, 2017, 01:51:50 AM »
Ideally an actor system would only calculate animation timing and such for actors near the current camera view. This would mean that all the animations have no logic overhead for stuff not near the view.

However Simutrans does not have an actor model, with instead graphics being rendered at a much lower level, often as part of the object state tick (eg power station transformers).

Animating moving vehicles would probably need a normalized speed. Eg 1 tile per second of animation, where animation is defined in frames per second and the specified animation frames loop. As the convoy increases in speed the animation would also increase in speed.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #20 on: February 06, 2017, 06:24:08 AM »
Animating moving vehicles would probably need a normalized speed. Eg 1 tile per second of animation, where animation is defined in frames per second and the specified animation frames loop. As the convoy increases in speed the animation would also increase in speed.

That's what happens with Dwachs suggestion. The animation across the tile stays the same, no matter how quick the vehicle moves. So if the vehicle moves quicker, the animation speeds up.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8799
  • Total likes: 320
  • Helpful: 229
  • Languages: De,EN,JP
Re: Animated Vehicles
« Reply #21 on: February 06, 2017, 10:00:04 AM »
The distance on a diagonal is shorter, so it will be a little more tricky than that. But indeed, that was the idea.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #22 on: February 21, 2017, 10:43:18 AM »
I might have some time in the evening today.

Are pedestrian frames in all 8 directions, positioned on the stylesheet as usual, all that you people need for testing right now? Or is there something else required? (Not that I think you would do it right away - new release and all that ;) )

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #23 on: February 21, 2017, 12:28:18 PM »
This would be the ideal image to start.  The pedestrian should 'walk' at the same position all the time. Then the movement of the pedestrian can be done with the existing code, 'only' the animation has to be implemented. You do not need to animate  all 8 directions yet.
Parsley, sage, rosemary, and maggikraut.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #24 on: February 21, 2017, 03:44:06 PM »
Oh. I attached the file - only South and East are animated, the others are still static.

Code: [Select]
Image[W]=pedestrian.0.2
Image[N]=pedestrian.0.1
Image[E]=pedestrian.0.0
Image[S]=pedestrian.0.3
Image[SE]=pedestrian.0.4
Image[NE]=pedestrian.0.5
Image[NW]=pedestrian.0.6
Image[SW]=pedestrian.0.7

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #25 on: February 22, 2017, 05:18:19 PM »
Can you say how many pixels the person moves in x and y direction after one loop of the animation frames?
Parsley, sage, rosemary, and maggikraut.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #26 on: February 24, 2017, 06:02:53 PM »
Here is a proof of concept for animated pedestrians:

https://www.((Site not allowed - serves viruses))/download-12334686/animated_ped.zip.html

zip archive contains simutrans and makeobj windows executable, patch, and pedestrian dat  + pak.
Parsley, sage, rosemary, and maggikraut.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2592
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Animated Vehicles
« Reply #27 on: February 24, 2017, 07:23:02 PM »
Amazing, super nice. But the graphics have white artifacts in some frames, Leartin forgot to set the background colour as #7FFFFF. :P

I decided to follow some pedestrians and they seems to be able to teleport now. One was walking E->W in the north part of the tile, when the guy reached the NW part of the crossing he simply teleported to the NE part and walked N->S. The same happened with another walking N->S at the west side of the tile and then decided to go east at the crossing, just teleported from N to S.

Offline Yona-TYT

Re: Animated Vehicles
« Reply #28 on: February 24, 2017, 08:07:46 PM »

I decided to follow some pedestrians and they seems to be able to teleport now. One was walking E->W in the north part of the tile, when the guy reached the NW part of the crossing he simply teleported to the NE part and walked N->S. The same happened with another walking N->S at the west side of the tile and then decided to go east at the crossing, just teleported from N to S.

I think this error (teleport) has been around for a long time.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4812
  • Total likes: 191
  • Helpful: 108
  • Languages: EN, NO
Re: Animated Vehicles
« Reply #29 on: February 24, 2017, 08:21:37 PM »
I think this error (teleport) has been around for a long time.
Yes, and although they are not this kind of pedestrians, the sheep in pak64 are probably the worst offender of all, at least when cornered.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8799
  • Total likes: 320
  • Helpful: 229
  • Languages: De,EN,JP
Re: Animated Vehicles
« Reply #30 on: February 25, 2017, 11:02:15 AM »
The problem is also that the corners are ways are shorter and longer at the sides of the road compared to cars or trains, which are more central. So pedestrians are bound to have artefacts at crossings, at least when using the same steps at coners.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #31 on: February 25, 2017, 06:37:40 PM »
I saw it on Facebook. Amazing! At least as long as they walk straight.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2592
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Animated Vehicles
« Reply #32 on: February 25, 2017, 08:47:17 PM »
The problem is also that the corners are ways are shorter and longer at the sides of the road compared to cars or trains, which are more central. So pedestrians are bound to have artefacts at crossings, at least when using the same steps at coners.
I understand why, but now that the graphic is always fixed at the bottom this can be fixed. I guess that's why Dwachs asked them to be at the bottom.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Animated Vehicles
« Reply #33 on: February 26, 2017, 10:49:51 AM »
This would be another patch: make the length of diagonals a parameter for paks.

If the animated graphics is fixed at the same position as the non-animated then the graphics movement is the same for non-animated and animated.

For animation, which parameters do we need? I imagine some scaling parameter to scale animation speed with movement speed.
Parsley, sage, rosemary, and maggikraut.

Offline Leartin

  • Devotee
  • *
  • Posts: 800
  • Total likes: 287
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: Animated Vehicles
« Reply #34 on: February 26, 2017, 02:09:29 PM »
This would be another patch: make the length of diagonals a parameter for paks.
May I redirect to the proper extension request, just to keep this thread cleaner:
http://forum.simutrans.com/index.php?topic=15200.msg149917#msg149917

For animation, which parameters do we need? I imagine some scaling parameter to scale animation speed with movement speed.
Depends. Is the first position on each tile always the first frame of the animation, or can the animation cross tiles?
If the animation can't cross border, it means the animation needs to complete within the tile. So I think it would be best if you can decide how often the loop should repeat within one tile.
If it can cross tiles, I'd say define the animation speed by how many 'steps' use the same frame, based on a straight tile. So if it's a 6-frame animation and you want to see it looped 6 times per tile, you'd define animation speed as 7 steps. Does not quite add up, but since it does not interupt the animation at tile borders, it does not matter. Same goes for defining the number of steps per loop, but I think steps per frame makes more sense, since it's similar to the animation speed we already know.

I think that's it for this feature, as a content creator, I don't see what else I would like to set myself.