From 69e129805e2dbf3090cdb5b72413013380e091e2 Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Thu, 29 May 2025 02:52:31 +0200 Subject: [PATCH] More math improvements (#820) * More math improvements * more math functions * stack check * added error message when trying to modify read-only table; fix gSmluaConstants printed to console --- autogen/common.py | 7 +- autogen/convert_constants.py | 27 + autogen/convert_functions.py | 10 + autogen/gen_math.py | 3 +- autogen/lua_constants/built-in.lua | 79 ++- autogen/lua_definitions/constants.lua | 157 +++++- autogen/lua_definitions/functions.lua | 166 ++++-- autogen/vec_types.py | 49 ++ docs/lua/functions-3.md | 2 +- docs/lua/functions-4.md | 748 +++++++++++--------------- docs/lua/functions-5.md | 551 +++++++++---------- docs/lua/functions-6.md | 292 ++++++++++ docs/lua/functions.md | 50 +- docs/lua/structs.md | 6 +- include/types.h | 11 + src/engine/math_util.c | 12 +- src/engine/math_util.h | 14 +- src/engine/math_util_vec3.tmpl | 46 +- src/engine/math_util_vec3f.inl | 50 +- src/engine/math_util_vec3i.inl | 50 +- src/engine/math_util_vec3s.inl | 50 +- src/pc/lua/smlua_constants_autogen.c | 95 +++- src/pc/lua/smlua_functions.c | 112 ++++ src/pc/lua/smlua_functions_autogen.c | 345 ++++++++++-- src/pc/lua/smlua_utils.c | 18 +- 25 files changed, 2015 insertions(+), 935 deletions(-) diff --git a/autogen/common.py b/autogen/common.py index 77c503f98..6b1886a7d 100644 --- a/autogen/common.py +++ b/autogen/common.py @@ -233,7 +233,10 @@ def translate_type_to_lua(ptype): ptype = ptype.split(' ')[1].replace('*', '') return ptype, 'structs.md#%s' % ptype - if 'Vec3' in ptype: + if ptype in VECP_TYPES: + return VECP_TYPES[ptype], 'structs.md#%s' % VECP_TYPES[ptype] + + if ptype in VEC_TYPES: return ptype, 'structs.md#%s' % ptype if ptype.startswith('enum '): @@ -267,7 +270,7 @@ def translate_type_to_lua(ptype): if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype): ptype = ptype.replace('const', '').replace('*', '').strip() - s = '`Pointer` <%s>' % translate_type_to_lua(ptype)[0] + s = '`Pointer` <`%s`>' % translate_type_to_lua(ptype)[0].replace('`', '').strip() return s, None if not ptype.startswith('`'): diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py index 2af19228d..d4ee7a80e 100644 --- a/autogen/convert_constants.py +++ b/autogen/convert_constants.py @@ -1,5 +1,6 @@ from common import * from extract_constants import * +from vec_types import * import sys in_filename = 'autogen/lua_constants/built-in.lua' @@ -365,12 +366,30 @@ def build_files(processed_files): return s +def build_vec_type_constant(type_name, vec_type, constant, values): + txt = 'g%s%s = create_read_only_table({' % (type_name, constant) + txt += ','.join([ + '%s=%s' % (lua_field, str(values[i])) + for i, lua_field in enumerate(vec_type["fields_mapping"]) + ]) + txt += '})' + return txt + def build_to_c(built_files): txt = '' + + # Built-in and deprecated for filename in [in_filename, deprecated_filename]: with open(get_path(filename), 'r') as f: for line in f.readlines(): txt += line.strip() + '\n' + + # Vec types constants + for type_name, vec_type in VEC_TYPES.items(): + for constant, values in vec_type.get("constants", {}).items(): + txt += build_vec_type_constant(type_name, vec_type, constant, values) + '\n' + + # Source files txt += '\n' + built_files while ('\n\n' in txt): @@ -505,6 +524,14 @@ def build_to_def(processed_files): s += f.read() s += '\n' + s += '\n\n-------------------------\n' + s += '-- vec types constants --\n' + s += '-------------------------\n\n' + for type_name, vec_type in VEC_TYPES.items(): + for constant, values in vec_type.get("constants", {}).items(): + s += '--- @type %s\n' % (type_name) + s += build_vec_type_constant(type_name, vec_type, constant, values) + '\n\n' + for file in processed_files: constants = file['constants'] skip_constant = False diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 374382265..36be2fb96 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -921,6 +921,9 @@ def build_call(function): elif ftype == 'void *': return ' %s;\n' % ccall + if ftype in VECP_TYPES: + return ' %s;\n' % ccall + flot = translate_type_to_lot(ftype) lfunc = 'UNIMPLEMENTED -->' @@ -994,6 +997,10 @@ def build_function(function, do_extern): i += 1 s += '\n' + # To allow chaining vector functions calls, return the table corresponding to `dest` parameter + if function['type'] in VECP_TYPES: + s += ' lua_settop(L, 1);\n' + s += ' return 1;\n}\n' if fid in override_function_version_excludes: @@ -1442,6 +1449,9 @@ def def_files(processed_files): for def_pointer in def_pointers: s += '--- @alias %s %s\n' % (def_pointer, def_pointer[8:]) + for vecp_type, vec_type in VECP_TYPES.items(): + s += '--- @alias %s %s\n' % (vecp_type, vec_type) + with open(get_path(out_filename_defs), 'w', encoding='utf-8', newline='\n') as out: out.write(s) diff --git a/autogen/gen_math.py b/autogen/gen_math.py index 3e9dc8ec2..db411a975 100644 --- a/autogen/gen_math.py +++ b/autogen/gen_math.py @@ -5,7 +5,7 @@ VEC3X_TO_VEC3Y = """ /* |description| Converts a 3D {{desc}} vector `a` into a 3D {{desc_2}} vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type_2}} *vec3{{suffix}}_to_vec3{{suffix_2}}(Vec3{{suffix_2}} dest, Vec3{{suffix}} a) { +INLINE OPTIMIZE_O3 Vec3{{suffix_2}}p vec3{{suffix}}_to_vec3{{suffix_2}}(Vec3{{suffix_2}} dest, Vec3{{suffix}} a) { dest[0] = a[0]{{rounding_0}}; dest[1] = a[1]{{rounding_1}}; dest[2] = a[2]{{rounding_2}}; @@ -24,7 +24,6 @@ def vec3_write_conversion_functions(generated: str, curr_template: dict, templat .replace("{{desc}}", curr_template["desc"]) \ .replace("{{suffix}}", curr_template["suffix"]) \ .replace("{{desc_2}}", template["desc"]) \ - .replace("{{type_2}}", template["type"]) \ .replace("{{suffix_2}}", template["suffix"]) for i in range(size): diff --git a/autogen/lua_constants/built-in.lua b/autogen/lua_constants/built-in.lua index aaca0277d..986dfaf5d 100644 --- a/autogen/lua_constants/built-in.lua +++ b/autogen/lua_constants/built-in.lua @@ -21,12 +21,47 @@ _ReadOnlyTable = { end } +----------- +-- table -- +----------- + +--- Creates a shallow copy of table `t` +--- @param t table +--- @return table +function table.copy(t) + return table_copy(t) +end + +--- Creates a deep copy of table `t` +--- @param t table +--- @return table +function table.deepcopy(t) + return table_deepcopy(t) +end + +--- Utility function to create a read-only table +--- @param data table +--- @return table +function create_read_only_table(data) + local t = {} + local mt = { + __index = data, + __newindex = function(_, k, _) + error('Attempting to modify key `' .. k .. '` of read-only table') + end, + __call = function() return table_copy(data) end, + __metatable = false + } + setmetatable(t, mt) + return t +end + ----------- -- sound -- ----------- --- @type Vec3f -gGlobalSoundSource = { x = 0, y = 0, z = 0 } +gGlobalSoundSource = create_read_only_table({ x = 0, y = 0, z = 0 }) --- @param bank number --- @param soundID number @@ -167,6 +202,48 @@ function math.hypot(a, b) return __math_sqrt(a * a + b * b) end +--- @param x number +--- @return number +--- Returns 1 if `x` is positive or zero, -1 otherwise +function math.sign(x) + return x >= 0 and 1 or -1 +end + +--- @param x number +--- @return number +--- Returns 1 if `x` is positive, 0 if it is zero, -1 otherwise +function math.sign0(x) + return x ~= 0 and (x > 0 and 1 or -1) or 0 +end + +--- @param t number +--- @param a number +--- @param b number +--- @return number +--- Linearly interpolates `t` between `a` and `b` +function math.lerp(t, a, b) + return a + (b - a) * t +end + +--- @param x number +--- @param a number +--- @param b number +--- @return number +--- Determines where `x` linearly lies between `a` and `b`. It's the inverse of `math.lerp` +function math.invlerp(x, a, b) + return (x - a) / (b - a) +end + +--- @param x number +--- @param a number +--- @param b number +--- @param c number +--- @param d number +--- @return number +--- Linearly remaps `x` from the source range `[a, b]` to the destination range `[c, d]` +function math.remap(x, a, b, c, d) + return c + (d - c) * ((x - a) / (b - a)) +end ----------------- -- legacy font -- diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index a468c8e96..828eaa822 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -23,12 +23,47 @@ _ReadOnlyTable = { end } +----------- +-- table -- +----------- + +--- Creates a shallow copy of table `t` +--- @param t table +--- @return table +function table.copy(t) + return table_copy(t) +end + +--- Creates a deep copy of table `t` +--- @param t table +--- @return table +function table.deepcopy(t) + return table_deepcopy(t) +end + +--- Utility function to create a read-only table +--- @param data table +--- @return table +function create_read_only_table(data) + local t = {} + local mt = { + __index = data, + __newindex = function(_, k, _) + error('Attempting to modify key `' .. k .. '` of read-only table') + end, + __call = function() return table_copy(data) end, + __metatable = false + } + setmetatable(t, mt) + return t +end + ----------- -- sound -- ----------- --- @type Vec3f -gGlobalSoundSource = { x = 0, y = 0, z = 0 } +gGlobalSoundSource = create_read_only_table({ x = 0, y = 0, z = 0 }) --- @param bank number --- @param soundID number @@ -169,6 +204,48 @@ function math.hypot(a, b) return __math_sqrt(a * a + b * b) end +--- @param x number +--- @return number +--- Returns 1 if `x` is positive or zero, -1 otherwise +function math.sign(x) + return x >= 0 and 1 or -1 +end + +--- @param x number +--- @return number +--- Returns 1 if `x` is positive, 0 if it is zero, -1 otherwise +function math.sign0(x) + return x ~= 0 and (x > 0 and 1 or -1) or 0 +end + +--- @param t number +--- @param a number +--- @param b number +--- @return number +--- Linearly interpolates `t` between `a` and `b` +function math.lerp(t, a, b) + return a + (b - a) * t +end + +--- @param x number +--- @param a number +--- @param b number +--- @return number +--- Determines where `x` linearly lies between `a` and `b`. It's the inverse of `math.lerp` +function math.invlerp(x, a, b) + return (x - a) / (b - a) +end + +--- @param x number +--- @param a number +--- @param b number +--- @param c number +--- @param d number +--- @return number +--- Linearly remaps `x` from the source range `[a, b]` to the destination range `[c, d]` +function math.remap(x, a, b, c, d) + return c + (d - c) * ((x - a) / (b - a)) +end ----------------- -- legacy font -- @@ -177,6 +254,84 @@ end --- @type integer FONT_TINY = -1 + +------------------------- +-- vec types constants -- +------------------------- + +--- @type Vec2f +gVec2fZero = create_read_only_table({x=0,y=0}) + +--- @type Vec2f +gVec2fOne = create_read_only_table({x=1,y=1}) + +--- @type Vec3f +gVec3fZero = create_read_only_table({x=0,y=0,z=0}) + +--- @type Vec3f +gVec3fOne = create_read_only_table({x=1,y=1,z=1}) + +--- @type Vec3f +gVec3fX = create_read_only_table({x=1,y=0,z=0}) + +--- @type Vec3f +gVec3fY = create_read_only_table({x=0,y=1,z=0}) + +--- @type Vec3f +gVec3fZ = create_read_only_table({x=0,y=0,z=1}) + +--- @type Vec4f +gVec4fZero = create_read_only_table({x=0,y=0,z=0,w=0}) + +--- @type Vec4f +gVec4fOne = create_read_only_table({x=1,y=1,z=1,w=1}) + +--- @type Vec2i +gVec2iZero = create_read_only_table({x=0,y=0}) + +--- @type Vec2i +gVec2iOne = create_read_only_table({x=1,y=1}) + +--- @type Vec3i +gVec3iZero = create_read_only_table({x=0,y=0,z=0}) + +--- @type Vec3i +gVec3iOne = create_read_only_table({x=1,y=1,z=1}) + +--- @type Vec4i +gVec4iZero = create_read_only_table({x=0,y=0,z=0,w=0}) + +--- @type Vec4i +gVec4iOne = create_read_only_table({x=1,y=1,z=1,w=1}) + +--- @type Vec2s +gVec2sZero = create_read_only_table({x=0,y=0}) + +--- @type Vec2s +gVec2sOne = create_read_only_table({x=1,y=1}) + +--- @type Vec3s +gVec3sZero = create_read_only_table({x=0,y=0,z=0}) + +--- @type Vec3s +gVec3sOne = create_read_only_table({x=1,y=1,z=1}) + +--- @type Vec4s +gVec4sZero = create_read_only_table({x=0,y=0,z=0,w=0}) + +--- @type Vec4s +gVec4sOne = create_read_only_table({x=1,y=1,z=1,w=1}) + +--- @type Mat4 +gMat4Zero = create_read_only_table({m00=0,m01=0,m02=0,m03=0,m10=0,m11=0,m12=0,m13=0,m20=0,m21=0,m22=0,m23=0,m30=0,m31=0,m32=0,m33=0}) + +--- @type Mat4 +gMat4Identity = create_read_only_table({m00=1,m01=0,m02=0,m03=0,m10=0,m11=1,m12=0,m13=0,m20=0,m21=0,m22=1,m23=0,m30=0,m31=0,m32=0,m33=1}) + +--- @type Mat4 +gMat4Fullscreen = create_read_only_table({m00=0.00625,m01=0,m02=0,m03=0,m10=0,m11=0.008333333333333333,m12=0,m13=0,m20=0,m21=0,m22=-1,m23=0,m30=-1,m31=-1,m32=-1,m33=1}) + + --- @type integer INSTANT_WARP_INDEX_START = 0x00 diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 6503fc5e8..4497620a2 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -6360,7 +6360,7 @@ end --- @param v Vec3f --- @param rotate Vec3s ---- @return Pointer_number +--- @return Vec3f --- Rotates the 3D floating-point vector `v` by the angles specified in the 3D signed-integer vector `rotate`, applying the rotations in the order Z, then X, then Y. The rotated vector replaces `v` function vec3f_rotate_zxy(v, rotate) -- ... @@ -6370,7 +6370,7 @@ end --- @param v Vec3f --- @param n Vec3f --- @param r integer ---- @return Pointer_number +--- @return Vec3f --- Rotates the 3D floating-point vector `v` around the vector `n`, given a rotation `r` (in sm64 angle units), and stores the result in `dest` function vec3f_rotate_around_n(dest, v, n, r) -- ... @@ -6379,7 +6379,7 @@ end --- @param dest Vec3f --- @param v Vec3f --- @param onto Vec3f ---- @return Pointer_number +--- @return Vec3f --- Projects the 3D floating-point vector `v` onto another 3D floating-point vector `onto`. The resulting projection, stored in `dest`, represents how much of `v` lies along the direction of `onto` function vec3f_project(dest, v, onto) -- ... @@ -6390,7 +6390,7 @@ end --- @param translation Vec3f --- @param rotation Vec3s --- @param scale Vec3f ---- @return Pointer_number +--- @return Vec3f --- Scales the 3D floating-point vector `v` by the vector `scale`, then rotates it by the rotation vector `rotation`, and finally translates it by the vector `translation`. The resulting vector is stored in `dest` function vec3f_transform(dest, v, translation, rotation, scale) -- ... @@ -6420,7 +6420,7 @@ end --- @param a Vec3f --- @param b Vec3f --- @param c Vec3f ---- @return Pointer_number +--- @return Vec3f --- Determines a vector that is perpendicular (normal) to the plane defined by three given 3D floating-point points `a`, `b`, and `c`. The resulting perpendicular vector is stored in `dest` function find_vector_perpendicular_to_plane(dest, a, b, c) -- ... @@ -6498,7 +6498,7 @@ end --- @param mtx Mat4 --- @param b Vec3s --- @return Pointer_integer ---- Multiplies the 4x4 floating-point matrix `mtx` by a 3D signed-integer vector `b`, potentially interpreting `b` as angles or translations depending on usage, and modifies `mtx` accordingly +--- Multiplies the 3D signed-integer vector `b` with the 4x4 floating-point matrix `mtx`, which applies the transformation to the point function mtxf_mul_vec3s(mtx, b) -- ... end @@ -6520,7 +6520,7 @@ end --- @param dest Vec3f --- @param objMtx Mat4 --- @param camMtx Mat4 ---- @return Pointer_number +--- @return Vec3f --- Extracts the position (translation component) from the transformation matrix `objMtx` relative to the coordinate system defined by `camMtx` and stores that 3D position in `dest`. This can be used to get the object's coordinates in camera space function get_pos_from_transform_mtx(dest, objMtx, camMtx) -- ... @@ -6597,7 +6597,7 @@ function mtxf_scale_vec3f(dest, mtx, s) end --- @param v Vec3f ---- @return Pointer_number +--- @return Vec3f --- Sets the components of the 3D floating-point vector `v` to 0 function vec3f_zero(v) -- ... @@ -6605,7 +6605,7 @@ end --- @param dest Vec3f --- @param src Vec3f ---- @return Pointer_number +--- @return Vec3f --- Copies the contents of a 3D floating-point vector (`src`) into another 3D floating-point vector (`dest`) function vec3f_copy(dest, src) -- ... @@ -6615,7 +6615,7 @@ end --- @param x number --- @param y number --- @param z number ---- @return Pointer_number +--- @return Vec3f --- Sets the values of the 3D floating-point vector `dest` to the given x, y, and z values function vec3f_set(dest, x, y, z) -- ... @@ -6623,7 +6623,7 @@ end --- @param dest Vec3f --- @param a Vec3f ---- @return Pointer_number +--- @return Vec3f --- Adds the components of the 3D floating-point vector `a` to `dest` function vec3f_add(dest, a) -- ... @@ -6632,7 +6632,7 @@ end --- @param dest Vec3f --- @param a Vec3f --- @param b Vec3f ---- @return Pointer_number +--- @return Vec3f --- Adds the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` function vec3f_sum(dest, a, b) -- ... @@ -6640,7 +6640,7 @@ end --- @param dest Vec3f --- @param a Vec3f ---- @return Pointer_number +--- @return Vec3f --- Subtracts the components of the 3D floating-point vector `a` from `dest` function vec3f_sub(dest, a) -- ... @@ -6649,7 +6649,7 @@ end --- @param dest Vec3f --- @param a Vec3f --- @param b Vec3f ---- @return Pointer_number +--- @return Vec3f --- Subtracts the components of the 3D floating-point vector `b` from the components of `a` and stores the result in `dest` function vec3f_dif(dest, a, b) -- ... @@ -6657,15 +6657,32 @@ end --- @param dest Vec3f --- @param a number ---- @return Pointer_number +--- @return Vec3f --- Multiplies each component of the 3D floating-point vector `dest` by the scalar value `a` function vec3f_mul(dest, a) -- ... end +--- @param dest Vec3f +--- @param a Vec3f +--- @return Vec3f +--- Multiplies the components of the 3D floating-point vector `dest` with the components of `a` +function vec3f_mult(dest, a) + -- ... +end + +--- @param dest Vec3f +--- @param a Vec3f +--- @param b Vec3f +--- @return Vec3f +--- Multiplies the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` +function vec3f_prod(dest, a, b) + -- ... +end + --- @param dest Vec3f --- @param a number ---- @return Pointer_number +--- @return Vec3f --- Divides each component of the 3D floating-point vector `dest` by the scalar value `a` function vec3f_div(dest, a) -- ... @@ -6679,7 +6696,7 @@ function vec3f_length(a) end --- @param v Vec3f ---- @return Pointer_number +--- @return Vec3f --- Normalizes the 3D floating-point vector `v` so that its length (magnitude) becomes 1, while retaining its direction function vec3f_normalize(v) -- ... @@ -6687,7 +6704,7 @@ end --- @param v Vec3f --- @param mag number ---- @return Pointer_number +--- @return Vec3f --- Sets the length (magnitude) of 3D floating-point vector `v`, while retaining its direction function vec3f_set_magnitude(v, mag) -- ... @@ -6704,7 +6721,7 @@ end --- @param dest Vec3f --- @param a Vec3f --- @param b Vec3f ---- @return Pointer_number +--- @return Vec3f --- Computes the cross product of two 3D floating-point vectors `a` and `b` and stores the result in `dest` function vec3f_cross(dest, a, b) -- ... @@ -6715,7 +6732,7 @@ end --- @param vecB Vec3f --- @param sclA number --- @param sclB number ---- @return Pointer_number +--- @return Vec3f --- Takes two 3D floating-point vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` function vec3f_combine(dest, vecA, vecB, sclA, sclB) -- ... @@ -6746,7 +6763,7 @@ end --- @param dest Vec3i --- @param a Vec3f ---- @return Pointer_integer +--- @return Vec3i --- Converts a 3D floating-point vector `a` into a 3D integer vector and stores the result in `dest` function vec3f_to_vec3i(dest, a) -- ... @@ -6754,14 +6771,14 @@ end --- @param dest Vec3s --- @param a Vec3f ---- @return Pointer_integer +--- @return Vec3s --- Converts a 3D floating-point vector `a` into a 3D short integer vector and stores the result in `dest` function vec3f_to_vec3s(dest, a) -- ... end --- @param v Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Sets the components of the 3D integer vector `v` to 0 function vec3i_zero(v) -- ... @@ -6769,7 +6786,7 @@ end --- @param dest Vec3i --- @param src Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Copies the contents of a 3D integer vector (`src`) into another 3D integer vector (`dest`) function vec3i_copy(dest, src) -- ... @@ -6779,7 +6796,7 @@ end --- @param x integer --- @param y integer --- @param z integer ---- @return Pointer_integer +--- @return Vec3i --- Sets the values of the 3D integer vector `dest` to the given x, y, and z values function vec3i_set(dest, x, y, z) -- ... @@ -6787,7 +6804,7 @@ end --- @param dest Vec3i --- @param a Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Adds the components of the 3D integer vector `a` to `dest` function vec3i_add(dest, a) -- ... @@ -6796,7 +6813,7 @@ end --- @param dest Vec3i --- @param a Vec3i --- @param b Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Adds the components of two 3D integer vectors `a` and `b` and stores the result in `dest` function vec3i_sum(dest, a, b) -- ... @@ -6804,7 +6821,7 @@ end --- @param dest Vec3i --- @param a Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Subtracts the components of the 3D integer vector `a` from `dest` function vec3i_sub(dest, a) -- ... @@ -6813,7 +6830,7 @@ end --- @param dest Vec3i --- @param a Vec3i --- @param b Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Subtracts the components of the 3D integer vector `b` from the components of `a` and stores the result in `dest` function vec3i_dif(dest, a, b) -- ... @@ -6821,15 +6838,32 @@ end --- @param dest Vec3i --- @param a number ---- @return Pointer_integer +--- @return Vec3i --- Multiplies each component of the 3D integer vector `dest` by the scalar value `a` function vec3i_mul(dest, a) -- ... end +--- @param dest Vec3i +--- @param a Vec3i +--- @return Vec3i +--- Multiplies the components of the 3D integer vector `dest` with the components of `a` +function vec3i_mult(dest, a) + -- ... +end + +--- @param dest Vec3i +--- @param a Vec3i +--- @param b Vec3i +--- @return Vec3i +--- Multiplies the components of two 3D integer vectors `a` and `b` and stores the result in `dest` +function vec3i_prod(dest, a, b) + -- ... +end + --- @param dest Vec3i --- @param a number ---- @return Pointer_integer +--- @return Vec3i --- Divides each component of the 3D integer vector `dest` by the scalar value `a` function vec3i_div(dest, a) -- ... @@ -6843,7 +6877,7 @@ function vec3i_length(a) end --- @param v Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Normalizes the 3D integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction function vec3i_normalize(v) -- ... @@ -6851,7 +6885,7 @@ end --- @param v Vec3i --- @param mag number ---- @return Pointer_integer +--- @return Vec3i --- Sets the length (magnitude) of 3D integer vector `v`, while retaining its direction function vec3i_set_magnitude(v, mag) -- ... @@ -6868,7 +6902,7 @@ end --- @param dest Vec3i --- @param a Vec3i --- @param b Vec3i ---- @return Pointer_integer +--- @return Vec3i --- Computes the cross product of two 3D integer vectors `a` and `b` and stores the result in `dest` function vec3i_cross(dest, a, b) -- ... @@ -6879,7 +6913,7 @@ end --- @param vecB Vec3i --- @param sclA number --- @param sclB number ---- @return Pointer_integer +--- @return Vec3i --- Takes two 3D integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` function vec3i_combine(dest, vecA, vecB, sclA, sclB) -- ... @@ -6910,7 +6944,7 @@ end --- @param dest Vec3f --- @param a Vec3i ---- @return Pointer_number +--- @return Vec3f --- Converts a 3D integer vector `a` into a 3D floating-point vector and stores the result in `dest` function vec3i_to_vec3f(dest, a) -- ... @@ -6918,14 +6952,14 @@ end --- @param dest Vec3s --- @param a Vec3i ---- @return Pointer_integer +--- @return Vec3s --- Converts a 3D integer vector `a` into a 3D short integer vector and stores the result in `dest` function vec3i_to_vec3s(dest, a) -- ... end --- @param v Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Sets the components of the 3D short integer vector `v` to 0 function vec3s_zero(v) -- ... @@ -6933,7 +6967,7 @@ end --- @param dest Vec3s --- @param src Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Copies the contents of a 3D short integer vector (`src`) into another 3D short integer vector (`dest`) function vec3s_copy(dest, src) -- ... @@ -6943,7 +6977,7 @@ end --- @param x integer --- @param y integer --- @param z integer ---- @return Pointer_integer +--- @return Vec3s --- Sets the values of the 3D short integer vector `dest` to the given x, y, and z values function vec3s_set(dest, x, y, z) -- ... @@ -6951,7 +6985,7 @@ end --- @param dest Vec3s --- @param a Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Adds the components of the 3D short integer vector `a` to `dest` function vec3s_add(dest, a) -- ... @@ -6960,7 +6994,7 @@ end --- @param dest Vec3s --- @param a Vec3s --- @param b Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Adds the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` function vec3s_sum(dest, a, b) -- ... @@ -6968,7 +7002,7 @@ end --- @param dest Vec3s --- @param a Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Subtracts the components of the 3D short integer vector `a` from `dest` function vec3s_sub(dest, a) -- ... @@ -6977,7 +7011,7 @@ end --- @param dest Vec3s --- @param a Vec3s --- @param b Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Subtracts the components of the 3D short integer vector `b` from the components of `a` and stores the result in `dest` function vec3s_dif(dest, a, b) -- ... @@ -6985,15 +7019,32 @@ end --- @param dest Vec3s --- @param a number ---- @return Pointer_integer +--- @return Vec3s --- Multiplies each component of the 3D short integer vector `dest` by the scalar value `a` function vec3s_mul(dest, a) -- ... end +--- @param dest Vec3s +--- @param a Vec3s +--- @return Vec3s +--- Multiplies the components of the 3D short integer vector `dest` with the components of `a` +function vec3s_mult(dest, a) + -- ... +end + +--- @param dest Vec3s +--- @param a Vec3s +--- @param b Vec3s +--- @return Vec3s +--- Multiplies the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` +function vec3s_prod(dest, a, b) + -- ... +end + --- @param dest Vec3s --- @param a number ---- @return Pointer_integer +--- @return Vec3s --- Divides each component of the 3D short integer vector `dest` by the scalar value `a` function vec3s_div(dest, a) -- ... @@ -7007,7 +7058,7 @@ function vec3s_length(a) end --- @param v Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Normalizes the 3D short integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction function vec3s_normalize(v) -- ... @@ -7015,7 +7066,7 @@ end --- @param v Vec3s --- @param mag number ---- @return Pointer_integer +--- @return Vec3s --- Sets the length (magnitude) of 3D short integer vector `v`, while retaining its direction function vec3s_set_magnitude(v, mag) -- ... @@ -7032,7 +7083,7 @@ end --- @param dest Vec3s --- @param a Vec3s --- @param b Vec3s ---- @return Pointer_integer +--- @return Vec3s --- Computes the cross product of two 3D short integer vectors `a` and `b` and stores the result in `dest` function vec3s_cross(dest, a, b) -- ... @@ -7043,7 +7094,7 @@ end --- @param vecB Vec3s --- @param sclA number --- @param sclB number ---- @return Pointer_integer +--- @return Vec3s --- Takes two 3D short integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` function vec3s_combine(dest, vecA, vecB, sclA, sclB) -- ... @@ -7074,7 +7125,7 @@ end --- @param dest Vec3f --- @param a Vec3s ---- @return Pointer_number +--- @return Vec3f --- Converts a 3D short integer vector `a` into a 3D floating-point vector and stores the result in `dest` function vec3s_to_vec3f(dest, a) -- ... @@ -7082,7 +7133,7 @@ end --- @param dest Vec3i --- @param a Vec3s ---- @return Pointer_integer +--- @return Vec3i --- Converts a 3D short integer vector `a` into a 3D integer vector and stores the result in `dest` function vec3s_to_vec3i(dest, a) -- ... @@ -11693,3 +11744,14 @@ end --- @alias Pointer_Collision Collision --- @alias Pointer_Gfx Gfx --- @alias Pointer_Vtx Vtx +--- @alias Vec2fp Vec2f +--- @alias Vec3fp Vec3f +--- @alias Vec4fp Vec4f +--- @alias Vec2ip Vec2i +--- @alias Vec3ip Vec3i +--- @alias Vec4ip Vec4i +--- @alias Vec2sp Vec2s +--- @alias Vec3sp Vec3s +--- @alias Vec4sp Vec4s +--- @alias Mat4p Mat4 +--- @alias Colorp Color diff --git a/autogen/vec_types.py b/autogen/vec_types.py index 1b925ef8b..9d72c2b3f 100644 --- a/autogen/vec_types.py +++ b/autogen/vec_types.py @@ -6,6 +6,10 @@ VEC_TYPES = { "x": "[0]", "y": "[1]", }, + "constants": { + "Zero": [ 0, 0 ], + "One": [ 1, 1 ], + }, }, "Vec3f": { "field_c_type": "f32", @@ -15,6 +19,13 @@ VEC_TYPES = { "y": "[1]", "z": "[2]", }, + "constants": { + "Zero": [ 0, 0, 0 ], + "One": [ 1, 1, 1 ], + "X": [ 1, 0, 0 ], + "Y": [ 0, 1, 0 ], + "Z": [ 0, 0, 1 ], + }, }, "Vec4f": { "field_c_type": "f32", @@ -25,6 +36,10 @@ VEC_TYPES = { "z": "[2]", "w": "[3]", }, + "constants": { + "Zero": [ 0, 0, 0, 0 ], + "One": [ 1, 1, 1, 1 ], + }, }, "Vec2i": { "field_c_type": "s32", @@ -33,6 +48,10 @@ VEC_TYPES = { "x": "[0]", "y": "[1]", }, + "constants": { + "Zero": [ 0, 0 ], + "One": [ 1, 1 ], + }, }, "Vec3i": { "field_c_type": "s32", @@ -42,6 +61,10 @@ VEC_TYPES = { "y": "[1]", "z": "[2]", }, + "constants": { + "Zero": [ 0, 0, 0 ], + "One": [ 1, 1, 1 ], + }, }, "Vec4i": { "field_c_type": "s32", @@ -52,6 +75,10 @@ VEC_TYPES = { "z": "[2]", "w": "[3]", }, + "constants": { + "Zero": [ 0, 0, 0, 0 ], + "One": [ 1, 1, 1, 1 ], + }, }, "Vec2s": { "field_c_type": "s16", @@ -60,6 +87,10 @@ VEC_TYPES = { "x": "[0]", "y": "[1]", }, + "constants": { + "Zero": [ 0, 0 ], + "One": [ 1, 1 ], + }, }, "Vec3s": { "field_c_type": "s16", @@ -69,6 +100,10 @@ VEC_TYPES = { "y": "[1]", "z": "[2]", }, + "constants": { + "Zero": [ 0, 0, 0 ], + "One": [ 1, 1, 1 ], + }, }, "Vec4s": { "field_c_type": "s16", @@ -79,6 +114,10 @@ VEC_TYPES = { "z": "[2]", "w": "[3]", }, + "constants": { + "Zero": [ 0, 0, 0, 0 ], + "One": [ 1, 1, 1, 1 ], + }, }, "Mat4": { "field_c_type": "f32", @@ -119,6 +158,11 @@ VEC_TYPES = { "o": "[3][2]", "p": "[3][3]", }, + "constants": { + "Zero": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + "Identity": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "Fullscreen": [ 2.0 / 320.0, 0, 0, 0, 0, 2.0 / 240.0, 0, 0, 0, 0, -1, 0, -1, -1, -1, 1 ] + }, }, "Color": { "field_c_type": "u8", @@ -130,3 +174,8 @@ VEC_TYPES = { }, }, } + +VECP_TYPES = { + vec_type + "p": vec_type + for vec_type in VEC_TYPES +} diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 8304100ac..e74eb3d08 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -6425,7 +6425,7 @@ Calculates the lighting with `lightIntensityScalar` at a position and outputs th | Field | Type | | ----- | ---- | | pos | [Vec3f](structs.md#Vec3f) | -| out | `Color` | +| out | [Color](structs.md#Color) | | lightIntensityScalar | `number` | ### Returns diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index 1fa558fc8..72de5afc3 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -4303,7 +4303,7 @@ Computes spline interpolation weights for a given parameter `t` and stores these | Field | Type | | ----- | ---- | | m | [MarioState](structs.md#MarioState) | -| result | `Vec4f` | +| result | [Vec4f](structs.md#Vec4f) | | t | `number` | | c | `integer` | @@ -4371,7 +4371,7 @@ Advances the spline-based animation associated with `m` and stores the current i Rotates the 3D floating-point vector `v` by the angles specified in the 3D signed-integer vector `rotate`, applying the rotations in the order Z, then X, then Y. The rotated vector replaces `v` ### Lua Example -`local PointerValue = vec3f_rotate_zxy(v, rotate)` +`local Vec3fValue = vec3f_rotate_zxy(v, rotate)` ### Parameters | Field | Type | @@ -4380,10 +4380,10 @@ Rotates the 3D floating-point vector `v` by the angles specified in the 3D signe | rotate | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_rotate_zxy(Vec3f v, Vec3s rotate);` +`Vec3fp vec3f_rotate_zxy(Vec3f v, Vec3s rotate);` [:arrow_up_small:](#) @@ -4395,7 +4395,7 @@ Rotates the 3D floating-point vector `v` by the angles specified in the 3D signe Rotates the 3D floating-point vector `v` around the vector `n`, given a rotation `r` (in sm64 angle units), and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_rotate_around_n(dest, v, n, r)` +`local Vec3fValue = vec3f_rotate_around_n(dest, v, n, r)` ### Parameters | Field | Type | @@ -4406,10 +4406,10 @@ Rotates the 3D floating-point vector `v` around the vector `n`, given a rotation | r | `integer` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r);` +`Vec3fp vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r);` [:arrow_up_small:](#) @@ -4421,7 +4421,7 @@ Rotates the 3D floating-point vector `v` around the vector `n`, given a rotation Projects the 3D floating-point vector `v` onto another 3D floating-point vector `onto`. The resulting projection, stored in `dest`, represents how much of `v` lies along the direction of `onto` ### Lua Example -`local PointerValue = vec3f_project(dest, v, onto)` +`local Vec3fValue = vec3f_project(dest, v, onto)` ### Parameters | Field | Type | @@ -4431,10 +4431,10 @@ Projects the 3D floating-point vector `v` onto another 3D floating-point vector | onto | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_project(Vec3f dest, Vec3f v, Vec3f onto);` +`Vec3fp vec3f_project(Vec3f dest, Vec3f v, Vec3f onto);` [:arrow_up_small:](#) @@ -4446,7 +4446,7 @@ Projects the 3D floating-point vector `v` onto another 3D floating-point vector Scales the 3D floating-point vector `v` by the vector `scale`, then rotates it by the rotation vector `rotation`, and finally translates it by the vector `translation`. The resulting vector is stored in `dest` ### Lua Example -`local PointerValue = vec3f_transform(dest, v, translation, rotation, scale)` +`local Vec3fValue = vec3f_transform(dest, v, translation, rotation, scale)` ### Parameters | Field | Type | @@ -4458,10 +4458,10 @@ Scales the 3D floating-point vector `v` by the vector `scale`, then rotates it b | scale | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale);` +`Vec3fp vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale);` [:arrow_up_small:](#) @@ -4527,7 +4527,7 @@ Positions the point `to` at a given `dist`, `pitch`, and `yaw` relative to the p Determines a vector that is perpendicular (normal) to the plane defined by three given 3D floating-point points `a`, `b`, and `c`. The resulting perpendicular vector is stored in `dest` ### Lua Example -`local PointerValue = find_vector_perpendicular_to_plane(dest, a, b, c)` +`local Vec3fValue = find_vector_perpendicular_to_plane(dest, a, b, c)` ### Parameters | Field | Type | @@ -4538,10 +4538,10 @@ Determines a vector that is perpendicular (normal) to the plane defined by three | c | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c);` +`Vec3fp find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c);` [:arrow_up_small:](#) @@ -4558,7 +4558,7 @@ Adjusts the 4x4 floating-point matrix `mtx` so that it represents a viewing tran ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | | from | [Vec3f](structs.md#Vec3f) | | to | [Vec3f](structs.md#Vec3f) | | roll | `integer` | @@ -4584,7 +4584,7 @@ Rotates `dest` according to the angles in `rotate` using ZXY order, and then tra ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | | translate | [Vec3f](structs.md#Vec3f) | | rotate | [Vec3s](structs.md#Vec3s) | @@ -4609,7 +4609,7 @@ Rotates `dest` using angles in XYZ order, and then translates it by the 3D float ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | | b | [Vec3f](structs.md#Vec3f) | | c | [Vec3s](structs.md#Vec3s) | @@ -4634,8 +4634,8 @@ Transforms a 4x4 floating-point matrix `mtx` into a "billboard" oriented toward ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| mtx | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| mtx | [Mat4](structs.md#Mat4) | | position | [Vec3f](structs.md#Vec3f) | | angle | `integer` | @@ -4660,8 +4660,8 @@ Creates a "cylindrical billboard" transformation from the 4x4 matrix `mtx` place ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| mtx | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| mtx | [Mat4](structs.md#Mat4) | | position | [Vec3f](structs.md#Vec3f) | | angle | `integer` | @@ -4686,7 +4686,7 @@ Aligns `dest` so that it fits the orientation of a terrain surface defined by it ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | | upDir | [Vec3f](structs.md#Vec3f) | | pos | [Vec3f](structs.md#Vec3f) | | yaw | `integer` | @@ -4712,7 +4712,7 @@ Aligns `mtx` to fit onto a terrain triangle at `pos`, applying a given `yaw` and ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | | pos | [Vec3f](structs.md#Vec3f) | | yaw | `integer` | | radius | `number` | @@ -4738,9 +4738,9 @@ Multiplies two 4x4 floating-point matrices `a` and `b` (in that order), storing ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| a | `Mat4` | -| b | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| a | [Mat4](structs.md#Mat4) | +| b | [Mat4](structs.md#Mat4) | ### Returns - None @@ -4755,7 +4755,7 @@ Multiplies two 4x4 floating-point matrices `a` and `b` (in that order), storing ## [mtxf_mul_vec3s](#mtxf_mul_vec3s) ### Description -Multiplies the 4x4 floating-point matrix `mtx` by a 3D signed-integer vector `b`, potentially interpreting `b` as angles or translations depending on usage, and modifies `mtx` accordingly +Multiplies the 3D signed-integer vector `b` with the 4x4 floating-point matrix `mtx`, which applies the transformation to the point ### Lua Example `local PointerValue = mtxf_mul_vec3s(mtx, b)` @@ -4763,7 +4763,7 @@ Multiplies the 4x4 floating-point matrix `mtx` by a 3D signed-integer vector `b` ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | | b | [Vec3s](structs.md#Vec3s) | ### Returns @@ -4787,7 +4787,7 @@ Rotates the matrix `mtx` in the XY plane by the given `angle`. Rotating in the X ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | | angle | `integer` | ### Returns @@ -4811,8 +4811,8 @@ Inverts the 4x4 floating-point matrix `src` and stores the inverse in `dest`. Ap ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| src | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| src | [Mat4](structs.md#Mat4) | ### Returns - None @@ -4830,20 +4830,20 @@ Inverts the 4x4 floating-point matrix `src` and stores the inverse in `dest`. Ap Extracts the position (translation component) from the transformation matrix `objMtx` relative to the coordinate system defined by `camMtx` and stores that 3D position in `dest`. This can be used to get the object's coordinates in camera space ### Lua Example -`local PointerValue = get_pos_from_transform_mtx(dest, objMtx, camMtx)` +`local Vec3fValue = get_pos_from_transform_mtx(dest, objMtx, camMtx)` ### Parameters | Field | Type | | ----- | ---- | | dest | [Vec3f](structs.md#Vec3f) | -| objMtx | `Mat4` | -| camMtx | `Mat4` | +| objMtx | [Mat4](structs.md#Mat4) | +| camMtx | [Mat4](structs.md#Mat4) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx);` +`Vec3fp get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx);` [:arrow_up_small:](#) @@ -4988,7 +4988,7 @@ Sets the 4x4 floating-point matrix `mtx` to all zeros. Unless you really need th ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | ### Returns - None @@ -5011,8 +5011,8 @@ Copies the 4x4 floating-point matrix `src` into `dest`. After this operation, `d ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| src | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| src | [Mat4](structs.md#Mat4) | ### Returns - None @@ -5035,7 +5035,7 @@ Sets the 4x4 floating-point matrix `mtx` to the identity matrix. The identity ma ### Parameters | Field | Type | | ----- | ---- | -| mtx | `Mat4` | +| mtx | [Mat4](structs.md#Mat4) | ### Returns - None @@ -5058,7 +5058,7 @@ Applies a translation to the 4x4 floating-point matrix `dest` by adding the coor ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | | b | [Vec3f](structs.md#Vec3f) | ### Returns @@ -5082,8 +5082,8 @@ Scales the 4x4 floating-point matrix `mtx` by the scaling factors found in the 3 ### Parameters | Field | Type | | ----- | ---- | -| dest | `Mat4` | -| mtx | `Mat4` | +| dest | [Mat4](structs.md#Mat4) | +| mtx | [Mat4](structs.md#Mat4) | | s | [Vec3f](structs.md#Vec3f) | ### Returns @@ -5108,7 +5108,7 @@ Scales the 4x4 floating-point matrix `mtx` by the scaling factors found in the 3 Sets the components of the 3D floating-point vector `v` to 0 ### Lua Example -`local PointerValue = vec3f_zero(v)` +`local Vec3fValue = vec3f_zero(v)` ### Parameters | Field | Type | @@ -5116,10 +5116,10 @@ Sets the components of the 3D floating-point vector `v` to 0 | v | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_zero(Vec3f v);` +`Vec3fp vec3f_zero(Vec3f v);` [:arrow_up_small:](#) @@ -5131,7 +5131,7 @@ Sets the components of the 3D floating-point vector `v` to 0 Copies the contents of a 3D floating-point vector (`src`) into another 3D floating-point vector (`dest`) ### Lua Example -`local PointerValue = vec3f_copy(dest, src)` +`local Vec3fValue = vec3f_copy(dest, src)` ### Parameters | Field | Type | @@ -5140,10 +5140,10 @@ Copies the contents of a 3D floating-point vector (`src`) into another 3D floati | src | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_copy(Vec3f dest, Vec3f src);` +`Vec3fp vec3f_copy(Vec3f dest, Vec3f src);` [:arrow_up_small:](#) @@ -5155,7 +5155,7 @@ Copies the contents of a 3D floating-point vector (`src`) into another 3D floati Sets the values of the 3D floating-point vector `dest` to the given x, y, and z values ### Lua Example -`local PointerValue = vec3f_set(dest, x, y, z)` +`local Vec3fValue = vec3f_set(dest, x, y, z)` ### Parameters | Field | Type | @@ -5166,10 +5166,10 @@ Sets the values of the 3D floating-point vector `dest` to the given x, y, and z | z | `number` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);` +`Vec3fp vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);` [:arrow_up_small:](#) @@ -5181,7 +5181,7 @@ Sets the values of the 3D floating-point vector `dest` to the given x, y, and z Adds the components of the 3D floating-point vector `a` to `dest` ### Lua Example -`local PointerValue = vec3f_add(dest, a)` +`local Vec3fValue = vec3f_add(dest, a)` ### Parameters | Field | Type | @@ -5190,10 +5190,10 @@ Adds the components of the 3D floating-point vector `a` to `dest` | a | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_add(Vec3f dest, Vec3f a);` +`Vec3fp vec3f_add(Vec3f dest, Vec3f a);` [:arrow_up_small:](#) @@ -5205,7 +5205,7 @@ Adds the components of the 3D floating-point vector `a` to `dest` Adds the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_sum(dest, a, b)` +`local Vec3fValue = vec3f_sum(dest, a, b)` ### Parameters | Field | Type | @@ -5215,10 +5215,10 @@ Adds the components of two 3D floating-point vectors `a` and `b` and stores the | b | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b);` +`Vec3fp vec3f_sum(Vec3f dest, Vec3f a, Vec3f b);` [:arrow_up_small:](#) @@ -5230,7 +5230,7 @@ Adds the components of two 3D floating-point vectors `a` and `b` and stores the Subtracts the components of the 3D floating-point vector `a` from `dest` ### Lua Example -`local PointerValue = vec3f_sub(dest, a)` +`local Vec3fValue = vec3f_sub(dest, a)` ### Parameters | Field | Type | @@ -5239,10 +5239,10 @@ Subtracts the components of the 3D floating-point vector `a` from `dest` | a | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_sub(Vec3f dest, Vec3f a);` +`Vec3fp vec3f_sub(Vec3f dest, Vec3f a);` [:arrow_up_small:](#) @@ -5254,7 +5254,7 @@ Subtracts the components of the 3D floating-point vector `a` from `dest` Subtracts the components of the 3D floating-point vector `b` from the components of `a` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_dif(dest, a, b)` +`local Vec3fValue = vec3f_dif(dest, a, b)` ### Parameters | Field | Type | @@ -5264,10 +5264,10 @@ Subtracts the components of the 3D floating-point vector `b` from the components | b | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_dif(Vec3f dest, Vec3f a, Vec3f b);` +`Vec3fp vec3f_dif(Vec3f dest, Vec3f a, Vec3f b);` [:arrow_up_small:](#) @@ -5279,7 +5279,7 @@ Subtracts the components of the 3D floating-point vector `b` from the components Multiplies each component of the 3D floating-point vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3f_mul(dest, a)` +`local Vec3fValue = vec3f_mul(dest, a)` ### Parameters | Field | Type | @@ -5288,10 +5288,59 @@ Multiplies each component of the 3D floating-point vector `dest` by the scalar v | a | `number` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_mul(Vec3f dest, f32 a);` +`Vec3fp vec3f_mul(Vec3f dest, f32 a);` + +[:arrow_up_small:](#) + +
+ +## [vec3f_mult](#vec3f_mult) + +### Description +Multiplies the components of the 3D floating-point vector `dest` with the components of `a` + +### Lua Example +`local Vec3fValue = vec3f_mult(dest, a)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3f](structs.md#Vec3f) | +| a | [Vec3f](structs.md#Vec3f) | + +### Returns +[Vec3f](structs.md#Vec3f) + +### C Prototype +`Vec3fp vec3f_mult(Vec3f dest, Vec3f a);` + +[:arrow_up_small:](#) + +
+ +## [vec3f_prod](#vec3f_prod) + +### Description +Multiplies the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` + +### Lua Example +`local Vec3fValue = vec3f_prod(dest, a, b)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3f](structs.md#Vec3f) | +| a | [Vec3f](structs.md#Vec3f) | +| b | [Vec3f](structs.md#Vec3f) | + +### Returns +[Vec3f](structs.md#Vec3f) + +### C Prototype +`Vec3fp vec3f_prod(Vec3f dest, Vec3f a, Vec3f b);` [:arrow_up_small:](#) @@ -5303,7 +5352,7 @@ Multiplies each component of the 3D floating-point vector `dest` by the scalar v Divides each component of the 3D floating-point vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3f_div(dest, a)` +`local Vec3fValue = vec3f_div(dest, a)` ### Parameters | Field | Type | @@ -5312,10 +5361,10 @@ Divides each component of the 3D floating-point vector `dest` by the scalar valu | a | `number` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_div(Vec3f dest, f32 a);` +`Vec3fp vec3f_div(Vec3f dest, f32 a);` [:arrow_up_small:](#) @@ -5350,7 +5399,7 @@ Calculates the length (magnitude) of the 3D floating-point vector `a` Normalizes the 3D floating-point vector `v` so that its length (magnitude) becomes 1, while retaining its direction ### Lua Example -`local PointerValue = vec3f_normalize(v)` +`local Vec3fValue = vec3f_normalize(v)` ### Parameters | Field | Type | @@ -5358,10 +5407,10 @@ Normalizes the 3D floating-point vector `v` so that its length (magnitude) becom | v | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_normalize(Vec3f v);` +`Vec3fp vec3f_normalize(Vec3f v);` [:arrow_up_small:](#) @@ -5373,7 +5422,7 @@ Normalizes the 3D floating-point vector `v` so that its length (magnitude) becom Sets the length (magnitude) of 3D floating-point vector `v`, while retaining its direction ### Lua Example -`local PointerValue = vec3f_set_magnitude(v, mag)` +`local Vec3fValue = vec3f_set_magnitude(v, mag)` ### Parameters | Field | Type | @@ -5382,10 +5431,10 @@ Sets the length (magnitude) of 3D floating-point vector `v`, while retaining its | mag | `number` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_set_magnitude(Vec3f v, f32 mag);` +`Vec3fp vec3f_set_magnitude(Vec3f v, f32 mag);` [:arrow_up_small:](#) @@ -5421,7 +5470,7 @@ Computes the dot product of the two 3D floating-point vectors `a` and `b` Computes the cross product of two 3D floating-point vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_cross(dest, a, b)` +`local Vec3fValue = vec3f_cross(dest, a, b)` ### Parameters | Field | Type | @@ -5431,10 +5480,10 @@ Computes the cross product of two 3D floating-point vectors `a` and `b` and stor | b | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);` +`Vec3fp vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);` [:arrow_up_small:](#) @@ -5446,7 +5495,7 @@ Computes the cross product of two 3D floating-point vectors `a` and `b` and stor Takes two 3D floating-point vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_combine(dest, vecA, vecB, sclA, sclB)` +`local Vec3fValue = vec3f_combine(dest, vecA, vecB, sclA, sclB)` ### Parameters | Field | Type | @@ -5458,10 +5507,10 @@ Takes two 3D floating-point vectors `vecA` and `vecB`, multiplies them by `sclA` | sclB | `number` | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3f_combine(Vec3f dest, Vec3f vecA, Vec3f vecB, f32 sclA, f32 sclB);` +`Vec3fp vec3f_combine(Vec3f dest, Vec3f vecA, Vec3f vecB, f32 sclA, f32 sclB);` [:arrow_up_small:](#) @@ -5544,7 +5593,7 @@ Returns `true` if all components of the 3D floating-point vector `v` are zero Converts a 3D floating-point vector `a` into a 3D integer vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_to_vec3i(dest, a)` +`local Vec3iValue = vec3f_to_vec3i(dest, a)` ### Parameters | Field | Type | @@ -5553,10 +5602,10 @@ Converts a 3D floating-point vector `a` into a 3D integer vector and stores the | a | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3f_to_vec3i(Vec3i dest, Vec3f a);` +`Vec3ip vec3f_to_vec3i(Vec3i dest, Vec3f a);` [:arrow_up_small:](#) @@ -5568,7 +5617,7 @@ Converts a 3D floating-point vector `a` into a 3D integer vector and stores the Converts a 3D floating-point vector `a` into a 3D short integer vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3f_to_vec3s(dest, a)` +`local Vec3sValue = vec3f_to_vec3s(dest, a)` ### Parameters | Field | Type | @@ -5577,10 +5626,10 @@ Converts a 3D floating-point vector `a` into a 3D short integer vector and store | a | [Vec3f](structs.md#Vec3f) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3f_to_vec3s(Vec3s dest, Vec3f a);` +`Vec3sp vec3f_to_vec3s(Vec3s dest, Vec3f a);` [:arrow_up_small:](#) @@ -5598,7 +5647,7 @@ Converts a 3D floating-point vector `a` into a 3D short integer vector and store Sets the components of the 3D integer vector `v` to 0 ### Lua Example -`local PointerValue = vec3i_zero(v)` +`local Vec3iValue = vec3i_zero(v)` ### Parameters | Field | Type | @@ -5606,10 +5655,10 @@ Sets the components of the 3D integer vector `v` to 0 | v | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_zero(Vec3i v);` +`Vec3ip vec3i_zero(Vec3i v);` [:arrow_up_small:](#) @@ -5621,7 +5670,7 @@ Sets the components of the 3D integer vector `v` to 0 Copies the contents of a 3D integer vector (`src`) into another 3D integer vector (`dest`) ### Lua Example -`local PointerValue = vec3i_copy(dest, src)` +`local Vec3iValue = vec3i_copy(dest, src)` ### Parameters | Field | Type | @@ -5630,10 +5679,10 @@ Copies the contents of a 3D integer vector (`src`) into another 3D integer vecto | src | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_copy(Vec3i dest, Vec3i src);` +`Vec3ip vec3i_copy(Vec3i dest, Vec3i src);` [:arrow_up_small:](#) @@ -5645,7 +5694,7 @@ Copies the contents of a 3D integer vector (`src`) into another 3D integer vecto Sets the values of the 3D integer vector `dest` to the given x, y, and z values ### Lua Example -`local PointerValue = vec3i_set(dest, x, y, z)` +`local Vec3iValue = vec3i_set(dest, x, y, z)` ### Parameters | Field | Type | @@ -5656,10 +5705,10 @@ Sets the values of the 3D integer vector `dest` to the given x, y, and z values | z | `integer` | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_set(Vec3i dest, s32 x, s32 y, s32 z);` +`Vec3ip vec3i_set(Vec3i dest, s32 x, s32 y, s32 z);` [:arrow_up_small:](#) @@ -5671,7 +5720,7 @@ Sets the values of the 3D integer vector `dest` to the given x, y, and z values Adds the components of the 3D integer vector `a` to `dest` ### Lua Example -`local PointerValue = vec3i_add(dest, a)` +`local Vec3iValue = vec3i_add(dest, a)` ### Parameters | Field | Type | @@ -5680,10 +5729,10 @@ Adds the components of the 3D integer vector `a` to `dest` | a | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_add(Vec3i dest, Vec3i a);` +`Vec3ip vec3i_add(Vec3i dest, Vec3i a);` [:arrow_up_small:](#) @@ -5695,7 +5744,7 @@ Adds the components of the 3D integer vector `a` to `dest` Adds the components of two 3D integer vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_sum(dest, a, b)` +`local Vec3iValue = vec3i_sum(dest, a, b)` ### Parameters | Field | Type | @@ -5705,10 +5754,10 @@ Adds the components of two 3D integer vectors `a` and `b` and stores the result | b | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_sum(Vec3i dest, Vec3i a, Vec3i b);` +`Vec3ip vec3i_sum(Vec3i dest, Vec3i a, Vec3i b);` [:arrow_up_small:](#) @@ -5720,7 +5769,7 @@ Adds the components of two 3D integer vectors `a` and `b` and stores the result Subtracts the components of the 3D integer vector `a` from `dest` ### Lua Example -`local PointerValue = vec3i_sub(dest, a)` +`local Vec3iValue = vec3i_sub(dest, a)` ### Parameters | Field | Type | @@ -5729,10 +5778,10 @@ Subtracts the components of the 3D integer vector `a` from `dest` | a | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_sub(Vec3i dest, Vec3i a);` +`Vec3ip vec3i_sub(Vec3i dest, Vec3i a);` [:arrow_up_small:](#) @@ -5744,7 +5793,7 @@ Subtracts the components of the 3D integer vector `a` from `dest` Subtracts the components of the 3D integer vector `b` from the components of `a` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_dif(dest, a, b)` +`local Vec3iValue = vec3i_dif(dest, a, b)` ### Parameters | Field | Type | @@ -5754,10 +5803,10 @@ Subtracts the components of the 3D integer vector `b` from the components of `a` | b | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_dif(Vec3i dest, Vec3i a, Vec3i b);` +`Vec3ip vec3i_dif(Vec3i dest, Vec3i a, Vec3i b);` [:arrow_up_small:](#) @@ -5769,7 +5818,7 @@ Subtracts the components of the 3D integer vector `b` from the components of `a` Multiplies each component of the 3D integer vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3i_mul(dest, a)` +`local Vec3iValue = vec3i_mul(dest, a)` ### Parameters | Field | Type | @@ -5778,10 +5827,59 @@ Multiplies each component of the 3D integer vector `dest` by the scalar value `a | a | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_mul(Vec3i dest, f32 a);` +`Vec3ip vec3i_mul(Vec3i dest, f32 a);` + +[:arrow_up_small:](#) + +
+ +## [vec3i_mult](#vec3i_mult) + +### Description +Multiplies the components of the 3D integer vector `dest` with the components of `a` + +### Lua Example +`local Vec3iValue = vec3i_mult(dest, a)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3i](structs.md#Vec3i) | +| a | [Vec3i](structs.md#Vec3i) | + +### Returns +[Vec3i](structs.md#Vec3i) + +### C Prototype +`Vec3ip vec3i_mult(Vec3i dest, Vec3i a);` + +[:arrow_up_small:](#) + +
+ +## [vec3i_prod](#vec3i_prod) + +### Description +Multiplies the components of two 3D integer vectors `a` and `b` and stores the result in `dest` + +### Lua Example +`local Vec3iValue = vec3i_prod(dest, a, b)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3i](structs.md#Vec3i) | +| a | [Vec3i](structs.md#Vec3i) | +| b | [Vec3i](structs.md#Vec3i) | + +### Returns +[Vec3i](structs.md#Vec3i) + +### C Prototype +`Vec3ip vec3i_prod(Vec3i dest, Vec3i a, Vec3i b);` [:arrow_up_small:](#) @@ -5793,7 +5891,7 @@ Multiplies each component of the 3D integer vector `dest` by the scalar value `a Divides each component of the 3D integer vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3i_div(dest, a)` +`local Vec3iValue = vec3i_div(dest, a)` ### Parameters | Field | Type | @@ -5802,10 +5900,10 @@ Divides each component of the 3D integer vector `dest` by the scalar value `a` | a | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_div(Vec3i dest, f32 a);` +`Vec3ip vec3i_div(Vec3i dest, f32 a);` [:arrow_up_small:](#) @@ -5840,7 +5938,7 @@ Calculates the length (magnitude) of the 3D integer vector `a` Normalizes the 3D integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction ### Lua Example -`local PointerValue = vec3i_normalize(v)` +`local Vec3iValue = vec3i_normalize(v)` ### Parameters | Field | Type | @@ -5848,10 +5946,10 @@ Normalizes the 3D integer vector `v` so that its length (magnitude) becomes 1, w | v | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_normalize(Vec3i v);` +`Vec3ip vec3i_normalize(Vec3i v);` [:arrow_up_small:](#) @@ -5863,7 +5961,7 @@ Normalizes the 3D integer vector `v` so that its length (magnitude) becomes 1, w Sets the length (magnitude) of 3D integer vector `v`, while retaining its direction ### Lua Example -`local PointerValue = vec3i_set_magnitude(v, mag)` +`local Vec3iValue = vec3i_set_magnitude(v, mag)` ### Parameters | Field | Type | @@ -5872,10 +5970,10 @@ Sets the length (magnitude) of 3D integer vector `v`, while retaining its direct | mag | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_set_magnitude(Vec3i v, f32 mag);` +`Vec3ip vec3i_set_magnitude(Vec3i v, f32 mag);` [:arrow_up_small:](#) @@ -5911,7 +6009,7 @@ Computes the dot product of the two 3D integer vectors `a` and `b` Computes the cross product of two 3D integer vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_cross(dest, a, b)` +`local Vec3iValue = vec3i_cross(dest, a, b)` ### Parameters | Field | Type | @@ -5921,10 +6019,10 @@ Computes the cross product of two 3D integer vectors `a` and `b` and stores the | b | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_cross(Vec3i dest, Vec3i a, Vec3i b);` +`Vec3ip vec3i_cross(Vec3i dest, Vec3i a, Vec3i b);` [:arrow_up_small:](#) @@ -5936,7 +6034,7 @@ Computes the cross product of two 3D integer vectors `a` and `b` and stores the Takes two 3D integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_combine(dest, vecA, vecB, sclA, sclB)` +`local Vec3iValue = vec3i_combine(dest, vecA, vecB, sclA, sclB)` ### Parameters | Field | Type | @@ -5948,10 +6046,10 @@ Takes two 3D integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `s | sclB | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3i_combine(Vec3i dest, Vec3i vecA, Vec3i vecB, f32 sclA, f32 sclB);` +`Vec3ip vec3i_combine(Vec3i dest, Vec3i vecA, Vec3i vecB, f32 sclA, f32 sclB);` [:arrow_up_small:](#) @@ -6034,7 +6132,7 @@ Returns `true` if all components of the 3D integer vector `v` are zero Converts a 3D integer vector `a` into a 3D floating-point vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_to_vec3f(dest, a)` +`local Vec3fValue = vec3i_to_vec3f(dest, a)` ### Parameters | Field | Type | @@ -6043,10 +6141,10 @@ Converts a 3D integer vector `a` into a 3D floating-point vector and stores the | a | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3i_to_vec3f(Vec3f dest, Vec3i a);` +`Vec3fp vec3i_to_vec3f(Vec3f dest, Vec3i a);` [:arrow_up_small:](#) @@ -6058,7 +6156,7 @@ Converts a 3D integer vector `a` into a 3D floating-point vector and stores the Converts a 3D integer vector `a` into a 3D short integer vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3i_to_vec3s(dest, a)` +`local Vec3sValue = vec3i_to_vec3s(dest, a)` ### Parameters | Field | Type | @@ -6067,10 +6165,10 @@ Converts a 3D integer vector `a` into a 3D short integer vector and stores the r | a | [Vec3i](structs.md#Vec3i) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3i_to_vec3s(Vec3s dest, Vec3i a);` +`Vec3sp vec3i_to_vec3s(Vec3s dest, Vec3i a);` [:arrow_up_small:](#) @@ -6088,7 +6186,7 @@ Converts a 3D integer vector `a` into a 3D short integer vector and stores the r Sets the components of the 3D short integer vector `v` to 0 ### Lua Example -`local PointerValue = vec3s_zero(v)` +`local Vec3sValue = vec3s_zero(v)` ### Parameters | Field | Type | @@ -6096,10 +6194,10 @@ Sets the components of the 3D short integer vector `v` to 0 | v | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_zero(Vec3s v);` +`Vec3sp vec3s_zero(Vec3s v);` [:arrow_up_small:](#) @@ -6111,7 +6209,7 @@ Sets the components of the 3D short integer vector `v` to 0 Copies the contents of a 3D short integer vector (`src`) into another 3D short integer vector (`dest`) ### Lua Example -`local PointerValue = vec3s_copy(dest, src)` +`local Vec3sValue = vec3s_copy(dest, src)` ### Parameters | Field | Type | @@ -6120,10 +6218,10 @@ Copies the contents of a 3D short integer vector (`src`) into another 3D short i | src | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_copy(Vec3s dest, Vec3s src);` +`Vec3sp vec3s_copy(Vec3s dest, Vec3s src);` [:arrow_up_small:](#) @@ -6135,7 +6233,7 @@ Copies the contents of a 3D short integer vector (`src`) into another 3D short i Sets the values of the 3D short integer vector `dest` to the given x, y, and z values ### Lua Example -`local PointerValue = vec3s_set(dest, x, y, z)` +`local Vec3sValue = vec3s_set(dest, x, y, z)` ### Parameters | Field | Type | @@ -6146,10 +6244,10 @@ Sets the values of the 3D short integer vector `dest` to the given x, y, and z v | z | `integer` | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);` +`Vec3sp vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);` [:arrow_up_small:](#) @@ -6161,7 +6259,7 @@ Sets the values of the 3D short integer vector `dest` to the given x, y, and z v Adds the components of the 3D short integer vector `a` to `dest` ### Lua Example -`local PointerValue = vec3s_add(dest, a)` +`local Vec3sValue = vec3s_add(dest, a)` ### Parameters | Field | Type | @@ -6170,10 +6268,10 @@ Adds the components of the 3D short integer vector `a` to `dest` | a | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_add(Vec3s dest, Vec3s a);` +`Vec3sp vec3s_add(Vec3s dest, Vec3s a);` [:arrow_up_small:](#) @@ -6185,7 +6283,7 @@ Adds the components of the 3D short integer vector `a` to `dest` Adds the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_sum(dest, a, b)` +`local Vec3sValue = vec3s_sum(dest, a, b)` ### Parameters | Field | Type | @@ -6195,10 +6293,10 @@ Adds the components of two 3D short integer vectors `a` and `b` and stores the r | b | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);` +`Vec3sp vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);` [:arrow_up_small:](#) @@ -6210,7 +6308,7 @@ Adds the components of two 3D short integer vectors `a` and `b` and stores the r Subtracts the components of the 3D short integer vector `a` from `dest` ### Lua Example -`local PointerValue = vec3s_sub(dest, a)` +`local Vec3sValue = vec3s_sub(dest, a)` ### Parameters | Field | Type | @@ -6219,10 +6317,10 @@ Subtracts the components of the 3D short integer vector `a` from `dest` | a | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_sub(Vec3s dest, Vec3s a);` +`Vec3sp vec3s_sub(Vec3s dest, Vec3s a);` [:arrow_up_small:](#) @@ -6234,7 +6332,7 @@ Subtracts the components of the 3D short integer vector `a` from `dest` Subtracts the components of the 3D short integer vector `b` from the components of `a` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_dif(dest, a, b)` +`local Vec3sValue = vec3s_dif(dest, a, b)` ### Parameters | Field | Type | @@ -6244,10 +6342,10 @@ Subtracts the components of the 3D short integer vector `b` from the components | b | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_dif(Vec3s dest, Vec3s a, Vec3s b);` +`Vec3sp vec3s_dif(Vec3s dest, Vec3s a, Vec3s b);` [:arrow_up_small:](#) @@ -6259,7 +6357,7 @@ Subtracts the components of the 3D short integer vector `b` from the components Multiplies each component of the 3D short integer vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3s_mul(dest, a)` +`local Vec3sValue = vec3s_mul(dest, a)` ### Parameters | Field | Type | @@ -6268,10 +6366,59 @@ Multiplies each component of the 3D short integer vector `dest` by the scalar va | a | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_mul(Vec3s dest, f32 a);` +`Vec3sp vec3s_mul(Vec3s dest, f32 a);` + +[:arrow_up_small:](#) + +
+ +## [vec3s_mult](#vec3s_mult) + +### Description +Multiplies the components of the 3D short integer vector `dest` with the components of `a` + +### Lua Example +`local Vec3sValue = vec3s_mult(dest, a)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3s](structs.md#Vec3s) | +| a | [Vec3s](structs.md#Vec3s) | + +### Returns +[Vec3s](structs.md#Vec3s) + +### C Prototype +`Vec3sp vec3s_mult(Vec3s dest, Vec3s a);` + +[:arrow_up_small:](#) + +
+ +## [vec3s_prod](#vec3s_prod) + +### Description +Multiplies the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` + +### Lua Example +`local Vec3sValue = vec3s_prod(dest, a, b)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dest | [Vec3s](structs.md#Vec3s) | +| a | [Vec3s](structs.md#Vec3s) | +| b | [Vec3s](structs.md#Vec3s) | + +### Returns +[Vec3s](structs.md#Vec3s) + +### C Prototype +`Vec3sp vec3s_prod(Vec3s dest, Vec3s a, Vec3s b);` [:arrow_up_small:](#) @@ -6283,7 +6430,7 @@ Multiplies each component of the 3D short integer vector `dest` by the scalar va Divides each component of the 3D short integer vector `dest` by the scalar value `a` ### Lua Example -`local PointerValue = vec3s_div(dest, a)` +`local Vec3sValue = vec3s_div(dest, a)` ### Parameters | Field | Type | @@ -6292,10 +6439,10 @@ Divides each component of the 3D short integer vector `dest` by the scalar value | a | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_div(Vec3s dest, f32 a);` +`Vec3sp vec3s_div(Vec3s dest, f32 a);` [:arrow_up_small:](#) @@ -6330,7 +6477,7 @@ Calculates the length (magnitude) of the 3D short integer vector `a` Normalizes the 3D short integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction ### Lua Example -`local PointerValue = vec3s_normalize(v)` +`local Vec3sValue = vec3s_normalize(v)` ### Parameters | Field | Type | @@ -6338,10 +6485,10 @@ Normalizes the 3D short integer vector `v` so that its length (magnitude) become | v | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_normalize(Vec3s v);` +`Vec3sp vec3s_normalize(Vec3s v);` [:arrow_up_small:](#) @@ -6353,7 +6500,7 @@ Normalizes the 3D short integer vector `v` so that its length (magnitude) become Sets the length (magnitude) of 3D short integer vector `v`, while retaining its direction ### Lua Example -`local PointerValue = vec3s_set_magnitude(v, mag)` +`local Vec3sValue = vec3s_set_magnitude(v, mag)` ### Parameters | Field | Type | @@ -6362,10 +6509,10 @@ Sets the length (magnitude) of 3D short integer vector `v`, while retaining its | mag | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_set_magnitude(Vec3s v, f32 mag);` +`Vec3sp vec3s_set_magnitude(Vec3s v, f32 mag);` [:arrow_up_small:](#) @@ -6401,7 +6548,7 @@ Computes the dot product of the two 3D short integer vectors `a` and `b` Computes the cross product of two 3D short integer vectors `a` and `b` and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_cross(dest, a, b)` +`local Vec3sValue = vec3s_cross(dest, a, b)` ### Parameters | Field | Type | @@ -6411,10 +6558,10 @@ Computes the cross product of two 3D short integer vectors `a` and `b` and store | b | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_cross(Vec3s dest, Vec3s a, Vec3s b);` +`Vec3sp vec3s_cross(Vec3s dest, Vec3s a, Vec3s b);` [:arrow_up_small:](#) @@ -6426,7 +6573,7 @@ Computes the cross product of two 3D short integer vectors `a` and `b` and store Takes two 3D short integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_combine(dest, vecA, vecB, sclA, sclB)` +`local Vec3sValue = vec3s_combine(dest, vecA, vecB, sclA, sclB)` ### Parameters | Field | Type | @@ -6438,10 +6585,10 @@ Takes two 3D short integer vectors `vecA` and `vecB`, multiplies them by `sclA` | sclB | `number` | ### Returns -- `Pointer` <`integer`> +[Vec3s](structs.md#Vec3s) ### C Prototype -`s16 *vec3s_combine(Vec3s dest, Vec3s vecA, Vec3s vecB, f32 sclA, f32 sclB);` +`Vec3sp vec3s_combine(Vec3s dest, Vec3s vecA, Vec3s vecB, f32 sclA, f32 sclB);` [:arrow_up_small:](#) @@ -6524,7 +6671,7 @@ Returns `true` if all components of the 3D short integer vector `v` are zero Converts a 3D short integer vector `a` into a 3D floating-point vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_to_vec3f(dest, a)` +`local Vec3fValue = vec3s_to_vec3f(dest, a)` ### Parameters | Field | Type | @@ -6533,10 +6680,10 @@ Converts a 3D short integer vector `a` into a 3D floating-point vector and store | a | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`number`> +[Vec3f](structs.md#Vec3f) ### C Prototype -`f32 *vec3s_to_vec3f(Vec3f dest, Vec3s a);` +`Vec3fp vec3s_to_vec3f(Vec3f dest, Vec3s a);` [:arrow_up_small:](#) @@ -6548,7 +6695,7 @@ Converts a 3D short integer vector `a` into a 3D floating-point vector and store Converts a 3D short integer vector `a` into a 3D integer vector and stores the result in `dest` ### Lua Example -`local PointerValue = vec3s_to_vec3i(dest, a)` +`local Vec3iValue = vec3s_to_vec3i(dest, a)` ### Parameters | Field | Type | @@ -6557,251 +6704,10 @@ Converts a 3D short integer vector `a` into a 3D integer vector and stores the r | a | [Vec3s](structs.md#Vec3s) | ### Returns -- `Pointer` <`integer`> +[Vec3i](structs.md#Vec3i) ### C Prototype -`s32 *vec3s_to_vec3i(Vec3i dest, Vec3s a);` - -[:arrow_up_small:](#) - -
- ---- -# functions from misc.h - -
- - -## [smooth_step](#smooth_step) - -### Description -Smoothly steps between `edge0` and `edge1` with `x` as delta - -### Lua Example -`local numberValue = smooth_step(edge0, edge1, x)` - -### Parameters -| Field | Type | -| ----- | ---- | -| edge0 | `number` | -| edge1 | `number` | -| x | `number` | - -### Returns -- `number` - -### C Prototype -`float smooth_step(float edge0, float edge1, float x);` - -[:arrow_up_small:](#) - -
- -## [update_all_mario_stars](#update_all_mario_stars) - -### Description -Updates every Mario state's star count with the save file total star count - -### Lua Example -`update_all_mario_stars()` - -### Parameters -- None - -### Returns -- None - -### C Prototype -`void update_all_mario_stars(void);` - -[:arrow_up_small:](#) - -
- -## [clock_elapsed](#clock_elapsed) - -### Description -Gets the current clock elapsed time - -### Lua Example -`local numberValue = clock_elapsed()` - -### Parameters -- None - -### Returns -- `number` - -### C Prototype -`f32 clock_elapsed(void);` - -[:arrow_up_small:](#) - -
- -## [clock_elapsed_f64](#clock_elapsed_f64) - -### Description -Gets the current clock elapsed time with double precision - -### Lua Example -`local numberValue = clock_elapsed_f64()` - -### Parameters -- None - -### Returns -- `number` - -### C Prototype -`f64 clock_elapsed_f64(void);` - -[:arrow_up_small:](#) - -
- -## [clock_elapsed_ticks](#clock_elapsed_ticks) - -### Description -Gets the current clock elapsed time in frames - -### Lua Example -`local integerValue = clock_elapsed_ticks()` - -### Parameters -- None - -### Returns -- `integer` - -### C Prototype -`u32 clock_elapsed_ticks(void);` - -[:arrow_up_small:](#) - -
- -## [clock_is_date](#clock_is_date) - -### Description -Checks whether it is the day given - -### Lua Example -`local booleanValue = clock_is_date(month, day)` - -### Parameters -| Field | Type | -| ----- | ---- | -| month | `integer` | -| day | `integer` | - -### Returns -- `boolean` - -### C Prototype -`bool clock_is_date(u8 month, u8 day);` - -[:arrow_up_small:](#) - -
- -## [delta_interpolate_f32](#delta_interpolate_f32) - -### Description -Linearly interpolates between `a` and `b` with `delta` - -### Lua Example -`local numberValue = delta_interpolate_f32(a, b, delta)` - -### Parameters -| Field | Type | -| ----- | ---- | -| a | `number` | -| b | `number` | -| delta | `number` | - -### Returns -- `number` - -### C Prototype -`f32 delta_interpolate_f32(f32 a, f32 b, f32 delta);` - -[:arrow_up_small:](#) - -
- -## [delta_interpolate_s32](#delta_interpolate_s32) - -### Description -Linearly interpolates between `a` and `b` with `delta` - -### Lua Example -`local integerValue = delta_interpolate_s32(a, b, delta)` - -### Parameters -| Field | Type | -| ----- | ---- | -| a | `integer` | -| b | `integer` | -| delta | `number` | - -### Returns -- `integer` - -### C Prototype -`s32 delta_interpolate_s32(s32 a, s32 b, f32 delta);` - -[:arrow_up_small:](#) - -
- -## [delta_interpolate_vec3f](#delta_interpolate_vec3f) - -### Description -Linearly interpolates `res` between `a` and `b` with `delta` - -### Lua Example -`delta_interpolate_vec3f(res, a, b, delta)` - -### Parameters -| Field | Type | -| ----- | ---- | -| res | [Vec3f](structs.md#Vec3f) | -| a | [Vec3f](structs.md#Vec3f) | -| b | [Vec3f](structs.md#Vec3f) | -| delta | `number` | - -### Returns -- None - -### C Prototype -`void delta_interpolate_vec3f(Vec3f res, Vec3f a, Vec3f b, f32 delta);` - -[:arrow_up_small:](#) - -
- -## [delta_interpolate_vec3s](#delta_interpolate_vec3s) - -### Description -Linearly interpolates `res` between `a` and `b` with `delta` - -### Lua Example -`delta_interpolate_vec3s(res, a, b, delta)` - -### Parameters -| Field | Type | -| ----- | ---- | -| res | [Vec3s](structs.md#Vec3s) | -| a | [Vec3s](structs.md#Vec3s) | -| b | [Vec3s](structs.md#Vec3s) | -| delta | `number` | - -### Returns -- None - -### C Prototype -`void delta_interpolate_vec3s(Vec3s res, Vec3s a, Vec3s b, f32 delta);` +`Vec3ip vec3s_to_vec3i(Vec3i dest, Vec3s a);` [:arrow_up_small:](#) diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index 59c9383bb..f2a39d725 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -5,6 +5,247 @@ [< prev](functions-4.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | 5 | [6](functions-6.md) | [next >](functions-6.md)] +--- +# functions from misc.h + +
+ + +## [smooth_step](#smooth_step) + +### Description +Smoothly steps between `edge0` and `edge1` with `x` as delta + +### Lua Example +`local numberValue = smooth_step(edge0, edge1, x)` + +### Parameters +| Field | Type | +| ----- | ---- | +| edge0 | `number` | +| edge1 | `number` | +| x | `number` | + +### Returns +- `number` + +### C Prototype +`float smooth_step(float edge0, float edge1, float x);` + +[:arrow_up_small:](#) + +
+ +## [update_all_mario_stars](#update_all_mario_stars) + +### Description +Updates every Mario state's star count with the save file total star count + +### Lua Example +`update_all_mario_stars()` + +### Parameters +- None + +### Returns +- None + +### C Prototype +`void update_all_mario_stars(void);` + +[:arrow_up_small:](#) + +
+ +## [clock_elapsed](#clock_elapsed) + +### Description +Gets the current clock elapsed time + +### Lua Example +`local numberValue = clock_elapsed()` + +### Parameters +- None + +### Returns +- `number` + +### C Prototype +`f32 clock_elapsed(void);` + +[:arrow_up_small:](#) + +
+ +## [clock_elapsed_f64](#clock_elapsed_f64) + +### Description +Gets the current clock elapsed time with double precision + +### Lua Example +`local numberValue = clock_elapsed_f64()` + +### Parameters +- None + +### Returns +- `number` + +### C Prototype +`f64 clock_elapsed_f64(void);` + +[:arrow_up_small:](#) + +
+ +## [clock_elapsed_ticks](#clock_elapsed_ticks) + +### Description +Gets the current clock elapsed time in frames + +### Lua Example +`local integerValue = clock_elapsed_ticks()` + +### Parameters +- None + +### Returns +- `integer` + +### C Prototype +`u32 clock_elapsed_ticks(void);` + +[:arrow_up_small:](#) + +
+ +## [clock_is_date](#clock_is_date) + +### Description +Checks whether it is the day given + +### Lua Example +`local booleanValue = clock_is_date(month, day)` + +### Parameters +| Field | Type | +| ----- | ---- | +| month | `integer` | +| day | `integer` | + +### Returns +- `boolean` + +### C Prototype +`bool clock_is_date(u8 month, u8 day);` + +[:arrow_up_small:](#) + +
+ +## [delta_interpolate_f32](#delta_interpolate_f32) + +### Description +Linearly interpolates between `a` and `b` with `delta` + +### Lua Example +`local numberValue = delta_interpolate_f32(a, b, delta)` + +### Parameters +| Field | Type | +| ----- | ---- | +| a | `number` | +| b | `number` | +| delta | `number` | + +### Returns +- `number` + +### C Prototype +`f32 delta_interpolate_f32(f32 a, f32 b, f32 delta);` + +[:arrow_up_small:](#) + +
+ +## [delta_interpolate_s32](#delta_interpolate_s32) + +### Description +Linearly interpolates between `a` and `b` with `delta` + +### Lua Example +`local integerValue = delta_interpolate_s32(a, b, delta)` + +### Parameters +| Field | Type | +| ----- | ---- | +| a | `integer` | +| b | `integer` | +| delta | `number` | + +### Returns +- `integer` + +### C Prototype +`s32 delta_interpolate_s32(s32 a, s32 b, f32 delta);` + +[:arrow_up_small:](#) + +
+ +## [delta_interpolate_vec3f](#delta_interpolate_vec3f) + +### Description +Linearly interpolates `res` between `a` and `b` with `delta` + +### Lua Example +`delta_interpolate_vec3f(res, a, b, delta)` + +### Parameters +| Field | Type | +| ----- | ---- | +| res | [Vec3f](structs.md#Vec3f) | +| a | [Vec3f](structs.md#Vec3f) | +| b | [Vec3f](structs.md#Vec3f) | +| delta | `number` | + +### Returns +- None + +### C Prototype +`void delta_interpolate_vec3f(Vec3f res, Vec3f a, Vec3f b, f32 delta);` + +[:arrow_up_small:](#) + +
+ +## [delta_interpolate_vec3s](#delta_interpolate_vec3s) + +### Description +Linearly interpolates `res` between `a` and `b` with `delta` + +### Lua Example +`delta_interpolate_vec3s(res, a, b, delta)` + +### Parameters +| Field | Type | +| ----- | ---- | +| res | [Vec3s](structs.md#Vec3s) | +| a | [Vec3s](structs.md#Vec3s) | +| b | [Vec3s](structs.md#Vec3s) | +| delta | `number` | + +### Returns +- None + +### C Prototype +`void delta_interpolate_vec3s(Vec3s res, Vec3s a, Vec3s b, f32 delta);` + +[:arrow_up_small:](#) + +
+ --- # functions from mod_storage.h @@ -406,7 +647,7 @@ Sets the `part in `np`'s override color palette` | ----- | ---- | | np | [NetworkPlayer](structs.md#NetworkPlayer) | | part | [enum PlayerPart](constants.md#enum-PlayerPart) | -| color | `Color` | +| color | [Color](structs.md#Color) | ### Returns - None @@ -2659,7 +2900,7 @@ Overrides the current room Mario is in. Set to -1 to reset override ### Parameters | Field | Type | | ----- | ---- | -| a0 | `Mat4` | +| a0 | [Mat4](structs.md#Mat4) | | a1 | [Object](structs.md#Object) | ### Returns @@ -2681,8 +2922,8 @@ Overrides the current room Mario is in. Set to -1 to reset override | Field | Type | | ----- | ---- | | obj | [Object](structs.md#Object) | -| dst | `Mat4` | -| src | `Mat4` | +| dst | [Mat4](structs.md#Mat4) | +| src | [Mat4](structs.md#Mat4) | ### Returns - None @@ -2702,9 +2943,9 @@ Overrides the current room Mario is in. Set to -1 to reset override ### Parameters | Field | Type | | ----- | ---- | -| a0 | `Mat4` | -| a1 | `Mat4` | -| a2 | `Mat4` | +| a0 | [Mat4](structs.md#Mat4) | +| a1 | [Mat4](structs.md#Mat4) | +| a2 | [Mat4](structs.md#Mat4) | ### Returns - None @@ -3376,7 +3617,7 @@ Multiplies a vector by a matrix of the form: `| ? ? ? 0 |` `| ? ? ? 0 |` `| ? ? ### Parameters | Field | Type | | ----- | ---- | -| m | `Mat4` | +| m | [Mat4](structs.md#Mat4) | | dst | [Vec3f](structs.md#Vec3f) | | v | [Vec3f](structs.md#Vec3f) | @@ -3401,7 +3642,7 @@ Multiplies a vector by the transpose of a matrix of the form: `| ? ? ? 0 |` `| ? ### Parameters | Field | Type | | ----- | ---- | -| m | `Mat4` | +| m | [Mat4](structs.md#Mat4) | | dst | [Vec3f](structs.md#Vec3f) | | v | [Vec3f](structs.md#Vec3f) | @@ -7861,298 +8102,6 @@ Returns the current sound mode (e.g., stereo, mono) stored in the save file. Use [:arrow_up_small:](#) -
- ---- -# functions from seqplayer.h - -
- - -## [sequence_player_get_tempo](#sequence_player_get_tempo) - -### Description -Gets the tempo of `player` - -### Lua Example -`local integerValue = sequence_player_get_tempo(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `integer` - -### C Prototype -`u16 sequence_player_get_tempo(u8 player);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_set_tempo](#sequence_player_set_tempo) - -### Description -Sets the `tempo` of `player`. Resets when another sequence is played - -### Lua Example -`sequence_player_set_tempo(player, tempo)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | -| tempo | `integer` | - -### Returns -- None - -### C Prototype -`void sequence_player_set_tempo(u8 player, u16 tempo);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_get_tempo_acc](#sequence_player_get_tempo_acc) - -### Description -Gets the tempoAcc (tempo accumulation) of `player` - -### Lua Example -`local integerValue = sequence_player_get_tempo_acc(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `integer` - -### C Prototype -`u16 sequence_player_get_tempo_acc(u8 player);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_set_tempo_acc](#sequence_player_set_tempo_acc) - -### Description -Sets the `tempoAcc` (tempo accumulation) of `player`. Resets when another sequence is played - -### Lua Example -`sequence_player_set_tempo_acc(player, tempoAcc)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | -| tempoAcc | `integer` | - -### Returns -- None - -### C Prototype -`void sequence_player_set_tempo_acc(u8 player, u16 tempoAcc);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_get_transposition](#sequence_player_get_transposition) - -### Description -Gets the transposition (pitch) of `player` - -### Lua Example -`local integerValue = sequence_player_get_transposition(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `integer` - -### C Prototype -`u16 sequence_player_get_transposition(u8 player);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_set_transposition](#sequence_player_set_transposition) - -### Description -Sets the `transposition` (pitch) of `player`. Resets when another sequence is played - -### Lua Example -`sequence_player_set_transposition(player, transposition)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | -| transposition | `integer` | - -### Returns -- None - -### C Prototype -`void sequence_player_set_transposition(u8 player, u16 transposition);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_get_volume](#sequence_player_get_volume) - -### Description -Gets the volume of `player` - -### Lua Example -`local numberValue = sequence_player_get_volume(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `number` - -### C Prototype -`f32 sequence_player_get_volume(u8 player);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_get_fade_volume](#sequence_player_get_fade_volume) - -### Description -Gets the fade volume of `player` - -### Lua Example -`local numberValue = sequence_player_get_fade_volume(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `number` - -### C Prototype -`f32 sequence_player_get_fade_volume(u8 player);` - -[:arrow_up_small:](#) - -
- -## [sequence_player_get_mute_volume_scale](#sequence_player_get_mute_volume_scale) - -### Description -Gets the mute volume scale of `player` - -### Lua Example -`local numberValue = sequence_player_get_mute_volume_scale(player)` - -### Parameters -| Field | Type | -| ----- | ---- | -| player | `integer` | - -### Returns -- `number` - -### C Prototype -`f32 sequence_player_get_mute_volume_scale(u8 player);` - -[:arrow_up_small:](#) - -
- ---- -# functions from smlua_anim_utils.h - -
- - -## [get_mario_vanilla_animation](#get_mario_vanilla_animation) - -### Description -Gets a vanilla mario Animation with `index` - -### Lua Example -`local AnimationValue = get_mario_vanilla_animation(index)` - -### Parameters -| Field | Type | -| ----- | ---- | -| index | `integer` | - -### Returns -[Animation](structs.md#Animation) - -### C Prototype -`struct Animation *get_mario_vanilla_animation(u16 index);` - -[:arrow_up_small:](#) - -
- -## [smlua_anim_util_set_animation](#smlua_anim_util_set_animation) - -### Description -Sets the animation of `obj` to the animation `name` corresponds to - -### Lua Example -`smlua_anim_util_set_animation(obj, name)` - -### Parameters -| Field | Type | -| ----- | ---- | -| obj | [Object](structs.md#Object) | -| name | `string` | - -### Returns -- None - -### C Prototype -`void smlua_anim_util_set_animation(struct Object *obj, const char *name);` - -[:arrow_up_small:](#) - -
- -## [smlua_anim_util_get_current_animation_name](#smlua_anim_util_get_current_animation_name) - -### Description -Gets the name of the current animation playing on `obj`, returns `nil` if there's no name - -### Lua Example -`local stringValue = smlua_anim_util_get_current_animation_name(obj)` - -### Parameters -| Field | Type | -| ----- | ---- | -| obj | [Object](structs.md#Object) | - -### Returns -- `string` - -### C Prototype -`const char *smlua_anim_util_get_current_animation_name(struct Object *obj);` - -[:arrow_up_small:](#) -
--- diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md index 75016525c..c065ffed0 100644 --- a/docs/lua/functions-6.md +++ b/docs/lua/functions-6.md @@ -5,6 +5,298 @@ [< prev](functions-5.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | 6] +--- +# functions from seqplayer.h + +
+ + +## [sequence_player_get_tempo](#sequence_player_get_tempo) + +### Description +Gets the tempo of `player` + +### Lua Example +`local integerValue = sequence_player_get_tempo(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `integer` + +### C Prototype +`u16 sequence_player_get_tempo(u8 player);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_set_tempo](#sequence_player_set_tempo) + +### Description +Sets the `tempo` of `player`. Resets when another sequence is played + +### Lua Example +`sequence_player_set_tempo(player, tempo)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | +| tempo | `integer` | + +### Returns +- None + +### C Prototype +`void sequence_player_set_tempo(u8 player, u16 tempo);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_get_tempo_acc](#sequence_player_get_tempo_acc) + +### Description +Gets the tempoAcc (tempo accumulation) of `player` + +### Lua Example +`local integerValue = sequence_player_get_tempo_acc(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `integer` + +### C Prototype +`u16 sequence_player_get_tempo_acc(u8 player);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_set_tempo_acc](#sequence_player_set_tempo_acc) + +### Description +Sets the `tempoAcc` (tempo accumulation) of `player`. Resets when another sequence is played + +### Lua Example +`sequence_player_set_tempo_acc(player, tempoAcc)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | +| tempoAcc | `integer` | + +### Returns +- None + +### C Prototype +`void sequence_player_set_tempo_acc(u8 player, u16 tempoAcc);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_get_transposition](#sequence_player_get_transposition) + +### Description +Gets the transposition (pitch) of `player` + +### Lua Example +`local integerValue = sequence_player_get_transposition(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `integer` + +### C Prototype +`u16 sequence_player_get_transposition(u8 player);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_set_transposition](#sequence_player_set_transposition) + +### Description +Sets the `transposition` (pitch) of `player`. Resets when another sequence is played + +### Lua Example +`sequence_player_set_transposition(player, transposition)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | +| transposition | `integer` | + +### Returns +- None + +### C Prototype +`void sequence_player_set_transposition(u8 player, u16 transposition);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_get_volume](#sequence_player_get_volume) + +### Description +Gets the volume of `player` + +### Lua Example +`local numberValue = sequence_player_get_volume(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `number` + +### C Prototype +`f32 sequence_player_get_volume(u8 player);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_get_fade_volume](#sequence_player_get_fade_volume) + +### Description +Gets the fade volume of `player` + +### Lua Example +`local numberValue = sequence_player_get_fade_volume(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `number` + +### C Prototype +`f32 sequence_player_get_fade_volume(u8 player);` + +[:arrow_up_small:](#) + +
+ +## [sequence_player_get_mute_volume_scale](#sequence_player_get_mute_volume_scale) + +### Description +Gets the mute volume scale of `player` + +### Lua Example +`local numberValue = sequence_player_get_mute_volume_scale(player)` + +### Parameters +| Field | Type | +| ----- | ---- | +| player | `integer` | + +### Returns +- `number` + +### C Prototype +`f32 sequence_player_get_mute_volume_scale(u8 player);` + +[:arrow_up_small:](#) + +
+ +--- +# functions from smlua_anim_utils.h + +
+ + +## [get_mario_vanilla_animation](#get_mario_vanilla_animation) + +### Description +Gets a vanilla mario Animation with `index` + +### Lua Example +`local AnimationValue = get_mario_vanilla_animation(index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | + +### Returns +[Animation](structs.md#Animation) + +### C Prototype +`struct Animation *get_mario_vanilla_animation(u16 index);` + +[:arrow_up_small:](#) + +
+ +## [smlua_anim_util_set_animation](#smlua_anim_util_set_animation) + +### Description +Sets the animation of `obj` to the animation `name` corresponds to + +### Lua Example +`smlua_anim_util_set_animation(obj, name)` + +### Parameters +| Field | Type | +| ----- | ---- | +| obj | [Object](structs.md#Object) | +| name | `string` | + +### Returns +- None + +### C Prototype +`void smlua_anim_util_set_animation(struct Object *obj, const char *name);` + +[:arrow_up_small:](#) + +
+ +## [smlua_anim_util_get_current_animation_name](#smlua_anim_util_get_current_animation_name) + +### Description +Gets the name of the current animation playing on `obj`, returns `nil` if there's no name + +### Lua Example +`local stringValue = smlua_anim_util_get_current_animation_name(obj)` + +### Parameters +| Field | Type | +| ----- | ---- | +| obj | [Object](structs.md#Object) | + +### Returns +- `string` + +### C Prototype +`const char *smlua_anim_util_get_current_animation_name(struct Object *obj);` + +[:arrow_up_small:](#) + +
+ --- # functions from smlua_audio_utils.h diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 1f4f1fbd7..d08ed79d7 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1245,6 +1245,8 @@ - [vec3f_sub](functions-4.md#vec3f_sub) - [vec3f_dif](functions-4.md#vec3f_dif) - [vec3f_mul](functions-4.md#vec3f_mul) + - [vec3f_mult](functions-4.md#vec3f_mult) + - [vec3f_prod](functions-4.md#vec3f_prod) - [vec3f_div](functions-4.md#vec3f_div) - [vec3f_length](functions-4.md#vec3f_length) - [vec3f_normalize](functions-4.md#vec3f_normalize) @@ -1269,6 +1271,8 @@ - [vec3i_sub](functions-4.md#vec3i_sub) - [vec3i_dif](functions-4.md#vec3i_dif) - [vec3i_mul](functions-4.md#vec3i_mul) + - [vec3i_mult](functions-4.md#vec3i_mult) + - [vec3i_prod](functions-4.md#vec3i_prod) - [vec3i_div](functions-4.md#vec3i_div) - [vec3i_length](functions-4.md#vec3i_length) - [vec3i_normalize](functions-4.md#vec3i_normalize) @@ -1293,6 +1297,8 @@ - [vec3s_sub](functions-4.md#vec3s_sub) - [vec3s_dif](functions-4.md#vec3s_dif) - [vec3s_mul](functions-4.md#vec3s_mul) + - [vec3s_mult](functions-4.md#vec3s_mult) + - [vec3s_prod](functions-4.md#vec3s_prod) - [vec3s_div](functions-4.md#vec3s_div) - [vec3s_length](functions-4.md#vec3s_length) - [vec3s_normalize](functions-4.md#vec3s_normalize) @@ -1309,16 +1315,16 @@
- misc.h - - [smooth_step](functions-4.md#smooth_step) - - [update_all_mario_stars](functions-4.md#update_all_mario_stars) - - [clock_elapsed](functions-4.md#clock_elapsed) - - [clock_elapsed_f64](functions-4.md#clock_elapsed_f64) - - [clock_elapsed_ticks](functions-4.md#clock_elapsed_ticks) - - [clock_is_date](functions-4.md#clock_is_date) - - [delta_interpolate_f32](functions-4.md#delta_interpolate_f32) - - [delta_interpolate_s32](functions-4.md#delta_interpolate_s32) - - [delta_interpolate_vec3f](functions-4.md#delta_interpolate_vec3f) - - [delta_interpolate_vec3s](functions-4.md#delta_interpolate_vec3s) + - [smooth_step](functions-5.md#smooth_step) + - [update_all_mario_stars](functions-5.md#update_all_mario_stars) + - [clock_elapsed](functions-5.md#clock_elapsed) + - [clock_elapsed_f64](functions-5.md#clock_elapsed_f64) + - [clock_elapsed_ticks](functions-5.md#clock_elapsed_ticks) + - [clock_is_date](functions-5.md#clock_is_date) + - [delta_interpolate_f32](functions-5.md#delta_interpolate_f32) + - [delta_interpolate_s32](functions-5.md#delta_interpolate_s32) + - [delta_interpolate_vec3f](functions-5.md#delta_interpolate_vec3f) + - [delta_interpolate_vec3s](functions-5.md#delta_interpolate_vec3s)
@@ -1726,22 +1732,22 @@
- seqplayer.h - - [sequence_player_get_tempo](functions-5.md#sequence_player_get_tempo) - - [sequence_player_set_tempo](functions-5.md#sequence_player_set_tempo) - - [sequence_player_get_tempo_acc](functions-5.md#sequence_player_get_tempo_acc) - - [sequence_player_set_tempo_acc](functions-5.md#sequence_player_set_tempo_acc) - - [sequence_player_get_transposition](functions-5.md#sequence_player_get_transposition) - - [sequence_player_set_transposition](functions-5.md#sequence_player_set_transposition) - - [sequence_player_get_volume](functions-5.md#sequence_player_get_volume) - - [sequence_player_get_fade_volume](functions-5.md#sequence_player_get_fade_volume) - - [sequence_player_get_mute_volume_scale](functions-5.md#sequence_player_get_mute_volume_scale) + - [sequence_player_get_tempo](functions-6.md#sequence_player_get_tempo) + - [sequence_player_set_tempo](functions-6.md#sequence_player_set_tempo) + - [sequence_player_get_tempo_acc](functions-6.md#sequence_player_get_tempo_acc) + - [sequence_player_set_tempo_acc](functions-6.md#sequence_player_set_tempo_acc) + - [sequence_player_get_transposition](functions-6.md#sequence_player_get_transposition) + - [sequence_player_set_transposition](functions-6.md#sequence_player_set_transposition) + - [sequence_player_get_volume](functions-6.md#sequence_player_get_volume) + - [sequence_player_get_fade_volume](functions-6.md#sequence_player_get_fade_volume) + - [sequence_player_get_mute_volume_scale](functions-6.md#sequence_player_get_mute_volume_scale)
- smlua_anim_utils.h - - [get_mario_vanilla_animation](functions-5.md#get_mario_vanilla_animation) - - [smlua_anim_util_set_animation](functions-5.md#smlua_anim_util_set_animation) - - [smlua_anim_util_get_current_animation_name](functions-5.md#smlua_anim_util_get_current_animation_name) + - [get_mario_vanilla_animation](functions-6.md#get_mario_vanilla_animation) + - [smlua_anim_util_set_animation](functions-6.md#smlua_anim_util_set_animation) + - [smlua_anim_util_get_current_animation_name](functions-6.md#smlua_anim_util_get_current_animation_name)
diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 286c7223e..867962a77 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -408,7 +408,7 @@ | filler3C | `Array` <`integer`> | | | focus | [Vec3f](structs.md#Vec3f) | read-only | | mode | `integer` | | -| mtx | `Mat4` | read-only | +| mtx | [Mat4](structs.md#Mat4) | read-only | | nextYaw | `integer` | | | paletteEditorCap | `boolean` | | | pos | [Vec3f](structs.md#Vec3f) | read-only | @@ -1384,7 +1384,7 @@ | prevScaleTimestamp | `integer` | read-only | | prevShadowPos | [Vec3f](structs.md#Vec3f) | read-only | | prevShadowPosTimestamp | `integer` | read-only | -| prevThrowMatrix | `Mat4` | read-only | +| prevThrowMatrix | [Mat4](structs.md#Mat4) | read-only | | prevThrowMatrixTimestamp | `integer` | read-only | | prevTimestamp | `integer` | read-only | | scale | [Vec3f](structs.md#Vec3f) | read-only | @@ -2043,7 +2043,7 @@ | prevObj | [Object](structs.md#Object) | | | respawnInfoType | `integer` | read-only | | setHome | `integer` | | -| transform | `Mat4` | read-only | +| transform | [Mat4](structs.md#Mat4) | read-only | | unused1 | `integer` | | | usingObj | [Object](structs.md#Object) | | diff --git a/include/types.h b/include/types.h index 52856a77f..5995ba5b9 100644 --- a/include/types.h +++ b/include/types.h @@ -50,6 +50,17 @@ typedef f32 Vec4f[4]; // X, Y, Z, W typedef s16 Vec4s[4]; typedef s32 Vec4i[4]; +// Pointer types for return values +typedef f32 *Vec2fp; +typedef s16 *Vec2sp; +typedef s32 *Vec2ip; +typedef f32 *Vec3fp; +typedef s16 *Vec3sp; +typedef s32 *Vec3ip; +typedef f32 *Vec4fp; +typedef s16 *Vec4sp; +typedef s32 *Vec4ip; + typedef f32 Mat4[4][4]; typedef uintptr_t GeoLayout; diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 741112b66..7fe0d038c 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -245,7 +245,7 @@ Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f }; * Returns a vector rotated around the z axis, then the x axis, then the y * axis. */ -OPTIMIZE_O3 f32 *vec3f_rotate_zxy(Vec3f dest, Vec3s rotate) { +OPTIMIZE_O3 Vec3fp vec3f_rotate_zxy(Vec3f dest, Vec3s rotate) { Vec3f v = { dest[0], dest[1], dest[2] }; f32 sx = sins(rotate[0]); @@ -270,7 +270,7 @@ OPTIMIZE_O3 f32 *vec3f_rotate_zxy(Vec3f dest, Vec3s rotate) { // Rodrigues' formula // dest = v * cos(r) + (n x v) * sin(r) + n * (n . v) * (1 - cos(r)) -OPTIMIZE_O3 f32 *vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r) { +OPTIMIZE_O3 Vec3fp vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r) { Vec3f nvCross; vec3f_cross(nvCross, n, v); f32 nvDot = vec3f_dot(n, v); @@ -282,7 +282,7 @@ OPTIMIZE_O3 f32 *vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r) { return dest; } -OPTIMIZE_O3 f32 *vec3f_project(Vec3f dest, Vec3f v, Vec3f onto) { +OPTIMIZE_O3 Vec3fp vec3f_project(Vec3f dest, Vec3f v, Vec3f onto) { f32 numerator = vec3f_dot(v, onto); f32 denominator = vec3f_dot(onto, onto); if (denominator == 0) { @@ -294,7 +294,7 @@ OPTIMIZE_O3 f32 *vec3f_project(Vec3f dest, Vec3f v, Vec3f onto) { return dest; } -OPTIMIZE_O3 f32 *vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale) { +OPTIMIZE_O3 Vec3fp vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale) { vec3f_copy(dest, v); // scale @@ -341,7 +341,7 @@ OPTIMIZE_O3 void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pi * It is similar to vec3f_cross, but it calculates the vectors (c-b) and (b-a) * at the same time. */ -OPTIMIZE_O3 f32 *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c) { +OPTIMIZE_O3 Vec3fp find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c) { dest[0] = (b[1] - a[1]) * (c[2] - b[2]) - (c[1] - b[1]) * (b[2] - a[2]); dest[1] = (b[2] - a[2]) * (c[0] - b[0]) - (c[2] - b[2]) * (b[0] - a[0]); dest[2] = (b[0] - a[0]) * (c[1] - b[1]) - (c[0] - b[0]) * (b[1] - a[1]); @@ -789,7 +789,7 @@ OPTIMIZE_O3 void mtxf_inverse(Mat4 dest, Mat4 src) { * objMtx back from screen orientation to world orientation, and then subtracting * the camera position. */ -OPTIMIZE_O3 f32 *get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) { +OPTIMIZE_O3 Vec3fp get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) { f32 camX = camMtx[3][0] * camMtx[0][0] + camMtx[3][1] * camMtx[0][1] + camMtx[3][2] * camMtx[0][2]; f32 camY = camMtx[3][0] * camMtx[1][0] + camMtx[3][1] * camMtx[1][1] + camMtx[3][2] * camMtx[1][2]; f32 camZ = camMtx[3][0] * camMtx[2][0] + camMtx[3][1] * camMtx[2][1] + camMtx[3][2] * camMtx[2][2]; diff --git a/src/engine/math_util.h b/src/engine/math_util.h index 070c440be..0289367d6 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -152,22 +152,22 @@ OPTIMIZE_O3 s32 anim_spline_poll(struct MarioState* m, Vec3f result); /* |description| Rotates the 3D floating-point vector `v` by the angles specified in the 3D signed-integer vector `rotate`, applying the rotations in the order Z, then X, then Y. The rotated vector replaces `v` |descriptionEnd| */ -OPTIMIZE_O3 f32 *vec3f_rotate_zxy(Vec3f v, Vec3s rotate); +OPTIMIZE_O3 Vec3fp vec3f_rotate_zxy(Vec3f v, Vec3s rotate); /* |description| Rotates the 3D floating-point vector `v` around the vector `n`, given a rotation `r` (in sm64 angle units), and stores the result in `dest` |descriptionEnd| */ -OPTIMIZE_O3 f32 *vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r); +OPTIMIZE_O3 Vec3fp vec3f_rotate_around_n(Vec3f dest, Vec3f v, Vec3f n, s16 r); /* |description| Projects the 3D floating-point vector `v` onto another 3D floating-point vector `onto`. The resulting projection, stored in `dest`, represents how much of `v` lies along the direction of `onto` |descriptionEnd| */ -OPTIMIZE_O3 f32 *vec3f_project(Vec3f dest, Vec3f v, Vec3f onto); +OPTIMIZE_O3 Vec3fp vec3f_project(Vec3f dest, Vec3f v, Vec3f onto); /* |description| Scales the 3D floating-point vector `v` by the vector `scale`, then rotates it by the rotation vector `rotation`, and finally translates it by the vector `translation`. The resulting vector is stored in `dest` |descriptionEnd| */ -OPTIMIZE_O3 f32 *vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale); +OPTIMIZE_O3 Vec3fp vec3f_transform(Vec3f dest, Vec3f v, Vec3f translation, Vec3s rotation, Vec3f scale); /* |description| Calculates the distance between two points in 3D space (`from` and `to`), as well as the pitch and yaw angles that describe the direction from `from` to `to`. The results are stored in `dist`, `pitch`, and `yaw` @@ -182,7 +182,7 @@ OPTIMIZE_O3 void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pi /* |description| Determines a vector that is perpendicular (normal) to the plane defined by three given 3D floating-point points `a`, `b`, and `c`. The resulting perpendicular vector is stored in `dest` |descriptionEnd| */ -OPTIMIZE_O3 f32 *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c); +OPTIMIZE_O3 Vec3fp find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c); /////////// // Vec3i // @@ -243,7 +243,7 @@ Multiplies two 4x4 floating-point matrices `a` and `b` (in that order), storing OPTIMIZE_O3 void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b); /* |description| -Multiplies the 4x4 floating-point matrix `mtx` by a 3D signed-integer vector `b`, potentially interpreting `b` as angles or translations depending on usage, and modifies `mtx` accordingly +Multiplies the 3D signed-integer vector `b` with the 4x4 floating-point matrix `mtx`, which applies the transformation to the point |descriptionEnd| */ OPTIMIZE_O3 s16 *mtxf_mul_vec3s(Mat4 mtx, Vec3s b); @@ -260,7 +260,7 @@ OPTIMIZE_O3 void mtxf_inverse(Mat4 dest, Mat4 src); /* |description| Extracts the position (translation component) from the transformation matrix `objMtx` relative to the coordinate system defined by `camMtx` and stores that 3D position in `dest`. This can be used to get the object's coordinates in camera space |descriptionEnd| */ -OPTIMIZE_O3 f32 *get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx); +OPTIMIZE_O3 Vec3fp get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx); #endif // MATH_UTIL_H diff --git a/src/engine/math_util_vec3.tmpl b/src/engine/math_util_vec3.tmpl index d2d107398..083a8ae6a 100644 --- a/src/engine/math_util_vec3.tmpl +++ b/src/engine/math_util_vec3.tmpl @@ -3,7 +3,7 @@ /* |description| Sets the components of the 3D {{desc}} vector `v` to 0 |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_zero(Vec3{{suffix}} v) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_zero(Vec3{{suffix}} v) { memset(v, 0, sizeof(Vec3{{suffix}})); return v; } @@ -11,7 +11,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_zero(Vec3{{suffix}} v) { /* |description| Copies the contents of a 3D {{desc}} vector (`src`) into another 3D {{desc}} vector (`dest`) |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_copy(Vec3{{suffix}} dest, Vec3{{suffix}} src) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_copy(Vec3{{suffix}} dest, Vec3{{suffix}} src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; @@ -21,7 +21,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_copy(Vec3{{suffix}} dest, Vec3{{suff /* |description| Sets the values of the 3D {{desc}} vector `dest` to the given x, y, and z values |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_set(Vec3{{suffix}} dest, {{type}} x, {{type}} y, {{type}} z) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_set(Vec3{{suffix}} dest, {{type}} x, {{type}} y, {{type}} z) { dest[0] = x; dest[1] = y; dest[2] = z; @@ -31,7 +31,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_set(Vec3{{suffix}} dest, {{type}} x, /* |description| Adds the components of the 3D {{desc}} vector `a` to `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_add(Vec3{{suffix}} dest, Vec3{{suffix}} a) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_add(Vec3{{suffix}} dest, Vec3{{suffix}} a) { dest[0] += a[0]; dest[1] += a[1]; dest[2] += a[2]; @@ -41,7 +41,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_add(Vec3{{suffix}} dest, Vec3{{suffi /* |description| Adds the components of two 3D {{desc}} vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_sum(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_sum(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -51,7 +51,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_sum(Vec3{{suffix}} dest, Vec3{{suffi /* |description| Subtracts the components of the 3D {{desc}} vector `a` from `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_sub(Vec3{{suffix}} dest, Vec3{{suffix}} a) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_sub(Vec3{{suffix}} dest, Vec3{{suffix}} a) { dest[0] -= a[0]; dest[1] -= a[1]; dest[2] -= a[2]; @@ -61,7 +61,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_sub(Vec3{{suffix}} dest, Vec3{{suffi /* |description| Subtracts the components of the 3D {{desc}} vector `b` from the components of `a` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_dif(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_dif(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -71,17 +71,37 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_dif(Vec3{{suffix}} dest, Vec3{{suffi /* |description| Multiplies each component of the 3D {{desc}} vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_mul(Vec3{{suffix}} dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_mul(Vec3{{suffix}} dest, f32 a) { dest[0] *= a; dest[1] *= a; dest[2] *= a; return dest; } +/* |description| +Multiplies the components of the 3D {{desc}} vector `dest` with the components of `a` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_mult(Vec3{{suffix}} dest, Vec3{{suffix}} a) { + dest[0] *= a[0]; + dest[1] *= a[1]; + dest[2] *= a[2]; + return dest; +} + +/* |description| +Multiplies the components of two 3D {{desc}} vectors `a` and `b` and stores the result in `dest` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_prod(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + return dest; +} + /* |description| Divides each component of the 3D {{desc}} vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_div(Vec3{{suffix}} dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_div(Vec3{{suffix}} dest, f32 a) { if (a == 0) { return dest; } dest[0] /= a; dest[1] /= a; @@ -99,7 +119,7 @@ INLINE OPTIMIZE_O3 f32 vec3{{suffix}}_length(Vec3{{suffix}} a) { /* |description| Normalizes the 3D {{desc}} vector `v` so that its length (magnitude) becomes 1, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_normalize(Vec3{{suffix}} v) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_normalize(Vec3{{suffix}} v) { f32 mag = vec3{{suffix}}_length(v); vec3{{suffix}}_div(v, mag); return v; @@ -108,7 +128,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_normalize(Vec3{{suffix}} v) { /* |description| Sets the length (magnitude) of 3D {{desc}} vector `v`, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_set_magnitude(Vec3{{suffix}} v, f32 mag) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_set_magnitude(Vec3{{suffix}} v, f32 mag) { vec3{{suffix}}_normalize(v); vec3{{suffix}}_mul(v, mag); return v; @@ -124,7 +144,7 @@ INLINE OPTIMIZE_O3 f32 vec3{{suffix}}_dot(Vec3{{suffix}} a, Vec3{{suffix}} b) { /* |description| Computes the cross product of two 3D {{desc}} vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_cross(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_cross(Vec3{{suffix}} dest, Vec3{{suffix}} a, Vec3{{suffix}} b) { dest[0] = a[1] * b[2] - b[1] * a[2]; dest[1] = a[2] * b[0] - b[2] * a[0]; dest[2] = a[0] * b[1] - b[0] * a[1]; @@ -134,7 +154,7 @@ INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_cross(Vec3{{suffix}} dest, Vec3{{suf /* |description| Takes two 3D {{desc}} vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 {{type}} *vec3{{suffix}}_combine(Vec3{{suffix}} dest, Vec3{{suffix}} vecA, Vec3{{suffix}} vecB, f32 sclA, f32 sclB) { +INLINE OPTIMIZE_O3 Vec3{{suffix}}p vec3{{suffix}}_combine(Vec3{{suffix}} dest, Vec3{{suffix}} vecA, Vec3{{suffix}} vecB, f32 sclA, f32 sclB) { dest[0] = vecA[0] * sclA + vecB[0] * sclB; dest[1] = vecA[1] * sclA + vecB[1] * sclB; dest[2] = vecA[2] * sclA + vecB[2] * sclB; diff --git a/src/engine/math_util_vec3f.inl b/src/engine/math_util_vec3f.inl index 4531a8713..d6b4bacf6 100644 --- a/src/engine/math_util_vec3f.inl +++ b/src/engine/math_util_vec3f.inl @@ -6,7 +6,7 @@ /* |description| Sets the components of the 3D floating-point vector `v` to 0 |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_zero(Vec3f v) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_zero(Vec3f v) { memset(v, 0, sizeof(Vec3f)); return v; } @@ -14,7 +14,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_zero(Vec3f v) { /* |description| Copies the contents of a 3D floating-point vector (`src`) into another 3D floating-point vector (`dest`) |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_copy(Vec3f dest, Vec3f src) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_copy(Vec3f dest, Vec3f src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; @@ -24,7 +24,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_copy(Vec3f dest, Vec3f src) { /* |description| Sets the values of the 3D floating-point vector `dest` to the given x, y, and z values |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) { dest[0] = x; dest[1] = y; dest[2] = z; @@ -34,7 +34,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) { /* |description| Adds the components of the 3D floating-point vector `a` to `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_add(Vec3f dest, Vec3f a) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_add(Vec3f dest, Vec3f a) { dest[0] += a[0]; dest[1] += a[1]; dest[2] += a[2]; @@ -44,7 +44,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_add(Vec3f dest, Vec3f a) { /* |description| Adds the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -54,7 +54,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) { /* |description| Subtracts the components of the 3D floating-point vector `a` from `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_sub(Vec3f dest, Vec3f a) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_sub(Vec3f dest, Vec3f a) { dest[0] -= a[0]; dest[1] -= a[1]; dest[2] -= a[2]; @@ -64,7 +64,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_sub(Vec3f dest, Vec3f a) { /* |description| Subtracts the components of the 3D floating-point vector `b` from the components of `a` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_dif(Vec3f dest, Vec3f a, Vec3f b) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_dif(Vec3f dest, Vec3f a, Vec3f b) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -74,17 +74,37 @@ INLINE OPTIMIZE_O3 f32 *vec3f_dif(Vec3f dest, Vec3f a, Vec3f b) { /* |description| Multiplies each component of the 3D floating-point vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_mul(Vec3f dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_mul(Vec3f dest, f32 a) { dest[0] *= a; dest[1] *= a; dest[2] *= a; return dest; } +/* |description| +Multiplies the components of the 3D floating-point vector `dest` with the components of `a` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3fp vec3f_mult(Vec3f dest, Vec3f a) { + dest[0] *= a[0]; + dest[1] *= a[1]; + dest[2] *= a[2]; + return dest; +} + +/* |description| +Multiplies the components of two 3D floating-point vectors `a` and `b` and stores the result in `dest` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3fp vec3f_prod(Vec3f dest, Vec3f a, Vec3f b) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + return dest; +} + /* |description| Divides each component of the 3D floating-point vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_div(Vec3f dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_div(Vec3f dest, f32 a) { if (a == 0) { return dest; } dest[0] /= a; dest[1] /= a; @@ -102,7 +122,7 @@ INLINE OPTIMIZE_O3 f32 vec3f_length(Vec3f a) { /* |description| Normalizes the 3D floating-point vector `v` so that its length (magnitude) becomes 1, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_normalize(Vec3f v) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_normalize(Vec3f v) { f32 mag = vec3f_length(v); vec3f_div(v, mag); return v; @@ -111,7 +131,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_normalize(Vec3f v) { /* |description| Sets the length (magnitude) of 3D floating-point vector `v`, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_set_magnitude(Vec3f v, f32 mag) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_set_magnitude(Vec3f v, f32 mag) { vec3f_normalize(v); vec3f_mul(v, mag); return v; @@ -127,7 +147,7 @@ INLINE OPTIMIZE_O3 f32 vec3f_dot(Vec3f a, Vec3f b) { /* |description| Computes the cross product of two 3D floating-point vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) { dest[0] = a[1] * b[2] - b[1] * a[2]; dest[1] = a[2] * b[0] - b[2] * a[0]; dest[2] = a[0] * b[1] - b[0] * a[1]; @@ -137,7 +157,7 @@ INLINE OPTIMIZE_O3 f32 *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) { /* |description| Takes two 3D floating-point vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3f_combine(Vec3f dest, Vec3f vecA, Vec3f vecB, f32 sclA, f32 sclB) { +INLINE OPTIMIZE_O3 Vec3fp vec3f_combine(Vec3f dest, Vec3f vecA, Vec3f vecB, f32 sclA, f32 sclB) { dest[0] = vecA[0] * sclA + vecB[0] * sclB; dest[1] = vecA[1] * sclA + vecB[1] * sclB; dest[2] = vecA[2] * sclA + vecB[2] * sclB; @@ -171,7 +191,7 @@ INLINE OPTIMIZE_O3 bool vec3f_is_zero(Vec3f v) { /* |description| Converts a 3D floating-point vector `a` into a 3D integer vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3f_to_vec3i(Vec3i dest, Vec3f a) { +INLINE OPTIMIZE_O3 Vec3ip vec3f_to_vec3i(Vec3i dest, Vec3f a) { dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f); dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f); dest[2] = a[2] + ((a[2] > 0) ? 0.5f : -0.5f); @@ -181,7 +201,7 @@ INLINE OPTIMIZE_O3 s32 *vec3f_to_vec3i(Vec3i dest, Vec3f a) { /* |description| Converts a 3D floating-point vector `a` into a 3D short integer vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3f_to_vec3s(Vec3s dest, Vec3f a) { +INLINE OPTIMIZE_O3 Vec3sp vec3f_to_vec3s(Vec3s dest, Vec3f a) { dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f); dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f); dest[2] = a[2] + ((a[2] > 0) ? 0.5f : -0.5f); diff --git a/src/engine/math_util_vec3i.inl b/src/engine/math_util_vec3i.inl index 4c3f1d61f..607f7137c 100644 --- a/src/engine/math_util_vec3i.inl +++ b/src/engine/math_util_vec3i.inl @@ -6,7 +6,7 @@ /* |description| Sets the components of the 3D integer vector `v` to 0 |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_zero(Vec3i v) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_zero(Vec3i v) { memset(v, 0, sizeof(Vec3i)); return v; } @@ -14,7 +14,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_zero(Vec3i v) { /* |description| Copies the contents of a 3D integer vector (`src`) into another 3D integer vector (`dest`) |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_copy(Vec3i dest, Vec3i src) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_copy(Vec3i dest, Vec3i src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; @@ -24,7 +24,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_copy(Vec3i dest, Vec3i src) { /* |description| Sets the values of the 3D integer vector `dest` to the given x, y, and z values |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_set(Vec3i dest, s32 x, s32 y, s32 z) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_set(Vec3i dest, s32 x, s32 y, s32 z) { dest[0] = x; dest[1] = y; dest[2] = z; @@ -34,7 +34,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_set(Vec3i dest, s32 x, s32 y, s32 z) { /* |description| Adds the components of the 3D integer vector `a` to `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_add(Vec3i dest, Vec3i a) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_add(Vec3i dest, Vec3i a) { dest[0] += a[0]; dest[1] += a[1]; dest[2] += a[2]; @@ -44,7 +44,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_add(Vec3i dest, Vec3i a) { /* |description| Adds the components of two 3D integer vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_sum(Vec3i dest, Vec3i a, Vec3i b) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_sum(Vec3i dest, Vec3i a, Vec3i b) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -54,7 +54,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_sum(Vec3i dest, Vec3i a, Vec3i b) { /* |description| Subtracts the components of the 3D integer vector `a` from `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_sub(Vec3i dest, Vec3i a) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_sub(Vec3i dest, Vec3i a) { dest[0] -= a[0]; dest[1] -= a[1]; dest[2] -= a[2]; @@ -64,7 +64,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_sub(Vec3i dest, Vec3i a) { /* |description| Subtracts the components of the 3D integer vector `b` from the components of `a` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_dif(Vec3i dest, Vec3i a, Vec3i b) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_dif(Vec3i dest, Vec3i a, Vec3i b) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -74,17 +74,37 @@ INLINE OPTIMIZE_O3 s32 *vec3i_dif(Vec3i dest, Vec3i a, Vec3i b) { /* |description| Multiplies each component of the 3D integer vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_mul(Vec3i dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_mul(Vec3i dest, f32 a) { dest[0] *= a; dest[1] *= a; dest[2] *= a; return dest; } +/* |description| +Multiplies the components of the 3D integer vector `dest` with the components of `a` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3ip vec3i_mult(Vec3i dest, Vec3i a) { + dest[0] *= a[0]; + dest[1] *= a[1]; + dest[2] *= a[2]; + return dest; +} + +/* |description| +Multiplies the components of two 3D integer vectors `a` and `b` and stores the result in `dest` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3ip vec3i_prod(Vec3i dest, Vec3i a, Vec3i b) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + return dest; +} + /* |description| Divides each component of the 3D integer vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_div(Vec3i dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_div(Vec3i dest, f32 a) { if (a == 0) { return dest; } dest[0] /= a; dest[1] /= a; @@ -102,7 +122,7 @@ INLINE OPTIMIZE_O3 f32 vec3i_length(Vec3i a) { /* |description| Normalizes the 3D integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_normalize(Vec3i v) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_normalize(Vec3i v) { f32 mag = vec3i_length(v); vec3i_div(v, mag); return v; @@ -111,7 +131,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_normalize(Vec3i v) { /* |description| Sets the length (magnitude) of 3D integer vector `v`, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_set_magnitude(Vec3i v, f32 mag) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_set_magnitude(Vec3i v, f32 mag) { vec3i_normalize(v); vec3i_mul(v, mag); return v; @@ -127,7 +147,7 @@ INLINE OPTIMIZE_O3 f32 vec3i_dot(Vec3i a, Vec3i b) { /* |description| Computes the cross product of two 3D integer vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_cross(Vec3i dest, Vec3i a, Vec3i b) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_cross(Vec3i dest, Vec3i a, Vec3i b) { dest[0] = a[1] * b[2] - b[1] * a[2]; dest[1] = a[2] * b[0] - b[2] * a[0]; dest[2] = a[0] * b[1] - b[0] * a[1]; @@ -137,7 +157,7 @@ INLINE OPTIMIZE_O3 s32 *vec3i_cross(Vec3i dest, Vec3i a, Vec3i b) { /* |description| Takes two 3D integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3i_combine(Vec3i dest, Vec3i vecA, Vec3i vecB, f32 sclA, f32 sclB) { +INLINE OPTIMIZE_O3 Vec3ip vec3i_combine(Vec3i dest, Vec3i vecA, Vec3i vecB, f32 sclA, f32 sclB) { dest[0] = vecA[0] * sclA + vecB[0] * sclB; dest[1] = vecA[1] * sclA + vecB[1] * sclB; dest[2] = vecA[2] * sclA + vecB[2] * sclB; @@ -171,7 +191,7 @@ INLINE OPTIMIZE_O3 bool vec3i_is_zero(Vec3i v) { /* |description| Converts a 3D integer vector `a` into a 3D floating-point vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3i_to_vec3f(Vec3f dest, Vec3i a) { +INLINE OPTIMIZE_O3 Vec3fp vec3i_to_vec3f(Vec3f dest, Vec3i a) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -181,7 +201,7 @@ INLINE OPTIMIZE_O3 f32 *vec3i_to_vec3f(Vec3f dest, Vec3i a) { /* |description| Converts a 3D integer vector `a` into a 3D short integer vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3i_to_vec3s(Vec3s dest, Vec3i a) { +INLINE OPTIMIZE_O3 Vec3sp vec3i_to_vec3s(Vec3s dest, Vec3i a) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; diff --git a/src/engine/math_util_vec3s.inl b/src/engine/math_util_vec3s.inl index 00045b9f0..28406a7ae 100644 --- a/src/engine/math_util_vec3s.inl +++ b/src/engine/math_util_vec3s.inl @@ -6,7 +6,7 @@ /* |description| Sets the components of the 3D short integer vector `v` to 0 |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_zero(Vec3s v) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_zero(Vec3s v) { memset(v, 0, sizeof(Vec3s)); return v; } @@ -14,7 +14,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_zero(Vec3s v) { /* |description| Copies the contents of a 3D short integer vector (`src`) into another 3D short integer vector (`dest`) |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_copy(Vec3s dest, Vec3s src) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_copy(Vec3s dest, Vec3s src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; @@ -24,7 +24,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_copy(Vec3s dest, Vec3s src) { /* |description| Sets the values of the 3D short integer vector `dest` to the given x, y, and z values |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) { dest[0] = x; dest[1] = y; dest[2] = z; @@ -34,7 +34,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) { /* |description| Adds the components of the 3D short integer vector `a` to `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_add(Vec3s dest, Vec3s a) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_add(Vec3s dest, Vec3s a) { dest[0] += a[0]; dest[1] += a[1]; dest[2] += a[2]; @@ -44,7 +44,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_add(Vec3s dest, Vec3s a) { /* |description| Adds the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -54,7 +54,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) { /* |description| Subtracts the components of the 3D short integer vector `a` from `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_sub(Vec3s dest, Vec3s a) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_sub(Vec3s dest, Vec3s a) { dest[0] -= a[0]; dest[1] -= a[1]; dest[2] -= a[2]; @@ -64,7 +64,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_sub(Vec3s dest, Vec3s a) { /* |description| Subtracts the components of the 3D short integer vector `b` from the components of `a` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_dif(Vec3s dest, Vec3s a, Vec3s b) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_dif(Vec3s dest, Vec3s a, Vec3s b) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -74,17 +74,37 @@ INLINE OPTIMIZE_O3 s16 *vec3s_dif(Vec3s dest, Vec3s a, Vec3s b) { /* |description| Multiplies each component of the 3D short integer vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_mul(Vec3s dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_mul(Vec3s dest, f32 a) { dest[0] *= a; dest[1] *= a; dest[2] *= a; return dest; } +/* |description| +Multiplies the components of the 3D short integer vector `dest` with the components of `a` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3sp vec3s_mult(Vec3s dest, Vec3s a) { + dest[0] *= a[0]; + dest[1] *= a[1]; + dest[2] *= a[2]; + return dest; +} + +/* |description| +Multiplies the components of two 3D short integer vectors `a` and `b` and stores the result in `dest` +|descriptionEnd| */ +INLINE OPTIMIZE_O3 Vec3sp vec3s_prod(Vec3s dest, Vec3s a, Vec3s b) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + return dest; +} + /* |description| Divides each component of the 3D short integer vector `dest` by the scalar value `a` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_div(Vec3s dest, f32 a) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_div(Vec3s dest, f32 a) { if (a == 0) { return dest; } dest[0] /= a; dest[1] /= a; @@ -102,7 +122,7 @@ INLINE OPTIMIZE_O3 f32 vec3s_length(Vec3s a) { /* |description| Normalizes the 3D short integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_normalize(Vec3s v) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_normalize(Vec3s v) { f32 mag = vec3s_length(v); vec3s_div(v, mag); return v; @@ -111,7 +131,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_normalize(Vec3s v) { /* |description| Sets the length (magnitude) of 3D short integer vector `v`, while retaining its direction |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_set_magnitude(Vec3s v, f32 mag) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_set_magnitude(Vec3s v, f32 mag) { vec3s_normalize(v); vec3s_mul(v, mag); return v; @@ -127,7 +147,7 @@ INLINE OPTIMIZE_O3 f32 vec3s_dot(Vec3s a, Vec3s b) { /* |description| Computes the cross product of two 3D short integer vectors `a` and `b` and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_cross(Vec3s dest, Vec3s a, Vec3s b) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_cross(Vec3s dest, Vec3s a, Vec3s b) { dest[0] = a[1] * b[2] - b[1] * a[2]; dest[1] = a[2] * b[0] - b[2] * a[0]; dest[2] = a[0] * b[1] - b[0] * a[1]; @@ -137,7 +157,7 @@ INLINE OPTIMIZE_O3 s16 *vec3s_cross(Vec3s dest, Vec3s a, Vec3s b) { /* |description| Takes two 3D short integer vectors `vecA` and `vecB`, multiplies them by `sclA` and `sclB` respectively, adds the scaled vectors together and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s16 *vec3s_combine(Vec3s dest, Vec3s vecA, Vec3s vecB, f32 sclA, f32 sclB) { +INLINE OPTIMIZE_O3 Vec3sp vec3s_combine(Vec3s dest, Vec3s vecA, Vec3s vecB, f32 sclA, f32 sclB) { dest[0] = vecA[0] * sclA + vecB[0] * sclB; dest[1] = vecA[1] * sclA + vecB[1] * sclB; dest[2] = vecA[2] * sclA + vecB[2] * sclB; @@ -171,7 +191,7 @@ INLINE OPTIMIZE_O3 bool vec3s_is_zero(Vec3s v) { /* |description| Converts a 3D short integer vector `a` into a 3D floating-point vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 f32 *vec3s_to_vec3f(Vec3f dest, Vec3s a) { +INLINE OPTIMIZE_O3 Vec3fp vec3s_to_vec3f(Vec3f dest, Vec3s a) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -181,7 +201,7 @@ INLINE OPTIMIZE_O3 f32 *vec3s_to_vec3f(Vec3f dest, Vec3s a) { /* |description| Converts a 3D short integer vector `a` into a 3D integer vector and stores the result in `dest` |descriptionEnd| */ -INLINE OPTIMIZE_O3 s32 *vec3s_to_vec3i(Vec3i dest, Vec3s a) { +INLINE OPTIMIZE_O3 Vec3ip vec3s_to_vec3i(Vec3i dest, Vec3s a) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index e287922f0..e9e79ddef 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -20,10 +20,41 @@ char gSmluaConstants[] = "" "end\n" "}\n" "-----------\n" +"-- table --\n" +"-----------\n" +"--- Creates a shallow copy of table `t`\n" +"--- @param t table\n" +"--- @return table\n" +"function table.copy(t)\n" +"return table_copy(t)\n" +"end\n" +"--- Creates a deep copy of table `t`\n" +"--- @param t table\n" +"--- @return table\n" +"function table.deepcopy(t)\n" +"return table_deepcopy(t)\n" +"end\n" +"--- Utility function to create a read-only table\n" +"--- @param data table\n" +"--- @return table\n" +"function create_read_only_table(data)\n" +"local t = {}\n" +"local mt = {\n" +"__index = data,\n" +"__newindex = function(_, k, _)\n" +"error('Attempting to modify key `' .. k .. '` of read-only table')\n" +"end,\n" +"__call = function() return table_copy(data) end,\n" +"__metatable = false\n" +"}\n" +"setmetatable(t, mt)\n" +"return t\n" +"end\n" +"-----------\n" "-- sound --\n" "-----------\n" "--- @type Vec3f\n" -"gGlobalSoundSource = { x = 0, y = 0, z = 0 }\n" +"gGlobalSoundSource = create_read_only_table({ x = 0, y = 0, z = 0 })\n" "--- @param bank number\n" "--- @param soundID number\n" "--- @param priority number\n" @@ -150,6 +181,44 @@ char gSmluaConstants[] = "" "function math.hypot(a, b)\n" "return __math_sqrt(a * a + b * b)\n" "end\n" +"--- @param x number\n" +"--- @return number\n" +"--- Returns 1 if `x` is positive or zero, -1 otherwise\n" +"function math.sign(x)\n" +"return x >= 0 and 1 or -1\n" +"end\n" +"--- @param x number\n" +"--- @return number\n" +"--- Returns 1 if `x` is positive, 0 if it is zero, -1 otherwise\n" +"function math.sign0(x)\n" +"return x ~= 0 and (x > 0 and 1 or -1) or 0\n" +"end\n" +"--- @param t number\n" +"--- @param a number\n" +"--- @param b number\n" +"--- @return number\n" +"--- Linearly interpolates `t` between `a` and `b`\n" +"function math.lerp(t, a, b)\n" +"return a + (b - a) * t\n" +"end\n" +"--- @param x number\n" +"--- @param a number\n" +"--- @param b number\n" +"--- @return number\n" +"--- Determines where `x` linearly lies between `a` and `b`. It's the inverse of `math.lerp`\n" +"function math.invlerp(x, a, b)\n" +"return (x - a) / (b - a)\n" +"end\n" +"--- @param x number\n" +"--- @param a number\n" +"--- @param b number\n" +"--- @param c number\n" +"--- @param d number\n" +"--- @return number\n" +"--- Linearly remaps `x` from the source range `[a, b]` to the destination range `[c, d]`\n" +"function math.remap(x, a, b, c, d)\n" +"return c + (d - c) * ((x - a) / (b - a))\n" +"end\n" "-----------------\n" "-- legacy font --\n" "-----------------\n" @@ -171,6 +240,30 @@ char gSmluaConstants[] = "" "clamp = math.clamp\n" "clampf = math.clamp\n" "hypotf = math.hypot\n" +"gVec2fZero = create_read_only_table({x=0,y=0})\n" +"gVec2fOne = create_read_only_table({x=1,y=1})\n" +"gVec3fZero = create_read_only_table({x=0,y=0,z=0})\n" +"gVec3fOne = create_read_only_table({x=1,y=1,z=1})\n" +"gVec3fX = create_read_only_table({x=1,y=0,z=0})\n" +"gVec3fY = create_read_only_table({x=0,y=1,z=0})\n" +"gVec3fZ = create_read_only_table({x=0,y=0,z=1})\n" +"gVec4fZero = create_read_only_table({x=0,y=0,z=0,w=0})\n" +"gVec4fOne = create_read_only_table({x=1,y=1,z=1,w=1})\n" +"gVec2iZero = create_read_only_table({x=0,y=0})\n" +"gVec2iOne = create_read_only_table({x=1,y=1})\n" +"gVec3iZero = create_read_only_table({x=0,y=0,z=0})\n" +"gVec3iOne = create_read_only_table({x=1,y=1,z=1})\n" +"gVec4iZero = create_read_only_table({x=0,y=0,z=0,w=0})\n" +"gVec4iOne = create_read_only_table({x=1,y=1,z=1,w=1})\n" +"gVec2sZero = create_read_only_table({x=0,y=0})\n" +"gVec2sOne = create_read_only_table({x=1,y=1})\n" +"gVec3sZero = create_read_only_table({x=0,y=0,z=0})\n" +"gVec3sOne = create_read_only_table({x=1,y=1,z=1})\n" +"gVec4sZero = create_read_only_table({x=0,y=0,z=0,w=0})\n" +"gVec4sOne = create_read_only_table({x=1,y=1,z=1,w=1})\n" +"gMat4Zero = create_read_only_table({m00=0,m01=0,m02=0,m03=0,m10=0,m11=0,m12=0,m13=0,m20=0,m21=0,m22=0,m23=0,m30=0,m31=0,m32=0,m33=0})\n" +"gMat4Identity = create_read_only_table({m00=1,m01=0,m02=0,m03=0,m10=0,m11=1,m12=0,m13=0,m20=0,m21=0,m22=1,m23=0,m30=0,m31=0,m32=0,m33=1})\n" +"gMat4Fullscreen = create_read_only_table({m00=0.00625,m01=0,m02=0,m03=0,m10=0,m11=0.008333333333333333,m12=0,m13=0,m20=0,m21=0,m22=-1,m23=0,m30=-1,m31=-1,m32=-1,m33=1})\n" "INSTANT_WARP_INDEX_START=0x00\n" "INSTANT_WARP_INDEX_STOP=0x04\n" "MAX_AREAS=16\n" diff --git a/src/pc/lua/smlua_functions.c b/src/pc/lua/smlua_functions.c index b3cce5ec3..86f51191a 100644 --- a/src/pc/lua/smlua_functions.c +++ b/src/pc/lua/smlua_functions.c @@ -40,6 +40,116 @@ bool smlua_functions_valid_param_range(lua_State* L, int min, int max) { return true; } + /////////// + // table // +/////////// + +int smlua_func_table_copy(lua_State *L) { + LUA_STACK_CHECK_BEGIN_NUM(1); + + if (!smlua_functions_valid_param_count(L, 1)) { return 0; } + + if (lua_type(L, 1) != LUA_TTABLE) { + LOG_LUA_LINE("table_copy() called with an invalid type for param 1: %s", luaL_typename(L, 1)); + return 0; + } + + // Create a new table that will be the copy + lua_newtable(L); + + // Iterate through original table + lua_pushnil(L); // first key + while (lua_next(L, 1) != 0) { + + // Stack at the start of iteration is orig_table, new_table, key, value + // At the end of iteration, we need the key on top of the stack + // But settable also needs the key, so we manipulate the stack to become: + // orig_table, new_table, key, key, value (before settable) + // orig_table, new_table, key (after settable) + lua_pushvalue(L, -2); + lua_insert(L, -2); + lua_settable(L, 2); + } + + LUA_STACK_CHECK_END(); + return 1; +} + +static void table_deepcopy_table(lua_State *L, int idxTable, int idxCache); + +static void table_deepcopy_value(lua_State *L, int idx, int idxCache) { + idx = lua_absindex(L, idx); + if (lua_type(L, idx) == LUA_TTABLE) { + table_deepcopy_table(L, idx, idxCache); + } else { + lua_pushvalue(L, idx); + } +} + +static void table_deepcopy_table(lua_State *L, int idxTable, int idxCache) { + idxTable = lua_absindex(L, idxTable); + idxCache = lua_absindex(L, idxCache); + + // Check the cache to see if the table has already been copied + lua_pushvalue(L, idxTable); + lua_rawget(L, idxCache); + if (!lua_isnil(L, -1)) { + return; + } + lua_pop(L, 1); + + // Create a new table that will be the copy and add it to the cache + lua_newtable(L); + int idxNewTable = lua_gettop(L); + lua_pushvalue(L, idxTable); + lua_pushvalue(L, idxNewTable); + lua_rawset(L, idxCache); + + // Iterate through original table + lua_pushnil(L); // first key + while (lua_next(L, idxTable) != 0) { + int idxKey = lua_absindex(L, -2); + int idxValue = lua_absindex(L, -1); + + // Copy key and value to new table + table_deepcopy_value(L, idxKey, idxCache); + table_deepcopy_value(L, idxValue, idxCache); + lua_settable(L, idxNewTable); + + // Pop value to set key on top of the stack + lua_pop(L, 1); + } + + // Copy metatable + if (lua_getmetatable(L, idxTable)) { + table_deepcopy_value(L, -1, idxCache); + lua_setmetatable(L, idxNewTable); + lua_pop(L, 1); + } +} + +int smlua_func_table_deepcopy(lua_State *L) { + LUA_STACK_CHECK_BEGIN_NUM(1); + + if (!smlua_functions_valid_param_count(L, 1)) { return 0; } + + if (lua_type(L, 1) != LUA_TTABLE) { + LOG_LUA_LINE("table_deepcopy() called with an invalid type for param 1: %s", luaL_typename(L, 1)); + return 0; + } + + // Cache to prevent copying the same table twice + lua_newtable(L); + int idxCache = lua_gettop(L); + + table_deepcopy_table(L, 1, idxCache); + + lua_remove(L, idxCache); + + LUA_STACK_CHECK_END(); + return 1; +} + ////////// // misc // ////////// @@ -1149,6 +1259,8 @@ void smlua_bind_functions(void) { lua_State* L = gLuaState; // misc + smlua_bind_function(L, "table_copy", smlua_func_table_copy); + smlua_bind_function(L, "table_deepcopy", smlua_func_table_deepcopy); smlua_bind_function(L, "init_mario_after_warp", smlua_func_init_mario_after_warp); smlua_bind_function(L, "initiate_warp", smlua_func_initiate_warp); smlua_bind_function(L, "network_init_object", smlua_func_network_init_object); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 8728d4f3d..75dc114e2 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -19075,12 +19075,13 @@ int smlua_func_vec3f_rotate_zxy(lua_State* L) { smlua_get_vec3s(rotate, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_rotate_zxy"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_rotate_zxy(v, rotate), NULL); + vec3f_rotate_zxy(v, rotate); smlua_push_vec3f(v, 1); smlua_push_vec3s(rotate, 2); + lua_settop(L, 1); return 1; } @@ -19108,7 +19109,7 @@ int smlua_func_vec3f_rotate_around_n(lua_State* L) { s16 r = smlua_to_integer(L, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "vec3f_rotate_around_n"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_rotate_around_n(dest, v, n, r), NULL); + vec3f_rotate_around_n(dest, v, n, r); smlua_push_vec3f(dest, 1); @@ -19116,6 +19117,7 @@ int smlua_func_vec3f_rotate_around_n(lua_State* L) { smlua_push_vec3f(n, 3); + lua_settop(L, 1); return 1; } @@ -19141,7 +19143,7 @@ int smlua_func_vec3f_project(lua_State* L) { smlua_get_vec3f(onto, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3f_project"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_project(dest, v, onto), NULL); + vec3f_project(dest, v, onto); smlua_push_vec3f(dest, 1); @@ -19149,6 +19151,7 @@ int smlua_func_vec3f_project(lua_State* L) { smlua_push_vec3f(onto, 3); + lua_settop(L, 1); return 1; } @@ -19182,7 +19185,7 @@ int smlua_func_vec3f_transform(lua_State* L) { smlua_get_vec3f(scale, 5); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "vec3f_transform"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_transform(dest, v, translation, rotation, scale), NULL); + vec3f_transform(dest, v, translation, rotation, scale); smlua_push_vec3f(dest, 1); @@ -19194,6 +19197,7 @@ int smlua_func_vec3f_transform(lua_State* L) { smlua_push_vec3f(scale, 5); + lua_settop(L, 1); return 1; } @@ -19289,7 +19293,7 @@ int smlua_func_find_vector_perpendicular_to_plane(lua_State* L) { smlua_get_vec3f(c, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "find_vector_perpendicular_to_plane"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)find_vector_perpendicular_to_plane(dest, a, b, c), NULL); + find_vector_perpendicular_to_plane(dest, a, b, c); smlua_push_vec3f(dest, 1); @@ -19299,6 +19303,7 @@ int smlua_func_find_vector_perpendicular_to_plane(lua_State* L) { smlua_push_vec3f(c, 4); + lua_settop(L, 1); return 1; } @@ -19671,7 +19676,7 @@ int smlua_func_get_pos_from_transform_mtx(lua_State* L) { smlua_get_mat4(camMtx, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "get_pos_from_transform_mtx"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)get_pos_from_transform_mtx(dest, objMtx, camMtx), NULL); + get_pos_from_transform_mtx(dest, objMtx, camMtx); smlua_push_vec3f(dest, 1); @@ -19679,6 +19684,7 @@ int smlua_func_get_pos_from_transform_mtx(lua_State* L) { smlua_push_mat4(camMtx, 3); + lua_settop(L, 1); return 1; } @@ -19949,10 +19955,11 @@ int smlua_func_vec3f_zero(lua_State* L) { smlua_get_vec3f(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3f_zero"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_zero(v), NULL); + vec3f_zero(v); smlua_push_vec3f(v, 1); + lua_settop(L, 1); return 1; } @@ -19974,12 +19981,13 @@ int smlua_func_vec3f_copy(lua_State* L) { smlua_get_vec3f(src, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_copy"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_copy(dest, src), NULL); + vec3f_copy(dest, src); smlua_push_vec3f(dest, 1); smlua_push_vec3f(src, 2); + lua_settop(L, 1); return 1; } @@ -20003,10 +20011,11 @@ int smlua_func_vec3f_set(lua_State* L) { f32 z = smlua_to_number(L, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "vec3f_set"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_set(dest, x, y, z), NULL); + vec3f_set(dest, x, y, z); smlua_push_vec3f(dest, 1); + lua_settop(L, 1); return 1; } @@ -20028,12 +20037,13 @@ int smlua_func_vec3f_add(lua_State* L) { smlua_get_vec3f(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_add"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_add(dest, a), NULL); + vec3f_add(dest, a); smlua_push_vec3f(dest, 1); smlua_push_vec3f(a, 2); + lua_settop(L, 1); return 1; } @@ -20059,7 +20069,7 @@ int smlua_func_vec3f_sum(lua_State* L) { smlua_get_vec3f(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3f_sum"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_sum(dest, a, b), NULL); + vec3f_sum(dest, a, b); smlua_push_vec3f(dest, 1); @@ -20067,6 +20077,7 @@ int smlua_func_vec3f_sum(lua_State* L) { smlua_push_vec3f(b, 3); + lua_settop(L, 1); return 1; } @@ -20088,12 +20099,13 @@ int smlua_func_vec3f_sub(lua_State* L) { smlua_get_vec3f(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_sub"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_sub(dest, a), NULL); + vec3f_sub(dest, a); smlua_push_vec3f(dest, 1); smlua_push_vec3f(a, 2); + lua_settop(L, 1); return 1; } @@ -20119,7 +20131,7 @@ int smlua_func_vec3f_dif(lua_State* L) { smlua_get_vec3f(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3f_dif"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_dif(dest, a, b), NULL); + vec3f_dif(dest, a, b); smlua_push_vec3f(dest, 1); @@ -20127,6 +20139,7 @@ int smlua_func_vec3f_dif(lua_State* L) { smlua_push_vec3f(b, 3); + lua_settop(L, 1); return 1; } @@ -20146,10 +20159,73 @@ int smlua_func_vec3f_mul(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_mul"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_mul(dest, a), NULL); + vec3f_mul(dest, a); smlua_push_vec3f(dest, 1); + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3f_mult(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", "vec3f_mult", 2, top); + return 0; + } + + + Vec3f dest; + smlua_get_vec3f(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3f_mult"); return 0; } + + Vec3f a; + smlua_get_vec3f(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_mult"); return 0; } + + vec3f_mult(dest, a); + + smlua_push_vec3f(dest, 1); + + smlua_push_vec3f(a, 2); + + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3f_prod(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 3) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "vec3f_prod", 3, top); + return 0; + } + + + Vec3f dest; + smlua_get_vec3f(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3f_prod"); return 0; } + + Vec3f a; + smlua_get_vec3f(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_prod"); return 0; } + + Vec3f b; + smlua_get_vec3f(b, 3); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3f_prod"); return 0; } + + vec3f_prod(dest, a, b); + + smlua_push_vec3f(dest, 1); + + smlua_push_vec3f(a, 2); + + smlua_push_vec3f(b, 3); + + lua_settop(L, 1); return 1; } @@ -20169,10 +20245,11 @@ int smlua_func_vec3f_div(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_div"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_div(dest, a), NULL); + vec3f_div(dest, a); smlua_push_vec3f(dest, 1); + lua_settop(L, 1); return 1; } @@ -20211,10 +20288,11 @@ int smlua_func_vec3f_normalize(lua_State* L) { smlua_get_vec3f(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3f_normalize"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_normalize(v), NULL); + vec3f_normalize(v); smlua_push_vec3f(v, 1); + lua_settop(L, 1); return 1; } @@ -20234,10 +20312,11 @@ int smlua_func_vec3f_set_magnitude(lua_State* L) { f32 mag = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_set_magnitude"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_set_magnitude(v, mag), NULL); + vec3f_set_magnitude(v, mag); smlua_push_vec3f(v, 1); + lua_settop(L, 1); return 1; } @@ -20290,7 +20369,7 @@ int smlua_func_vec3f_cross(lua_State* L) { smlua_get_vec3f(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3f_cross"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_cross(dest, a, b), NULL); + vec3f_cross(dest, a, b); smlua_push_vec3f(dest, 1); @@ -20298,6 +20377,7 @@ int smlua_func_vec3f_cross(lua_State* L) { smlua_push_vec3f(b, 3); + lua_settop(L, 1); return 1; } @@ -20327,7 +20407,7 @@ int smlua_func_vec3f_combine(lua_State* L) { f32 sclB = smlua_to_number(L, 5); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "vec3f_combine"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3f_combine(dest, vecA, vecB, sclA, sclB), NULL); + vec3f_combine(dest, vecA, vecB, sclA, sclB); smlua_push_vec3f(dest, 1); @@ -20335,6 +20415,7 @@ int smlua_func_vec3f_combine(lua_State* L) { smlua_push_vec3f(vecB, 3); + lua_settop(L, 1); return 1; } @@ -20431,12 +20512,13 @@ int smlua_func_vec3f_to_vec3i(lua_State* L) { smlua_get_vec3f(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_to_vec3i"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3f_to_vec3i(dest, a), NULL); + vec3f_to_vec3i(dest, a); smlua_push_vec3i(dest, 1); smlua_push_vec3f(a, 2); + lua_settop(L, 1); return 1; } @@ -20458,12 +20540,13 @@ int smlua_func_vec3f_to_vec3s(lua_State* L) { smlua_get_vec3f(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3f_to_vec3s"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3f_to_vec3s(dest, a), NULL); + vec3f_to_vec3s(dest, a); smlua_push_vec3s(dest, 1); smlua_push_vec3f(a, 2); + lua_settop(L, 1); return 1; } @@ -20485,10 +20568,11 @@ int smlua_func_vec3i_zero(lua_State* L) { smlua_get_vec3i(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3i_zero"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_zero(v), NULL); + vec3i_zero(v); smlua_push_vec3i(v, 1); + lua_settop(L, 1); return 1; } @@ -20510,12 +20594,13 @@ int smlua_func_vec3i_copy(lua_State* L) { smlua_get_vec3i(src, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_copy"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_copy(dest, src), NULL); + vec3i_copy(dest, src); smlua_push_vec3i(dest, 1); smlua_push_vec3i(src, 2); + lua_settop(L, 1); return 1; } @@ -20539,10 +20624,11 @@ int smlua_func_vec3i_set(lua_State* L) { s32 z = smlua_to_integer(L, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "vec3i_set"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_set(dest, x, y, z), NULL); + vec3i_set(dest, x, y, z); smlua_push_vec3i(dest, 1); + lua_settop(L, 1); return 1; } @@ -20564,12 +20650,13 @@ int smlua_func_vec3i_add(lua_State* L) { smlua_get_vec3i(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_add"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_add(dest, a), NULL); + vec3i_add(dest, a); smlua_push_vec3i(dest, 1); smlua_push_vec3i(a, 2); + lua_settop(L, 1); return 1; } @@ -20595,7 +20682,7 @@ int smlua_func_vec3i_sum(lua_State* L) { smlua_get_vec3i(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3i_sum"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_sum(dest, a, b), NULL); + vec3i_sum(dest, a, b); smlua_push_vec3i(dest, 1); @@ -20603,6 +20690,7 @@ int smlua_func_vec3i_sum(lua_State* L) { smlua_push_vec3i(b, 3); + lua_settop(L, 1); return 1; } @@ -20624,12 +20712,13 @@ int smlua_func_vec3i_sub(lua_State* L) { smlua_get_vec3i(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_sub"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_sub(dest, a), NULL); + vec3i_sub(dest, a); smlua_push_vec3i(dest, 1); smlua_push_vec3i(a, 2); + lua_settop(L, 1); return 1; } @@ -20655,7 +20744,7 @@ int smlua_func_vec3i_dif(lua_State* L) { smlua_get_vec3i(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3i_dif"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_dif(dest, a, b), NULL); + vec3i_dif(dest, a, b); smlua_push_vec3i(dest, 1); @@ -20663,6 +20752,7 @@ int smlua_func_vec3i_dif(lua_State* L) { smlua_push_vec3i(b, 3); + lua_settop(L, 1); return 1; } @@ -20682,10 +20772,73 @@ int smlua_func_vec3i_mul(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_mul"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_mul(dest, a), NULL); + vec3i_mul(dest, a); smlua_push_vec3i(dest, 1); + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3i_mult(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", "vec3i_mult", 2, top); + return 0; + } + + + Vec3i dest; + smlua_get_vec3i(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3i_mult"); return 0; } + + Vec3i a; + smlua_get_vec3i(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_mult"); return 0; } + + vec3i_mult(dest, a); + + smlua_push_vec3i(dest, 1); + + smlua_push_vec3i(a, 2); + + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3i_prod(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 3) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "vec3i_prod", 3, top); + return 0; + } + + + Vec3i dest; + smlua_get_vec3i(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3i_prod"); return 0; } + + Vec3i a; + smlua_get_vec3i(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_prod"); return 0; } + + Vec3i b; + smlua_get_vec3i(b, 3); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3i_prod"); return 0; } + + vec3i_prod(dest, a, b); + + smlua_push_vec3i(dest, 1); + + smlua_push_vec3i(a, 2); + + smlua_push_vec3i(b, 3); + + lua_settop(L, 1); return 1; } @@ -20705,10 +20858,11 @@ int smlua_func_vec3i_div(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_div"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_div(dest, a), NULL); + vec3i_div(dest, a); smlua_push_vec3i(dest, 1); + lua_settop(L, 1); return 1; } @@ -20747,10 +20901,11 @@ int smlua_func_vec3i_normalize(lua_State* L) { smlua_get_vec3i(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3i_normalize"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_normalize(v), NULL); + vec3i_normalize(v); smlua_push_vec3i(v, 1); + lua_settop(L, 1); return 1; } @@ -20770,10 +20925,11 @@ int smlua_func_vec3i_set_magnitude(lua_State* L) { f32 mag = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_set_magnitude"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_set_magnitude(v, mag), NULL); + vec3i_set_magnitude(v, mag); smlua_push_vec3i(v, 1); + lua_settop(L, 1); return 1; } @@ -20826,7 +20982,7 @@ int smlua_func_vec3i_cross(lua_State* L) { smlua_get_vec3i(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3i_cross"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_cross(dest, a, b), NULL); + vec3i_cross(dest, a, b); smlua_push_vec3i(dest, 1); @@ -20834,6 +20990,7 @@ int smlua_func_vec3i_cross(lua_State* L) { smlua_push_vec3i(b, 3); + lua_settop(L, 1); return 1; } @@ -20863,7 +21020,7 @@ int smlua_func_vec3i_combine(lua_State* L) { f32 sclB = smlua_to_number(L, 5); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "vec3i_combine"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3i_combine(dest, vecA, vecB, sclA, sclB), NULL); + vec3i_combine(dest, vecA, vecB, sclA, sclB); smlua_push_vec3i(dest, 1); @@ -20871,6 +21028,7 @@ int smlua_func_vec3i_combine(lua_State* L) { smlua_push_vec3i(vecB, 3); + lua_settop(L, 1); return 1; } @@ -20967,12 +21125,13 @@ int smlua_func_vec3i_to_vec3f(lua_State* L) { smlua_get_vec3i(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_to_vec3f"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3i_to_vec3f(dest, a), NULL); + vec3i_to_vec3f(dest, a); smlua_push_vec3f(dest, 1); smlua_push_vec3i(a, 2); + lua_settop(L, 1); return 1; } @@ -20994,12 +21153,13 @@ int smlua_func_vec3i_to_vec3s(lua_State* L) { smlua_get_vec3i(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3i_to_vec3s"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3i_to_vec3s(dest, a), NULL); + vec3i_to_vec3s(dest, a); smlua_push_vec3s(dest, 1); smlua_push_vec3i(a, 2); + lua_settop(L, 1); return 1; } @@ -21021,10 +21181,11 @@ int smlua_func_vec3s_zero(lua_State* L) { smlua_get_vec3s(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3s_zero"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_zero(v), NULL); + vec3s_zero(v); smlua_push_vec3s(v, 1); + lua_settop(L, 1); return 1; } @@ -21046,12 +21207,13 @@ int smlua_func_vec3s_copy(lua_State* L) { smlua_get_vec3s(src, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_copy"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_copy(dest, src), NULL); + vec3s_copy(dest, src); smlua_push_vec3s(dest, 1); smlua_push_vec3s(src, 2); + lua_settop(L, 1); return 1; } @@ -21075,10 +21237,11 @@ int smlua_func_vec3s_set(lua_State* L) { s16 z = smlua_to_integer(L, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "vec3s_set"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_set(dest, x, y, z), NULL); + vec3s_set(dest, x, y, z); smlua_push_vec3s(dest, 1); + lua_settop(L, 1); return 1; } @@ -21100,12 +21263,13 @@ int smlua_func_vec3s_add(lua_State* L) { smlua_get_vec3s(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_add"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_add(dest, a), NULL); + vec3s_add(dest, a); smlua_push_vec3s(dest, 1); smlua_push_vec3s(a, 2); + lua_settop(L, 1); return 1; } @@ -21131,7 +21295,7 @@ int smlua_func_vec3s_sum(lua_State* L) { smlua_get_vec3s(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3s_sum"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_sum(dest, a, b), NULL); + vec3s_sum(dest, a, b); smlua_push_vec3s(dest, 1); @@ -21139,6 +21303,7 @@ int smlua_func_vec3s_sum(lua_State* L) { smlua_push_vec3s(b, 3); + lua_settop(L, 1); return 1; } @@ -21160,12 +21325,13 @@ int smlua_func_vec3s_sub(lua_State* L) { smlua_get_vec3s(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_sub"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_sub(dest, a), NULL); + vec3s_sub(dest, a); smlua_push_vec3s(dest, 1); smlua_push_vec3s(a, 2); + lua_settop(L, 1); return 1; } @@ -21191,7 +21357,7 @@ int smlua_func_vec3s_dif(lua_State* L) { smlua_get_vec3s(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3s_dif"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_dif(dest, a, b), NULL); + vec3s_dif(dest, a, b); smlua_push_vec3s(dest, 1); @@ -21199,6 +21365,7 @@ int smlua_func_vec3s_dif(lua_State* L) { smlua_push_vec3s(b, 3); + lua_settop(L, 1); return 1; } @@ -21218,10 +21385,73 @@ int smlua_func_vec3s_mul(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_mul"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_mul(dest, a), NULL); + vec3s_mul(dest, a); smlua_push_vec3s(dest, 1); + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3s_mult(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", "vec3s_mult", 2, top); + return 0; + } + + + Vec3s dest; + smlua_get_vec3s(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3s_mult"); return 0; } + + Vec3s a; + smlua_get_vec3s(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_mult"); return 0; } + + vec3s_mult(dest, a); + + smlua_push_vec3s(dest, 1); + + smlua_push_vec3s(a, 2); + + lua_settop(L, 1); + return 1; +} + +int smlua_func_vec3s_prod(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 3) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "vec3s_prod", 3, top); + return 0; + } + + + Vec3s dest; + smlua_get_vec3s(dest, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3s_prod"); return 0; } + + Vec3s a; + smlua_get_vec3s(a, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_prod"); return 0; } + + Vec3s b; + smlua_get_vec3s(b, 3); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3s_prod"); return 0; } + + vec3s_prod(dest, a, b); + + smlua_push_vec3s(dest, 1); + + smlua_push_vec3s(a, 2); + + smlua_push_vec3s(b, 3); + + lua_settop(L, 1); return 1; } @@ -21241,10 +21471,11 @@ int smlua_func_vec3s_div(lua_State* L) { f32 a = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_div"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_div(dest, a), NULL); + vec3s_div(dest, a); smlua_push_vec3s(dest, 1); + lua_settop(L, 1); return 1; } @@ -21283,10 +21514,11 @@ int smlua_func_vec3s_normalize(lua_State* L) { smlua_get_vec3s(v, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vec3s_normalize"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_normalize(v), NULL); + vec3s_normalize(v); smlua_push_vec3s(v, 1); + lua_settop(L, 1); return 1; } @@ -21306,10 +21538,11 @@ int smlua_func_vec3s_set_magnitude(lua_State* L) { f32 mag = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_set_magnitude"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_set_magnitude(v, mag), NULL); + vec3s_set_magnitude(v, mag); smlua_push_vec3s(v, 1); + lua_settop(L, 1); return 1; } @@ -21362,7 +21595,7 @@ int smlua_func_vec3s_cross(lua_State* L) { smlua_get_vec3s(b, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "vec3s_cross"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_cross(dest, a, b), NULL); + vec3s_cross(dest, a, b); smlua_push_vec3s(dest, 1); @@ -21370,6 +21603,7 @@ int smlua_func_vec3s_cross(lua_State* L) { smlua_push_vec3s(b, 3); + lua_settop(L, 1); return 1; } @@ -21399,7 +21633,7 @@ int smlua_func_vec3s_combine(lua_State* L) { f32 sclB = smlua_to_number(L, 5); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "vec3s_combine"); return 0; } - smlua_push_pointer(L, LVT_S16_P, (void*)vec3s_combine(dest, vecA, vecB, sclA, sclB), NULL); + vec3s_combine(dest, vecA, vecB, sclA, sclB); smlua_push_vec3s(dest, 1); @@ -21407,6 +21641,7 @@ int smlua_func_vec3s_combine(lua_State* L) { smlua_push_vec3s(vecB, 3); + lua_settop(L, 1); return 1; } @@ -21503,12 +21738,13 @@ int smlua_func_vec3s_to_vec3f(lua_State* L) { smlua_get_vec3s(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_to_vec3f"); return 0; } - smlua_push_pointer(L, LVT_F32_P, (void*)vec3s_to_vec3f(dest, a), NULL); + vec3s_to_vec3f(dest, a); smlua_push_vec3f(dest, 1); smlua_push_vec3s(a, 2); + lua_settop(L, 1); return 1; } @@ -21530,12 +21766,13 @@ int smlua_func_vec3s_to_vec3i(lua_State* L) { smlua_get_vec3s(a, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "vec3s_to_vec3i"); return 0; } - smlua_push_pointer(L, LVT_S32_P, (void*)vec3s_to_vec3i(dest, a), NULL); + vec3s_to_vec3i(dest, a); smlua_push_vec3i(dest, 1); smlua_push_vec3s(a, 2); + lua_settop(L, 1); return 1; } @@ -36134,6 +36371,8 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "vec3f_sub", smlua_func_vec3f_sub); smlua_bind_function(L, "vec3f_dif", smlua_func_vec3f_dif); smlua_bind_function(L, "vec3f_mul", smlua_func_vec3f_mul); + smlua_bind_function(L, "vec3f_mult", smlua_func_vec3f_mult); + smlua_bind_function(L, "vec3f_prod", smlua_func_vec3f_prod); smlua_bind_function(L, "vec3f_div", smlua_func_vec3f_div); smlua_bind_function(L, "vec3f_length", smlua_func_vec3f_length); smlua_bind_function(L, "vec3f_normalize", smlua_func_vec3f_normalize); @@ -36156,6 +36395,8 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "vec3i_sub", smlua_func_vec3i_sub); smlua_bind_function(L, "vec3i_dif", smlua_func_vec3i_dif); smlua_bind_function(L, "vec3i_mul", smlua_func_vec3i_mul); + smlua_bind_function(L, "vec3i_mult", smlua_func_vec3i_mult); + smlua_bind_function(L, "vec3i_prod", smlua_func_vec3i_prod); smlua_bind_function(L, "vec3i_div", smlua_func_vec3i_div); smlua_bind_function(L, "vec3i_length", smlua_func_vec3i_length); smlua_bind_function(L, "vec3i_normalize", smlua_func_vec3i_normalize); @@ -36178,6 +36419,8 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "vec3s_sub", smlua_func_vec3s_sub); smlua_bind_function(L, "vec3s_dif", smlua_func_vec3s_dif); smlua_bind_function(L, "vec3s_mul", smlua_func_vec3s_mul); + smlua_bind_function(L, "vec3s_mult", smlua_func_vec3s_mult); + smlua_bind_function(L, "vec3s_prod", smlua_func_vec3s_prod); smlua_bind_function(L, "vec3s_div", smlua_func_vec3s_div); smlua_bind_function(L, "vec3s_length", smlua_func_vec3s_length); smlua_bind_function(L, "vec3s_normalize", smlua_func_vec3s_normalize); diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 97ee0f7c9..5c0393ddd 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -751,15 +751,21 @@ void smlua_logline(void) { // Get the folder and file // in the format: "folder/file.lua" const char* src = info.source; - int slashCount = 0; const char* folderStart = NULL; - for (const char* p = src + strlen(src); p > src; --p) { - if (*p == '/' || *p == '\\') { - if (++slashCount == 2) { - folderStart = p + 1; - break; + if (strlen(src) < SYS_MAX_PATH) { + int slashCount = 0; + for (const char* p = src + strlen(src); p > src; --p) { + if (*p == '/' || *p == '\\') { + if (++slashCount == 2) { + folderStart = p + 1; + break; + } } } + } else { + // That's not a filepath + // It also explains why sometimes the whole gSmluaConstants string was printed to the console + snprintf(info.short_src, sizeof(info.short_src), "gSmluaConstants"); } LOG_LUA(" [%d] '%s':%d -- %s [%s]",