Hey again !
So, the past 10 days I've been experimenting with quite some things, and here is the progress:
- Blend file loading / freeing: Implemented a way to load and unload levels dynamically. Also ironed out some functions to delete objects in the scene before loading a new one. The framework will load the relevant .blend via LibLoad, and free the files which are no longer required with LibFree. All you have to do is to specify what you need, the management is automatic.
- Improved event handling: I added the possibility to add sub event handlers, because in order to trigger events on each tick, what I was doing was this:
Code:
class EventManager(Manager):
...
def post_draw(self, scene):
events.trigger("post_draw%d" % utils.getTick())
And I had to register my events like events.registerCallback(callback, "post_draw%d" % desiredTickNumber)... which was a bit silly.
I mean, it got the job done, and I could make so the callback could be triggered on the next frame by doing desiredTickNumber = utils.getTick() + framesToSkip.
But instead, I made so that you could add sub event handler, on specific events, and make them dispatch calls from the paremeters of the parent ones. Its not clear, I get it. Here is an example:
Code:
# Getting the "main" EventHandler
events = Service.GlobalEvents
# Create a sub event handler on the "post_draw" event.
# You can still register callbacks
events.addHandler("post_draw")
def testA(*args):
print("A:", args)
def testB(*args):
print("B:", args)
# Registering the callback on an event
events.registerCallback(testA, "post_draw")
# Registering the callback on a sub event event
# (test is binded to the "more" event of the "post_draw" sub event handler)
events.registerCallback(testB, "post_draw", "more")
events.trigger("post_draw")
# prints:
# A: ()
events.trigger("post_draw", "more")
# prints:
# A: ("more")
# B: ()
events.trigger("post_draw", "more", "extra")
# prints:
# A: ("more", "extra")
# B: ("extra")
This allow you to bind certain callbacks on "general" events, still allowing you to get the full event argument list, or binding on more specific sub events !
- More documentation: I wrote a bit of document, its far from perfect, but again I would love feedback.
https://gitlab.com/bgez/bgez#bgez-blender-game-ez
Also I uploaded my BGMC game and the improvements I made on GitLab too:
https://gitlab.com/bgez/demos/BGMC26...mc26-prototype
--------------------------------------------
I think the thing that took me the longest was the libload / libfree stuff. I got Blender to crash, with absolutly no error. Like, nothing was written to stdout / stderr. Just a plain crash. This made the debugging extra boring, but I finally got through it. I think I took 3 or 4 days before I got Blender not crashing, trying every line permutation possible, using "prints" everywhere.
At the end of the day, one of the things that was crashing Blender was to end the active camera. As in: "scene.active_camera.endObject()". This just makes the BGE stop. Not even crash. Stop. Nothing happens past this.
You may ask why I was ending the active camera, well... I was just trying to clean the scene, removing every object blindly.
Turns out you should test if you are not about to remove the current cam. Now I know.
--------------------------------------------
What comes next ?
So far I don't really know. I want to use the framework for a bit on the BGMC game I made, keeping using it and pushing it as far as I can until I get something to break in some way, this should allow me to strengthen what's already there, and maybe show me what to add next.
I would really like to think about the way to get networking going. I have a pretty solid foundation as far as I know, with automatic links between Python classes and actual GameObjects in game. I think a system allowing to serialize a particular live object and send it to a server, just to pass it down to another instance of the BGE and trying to synchronize the two could be cool.
I mean, the base seems ready to implement such an abstraction layer around networked ingame assets.
But I'm thinking about the role that the event system will play in all of this. Should I go full callbacks ? I wonder a bit, because sure, supporting entity synchronization is cool, but what if people have other stuff, more general networking messages to send ? The implementation should permit to setup a legitimate server in the BGE, and then on top of this I should build the entity synchronization.
A bit of work here.
I might just chill and try to make levels for the BGMC game, this would free me a bit from this Python frenzy lol.
Bookmarks