Page 2 of 2

Re: Vector3 copy constructor

Posted: Sun Aug 14, 2011 2:10 pm
by madmarx
Hi,

I was the one to suppress the Vector3 copy constructor (and same for quaternion I think) from Ogre a few years ago.
I did it for performance purpose in debug mode when using for instance some big std::vector<Ogre::Vector3>.
I personnaly would prefer to keep that this way, but I think the performance difference only happens in debug mode.
Anyway, If you found a solution, that is really great jacmoe !

Just my 2 cents,

Pierre

Re: Vector3 copy constructor

Posted: Mon Apr 15, 2013 5:47 pm
by jacmoe
Actually, that crap didn't work.

I've been fighting to get Angelscript to work on my 64-bit Debian box for much longer than I'd like to remember..

I never thought I'd live to see the day that I managed to fix it, but - lo and behold! Angelscript now works with Vector3 and Quaternion (and friends) - also when it's passed around by value sans copy constructor. :D

Code: Select all

-        r = engine->RegisterObjectType("Quaternion", sizeof(Ogre::Quaternion), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK); assert( r >= 0 );
+        r = engine->RegisterObjectType("Quaternion", sizeof(Ogre::Quaternion), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA | asOBJ_APP_CLASS_ALLFLOATS); assert( r >= 0 );
The most important change is from asOBJ_APP_CLASS_CAK to asOBJ_APP_CLASS_CA | asOBJ_APP_CLASS_ALLFLOATS.
Andreas Jonsson wrote: Posted 10 October 2011 - 08:02 PM
I've added an additional flag asOBJ_APP_ALLFLOATS that when used with the registration of the Ogre::Vector3 should allow you to use this type in native functions without wrappers. It tells AngelScript that the class consists only of floats, and will thus allow AngelScript to know that the type is returned in the XMM registers instead of the general purpose registers.
As you can see from the date, I've been trying to fix the issues for almost 1.5 years. :lol:

Re: Vector3 copy constructor

Posted: Mon Apr 15, 2013 5:48 pm
by jacmoe
Just throwing the fix in here so that it might prevent other poor souls from losing their sanity and/or valuable time. ;)

Re: Vector3 copy constructor

Posted: Mon Apr 15, 2013 8:55 pm
by madmarx
That's nice to do it even later. It gives a sense of continuity/not forgotten/not done in vain (pick the one you like).
One of my first posts here was solved 3.5 or 4 years later :D.

Re: Vector3 copy constructor

Posted: Mon Apr 15, 2013 9:59 pm
by jacmoe
I feel better already! :)

Re: Vector3 copy constructor

Posted: Mon Apr 15, 2013 10:15 pm
by saejox
I wish there were c++11 traits like std::is_composed_of_integrals<T> and std::is_composed_of_floats<T>

I looked at all c++14 proposal there isn't one for this. I really wish there was. This blocks my auto generated script bindings generator.

Re: Vector3 copy constructor

Posted: Tue Apr 16, 2013 11:02 am
by Klaim
saejox wrote:I wish there were c++11 traits like std::is_composed_of_integrals<T> and std::is_composed_of_floats<T>

I looked at all c++14 proposal there isn't one for this. I really wish there was. This blocks my auto generated script bindings generator.
The last proposals are not the only ones, there are proposals for reflection but they focus on compile-time, so that would be a solution.
Unfortunately I don't think we'll get any reflection improvements until c++17 (if it's not late) ;___;
The good news is that it is necessary to get networking in good shape, so big companies push the standard to have these (in particular Google, using Protobuf as example in proposals)

Re: Vector3 copy constructor

Posted: Tue Apr 16, 2013 6:55 pm
by jacmoe
Just want to add, so that I don't look like a complete idiot, that the fix above was only possible to apply after changing the way we (in Ogitor) register the reference objects:

Code: Select all

-    #define REGISTER_REFERENCE_BASEOBJECT( name, classname )\
-    {\
-        r = engine->RegisterObjectType(name, 0, asOBJ_REF);assert(r >= 0);\
-        r = engine->RegisterObjectBehaviour(name, asBEHAVE_ADDREF, "void f()", asMETHOD(classname,_addRef), asCALL_THISCALL); assert( r >= 0 );\
-        r = engine->RegisterObjectBehaviour(name, asBEHAVE_RELEASE, "void f()", asMETHOD(classname,_release), asCALL_THISCALL); assert( r >= 0 );\
-        r = engine->RegisterObjectBehaviour("BaseEditor", asBEHAVE_REF_CAST, name "@ f()", asFUNCTION((refCast<CBaseEditor,classname>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );\
-        r = engine->RegisterObjectBehaviour(name, asBEHAVE_IMPLICIT_REF_CAST, "BaseEditor@ f()", asFUNCTION((refCast<classname,CBaseEditor>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );\
-    }\
-    //-----------------------------------------------------------------------------------------
+#define REGISTER_REFERENCE_BASEOBJECT( name, classname )\
+{\
+    r = engine->RegisterObjectType(name, sizeof(classname), asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);\
+}\
+//-----------------------------------------------------------------------------------------
asOBJ_NOCOUNT!
As in "get the pointer and leave it alone".
That the code became simpler, is a good thing too.

With that fix in place, I could finally apply the fix that were given to me 1.5 years ago (which I forgotten about).
Weird thing is that none of the projects using Angelscript registers objects that way. So I couldn't just browse code and learn.