Global Properties and modules

Started by
9 comments, last by WitchLord 11 years, 9 months ago
Hi!

Looks like if I declare global properties throught RegisterGlobalProperty method of asIScriptEngine class then all modules have access to that properties. But I need declare global properties for each module. Looks like I can not do that. I can create asIScriptEngine for each module but I need import functions feature. And there are lies library restriction. It is strange that each module have own global properties but i can not bind it. This strange restriction broke all my architecture because i need import feature but now wnen i implement this feature all script logic are totaly broken.
Advertisement
module has these:

CompileGlobalVar()
int id = GetGlobalVarIndexByDecl()
GetAddressOfGlobalVar()
Hi!

I need bind not just complie. So looks like AngelScript has serious limitation ((((

Hi!

I need bind not just complie. So looks like AngelScript has serious limitation ((((


GetAddressOfGlobalVar() does what you want.

you first compile your variable, then get its address.
assign anything you want to it.
You can use access masks to specify which modules should have access to which global properties registered by the application.

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

Hi!

In my case mask is not an option because every module may have global properties with same name. Also Angel Script have another huge limitation - i can not deregister properties. So a realy need way to register global properties of modules. Look like i need to use GetAddressOfGlobalVar() and hack AngelScript.
What do you intend to expose to the modules in this property? Why does the property have to have the same name in all modules?

The registered properties can be removed by using configuration groups.

However, perhaps an easier way is to use virtual property accessors, i.e. a pair of set/get functions that can determine at runtime what module is being worked on. Perhaps something like this:


int get_property()
{
// Determine which module is accessing the property
asIScriptContext *ctx = asGetActiveContext();
asIScriptFunction *func = ctx->GetFunction();
asIScriptModule *mod = ctx->GetEngine()->GetModule(func->GetModuleName());

// Get the property associated with the module. The association
// can be done with a hash map, or perhaps the modules' user data
SomeStruct *ptr = reinterpret_cast<SomeStruct*>(mod->GetUserData());

return ptr->property;
}

void set_property(int value)
{
// Find the property in the same way as in get_property() to set the value
}

// Register the virtual property accessors
void register(asIScriptEngine *engine)
{
engine->RegisterGlobalFunction("int get_property()", asFUNCTION(get_property), asCALL_CDECL);
engine->RegisterGlobalFunction("void set_property(int)", asFUNCTION(get_property), asCALL_CDECL);
}


With the above, the script will be able to use the identifier 'property' to access the module specific value, just like you wanted.


// Script
void main()
{
int value = property; // will call get_property() behind the scene

property = value; // will call set_property(value) behind the scene
}

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

Hi!

My architecture is very simple - my engine support multiscenes. This mean that game splited into severel scenes each scene can be loaded and unloaded whenever this neccesery. This mechanism needed to create streaming. Every scene has one script module and in ?????? module engine register all scene entity as properties. Because scene can be unloaded at any time i need deregister properties associated with unloaded scene entities.

So is i correct understend - before registering propertis of scene i need call BeginConfigGroup and after i done call EndConfigGroup. When I ulnoading scene and removinng script module i call RemoveConfigGroup and this will remove registeret properties?
Yes, that is correct.

Before calling RemoveConfigGroup() you need to make sure there is no script code that still refers to the properties or else the call will not allow the removal, so you'll want to call DiscardModule() and GarbageCollect(asGC_FULL_CYCLE) to guarantee that all scripts and objects that might be referring the properties are destroyed.

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

Hi!

i rewrote some code and now all work as i wanted. Now I declare scene entities in groups in namespace so properties sits in scene namespace. When scene unloaded all scene related global properies are deleted. Also I got another cool feature - all scene entities from any scene are acesseble from any script module throught scene namesapce. Also function import feature works as a charm.

I so happy now :)

But one thing looks like missing - there are no analog in angle script of "using namespace". Maybe I miss something but I have no luck in finding this feature (((

This topic is closed to new replies.

Advertisement