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

Shoukang

Veteran
Veteran
Joined
Jan 28, 2021
Messages
119
Reaction score
115
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,099
Reaction score
565
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
119
Reaction score
115
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 Profile Posts

I just successfully tested having events check if specific actors are in a particular party slot and then changing image to match. This will let me make scenes take into account who is in the party at the time and arrange them accordingly - this is important since I'll have extra actors beyond current party. The script used is the same from MV and is compatible with my current core plugin setup in MZ. Thank goodness.
That awkward moment when you're talking about thinking about writing a limited shop stock plugin for MZ and then find out you already wrote one...last May. My memory is so bad.
When I open my project and I'm like, hell yeah.
Some drawings I made in Lapis, one day I intend to involve them in some RPG Maker project.
* maybe two wall frames
*or some sprite flower tiara, or maybe it inspires someone to do something.
bdd19b62e539d17b3b00cc3d63034f7d.jpg

fcca5c8471b34483da8e032cfe579275.jpg
Step by step, I am coming back.

memorial.png

Forum statistics

Threads
118,424
Messages
1,115,842
Members
155,375
Latest member
CrazyCream
Top