[raymath] Add C++ constexpr support and Matrix scalar multiplication#5606
[raymath] Add C++ constexpr support and Matrix scalar multiplication#5606lamweilun wants to merge 4 commits intoraysan5:masterfrom
constexpr support and Matrix scalar multiplication#5606Conversation
- Make RMAPI functions constexpr in C++ mode - Add constexpr to all C++ math operators - Add MatrixMultiplyValue() and scalar operators - Add MatrixZeros and MatrixUnit constants
|
@JeffM2501 please, could you review this change? I'm not a C++ expert. |
constexpr support and Matrix scalar multiplication
|
There are two considerations here, though they might not matter at all.
@lamweilun Do you have examples of actual use cases where This gets us a very long way from the anchoring of raylib on C89. I suspect this is better handled, if at all, in a C++ binding or supplementary header, not in @JeffM2501 is this consistent with your understanding? |
|
So just based on my testing so far, it definitely needs at least C++14 to compile due to the fact that variable declaration inside a constexpr function body was only added then. To be fair, I have not extensively tested as to how much of a performance boost it would have. This PR is also lacking certain things such as replacing Actually the separation of the functions into a separate header sounds reasonable. I might work on that actually. And perhaps I could also add on a build define option to enable/disable the constexpr stuffs, with disabled being the default I suppose. Perhaps we can continue discussing once I have made those changes? EDIT: Just to add on, actually all I wanted was to add on more constants for the Quaternion type 😆, I just thought the constexpr would be a helpful addon |
Other considerations here also involve the use of intrinsics, which is another tendency for improvement of the array operations and also the use of hardware-provided implementations of trig functions and some array/vector operations. This seems particularly useful for x64 builds. (I must remind myself of this for a project I'm doing using VC/C++ where intrinsics are a compiler option.) |
…separate header raymath_cpp_addon.h. Added a macro RAYMATH_CPP_CONSTEXPR that enables the usage of constexpr in raymath.h.
|
Not sure if the changes made above in those 2 commits are desirable. Do let me know if there are issues |
|
I'm not a fan of these changes, it all feels messy. I don't like one header including another, and I agree requiring C++14 is not great. I'd prefer to only require C++11 since raylib uses C99. This just feels like an inelegant solution. I will need to ponder. |
|
@JeffM2501 It's completely alright if the constexpr changes goes against the philosophy of the project. We can ignore that. Though I would love to at least have the Matrix changes added 🙏🏻 |
|
I will take a pass through raymath.h |
raymath: Add C++ constexpr support and Matrix scalar multiplication