• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Room persistence for all rooms?

S

Steve Gal

Guest
Hello there, I have a question related to room persistence.

As I understand it if a room is set to persistent upon leaving the room it's current state will be stored in the ram (with the exception of persistent objects ofc) so my question is, is there any way to flush this data out of the ram entirely, for all rooms? Or remotely set all rooms back to not persistent?

I am talking about over 200 rather large and complex rooms so entering them in sequence and resetting is not optimal at all.

Any suggestions are welcomed.
 
You could loop through all the rooms using something like this:

Code:
var _rm = room_first

while ( _rm != room_last )
{
   room_set_persistent(_rm, false)
    _rm = room_next(_rm)
}
 
S

Steve Gal

Guest
Yeah that's the thing, there are 200+ rooms in the final version and some of them are huge, so I doubt this is very optimal.

Thanks anyways.
 
Well, I don't have a 200 room project to test this on, but the code below doesn't actually open each room as it goes through, it just flags the room as not persistent, so it should only take a moment to run. After that, when you go into a room, it will be reset to its initial starting state. I don't know if it will flush the memory of all the persistent rooms but that's something you could test yourself, but it will remotely set all the rooms back to being non-persistent.

If it's the memory usage you are worried about, then that would be another conversation I guess, working out how to save a room state and all its objects without using the persistent flag. Serialising all the room data to a binary file would be one way, but I've never tried that with GameMaker yet.

Oops, forgot one line, it should be:

Code:
var _rm = room_first

while ( _rm != room_last )
{
  room_set_persistent(_rm, false)
    _rm = room_next(_rm)
}
room_set_persistent(_rm, false) // catch the last room because it will be missed by the while loop
 
S

Steve Gal

Guest
Yeah the help documentation never goes into detail on what is actually happening to ram.
Plus I was under the impression(from older posts I found) that you HAD to enter rooms to set their persistence they were likely wrong.

I will test this, thank you for the help.
 
@Steve Gal Ok, so I re-read the GameMaker manual, and it seems you are right, my code will only work if you haven't visited the room already.

Apologies for mis-leading you.

Without knowing more about your game, would setting the room_persistent value to false just before you exit a room you no longer need to be persistent work for you? Or do rooms need to be persistent throughout the whole game?

It's an interesting problem though, it's got me curious, why do you need over 200 persistent rooms. Just wondering if there is another way to do this, I'd be interested to work out a solution.
 
S

Steve Gal

Guest
I had that idea, but wanted to avoid it because of the number of destructible objects in each room on top of the enemies, I guess I have no other choice.
 

TheouAegis

Member
If you can compress the amount of data you store, you could keep the room data inside the game itself rather than in a file.

I haven't tested anything beyond a simple room, but persistence seems pretty efficient to me in terms of memory management. The issue of course is just the amount of work it takes to remove persistence once it's been added. As your project develops, you could probably find someone to help you come up with concise, efficient global array management to store all room data without the need for persistence. Since when using arrays, all you'd need to do is something like global.roomdata = 0 and you just reset all the rooms with one single line of code.
 
S

Steve Gal

Guest
I guess I have no other way than either sticking to the system I used in my first game, with the alteration that persistence is only turned on when you visit the room, and turned off when I need to reset the room.

Thanks again for the suggestions!
 
Top