Monarch preload

Hello. I wanted to load game related collection only when game starts not when I’m loading the main menu. So it was done, but with more and more animations the loading of these collections becomes more visible. Current load/unload structure is like this:
Main menu → loads Game
Game → can show (and load) various pop-up collections which can also be hidden after use
Game → loads Main Menu when we are getting back from the game.

Idea is to have all pop-up screen preloaded during the load of the Game from Main Menu. And unload them (if they weren’t shown) during the Menu load. I can use monarch.preload. And it will preload it, but only ones. If I hide this screen (and this is natural behavior) it will require preloading again.

If the collection is preloaded from the beginning (via boolean in collection proxy setting) it will always be preloaded. But in this case, I will need to manually clean guis in that collection (which I really do not want to do :upside_down_face:), as it will retain all information from the last game.

So is there a way to ‘clear’ always preloaded collections or somehow preload collections for some period with options to unload it manually? I am also open to other suggestions)

P.S. All pop-up collections mentioned above basically consists of one or two guis elements. They were put into separate collections to not to bother with their cleanup after each call.

I’m not 100% sure I understand the problem. Why don’t you want to use monarch.preload() on the popups?

I do. But it’s preloading it only once. So if in the loading of the game I preload all popups, I can use them only once. After monarch.hide() it will be unloaded for the next monarch.show().

Ah, I understand. What if we add an option to keep the popup preloaded somehow? It could be an option to monarch.hide():

-- hide screen but do not unload resources
monarch.hide("some_screen", { keep_loaded = true }, cb)

The same could be done for monarch.back()

-- go back but do not unload resources for current screen
monarch.back({ keep_loaded = true }, cb)

Or it could be an option to monarch.preload():

-- preload and keep screen loaded even after navigation using hide() or back() (but not after unload())
monarch.preload("some_screen", { keep_loaded = true }, cb)
2 Likes

I think it’s best to use that option. But it’s up to you anyway)

Could you please create a ticket on GitHub and I’ll try to work on it this evening?

4 Likes

Done.

1 Like

I’ve added a keep_loaded option to monarch.preload() and released a new version. The new option will ensure that a preloaded screen. doesn’t get unloaded due to a navigation event.

3 Likes

Thanks. Gonna test it soon!

I’m getting such error when I’m trying to use monarch.unload()

ERROR:GAMESYS: The collection /Tasks/Tasks.collectionc could not be disabled since it is not enabled. Message 'disable' sent from Main:/4.Tasks#screen_proxy to Main:/4.Tasks#Screen.

Hmm, ok, could you please provide steps to reproduce?

Here is the minimal setup that shows it.

Zooconomy minimal.zip (2.0 MB)

Thanks. I’ve added a check to prevent this error. The problem was that you unloaded a screen which was not shown but preloaded.

1 Like

Actually it also appeared when screen was shown, but later hidden. Anyway it seems that it should work fine this time. Gonna check more tomorrow

@britzl I’m back and have some experiments with preload. It looks like it still is not unloading properly.

So, during hte first load of the map, while desired screen is preloaded, monarch log is showing that it is preloading:

preload()	hash: [Tasks]
DEBUG:SCRIPT: change_context()	hash: [Tasks]
DEBUG:SCRIPT: preload() preloading screen	hash: [Tasks]
DEBUG:SCRIPT: preload() proxy
DEBUG:SCRIPT: preload() preloading done	hash: [Tasks]

After loading back to main menu it should be unloaded

unload()	hash: [Tasks]
DEBUG:SCRIPT: change_context()	hash: [Tasks]
DEBUG:SCRIPT: unload() proxy	hash: [Tasks]

During next load of the map with Task screen preloaded, log is showing this:

DEBUG:SCRIPT: preload() queuing action|hash: [Tasks]|
DEBUG:SCRIPT: queue() adding|function: 0x0180270b2ed0|
DEBUG:SCRIPT: queue() next action|function: 0x0180270b2ed0|
DEBUG:SCRIPT: preload()|hash: [Tasks]|

So its kinda not even preloading or acknowledging that its preloaded for example when showing the screen.

DEBUG:SCRIPT: show_in()	hash: [Tasks]	false
DEBUG:SCRIPT: notify_transition_listeners()	hash: [monarch_screen_transition_in_started]
DEBUG:SCRIPT: change_context()	hash: [Tasks]
DEBUG:SCRIPT: load()	hash: [Tasks]
DEBUG:SCRIPT: preload() preloading screen	hash: [Tasks]
DEBUG:SCRIPT: preload() screen already preloaded	hash: [Tasks]

And final(self) is not call during the unloading of the screen.

1 Like

Hmm, ok, I need to look into this. Could you please re-open the ticket on GitHub and add your new findings?

1 Like

It seems that I can’t reopen the ticket, only create new one or leave comments on the old

@russelkgd I’ve reopened the ticket. Could you please provide a clear step by step guide to verify this behavior. I think I know what to test, but I’m not 100% sure and want to avoid guessing.

@britzl thanks.

Here is again a slightly modified minimal project:
Zooconomy minimal.zip (2.0 MB)

So:

  1. If you click on button “No preload show”. It will use regular monarch.show to load level without preloading popup screen.
  2. If you click on button in the middle it will open popup screen.
  3. If you click outside the window it will be hidden by monarch.hide, which will result in unloading the screen and final(self) been executed.
  4. If you click on left button it will return to main menu. This is expected behavior.
  5. If you click on button “Preload show”. It will use preload of popup screen and then regular monarch.show to load level.
  6. If you click on button in the middle it will open popup screen.
  7. If you click outside the window it will be hidden by monarch.hide, but without unloading it. final(self) won’t be triggered. Which is also expected behavior.
  8. If you click on left button it will return to main menu. It will use monarch.unload - to unload popup screen and then regular monarch.show to load main menu. During the process it should unload the pop up and call final(self) there, which is not happening. That’s unexpected behavior. Basically the screen is not unloading.

Ah, I see. Ok, what I did was to make the explicitly preloaded screen act exactly like a screen where the Preload checkbox is ticked. And in such a case any call to monarch.preload() will be ignored. This is in my opinion a bit strange. Calling monarch.unload() should unload a preloaded screen, regardless if it was preloaded via monarch.preload() or on creation using the checkbox. I’ve released a new version which fixes this: Release Monarch 3.7.0 · britzl/monarch · GitHub

3 Likes