Sign in to follow this  
_Engine_

Global Properties and modules

Recommended Posts

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. Edited by _Engine_

Share this post


Link to post
Share on other sites
module has these:

CompileGlobalVar()
int id = GetGlobalVarIndexByDecl()
[url="http://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_module.html#a0998d375ca1de02bc72f4544806da58c"]GetAddressOfGlobalVar[/url]()

Share this post


Link to post
Share on other sites
[quote name='_Engine_' timestamp='1343013000' post='4962121']
Hi!

I need bind not just complie. So looks like AngelScript has serious limitation ((((
[/quote]

GetAddressOfGlobalVar() does what you want.

you first compile your variable, then get its address.
assign anything you want to it.

Share this post


Link to post
Share on other sites
You can use [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_access_mask.html"]access masks[/url] to specify which modules should have access to which global properties registered by the application.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_dynamic_config.html"]configuration groups[/url].

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:

[code]
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);
}
[/code]

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

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

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 (((

Share this post


Link to post
Share on other sites
It's true, "using namespace" is not yet implemented.

The whole namespace feature is still a relatively fresh implementation. It was first implemented in version 2.22.2. I will continue to improve the namespace feature over coming releases, but first I want to allow it time to mature enough to remove most of the bugs before adding more complexity to it.


I'm pleased you managed to implement what you had in mind. Please don't hesitate to post here if you find some other features you'd like to see implemented in AngelScript.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this