How to keep the sprites updating while running a really slow function

Shoukang

Veteran
Veteran
Joined
Jan 28, 2021
Messages
120
Reaction score
118
First Language
Chinese
Primarily Uses
RMMV
So I'm developing the SRPG Engine plugin and one of the functions requires quite a long time to run(about 500ms). While running that function, all the sprites will stop updating, and the screen freeze. The function is about AI moving and targeting, which includes complex route searching, tile evaluation, and target evaluation, so it can be very slow when a battler has a lot of large range AoE skills and high mobility.
To simplify the situation, say you have a function like this, and it's triggered by an event:
JavaScript:
var sample = function(){
    for (var i = 0; i< 20; i++){
        for (var j = 0; j < 100000; j ++){
            var dosomething = 'dosomething' //dosomething...
        }
        //I want to put some code here to update sprites.
    }
}
After you trigger this event, the game will freeze for about 0.5s.
Is there a way to update sprites after each inner loop?
I already tried SceneManager.updateScene(), and some other methods to update the sprites, they won't work.
I feel like updating the frame is controlled by the window object, but I have no idea how to force it to update the frame.
Thank you for you help in advance.
 
Last edited:

dopan

Veteran
Veteran
Joined
Mar 27, 2020
Messages
1,101
Reaction score
568
First Language
German
Primarily Uses
RMMV
no idea what you are trying to do, but as far i know, the function that is used to updated char sprites is:

Sprite_Character.prototype.updateCharacterFrame = function() {

it can be found in the default "rpg-sprites" plugin, its also used in a few srpg plugins:
in the srpgCore this function is used for the "E,X,A", and its used for the MapStateOverlay which i added with my "SRPG_mapStateOverlay-Plugin"..
I also made a "non srpg plugin" to add loaded imgs to the $gamePlayer, which uses this function..
And its used on the "unitMapInfo"-plugin, which shows the hp bar on units ect..

I am pretty sure by default this function also updates the event char Sprite imgs ect..
-----
If i somehow can understand better what you want to do and why that stops the sprites update, i might get better ideas, but at the moment thats all ,..sry.
 
Last edited:

Shoukang

Veteran
Veteran
Joined
Jan 28, 2021
Messages
120
Reaction score
118
First Language
Chinese
Primarily Uses
RMMV
no idea what you are trying to do, but as far i know, the function that is used to updated char sprites is:

Sprite_Character.prototype.updateCharacterFrame = function() {

it can be found in the default "rpg-sprites" plugin, its also used in a few srpg plugins:
in the srpgCore this function is used for the "E,X,A", and its used for the MapStateOverlay which i added with my "SRPG_mapStateOverlay-Plugin"..
I also made a "non srpg plugin" to add loaded imgs to the $gamePlayer, which uses this function..
And its used on the "unitMapInfo"-plugin, which shows the hp bar on units ect..

I am pretty sure by default this function also updates the event char Sprite imgs ect..
-----
If i somehow can understand better what you want to do and why that stops the sprites update, i might get better ideas, but at the moment thats all ,..sry.
Just try my sample code in an event and you will understand what will happen. Your code won't work.

--------‐------------------------------
After doing some research on stackoverflow I now believe the solution is to do the inner loop each time the scene map updates, or to use the set time out function. However either way I need to make sure everything else can work as normal while waiting for computing, which seems hard and can break plugin compatibility, but still doable...
 

Latest Threads

Latest Posts

Latest Profile Posts

Steam has announced a new feature to let people switch between playing on PC and on Steam Deck with the same save. I'll come back to add support for it to my steam plugins when the time comes.
Hang on, let me get my glasses...
giphy.gif
Bust Status 1!
Animated lipsynch as well as lineart. Just lineart so far...
Ramona Expression 1-2 L.gifRamona Expression 1-1 L.gifRamona Bust 1C.png
2 FPS 5 FPS Static
SF_People3_7 added!
index.php

Anyone want dynamically soft shadow? :kaohi:
1643106068630.png

Forum statistics

Threads
118,692
Messages
1,117,945
Members
155,819
Latest member
SCW
Top