Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

- - - - -

Delegates in AngelScript

  • You cannot reply to this topic
25 replies to this topic

#21 Andreas Jonsson   Moderators   -  Reputation: 2321

Like
0Likes
Like

Posted 19 January 2013 - 01:28 PM

1. Correct. Holding a pointer to the method will need to increase the reference count of the object to guarantee the object is alive when the method is actually called. 

2. Yes, the delegate will hold a pointer to both the object and the method. 

3. That is the dilemma. For now I will not bother with weak references, so a delegate will initially hold a hard reference to the object. The garbage collector is already capable of resolving circular references that may arise, so this shouldn't be a major problem.

 

The difficulty with weak references is more a design issue than the actual implementation. The weak references must be generic so the script compiler can build the code for them, but they must also not add a performance penalty where they are not used. I'm toying with several different ideas for this, but so far I'm not ready to start implementing weak references in AngelScript.


Edited by Andreas Jonsson, 19 January 2013 - 01:52 PM.

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

Sponsor:

#22 Jake Albano   Members   -  Reputation: 358

Like
0Likes
Like

Posted 19 January 2013 - 01:48 PM

but so far I'm ready to start implementing weak references in AngelScript.

 

Was this a typo? It seems you meant not ready.



#23 Andreas Jonsson   Moderators   -  Reputation: 2321

Like
0Likes
Like

Posted 19 January 2013 - 01:51 PM

Indeed. Thanks for pointing it out. 

 

I've corrected the original text.


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

#24 vroad   Members   -  Reputation: 126

Like
0Likes
Like

Posted 26 March 2013 - 09:19 AM

I tried to implement weak reference in AngelScript first.

This modification seems working, but sample crashes when I use this test addon in script.

 

https://gist.github.com/vroad/6f9961e5cd635b1e28c2



#25 Andreas Jonsson   Moderators   -  Reputation: 2321

Like
0Likes
Like

Posted 26 March 2013 - 04:32 PM

Thanks for the contribution. I'll review it carefully when I can and see if it is something I can commit to the svn. 


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

#26 vroad   Members   -  Reputation: 126

Like
0Likes
Like

Posted 27 March 2013 - 08:47 AM

Oops, I made some mistakes in code.

I successfully fixed some problems in weakref addon code.

I posted new revision of the patch to gist.

 

Is this best way to implement weak reference? I heard about the technique called "reference counted boolean" for the first time in Thiago Macieira's blog.

 

Continue using QPointer » Thiago Macieira's blog

http://www.macieira.org/blog/2012/07/continue-using-qpointer/







PARTNERS