Multiple Parallax Lag Reduction

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
Hey there...

So I have been experimenting with adding multiple parallax backgrounds in to my current project; however, I have encountered the issue of "when parallax is initialized it causes temporary FPS drop, from 60 down to about 30-40 for 1 second".

The parallax script I am using stores all parallax info in a customization module. It then checks against a global variable (variable is attached to a new class made for the parallax data) to see if the image is able to be displayed.

My first thought was that Im pre-loading too many images; however, this is not the case as I have the same FPS drop whether i initialize 1 or 9 parallax's.

The initialization happens before a map transfer and is then displayed when transfer is complete. It is at this point the FPS drop occurs.

So, I am wondering if any other scripts have experienced similar issues when creating their own parallax scripts and if so, what did you do to counter this and reduce the FPS ?

I am currently testing various methods in order to optimize efficiency and I would appreciate any input you guys may have :)

Thank you in advance.
 

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,311
Reaction score
485
First Language
French
So I have been experimenting with adding multiple parallax backgrounds in to my current project; however, I have encountered the issue of "when parallax is initialized it causes temporary FPS drop, from 60 down to about 30-40 for 1 second".
I've the same problem with my battles and my mountains'map (parallax)... I think it's because Rpg maker take some seconds to loads big scripts/maps. That's probably why pro made loading screen ?

Anyway, I'm also interest in a way to rise my FPS.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
RPG Maker loads all the scripts at startup... well

It loads all Modules at startup, it then triggers the data manager module method to start game, which in turn starts the title scene and then scripts are accessed when required from there on in.

Large Maps do cause a little lag though, depending on whats happening on the map in question, but my map is medium sized, not too large and was functioning with minimal FPS drop before I added this script.

The only time (in my opinion) that lag is caused is when code is inefficient or your computer cannot handle the game, which is my main concern as I know my computer can handle it , which means its my code thats "funky" ... :/

Edit:

You state that "pro made loading screen". I am unsure what you mean by this, could you elaborate please.

Edit 2:

Its also worth mentioning; I only encounter the FPS drop the FIRST time I enter the map in question. Ifi exit the map (after FPS drop) and then re-enter the FPS is fine.
 
Last edited by a moderator:

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
Edit 2:


Its also worth mentioning; I only encounter the FPS drop the FIRST time I enter the map in question. Ifi exit the map (after FPS drop) and then re-enter the FPS is fine.
That's pre-cacheing isn't it? When images are loaded for the first time, they take a while to load depending on the image format. For example, if your parallax is JPG for some reason, it takes forever if there's a lot of images. Try making a test map with bmp files, you'll find that it's faster.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
JPG and PNG both require additional processing time to decode the data, whereas bitmaps can be read relatively quickly cause it's uncompressed data.


This is the main trade-off between filesize and performance.
 
Last edited by a moderator:

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,311
Reaction score
485
First Language
French
You state that "pro made loading screen". I am unsure what you mean by this, could you elaborate please.
Professional make loading screen to load theinr maps/scripts (whatever reasons).

For example in Skyrim ; fans removed the loading screen when you enter the city (they wanted 100% open world), they discovered it made the game lag when you enter city.
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
They have loading screens to cache in the data. If not then they'll see the game loading the materials before it's ready to be playable.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
That's pre-cacheing isn't it? When images are loaded for the first time, they take a while to load depending on the image format. For example, if your parallax is JPG for some reason, it takes forever if there's a lot of images. Try making a test map with bmp files, you'll find that it's faster.
Yes, my issue only occurs when the images are initially loaded. OR when the visible layers change and a new layer is added.

I will convert my png into .bmp and see how that goes :)

Thanks for the tip.

Professional make loading screen to load theinr maps/scripts (whatever reasons).

For example in Skyrim ; fans removed the loading screen when you enter the city (they wanted 100% open world), they discovered it made the game lag when you enter city.
Ahh, I get what you mean now.

I thought you meant someone (alias name = pro) had made a loading screen script :p

JPG and PNG both require additional processing time to decode the data, whereas bitmaps can be read relatively quickly cause it's uncompressed data.

This is the main trade-off between filesize and performance.
On this note, I had tried to save my Bitmap into a public variable, like so ...

  def initialize(id)    name   = "Fog_#{id}"    hue    = 0    @image = Cache.defog(name, hue)  endWhich works fine; however, when i then try to save the information within this class the game does not allow it.

I'm not sure exactly why the game in not capable of retaining such simple information as a bitmap... 

Just figured that was worth mentioning :p
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Bitmap doesn't define functionality for marshaling. You will need to write your own.


Or get one from someone else


http://forums.rpgmakerweb.com/index.php?/topic/7588-garycxjk-marshal-dumpable-bitmap-data/


I honestly don't know why you would even want to SAVE image data when you're saving your game. You're going to have massive save files.


If you don't intend to save it, then you'll have to modify the save/load data to ignore the particular variable (but then you need to reload it again somehow if you need it again)
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
I didn't even think it would have been a marshaling issue :/

Thanks for the link, seems this little script will come in handy if I want to continue down the route of pre-cache-ing all images and saving them to variables to be pulled into view at a later time.
 

This method seems to reduce lag when changing the visible images; however, its still causing problems with the initial loading of all images.
Something tells me that i am never going to be able to fully remove all lag from the initialization process :(

Edit:
I notice you are mentioned within this script for the methods which capture the bitmap data. As this is the only thing I really need, I ask which script it was that you wrote that has these methods.
I would quite like to see what you done and how u done it :)
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
It's this stuff, for getting pointers to the different structures in memory.

Code:
rdata_ptr = DL::CPtr.new((object_id<<1)+16, 4)[0, 4].unpack('I')[0]bm_info_ptr = DL::CPtr.new(rdata_ptr+8, 4)[0, 4].unpack('I')[0]bm_data_ptr = DL::CPtr.new(bm_info_ptr+12, 4)[0, 4].unpack('I')[0]data = DL::CPtr.new(bm_data_ptr-((height-1)*width*4))data
I think zeus81 wrote it.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
Sweeeet. I was hoping it was that exact piece of code (or that method).

It seems that its only that small bit I would need to use from the whole script :)

I remember trying to research the DL::CPtr class (about 6 months ago) and it just blew my mind. I should probably have another glance and see if anything stands out now :D

Edit:

So, I changed my image types to bmp images. This causes more issues and fixes none :/
The game is somehow not capable of making plane's using BMP images.
It also changed the color of my fogs :/

Went back to png...
 
Last edited by a moderator:

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,268
Reaction score
1,422
First Language
English
Primarily Uses
RMXP
Standard bitmap format does not include an alpha channel. You must use something like a RGBA or ARGB bitmap format if your images contains transparancy, though I do not know if those formats are supported.

Anyway actually using raw bitmaps may decrease performance since the IO can be quite taxing. A couple of years ago I did some testing for RPG Maker XP and loading the files as png was significantly faster. (You probably can construct images where the bmp would be faster to load). How it is with an ssd I dunno.

Loading resources from disk takes time. You may have to deal with a minimum time.

How much memory does it take to store all the images in the memory? Measure it, maybe storing all is feasible.

Assuming that is the case for simplicity I suggest considering a couple of options:

  • Use a loading screen. Conceptually you can follow this code: http://pastebin.com/cCN8g9Bb
    Be sure that anything you load using the thread is not used in the loading screen.
     
  • Load the images over time. For example you could load an image every couple or several frames. Where you need the images you may have to deliberately load any images not yet in memory. If any image is so large that it alone causes lag then you can consider splitting it up into multiple files and let your script stitch it back together.

The concepts are still workable if the memory consumption do require you to put a limit on the cache. Likely any typical caching you'd want your most commonly used images to stay in the cache and remove less frequently used ones. But only worry about that if the need arises.

Do not take what I have written here as the sole options, always keep an open mind for more potential solutions.

*hugs*

 - Zeriab
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
It seems that storing the bitmap of the image on a variable is not a viable option :/
It works fine and all, but I still have the problem of FPS drop the first time the data is recalled, which defeats the whole point of the idea -_-

And as Tsukihime mentioned, it makes the save files larger :(

@Zeriab..
I'm trying to stay clear from loading screens. I feel that they make any built up intensity (while playing the game) evaporate(slightly)...
Like, you just slashed your way though a huge dungeon... the boss is in the next room... load screen causes delay... 

I'm trying to make my map transitions as seamless as possible.

I like what you suggest about having the game load each image separately on different frames...

I'm now thinking would it be 'wise' to load all of my fogs upon game launch an then simply 'hide' any that shouldn't be visible at that time. Easy enough to make the update method ignore all images that aren't currently visible..

Just trying to get the best method possible ^_^
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
Edit:

So, I changed my image types to bmp images. This causes more issues and fixes none :/

The game is somehow not capable of making plane's using BMP images.

It also changed the color of my fogs :/

Went back to png...
Oh no you misunderstood my post, I was merely explaining about compression and such and why things like that happen. D:

I highly recommend using a loading screen though, I am using one myself because I have the same problem for my game.
 
Last edited by a moderator:

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,311
Reaction score
485
First Language
French
I highly recommend using a loading screen though, I am using one myself because I have the same problem for my game.
Event or script ?
 
Last edited by a moderator:

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
Nah it's a customized one. Loading scripts are usually customized for certain areas IIRC that actually needs it :'o
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
It seems that storing the bitmap of the image on a variable is not a viable option :/


It works fine and all, but I still have the problem of FPS drop the first time the data is recalled, which defeats the whole point of the idea -_-


And as Tsukihime mentioned, it makes the save files larger :(
That's if you're saving it in the save file.


If you just load it into Game_Temp or something you should be fine.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top