diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 4491abf27..c94c2f42e 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -5070,34 +5070,6 @@ function get_pos_from_transform_mtx(dest, objMtx, camMtx)
-- ...
end
---- @param a integer
---- @param b integer
---- @return integer
-function max(a, b)
- -- ...
-end
-
---- @param a number
---- @param b number
---- @return number
-function maxf(a, b)
- -- ...
-end
-
---- @param a integer
---- @param b integer
---- @return integer
-function min(a, b)
- -- ...
-end
-
---- @param a number
---- @param b number
---- @return number
-function minf(a, b)
- -- ...
-end
-
--- @param dest Mat4
--- @param upDir Vec3f
--- @param pos Vec3f
@@ -5228,18 +5200,6 @@ function spline_get_weights(m, result, t, c)
-- ...
end
---- @param x integer
---- @return integer
-function sqr(x)
- -- ...
-end
-
---- @param x number
---- @return number
-function sqrf(x)
- -- ...
-end
-
--- @param dest Vec3f
--- @param a Vec3f
--- @return void*
@@ -8245,6 +8205,34 @@ function hypotf(a, b)
-- ...
end
+--- @param a integer
+--- @param b integer
+--- @return integer
+function max(a, b)
+ -- ...
+end
+
+--- @param a number
+--- @param b number
+--- @return number
+function maxf(a, b)
+ -- ...
+end
+
+--- @param a integer
+--- @param b integer
+--- @return integer
+function min(a, b)
+ -- ...
+end
+
+--- @param a number
+--- @param b number
+--- @return number
+function minf(a, b)
+ -- ...
+end
+
--- @param radiansAngle number
--- @return integer
function radians_to_sm64(radiansAngle)
@@ -8263,6 +8251,18 @@ function sm64_to_radians(sm64Angle)
-- ...
end
+--- @param x integer
+--- @return integer
+function sqr(x)
+ -- ...
+end
+
+--- @param x number
+--- @return number
+function sqrf(x)
+ -- ...
+end
+
--- @param actFlags integer
--- @return integer
function allocate_mario_action(actFlags)
@@ -9209,6 +9209,12 @@ function obj_get_surface_from_index(o, index)
-- ...
end
+--- @param surfaceType integer
+--- @return boolean
+function surface_has_force(surfaceType)
+ -- ...
+end
+
--- @class Pointer_integer
--- @class Pointer_BehaviorScript
--- @class Pointer_number
diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md
index 4f394f0b7..ef99f81a1 100644
--- a/docs/lua/functions-4.md
+++ b/docs/lua/functions-4.md
@@ -185,90 +185,6 @@
-## [max](#max)
-
-### Lua Example
-`local integerValue = max(a, b)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| a | `integer` |
-| b | `integer` |
-
-### Returns
-- `integer`
-
-### C Prototype
-`s16 max(s16 a, s16 b);`
-
-[:arrow_up_small:](#)
-
-
-
-## [maxf](#maxf)
-
-### Lua Example
-`local numberValue = maxf(a, b)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| a | `number` |
-| b | `number` |
-
-### Returns
-- `number`
-
-### C Prototype
-`f32 maxf(f32 a, f32 b);`
-
-[:arrow_up_small:](#)
-
-
-
-## [min](#min)
-
-### Lua Example
-`local integerValue = min(a, b)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| a | `integer` |
-| b | `integer` |
-
-### Returns
-- `integer`
-
-### C Prototype
-`s16 min(s16 a, s16 b);`
-
-[:arrow_up_small:](#)
-
-
-
-## [minf](#minf)
-
-### Lua Example
-`local numberValue = minf(a, b)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| a | `number` |
-| b | `number` |
-
-### Returns
-- `number`
-
-### C Prototype
-`f32 minf(f32 a, f32 b);`
-
-[:arrow_up_small:](#)
-
-
-
## [mtxf_align_terrain_normal](#mtxf_align_terrain_normal)
### Lua Example
@@ -682,46 +598,6 @@
-## [sqr](#sqr)
-
-### Lua Example
-`local integerValue = sqr(x)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| x | `integer` |
-
-### Returns
-- `integer`
-
-### C Prototype
-`s16 sqr(s16 x);`
-
-[:arrow_up_small:](#)
-
-
-
-## [sqrf](#sqrf)
-
-### Lua Example
-`local numberValue = sqrf(x)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| x | `number` |
-
-### Returns
-- `number`
-
-### C Prototype
-`f32 sqrf(f32 x);`
-
-[:arrow_up_small:](#)
-
-
-
## [vec3f_add](#vec3f_add)
### Lua Example
diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md
index 24592d3c2..b5c43092c 100644
--- a/docs/lua/functions-5.md
+++ b/docs/lua/functions-5.md
@@ -1901,6 +1901,90 @@
+## [max](#max)
+
+### Lua Example
+`local integerValue = max(a, b)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| a | `integer` |
+| b | `integer` |
+
+### Returns
+- `integer`
+
+### C Prototype
+`s32 max(s32 a, s32 b);`
+
+[:arrow_up_small:](#)
+
+
+
+## [maxf](#maxf)
+
+### Lua Example
+`local numberValue = maxf(a, b)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| a | `number` |
+| b | `number` |
+
+### Returns
+- `number`
+
+### C Prototype
+`f32 maxf(f32 a, f32 b);`
+
+[:arrow_up_small:](#)
+
+
+
+## [min](#min)
+
+### Lua Example
+`local integerValue = min(a, b)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| a | `integer` |
+| b | `integer` |
+
+### Returns
+- `integer`
+
+### C Prototype
+`s32 min(s32 a, s32 b);`
+
+[:arrow_up_small:](#)
+
+
+
+## [minf](#minf)
+
+### Lua Example
+`local numberValue = minf(a, b)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| a | `number` |
+| b | `number` |
+
+### Returns
+- `number`
+
+### C Prototype
+`f32 minf(f32 a, f32 b);`
+
+[:arrow_up_small:](#)
+
+
+
## [radians_to_sm64](#radians_to_sm64)
### Lua Example
@@ -1961,6 +2045,46 @@
+## [sqr](#sqr)
+
+### Lua Example
+`local integerValue = sqr(x)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| x | `integer` |
+
+### Returns
+- `integer`
+
+### C Prototype
+`s32 sqr(s32 x);`
+
+[:arrow_up_small:](#)
+
+
+
+## [sqrf](#sqrf)
+
+### Lua Example
+`local numberValue = sqrf(x)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| x | `number` |
+
+### Returns
+- `number`
+
+### C Prototype
+`f32 sqrf(f32 x);`
+
+[:arrow_up_small:](#)
+
+
+
---
# functions from smlua_misc_utils.h
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 7de645186..4623a1bad 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1145,10 +1145,6 @@
- [coss](functions-4.md#coss)
- [find_vector_perpendicular_to_plane](functions-4.md#find_vector_perpendicular_to_plane)
- [get_pos_from_transform_mtx](functions-4.md#get_pos_from_transform_mtx)
- - [max](functions-4.md#max)
- - [maxf](functions-4.md#maxf)
- - [min](functions-4.md#min)
- - [minf](functions-4.md#minf)
- [mtxf_align_terrain_normal](functions-4.md#mtxf_align_terrain_normal)
- [mtxf_align_terrain_triangle](functions-4.md#mtxf_align_terrain_triangle)
- [mtxf_billboard](functions-4.md#mtxf_billboard)
@@ -1168,8 +1164,6 @@
- [not_zero](functions-4.md#not_zero)
- [sins](functions-4.md#sins)
- [spline_get_weights](functions-4.md#spline_get_weights)
- - [sqr](functions-4.md#sqr)
- - [sqrf](functions-4.md#sqrf)
- [vec3f_add](functions-4.md#vec3f_add)
- [vec3f_combine](functions-4.md#vec3f_combine)
- [vec3f_copy](functions-4.md#vec3f_copy)
@@ -1730,9 +1724,15 @@
- [clampf](functions-5.md#clampf)
- [degrees_to_sm64](functions-5.md#degrees_to_sm64)
- [hypotf](functions-5.md#hypotf)
+ - [max](functions-5.md#max)
+ - [maxf](functions-5.md#maxf)
+ - [min](functions-5.md#min)
+ - [minf](functions-5.md#minf)
- [radians_to_sm64](functions-5.md#radians_to_sm64)
- [sm64_to_degrees](functions-5.md#sm64_to_degrees)
- [sm64_to_radians](functions-5.md#sm64_to_radians)
+ - [sqr](functions-5.md#sqr)
+ - [sqrf](functions-5.md#sqrf)
diff --git a/src/engine/math_util.h b/src/engine/math_util.h
index 3a503eb18..722b92fc3 100644
--- a/src/engine/math_util.h
+++ b/src/engine/math_util.h
@@ -35,59 +35,35 @@ extern f32 gCosineTable[];
// Inline Function prototypes
#if defined(__clang__) || defined(__GNUC__)
-// Use built-in functions when using Clang or GCC
-static inline f32 minf(f32 a, f32 b) { return __builtin_fminf(a, b); }
-static inline f32 maxf(f32 a, f32 b) { return __builtin_fmaxf(a, b); }
-#else
+// These macros allow for type safe comparisons that expand without recursion in complex calls, also will use the faster fminf for f32 values
+#define min(a, b) ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _Generic((_a), \
+ f32: _Generic((_b), \
+ f32: __builtin_fminf(_a, _b), \
+ default: (_a) < (_b) ? (_a) : (_b) \
+ ), \
+ default: (_a) < (_b) ? (_a) : (_b) \
+ ); \
+})
-// Fallback to the original implementation for iDO
-static inline f32 minf(f32 a, f32 b) { return (a <= b) ? a : b; }
-static inline f32 maxf(f32 a, f32 b) { return (a > b) ? a : b; }
-#endif
+#define max(a, b) ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _Generic((_a), \
+ f32: _Generic((_b), \
+ f32: __builtin_fmaxf(a, b), \
+ default: (_a) > (_b) ? (_a) : (_b) \
+ ), \
+ default: (_a) > (_b) ? (_a) : (_b) \
+ ); \
+})
-static inline f32 sqrf(f32 x) { return x * x; }
-
-f32 sins(s16 sm64Angle);
-f32 coss(s16 sm64Angle);
-
-#define DEFINE_FOR_TYPE(t) \
- static inline t min_##t(t a, t b) { return (a < b) ? a : b; } \
- static inline t max_##t(t a, t b) { return (a > b) ? a : b; } \
- static inline t sqr_##t(t x) { return x * x; }
-DEFINE_FOR_TYPE(s16);
-DEFINE_FOR_TYPE(s32);
-DEFINE_FOR_TYPE(u8);
-DEFINE_FOR_TYPE(size_t);
-
-// These macros intentionally don't have a default.
-// If you get an error saying that a type is not compatible,
-// it must be added within this file.
-
-#define min(a, b) _Generic((a), \
- f32: minf, \
- s16: min_s16, \
- s32: min_s32, \
- u8: min_u8, \
- size_t: min_size_t \
-)(a, b)
-
-#define max(a, b) _Generic((a), \
- f32: maxf, \
- s16: max_s16, \
- s32: max_s32, \
- u8: max_u8, \
- size_t: max_size_t \
-)(a, b)
-
-#define sqr(x) _Generic((x), \
- f32: sqrf, \
- s16: sqr_s16, \
- s32: sqr_s32, \
- u8: sqr_u8, \
- size_t: sqr_size_t \
-)(x)
-
-#if defined(__clang__) || defined(__GNUC__)
+#define sqr(x) ({ \
+ __typeof__(x) _x = (x); \
+ _x * _x; \
+})
#define absx(x) _Generic((x), \
f32: __builtin_fabsf, \
@@ -97,10 +73,17 @@ DEFINE_FOR_TYPE(size_t);
#else
+// Fallback to the original implementation for iDO
+#define min(a,b) (a < b ? a : b)
+#define max(a,b) (a > b ? a : b)
#define absx(x) ((x) < 0 ? -(x) : (x))
#endif
+static inline f32 sqrf(f32 x) { return x * x; }
+f32 sins(s16 sm64Angle);
+f32 coss(s16 sm64Angle);
+
#include "../../include/libc/stdlib.h"
void *vec3f_copy(Vec3f dest, Vec3f src);
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index a3a996e45..a54e9ad3d 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -18604,82 +18604,6 @@ int smlua_func_get_pos_from_transform_mtx(lua_State* L) {
return 1;
}
-int smlua_func_max(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 2) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "max", 2, top);
- return 0;
- }
-
- s16 a = smlua_to_integer(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "max"); return 0; }
- s16 b = smlua_to_integer(L, 2);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "max"); return 0; }
-
- lua_pushinteger(L, max(a, b));
-
- return 1;
-}
-
-int smlua_func_maxf(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 2) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "maxf", 2, top);
- return 0;
- }
-
- f32 a = smlua_to_number(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "maxf"); return 0; }
- f32 b = smlua_to_number(L, 2);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "maxf"); return 0; }
-
- lua_pushnumber(L, maxf(a, b));
-
- return 1;
-}
-
-int smlua_func_min(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 2) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "min", 2, top);
- return 0;
- }
-
- s16 a = smlua_to_integer(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "min"); return 0; }
- s16 b = smlua_to_integer(L, 2);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "min"); return 0; }
-
- lua_pushinteger(L, min(a, b));
-
- return 1;
-}
-
-int smlua_func_minf(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 2) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "minf", 2, top);
- return 0;
- }
-
- f32 a = smlua_to_number(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "minf"); return 0; }
- f32 b = smlua_to_number(L, 2);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "minf"); return 0; }
-
- lua_pushnumber(L, minf(a, b));
-
- return 1;
-}
-
int smlua_func_mtxf_align_terrain_normal(lua_State* L) {
if (L == NULL) { return 0; }
@@ -19939,40 +19863,6 @@ int smlua_func_spline_get_weights(lua_State* L) {
return 1;
}
-int smlua_func_sqr(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 1) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "sqr", 1, top);
- return 0;
- }
-
- s16 x = smlua_to_integer(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "sqr"); return 0; }
-
- lua_pushinteger(L, sqr(x));
-
- return 1;
-}
-
-int smlua_func_sqrf(lua_State* L) {
- if (L == NULL) { return 0; }
-
- int top = lua_gettop(L);
- if (top != 1) {
- LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "sqrf", 1, top);
- return 0;
- }
-
- f32 x = smlua_to_number(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "sqrf"); return 0; }
-
- lua_pushnumber(L, sqrf(x));
-
- return 1;
-}
-
int smlua_func_vec3f_add(lua_State* L) {
if (L == NULL) { return 0; }
@@ -30342,6 +30232,82 @@ int smlua_func_hypotf(lua_State* L) {
return 1;
}
+int smlua_func_max(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 2) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "max", 2, top);
+ return 0;
+ }
+
+ s32 a = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "max"); return 0; }
+ s32 b = smlua_to_integer(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "max"); return 0; }
+
+ lua_pushinteger(L, max(a, b));
+
+ return 1;
+}
+
+int smlua_func_maxf(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 2) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "maxf", 2, top);
+ return 0;
+ }
+
+ f32 a = smlua_to_number(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "maxf"); return 0; }
+ f32 b = smlua_to_number(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "maxf"); return 0; }
+
+ lua_pushnumber(L, maxf(a, b));
+
+ return 1;
+}
+
+int smlua_func_min(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 2) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "min", 2, top);
+ return 0;
+ }
+
+ s32 a = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "min"); return 0; }
+ s32 b = smlua_to_integer(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "min"); return 0; }
+
+ lua_pushinteger(L, min(a, b));
+
+ return 1;
+}
+
+int smlua_func_minf(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 2) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "minf", 2, top);
+ return 0;
+ }
+
+ f32 a = smlua_to_number(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "minf"); return 0; }
+ f32 b = smlua_to_number(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "minf"); return 0; }
+
+ lua_pushnumber(L, minf(a, b));
+
+ return 1;
+}
+
int smlua_func_radians_to_sm64(lua_State* L) {
if (L == NULL) { return 0; }
@@ -30393,6 +30359,40 @@ int smlua_func_sm64_to_radians(lua_State* L) {
return 1;
}
+int smlua_func_sqr(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "sqr", 1, top);
+ return 0;
+ }
+
+ s32 x = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "sqr"); return 0; }
+
+ lua_pushinteger(L, sqr(x));
+
+ return 1;
+}
+
+int smlua_func_sqrf(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "sqrf", 1, top);
+ return 0;
+ }
+
+ f32 x = smlua_to_number(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "sqrf"); return 0; }
+
+ lua_pushnumber(L, sqrf(x));
+
+ return 1;
+}
+
////////////////////////
// smlua_misc_utils.h //
////////////////////////
@@ -33374,6 +33374,23 @@ int smlua_func_obj_get_surface_from_index(lua_State* L) {
return 1;
}
+int smlua_func_surface_has_force(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "surface_has_force", 1, top);
+ return 0;
+ }
+
+ s16 surfaceType = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "surface_has_force"); return 0; }
+
+ lua_pushboolean(L, surface_has_force(surfaceType));
+
+ return 1;
+}
+
void smlua_bind_functions_autogen(void) {
@@ -34456,10 +34473,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "coss", smlua_func_coss);
smlua_bind_function(L, "find_vector_perpendicular_to_plane", smlua_func_find_vector_perpendicular_to_plane);
smlua_bind_function(L, "get_pos_from_transform_mtx", smlua_func_get_pos_from_transform_mtx);
- smlua_bind_function(L, "max", smlua_func_max);
- smlua_bind_function(L, "maxf", smlua_func_maxf);
- smlua_bind_function(L, "min", smlua_func_min);
- smlua_bind_function(L, "minf", smlua_func_minf);
smlua_bind_function(L, "mtxf_align_terrain_normal", smlua_func_mtxf_align_terrain_normal);
smlua_bind_function(L, "mtxf_align_terrain_triangle", smlua_func_mtxf_align_terrain_triangle);
smlua_bind_function(L, "mtxf_billboard", smlua_func_mtxf_billboard);
@@ -34479,8 +34492,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "not_zero", smlua_func_not_zero);
smlua_bind_function(L, "sins", smlua_func_sins);
smlua_bind_function(L, "spline_get_weights", smlua_func_spline_get_weights);
- smlua_bind_function(L, "sqr", smlua_func_sqr);
- smlua_bind_function(L, "sqrf", smlua_func_sqrf);
smlua_bind_function(L, "vec3f_add", smlua_func_vec3f_add);
smlua_bind_function(L, "vec3f_combine", smlua_func_vec3f_combine);
smlua_bind_function(L, "vec3f_copy", smlua_func_vec3f_copy);
@@ -35022,9 +35033,15 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "clampf", smlua_func_clampf);
smlua_bind_function(L, "degrees_to_sm64", smlua_func_degrees_to_sm64);
smlua_bind_function(L, "hypotf", smlua_func_hypotf);
+ smlua_bind_function(L, "max", smlua_func_max);
+ smlua_bind_function(L, "maxf", smlua_func_maxf);
+ smlua_bind_function(L, "min", smlua_func_min);
+ smlua_bind_function(L, "minf", smlua_func_minf);
smlua_bind_function(L, "radians_to_sm64", smlua_func_radians_to_sm64);
smlua_bind_function(L, "sm64_to_degrees", smlua_func_sm64_to_degrees);
smlua_bind_function(L, "sm64_to_radians", smlua_func_sm64_to_radians);
+ smlua_bind_function(L, "sqr", smlua_func_sqr);
+ smlua_bind_function(L, "sqrf", smlua_func_sqrf);
// smlua_misc_utils.h
smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action);
@@ -35203,5 +35220,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "load_area_terrain", smlua_func_load_area_terrain);
smlua_bind_function(L, "load_object_collision_model", smlua_func_load_object_collision_model);
smlua_bind_function(L, "obj_get_surface_from_index", smlua_func_obj_get_surface_from_index);
+ smlua_bind_function(L, "surface_has_force", smlua_func_surface_has_force);
}
diff --git a/src/pc/lua/utils/smlua_math_utils.c b/src/pc/lua/utils/smlua_math_utils.c
index ccc3fc63d..06af14f14 100644
--- a/src/pc/lua/utils/smlua_math_utils.c
+++ b/src/pc/lua/utils/smlua_math_utils.c
@@ -18,7 +18,31 @@ s16 degrees_to_sm64(f32 degreesAngle) {
}
f32 hypotf(f32 a, f32 b) {
- return sqrtf(a * a + b * b);
+ return __builtin_sqrtf(a * a + b * b);
+}
+
+f32 minf(f32 a, f32 b) {
+ return __builtin_fminf(a, b);
+}
+
+f32 maxf(f32 a, f32 b) {
+ return __builtin_fmaxf(a, b);
+}
+
+s32 min(s32 a, s32 b){
+ return ((a) <= (b) ? (a) : (b));
+}
+
+s32 max(s32 a, s32 b){
+ return ((a) >= (b) ? (a) : (b));
+}
+
+s32 sqr(s32 x) {
+ return x * x;
+}
+
+f32 sqrf(f32 x) {
+ return x * x;
}
s32 clamp(s32 a, s32 b, s32 c) {
diff --git a/src/pc/lua/utils/smlua_math_utils.h b/src/pc/lua/utils/smlua_math_utils.h
index 7d1b40476..4ca6ce30c 100644
--- a/src/pc/lua/utils/smlua_math_utils.h
+++ b/src/pc/lua/utils/smlua_math_utils.h
@@ -1,6 +1,26 @@
#ifndef SMLUA_MATH_UTILS_H
#define SMLUA_MATH_UTILS_H
+#if defined(min)
+#undef min
+#endif
+
+#if defined(max)
+#undef max
+#endif
+
+#if defined(sqr)
+#undef sqr
+#endif
+
+// these are also defined in math_util.h as macros
+s32 min(s32 a, s32 b);
+s32 max(s32 a, s32 b);
+s32 sqr(s32 x);
+
+f32 minf(f32 a, f32 b);
+f32 maxf(f32 a, f32 b);
+f32 sqrf(f32 x);
f32 sm64_to_radians(s16 sm64Angle);
s16 radians_to_sm64(f32 radiansAngle);
f32 sm64_to_degrees(s16 sm64Angle);
@@ -9,5 +29,7 @@ f32 hypotf(f32 a, f32 b);
s32 clamp(s32 a, s32 b, s32 c);
f32 clampf(f32 a, f32 b, f32 c);
+
+
#endif // SMLUA_MATH_UTILS_H