Author Topic: Can I improve high resolution animation that lags?  (Read 3201 times)

TheManInBoots

  • Epically wrote function to declare an int
Hi everyone!

I have been working on a game for the previous months. Now in the last steps of the process I want to see if I can improve the animated intro story, which is lagging a lot.
Because I use very high resolution animations (the game is in 1600x900, sometimes I have animations with 1600x900 sized sprites and additional animations on top of that), the animation becomes really slow and starts lagging, so that even the background music lags and cracks and pauses. And that is even before I added sound effects and voice over.
That's why I come back here again to seek help from creative, competent and inspired minds!

So far I tried changing the graphics driver to Direct3D 9, and turning "Limit display-mode to 16bit" as well as "Render sprites to screen resolution" to 'true'. I feel as if it improved the lagging a little bit, but the lagging still exists, especially during the higher resolution animations. Also, during the gameplay after the intro, I would like to animate the grass in the foreground, but doing so slows the game down. It creates lagging and the character does not move fluently anymore. (The grass covers a big area (1600x500). Also the animated grass is in the foreground so I cannot turn it into a background animation, in case you're thinking about it :) ) Increasing the sprite cache size does not work.

Are there any ways and tricks to reduce the lag or even eliminate it?

I'm aware most people don't create adventure games with those size dimensions and might not encounter this problem too often, so I'm really thankful for anyone who can help!
« Last Edit: 17 Nov 2019, 19:57 by TheManInBoots »

Jack

  • Think deviant
    • I can help with AGS tutoring
    • I can help with scripting
    • I can help with story design
    • Jack worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #1 on: 17 Nov 2019, 20:03 »
I have done some high res full screen animation tests with the same disheartening results. Turning off the sprite compression will make it faster, but will also make your game a lot bigger. Luckily compressing the game itself with another program for a download will bring the size down again significantly.

Would it be possible to separate the animations into smaller parts? Assuming not the whole screen is animated.

I don't know whether .ogv videos can be used instead of backgrounds in AGS, but it might be faster. As I understand, the codec is supported by AGS itself, so you don't have to worry about the codec being installed on the player's computer.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #2 on: 17 Nov 2019, 20:11 »
OGV video playing in the BG is only supported using a plugin (which might mean you get stuck in windows only mode, if the plugin can't run on other systems).

I'm not sure if you are animating a "cut scene" or the play world in it self. If it's a cut scene you can just replace it with a full sized animated frame or a video. If it's the play world thingswill get tricky and I'm not really the best one to give advice on it.  ;)
There are those who believe that life here began out there...

Re: Can I improve high resolution animation that lags?
« Reply #3 on: 17 Nov 2019, 20:54 »
AGS currently has two bottlenecks when it comes to hi-res sprites and animations:

1) Loading sprites.

AGS streams sprites upon request into "sprite cache" from the file, and this means that it may start reading file alot right before or during the animation.
At the moment (AGS 3.5.0) there's still no means to tell AGS to preload sprites by command, but to work around this there is a precaching technique where you force sprite to load using some operation. Unfortunately this is not documented, so may require investigation to find simpliest action that works. For instance, setting object's Graphic property does not load sprite until object is redrawn, which kind of defeats the purpose. But setting graphic to mouse cursor (using Mouse.ChangeModeGraphic) does --- I know that because I looked into the engine code.
So in theory you could try to preload all sprites for the next scene by calling Mouse.ChangeModeGraphic in a loop.

Another important factor here is sprite cache size. If it's not large enough to store all the sprites, then some of the loaded ones will be discarded before loading next ones. If you have a looping animation, this may lead to problems again.


2) Converting native bitmaps to textures.

When running Direct3D or OpenGL renderer, AGS must convert bitmaps to corresponding texture format. This process may be slow for large number of hires gfx. Unfortunately, at the moment AGS does not cache textures along with sprites, and so textures may actually be discarded earlier, when you change object graphic for instance. Also, these textures are not shared between objects, so even if two objects use same sprite, they may still end up having two duplicating textures that are created and updated separately. Improving this may be one of the primary TODOs for the next version of AGS, because people begin making hires games with big animations more often. But I am afraid there's no possible workarounds that you could use yourself at the moment.
EDIT: thinking about this, Jack's suggestion from above may work: try splitting up animation frames into pieces that change and pieces that don't change (and even - pieces that change often and rarely), and display them on separate objects. This will reduce amount of pixels needed to be updated to texture each turn.


To sum up, I'd frankly say that the best course of action would be to delay using lots of hires animations in AGS for now, and keep reminding this problem to engine developers to prioritize this...

Other than that, if you need these primarily for the cutscene, maybe trying playing video instead, as Cassiebsg suggested above.
« Last Edit: 17 Nov 2019, 21:14 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #4 on: 25 Nov 2019, 16:02 »
Thank you for your answers!


Jack

Turning the compressing off actually helps, thanks! (And yes my game is 3 GB bigger now  :P)
But it's quite irregular, sometimes the animations are more smoothly and sometimes more laggy!
Yes, I assume I will probably use an .ogv video for the animation, that will be some work to turn it into an actual video, but it might be the only option.
For the background (or rather foreground)  in-game animation of the grass, I found out that it actually helps to reduce the number of sprites in the animation loop to speed up the game and animation.
I know that there is decent compressing software for free online, but do you have a program that you prefer for compressing your game?




Cassiebsg

From what I read in the AGS index I believe that playing videos (both .ogv or other standard formats as .mpg or .avi) are supported with plugins that are built in the engine and that function on both windows and mac computers (only not on Linux), so I believe it will be fine.
I am mainly animating a cut scene, only the grass animation is in the play world.
About the full size animation, that's actually where the problem comes up, full sized animated frames are not animated fastly and smoothly, the game begins to lag and freeze or at least slow down, when you have enough frames in the animation. Even if it is only one full sized animated frame. But I'll look into the option to play it as a video. That will hopefully work.




Crimson Wizard

I'm not sure if I understood how exactly you want me to use the "Mouse.ChangeModeGraphic" function.
I tried putting "Mouse.ChangeModeGraphic" in Repeatedly execute triggered by a bool to keep it in a loop while the animation runs, but that seemed to only slow it down.
Now I placed a "Mouse.ChangeModeGraphic" function in front of each scene.
Do I need to load each sprite of the animation as the mouse graphic in order to preload it? Or do I simply run the "Mouse.ChangeModeGraphic" command no matter what sprite I use as the mouse graphic, and all the sprites automatically preload? (I used a random sprite.)
How exactly does it work with the engine code?

There definitely seems to be a problem on how sprites are saved. When I have several longer animations with more sprites, it becomes worse. But I set the sprite cache to 50GB and it still lags.
Sometimes I just turned animated objects or characters transparent and let them keep animating while the next scene starts. Since you said the sprite cache is limited I made sure to not let anything animate in the background transparently in a loop.

It still lags. The weird thing is that sometimes it lags more, sometimes less for no obvious reason, when I test run it several times. But it does not display the animation as it should.

So, it seems that I will turn the intro story into a video and play it that way.

(If I get to it, I'll make sure to drop a few lines in the engine development)
« Last Edit: 25 Nov 2019, 16:25 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #5 on: 25 Nov 2019, 16:34 »
I'm not sure if I understood how exactly you want me to use the "Mouse.ChangeModeGraphic" function.
I tried putting "Mouse.ChangeModeGraphic" in Repeatedly execute triggered by a bool to keep it in a loop while the animation runs, but that seemed to only slow it down.
Now I placed a "Mouse.ChangeModeGraphic" function in front of each scene.
Do I need to load each sprite of the animation as the mouse graphic in order to preload it? Or do I simply run the "Mouse.ChangeModeGraphic" command no matter what sprite I use as the mouse graphic, and all the sprites automatically preload? (I used a random sprite.)

You call Mouse.ChangeModeGraphic for each sprite you need to preload and it will get preloaded. Only sprites you call ChangeModeGraphic with are preloaded while you do so.

The time of call is up to you. You have to understand that calling this function does not magically make your animation faster, it merely allows you to control the time of sprite loading operation. After that, if sprite stays in memory, animation does not need to load it while it plays.
Normally I'd suggest do this when/before the scene starts. I guess it's even possible to put a "loading, please wait" text on screen while you do that.
« Last Edit: 25 Nov 2019, 16:38 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #6 on: 25 Nov 2019, 18:20 »
Okay, I will give it a try, this pre-loading technique might actually work.
When I restart the game and play the animation again after having played part of the animation before, that part of the animation is fluid (so apparently even when you close the game, the sprite cache is still saved with the loaded sprite files). But I also have too many sprites in my animation to save them all at the same time in the sprite cache. (That's why when I restart and play the animation again after having played the WHOLE animation, it does not work anymore, because the first sprites have already been deleted and so continue to get replaced before being displayed)

Do you know if the sprite cache limit is based on the number of sprites, or by the overall file size/used space of the sprites?  (I assume file size because higher resolution animations lag more, but I'd like to know for sure)
And if I pre-load the frames of a certain loop in this way and then I animate two objects with the same loop (that I just pre-loaded), the sprites are pre-loaded for both objects at the same time, and don't take double the sprite cache size, right? (Because you mentioned the texturing on the other hand is being done separately every single time). Knowing this could help me to re-structure my animation properly.  Maybe I can work around having to pause in the middle of the animated story just to load the new upcoming frames into the cache.

And I assume there is no way to increase the sprite cache limit, right? (The sprite cache in Default Settings seems to have no effect on this)

A "Loading..." symbol is a nice idea. :)
« Last Edit: 25 Nov 2019, 18:27 by TheManInBoots »

Jack

  • Think deviant
    • I can help with AGS tutoring
    • I can help with scripting
    • I can help with story design
    • Jack worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #7 on: 25 Nov 2019, 18:28 »
I use winrar, but any tool that allows you to set the compression level of a zip file will do. pkzip is free and will do everything you need. It has a terminal interface.

Re: Can I improve high resolution animation that lags?
« Reply #8 on: 25 Nov 2019, 18:47 »
When I restart the game and play the animation again after having played part of the animation before, that part of the animation is fluid (so apparently even when you close the game, the sprite cache is still saved with the loaded sprite files).

IDK how that is possible. Maybe there's a misunderstanding on how this works, or I do not quite understand what you mean.

Sprite file (acsprset.spr) is where sprites are stored on disk. Sprite cache is an array in memory where sprites are stored while you played the game. Engine does not save sprite cache anywhere. Each time you start the game (run exe, that is) sprite cache is empty and is only filled as you play. Nothing is preloaded until necessary.

On the other hand, if you play animation in game, and then play same animation again without quitting the game (closing the program), then some or all of the sprites may be still be in the cache and no extra loading would be necessary.


Do you know if the sprite cache limit is based on the number of sprites, or by the overall file size/used space of the sprites?  (I assume file size because higher resolution animations lag more, but I'd like to know for sure)
And if I pre-load the frames of a certain loop in this way and then I animate two objects with the same loop (that I just pre-loaded), the sprites are pre-loaded for both objects at the same time, and don't take double the sprite cache size, right? (Because you mentioned the texturing on the other hand is being done separately every single time). Knowing this could help me to re-structure my animation properly.  Maybe I can work around having to pause in the middle of the animated story just to load the new upcoming frames into the cache.

Sprite cache size means roughly the size of sprites in memory. I say roughly, because it does not account for certain "locked sprites". But I don't remember if it also counts DynamicSprite sizes as well.
If you use same sprite number in multiple frames, views, or objects, that's the same sprite, and once loaded it does not have to be duplicated multiple times.

And I assume there is no way to increase the sprite cache limit, right? (The sprite cache in Default Settings seems to have no effect on this)

Of course there is, why would the setting exist otherwise?!
The "Default Setup" has effect only on freshly installed game  (that's why it's called default). I suspect the manual does not explain this very well, so I will have to update the wording there...
"Default setup" is overidden by user settings. Presumably you have already created them by running winsetup once. So you should change both Default Setup and user settings (by running winsetup).
Actually, you may not touch Defaut Setup at all until or unless you are sending your game to someone else.

PS. Just be careful with the big sizes. Sprite cache takes real computer memory, and there are other things in game that also do, and there may be other applications running at the same time... if you are going to load all your 10 GB sprites in memory that will make an impact on player's PC perfomance (and may crash the game) :).
« Last Edit: 25 Nov 2019, 19:10 by Crimson Wizard »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #9 on: 25 Nov 2019, 20:01 »
Just for clarification.
I was not talking about playing a simple cutscene video. I know AGS supports that with no need of extra plugins at all. But you must know that this video will play in the foreground, so if you need AGS to add text, voice over or something else, you won't be able.

I was talking of playing a video in the background, so that you can display text, run voice over, GUIs, etc over the video. In this case you will need to use a plugin for ags.
You can find the plugin here, if you need it: https://www.adventuregamestudio.co.uk/forums/index.php?topic=45348.0
There are those who believe that life here began out there...

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #10 on: 06 Dec 2019, 16:12 »
Jack

I appreciate the recommendation.


Cassiebsg

My first priority for now is to explore the options I have that work for both the windows and Mac platform.
But do you know if it is possible with this plugin to play an animated object on top of the playing video?
It's not addressed in the thread.
This would prove to be really helpful if the other options fail.
Thanks for the link.


Crimson Wizard

So, the sprites were actually being saved in the sprite cache even after I closed the game and re-started it, that's actually what I meant. But I opened the game from the game editor, so not via the .exe or winsetup file. If that is actually surprising to you and you want to look into it, I used the AGS 3.5.0.17 / RC1 version. I haven't tested it on the more recent versions. Also it only worked when the "Compress the sprite file" option was set to false.

I'm actually looking forward to the day that my computer is going to crash because of a 2D point and click game lmao.
When I pre-load part of the animation cutscene into the sprite cache and then start the .exe or winsetup file it works.
But when I pre-load ALL the sprites of the animation I receive this error message at some point during the pre-loading process after the game started:


And it does not matter if I set the Sprite cache size to 1GB, 10GB or 15 GB and then export the game. When I start the game I still get the error message at the same point.

I interpret the message in the sense that the sprites of the complete animation have a size of 5,76 GB, and since the working memory of my computer is less than 5,76 GB the engine has no way to save them.
I have no knowledge on how to read these kind of messages, so tell me if my interpretation is wrong.

Another option that could really save me with this issue is if I could actually play music while the sprites are loaded into the sprite cache. Right now the music starts stagnating and faltering when it plays while the sprites are loaded into the sprite cache.
If I could play sounds and music while sprites are saved into the sprite cache I could use a slowly animated frame/ a still frame/ a black frame while the new sprites are loaded into the cache in the middle of my animation cut scene, and in this way I could avoid the sprite cache to be overloaded by uploading each half of the sprite group separately, instead of all at once. Maybe if I use certain audio formats, or use specific functions or do anything else I might be able to prevent the sounds from faltering?

Side note on pre-loading:
Is the engine loading the sprites faster into the sprite cache if I use the "Mouse.ChangeModeGraphic" function on every sprite, instead of playing every single loop of the animation cutscene on an objec? Or is it taking the same amount of time?

EDIT: Right, you already told me that the sprite is not loaded into the cache until the object is being redrawn. And there is no way to work around it by placing the object outside the screen or covering the object by another object? It still means that it's not being redrawn? Actually you could set a characters transparency to 99, and run the character through all the loops. I don't believe you can actually see it when the transparency is set to 99 on a black background.
Still I assume it takes longer because of the texturing and redrawing.
« Last Edit: 06 Dec 2019, 19:16 by TheManInBoots »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #11 on: 06 Dec 2019, 17:15 »
But do you know if it is possible with this plugin to play an animated object on top of the playing video?
It's not addressed in the thread.

It can, as it renders the movie in the background. You can then have characters, objects, GUIS, text, audio, etc over it.
You can see the plugin in action on this game by mandle: https://www.adventuregamestudio.co.uk/site/games/game/2118/
Or my own game in the intro and start movie/cutscene: https://www.adventuregamestudio.co.uk/site/games/game/2201/ (all text, music and voice are AGS scripted. This allows to change the music and translation files, and still only use one movie).

There are those who believe that life here began out there...

Re: Can I improve high resolution animation that lags?
« Reply #12 on: 06 Dec 2019, 19:32 »
So, the sprites were actually being saved in the sprite cache even after I closed the game and re-started it, that's actually what I meant.

Sorry, but I still can't understand what you mean by that. Do you mean that animation sprites are found in the cache when you re-launch the game, even before you do the preload? How did you find that out? Or do you mean something else? I am confused by words "saved in sprite cache". Sprite cache does not exist in between game launches.


And it does not matter if I set the Sprite cache size to 1GB, 10GB or 15 GB and then export the game. When I start the game I still get the error message at the same point.

I interpret the message in the sense that the sprites of the complete animation have a size of 5,76 GB, and since the working memory of my computer is less than 5,76 GB the engine has no way to save them.
I have no knowledge on how to read these kind of messages, so tell me if my interpretation is wrong.

Of course your interpretation is correct, you may set any number for sprite cache size, but if your computer memory is less, that won't work and may eventually crash the program.


Another option that could really save me with this issue is if I could actually play music while the sprites are loaded into the sprite cache. Right now the music starts stagnating and faltering when it plays while the sprites are loaded into the sprite cache.

Perhaps, try turning threaded audio on. Right now it's only possible to do by hand by setting following in a acsetup.cfg
Quote
[sound]
threaded=1

BTW this reminds me, we should add this to Default Setup, and maybe to winsetup too...


Is the engine loading the sprites faster into the sprite cache if I use the "Mouse.ChangeModeGraphic" function on every sprite, instead of playing every single loop of the animation cutscene on an objec? Or is it taking the same amount of time?

I believe loading itself will take same amount of time, since that's exactly same operation.
For actually preparing sprites for display on screen there may be additional action of course, but it's something that cannot be avoided.
« Last Edit: 06 Dec 2019, 19:34 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #13 on: 07 Dec 2019, 00:58 »
It can, as it renders the movie in the background.

Great, I'll keep it in mind. I'm currently downloading the games to check it out a little.

Perhaps, try turning threaded audio on.

I tried (with both acsetup files). It did not work. There is nothing else I can do?
If there was a way, the problem would be solved and I could finish my cutscene!




Do you mean that animation sprites are found in the cache when you re-launch the game, even before you do the preload? How did you find that out?
YES, the animation sprites were found in the cache when I re-launched the game, even before I did the preload.
I started the game from the editor when I observed this. The parts of the animation I had played the previous launch were fluid.

BTW this reminds me, we should add this to Default Setup, and maybe to winsetup too...
Sure.

For actually preparing sprites for display on screen there may be additional action of course, but it's something that cannot be avoided.

OK, so it DOES take more time right? And for the re-drawing of sprites, an object that is covered by another object, are its sprites being re-drawn or not when it's animated?
« Last Edit: 07 Dec 2019, 14:05 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #14 on: 07 Dec 2019, 16:10 »
Perhaps, try turning threaded audio on.
I tried (with both acsetup files). It did not work. There is nothing else I can do?
If there was a way, the problem would be solved and I could finish my cutscene!

I wish I had a way to test it, but I dont have a game with large sprites at the moment (I may try making a dummy game later).

But, could you show how do you do preloading in script?
I think it's worth trying to add Wait() command in this process. For example, if you have 1000 sprites to preload, load 100, call Wait (time may be adjusted), then continue.
Simple example (untested):
Code: Adventure Game Studio
  1. int counter;
  2. for (int i = 0; i < 1000; i++)
  3. {
  4.       Mouse.ChangeModeGraphic(eModeLookat, i);
  5.       counter++;
  6.       if (counter > 100)
  7.       {
  8.             Wait(10); // experiment increasing/decreasing the delay
  9.             counter = 0;
  10.       }
  11. }
  12.  



Do you mean that animation sprites are found in the cache when you re-launch the game, even before you do the preload? How did you find that out?
YES, the animation sprites were found in the cache when I re-launched the game, even before I did the preload.
I started the game from the editor when I observed this. The parts of the animation I had played the previous launch were fluid.

Engine does not do anything that could lead to this. The only explanation that I have is that maybe operating system keeps some of the loaded data in its own cache and this allows for faster inserting them back into engine memory when it asks to load files from disk. I heard Windows actually may do that with larger apps so it's faster to start them up later.



For actually preparing sprites for display on screen there may be additional action of course, but it's something that cannot be avoided.

OK, so it DOES take more time right?

It takes extra time to put them on display, in addition to loading (regardless of how and when you load). I hope we will improve (reduce) this extra time in later versions.


And for the re-drawing of sprites, an object that is covered by another object, are its sprites being re-drawn or not when it's animated?

Good question, and I think they are. This may need more investigation, but from a quick look into engine code, these are conditions under which the object is skipped:
1. Object is off (Visible = false)
2. Object is off the room limits.
It's interesting to note that this is not the optimal check, as it should probably test whether object is actually shown in viewport.
Furthermore, something I noticed only now, it does not work for all outside positions, but only when an object is beyond rightmost X border (object.x > room.width), or topmost Y border (object.y < 0).

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #15 on: 07 Dec 2019, 16:40 »
Furthermore, something I noticed only now, it does not work for all outside positions, but only when an object is beyond rightmost X border (object.x > room.width), or topmost Y border (object.y < 0).

Probably because otherwise you'd have to take into account the object height/width to decide whether to draw it.

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #16 on: 13 Dec 2019, 00:12 »
I think it's worth trying to add Wait() command in this process. For example, if you have 1000 sprites to preload, load 100, call Wait

How does waiting after 100 sprites make any sense? My game starts lagging from only one full-sized sprite on sometimes. If it has not been loaded into the sprite cache I display a sprite and the music starts clicking and pauses for a second before the next sprite is displayed. Sometimes it clicks and breaks several times during one single sprite when I have a full 1600x900 sized animation.
After 100 sprites I have already 100 lags.

I experimented anyways with the idea of adding a Wait function, but after each Mouse.ChangeModeGraphic function, in case that creating some time gap between each sprite loading might help.
Something like this for example:

Code: Adventure Game Studio
  1. int sp=1;
  2. while(sp>0&&sp<1001)
  3. {Mouse.ChangeModeGraphic(eModeUsermode2,sp);
  4. Wait(10);
  5. sp++;}
  6.  

But that does not work.

I wish I had a way to test it, but I dont have a game with large sprites at the moment (I may try making a dummy game later).

Yeah,I'd appreciate it, that is probably the best way to go about it. I tried to recreate the situation with 90 large sprites in a separate game but it did not lag. It's just happening in my game. Maybe you need a big enough amount of sprites?
However it is acting really bizarre in my project. The whole game seems to freeze while the sprite is loaded into cache. I added an animated Loading symbol as the (5 frame) background animation of the room, since those sprites are handled independently from the sprite file, but even the background animation starts to freeze. Also the music playback -and everything else happening on the screen- freezes... it seems like the whole game comes to a halt and waits for the sprite to be loaded into the cache before continuing.
I don't know if I have to send you the game again in order to find a way to fix this sigh. But maybe you are able to replicate the situation.

The only explanation that I have is that maybe operating system keeps some of the loaded data in its own cache (...) I heard Windows actually may do that with larger apps so it's faster to start them up later.

I know nothing about that. It's possible.

It takes extra time to put them on display, in addition to loading (regardless of how and when you load). I hope we will improve (reduce) this extra time in later versions.

I experimented a little bit with the putting on display. The engine displays an animation with the highest possible speed (of 40 frames/second) without delay: 40 frames within 1 second, even for high resolution animations. And when it is not fast enough to display it, it simply skips one sprite in the loop, but one wouldn't notice because it's animated so fast. (So used for loading sprites it probably does not even slow down the loading process, put simply skips a few sprites). Honestly I think it's working good enough ... but it's especially the process of loading into the sprite cache which really slows things down...

And actually the object animation and redrawing thing is not really important. I only thought animating the object might be easier to script, but that is not at all the case. Plus you are limited to 40 sprites per second, while you can loop the Mouse.ChangeModeGraphic up to 150.000 times in less than a second, so that says everything. It's very interesting to know about the object sprite display, though.

Probably because otherwise you'd have to take into account the object height/width to decide whether to draw it.
That makes total sense.
« Last Edit: 13 Dec 2019, 00:24 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #17 on: 13 Dec 2019, 00:34 »
40 frames/second is not the highest possible speed, it's the default. You can change this rate using SetGameSpeed.

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #18 on: 13 Dec 2019, 01:05 »
Ok, good to know, it works until 1000 loops per second I see. And for the sprite loading, do you think you'll be able to create a dummy game?
« Last Edit: 13 Dec 2019, 01:54 by TheManInBoots »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #19 on: 13 Dec 2019, 15:12 »
Ignore if this is a completely stupid idea.  ;)

But you could try and start a dummy game self, with just the files needed for the intro and build it there and see if that lags too.
- If it doesn't then there's two options: 1) try and figure out why it does in your game or 2) use that dummy game to just run the intro and the run your game minus the exe. (disadvantage here if that you get a second exe).

- If it does, send it to CW so he can try and figure out what's going on.
There are those who believe that life here began out there...

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #20 on: 14 Dec 2019, 23:12 »
No, it's fine Cassiebsg, it's a constructive idea.

Well, I created a new project only with the animation and it lags just as much.

I also tried to change a few things in the original project to use less sprite cache. For example by using a larger than screen sprite and then move it around, instead of having an animated object as the moving background frame by frame.
But now I am getting a new error message:


And also this one, which doesn't make a lot of sense to me:



And I get a similar error message as the first one in the dummy game I created with the animation as well:


And sometimes messages like the second one. It's a mess.


I am not a coder or programmer, I don't know how to fix the program...

I guess I send it to Crimson, in case he's gonna look into it...

I assume AGS simply isn't the engine to go to for high resolution games and animations.

Re: Can I improve high resolution animation that lags?
« Reply #21 on: 14 Dec 2019, 23:18 »
Well, there are definitely boundaries of how much you can push it...
1280x720 games seem to play alright, but I never tried anything above that.

Certainly, I can look at this, now when 3.5.0 is released there's some spare time.
« Last Edit: 15 Dec 2019, 00:18 by Crimson Wizard »

Re: Can I improve high resolution animation that lags?
« Reply #22 on: 15 Dec 2019, 00:50 »
Erm, now reading your post (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57632.0) and learning there's over 500 sprites in animation in 1600x900 res, I begin to question whether the idea of using sprite animation is a good one in the first place. It's just that you may get pretty high memory requirements with this if you push all that into cache at once.

Normally I think the solution here is to at least have a resource streaming in a separate thread, this is something that Nick Sonneveld is trying to add to AGS in his experimental branch.

So I really think playing video should be a better option in this case for now.


PS Regarding error messages, the second error is pretty obvious, it sais "Out of memory", which means your system ran out of memory trying to accomodate the game.
The first and the last error messages you show, maybe they happen because Gfx driver cannot create a texture of certain size. Or maybe it's because there's not enough memory again.
You said:
Quote
For example by using a larger than screen sprite and then move it around, instead of having an animated object as the moving background frame by frame.
What is the largest sprite size in your game?
« Last Edit: 15 Dec 2019, 01:36 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #23 on: 16 Dec 2019, 13:31 »
Erm, now reading your post (...) and learning there's over 500 sprites in animation in 1600x900 res, I begin to question whether the idea of using sprite animation is a good one in the first place. It's just that you may get pretty high memory requirements with this if you push all that into cache at once.

Actually not every sprite is sized 1600x900. Only the background frames, and certain animations where the entire background is animated.
Also, it is not my goal to load the entire animation into sprite cache at once.
The main problems that I believe to be related to the engine and think could be improved are these:

1) That the music and the rest of the game lags while the sprites are loaded into the sprite cache.

2) That I get an error message in the middle of the animation:
Shouldn't the old sprites be discarded from the sprite cache when new ones get loaded? So why do I receive an error message? There should be enough space to load new sprites into the cache when the old ones are discarded, right? I believe that's a malfunction of the program of some sort, isn't it?

Normally I think the solution here is to at least have a resource streaming in a separate thread, this is something that Nick Sonneveld is trying to add to AGS in his experimental branch.

What is that resource streaming? Do I stream the sprites from a different thread?
Are you talking about Sonneveld's Adventure Game studio fork? (https://libraries.io/github/sonneveld/ags)
I wouldn't know how to use it. I have never used Visual Studio before. I'm not coding. Only basic AGS coding.

What is the largest sprite size in your game?

Actually I changed the "larger than screen" sprite. It was 2081x900 big, but I split it into two sprites afterwards, so 1600x900 and 481x900. Hence the biggest sprite is 1600x900 big. But the error message remains.

So can I send you the animation project link once it's uploaded? Just to look into it?
I believe there are still things that can be improved about the program that are entirely unrelated to hardware demands. Like the lagging music for example.
« Last Edit: 16 Dec 2019, 16:45 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #24 on: 17 Dec 2019, 11:19 »
1) That the music and the rest of the game lags while the sprites are loaded into the sprite cache.

Music lag sounds strange if you have threaded audio enabled, I would like to see this in action and find out what's going on.

2) That I get an error message in the middle of the animation:
Shouldn't the old sprites be discarded from the sprite cache when new ones get loaded? So why do I receive an error message? There should be enough space to load new sprites into the cache when the old ones are discarded, right? I believe that's a malfunction of the program of some sort, isn't it?

It loads sprite cache as much as it's "max size" parameter allows. It discards only when it is filled up to "max size". What is your current cache size setting, and what is your system memory?
Note that program requires memory not only for these sprites, but for other things too: room backgrounds are kept separately, music, loaded scripts - these may not take much individually, but add some amount in combination.
Also, actually there's more - the sprite storage keeps "locked" sprites which are never discarded (I think this also counts DynamicSprite objects). You can press Ctrl+Alt+V in game to see how much is locked.


What is that resource streaming? Do I stream the sprites from a different thread?
No, not you, but the engine should do that itself.
Are you talking about Sonneveld's Adventure Game studio fork? (https://libraries.io/github/sonneveld/ags)
I wouldn't know how to use it. I have never used Visual Studio before. I'm not coding. Only basic AGS coding.
No, sorry, I am not suggesting to use it, I merely mentioned that there's a person who is experimenting with that right now, and we hope to have it in official version in the future.

So can I send you the animation project link once it's uploaded? Just to look into it?
I believe there are still things that can be improved about the program that are entirely unrelated to hardware demands. Like the lagging music for example.

Sure, I can take a look. I've got a decent internet connection so will be able to download big game too (so long as it's convenient for you to upload).

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #25 on: 19 Dec 2019, 02:28 »
What is your current cache size setting, and what is your system memory?

My current sprite cache size is 1GB. I have a good deal more RAM, so I don't know why this happened.

Sure, I can take a look.

So here is the link to the animation project with the lagging animation (I added it as well to the other thread for the developpers):

https://drive.google.com/file/d/1tTeDxlTogBwmSCQ3csK1u5VNHg91njya/view?usp=sharing

Note: Make sure to delete line 611 in room script "room1.asc", I forgot to do that. It is a line from the original game and causes an error in the demo.


Click below to view more file info
Spoiler: ShowHide

About the file:

It's 1,1 GB big, decompressed 3,16 GB.

The version used is: AGS 3.5.0.20 (Edit:RC4)


About the script:

I created a quick overview of the different scenes as well to make it easier to understand the script if necessary:

https://i.imgur.com/9uvX9XX.png

I call the different scenes "pic" in my script, I guess I wasn't paying too much attention when choosing the term :P

So "Pic" 1-13 are static, 14-30 animated.

For the animation test I skipped 1-11, so as to test especially the animated part. I did not pre-load all the sprites, only some of them, so not all scenes/pics should be fluent.
You can check everything out in the room1.asc script.
Besides the room1.asc script I have coded only two functions in GlobalScript, the
Code: Adventure Game Studio
  1. function late_repeatedly_execute_always()
and
Code: Adventure Game Studio
  1. function late_repeatedly_execute_always()

The rest is default game script.

Because of the lagging I did not end and perfect the animation. Some movements might be too slow or fast, the lighting bolt in scene/ pic 25 is misplaced, and I don't know about the last scenes because I never saw them in the Animation test project due to the error message.

Again, the problems that occur are as follows, ordered by importance:

1) The music is lagging while the sprites are loaded into cache. All game activities/loops seem to pause while a sprite is loaded into cache (the Loading symbol is a room background animation and should be moving as well).

2) I get an error message in the middle of the animation, even though my computer memory is not exhausted, as far as I can tell.

3) The loading into sprite cache takes a lot of time. When I skip the cutscene in the original game e.g. I have to wait an estimated two minutes before the game continues.


So hopefully it all made sense the way I explained it and I didn't forget anything, I'm a bit tired.


Good testing!
« Last Edit: 17 Jan 2020, 10:25 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #26 on: 22 Dec 2019, 14:26 »
I will try to test this during the week.

But, could we please keep the discussion in this one thread? I was not sure why did you start another one in different forum section.
« Last Edit: 22 Dec 2019, 14:28 by Crimson Wizard »

eri0o

Re: Can I improve high resolution animation that lags?
« Reply #27 on: 22 Dec 2019, 14:56 »
In the project I have a crash here:

Code: Adventure Game Studio
  1. in "room1.asc", line 611
  2.  
  3. Error: SetCharacterView: invalid view number (You said 43, max is 6)

Top memory usage was 1.9GiB on my machine.

Spoiler: ShowHide

My pc config:
Code: Bash
  1.            .-/+oossssoo+/-.               eri0o@future
  2.         `:+ssssssssssssssssss+:`           ------------------
  3.       -+ssssssssssssssssssyyssss+-         OS: Ubuntu 18.04.3 LTS x86_64
  4.     .ossssssssssssssssssdMMMNysssso.       Host: MS-7924 1.0
  5.    /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 5.3.0-7625-generic
  6.   +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 1 hour, 25 mins
  7.  /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 2865
  8. .ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.4.20
  9. +sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: 2560x1440
  10. ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: GNOME 3.28.4
  11. ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: GNOME Shell
  12. +sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: Adwaita
  13. .ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Pop-slim-dark [GTK2/3]
  14.  /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: Pop [GTK2/3]
  15.   +sssssssssdmydMMMMMMMMddddyssssssss+     Terminal: gnome-terminal
  16.    /ssssssssssshdmNNNNmyNMMMMhssssss/      CPU: Intel i5-4590 (4) @ 3.700GHz
  17.     .ossssssssssssssssssdMMMNysssso.       GPU: NVIDIA GeForce GTX 970
  18.       -+sssssssssssssssssyyyssss+-         Memory: 5619MiB / 24006MiB
  19.         `:+ssssssssssssssssss+:`
  20.             .-/+oossssoo+/-.                                      
  21.  


Here is the game on my pc, not sure where the lagging parts are supposedly to be.

streamable.com/8jsm2

As CW said, this is not an easy to solve problem and will take time on multiple different areas in the Engine.

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #28 on: 23 Dec 2019, 02:21 »
So I'll answer you quick, before the holidays begin:

But, could we please keep the discussion in this one thread?

Yes, no problem.

In the project I have a crash here:

Code: Adventure Game Studio
  1. in "room1.asc", line 611
  2.  
  3. Error: SetCharacterView: invalid view number (You said 43, max is 6)

Yes, you're absolutely right. Thanks for pointing that out. It is set to the view number in the original game, and I could not notice because the animation always crashed before I reached the end. I will note that in my comment above.

Here is the game on my pc, not sure where the lagging parts are supposedly to be.

I watched your video, and the animation is being played flawlessly! And the music playback? There was no problem with it?

I have 3.84 GB usable RAM, and 2.2 GHz CPU. Shouldn't that be working as well?

So is my computer simply to slow to perform the animation?
Or is it because you use Ubuntu?
Or is it mainly the graphics card maybe?

My graphic card is called "Mobile Intel(R) 4 Series Express Chipset Family".
And I see now that it has 1,76 GB usable memory, maybe that is the memory that is relevant for the game!? And not at all the computer memory?
So if it has to use 1,9GB as you said, but has only 1,7 GB available, maybe that is when the game starts to really lag???
 
On my PC the animation starts lagging for example right in the beginning during the scene with the three flying marbles in front of the island and water (scene 14). Those sprites are not pre-loaded and during the animation the music is constantly interrupting and the animation goes about very slowly.
Also on scene 17, with the big moon, it lags a lot. And then there is the error message. See:

https://streamable.com/pl296

(Sorry for the terrible audio, maybe make sure to lower the volume beforehand. I wasn't aware it was recording with the computer inbuilt mike, but you get an idea on how it lags)

As CW said, this is not an easy to solve problem and will take time on multiple different areas in the Engine.

Yes, I am aware, and I am not expecting any fast results. I am turning the animation into a video for now. I use "Synfig" as a software, which is quite easy to use and is perfect for this job. The animation might look even better after that!

Engine does not do anything that could lead to this. The only explanation that I have is that maybe operating system keeps some of the loaded data in its own cache and this allows for faster inserting them back into engine memory when it asks to load files from disk. I heard Windows actually may do that with larger apps so it's faster to start them up later.

Crimson Wizard, actually I can confirm your theory. I was editing the sprites in another software, "Synfig", to prepare them to turn them into video, and then when I opened AGS and played the animation for the first time, the animation was played fluently, as if the sprites were already pre-loaded, even though they were not! I basically pre-loaded them in a different program lol! That's the same reason why they were "pre-loaded" by previous game launches.
However I tend to believe that they are not necessarily saved in the working memory of the computer, but actually in the memory of the graphic card. I think that would make total sense, don't you?

You can see the plugin in action on this game (...)
Or my own game in the intro and start movie/cutscene

Cassiebsg I actually wanted to ask you about the intro: those text titles are really smooth! Were they part of the video or did you add them with AGS?



Alright, and enjoy the holidays I guess
« Last Edit: 23 Dec 2019, 02:24 by TheManInBoots »

eri0o

Re: Can I improve high resolution animation that lags?
« Reply #29 on: 23 Dec 2019, 02:26 »
I had no problem with the audio. I am sorry I couldn't record it, I screwed something in OBSStudio and forgot how to switch back to internal audio output. I have no answers for your questions on where the bottleneck is.

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #30 on: 23 Dec 2019, 02:47 »
OK, no problem.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Can I improve high resolution animation that lags?
« Reply #31 on: 23 Dec 2019, 09:34 »
The text is not part of the video.
The video only has image, no sound or text on it. Reason for it is, that you can change the music tracks that are playing in the settings if you like, and text I also wanted it to be changeable in case of needing it to be translated.
The text is being displayed using CW's great Typewriter module.  (nod)
There are those who believe that life here began out there...

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #32 on: 28 Dec 2019, 17:43 »
Cool. Umm, Crimson's Struct Stream? I saw Phemar created a type writer module which seems pretty cool.

Since the problem is related to bottlenecks in hardware and PC performance it would be pretty cool to have an option in the future to change the quality of your game (Low, high resolution), so that you can create a high resolution game that can be played on all computers. Also interesting to find out where the bottlenecks are exactly. Would be cool if the engine could instead of displaying error "not enough memory", it could display "Your Computer performance is not high enough.(or your graphic card is not compatible) Want to switch to lower quality?"

I might suggest that to developmnt at some point.

HEre's a summary of gthe thread for lazy people who deaL with high resolution lagging:


SUMMARY AVOID LAG

Spoiler: ShowHide

To avoid lag in high resolution animations you can pre-load sprites. This is useful for in-game animations.
Fastest and easiest way is Mouse.ChangModeGraphic, e.g. sprites 1-100

Code: Adventure Game Studio
  1. int sp=1;
  2.  
  3. while (sp>0&&sp<101)
  4. {Mouse.ChangeModeGraphic(sp, eModeUsermode2);
  5. sp  ;}
  6.  

You can also play videos as the animation. This is useful for cutscenes.
Personally I used Synfig and a video editor to turn the animation into a video.

Side note: There is a plugin that allows you to play videos in the background, so that you can play music, audio at the same time, and place, text, objects, characters, etc. on top of the video. For Windows only



Thnkas
« Last Edit: 18 May 2020, 00:16 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #33 on: 29 Dec 2019, 22:03 »
The text is being displayed using CW's great Typewriter module.  (nod)
Cool. Umm, Crimson's Struct Stream? I saw Phemar created a type writer module which seems pretty cool.

I made a more universal module later, because Phemar's is only blocking (IIRC) and I needed an non-blocking one for my game, with more ways to customize it.
It's called Typed Text: https://www.adventuregamestudio.co.uk/forums/index.php?topic=54450.0

I am aware that the description is not as clear as one would like to... I still plan on creating a proper documentation with less abstract explanation.
But it comes with a demo game, so hopefully may give a better idea of its use.
« Last Edit: 30 Dec 2019, 09:18 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #34 on: 02 Jan 2020, 20:39 »
Demo games always help. I'll check it out thank you

Btw. The links didn't work for me I had to change the ending to download it, e.g.  "... ags-script-modules.git" to "... ags-script-modules/downloads/" maybe that's just my PC
« Last Edit: 02 Jan 2020, 21:50 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #35 on: 02 Jan 2020, 22:45 »
Btw. The links didn't work for me I had to change the ending to download it, e.g.  "... ags-script-modules.git" to "... ags-script-modules/downloads/" maybe that's just my PC

There are two links: first, with big "DOWNLOAD" point to zip archive, and another - "git cloning address" is to be used with "Git" source version control tool.

On a side note, I seem to finally able to get most of planned tasks off my hands, so hopefully will be checking your demo game soon too.

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #36 on: 06 Jan 2020, 17:47 »
Btw. The links didn't work for me I had to change the ending to download it, e.g.  "... ags-script-modules.git" to "... ags-script-modules/downloads/" maybe that's just my PC
There are two links: first, with big "DOWNLOAD" point to zip archive, and another - "git cloning address" is to be used with "Git" source version control tool.

Makes sense, thanks for the explanation

On a side note, I seem to finally able to get most of planned tasks off my hands, so hopefully will be checking your demo game soon too.

So the question for you is then how worthwhile it is to look into making the way animation is handled more efficient. eri0o already tested it and it works fine on his PC, so the lagging comes also from lower PC performance. You have the overview of what you're working on, so you know what's important for the game development.
« Last Edit: 17 Jan 2020, 10:27 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #37 on: 11 Jan 2020, 16:32 »
Alright, finally to the animation demo.

Firstly, the issues I found when started:
- it takes too much time to startup the game. There's no "preload" screen in this game, and it looks like game window froze, because there's no image for around 5 seconds.
- the animation itself and music works okay, for the first time
- somewhere around the room with the sea and some coastal rocks game crashes with "out of memory" error. Same happens if I try to skip the intro.
Now, I did not think about this earlier, but thing is, the engine is built as a 32-bit program, which supposedly means the max memory it may use is 4 GB. But this game crashes with "out of memory" when it reaches 2 GB. NOTE: I have 16 GB RAM on my PC.
Okay, 64-bit Windows may be limiting 32-bit programs to 2 GB actually: https://www.quora.com/What-are-the-memory-limits-for-32-bit-applications-on-a-64-bit-Windows
- skipping intro does not really skip it, it seem to keep playing script on background for the same time.
EDIT: - There's a peculiar issue of sprite cache reporting "locked size" = 1.5 GB. You can see it if you stop intro mid-way somewhere before it crashes and press Ctrl+V.
This "locked size" are special images that are never automatically deleted by the cache. Meaning there's only 0.5 GB left for the rest of sprites... Might be a good idea to understand why it locks so much.
I remember that mouse cursor images are getting locked, and DynamicSprites are. Since you are using that ChangeModeGraphic trick to preload sprites, I wonder, if AGS has a bug and does not release previous sprites set as a cursor..... UPDATE but after I commented out all ChangeModeGraphic calls, that reduced "locked size" only to 1.35 GB.....



One thing I can tell about animation itself... it struck me that I do not see much of things animated on screen at the same time, so at first thought the situation is not too bad.
But when I looked into game project I found out that part of the animation is created in a very non-optimal way.

Take the first scene, for instance. There is a static image of a boy, and only his eyes are flashing. Normally, one would create 2 tiny objects as flashes and animate these, but instead in this game you have five 1600x900 full-screen sprites which has nothing but these tiny flashes in the middle. These could be easily reduced to like 16x16 sprites put onto 2 objects in the room, making this part of animation take about 100 times less memory already.

Other quick examples that I noticed:
* the "Press escape to skip intro" looks like basically one image rescaled several times to make an animation. This could be optimized by having 1 image and scaling the room object. Or have a TTF font or sprite font and drawing a text.
* the marble with a face and wings - these sprites are bigger than necessary and could be cropped to reduce to around twice as smaller size. In fact, if you push to max effect, you could place the face, that does not change at all, onto the 1 separate sprite and object, and animate wings on 2 separate objects. This would reduce memory for these flying faces more roughly by 1/3.
* the "monster attack" animation I found in the sprite folders - again, the sprites are 1600x900 big but contain too little, these could be cropped significantly and played while also moving object around.

It's important to note that making animation with game objects is not the same as making animation in a video. Video may have good animation compressions by only remembering the differences between series of frames, but when you play separate frames by hand in AGS you cannot do that, because AGS does not know how are you planning to use these sprites, so there's much less potential for automatic optimization. So, when you are doing big hires animations like this by hand (using game objects), you have to optimize yourself.
« Last Edit: 11 Jan 2020, 16:58 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #38 on: 20 Jan 2020, 02:49 »
Heya

Saw your post only recently.

it takes too much time to startup the game. There's no "preload" screen in this game, and it looks like game window froze

I can see the Loading symbol when I run the game on my computer, so that probably means that your computer pre-loads the sprites fast enough so that you don't even get to see the Loading symbol.

For me, too, it takes too much time starting the game with a blank, black screen (in the "room before fade in" phase).
Also, as a side note: When I start a project and create a high resolution animation with less sprites, only a bunch of them, it works without any problem. However from a certain number of sprites this terrible lag and the error message is happening. Relating to what you said
There's a peculiar issue of sprite cache reporting "locked size" = 1.5 GB.
my theory is that the software does actually -before the room is loaded- lock a certain number of normal sprites only used in animation into cache, which would be badly programmed. So when I have a few sprites in the animation and thus only a few sprites in locked cache it does not interfere because it's nowhere near 2 GB.
So it seems the "Locking" into cache is not very clean and accurate when choosing which sprites to lock.

NOTE: I have 16 GB RAM on my PC.
Okay, 64-bit Windows may be limiting 32-bit programs to 2 GB actually:

So I assumed right after all, that it's not directly related to RAM but also related to engine. I'm glad it's not just my PC. Is your Graphic Card Memory anywhere near 2 GB?
Does it make any difference when you change the Sprite cache in Settings to 2 GB? (Because the demo is set to 1GB as is)

I mean after all that is a great insight you have! So if at any point this problem is addressed in development, you already know that the core problem is in how the sprites are selected and filtered to get locked into the sprite cache.

You can see it if you stop intro mid-way somewhere before it crashes and press Ctrl+V.
You can press Ctrl+Alt+V in game to see how much is locked.

Sorry, what do you mean by "stop" the intro? Press escape? Close the game? I was not able to view the Locked Sprite info, no matter at what point.
Neither by pressing "Ctrl+V", nor by pressing "Ctrl+Alt+V".

UPDATE but after I commented out all ChangeModeGraphic calls, that reduced "locked size" only to 1.35 GB.....
That again shows how "unclean" and inaccurate the selection process for sprites is. I pre-loaded the biggest part of the animation. The sprite file is almost 700 MB big.
So under no condition should the locked Sprite size be reduced by only 150 MB. It should be either ALL the pre-loaded sprites that get locked, because Mouse Cursor Graphics are locked, or NONE that get locked. But it's neither of those two options, it seems that only SOME of the pre-loaded sprites get locked.

Normally, one would create 2 tiny objects as flashes and animate these, but instead in this game you have five 1600x900 full-screen sprites which has nothing but these tiny flashes in the middle. These could be easily reduced to like 16x16 sprites put onto 2 objects in the room, making this part of animation take about 100 times less memory already.

Well, images usually only take up a lot of space when they include a LOT of different colors and textures, such as exactly the photographs I use that are vividly colored. But plain, one-colored sprites (or plainly transparent sprites) do not actually take up a lot of space. One transparent sprite, sized 1600x900, takes up more or less 55-60Kb. So by reducing the sprite size I would save only 50-55 KB in this example (55x6sprites=330KB). That is next to nothing when I have to reduce 1 GB or 1000000 KB sprite cache. And working through the entire animation to try to save space like that is just a waste of time. I really pushed myself to the limits doing this animation, I haven't really done a lot of animation before, so I already got exhausted creating this. On top of that I want the sparkle in the eyes to be placed exactly where it feels right to me. So I have to go to my graphics program, make the size smaller, than measure exactly the difference to the full sized image for the smaller sprites for both x and y, and transfer those Coordinates to AGS. Now imagine I do that for every object in the entire animation. It's a lot of work and it has very insufficient results. Whereas when I animate in full size I can simply set x,y to 0,900 and it's perfectly placed, and I added only 55KB to Sprite cache.

the marble with a face and wings - these sprites are bigger than necessary and could be cropped to reduce to around twice as smaller size. In fact, if you push to max effect, you could place the face, that does not change at all, onto the 1 separate sprite and object, and animate wings on 2 separate objects. This would reduce memory for these flying faces more roughly by 1/3.

Yeah I could have done the separating between wings and face to save space. However I am reluctant to reduce the quality and size them down somehow...:P

the "monster attack" animation I found in the sprite folders - again, the sprites are 1600x900 big but contain too little, these could be cropped significantly and played while also moving object around.
I cannot just move the sprite to make it look like he jumps. The monster is rotating while he jumps, which makes things more complicated again since rotating is not developped and integrated in AGS yet. Also it would be really messy to make it look like he catches the flying marble perfectly and align two different sprites perfectly. I would set approximate coordinates, run a terribly lagging animation, estimate new coordinates again, run a terribly lagging animation again, estimate new coordinates again... That's just too much. And again same thing:  I would save only very little space with a lot of work.

the "Press escape to skip intro" looks like basically one image rescaled several times to make an animation. This could be optimized by having 1 image and scaling the room object. Or have a TTF font or sprite font and drawing a text.
Yes I could have done that with Scaling and saved some sprites, true. I'm not gonna use that symbol eventually anyway. Can you scale Sprite font texts? For now I'm having difficulties with your type writer, seems a bit complex to me on the first attempts. I will still experiment a little bit more with it...

At least now you know that there are issues concerning the locking of sprites that can be adressed to improve the engine. The lagging music seems to be only my PC when it has to perform too much, so nothing engine related at all. I had the same problem to a lesser degree with a different game that wasn't AGS related. But that genius insight you had with the sprite locking, and the error message you get on your PC as well, that's AGS.
I for one will continue making the animations as videos. It's easier, it has way better performance, and I don't get all of those problems, which freaked me out a little bit at one point to be honest.

It's maybe not the worst suggestion to make the sprites all as small as possible where you can. But as I said it's just sooo messy and so much trouble doing that with AGS that it's barely worth it.
However that gave me an idea for a very useful option in the room editor that would make it all extremely easy, and I feel like anyone who has worked on a more elaborate animation so far could agree on it's utility:



Spoiler: ShowHide

An option to actually preview an object or character on a specific sprite in the room editor, and an option to preview it with scaling!
This way you can view a character in the view that you use in the animation, with the scaling that you use in the animation, move it exactly to the spot you want. And then you simply copy their x,y-Coordinates and use them in script of the animation, super easy!

I made some illustrations just for how that would look like, to make this clearer.
Those are only illustrations, obviously:




View in High Resolution: https://i.imgur.com/Xy29pto.png

So you can click the button in order to preview the character (or object- I will say only character from now on, only because I am too lazy to mention object as well every time) with a specific sprite that you choose, and if you click again you deactivate the preview.



View in High Resolution https://i.imgur.com/sNw8dZQ.png

So when you click on the little loading box on the side you can choose what Sprite you want the character to be previewed as. You can either type the sprite number or browse:


And then you can activate or deactivate the preview, while seeing on the button what Sprite you can preview as:




And for the scaling one could add a tick box, simply like this:



View in High Resolution: https://i.imgur.com/azU3JDu.png



View in High Resolution: https://i.imgur.com/qOaNtXw.png

And then you could choose the Scaling value for preview, by clicking on the small loading box on the side next to it. There you have the option to have a specific Scaling value, or preview the character with the scaling of the walkable area at it's x,y Coordinate:



Just to be clear, this wouldn't have ANY effect on the game play itself, it would only change the preview in the EDITOR while the button is clicked or the box is ticked.
This would really help organize and structure animations in an intuitive, effective way. You will know exactly where your characters and objects have to go during animation, you can accurately estimate the whole process of the animation. I know you guys are all geniuses when it comes to programming and logical problems, way better than me. But I think that part of creating games is also the story-telling, the creation of a world, being very IMAGINATIVE. And for that I think an intuitive tool like that can help tremendously make game creation and animation a bit more intuitive and imaginative, and will result in slightly better games.
What do you think Crimson, or anybody for that matter?


I got this idea here while working with this animation, but maybe I should post this in Editor development

Edit: And sorry, just saw how long this reply became. I just wrote off the top of my head, you can answer when you get to it, no pressure :)
« Last Edit: 20 Jan 2020, 12:05 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #39 on: 20 Jan 2020, 21:24 »
I do not have time to answer everything, but will note coupe of important things now.

1. How did I stop animation in a middle to press Ctrl+Alt+V and check the cache size.

Simply put "return;" command in the middle of the intro function to skip rest of animation before it crashes. When it stops, I can press buttons , and so on.


2. About locked sprites.

First of all, I must clarify sprite cache mechanics here.

Sprite cache consists of 2 types of sprites, let's call them cached and locked.

Cached sprites are loaded when necessary, but may be unloaded if there's a need to load more sprites, and cache is full. This is how most of the regular sprites work in AGS.

Locked sprites are forbidden from unloading until explicit command. Only following sprites are locked:
* Mouse cursors and cursor views (views set for cursor animation). Because cursor is always on screen, and should be persistent.
* Very first player's view. I think this is something existing for historical reasons, to speed things up for all the game's duration, although today games need other ways to optimize sprites.
* Dynamic Sprites. These cannot be released until game author tell so by calling DynamicSprite.Delete(), obviously.

So, I thought it is not normal that your game has a lot of locked sprites, because it's not normally supposed to be like that. The sprites you preload were supposed to be registered as regular "cached" sprites, at least that was my original thought.
Indeed, Mouse.ChangeGraphic locks the sprite, but I made a guess it unlocks the previous one, making it regular cached sprite that may be later disposed automatically if run out of cache space......


3. The real problem.

Thing is... it does not seem to unlock locked sprites after calling Mouse.ChangeGraphic again. Which is ridiculous, but true. Maybe it was never much of a problem, since cursor gfx are usually small enough. I could miss something, but from what I've seen in the engine code, it looks like it never actually releases any of the locked sprites. So, this might be a bug number one.

This essentially means that you cannot use Mouse.ChangeGraphic as it is now, because with every use you will reduce amount of available cache size, irreversibly.

I also found another bug, related to locked size counter, apparently it keeps increasing it if the locked sprite is told to be locked again, which means that this statistic is unreliable currently.


Finally, regarding the big locked amount, which exists even if I remove all the calls to Mouse.ChangeGraphic. Remember what I said, about the first player's view being locked?
Well, in your game player character is "cm", and its original view is View 1, which is a HUGE view with many big sprites. All of these get locked irreversibly as well, taking up cache space for little good reason. This also explains why the game takes so long to start....


Because some of the above are bugs (with a high level of certaincy), I will be looking to fix these, and see if that changes anything in regards to your game.
Most of this is a very old behavior from late 90-ies, when games were small so all that could sound like a good idea... Guess no one have looked into adjusting this before.



UPDATE:

So here's an experimental engine build that does not lock sprites at all, and only caches them (so that they could be replaced later along the game):
https://www.dropbox.com/s/6wq629989wpj3qg/acwin-3.5.0-test-nospritelocks.zip?dl=0

I also removed obligatory player's view precaching. That made game startup almost instant for me.
This is of course not the final solution, only something to test. I wonder if it will make any difference for you.
« Last Edit: 20 Jan 2020, 21:49 by Crimson Wizard »

eri0o

Re: Can I improve high resolution animation that lags?
« Reply #40 on: 20 Jan 2020, 22:03 »
Quote
Dynamic Sprites. These cannot be released until game author tell so by calling DynamicSprite.Delete(), obviously

Wait, if a dynamic sprite goes out of scope (losing that pointer forever), it doesn't get deleted?

Re: Can I improve high resolution animation that lags?
« Reply #41 on: 20 Jan 2020, 22:07 »
Quote
Dynamic Sprites. These cannot be released until game author tell so by calling DynamicSprite.Delete(), obviously

Wait, if a dynamic sprite goes out of scope (losing that pointer forever), it doesn't get deleted?

It does get deleted. I did not want to go into each detail about dynamic sprite, because it's not relevant to the issue.

eri0o

Re: Can I improve high resolution animation that lags?
« Reply #42 on: 20 Jan 2020, 22:11 »
Thanks!
« Last Edit: 20 Jan 2020, 22:21 by eri0o »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #43 on: 22 Jan 2020, 20:20 »
I'm glad, those are valuable insights Crimson Wizard.

It's cool to know all this. I experimented with it, and I was able to reduce the locked sprites to 100 KB in my original game with the video intro.

What striked me however is that it tells me that I have only 131172KB total sprite cache available. Only 131 MB?

I set the Sprite cache to 2 GB in Default Setup.
I saved the game in the editor.
I built the .EXE file.
I ran the game from the editor.
I ran the game over the winsetup file. Same result.

I have 3,84 GB usable RAM.
I have 1,759 GB total Graphic card memory.

Why could it be that I have only  131MB free cache??


Thing is... it does not seem to unlock locked sprites after calling Mouse.ChangeGraphic again.
Ok, good thing we also talked about the other means to preload sprites! It's always good to find out a little bit more beyond what seems relevant at the moment!

I also found another bug, related to locked size counter
Does the locked size counter actually have a limit?

I also removed obligatory player's view precaching. That made game startup almost instant for me.
Same for me, with your plugin there is no frozen black screen.


Side note: The character who's view sprites are locked into cache is always the character ID 0. I tried setting different characters as player anywhere in the scripts before the room was loaded, but that did not work (maybe it could be possible if you communicate directly to the machine...). I think it's not the first player's view, but simply Character ID 0's view that is being locked.
In order to reduce locked sprites I set character ID 0 to an empty view and created a different character whom I set up as my player.

Also interesting to know: the Speech, Idle and Blinking view are not being locked into cache. Only the normal view.
« Last Edit: 22 Jan 2020, 20:32 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #44 on: 22 Jan 2020, 20:34 »
What striked me however is that it tells me that I have only 131172KB total sprite cache available. Only 131 MB?

I cannot answer this, what are other numbers in the message? It should say "Sprite cache size: X (limit Y, locked Z)".

Does the locked size counter actually have a limit?

Yes, technically it's 4 billion, as a 32-bit unsigned integer, but it is not used for anything but statistics.

The character who's view sprites are locked into cache is always the character ID 0. I tried setting different characters as player anywhere in the scripts before the room was loaded, but that did not work

You can set it in the editor, by opening a character for edit and pressing "Make this the player character" button (it's right above the view preview).
« Last Edit: 22 Jan 2020, 20:37 by Crimson Wizard »

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #45 on: 31 Jan 2020, 00:04 »
what are other numbers in the message? It should say "Sprite cache size: X (limit Y, locked Z)".
It says:
Code: Adventure Game Studio
  1. Sprite cache size: 78319KB (limit: 131172 KB, 100 locked)
But actually don't worry, it's fine.
As soon as the sprite cache size surpasses the limit, the limit grows with it, so it's not actually a problem for me.
I thought the limit defines the maximum cache size.
You can set it in the editor, by opening a character for edit and pressing "Make this the player character" button (it's right above the view preview).
Oh yes of course, you're right. Been so long I used the button, I didn't even see it! Thanks.


And anyways, I'm happy you also found a few things that can be improved in the engine and that can make the program better.
« Last Edit: 31 Jan 2020, 00:07 by TheManInBoots »

Re: Can I improve high resolution animation that lags?
« Reply #46 on: 31 Jan 2020, 00:34 »
It says:
Code: Adventure Game Studio
  1. Sprite cache size: 78319KB (limit: 131172 KB, 100 locked)
But actually don't worry, it's fine.
As soon as the sprite cache size surpasses the limit, the limit grows with it, so it's not actually a problem for me.
I thought the limit defines the maximum cache size.

It should! so... weird. But if you are running that test build I made, maybe I broke something else unintentionally...

TheManInBoots

  • Epically wrote function to declare an int
Re: Can I improve high resolution animation that lags?
« Reply #47 on: 01 Feb 2020, 20:55 »
Hm... It's actually when I build and run the normal game from the editor. And I tried it out, it's the same when I start it via the winsetup.
This sprite cache seems to be a real trouble maker!
You told me about the counter that is inaccurate. The sprite limit is not very accurate now as well it seems. Maybe I'm just interpreting it wrong.
However I wonder if multiple inaccuracies like that could also lead to game crashes in more extreme situations, like high resolution animations.

EDIT: Just to clarify what I meant by it, because I talked about inaccuracies before in this thread:
If the game does not keep track correctly of the statistics (the sprites, the maximum sprite cache etc.) maybe some calculation will create an error or the engine believes sprite cache is full even though it isn't.
« Last Edit: 05 Feb 2020, 03:20 by TheManInBoots »