-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script API: add Game.PrecacheSprite() and PrecacheView() #2237
Script API: add Game.PrecacheSprite() and PrecacheView() #2237
Conversation
I can't see It seems, from the comments, this changes the rules so that |
They are locked by passing a "external" and "lock" flags to SetSprite call.
I removed the code that depended on that in commit named "cleaned up mouse cursor caching", it has bit more info in extended description.
The point of this is to have clear distinction between resource types, and knowing how much memory is reserved for which purpose:
If locked sprites count towards the normal cache limit, then they theoretically may fill it up, so that caching stops working. This is probably what happened in the Dave's game. On another hand, locking rule currently allows to lock any size of sprites, then what's the point in counting them towards the cache limit? It's been always like this historically, until I changed it when implementing texture cache. Now I am reverting this back. This is not related to dynamic sprites, as these are tagged as "external" objects that are always locked and not a part of the cache's size. |
But I need to think more about this, because i also had arguments for changing it earlier. Maybe it's more correct to count locked regular sprites along with the cached ones, if we consider "max sprite cache" setting to define the total allowed size of regular sprites in memory. |
Well if I understood, currently regular sprites don't get locked simply because the calls that did so got removed. So this doesn't matter much at this time. Ah, it is necessary to test the Editor too just in case this changes anything there - I think not, but would just check. Edit: I think it may be relevant to mention somewhere that this API is blocking - like if you ask to cache a view it will try to do so in a single game loop and freeze that frame if it takes too long. |
Avoid remembering sprite bitmap pointers in an array. Only use these locally in functions. Removed obsolete bits.
43049c1
to
47f2df3
Compare
I removed the change to the locked items calculation, but added a comment about this to ResourceCache class. I think this has to be rethought when designing a better resource management for AGS, including giving more control to the game developers. |
0bcac63
to
a751371
Compare
Fixed a bug in PrecacheView (forgot to convert from 1-based view index to 0-based). Added diagnostic logging. Example output for precaching that giant "Old Skies" intro animation:
|
a751371
to
28d9bad
Compare
Alright, I guess I will merge this, because this works as expected and may even be useful under some circumstances. |
This is the last thing i wanted to try adding in 3.6.1.
It's been always a problem in AGS that game developers have little control over the resource management. That is a big topic, and has to be thought through well before writing a good API, but I wanted to add couple of simple temporary methods, acting as a replacement for existing hacks that let precache a number of sprites and fix performance in certain scenes.
Precaching a sprite in both of these methods does not load only a raw sprite, but also prepares a texture for it, since we have a texture cache now too, and converting sprites to textures may also have an impact on performance.
An important note is that these functions work according to the existing cache rules. That is - cached assets are normally counted towards the cache limit, and if the limit is exceeded, then older objects will be freed. In addition, the sounds are only cached if their individual size does not exceed "stream_threshold" value from ags config.
This means that in the end the result of using these functions also depends on active game config, and this has to be honestly stated.