Handle RM_Scroll_Texture and editor_Scroll_Texture behaviors from RM2C hacks (#173)

This commit is contained in:
wRadion 2022-08-26 02:46:33 +02:00 committed by GitHub
parent 1777aa5c51
commit 44bbd23f83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 389 additions and 5 deletions

View file

@ -1983,7 +1983,13 @@ id_bhvYellowCoin = 533
id_bhvYoshi = 534
--- @type BehaviorId
id_bhv_max_count = 535
id_RM_Scroll_Texture = 535
--- @type BehaviorId
id_editor_Scroll_Texture = 536
--- @type BehaviorId
id_bhv_max_count = 537
--- @type integer
CAMERA_MODE_8_DIRECTIONS = 0x0E

View file

@ -2852,6 +2852,11 @@ function update_angle_from_move_flags(angle)
-- ...
end
--- @return nil
function uv_update_scroll()
-- ...
end
--- @param dest Vec3f
--- @param src Vec3f
--- @return nil
@ -7527,6 +7532,13 @@ function warp_to_level(aLevel, aArea, aAct)
-- ...
end
--- @param index integer
--- @param name string
--- @param offset integer
--- @param size integer
--- @return nil
function add_scroll_target(index, name, offset, size)
--- @return boolean
function warp_to_start_level()
-- ...
@ -7745,6 +7757,11 @@ function hud_show()
-- ...
end
--- @return nil
function init_scroll_targets()
-- ...
end
--- @return boolean
function is_game_paused()
-- ...

View file

@ -6379,3 +6379,19 @@ const BehaviorScript bhvIntroScene[] = {
CALL_NATIVE(bhv_intro_scene_loop),
END_LOOP(),
};
const BehaviorScript RM_Scroll_Texture[] = {
BEGIN(OBJ_LIST_GENACTOR),
ID(id_RM_Scroll_Texture),
BEGIN_LOOP(),
CALL_NATIVE(uv_update_scroll),
END_LOOP(),
};
const BehaviorScript editor_Scroll_Texture[] = {
BEGIN(OBJ_LIST_GENACTOR),
ID(id_editor_Scroll_Texture),
BEGIN_LOOP(),
CALL_NATIVE(uv_update_scroll),
END_LOOP(),
};

View file

@ -546,6 +546,8 @@ const struct BehaviorTableEntry gBehaviorTable[id_bhv_max_count] = {
BHV_ENTRY(bhvYellowBall),
BHV_ENTRY(bhvYellowCoin),
BHV_ENTRY(bhvYoshi),
BHV_ENTRY(RM_Scroll_Texture),
BHV_ENTRY(editor_Scroll_Texture)
};
enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior) {

View file

@ -65,6 +65,8 @@ void dynos_behavior_hook_all_custom_behaviors(void);
// -- other -- //
void dynos_mod_shutdown(void);
void dynos_add_scroll_target(u32 index, const char *name, u32 offset, u32 size);
void dynos_init_scroll_targets(void);
#endif
#endif

View file

@ -1064,5 +1064,8 @@ bool DynOS_Bin_IsCompressed(const SysPath &aFilename);
bool DynOS_Bin_Compress(const SysPath &aFilename);
BinFile *DynOS_Bin_Decompress(const SysPath &aFilename);
void DynOS_Add_Scroll_Target(u32 index, const char *name, u32 offset, u32 size);
void DynOS_Init_Scroll_Targets(void);
#endif
#endif

View file

@ -771,6 +771,8 @@ s64 DynOS_Bhv_ParseBehaviorScriptConstants(const String &_Arg, bool *found) {
bhv_constant(id_bhvYellowBall);
bhv_constant(id_bhvYellowCoin);
bhv_constant(id_bhvYoshi);
bhv_constant(id_RM_Scroll_Texture);
bhv_constant(id_editor_Scroll_Texture);
// Define a special type for new ids that don't override.
if (_Arg == "id_bhvNewId") { return (BehaviorScript) (0xFFFF); }
@ -2673,4 +2675,4 @@ void DynOS_Bhv_GeneratePack(const SysPath &aPackFolder) {
DynOS_Bhv_Generate(aPackFolder, _BehaviorsFolders, _GfxData);
DynOS_Gfx_Free(_GfxData);
}
}

View file

@ -547,6 +547,8 @@ s64 DynOS_Common_ParseBhvConstants(const String &_Arg, bool *found) {
common_constant(bhvEndBirds2);
common_constant(bhvIntroScene);
common_constant(bhvUnusedFakeStar);
common_constant(RM_Scroll_Texture);
common_constant(editor_Scroll_Texture);
// Legacy behavior names
common_legacy_constant(bhvFish2, bhvManyBlueFishSpawner);

View file

@ -198,4 +198,12 @@ void dynos_mod_shutdown(void) {
DynOS_Mod_Shutdown();
}
void dynos_add_scroll_target(u32 index, const char *name, u32 offset, u32 size) {
DynOS_Add_Scroll_Target(index, name, offset, size);
}
void dynos_init_scroll_targets(void) {
DynOS_Init_Scroll_Targets();
}
}

View file

@ -16,6 +16,7 @@ extern "C" {
#include "game/behavior_actions.h"
#include "game/rendering_graph_node.h"
#include "game/skybox.h"
#include "game/scroll_targets.h"
}
//
@ -174,3 +175,21 @@ void *DynOS_Geo_GetGraphNode(const void *aGeoLayout, bool aKeepInMemory) {
free(_Pool);
return NULL;
}
//
// Scroll Targets
//
void DynOS_Add_Scroll_Target(u32 index, const char* name, u32 offset, u32 size) {
for (auto& lvlPair : DynOS_Lvl_GetArray()) {
for (auto& node : lvlPair.second->mVertices) {
if (node->mName.Find(name) >= 0) {
add_vtx_scroll_target(index, &node->mData[offset], size);
}
}
}
}
void DynOS_Init_Scroll_Targets(void) {
init_vtx_scroll_targets();
}

View file

@ -619,7 +619,9 @@
| id_bhvYellowBall | 532 |
| id_bhvYellowCoin | 533 |
| id_bhvYoshi | 534 |
| id_bhv_max_count | 535 |
| id_RM_Scroll_Texture | 535 |
| id_editor_Scroll_Texture | 536 |
| id_bhv_max_count | 537 |
[:arrow_up_small:](#)

View file

@ -10184,6 +10184,24 @@
<br />
## [uv_update_scroll](#uv_update_scroll)
### Lua Example
`uv_update_scroll()`
### Parameters
- None
### Returns
- None
### C Prototype
`void uv_update_scroll(void);`
[:arrow_up_small:](#)
<br />
## [vec3f_copy_2](#vec3f_copy_2)
### Lua Example

View file

@ -6310,6 +6310,29 @@
<br />
## [add_scroll_target](#add_scroll_target)
### Lua Example
`add_scroll_target(index, name, offset, size)`
### Parameters
| Field | Type |
| ----- | ---- |
| index | `integer` |
| name | `string` |
| offset | `integer` |
| size | `integer` |
### Returns
- None
### C Prototype
`void add_scroll_target(u32 index, const char* name, u32 offset, u32 size);`
[:arrow_up_small:](#)
<br />
## [allocate_mario_action](#allocate_mario_action)
### Lua Example
@ -7024,6 +7047,24 @@
<br />
## [init_scroll_targets](#init_scroll_targets)
### Lua Example
`init_scroll_targets()`
### Parameters
- None
### Returns
- None
### C Prototype
`void init_scroll_targets(void);`
[:arrow_up_small:](#)
<br />
## [is_game_paused](#is_game_paused)
### Lua Example

View file

@ -583,6 +583,7 @@
- [spawn_wind_particles](functions-2.md#spawn_wind_particles)
- [tox_box_move](functions-2.md#tox_box_move)
- [update_angle_from_move_flags](functions-2.md#update_angle_from_move_flags)
- [uv_update_scroll](functions-2.md#uv_update_scroll)
- [vec3f_copy_2](functions-2.md#vec3f_copy_2)
<br />
@ -1405,6 +1406,7 @@
<br />
- smlua_misc_utils.h
- [add_scroll_target](functions-4.md#add_scroll_target)
- [allocate_mario_action](functions-4.md#allocate_mario_action)
- [camera_config_enable_analog_cam](functions-4.md#camera_config_enable_analog_cam)
- [camera_config_enable_free_cam](functions-4.md#camera_config_enable_free_cam)
@ -1442,6 +1444,7 @@
- [hud_render_power_meter](functions-4.md#hud_render_power_meter)
- [hud_set_value](functions-4.md#hud_set_value)
- [hud_show](functions-4.md#hud_show)
- [init_scroll_targets](functions-4.md#init_scroll_targets)
- [is_game_paused](functions-4.md#is_game_paused)
- [is_transition_playing](functions-4.md#is_transition_playing)
- [movtexqc_register](functions-4.md#movtexqc_register)

View file

@ -539,5 +539,7 @@ extern const BehaviorScript bhvEndBirds1[];
extern const BehaviorScript bhvEndBirds2[];
extern const BehaviorScript bhvIntroScene[];
extern const BehaviorScript bhvUnusedFakeStar[];
extern const BehaviorScript RM_Scroll_Texture[];
extern const BehaviorScript editor_Scroll_Texture[];
#endif // BEHAVIOR_DATA_H

View file

@ -539,6 +539,8 @@ enum BehaviorId {
id_bhvYellowBall,
id_bhvYellowCoin,
id_bhvYoshi,
id_RM_Scroll_Texture,
id_editor_Scroll_Texture,
id_bhv_max_count // must be the last in the list
};

View file

@ -284,3 +284,4 @@ s32 set_obj_anim_with_accel_and_sound(s16 a0, s16 a1, s32 a2) {
#include "behaviors/strong_wind_particle.inc.c"
#include "behaviors/sl_snowman_wind.inc.c"
#include "behaviors/sl_walking_penguin.inc.c"
#include "behaviors/texscroll.inc.c"

View file

@ -565,6 +565,7 @@ void bhv_intro_scene_loop(void);
void bhv_dust_smoke_loop(void);
void bhv_yoshi_loop(void);
void bhv_volcano_trap_loop(void);
void uv_update_scroll(void);
Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx);

View file

@ -0,0 +1,138 @@
/*
* All credit goes to https://github.com/jesusyoshi54
* also known as scuttlebugraiser, the creator of RM2C
* Created for the project https://github.com/jesusyoshi54/sm64ex-alo for RM2C support
* https://github.com/jesusyoshi54/sm64ex-alo/blob/master/src/game/behaviors/texscroll.inc.c
*/
#include <math.h>
#include "engine/math_util.h"
#include "src/game/scroll_targets.h"
#include "pc/pc_main.h"
#include "pc/utils/misc.h"
/* SCROLLING BHVS */
#define SCROLL_X 0
#define SCROLL_Y 1
#define SCROLL_Z 2
#define SCROLL_UV_X 4
#define SCROLL_UV_Y 5
/* SCROLLING TYPES */
#define MODE_SCROLL_UV 0
#define MODE_SCROLL_SINE 182 // 1
#define MODE_SCROLL_JUMP 108 // 2
// typedef struct {
// float ob[3]; /* x, y, z */
// unsigned short flag;
// short tc[2]; /* texture coord */
// signed char n[3]; /* normal */
// unsigned char a; /* alpha */
// } Vtx_tn;
// typedef union {
// Vtx_t v; /* Use this one for colors */
// Vtx_tn n; /* Use this one for normals */
// long long int force_structure_alignment;
// } Vtx;
extern Vtx *gScrollTargets[];
extern f32 gRenderingDelta;
static void shift_UV_JUMP(s32 vtxIndex, u16 vertcount, s16 speed, u16 bhv, u16 cycle) {
Vtx* *verts = get_scroll_targets(vtxIndex);
u16 i;
if (verts[0]->n.flag++ <= cycle) {
return;
}
verts[0]->n.flag = 0;
if (bhv < SCROLL_UV_X) {
for (i = 0; i < vertcount; i++) {
verts[i]->n.ob[bhv] += speed;
}
} else {
for (i = 0; i < vertcount; i++) {
verts[i]->n.tc[bhv-SCROLL_UV_X] += speed;
}
}
}
static void shift_UV_NORMAL(u32 vtxIndex, u16 vertcount, s16 speed, u16 bhv, u16 cycle) {
u16 overflownum = 0x1000;
Vtx* *verts = get_scroll_targets(vtxIndex);
u16 correction = 0;
u16 i;
if (bhv < SCROLL_UV_X) {
if (verts[0]->n.flag >= cycle) {
correction = verts[0]->n.flag * speed;
verts[0]->n.flag = 0;
}
for (i = 0; i < vertcount; i++) {
if (correction == 0) {
verts[i]->n.ob[bhv] += speed;
} else {
verts[i]->n.ob[bhv] -= correction;
}
}
} else {
if (verts[0]->n.flag * absi(speed) > overflownum) {
correction = overflownum * signum_positive(speed);
verts[0]->n.flag = 0;
}
for (i = 0; i < vertcount; i++) {
if (correction == 0) {
verts[i]->n.tc[bhv-SCROLL_UV_X] += speed;
} else {
verts[i]->n.tc[bhv-SCROLL_UV_X] -= correction;
}
}
}
if (correction == 0) {
verts[0]->n.flag++;
}
}
static void shift_UV_SINE(u32 vtxIndex, u16 vertcount, s16 speed, u16 bhv, u16 cycle) {
Vtx* *verts = get_scroll_targets(vtxIndex);
u32 i;
if (bhv < SCROLL_UV_X) {
for (i = 0; i < vertcount; i++) {
verts[i]->n.ob[bhv] += sins(verts[0]->n.flag) * speed;
}
} else {
for (i = 0; i < vertcount; i++) {
verts[i]->n.tc[bhv-SCROLL_UV_X] += (u16) (sins(verts[0]->n.flag) * speed);
}
}
verts[0]->n.flag += cycle * 0x23;
}
// format I will use is x=spd, y=bhv, z=vert amount, rx=offset, ry=scrollType, rz=cycle, bparam=addr
void uv_update_scroll(void) {
s16 speed = (s16) o->oPosX;
u16 bhv = (u16) o->oPosY;
u16 vertCount = (u16) o->oPosZ;
u8 scrollType = (u8) o->oFaceAngleYaw;
u16 cycle = (u16) o->oFaceAngleRoll * 180 / 0x8000;
u32 vtxIndex = (u32) o->oBehParams;
switch (scrollType) {
case MODE_SCROLL_UV:
shift_UV_NORMAL(vtxIndex, vertCount, speed, bhv, cycle);
break;
case MODE_SCROLL_SINE:
shift_UV_SINE(vtxIndex, vertCount, speed, bhv, cycle);
break;
case MODE_SCROLL_JUMP:
shift_UV_JUMP(vtxIndex, vertCount, speed, bhv, cycle);
break;
}
}

27
src/game/scroll_targets.c Normal file
View file

@ -0,0 +1,27 @@
#include "scroll_targets.h"
Vtx *gScrollTargets[1024];
static int startIndex[128];
static int lastIndex = 0;
Vtx* *get_scroll_targets(u32 id) {
return &gScrollTargets[startIndex[id]];
}
void add_vtx_scroll_target(u32 id, Vtx *vtx, u32 size) {
if (startIndex[id] == -1) {
startIndex[id] = lastIndex;
}
for (u32 i = 0; i < size; ++i) {
gScrollTargets[lastIndex++] = &vtx[i];
}
}
void init_vtx_scroll_targets(void) {
for (int i = 0; i < 128; ++i) {
startIndex[i] = -1;
}
lastIndex = 0;
}

19
src/game/scroll_targets.h Normal file
View file

@ -0,0 +1,19 @@
/*
* All credit goes to https://github.com/jesusyoshi54
* also known as scuttlebugraiser, the creator of RM2C
* Created for the project https://github.com/jesusyoshi54/sm64ex-alo for RM2C support
* https://github.com/jesusyoshi54/sm64ex-alo/blob/master/src/game/ScrollTargets.inc.c
*/
#include <PR/ultratypes.h>
#include "sm64.h"
#include "types.h"
//Q. Why does this exist instead of just directly referencing VBs?
//A. Because gcc is dumb and will seg fault if you reference a VB by abstracting it through a bparam
//instead of directly refencing it, causing this horrible shit.
extern Vtx *gScrollTargets[];
Vtx* *get_scroll_targets(u32 id);
void add_vtx_scroll_target(u32 id, Vtx *vtx, u32 size);
void init_vtx_scroll_targets(void);

View file

@ -4,6 +4,7 @@
#include "game/area.h"
#include "game/mario.h"
#include "game/hardcoded.h"
#include "game/scroll_targets.h"
#include "audio/external.h"
#include "object_fields.h"
#include "pc/djui/djui_hud_utils.h"
@ -590,7 +591,6 @@ void smlua_cobject_init_globals(void) {
smlua_push_object(L, LOT_BEHAVIORVALUES, &gBehaviorValues);
lua_setglobal(L, "gBehaviorValues");
}
}
void smlua_cobject_init_per_file_globals(char* path) {

View file

@ -855,7 +855,9 @@ char gSmluaConstants[] = ""
"id_bhvYellowBall = 532\n"
"id_bhvYellowCoin = 533\n"
"id_bhvYoshi = 534\n"
"id_bhv_max_count = 535\n"
"id_RM_Scroll_Texture = 535\n"
"id_editor_Scroll_Texture = 536\n"
"id_bhv_max_count = 537\n"
"CAM_MODE_MARIO_ACTIVE = 0x01\n"
"CAM_MODE_LAKITU_WAS_ZOOMED_OUT = 0x02\n"
"CAM_MODE_MARIO_SELECTED = 0x04\n"

View file

@ -5348,6 +5348,15 @@ int smlua_func_update_angle_from_move_flags(lua_State* L) {
return 1;
}
int smlua_func_uv_update_scroll(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
uv_update_scroll();
return 1;
}
int smlua_func_vec3f_copy_2(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
@ -16648,6 +16657,23 @@ int smlua_func_warp_to_start_level(UNUSED lua_State* L) {
// smlua_misc_utils.h //
////////////////////////
int smlua_func_add_scroll_target(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
u32 index = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'add_scroll_target'"); return 0; }
const char* name = smlua_to_string(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'add_scroll_target'"); return 0; }
u32 offset = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'add_scroll_target'"); return 0; }
u32 size = smlua_to_integer(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'add_scroll_target'"); return 0; }
add_scroll_target(index, name, offset, size);
return 1;
}
int smlua_func_allocate_mario_action(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@ -17037,6 +17063,15 @@ int smlua_func_hud_show(UNUSED lua_State* L) {
return 1;
}
int smlua_func_init_scroll_targets(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
init_scroll_targets();
return 1;
}
int smlua_func_is_game_paused(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
@ -18632,6 +18667,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "spawn_wind_particles", smlua_func_spawn_wind_particles);
smlua_bind_function(L, "tox_box_move", smlua_func_tox_box_move);
smlua_bind_function(L, "update_angle_from_move_flags", smlua_func_update_angle_from_move_flags);
smlua_bind_function(L, "uv_update_scroll", smlua_func_uv_update_scroll);
smlua_bind_function(L, "vec3f_copy_2", smlua_func_vec3f_copy_2);
// behavior_table.h
@ -19447,6 +19483,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "warp_to_start_level", smlua_func_warp_to_start_level);
// smlua_misc_utils.h
smlua_bind_function(L, "add_scroll_target", smlua_func_add_scroll_target);
smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action);
smlua_bind_function(L, "camera_config_enable_analog_cam", smlua_func_camera_config_enable_analog_cam);
smlua_bind_function(L, "camera_config_enable_free_cam", smlua_func_camera_config_enable_free_cam);
@ -19484,6 +19521,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "hud_render_power_meter", smlua_func_hud_render_power_meter);
smlua_bind_function(L, "hud_set_value", smlua_func_hud_set_value);
smlua_bind_function(L, "hud_show", smlua_func_hud_show);
smlua_bind_function(L, "init_scroll_targets", smlua_func_init_scroll_targets);
smlua_bind_function(L, "is_game_paused", smlua_func_is_game_paused);
smlua_bind_function(L, "is_transition_playing", smlua_func_is_transition_playing);
smlua_bind_function(L, "movtexqc_register", smlua_func_movtexqc_register);

View file

@ -353,3 +353,13 @@ void set_override_near(f32 near) {
void set_override_far(f32 far) {
gOverrideFar = far;
}
///
void add_scroll_target(u32 index, const char* name, u32 offset, u32 size) {
dynos_add_scroll_target(index, name, offset, size);
}
void init_scroll_targets(void) {
dynos_init_scroll_targets();
}

View file

@ -83,6 +83,9 @@ void set_override_fov(f32 fov);
void set_override_near(f32 near);
void set_override_far(f32 far);
void add_scroll_target(u32 index, const char* name, u32 offset, u32 size);
void init_scroll_targets(void);
void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue);
#endif