Skip to content

Commit cfddadc

Browse files
authored
Merge pull request HarbourMasters#152 from HarbourMasters/develop-rando
[Rando] Implement Randomizer Framework
2 parents 7f76a34 + edc0191 commit cfddadc

100 files changed

Lines changed: 5855 additions & 645 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/behavior_data.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include "types.h"
55

6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
610
extern const BehaviorScript bhvStarDoor[];
711
extern const BehaviorScript bhvMrI[];
812
extern const BehaviorScript bhvMrIBody[];
@@ -543,4 +547,8 @@ extern const BehaviorScript bhvEndBirds2[];
543547
extern const BehaviorScript bhvIntroScene[];
544548
extern const BehaviorScript bhvUnusedFakeStar[];
545549

550+
#ifdef __cplusplus
551+
}
552+
#endif
553+
546554
#endif // BEHAVIOR_DATA_H

include/macro_presets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct MacroPreset {
1111
/*0x06*/ s16 param;
1212
};
1313

14-
struct MacroPreset MacroObjectPresets[] = {
14+
static struct MacroPreset MacroObjectPresets[] = {
1515
{bhvYellowCoin, MODEL_YELLOW_COIN, 0},
1616
{bhvOneCoin, MODEL_YELLOW_COIN, 0},
1717
{bhvMovingBlueCoin, MODEL_BLUE_COIN, 0},

include/sm64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <PR/gu.h>
77
#include <PR/ucode.h>
88
#include "port/Engine.h"
9+
#include "port/hooks/Events.h"
910
#include <libultra/os.h>
1011
#include "variables.h"
1112

include/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ struct Object {
208208
/*0x218*/ void *collisionData;
209209
/*0x21C*/ Mat4 transform;
210210
/*0x25C*/ void *respawnInfo;
211+
/*0x260*/ u32 modelId;
212+
/*0x264*/ bool custom;
211213
};
212214

213215
struct ObjectHitbox {

src/audio/synthesis.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
681681
if (IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
682682
#endif
683683
gAudioErrorFlags = (note->bankId << 8) + noteIndex + 0x1000000;
684-
} else if (note->enabled == TRUE) {
684+
} else if (note->enabled == TRUE && note->synthesisBuffers != NULL) {
685685
#else
686686
if (note->noteSubEu.enabled == FALSE) {
687687
return cmd;
@@ -1196,14 +1196,16 @@ u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthes
11961196
u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) {
11971197
s32 a3;
11981198
s32 i;
1199-
aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0,
1199+
if (note->synthesisBuffers != NULL) {
1200+
aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0,
12001201
/*count*/ sizeof(note->synthesisBuffers->samples));
1201-
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples));
1202-
note->samplePosInt &= (note->sampleCount - 1);
1203-
a3 = 64 - note->samplePosInt;
1204-
if (a3 < nSamplesToLoad) {
1205-
for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) {
1206-
aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), /*count*/ sizeof(note->synthesisBuffers->samples));
1202+
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples));
1203+
note->samplePosInt &= (note->sampleCount - 1);
1204+
a3 = 64 - note->samplePosInt;
1205+
if (a3 < nSamplesToLoad) {
1206+
for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) {
1207+
aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), /*count*/ sizeof(note->synthesisBuffers->samples));
1208+
}
12071209
}
12081210
}
12091211
return cmd;

src/engine/behavior_script.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <libultraship.h>
2+
#include "port/hooks/list/PlayerEvent.h"
23

34
#include "sm64.h"
45
#include "behavior_data.h"
@@ -984,20 +985,26 @@ void cur_obj_update(void) {
984985
}
985986

986987
// Handle visibility of object
987-
if (gCurrentObject->oRoom != -1) {
988-
// If the object is in a room, only show it when Mario is in the room.
989-
cur_obj_enable_rendering_if_mario_in_room();
990-
} else if ((objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) && gCurrentObject->collisionData == NULL) {
991-
if (!(objFlags & OBJ_FLAG_ACTIVE_FROM_AFAR)) {
992-
// If the object has a render distance, check if it should be shown.
993-
if (distanceFromMario > gCurrentObject->oDrawingDistance) {
994-
// Out of render distance, hide the object.
995-
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
996-
gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY;
997-
} else if (gCurrentObject->oHeldState == HELD_FREE) {
998-
// In render distance (and not being held), show the object.
999-
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
1000-
gCurrentObject->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY;
988+
CALL_CANCELLABLE_EVENT(ModifyObjectVisibility, &gCurrentObject) {
989+
if (gCurrentObject->oRoom != -1) {
990+
// If the object is in a room, only show it when Mario is in the room.
991+
cur_obj_enable_rendering_if_mario_in_room();
992+
} else if ((objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) && gCurrentObject->collisionData == NULL) {
993+
if (!(objFlags & OBJ_FLAG_ACTIVE_FROM_AFAR)) {
994+
bool visible = distanceFromMario <= gCurrentObject->oDrawingDistance;
995+
996+
CALL_CANCELLABLE_EVENT(EntityDistanceRender, &visible) {
997+
// If the object has a render distance, check if it should be shown.
998+
if (!visible) {
999+
// Out of render distance, hide the object.
1000+
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
1001+
gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY;
1002+
} else if (gCurrentObject->oHeldState == HELD_FREE) {
1003+
// In render distance (and not being held), show the object.
1004+
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
1005+
gCurrentObject->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY;
1006+
}
1007+
}
10011008
}
10021009
}
10031010
}

src/engine/graph_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define GRAPH_RENDER_Z_BUFFER (1 << 3)
2121
#define GRAPH_RENDER_INVISIBLE (1 << 4)
2222
#define GRAPH_RENDER_HAS_ANIMATION (1 << 5)
23+
#define GRAPH_RENDER_DRAW_DEBUG (1 << 6)
2324

2425
// Whether the node type has a function pointer of type GraphNodeFunc
2526
#define GRAPH_NODE_TYPE_FUNCTIONAL 0x100

src/engine/level_script.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <libultraship.h>
22
#include <string.h>
3+
#include "port/hooks/list/PlayerEvent.h"
34

45
#include "sm64.h"
56
#include "audio/external.h"
@@ -443,6 +444,7 @@ static void level_cmd_place_object(void) {
443444

444445
if (sCurrAreaIndex != -1 && ((CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) {
445446
model = CMD_GET(u8, 3);
447+
446448
spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo));
447449

448450
spawnInfo->startPos[0] = CMD_GET(s16, 4);
@@ -457,11 +459,17 @@ static void level_cmd_place_object(void) {
457459
spawnInfo->activeAreaIndex = sCurrAreaIndex;
458460

459461
spawnInfo->behaviorArg = CMD_GET(u32, 16);
460-
spawnInfo->behaviorScript = CMD_GET(void *, 20);
462+
spawnInfo->behaviorScript = CMD_GET(void*, 20);
463+
461464
spawnInfo->model = gLoadedGraphNodes[model];
465+
spawnInfo->modelId = model;
466+
462467
spawnInfo->next = gAreas[sCurrAreaIndex].objectSpawnInfos;
463468

464-
gAreas[sCurrAreaIndex].objectSpawnInfos = spawnInfo;
469+
CALL_CANCELLABLE_EVENT(SpawnStar, &model, spawnInfo->startPos[0], spawnInfo->startPos[1],
470+
spawnInfo->startPos[2]) {
471+
gAreas[sCurrAreaIndex].objectSpawnInfos = spawnInfo;
472+
}
465473
}
466474

467475
sCurrentCmd = CMD_NEXT;
@@ -821,6 +829,7 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
821829

822830
while (sScriptStatus == SCRIPT_RUNNING) {
823831
LevelScriptJumpTable[sCurrentCmd->type]();
832+
CALL_EVENT(LevelScriptExecute, sCurrentCmd->type);
824833
}
825834

826835
profiler_log_thread5_time(LEVEL_SCRIPT_EXECUTE);
@@ -831,3 +840,12 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
831840

832841
return sCurrentCmd;
833842
}
843+
844+
// TODO: Move these elsewhere
845+
s16 get_current_area_index(void) {
846+
return sCurrAreaIndex;
847+
}
848+
849+
struct AllocOnlyPool* get_level_pool(void) {
850+
return sLevelPool;
851+
}

src/engine/surface_load.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,13 @@ void load_object_collision_model(void) {
789789
}
790790
}
791791

792-
if (marioDist < gCurrentObject->oDrawingDistance) {
793-
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
794-
} else {
795-
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
796-
}
792+
bool visible = (marioDist < gCurrentObject->oDrawingDistance);
793+
794+
CALL_CANCELLABLE_EVENT(EntityDistanceLoad, &visible) {
795+
if (visible) {
796+
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
797+
} else {
798+
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
799+
}
800+
};
797801
}

0 commit comments

Comments
 (0)