whDefRouter (ex. Defold UI Routing Library)

Thanks Britzl!

async_load was the bit of information I’ve missed. Working well now!

2 Likes

I will update the library with async_load today. Also, I’m not very familiar with Android (I’m another Apple user :slight_smile: ), as I understand there’s no built in support for splash screens like on iOS. If so, I can definitely add a support for a special launch screen. I’ll think on it today.

2 Likes

I believe the router should give the possibility to use “async load” or “regular load” depending the use case.
Async_load is merely a non-blocking load spread over multiples frames if I understand correctly. That wouldn’t be always the best option.

5 Likes

What about a loading screen?

You would have to “regular load” the loading screen scene while “async loading” the target scene?

3 Likes

From what I gathered it’s difficult to create a loading screen with a progress bar that does reflect actual metrics as Defold doesn’t expose anything that would allow you to compare what has been loaded to what’s need to be loaded.
Maybe if you break down your game in a set of collection proxy that you “async_load” one after another, as each proxy would send you a message once it’s done, but that seems contrived and hard to achieve for most cases.

Now, I believe a loading screen with an animation loop can be done using the same method as described before for creating a splash screen. Namely having your “loading screen” collection as bootstrap with in it :

  • the bare minimum to achieve the desired animation.
  • a collection proxy that points to your main collection.
  • a script of the following form:
function init(self)
    msg.post("#main", "async_load")
end

function on_message(self, message_id, message, sender)
    if message_id == hash("proxy_loaded") then
	-- Splash screen must die!
	msg.post(".", "disable")
	msg.post(".", "final")

	-- Show main collection
    	msg.post("#main", "init")
    	msg.post("#main", "enable")
    end
end
4 Likes

Nice example @Nicolas_Darques,

But when you say:

makes me wonder: is there any thread in the forum where this discussion is taking place or took place? Or you’re just refering to this thread?

1 Like

There is already a thread here, even it’s not very detailed:

Actually this thread is about Megus’s Routing library so maybe this discussion would be better off its own thread (in the Defoldmine) or moved to the one cited above.

1 Like

I am currently having a problem with this routing library. I set up my routing table with only the first scene, and then used push to push another scene.

The problem occurs when I call close on the pushed scene, The previous (first) scene shows up and works fine, but I get an error in the debug console:

ERROR:SCRIPT: wh_router/router.lua:64: attempt to call a nil value
stack traceback:
	wh_router/router.lua:64: in function 'next_scene'
	wh_router/router.lua:165: in function 'on_message'
	main/loader.script:27: in function <main/loader.script:24>

Any help ?

Nevermind, found the answer, I was firing the close twice :slight_smile:

3 Likes

Hello everyone! I’ve fixed an issue with the library which could cause crashes when you have big navigation stack or pass complex inputs/outputs/states. Thanks to @AGulev for identifying this! The change doesn’t affect existing code so you can safely update and continue to use it.

I think there is still room for optimizing this, I’ll look into it later. Also another set of updates is coming soon.

8 Likes

Hello everyone! I wonder if anyone actually uses my library in their projects? I’m planning a big update in the nearest couple of weeks and deciding whether to keep it backwards compatible because the updates may not fit good with the existing API. Also, I’m open to feature requests :slight_smile: All the previously mentioned planned improvements will be included in this update.

6 Likes

Begin to publish versions on github and encourage people to use versioned numbers in their lib includes (everyone should be doing this).

I have it included in a few projects but can live with making changes for the better.

2 Likes

I use your library for my game, thanks for implementing this. :slight_smile:

5 Likes

I’ve published the new version of my library and changed its name to whDefRouter.

The new features include:

  • Support animated transitions between scenes
  • Support “Loading…” scene to show while loading big scenes

The API is the same, but there are some new messages for transitions and “Loading.” The routing table format is changed, but it will be easy to convert. Check out the documentation on GitHub or at the Community Page: https://www.defold.com/community/projects/46206/

If you use my library in your project, try to update and let me know of any issues. I’m ready to help anyone :slight_smile:

10 Likes

Hello, as a newbie this library is helping me a lot, but I wonder how to reload the current scene?
I try to push the current scene but it will fail due to the scene already loaded.
Thanks. :bowing_man:

Edit: I already solve my problem by making a function to reload the stage in my scene :smiley:

3 Likes

I think I’ve seen similar requests several times already. I’ll add this to my backlog, maybe I can come up with some nice solution. I usually do it the same way you did it — re-initialize a level inside the loaded scene.

2 Likes

Hi, i was using your old asset and now when i updated and got the latest, the routing doesnt work any more… is it a lot i have to change to make it work again? can i use the old version still and if i can, how do i do that?

There are no releases on the GitHub page: https://github.com/Megus/defold-router @megus.sugem you really should create releases as it becomes a whole lot easier to lock down a specific version of the lib in your game.project file.

You can still lock down a specific version though:

Yes, my bad that I didn’t create a version tags. Well, I asked if people are fine with the new version not compatible with the previous one and they said OK :slight_smile:

Hello. Yes, the new version is slightly not compatible with the previous one, but the fix is pretty simple.

The main change is the routing table. It was extended to support new features of the router. So, you currently have something like this:

local M = {}

function M.first_scene()
    return "main_menu" -- Change to the name of your first scene
end

function M.main_menu()
    return "game"
end

return M

Convert it to the following format:

local M = {
    info = {},
    first_scene = "main_menu",
    routing = {
        main_menu = function()
            return "game"
        end
    }
}

return M

After this change the router should work for you again. Check out the documentation on GitHub on how to use the new features: animated transitions, sync/async loading of scenes and “Loading…” popup.

If you still have issues, let me know so I can help you.

Sorry for the inconvenience. I tried to make the new version as much compatible, but had to do this change.