Rm Mv - Update functions in my plugin

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,060
Reaction score
441
First Language
Portuguese - Br
Primarily Uses
RMMV
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
289
Reaction score
69
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

game chef *muah*
Veteran
Joined
Oct 16, 2018
Messages
39
Reaction score
26
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

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,060
Reaction score
441
First Language
Portuguese - Br
Primarily Uses
RMMV
@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
386
Reaction score
204
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

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,060
Reaction score
441
First Language
Portuguese - Br
Primarily Uses
RMMV
@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
386
Reaction score
204
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.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

It's weird I actually have MORE work to do when stuck at home than before.
The No Travel Game Jam is here! Jump in to make a game in the month of April that takes place all in one town!


Decided to take a stab at video editing.... Even made a clickbait screen. I'm so proud of my sellout ways. :LZSexcite:

Forum statistics

Threads
95,470
Messages
929,390
Members
125,711
Latest member
cst
Top