Advertisement

Move Constructors/Assignment

Started by October 21, 2013 07:22 PM
3 comments, last by WitchLord 11 years, 1 month ago

Have you given any thought toward C++11-style move constructors and assignment for AngelScript? It would be quite useful to be able to register something like opAssign(MyClass&& a) or opAssign(MyClass&temp a).

C++11 brought many interesting improvements to the C++ language, but right now there are so many other things to do AngelScript before I get to implement enhancements targeted at C++11 that it will likely take a very long time before I get to these.

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

Advertisement

As interesting as these would be, I *strongly* question whether or not something like this belongs in a game scripting language. Move semantics, as implemented in C++, solve a C++-specific design shortcoming, and I think the best way to approach this is to solve things at a higher level. There's a reason C++ code is bloody murder to reason about.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

I appreciate that it could take a very long time to get to implementing such a feature. I only ask to see if it is part of your vision or not.

Concerning whether or not such a thing belongs in a game scripting language, I have a Matrix class which I desire to have "value assignment" characteristics.

A = B will copy B to A, not simply add a reference to B and assign a pointer to A. Also, we all know it is most convenient for a function to "return" its result, particularly if one wants to chain together operations.


B = A.Transpose().Invert() 

rather than:


A.Transpose(temp);
temp.Invert(B);
 

The first syntax also avoids the need to do some parameter checking, like whether or not the destination object is equal to "this".


A.Transpose(A)  // Maybe not a good idea 

With the combination of the above concepts, any return from a function requires an unnecessary copy. Some of my users' matrices have thousands of rows, so I would like to avoid extra copying.

I agree with both of you.

The script writer should definitely not have to bother with move operators or normal copy operators (unless he really wants to), he/she should just write the code as quickly as possible.

But there is certainly nothing wrong with allowing the application to provide a more performatic API to the script engine, which is where the enhancement to AngelScript comes in. In order to take advantage of the new temp reference && in C++, the engine will need to know the difference between a temp reference and a normal reference when registering the interface. The compiler must also be enhanced to keep track of which references are to temporary objects or not so that it call call the appropriate function.

It is quite likely that I'll add this support in the future. Though as it is essentially an optimization feature, and probably only useable with C++11 capable compilers it will definitely be prioritized at the moment.

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

This topic is closed to new replies.

Advertisement