G_CULL_INVERT_EXT; Vec2 functions; bug fixes (#985)

This commit is contained in:
PeachyPeach 2025-10-21 18:56:35 +02:00 committed by GitHub
parent f58b82997f
commit 4671f09f79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 806 additions and 21 deletions

View file

@ -1,39 +1,70 @@
import sys
VEC3X_TO_VEC3Y = """
VECX_TO_VECY = """
/* |description|
Converts a 3D {{desc}} vector `a` into a 3D {{desc_2}} vector and stores the result in `dest`
Converts a {{size}}D {{desc}} vector `a` into a {{size}}D {{desc_2}} vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec3{{suffix_2}}p vec3{{suffix}}_to_vec3{{suffix_2}}(OUT 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}};
INLINE OPTIMIZE_O3 Vec{{size}}{{suffix_2}}p vec{{size}}{{suffix}}_to_vec{{size}}{{suffix_2}}(OUT Vec{{size}}{{suffix_2}} dest, Vec{{size}}{{suffix}} a) {
{{body}}
return dest;
}
"""
ROUNDING_FORMULA = " + ((a[%d] > 0) ? 0.5f : -0.5f)"
ROUNDING_FORMULA = " + ((a[{i}] > 0) ? 0.5f : -0.5f)"
def vec3_write_conversion_functions(generated: str, curr_template: dict, templates: list, size: int) -> str:
def vec_write_conversion_functions(generated: str, curr_template: dict, templates: list, size: int) -> str:
for template in templates:
if template["suffix"] == curr_template["suffix"]:
continue
generated += VEC3X_TO_VEC3Y \
body = "\n ".join([
"dest[{i}] = a[{i}]{rounding};".format(
i=i,
rounding=ROUNDING_FORMULA.format(i=i) if curr_template["rounding"] else ""
) for i in range(size)
])
generated += VECX_TO_VECY \
.replace("{{size}}", str(size)) \
.replace("{{desc}}", curr_template["desc"]) \
.replace("{{suffix}}", curr_template["suffix"]) \
.replace("{{desc_2}}", template["desc"]) \
.replace("{{suffix_2}}", template["suffix"])
for i in range(size):
rounding_i = "{{rounding_%d}}" % (i)
generated = generated.replace(rounding_i, ROUNDING_FORMULA % (i) if curr_template["rounding"] else "")
.replace("{{suffix_2}}", template["suffix"]) \
.replace("{{body}}", body)
return generated
TEMPLATES = {
"src/engine/math_util_vec2.tmpl": {
"size": 2,
"templates": [
{
"desc": "floating-point",
"type": "f32",
"suffix": "f",
"rounding": True
},
{
"desc": "integer",
"type": "s32",
"suffix": "i",
"rounding": False
},
{
"desc": "short integer",
"type": "s16",
"suffix": "s",
"rounding": False
}
],
"post-template": {
"function": vec_write_conversion_functions,
"args": {
"size": 2
}
}
},
"src/engine/math_util_vec3.tmpl": {
"size": 3,
"templates": [
@ -57,7 +88,7 @@ TEMPLATES = {
}
],
"post-template": {
"function": vec3_write_conversion_functions,
"function": vec_write_conversion_functions,
"args": {
"size": 3
}

View file

@ -405,6 +405,7 @@ s64 DynOS_Gfx_ParseGfxConstants(const String& _Arg, bool* found) {
gfx_constant(G_LIGHT_MAP_EXT);
gfx_constant(G_LIGHTING_ENGINE_EXT);
gfx_constant(G_PACKED_NORMALS_EXT);
gfx_constant(G_CULL_INVERT_EXT);
gfx_constant(G_FRESNEL_COLOR_EXT);
gfx_constant(G_FRESNEL_ALPHA_EXT);

View file

@ -15,5 +15,6 @@ Gfx shape_template_dl[] = {
/* [11] */ gsSPDisplayList(NULL),
/* [12] */ gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF),
/* [13] */ gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE),
/* [14] */ gsSPEndDisplayList(),
/* [14] */ gsSPLoadGeometryMode(G_LIGHTING | G_CULL_BACK),
/* [15] */ gsSPEndDisplayList(),
};

View file

@ -69,7 +69,11 @@ All of this is a holdover from when there were only two players. It was a reason
- [Custom HUD Texture](examples/custom-hud-texture)
- [Custom Audio Test](examples/audio-test)
- [Custom Texture Overriding](examples/texture-override)
- [Custom Animations (DynOS)](examples/custom-animations-dynos)
- [Custom Animations (Lua)](examples/custom-animations-lua)
- [Bytestring Packet Example](examples/bytestring-packet-example.lua)
- [Gfx/Vtx Demo](examples/gfx-vtx-demo)
- [Lighting Engine Demo](examples/lighting-engine-demo)
## Example Lua mods (large)
- [Hide and Seek Gamemode](../../mods/hide-and-seek.lua)

View file

@ -7,6 +7,7 @@
#define G_LIGHT_MAP_EXT 0x00000800
#define G_LIGHTING_ENGINE_EXT 0x00004000
#define G_PACKED_NORMALS_EXT 0x00000080
#define G_CULL_INVERT_EXT 0x00000100
#define G_FRESNEL_COLOR_EXT 0x00000040
#define G_FRESNEL_ALPHA_EXT 0x00400000

View file

@ -233,6 +233,30 @@ OPTIMIZE_O3 s32 anim_spline_poll(struct MarioState* m, OUT Vec3f result) {
return hasEnded;
}
///////////
// Vec2f //
///////////
Vec2f gVec2fZero = { 0.0f, 0.0f };
Vec2f gVec2fOne = { 1.0f, 1.0f };
///////////
// Vec2i //
///////////
Vec2i gVec2iZero = { 0, 0 };
Vec2i gVec2iOne = { 1, 1 };
///////////
// Vec2s //
///////////
Vec2s gVec2sZero = { 0, 0 };
Vec2s gVec2sOne = { 1, 1 };
///////////
// Vec3f //
///////////

View file

@ -87,6 +87,12 @@ extern f32 gCosineTable[];
#endif
extern Vec2f gVec2fZero;
extern Vec2i gVec2iZero;
extern Vec2s gVec2sZero;
extern Vec2f gVec2fOne;
extern Vec2i gVec2iOne;
extern Vec2s gVec2sOne;
extern Vec3f gVec3fZero;
extern Vec3i gVec3iZero;
extern Vec3s gVec3sZero;
@ -143,6 +149,24 @@ Advances the spline-based animation associated with `m` and stores the current i
|descriptionEnd| */
OPTIMIZE_O3 s32 anim_spline_poll(struct MarioState* m, OUT Vec3f result);
///////////
// Vec2f //
///////////
#include "math_util_vec2f.inl"
///////////
// Vec2i //
///////////
#include "math_util_vec2i.inl"
///////////
// Vec2s //
///////////
#include "math_util_vec2s.inl"
///////////
// Vec3f //
///////////

View file

@ -0,0 +1,157 @@
#pragma once
/* |description|
Sets the components of the 2D {{desc}} vector `v` to 0
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_zero(OUT Vec2{{suffix}} v) {
memset(v, 0, sizeof(Vec2{{suffix}}));
return v;
}
/* |description|
Copies the contents of a 2D {{desc}} vector (`src`) into another 2D {{desc}} vector (`dest`)
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_copy(OUT Vec2{{suffix}} dest, Vec2{{suffix}} src) {
dest[0] = src[0];
dest[1] = src[1];
return dest;
}
/* |description|
Sets the values of the 2D {{desc}} vector `dest` to the given x and y values
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_set(OUT Vec2{{suffix}} dest, {{type}} x, {{type}} y) {
dest[0] = x;
dest[1] = y;
return dest;
}
/* |description|
Adds the components of the 2D {{desc}} vector `a` to `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_add(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a) {
dest[0] += a[0];
dest[1] += a[1];
return dest;
}
/* |description|
Adds the components of two 2D {{desc}} vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_sum(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a, Vec2{{suffix}} b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
return dest;
}
/* |description|
Subtracts the components of the 2D {{desc}} vector `a` from `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_sub(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a) {
dest[0] -= a[0];
dest[1] -= a[1];
return dest;
}
/* |description|
Subtracts the components of the 2D {{desc}} vector `b` from the components of `a` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_dif(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a, Vec2{{suffix}} b) {
dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1];
return dest;
}
/* |description|
Multiplies each component of the 2D {{desc}} vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_mul(OUT Vec2{{suffix}} dest, f32 a) {
dest[0] *= a;
dest[1] *= a;
return dest;
}
/* |description|
Multiplies the components of the 2D {{desc}} vector `dest` with the components of `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_mult(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a) {
dest[0] *= a[0];
dest[1] *= a[1];
return dest;
}
/* |description|
Multiplies the components of two 2D {{desc}} vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_prod(OUT Vec2{{suffix}} dest, Vec2{{suffix}} a, Vec2{{suffix}} b) {
dest[0] = a[0] * b[0];
dest[1] = a[1] * b[1];
return dest;
}
/* |description|
Divides each component of the 2D {{desc}} vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_div(OUT Vec2{{suffix}} dest, f32 a) {
if (a == 0) { return dest; }
dest[0] /= a;
dest[1] /= a;
return dest;
}
/* |description|
Calculates the length (magnitude) of the 2D {{desc}} vector `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2{{suffix}}_length(Vec2{{suffix}} a) {
return sqrtf(a[0] * a[0] + a[1] * a[1]);
}
/* |description|
Normalizes the 2D {{desc}} vector `v` so that its length (magnitude) becomes 1, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_normalize(OUT Vec2{{suffix}} v) {
f32 mag = vec2{{suffix}}_length(v);
vec2{{suffix}}_div(v, mag);
return v;
}
/* |description|
Sets the length (magnitude) of 2D {{desc}} vector `v`, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2{{suffix}}p vec2{{suffix}}_set_magnitude(OUT Vec2{{suffix}} v, f32 mag) {
vec2{{suffix}}_normalize(v);
vec2{{suffix}}_mul(v, mag);
return v;
}
/* |description|
Computes the dot product of the two 2D {{desc}} vectors `a` and `b`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2{{suffix}}_dot(Vec2{{suffix}} a, Vec2{{suffix}} b) {
return (f32) (a[0] * b[0] + a[1] * b[1]);
}
/* |description|
Takes two 2D {{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 Vec2{{suffix}}p vec2{{suffix}}_combine(OUT Vec2{{suffix}} dest, Vec2{{suffix}} vecA, Vec2{{suffix}} vecB, f32 sclA, f32 sclB) {
dest[0] = vecA[0] * sclA + vecB[0] * sclB;
dest[1] = vecA[1] * sclA + vecB[1] * sclB;
return dest;
}
/* |description|
Calculates the distance between two 2D {{desc}} vectors `v1` and `v2`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2{{suffix}}_dist(Vec2{{suffix}} v1, Vec2{{suffix}} v2) {
Vec2{{suffix}} diff;
vec2{{suffix}}_dif(diff, v1, v2);
return vec2{{suffix}}_length(diff);
}
/* |description|
Returns `true` if all components of the 2D {{desc}} vector `v` are zero
|descriptionEnd| */
INLINE OPTIMIZE_O3 bool vec2{{suffix}}_is_zero(Vec2{{suffix}} v) {
return memcmp(v, gVec2{{suffix}}Zero, sizeof(Vec2{{suffix}})) == 0;
}

View file

@ -0,0 +1,178 @@
/* THIS FILE IS AUTO-GENERATED */
/* DO NOT EDIT IT MANUALLY */
#pragma once
/* |description|
Sets the components of the 2D floating-point vector `v` to 0
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_zero(OUT Vec2f v) {
memset(v, 0, sizeof(Vec2f));
return v;
}
/* |description|
Copies the contents of a 2D floating-point vector (`src`) into another 2D floating-point vector (`dest`)
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_copy(OUT Vec2f dest, Vec2f src) {
dest[0] = src[0];
dest[1] = src[1];
return dest;
}
/* |description|
Sets the values of the 2D floating-point vector `dest` to the given x and y values
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_set(OUT Vec2f dest, f32 x, f32 y) {
dest[0] = x;
dest[1] = y;
return dest;
}
/* |description|
Adds the components of the 2D floating-point vector `a` to `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_add(OUT Vec2f dest, Vec2f a) {
dest[0] += a[0];
dest[1] += a[1];
return dest;
}
/* |description|
Adds the components of two 2D floating-point vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_sum(OUT Vec2f dest, Vec2f a, Vec2f b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
return dest;
}
/* |description|
Subtracts the components of the 2D floating-point vector `a` from `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_sub(OUT Vec2f dest, Vec2f a) {
dest[0] -= a[0];
dest[1] -= a[1];
return dest;
}
/* |description|
Subtracts the components of the 2D floating-point vector `b` from the components of `a` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_dif(OUT Vec2f dest, Vec2f a, Vec2f b) {
dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1];
return dest;
}
/* |description|
Multiplies each component of the 2D floating-point vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_mul(OUT Vec2f dest, f32 a) {
dest[0] *= a;
dest[1] *= a;
return dest;
}
/* |description|
Multiplies the components of the 2D floating-point vector `dest` with the components of `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_mult(OUT Vec2f dest, Vec2f a) {
dest[0] *= a[0];
dest[1] *= a[1];
return dest;
}
/* |description|
Multiplies the components of two 2D floating-point vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_prod(OUT Vec2f dest, Vec2f a, Vec2f b) {
dest[0] = a[0] * b[0];
dest[1] = a[1] * b[1];
return dest;
}
/* |description|
Divides each component of the 2D floating-point vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_div(OUT Vec2f dest, f32 a) {
if (a == 0) { return dest; }
dest[0] /= a;
dest[1] /= a;
return dest;
}
/* |description|
Calculates the length (magnitude) of the 2D floating-point vector `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2f_length(Vec2f a) {
return sqrtf(a[0] * a[0] + a[1] * a[1]);
}
/* |description|
Normalizes the 2D floating-point vector `v` so that its length (magnitude) becomes 1, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_normalize(OUT Vec2f v) {
f32 mag = vec2f_length(v);
vec2f_div(v, mag);
return v;
}
/* |description|
Sets the length (magnitude) of 2D floating-point vector `v`, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2f_set_magnitude(OUT Vec2f v, f32 mag) {
vec2f_normalize(v);
vec2f_mul(v, mag);
return v;
}
/* |description|
Computes the dot product of the two 2D floating-point vectors `a` and `b`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2f_dot(Vec2f a, Vec2f b) {
return (f32) (a[0] * b[0] + a[1] * b[1]);
}
/* |description|
Takes two 2D 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 Vec2fp vec2f_combine(OUT Vec2f dest, Vec2f vecA, Vec2f vecB, f32 sclA, f32 sclB) {
dest[0] = vecA[0] * sclA + vecB[0] * sclB;
dest[1] = vecA[1] * sclA + vecB[1] * sclB;
return dest;
}
/* |description|
Calculates the distance between two 2D floating-point vectors `v1` and `v2`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2f_dist(Vec2f v1, Vec2f v2) {
Vec2f diff;
vec2f_dif(diff, v1, v2);
return vec2f_length(diff);
}
/* |description|
Returns `true` if all components of the 2D floating-point vector `v` are zero
|descriptionEnd| */
INLINE OPTIMIZE_O3 bool vec2f_is_zero(Vec2f v) {
return memcmp(v, gVec2fZero, sizeof(Vec2f)) == 0;
}
/* |description|
Converts a 2D floating-point vector `a` into a 2D integer vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2f_to_vec2i(OUT Vec2i dest, Vec2f a) {
dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f);
dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f);
return dest;
}
/* |description|
Converts a 2D floating-point vector `a` into a 2D short integer vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2f_to_vec2s(OUT Vec2s dest, Vec2f a) {
dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f);
dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f);
return dest;
}

View file

@ -0,0 +1,178 @@
/* THIS FILE IS AUTO-GENERATED */
/* DO NOT EDIT IT MANUALLY */
#pragma once
/* |description|
Sets the components of the 2D integer vector `v` to 0
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_zero(OUT Vec2i v) {
memset(v, 0, sizeof(Vec2i));
return v;
}
/* |description|
Copies the contents of a 2D integer vector (`src`) into another 2D integer vector (`dest`)
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_copy(OUT Vec2i dest, Vec2i src) {
dest[0] = src[0];
dest[1] = src[1];
return dest;
}
/* |description|
Sets the values of the 2D integer vector `dest` to the given x and y values
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_set(OUT Vec2i dest, s32 x, s32 y) {
dest[0] = x;
dest[1] = y;
return dest;
}
/* |description|
Adds the components of the 2D integer vector `a` to `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_add(OUT Vec2i dest, Vec2i a) {
dest[0] += a[0];
dest[1] += a[1];
return dest;
}
/* |description|
Adds the components of two 2D integer vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_sum(OUT Vec2i dest, Vec2i a, Vec2i b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
return dest;
}
/* |description|
Subtracts the components of the 2D integer vector `a` from `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_sub(OUT Vec2i dest, Vec2i a) {
dest[0] -= a[0];
dest[1] -= a[1];
return dest;
}
/* |description|
Subtracts the components of the 2D integer vector `b` from the components of `a` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_dif(OUT Vec2i dest, Vec2i a, Vec2i b) {
dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1];
return dest;
}
/* |description|
Multiplies each component of the 2D integer vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_mul(OUT Vec2i dest, f32 a) {
dest[0] *= a;
dest[1] *= a;
return dest;
}
/* |description|
Multiplies the components of the 2D integer vector `dest` with the components of `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_mult(OUT Vec2i dest, Vec2i a) {
dest[0] *= a[0];
dest[1] *= a[1];
return dest;
}
/* |description|
Multiplies the components of two 2D integer vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_prod(OUT Vec2i dest, Vec2i a, Vec2i b) {
dest[0] = a[0] * b[0];
dest[1] = a[1] * b[1];
return dest;
}
/* |description|
Divides each component of the 2D integer vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_div(OUT Vec2i dest, f32 a) {
if (a == 0) { return dest; }
dest[0] /= a;
dest[1] /= a;
return dest;
}
/* |description|
Calculates the length (magnitude) of the 2D integer vector `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2i_length(Vec2i a) {
return sqrtf(a[0] * a[0] + a[1] * a[1]);
}
/* |description|
Normalizes the 2D integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_normalize(OUT Vec2i v) {
f32 mag = vec2i_length(v);
vec2i_div(v, mag);
return v;
}
/* |description|
Sets the length (magnitude) of 2D integer vector `v`, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2i_set_magnitude(OUT Vec2i v, f32 mag) {
vec2i_normalize(v);
vec2i_mul(v, mag);
return v;
}
/* |description|
Computes the dot product of the two 2D integer vectors `a` and `b`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2i_dot(Vec2i a, Vec2i b) {
return (f32) (a[0] * b[0] + a[1] * b[1]);
}
/* |description|
Takes two 2D 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 Vec2ip vec2i_combine(OUT Vec2i dest, Vec2i vecA, Vec2i vecB, f32 sclA, f32 sclB) {
dest[0] = vecA[0] * sclA + vecB[0] * sclB;
dest[1] = vecA[1] * sclA + vecB[1] * sclB;
return dest;
}
/* |description|
Calculates the distance between two 2D integer vectors `v1` and `v2`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2i_dist(Vec2i v1, Vec2i v2) {
Vec2i diff;
vec2i_dif(diff, v1, v2);
return vec2i_length(diff);
}
/* |description|
Returns `true` if all components of the 2D integer vector `v` are zero
|descriptionEnd| */
INLINE OPTIMIZE_O3 bool vec2i_is_zero(Vec2i v) {
return memcmp(v, gVec2iZero, sizeof(Vec2i)) == 0;
}
/* |description|
Converts a 2D integer vector `a` into a 2D floating-point vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2i_to_vec2f(OUT Vec2f dest, Vec2i a) {
dest[0] = a[0];
dest[1] = a[1];
return dest;
}
/* |description|
Converts a 2D integer vector `a` into a 2D short integer vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2i_to_vec2s(OUT Vec2s dest, Vec2i a) {
dest[0] = a[0];
dest[1] = a[1];
return dest;
}

View file

@ -0,0 +1,178 @@
/* THIS FILE IS AUTO-GENERATED */
/* DO NOT EDIT IT MANUALLY */
#pragma once
/* |description|
Sets the components of the 2D short integer vector `v` to 0
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_zero(OUT Vec2s v) {
memset(v, 0, sizeof(Vec2s));
return v;
}
/* |description|
Copies the contents of a 2D short integer vector (`src`) into another 2D short integer vector (`dest`)
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_copy(OUT Vec2s dest, Vec2s src) {
dest[0] = src[0];
dest[1] = src[1];
return dest;
}
/* |description|
Sets the values of the 2D short integer vector `dest` to the given x and y values
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_set(OUT Vec2s dest, s16 x, s16 y) {
dest[0] = x;
dest[1] = y;
return dest;
}
/* |description|
Adds the components of the 2D short integer vector `a` to `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_add(OUT Vec2s dest, Vec2s a) {
dest[0] += a[0];
dest[1] += a[1];
return dest;
}
/* |description|
Adds the components of two 2D short integer vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_sum(OUT Vec2s dest, Vec2s a, Vec2s b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
return dest;
}
/* |description|
Subtracts the components of the 2D short integer vector `a` from `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_sub(OUT Vec2s dest, Vec2s a) {
dest[0] -= a[0];
dest[1] -= a[1];
return dest;
}
/* |description|
Subtracts the components of the 2D short integer vector `b` from the components of `a` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_dif(OUT Vec2s dest, Vec2s a, Vec2s b) {
dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1];
return dest;
}
/* |description|
Multiplies each component of the 2D short integer vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_mul(OUT Vec2s dest, f32 a) {
dest[0] *= a;
dest[1] *= a;
return dest;
}
/* |description|
Multiplies the components of the 2D short integer vector `dest` with the components of `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_mult(OUT Vec2s dest, Vec2s a) {
dest[0] *= a[0];
dest[1] *= a[1];
return dest;
}
/* |description|
Multiplies the components of two 2D short integer vectors `a` and `b` and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_prod(OUT Vec2s dest, Vec2s a, Vec2s b) {
dest[0] = a[0] * b[0];
dest[1] = a[1] * b[1];
return dest;
}
/* |description|
Divides each component of the 2D short integer vector `dest` by the scalar value `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_div(OUT Vec2s dest, f32 a) {
if (a == 0) { return dest; }
dest[0] /= a;
dest[1] /= a;
return dest;
}
/* |description|
Calculates the length (magnitude) of the 2D short integer vector `a`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2s_length(Vec2s a) {
return sqrtf(a[0] * a[0] + a[1] * a[1]);
}
/* |description|
Normalizes the 2D short integer vector `v` so that its length (magnitude) becomes 1, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_normalize(OUT Vec2s v) {
f32 mag = vec2s_length(v);
vec2s_div(v, mag);
return v;
}
/* |description|
Sets the length (magnitude) of 2D short integer vector `v`, while retaining its direction
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2sp vec2s_set_magnitude(OUT Vec2s v, f32 mag) {
vec2s_normalize(v);
vec2s_mul(v, mag);
return v;
}
/* |description|
Computes the dot product of the two 2D short integer vectors `a` and `b`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2s_dot(Vec2s a, Vec2s b) {
return (f32) (a[0] * b[0] + a[1] * b[1]);
}
/* |description|
Takes two 2D 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 Vec2sp vec2s_combine(OUT Vec2s dest, Vec2s vecA, Vec2s vecB, f32 sclA, f32 sclB) {
dest[0] = vecA[0] * sclA + vecB[0] * sclB;
dest[1] = vecA[1] * sclA + vecB[1] * sclB;
return dest;
}
/* |description|
Calculates the distance between two 2D short integer vectors `v1` and `v2`
|descriptionEnd| */
INLINE OPTIMIZE_O3 f32 vec2s_dist(Vec2s v1, Vec2s v2) {
Vec2s diff;
vec2s_dif(diff, v1, v2);
return vec2s_length(diff);
}
/* |description|
Returns `true` if all components of the 2D short integer vector `v` are zero
|descriptionEnd| */
INLINE OPTIMIZE_O3 bool vec2s_is_zero(Vec2s v) {
return memcmp(v, gVec2sZero, sizeof(Vec2s)) == 0;
}
/* |description|
Converts a 2D short integer vector `a` into a 2D floating-point vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2fp vec2s_to_vec2f(OUT Vec2f dest, Vec2s a) {
dest[0] = a[0];
dest[1] = a[1];
return dest;
}
/* |description|
Converts a 2D short integer vector `a` into a 2D integer vector and stores the result in `dest`
|descriptionEnd| */
INLINE OPTIMIZE_O3 Vec2ip vec2s_to_vec2i(OUT Vec2i dest, Vec2s a) {
dest[0] = a[0];
dest[1] = a[1];
return dest;
}

View file

@ -788,8 +788,11 @@ static Gfx *geo_mario_create_player_colors_dl(s32 index, Gfx *capEnemyGfx, Gfx *
if (gfx) {
Gfx *gfxp = gfx;
for (s32 part = 0; part != PLAYER_PART_MAX; ++part) {
gSPLight(gfxp++, &gNetworkPlayerColors[index].parts[part].l, (2 * (part + 1)) + 1);
gSPLight(gfxp++, &gNetworkPlayerColors[index].parts[part].a, (2 * (part + 1)) + 2);
Lights1 *light = alloc_display_list(sizeof(Lights1));
if (!light) { return NULL; }
*light = gNetworkPlayerColors[index].parts[part];
gSPLight(gfxp++, &light->l, (2 * (part + 1)) + 1);
gSPLight(gfxp++, &light->a, (2 * (part + 1)) + 2);
}
if (capEnemyGfx) { gSPDisplayList(gfxp++, capEnemyGfx); }
if (capEnemyDecalGfx) { gSPDisplayList(gfxp++, capEnemyDecalGfx); }

View file

@ -1028,6 +1028,11 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t
cross = -cross;
}
// Invert culling: back becomes front and front becomes back
if (rsp.geometry_mode & G_CULL_INVERT_EXT) {
cross = -cross;
}
switch (rsp.geometry_mode & G_CULL_BOTH) {
case G_CULL_FRONT:
if (cross <= 0) return;

View file

@ -41,10 +41,10 @@ struct LuaHookedEvent {
static struct LuaHookedEvent sHookedEvents[HOOK_MAX] = { 0 };
static const char* sLuaHookedEventTypeName[] = {
#define SMLUA_EVENT_HOOK(hookEventType, ...) #hookEventType,
#define SMLUA_EVENT_HOOK(hookEventType, ...) [hookEventType] = #hookEventType,
#include "smlua_hook_events.inl"
#undef SMLUA_EVENT_HOOK
"HOOK_MAX"
[HOOK_MAX] = "HOOK_MAX"
};
int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct Mod* activeMod, struct ModFile* activeModFile) {