Reloading modules on runtime

Started by
0 comments, last by WitchLord 12 years, 4 months ago
Hello,

Excuse me if this is lame question, I tried searching forums for topics regarding recompiling / reloading modules on the fly, something that is so important for scripting, and I couldn't find anything relating to my problem (I found good topic on serialization but thats not the case yet I think). I follow similar pattern as Angel Script's game engine, which means I register GameEntity class for AS then instantiate GameEntity from C++ and pass it to a constructor of controller script. So I have GameObject instance in C++ and it has a member "m_controller" that points to asIScriptObject.

So far I managed to reload all already loaded entity modules by building module again (if I'm correct it removes previous module). It works for all newly created objects but old ones remain unchanged (for example their 3d model or color doesn't change). So I can reload modules as many times as I want, but it only affects new instances of asIScriptObject.

What would be the best way of reloading already instantiated objects, so they change according to changes made in the script file? Lets assume I don't need to keep their current internal state for simplicity (I will worry about it later), but I want the changes that happen in class attributes or methods to be applied to all instances, not only new ones.

Where are we and when are we and who are we?
How many people in how many places at how many times?
Advertisement
To have already existing instances refresh with the recompile you need to find and replace them. This will obviously take a bit of an effort to implement, but unfortunately there is no easy way out as AngelScript doesn't keep track of all objects (only the ones that can potentially create circular references). Start with your own application objects (GameEntity), and then find all the script objects that you reference, then enumerate the properties of those objects to find any other instances they may reference, and so on.

If you wish to keep the attribute values when replacing the objects then there is a serializer add-on that will come in handy.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement