mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-20 15:02:28 +00:00
use a hmap for scroll targets
This commit is contained in:
parent
c0691d4b3e
commit
c65a67ccf1
4 changed files with 15 additions and 44 deletions
|
|
@ -124,7 +124,7 @@ void DynOS_Add_Scroll_Target(u32 index, const char* name, u32 offset, u32 size)
|
||||||
add_vtx_scroll_target(
|
add_vtx_scroll_target(
|
||||||
index,
|
index,
|
||||||
offset > 0 ? &node->mData[offset] : node->mData,
|
offset > 0 ? &node->mData[offset] : node->mData,
|
||||||
size > 0 ? size : node->mSize,
|
(size > 0 && size < node->mSize) ? size : node->mSize,
|
||||||
offset > 0
|
offset > 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#include "scroll_targets.h"
|
#include "scroll_targets.h"
|
||||||
#include "pc/lua/utils/smlua_math_utils.h"
|
#include "pc/lua/utils/smlua_math_utils.h"
|
||||||
|
#include "data/dynos_cmap.cpp.h"
|
||||||
|
|
||||||
static struct ScrollTarget *sScrollTargets = NULL;
|
static void *sScrollTargets = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the scroll targets identified by the given id
|
* Gets the scroll targets identified by the given id
|
||||||
|
|
@ -9,15 +10,7 @@ static struct ScrollTarget *sScrollTargets = NULL;
|
||||||
* Returns NULL if not found.
|
* Returns NULL if not found.
|
||||||
*/
|
*/
|
||||||
struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset) {
|
struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset) {
|
||||||
struct ScrollTarget *scroll = sScrollTargets;
|
struct ScrollTarget *scroll = hmap_get(sScrollTargets, id);
|
||||||
|
|
||||||
while (scroll) {
|
|
||||||
if (scroll->id == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
scroll = scroll->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scroll) {
|
if (scroll) {
|
||||||
|
|
||||||
// If we need to, realloc the block of vertices
|
// If we need to, realloc the block of vertices
|
||||||
|
|
@ -50,16 +43,12 @@ struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset) {
|
||||||
* isn't any scroll targets.
|
* isn't any scroll targets.
|
||||||
*/
|
*/
|
||||||
struct ScrollTarget* find_or_create_scroll_targets(u32 id, bool hasOffset) {
|
struct ScrollTarget* find_or_create_scroll_targets(u32 id, bool hasOffset) {
|
||||||
struct ScrollTarget *scroll = sScrollTargets;
|
struct ScrollTarget *scroll = NULL;
|
||||||
struct ScrollTarget *lastScroll = NULL;
|
|
||||||
|
|
||||||
while (scroll) {
|
if (sScrollTargets == NULL) {
|
||||||
if (scroll->id == id) {
|
sScrollTargets = hmap_create(true);
|
||||||
break;
|
} else {
|
||||||
}
|
scroll = hmap_get(sScrollTargets, id);
|
||||||
|
|
||||||
lastScroll = scroll;
|
|
||||||
scroll = scroll->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scroll == NULL) {
|
if (scroll == NULL) {
|
||||||
|
|
@ -67,13 +56,8 @@ struct ScrollTarget* find_or_create_scroll_targets(u32 id, bool hasOffset) {
|
||||||
scroll->id = id;
|
scroll->id = id;
|
||||||
scroll->size = 0;
|
scroll->size = 0;
|
||||||
scroll->vertices = NULL;
|
scroll->vertices = NULL;
|
||||||
scroll->next = NULL;
|
|
||||||
scroll->hasOffset = hasOffset;
|
scroll->hasOffset = hasOffset;
|
||||||
if (lastScroll) {
|
hmap_put(sScrollTargets, id, scroll);
|
||||||
lastScroll->next = scroll;
|
|
||||||
} else {
|
|
||||||
sScrollTargets = scroll;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scroll;
|
return scroll;
|
||||||
|
|
@ -114,29 +98,21 @@ void add_vtx_scroll_target(u32 id, Vtx *vtx, u32 size, bool hasOffset) {
|
||||||
* add_vtx_scroll_targets(id, vtx, size)
|
* add_vtx_scroll_targets(id, vtx, size)
|
||||||
*/
|
*/
|
||||||
void free_vtx_scroll_targets(void) {
|
void free_vtx_scroll_targets(void) {
|
||||||
struct ScrollTarget* scroll = sScrollTargets;
|
for (struct ScrollTarget* scroll = hmap_begin(sScrollTargets); scroll != NULL; scroll = hmap_next(sScrollTargets)) {
|
||||||
struct ScrollTarget* nextScroll;
|
|
||||||
|
|
||||||
while (scroll) {
|
|
||||||
nextScroll = scroll->next;
|
|
||||||
free(scroll->interpF32);
|
free(scroll->interpF32);
|
||||||
free(scroll->prevF32);
|
free(scroll->prevF32);
|
||||||
free(scroll->interpS16);
|
free(scroll->interpS16);
|
||||||
free(scroll->prevS16);
|
free(scroll->prevS16);
|
||||||
free(scroll->vertices);
|
free(scroll->vertices);
|
||||||
free(scroll);
|
free(scroll);
|
||||||
scroll = nextScroll;
|
|
||||||
}
|
}
|
||||||
|
hmap_destroy(sScrollTargets);
|
||||||
sScrollTargets = NULL;
|
sScrollTargets = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void patch_scroll_targets_before(void) {
|
void patch_scroll_targets_before(void) {
|
||||||
struct ScrollTarget *scroll = sScrollTargets;
|
for (struct ScrollTarget* scroll = hmap_begin(sScrollTargets); scroll != NULL; scroll = hmap_next(sScrollTargets)) {
|
||||||
|
|
||||||
while (scroll) {
|
|
||||||
scroll->needInterp = false;
|
scroll->needInterp = false;
|
||||||
scroll = scroll->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,9 +120,8 @@ void patch_scroll_targets_before(void) {
|
||||||
|
|
||||||
void patch_scroll_targets_interpolated(f32 delta) {
|
void patch_scroll_targets_interpolated(f32 delta) {
|
||||||
f32 antiDelta = 1.0f - delta;
|
f32 antiDelta = 1.0f - delta;
|
||||||
struct ScrollTarget *scroll = sScrollTargets;
|
|
||||||
|
|
||||||
while (scroll) {
|
for (struct ScrollTarget* scroll = hmap_begin(sScrollTargets); scroll != NULL; scroll = hmap_next(sScrollTargets)) {
|
||||||
if (scroll->needInterp) {
|
if (scroll->needInterp) {
|
||||||
Vtx* *verts = scroll->vertices;
|
Vtx* *verts = scroll->vertices;
|
||||||
if (scroll->bhv < SCROLL_UV_X) {
|
if (scroll->bhv < SCROLL_UV_X) {
|
||||||
|
|
@ -161,7 +136,5 @@ void patch_scroll_targets_interpolated(f32 delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scroll = scroll->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ struct ScrollTarget {
|
||||||
s16 *interpS16;
|
s16 *interpS16;
|
||||||
s16 *prevS16;
|
s16 *prevS16;
|
||||||
u16 bhv;
|
u16 bhv;
|
||||||
|
|
||||||
struct ScrollTarget *next;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset);
|
struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset);
|
||||||
|
|
|
||||||
|
|
@ -696,6 +696,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
|
||||||
gOverrideAllowToxicGasCamera = FALSE;
|
gOverrideAllowToxicGasCamera = FALSE;
|
||||||
gRomhackCameraAllowDpad = FALSE;
|
gRomhackCameraAllowDpad = FALSE;
|
||||||
camera_reset_overrides();
|
camera_reset_overrides();
|
||||||
|
free_vtx_scroll_targets();
|
||||||
dynos_mod_shutdown();
|
dynos_mod_shutdown();
|
||||||
mods_clear(&gActiveMods);
|
mods_clear(&gActiveMods);
|
||||||
mods_clear(&gRemoteMods);
|
mods_clear(&gRemoteMods);
|
||||||
|
|
@ -704,7 +705,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
|
||||||
gChangeLevel = LEVEL_CASTLE_GROUNDS;
|
gChangeLevel = LEVEL_CASTLE_GROUNDS;
|
||||||
network_player_init();
|
network_player_init();
|
||||||
camera_set_use_course_specific_settings(true);
|
camera_set_use_course_specific_settings(true);
|
||||||
free_vtx_scroll_targets();
|
|
||||||
gMarioStates[0].cap = 0;
|
gMarioStates[0].cap = 0;
|
||||||
gMarioStates[0].input = 0;
|
gMarioStates[0].input = 0;
|
||||||
extern s16 gTTCSpeedSetting;
|
extern s16 gTTCSpeedSetting;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue