mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 12:05:11 +00:00
Add first person functions to Lua
This commit is contained in:
parent
ac24f5878e
commit
ce987ef3dd
13 changed files with 191 additions and 82 deletions
|
@ -62,7 +62,8 @@ in_files = [
|
|||
"src/game/level_update.h",
|
||||
"src/game/area.h",
|
||||
"src/engine/level_script.h",
|
||||
"src/game/ingame_menu.h"
|
||||
"src/game/ingame_menu.h",
|
||||
"src/game/first_person_cam.h"
|
||||
]
|
||||
|
||||
override_allowed_functions = {
|
||||
|
@ -113,7 +114,8 @@ override_disallowed_functions = {
|
|||
"src/pc/lua/utils/smlua_level_utils.h": [ "smlua_level_util_reset" ],
|
||||
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_reset_all" ],
|
||||
"src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ],
|
||||
"src/pc/network/lag_compensation.h": [ "lag_compensation_clear", "lag_compensation_store" ]
|
||||
"src/pc/network/lag_compensation.h": [ "lag_compensation_clear", "lag_compensation_store" ],
|
||||
"src/game/first_person_cam.h": [ "first_person_update" ]
|
||||
}
|
||||
|
||||
override_hide_functions = {
|
||||
|
|
|
@ -3997,6 +3997,22 @@ function stop_sounds_in_continuous_banks()
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return nil
|
||||
function first_person_reset()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return boolean
|
||||
function get_first_person_enabled()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param enable boolean
|
||||
--- @return nil
|
||||
function set_first_person_enabled(enable)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return nil
|
||||
function reset_dialog_override_color()
|
||||
-- ...
|
||||
|
@ -8882,12 +8898,6 @@ function set_environment_region(index, value)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param enable boolean
|
||||
--- @return nil
|
||||
function set_first_person_camera_enabled(enable)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param index integer
|
||||
--- @param value integer
|
||||
--- @return nil
|
||||
|
|
|
@ -3242,6 +3242,68 @@
|
|||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from first_person_cam.h
|
||||
|
||||
<br />
|
||||
|
||||
|
||||
## [first_person_reset](#first_person_reset)
|
||||
|
||||
### Lua Example
|
||||
`first_person_reset()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void first_person_reset(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [get_first_person_enabled](#get_first_person_enabled)
|
||||
|
||||
### Lua Example
|
||||
`local booleanValue = get_first_person_enabled()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `boolean`
|
||||
|
||||
### C Prototype
|
||||
`bool get_first_person_enabled(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [set_first_person_enabled](#set_first_person_enabled)
|
||||
|
||||
### Lua Example
|
||||
`set_first_person_enabled(enable)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| enable | `boolean` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_first_person_enabled(bool enable);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from ingame_menu.h
|
||||
|
||||
|
|
|
@ -1483,26 +1483,6 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [set_first_person_camera_enabled](#set_first_person_camera_enabled)
|
||||
|
||||
### Lua Example
|
||||
`set_first_person_camera_enabled(enable)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| enable | `boolean` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_first_person_camera_enabled(bool enable);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [set_fog_color](#set_fog_color)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -798,6 +798,13 @@
|
|||
|
||||
<br />
|
||||
|
||||
- first_person_cam.h
|
||||
- [first_person_reset](functions-3.md#first_person_reset)
|
||||
- [get_first_person_enabled](functions-3.md#get_first_person_enabled)
|
||||
- [set_first_person_enabled](functions-3.md#set_first_person_enabled)
|
||||
|
||||
<br />
|
||||
|
||||
- ingame_menu.h
|
||||
- [reset_dialog_override_color](functions-3.md#reset_dialog_override_color)
|
||||
- [reset_dialog_override_pos](functions-3.md#reset_dialog_override_pos)
|
||||
|
@ -1659,7 +1666,6 @@
|
|||
- [save_file_get_using_backup_slot](functions-5.md#save_file_get_using_backup_slot)
|
||||
- [save_file_set_using_backup_slot](functions-5.md#save_file_set_using_backup_slot)
|
||||
- [set_environment_region](functions-5.md#set_environment_region)
|
||||
- [set_first_person_camera_enabled](functions-5.md#set_first_person_camera_enabled)
|
||||
- [set_fog_color](functions-5.md#set_fog_color)
|
||||
- [set_fog_intensity](functions-5.md#set_fog_intensity)
|
||||
- [set_got_file_coin_hi_score](functions-5.md#set_got_file_coin_hi_score)
|
||||
|
|
|
@ -105,6 +105,8 @@ __**NOTE**__: The fields in this struct are not synced and are meant to be chang
|
|||
## [gFirstPersonCamera](#gFirstPersonCamera)
|
||||
`gFirstPersonCamera`'s fields are listed in [FirstPersonCamera](structs.md#FirstPersonCamera).
|
||||
|
||||
__**NOTE**__: `gFirstPersonCamera.enabled` returns whether or not first person is enabled at all. `get_first_person_enabled()` also accounts for certain conditions that make the camera exit first person mode and will return `false` if so.
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
|
|
@ -3194,7 +3194,7 @@ void update_camera(struct Camera *c) {
|
|||
gCamera = c;
|
||||
update_camera_hud_status(c);
|
||||
|
||||
if ((gOverrideFreezeCamera || update_first_person()) && !gDjuiInMainMenu) {
|
||||
if ((gOverrideFreezeCamera || first_person_update()) && !gDjuiInMainMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,30 @@ struct FirstPersonCamera gFirstPersonCamera = {
|
|||
|
||||
extern s16 gMenuMode;
|
||||
|
||||
/**
|
||||
* A mode that implements an first person player camera. (referenced from Gun Mod v3)
|
||||
*/
|
||||
void update_first_person_camera(void) {
|
||||
bool first_person_check_cancels(void) {
|
||||
struct MarioState *m = &gMarioStates[0];
|
||||
|
||||
if (m->action == ACT_FIRST_PERSON || m->action == ACT_IN_CANNON || m->action == ACT_READING_NPC_DIALOG || m->action == ACT_DISAPPEARED) {
|
||||
return true;
|
||||
}
|
||||
struct Object *bowser = find_object_with_behavior(bhvBowser);
|
||||
if (bowser != NULL && (bowser->oAction == 5 || bowser->oAction == 6)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_first_person_enabled(void) {
|
||||
return gFirstPersonCamera.enabled && !first_person_check_cancels();
|
||||
}
|
||||
|
||||
void set_first_person_enabled(bool enable) {
|
||||
if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; }
|
||||
gFirstPersonCamera.enabled = enable;
|
||||
}
|
||||
|
||||
void first_person_camera_update(void) {
|
||||
struct MarioState *m = &gMarioStates[0];
|
||||
f32 sensX = 0.3f * camera_config_get_x_sensitivity();
|
||||
f32 sensY = 0.4f * camera_config_get_y_sensitivity();
|
||||
|
@ -59,8 +79,8 @@ void update_first_person_camera(void) {
|
|||
// fix yaw for some specific actions
|
||||
// if the left stick is held, use Mario's yaw to set the camera's yaw
|
||||
// otherwise, set Mario's yaw to the camera's yaw
|
||||
u32 actions[] = { ACT_HOLDING_BOWSER, ACT_TORNADO_TWIRLING, ACT_FLAG_ON_POLE, ACT_FLAG_SWIMMING, ACT_FLAG_SWIMMING_OR_FLYING };
|
||||
for (s32 i = 0; i < 4; i++) {
|
||||
u32 actions[] = { ACT_FLYING, ACT_HOLDING_BOWSER, ACT_TORNADO_TWIRLING, ACT_FLAG_ON_POLE, ACT_FLAG_SWIMMING, ACT_FLAG_SWIMMING_OR_FLYING };
|
||||
for (s32 i = 0; i < 6; i++) {
|
||||
u32 flag = actions[i];
|
||||
if ((m->action & flag) == flag) {
|
||||
if (ABS(m->controller->stickX) > 4) {
|
||||
|
@ -118,7 +138,7 @@ void update_first_person_camera(void) {
|
|||
gFOVState.fov = gFirstPersonCamera.fov;
|
||||
}
|
||||
|
||||
bool update_first_person(void) {
|
||||
bool first_person_update(void) {
|
||||
if (gFirstPersonCamera.enabled && !gDjuiInMainMenu) {
|
||||
if (gCurrActNum == 99) {
|
||||
return false;
|
||||
|
@ -127,19 +147,8 @@ bool update_first_person(void) {
|
|||
struct MarioState *m = &gMarioStates[0];
|
||||
|
||||
// check cancels
|
||||
if (m->action == ACT_FIRST_PERSON || m->action == ACT_IN_CANNON || m->action == ACT_READING_NPC_DIALOG) {
|
||||
gFOVState.fov = 45.0f;
|
||||
return false;
|
||||
}
|
||||
if (m->action == ACT_DISAPPEARED) {
|
||||
gFOVState.fov = 45.0f;
|
||||
return false;
|
||||
}
|
||||
struct Object *bowser = find_object_with_behavior(bhvBowser);
|
||||
if (bowser != NULL && (bowser->oAction == 5 || bowser->oAction == 6)) {
|
||||
gFOVState.fov = 45.0f;
|
||||
return false;
|
||||
}
|
||||
bool cancel = first_person_check_cancels();
|
||||
if (cancel) { return false; }
|
||||
|
||||
if (m->action == ACT_SHOT_FROM_CANNON && m->area->camera->mode == CAMERA_MODE_INSIDE_CANNON) {
|
||||
gFirstPersonCamera.yaw = m->faceAngle[1] + 0x8000;
|
||||
|
@ -160,7 +169,7 @@ bool update_first_person(void) {
|
|||
vec3f_sum(m->marioObj->header.gfx.pos, m->pos, camDir);
|
||||
}
|
||||
|
||||
update_first_person_camera();
|
||||
first_person_camera_update();
|
||||
|
||||
return true;
|
||||
} else if (!camera_config_is_mouse_look_enabled()) {
|
||||
|
@ -169,3 +178,9 @@ bool update_first_person(void) {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
void first_person_reset(void) {
|
||||
gFirstPersonCamera.pitch = 0;
|
||||
gFirstPersonCamera.yaw = 0;
|
||||
gFirstPersonCamera.crouch = 0;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ struct FirstPersonCamera {
|
|||
|
||||
extern struct FirstPersonCamera gFirstPersonCamera;
|
||||
|
||||
bool update_first_person(void);
|
||||
bool get_first_person_enabled(void);
|
||||
void set_first_person_enabled(bool enable);
|
||||
|
||||
bool first_person_update(void);
|
||||
void first_person_reset(void);
|
||||
|
||||
#endif
|
|
@ -42,6 +42,7 @@
|
|||
#include "src/game/area.h"
|
||||
#include "src/engine/level_script.h"
|
||||
#include "src/game/ingame_menu.h"
|
||||
#include "src/game/first_person_cam.h"
|
||||
|
||||
|
||||
////////////
|
||||
|
@ -13164,6 +13165,57 @@ int smlua_func_stop_sounds_in_continuous_banks(UNUSED lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// first_person_cam.h //
|
||||
////////////////////////
|
||||
|
||||
int smlua_func_first_person_reset(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 0) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "first_person_reset", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
first_person_reset();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_get_first_person_enabled(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 0) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_first_person_enabled", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
lua_pushboolean(L, get_first_person_enabled());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_set_first_person_enabled(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 1) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_first_person_enabled", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool enable = smlua_to_boolean(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_first_person_enabled"); return 0; }
|
||||
|
||||
set_first_person_enabled(enable);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// ingame_menu.h //
|
||||
///////////////////
|
||||
|
@ -29262,23 +29314,6 @@ int smlua_func_set_environment_region(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_set_first_person_camera_enabled(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 1) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_first_person_camera_enabled", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool enable = smlua_to_boolean(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_first_person_camera_enabled"); return 0; }
|
||||
|
||||
set_first_person_camera_enabled(enable);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_set_fog_color(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
@ -31979,6 +32014,11 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "stop_sounds_from_source", smlua_func_stop_sounds_from_source);
|
||||
smlua_bind_function(L, "stop_sounds_in_continuous_banks", smlua_func_stop_sounds_in_continuous_banks);
|
||||
|
||||
// first_person_cam.h
|
||||
smlua_bind_function(L, "first_person_reset", smlua_func_first_person_reset);
|
||||
smlua_bind_function(L, "get_first_person_enabled", smlua_func_get_first_person_enabled);
|
||||
smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled);
|
||||
|
||||
// ingame_menu.h
|
||||
smlua_bind_function(L, "reset_dialog_override_color", smlua_func_reset_dialog_override_color);
|
||||
smlua_bind_function(L, "reset_dialog_override_pos", smlua_func_reset_dialog_override_pos);
|
||||
|
@ -32791,7 +32831,6 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "save_file_get_using_backup_slot", smlua_func_save_file_get_using_backup_slot);
|
||||
smlua_bind_function(L, "save_file_set_using_backup_slot", smlua_func_save_file_set_using_backup_slot);
|
||||
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
|
||||
smlua_bind_function(L, "set_first_person_camera_enabled", smlua_func_set_first_person_camera_enabled);
|
||||
smlua_bind_function(L, "set_fog_color", smlua_func_set_fog_color);
|
||||
smlua_bind_function(L, "set_fog_intensity", smlua_func_set_fog_intensity);
|
||||
smlua_bind_function(L, "set_got_file_coin_hi_score", smlua_func_set_got_file_coin_hi_score);
|
||||
|
|
|
@ -628,13 +628,6 @@ void set_override_envfx(s32 envfx) {
|
|||
|
||||
///
|
||||
|
||||
void set_first_person_camera_enabled(bool enable) {
|
||||
if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; }
|
||||
gFirstPersonCamera.enabled = enable;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
const char* get_os_name(void) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return "Windows";
|
||||
|
|
|
@ -155,8 +155,6 @@ struct DateTime* get_date_and_time(void);
|
|||
u16 get_envfx(void);
|
||||
void set_override_envfx(s32 envfx);
|
||||
|
||||
void set_first_person_camera_enabled(bool enable);
|
||||
|
||||
const char* get_os_name(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -703,10 +703,8 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
|
|||
cnt->extStickY = 0;
|
||||
|
||||
gFirstPersonCamera.enabled = false;
|
||||
gFirstPersonCamera.pitch = 0;
|
||||
gFirstPersonCamera.yaw = 0;
|
||||
gFirstPersonCamera.crouch = 0;
|
||||
gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV;
|
||||
first_person_reset();
|
||||
|
||||
extern void save_file_load_all(UNUSED u8 reload);
|
||||
save_file_load_all(TRUE);
|
||||
|
|
Loading…
Reference in a new issue