Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Dec 2010
Offline Last Active Dec 17 2012 02:53 AM

Posts I've Made

In Topic: Delegates in AngelScript

19 September 2012 - 11:15 PM

The only modifications I made is being able to point a method address: I added a "IsSignatureExceptNameAndObjectEqual" that is the same as "IsSignatureExceptNameEqual" and does not care about the object type, so a funcdef is not dependent on the object type but only on the method signature. It may not be ideal but it was the fastest way for me to do what I wanted.

And actually yes, this method provide a compile time verification of the callback signature, if you implement a callback with the wrong signature, it will not compile at the "SetCallback" as the second argument is a pointer to a funcdef. It would produce this kind of error: (example taken for my script sorry if names are not very relevant)

Compiling BPE
MainMenuForm.bhass (3, 5): INFO: Compiling CMainMenuForm::CMainMenuForm()
MainMenuForm.bhass (6, 27): ERROR: No matching signatures to 'CButtonEventHandler::SetCallback(CMainMenuForm&, OnChallengesClick@const)'
MainMenuForm.bhass (6, 27): INFO: Candidates are:
MainMenuForm.bhass (6, 27): INFO: void CButtonEventHandler::SetCallback(IEventHandler@, ButtonEvent@)
(just added an int parameter to the callback method)

So even if the error is not very clear with current implementation, it is triggered when the callback signature is incorrect at compile time.

I didn't think of the CScriptHandle that would have been cleaner indeed. But now the product has been released so it may be for the next one :P.

In Topic: Delegates in AngelScript

19 September 2012 - 03:40 PM

I made some delegates system in C++ that I exposed to Angel script in my project with minor modifications of a v2.22.0 WIP of AS (in order to be able to specify a method adress).

This delegate system works with events and subscribers, only subscribers has been exposed to my angelscript (ie AS can catch some Engine event but not raise some event).
To expose briefly how it's used:
I register a funcdef in the ASEngine which will be my signature (for instance void MouseMoveEvent(CMouse@, const CVec2f&in))
Then I expose to the script an "event subscriber" (for instance: CMouseMoveEventHandler) that declares a method "SetCallback" which takes in our exemple (IEventHandler@, MouseMoveEvent@). IEventHandler is an empty interface that I declared so AS classes can register and catch events simply by inherit from it (there may be better solutions, and maybe there already is a hidden common parent class to all script classes)

After that all Game Engine that have events expose a RegisterToEventxxx and a UnregisterFromEventxxx (in our exemple RegisterToEventMouseMove(CMouseEventHandler@+) / UnregisterFromEventMouseMove(CMouseEventHandler@+)

Then the class script declares an EventHandler, implements the "callback" method and all is done
(this is pseudo code and may contain syntax errors)
class CScriptCatcher : IEventHandler
	 	 m_MouseMoved.SetCallback(this, @OnMouseMove);
	 private void OnMouseMove(CMouse@ _pMouse, const CVec2f& _vDelta)
	 //Do some stuff here to hande mouse move
	 private CMouseMoveEventHandler m_MouseMoved;

There certainly a better way and a better interface to use the idea to be a little more lightweight for the user, but it might help you to have an idea on how things could be done.

For the delegate implementation in C++, it's an event class that holds a list of generics subscribers using templates (because the system is primarily used with C++). Subscribers are only a "this" pointer and method pointer OR a function pointer so delegates can be either method members with a this or a static method / a function.

Hope this might help ;)

In Topic: Problems in C++ header paths in xCode

08 September 2012 - 12:44 AM

Ok, it seems that I finally found a solution. Adding a custom Build setting "USE_HEADERMAP" set to NO stopped the confusion between headers. It seems that xCode uses a "magic recipe" to found your headers (the heade map), and this command disables it. Magic recipes are always baaaad :)

In Topic: Odd thing with references

02 February 2012 - 03:44 PM

Okay, I'm just dumb, but the solution may help others in the future:
By looking to the byte code, I realized that the return of GetString is copied and stored in a temp local variable. My String class was declared as POD with no copy constructor so the string was copied "as is". Removing the POD flag and adding a CopyConstructor did the trick and solved my problem as the copy is now correct.

In Topic: Garbage collection bug?

28 October 2011 - 07:03 AM

Thanks for this report.

While the root cause was the lack of the GC behaviours, I've made some changes to make the library more robust in this scenario. Instead of crashing due to attempting to call a method that no longer exists, the engine will report an error message to the message stream and then simply skip the destruction the objects that couldn't be destroyed due to circular references with application objects. This will cause a memory leak, but at least it won't crash the application.

I just got the branch on SVN, this change is very usefull and save me a lot of time to see what classes causes some troubles and see if the game is still holding some references when it shouldn't! Thanks!