Vector3 copy constructor

Minor issues with the Ogre API that can be trivial to fix
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Vector3 copy constructor

Post 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
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Vector3 copy constructor

Post 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:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Vector3 copy constructor

Post by jacmoe »

Just throwing the fix in here so that it might prevent other poor souls from losing their sanity and/or valuable time. ;)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Vector3 copy constructor

Post 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.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Vector3 copy constructor

Post by jacmoe »

I feel better already! :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Vector3 copy constructor

Post 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.
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Vector3 copy constructor

Post 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)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Vector3 copy constructor

Post 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.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Post Reply