mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Color type and palette/color functions (#199)
Added a Color type (typedef u8 Color[3]) Added network_player_color_to_palette and network_player_palette_to_color Reran autogen
This commit is contained in:
parent
a97e7466bf
commit
6c0757c908
15 changed files with 189 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
|
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
|
||||||
vec3_types = ['Vec3s', 'Vec3f']
|
vec3_types = ['Vec3s', 'Vec3f', 'Color']
|
||||||
typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory']
|
typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory']
|
||||||
|
|
||||||
exclude_structs = [
|
exclude_structs = [
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,24 @@ param_override_build['Vec3s'] = {
|
||||||
'after': param_vec3s_after_call
|
'after': param_vec3s_after_call
|
||||||
}
|
}
|
||||||
|
|
||||||
|
param_color_before_call = """
|
||||||
|
u8* $[IDENTIFIER] = smlua_get_color_from_buffer();
|
||||||
|
$[IDENTIFIER][0] = smlua_get_integer_field($[INDEX], "r");
|
||||||
|
$[IDENTIFIER][1] = smlua_get_integer_field($[INDEX], "g");
|
||||||
|
$[IDENTIFIER][2] = smlua_get_integer_field($[INDEX], "b");
|
||||||
|
"""
|
||||||
|
|
||||||
|
param_color_after_call = """
|
||||||
|
smlua_push_integer_field($[INDEX], "r", $[IDENTIFIER][0]);
|
||||||
|
smlua_push_integer_field($[INDEX], "g", $[IDENTIFIER][1]);
|
||||||
|
smlua_push_integer_field($[INDEX], "b", $[IDENTIFIER][2]);
|
||||||
|
"""
|
||||||
|
|
||||||
|
param_override_build['Color'] = {
|
||||||
|
'before': param_color_before_call,
|
||||||
|
'after': param_color_after_call
|
||||||
|
}
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
manual_index_documentation = """
|
manual_index_documentation = """
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ sLuaManuallyDefinedStructs = [{
|
||||||
'path': 'n/a',
|
'path': 'n/a',
|
||||||
'structs': [
|
'structs': [
|
||||||
'struct Vec3f { float x; float y; float z; }',
|
'struct Vec3f { float x; float y; float z; }',
|
||||||
'struct Vec3s { s16 x; s16 y; s16 z; }'
|
'struct Vec3s { s16 x; s16 y; s16 z; }',
|
||||||
|
'struct Color { u8 r; u8 g; u8 b; }'
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5233,6 +5233,14 @@ function get_network_player_smallest_global()
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param np NetworkPlayer
|
||||||
|
--- @param part PlayerParts
|
||||||
|
--- @param color Color
|
||||||
|
--- @return nil
|
||||||
|
function network_player_color_to_palette(np, part, color)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @return integer
|
--- @return integer
|
||||||
function network_player_connected_count()
|
function network_player_connected_count()
|
||||||
-- ...
|
-- ...
|
||||||
|
|
@ -5244,6 +5252,14 @@ function network_player_from_global_index(globalIndex)
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param np NetworkPlayer
|
||||||
|
--- @param part PlayerParts
|
||||||
|
--- @param out Color
|
||||||
|
--- @return nil
|
||||||
|
function network_player_palette_to_color(np, part, out)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @param np NetworkPlayer
|
--- @param np NetworkPlayer
|
||||||
--- @param description string
|
--- @param description string
|
||||||
--- @param r integer
|
--- @param r integer
|
||||||
|
|
|
||||||
|
|
@ -1804,6 +1804,11 @@
|
||||||
--- @field public y integer
|
--- @field public y integer
|
||||||
--- @field public z integer
|
--- @field public z integer
|
||||||
|
|
||||||
|
--- @class Color
|
||||||
|
--- @field public b integer
|
||||||
|
--- @field public g integer
|
||||||
|
--- @field public r integer
|
||||||
|
|
||||||
--- @class Pointer_integer
|
--- @class Pointer_integer
|
||||||
--- @class Pointer_Trajectory
|
--- @class Pointer_Trajectory
|
||||||
--- @class Pointer_LevelScript
|
--- @class Pointer_LevelScript
|
||||||
|
|
|
||||||
|
|
@ -7164,6 +7164,28 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [network_player_color_to_palette](#network_player_color_to_palette)
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`network_player_color_to_palette(np, part, color)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| np | [NetworkPlayer](structs.md#NetworkPlayer) |
|
||||||
|
| part | [enum PlayerParts](constants.md#enum-PlayerParts) |
|
||||||
|
| color | `Color` |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- None
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`void network_player_color_to_palette(struct NetworkPlayer *np, enum PlayerParts part, Color color);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [network_player_connected_count](#network_player_connected_count)
|
## [network_player_connected_count](#network_player_connected_count)
|
||||||
|
|
||||||
### Lua Example
|
### Lua Example
|
||||||
|
|
@ -7202,6 +7224,28 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [network_player_palette_to_color](#network_player_palette_to_color)
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`network_player_palette_to_color(np, part, out)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| np | [NetworkPlayer](structs.md#NetworkPlayer) |
|
||||||
|
| part | [enum PlayerParts](constants.md#enum-PlayerParts) |
|
||||||
|
| out | `Color` |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- None
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerParts part, Color out);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [network_player_set_description](#network_player_set_description)
|
## [network_player_set_description](#network_player_set_description)
|
||||||
|
|
||||||
### Lua Example
|
### Lua Example
|
||||||
|
|
|
||||||
|
|
@ -1016,8 +1016,10 @@
|
||||||
- [get_network_player_from_area](functions-3.md#get_network_player_from_area)
|
- [get_network_player_from_area](functions-3.md#get_network_player_from_area)
|
||||||
- [get_network_player_from_level](functions-3.md#get_network_player_from_level)
|
- [get_network_player_from_level](functions-3.md#get_network_player_from_level)
|
||||||
- [get_network_player_smallest_global](functions-3.md#get_network_player_smallest_global)
|
- [get_network_player_smallest_global](functions-3.md#get_network_player_smallest_global)
|
||||||
|
- [network_player_color_to_palette](functions-3.md#network_player_color_to_palette)
|
||||||
- [network_player_connected_count](functions-3.md#network_player_connected_count)
|
- [network_player_connected_count](functions-3.md#network_player_connected_count)
|
||||||
- [network_player_from_global_index](functions-3.md#network_player_from_global_index)
|
- [network_player_from_global_index](functions-3.md#network_player_from_global_index)
|
||||||
|
- [network_player_palette_to_color](functions-3.md#network_player_palette_to_color)
|
||||||
- [network_player_set_description](functions-3.md#network_player_set_description)
|
- [network_player_set_description](functions-3.md#network_player_set_description)
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
- [CameraTrigger](#CameraTrigger)
|
- [CameraTrigger](#CameraTrigger)
|
||||||
- [ChainSegment](#ChainSegment)
|
- [ChainSegment](#ChainSegment)
|
||||||
- [Character](#Character)
|
- [Character](#Character)
|
||||||
|
- [Color](#Color)
|
||||||
- [Controller](#Controller)
|
- [Controller](#Controller)
|
||||||
- [CustomLevelInfo](#CustomLevelInfo)
|
- [CustomLevelInfo](#CustomLevelInfo)
|
||||||
- [Cutscene](#Cutscene)
|
- [Cutscene](#Cutscene)
|
||||||
|
|
@ -489,6 +490,18 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [Color](#Color)
|
||||||
|
|
||||||
|
| Field | Type | Access |
|
||||||
|
| ----- | ---- | ------ |
|
||||||
|
| b | `integer` | |
|
||||||
|
| g | `integer` | |
|
||||||
|
| r | `integer` | |
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [Controller](#Controller)
|
## [Controller](#Controller)
|
||||||
|
|
||||||
| Field | Type | Access |
|
| Field | Type | Access |
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ typedef s16 PaintingData;
|
||||||
typedef uintptr_t BehaviorScript;
|
typedef uintptr_t BehaviorScript;
|
||||||
typedef u8 Texture;
|
typedef u8 Texture;
|
||||||
|
|
||||||
|
typedef u8 Color[3];
|
||||||
|
|
||||||
enum SpTaskState {
|
enum SpTaskState {
|
||||||
SPTASK_STATE_NOT_STARTED,
|
SPTASK_STATE_NOT_STARTED,
|
||||||
SPTASK_STATE_RUNNING,
|
SPTASK_STATE_RUNNING,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ enum LuaObjectType {
|
||||||
LOT_NONE = 0,
|
LOT_NONE = 0,
|
||||||
LOT_VEC3S,
|
LOT_VEC3S,
|
||||||
LOT_VEC3F,
|
LOT_VEC3F,
|
||||||
|
LOT_COLOR,
|
||||||
LOT_POINTER,
|
LOT_POINTER,
|
||||||
LOT_MAX,
|
LOT_MAX,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11762,6 +11762,29 @@ int smlua_func_get_network_player_smallest_global(UNUSED lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_network_player_color_to_palette(lua_State* L) {
|
||||||
|
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
|
||||||
|
|
||||||
|
struct NetworkPlayer* np = (struct NetworkPlayer*)smlua_to_cobject(L, 1, LOT_NETWORKPLAYER);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'network_player_color_to_palette'"); return 0; }
|
||||||
|
int part = smlua_to_integer(L, 2);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'network_player_color_to_palette'"); return 0; }
|
||||||
|
|
||||||
|
u8* color = smlua_get_color_from_buffer();
|
||||||
|
color[0] = smlua_get_integer_field(3, "r");
|
||||||
|
color[1] = smlua_get_integer_field(3, "g");
|
||||||
|
color[2] = smlua_get_integer_field(3, "b");
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'network_player_color_to_palette'"); return 0; }
|
||||||
|
|
||||||
|
network_player_color_to_palette(np, part, color);
|
||||||
|
|
||||||
|
smlua_push_integer_field(3, "r", color[0]);
|
||||||
|
smlua_push_integer_field(3, "g", color[1]);
|
||||||
|
smlua_push_integer_field(3, "b", color[2]);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_network_player_connected_count(UNUSED lua_State* L) {
|
int smlua_func_network_player_connected_count(UNUSED lua_State* L) {
|
||||||
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
|
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
|
||||||
|
|
||||||
|
|
@ -11782,6 +11805,29 @@ int smlua_func_network_player_from_global_index(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_network_player_palette_to_color(lua_State* L) {
|
||||||
|
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
|
||||||
|
|
||||||
|
struct NetworkPlayer* np = (struct NetworkPlayer*)smlua_to_cobject(L, 1, LOT_NETWORKPLAYER);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'network_player_palette_to_color'"); return 0; }
|
||||||
|
int part = smlua_to_integer(L, 2);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'network_player_palette_to_color'"); return 0; }
|
||||||
|
|
||||||
|
u8* out = smlua_get_color_from_buffer();
|
||||||
|
out[0] = smlua_get_integer_field(3, "r");
|
||||||
|
out[1] = smlua_get_integer_field(3, "g");
|
||||||
|
out[2] = smlua_get_integer_field(3, "b");
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'network_player_palette_to_color'"); return 0; }
|
||||||
|
|
||||||
|
network_player_palette_to_color(np, part, out);
|
||||||
|
|
||||||
|
smlua_push_integer_field(3, "r", out[0]);
|
||||||
|
smlua_push_integer_field(3, "g", out[1]);
|
||||||
|
smlua_push_integer_field(3, "b", out[2]);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_network_player_set_description(lua_State* L) {
|
int smlua_func_network_player_set_description(lua_State* L) {
|
||||||
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
|
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
|
||||||
|
|
||||||
|
|
@ -19135,8 +19181,10 @@ void smlua_bind_functions_autogen(void) {
|
||||||
smlua_bind_function(L, "get_network_player_from_area", smlua_func_get_network_player_from_area);
|
smlua_bind_function(L, "get_network_player_from_area", smlua_func_get_network_player_from_area);
|
||||||
smlua_bind_function(L, "get_network_player_from_level", smlua_func_get_network_player_from_level);
|
smlua_bind_function(L, "get_network_player_from_level", smlua_func_get_network_player_from_level);
|
||||||
smlua_bind_function(L, "get_network_player_smallest_global", smlua_func_get_network_player_smallest_global);
|
smlua_bind_function(L, "get_network_player_smallest_global", smlua_func_get_network_player_smallest_global);
|
||||||
|
smlua_bind_function(L, "network_player_color_to_palette", smlua_func_network_player_color_to_palette);
|
||||||
smlua_bind_function(L, "network_player_connected_count", smlua_func_network_player_connected_count);
|
smlua_bind_function(L, "network_player_connected_count", smlua_func_network_player_connected_count);
|
||||||
smlua_bind_function(L, "network_player_from_global_index", smlua_func_network_player_from_global_index);
|
smlua_bind_function(L, "network_player_from_global_index", smlua_func_network_player_from_global_index);
|
||||||
|
smlua_bind_function(L, "network_player_palette_to_color", smlua_func_network_player_palette_to_color);
|
||||||
smlua_bind_function(L, "network_player_set_description", smlua_func_network_player_set_description);
|
smlua_bind_function(L, "network_player_set_description", smlua_func_network_player_set_description);
|
||||||
|
|
||||||
// network_utils.h
|
// network_utils.h
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ static u8 sVec3fBufferIndex = 0;
|
||||||
static Vec3s sVec3sBuffer[VEC3S_BUFFER_COUNT] = { 0 };
|
static Vec3s sVec3sBuffer[VEC3S_BUFFER_COUNT] = { 0 };
|
||||||
static u8 sVec3sBufferIndex = 0;
|
static u8 sVec3sBufferIndex = 0;
|
||||||
|
|
||||||
|
#define COLOR_BUFFER_COUNT 64
|
||||||
|
static Color sColorBuffer[COLOR_BUFFER_COUNT] = { 0 };
|
||||||
|
static u8 sColorBufferIndex = 0;
|
||||||
|
|
||||||
f32* smlua_get_vec3f_from_buffer(void) {
|
f32* smlua_get_vec3f_from_buffer(void) {
|
||||||
if (sVec3fBufferIndex >= VEC3F_BUFFER_COUNT) { sVec3fBufferIndex = 0; }
|
if (sVec3fBufferIndex >= VEC3F_BUFFER_COUNT) { sVec3fBufferIndex = 0; }
|
||||||
return sVec3fBuffer[sVec3fBufferIndex++];
|
return sVec3fBuffer[sVec3fBufferIndex++];
|
||||||
|
|
@ -22,6 +26,11 @@ s16* smlua_get_vec3s_from_buffer(void) {
|
||||||
return sVec3sBuffer[sVec3sBufferIndex++];
|
return sVec3sBuffer[sVec3sBufferIndex++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u8* smlua_get_color_from_buffer(void) {
|
||||||
|
if (sColorBufferIndex >= COLOR_BUFFER_COUNT) { sColorBufferIndex = 0; }
|
||||||
|
return sColorBuffer[sColorBufferIndex++];
|
||||||
|
}
|
||||||
|
|
||||||
f32 *smlua_get_vec3f_for_play_sound(f32 *pos) {
|
f32 *smlua_get_vec3f_for_play_sound(f32 *pos) {
|
||||||
if (pos < (f32 *) sVec3fBuffer || pos >= (f32 *) (sVec3fBuffer + VEC3F_BUFFER_COUNT)) {
|
if (pos < (f32 *) sVec3fBuffer || pos >= (f32 *) (sVec3fBuffer + VEC3F_BUFFER_COUNT)) {
|
||||||
return pos;
|
return pos;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ struct LSTNetworkType;
|
||||||
|
|
||||||
f32* smlua_get_vec3f_from_buffer(void);
|
f32* smlua_get_vec3f_from_buffer(void);
|
||||||
s16* smlua_get_vec3s_from_buffer(void);
|
s16* smlua_get_vec3s_from_buffer(void);
|
||||||
|
u8* smlua_get_color_from_buffer(void);
|
||||||
|
|
||||||
void smlua_bind_function(lua_State* L, const char* name, void* func);
|
void smlua_bind_function(lua_State* L, const char* name, void* func);
|
||||||
bool smlua_is_table_empty(int index);
|
bool smlua_is_table_empty(int index);
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,30 @@ struct NetworkPlayer *get_network_player_smallest_global(void) {
|
||||||
return smallest;
|
return smallest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void network_player_color_to_palette(struct NetworkPlayer *np, enum PlayerParts part, Color color) {
|
||||||
|
if (np == NULL || !(part < PLAYER_PART_MAX && part >= 0)) { return; }
|
||||||
|
|
||||||
|
np->palette.parts[part][0] = color[0];
|
||||||
|
np->palette.parts[part][1] = color[1];
|
||||||
|
np->palette.parts[part][2] = color[2];
|
||||||
|
np->overridePalette = np->palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerParts part, Color out) {
|
||||||
|
if (np == NULL || !(part < PLAYER_PART_MAX && part >= 0)) {
|
||||||
|
if (np == NULL) { // output config palette instead if np is NULL
|
||||||
|
out[0] = configPlayerPalette.parts[part][0];
|
||||||
|
out[1] = configPlayerPalette.parts[part][1];
|
||||||
|
out[2] = configPlayerPalette.parts[part][2];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
out[0] = np->palette.parts[part][0];
|
||||||
|
out[1] = np->palette.parts[part][1];
|
||||||
|
out[2] = np->palette.parts[part][2];
|
||||||
|
}
|
||||||
|
|
||||||
void network_player_update(void) {
|
void network_player_update(void) {
|
||||||
for (s32 i = 0; i < MAX_PLAYERS; i++) {
|
for (s32 i = 0; i < MAX_PLAYERS; i++) {
|
||||||
struct NetworkPlayer *np = &gNetworkPlayers[i];
|
struct NetworkPlayer *np = &gNetworkPlayers[i];
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,9 @@ struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s
|
||||||
struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex);
|
struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex);
|
||||||
struct NetworkPlayer* get_network_player_smallest_global(void);
|
struct NetworkPlayer* get_network_player_smallest_global(void);
|
||||||
|
|
||||||
|
void network_player_color_to_palette(struct NetworkPlayer *np, enum PlayerParts part, Color color);
|
||||||
|
void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerParts part, Color out);
|
||||||
|
|
||||||
void network_player_update(void);
|
void network_player_update(void);
|
||||||
|
|
||||||
u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* playerPalette, char* name);
|
u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* playerPalette, char* name);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue