Engine Events System & Starting Significant Scheduler Engine Revamp
So I made the events system. It works by a class on the JavaScript (engine) layer, and is attached to all entities. There are a couple of functions:
- on: fires on event
- once: fires on event only once
- off: clears event callback
- clear: clears all callbacks
Other entities are allowed to access another entitys events, being able to listen or even emit. A game architecture could work like having “manager” entities at the top level of the game which hold different events. For example, an “InventoryManager” entity could have an event for when an item is picked up, it itself can listen to it, as well as any other things that may find it useful.
I’ve also cleaned up the code, and now there is a “game” reference. Eventually, it will have access to more things but as of right now you can access an “inputManager” which holds functions and events for user inputs. It works by attaching a metatable to it and exposing global hidden functions to call to my JavaScript engine code.
But a huge problem showed up, the way I was running scripts. Before I thought just a simple coroutine running with a timeout for delays was just fine, but I was super wrong. If a callback from an event is fired and the function wants to do something, like call an external function or wait, it completely breaks. Why? I didn’t know and it took me a lot of time to find out. It’s because the callbacks aren’t a coroutine too. This is when I realized why something like Roblox has a full blown scheduler.
So I’ve been planning and starting on the scheduler engine. It has to handle a lot of stuff, including managing when scripts run, including WHEN they want to run (next frame, in 3 seconds, etc) and track if they are causing issues by keeping track of their budget. Everything will need to be in a coroutine coordinated by the scheduler. Including callbacks from events too. It’s going to be pretty complicated I think, requiring a rewrite of the entire scripting system.
I also just encountered a lot of bugs. And I fixed the errors from Wasmoon including the entire JS stacktrace for no reason too.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.