zacharycarter / zengine

2D | 3D Game development library
157 stars 13 forks source link

Hot loading framework #38

Open define-private-public opened 6 years ago

define-private-public commented 6 years ago

I wrote about hot loading w/ Nim over on my website: https://16bpp.net/page/hot-loading-code-in-nim


This is a pretty nice thing to have. It can make game development with compiled languages a little less painful and slow. E.g. If it takes 5 seconds for your game to init on app startup (resource loading, dynamic asset creation, etc), that can really suck, if you need to test out some logic adjustments.

The ideal thing IMO is if someone could script their game using Nim's syntax, then compile it later for performance, but I think this is the next best thing right now. I also don't think that this is something we should implement right away. We should save this for when the engine is a little more mature. But it isn't a bad idea to theorize how to do this at the moment.

Some problems/questions I have:

  1. Lifetime of variables that life in a hot loaded module? Where do they go after we unload/replace a module?
  2. What happens when we throw multithreading into the mix? I don't think it would be good if a DLL gets unloaded in one thread, but that hasn't been synced up with the other.
  3. What about dynamically allocated or GC'd resources? I want to avoid memory leaks.
  4. What are some use cases that we can design this around?
  5. What happens on non-{Windows | Linux | OS X} machines? I don't think JS is hot loadable. And I'm not sure how Android works exactly when it comes to DLLs.

When I first wrote that article about how to do hot loading in Nim @Araq (over the IRC channel) seemed a little interested in formalizing this some way as a macro. I was too busy at the time to work on it. He might be good to reach out to ask about those above problems. It also might be nice for the Nim community in general if this wasn't a zengine exclusive and could be plugged into other Nim projects.