utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
576 stars 39 forks source link

Use the new Kotlin debug preprocessor in core types. #510

Closed CedNaru closed 10 months ago

CedNaru commented 10 months ago

The C++ code is full of blocks like this:

#ifdef MATH_CHECKS
    ERR_FAIL_COND_V_MSG(!is_rotation(), Quaternion(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quaternion() or call orthonormalized() if the Basis contains linearly independent vectors.");
#endif

We have implemented those checks, but they are done in require blocks:

require(isRotation()) {
      "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quat() or call orthonormalized() instead."
 }

Some of those checks can be really expensive to compute, sometimes even the costliest part of the method. I want to leverage the new debug preprocessor to surround the relevant require blocks with if(DEBUG). It's a very straightforward work, but it has to be done across all methods in core types which can be time-consuming. We can't blindly wrap all "require" blocks as all of them are not necessarily coming from a MATH_CHECK C++ block.

piiertho commented 10 months ago

This needs a fix of pre-processor plugin. I don't know why yet, it makes our job failing: https://github.com/utopia-rise/godot-kotlin-jvm/pull/483