🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

unRegistering Globals?

Started by
6 comments, last by WitchLord 19 years, 4 months ago
Hey all, I'm trying to figure out the best way to solve a problem I have at the moment. Currently the program im developing loads everything modularly which works well for all concerned however up until now they have just been using globals and objects that I expose manually through the rest of the code. The problem occurs when one of these modules exposes itself to the script, initially this works perfectly and the desired result is achieved. However when that module is removed from memory and then later on reinitiated it results in the object type, the global property and the object method all being reregistered. This cuases the error of multiple functions with the same name and declaration being built, thus crashing when the script is executed. Attempting to fix this I stopped object methods from being re-registered however this results in the script failing on a general error when the global is accessed (probably due to the resident memeory address changing). I have toyed around with several other methods of such as binding (failed, same as the prior error), aswell as releasing modules and then reinstating them, however I'm still unable to get the desired result. So would it be feasible to unRegister a global or all of the associated data such as the object type, global property, and object methods, then just register tham as normal when that code module is loaded. (I've attempted to add this functionality, however I end up breaking the engine) Any thoughts or solutions to this problem? Thanks, Sorry for the long boring post, just throught I'd be thorough on this one.
Advertisement
This is a problem that I've been thinking about lately. As you figured out already there is currently no way of unregistering functions, or globals. The only way an engine can be reconfigured is by creating a new engine and do all the registration again (minus the part you wish to remove) but that also means the script code must be rebuilt.

I intend to include some support for unregistering part of the application interface, but it requires that I rethink some of the internal design of the library. My current thoughts go something like this:

When the application registers functions, types, and globals, it is able to group registrations into some form of modules, by adding a couple of calls like: StartConfigurationGroup("group name"), EndConfigurationGroup(). At a later time the application can unregister an entire group by calling UnregisterConfigurationGroup("group name"). Of course, if any currently built script modules uses the configuration group, the un-registration won't be allowed.

I don't know when I'll be able to implement this though.

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

Yeah, I considered switching my current setup where I have multiple contexts and a single engine and replacing it with multiple engines and a single context. This should work just fine, the only painful part is going through and ensuring that the globals are all registered for the engine that is restarted.

I think your ideas on implementing the unregistration awould be beneficial and I can understand why you need to do a rewrite on some of the handling code in the engine.
When I as modifying the engine my train of thought was to unregister an object type, and have it recursively check for any properties or methods attached to them and then destroy them from the array. which is obviously why the global pointers were all altered and everything broke... The method although hacky at best I dont think wasnt going to work too well.

On a side note, while I was modifying the code I noticed that you have used asCArray for most of the sticky parts of the engine (well all of them, from what I have seen). Have you considered using the std maps or vectors. I know some people arent fond of them (there are other implementations which are "improved"), however in areas where you are searching for a particular entry they allow for a faster result (generally)... its also a bit cleaner as you can use iterators.
Ultimately it comes down to personal preference and I'm willing to bet theres a good reason for not using anything vector based at the moment.
The main reason I use asCArray in the library is to not have to rely on any external libraries. Also I have found that the STL templates are not 100% portable, as they contain bugs in some implementations.

But you are right, there are several places where a hash map or even a balanced tree could make the code more efficient. However, at the moment there are no known critical situations where the gain from exchanging the code is so large as to merit the work needed.

In other projects I do indeed use the STL templates, as I think they are quite convenient to work with.

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

Yeh no your quite right about the portability and such.

Just thought I'd mention I have continued to try and find a solution to unregistering the globals, and Ive otherwise been unsuccessful. Seems everytime I get a little further along I just end up with a bigger problem.

The other reason is I wanted your oppinion on another possible approach to the problem. Like it was stated before the only real way to remove a global currently is to unload the entire engine and then reload it and recompile the script code. Like in another post where to reinitiate a script state, you suggested that the engine be modified so as it would unload and reinitialise a module effectively resetting the state.
Is it possible to extend this to an engine scale (opposed to a module scale) whereas the engine is able to reinitialise itself. Ofcourse this wouldnt so much solve the problem as just reset everything, however it could then be possible to check for the globals that need to be removed and simply no longer include them within the script code and such.
Without disecting the engine Im not really sure if this would work or if it is even feasible.
Sorry if Im just ranting and raving on here,
Thanks
That is basically what I'm planning on doing by allowing the application to group registrations of types, functions, and globals.

Each of these groups would then be separable, and could be removed and replaced individually. The engine would also be able to verify if any of the script modules were holding references to any of the groups and thus not allow the removal until the modules were removed.

The biggest problem that I see is with the IDs for the functions and globals. I will probably have to find a way to make the IDs local for a module so that when a module is compiled (or loaded from a precompiled bytecode) it will resolve these into their global IDs. Basically the same way a module currently imports functions from another module (except that it will be automatic).

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

You could always just have a lookup index for the ID's against the registered modules there in. So a big lookup table or matrix, then just store the functions as normal. Checking the table each time a "global" is requested for its global ID. However if the ID is generated as how I think it is (through the size of the systemFunctions array) would it not be possible for a non unique ID to be generated if an item is removed from the array and a same sized one enetered into it. This would result in the latest two globals having the same ID.

Personally I think one of the hardest things to do is generate unique ID's in a databse app although there are plenty of examples out there (one I use quite reguarly) however I still find it concievable that for 1 in every n'th entry entered it will result in a non unique ID. (I've just pissed off all the database developers and statiticians now, but hey I'm an engineer and anything is concievable if you think about it long enough)

As for removal checking, having a referenceCounter for each group would allow you to track it. Each time a group is requested by the engine its reference counter is incremented and when it is released the reference counter can be decremented, thereby if the counter is not 0 when the group is requested to be destroyed or updated then it can be denied.

As for the grouping itself would the groups behave similarly to the way modules are structured now or did you have something different in mind?

Thanks for putting up with all the questions, and my oppinions by the way I really appreciate it, I think this is an excellent engine you've developed and I plan on using it for all my future applications, so I'm more than happy to contribute where ever possible.

The unique IDs will be generated by letting each module have sequential ids for the functions they use, and then append the module ID. The number of functions a module can access will be limited to 65536, but I think that should be plenty enough. When passing this ID to the engine, it will look up the correct module and find the function from that one. This is exactly how it is done for script functions at the moment.

The module will have to copy the actual function pointer to its own table, so that it is not necessary to make more than one lookup when calling a function. This copy will be made when the bytecode is generated (or loaded).

At first the grouping of registrations will be purely for management, it will not change how the scripts access the functions. Later on, I will probably add the possibility of registering functions and globals in different namespaces.



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