Rm Mv - Update functions in my plugin

Status
Not open for further replies.

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,708
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi people!

Well, I have lost account of how many times I rewrote my plugin... But I hope that is the last one!
It is a plugin that adds new sprites to the timer. And I'm unsure about the performance of the update functions of them.

I have made two versions:

1 - Used only the Sprite_Timer and made every other sprite inside. Like the gauge sprite:

this.gauge = new Sprite();
this.gauge.bitmap = new Bitmap(96,48)..

And so on.
There is a maximum of 7 sprites new.
Although I divided it with comments and proper functions names(Sprite_Timer.prototype.gauge...) I think that is a little unorganized.

So here, the Sprite_Timer.prototype.update carries all the update functions to all sprites.

2 - Made a class sprite for every sprite:
Sprite_timerBackground.prototype...
Sprite_timerGauge.prototype...

That seems cleaner to me, and more readable.

But now I have an update function for each sprite.

________________________________________________________________________________

So if before(method 1) I have made an only one check in Sprite_Timer that goes for every sprite:
Code:
Sprite_Timer.prototype.updateBitmap = function() {
    if (this._seconds !== $gameTimer.seconds()) {
        this._seconds = $gameTimer.seconds();
        // update all things that need update
    }
};
Now(method 2), in some sprites, I have this check again in the other update functions, in 3 or more times, because other sprites need the update to, like the gauge one for every second the timer goes.

So, how do you think about that?
Should I stick with method one? Or go with method two for a more readable code?
 

pasunna

Veteran
Veteran
Joined
Feb 3, 2019
Messages
529
Reaction score
275
First Language
thai
Primarily Uses
RMMV
um... it's advanced than my knowledge
but why not test by yourself with performance
like fps or loading time etc

but... if by my self
I prefer one container
so I can move/scale it around
and other piece just move follow with already setting format
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
168
First Language
English
Primarily Uses
RMMV
Hello Eliaquim!

Does the second option perform more updates than the first or do they do the exact same updates per second just in different orders? I agree the second one feels more organized but I can't tell whether it's more workload or just a different route to the same solution.

Seems like it could be a big O notation issue but it might aswell not be. I'm just saying the same thing in different ways now aren't I :yswt:

I'd go with the fastest CPU wise but if there's no meaningful difference I'd go with the most structured/aesthetically pleasing one.
 
Last edited:

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,708
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
@pasunna thanks for the answer!
The problem for me to test is that my desktop is a good one, so both methods I get 60 fps. =/

@ozubon thanks for the answer!
Does the second option perform more updates than the first or do they do the exact same updates per second just in different orders?
In method one and two they do the exact same updates, but in method two, although they will still do the same updates, they will repeat some codes again for example, we have this function below that have an if statement:

JavaScript:
Sprite_Timer.prototype.updatePerSec = function() {
    if (this._seconds !== $gameTimer.seconds()) {
        this._seconds = $gameTimer.seconds();
        // do things
    }
};
In method 1 there is the update function:
JavaScript:
Sprite_Timer.prototype.update = function() {
    Sprite.prototype.update.call(this);
    this.updatePerSec(); // made the if statement check and update all the things that must be update.

};
In method 2 this would be like this:
JavaScript:
Sprite_Timer.prototype.update = function() {
    Sprite.prototype.update.call(this); // called one time
    this.updatePerSec(); // made the if statement check and update this sprite

};

Sprite_timerGauge1.prototype.update = function() {
    Sprite.prototype.update.call(this); // called two times(repeating)
    this.updatePerSec(); // made the same if statement check again(two times) and update this sprite

};

Sprite_timerGauge2.prototype.update = function() {
    Sprite.prototype.update.call(this); // called tree times(repeating)
    this.updatePerSec(); // made the same if statement check again(3 times) and update this sprite

};
I agree the second one feels more organized but I can't tell whether it's more workload or just a different route to the same solution.
The same here! This is what I want to know xD
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
Personally, I might be inclined to use the first option, primarily because it means I'm not repeating code and it doesn't offend my way of thinking.

In terms of performance though you're going to be calling the inherited update method on each sprite the same amount of times and provided your custom update code isn't different between the two options these will be run the same number of times as well. All that's different is that you're running the first two lines of updatePerSec an extra 2 times in option 2 - I'm going to hazard a guess and say that the performance differences are negligible.

Keeping your code readable for yourself is incredibly valuable (I know because I'm currently suffering the consequences of not doing this) so if option 2 makes more sense to you I'd say go for it.
 
Last edited:

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,708
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
@Silva Got it...
but in case of the inherited update, I can do this to prevent it(overwrite the function)?
Code:
Sprite_timerBackground.prototype.update = function(){
return; // or leave in blank...
};
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
In theory you could. Though the inherited update method (provided you're using Sprite) isn't really doing anything unless it has children (just "forEach" on an empty array), so you'd probably only be saving 1/100th of a millisecond in processing time per update.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,708
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi people! I ended with the first option after all.
Thank you for all opinions!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,862
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top