add locations

This commit is contained in:
Dominicentek 2023-08-25 16:55:40 +02:00
parent 95e9203dc7
commit b3b5ba603a
9 changed files with 282 additions and 46 deletions

View file

@ -287,13 +287,13 @@ static void *DynOS_Warp_UpdateWarp(void *aCmd, bool aIsLevelInitDone) {
gMarioSpawnInfo->startAngle[1] = _LevelEntryWarp[6];
gMarioSpawnInfo->startAngle[2] = 0;
gMarioSpawnInfo->areaIndex = gCurrAreaIndex;
if (!dynos_override_mario_and_camera) init_mario();
if (!dynos_override_mario) init_mario();
set_mario_initial_action(gMarioState, sDynosWarpSpawnType, 0);
DynOS_Warp_SetParam(gCurrLevelNum, DynOS_Opt_GetValue("dynos_warp_param"));
// Init transition
if (!override_mario_and_camera) reset_camera(gCurrentArea->camera);
if (!override_mario_and_camera) init_camera(gCurrentArea->camera);
if (!override_mario) reset_camera(gCurrentArea->camera);
if (!override_mario) init_camera(gCurrentArea->camera);
sDelayedWarpOp = WARP_OP_NONE;
switch (sDynosWarpSpawnType) {
case MARIO_SPAWN_UNKNOWN_03: play_transition(WARP_TRANSITION_FADE_FROM_STAR, 0x10, 0x00, 0x00, 0x00); break;
@ -325,15 +325,11 @@ static void *DynOS_Warp_UpdateWarp(void *aCmd, bool aIsLevelInitDone) {
sDynosWarpAreaNum = -1;
sDynosWarpActNum = -1;
sDynosWarpNodeNum = -1;
if (dynos_override_mario_and_camera) {
dynos_override_mario_and_camera = 0;
if (dynos_override_mario) {
dynos_override_mario = 0;
vec3f_copy(gMarioState->pos, overriden_mario_pos);
gMarioState->faceAngle[1] = overriden_mario_angle;
if (override_mario_and_camera) {
*gCamera = overriden_camera_struct;
gLakituState = overriden_lakitu_struct;
}
override_mario_and_camera--;
override_mario--;
}
}

BIN
dynos/locations.bin Normal file

Binary file not shown.

View file

@ -175,12 +175,10 @@ s16 unusedEULevelUpdateBss1;
s8 sTimerRunning;
s8 gShouldNotPlayCastleMusic;
u8 override_mario_and_camera;
u8 dynos_override_mario_and_camera;
u8 override_mario;
u8 dynos_override_mario;
s16 overriden_mario_angle;
Vec3f overriden_mario_pos;
struct Camera overriden_camera_struct;
struct LakituState overriden_lakitu_struct;
struct MarioState *gMarioState = &gMarioStates[0];
u8 unused1[4] = { 0 };
@ -401,14 +399,14 @@ void init_mario_after_warp(void) {
}
init_mario();
if (!override_mario_and_camera && !dynos_override_mario_and_camera) set_mario_initial_action(gMarioState, marioSpawnType, sWarpDest.arg);
if (!override_mario && !dynos_override_mario) set_mario_initial_action(gMarioState, marioSpawnType, sWarpDest.arg);
gMarioState->interactObj = spawnNode->object;
gMarioState->usedObj = spawnNode->object;
}
if (gCurrentArea) {
if (!override_mario_and_camera) reset_camera(gCurrentArea->camera);
if (!override_mario) reset_camera(gCurrentArea->camera);
}
sWarpDest.type = WARP_TYPE_NOT_WARPING;
sDelayedWarpOp = WARP_OP_NONE;
@ -548,8 +546,8 @@ void check_instant_warp(void) {
s16 cameraAngle;
struct Surface *floor;
if ((gCurrLevelNum == LEVEL_CASTLE
&& save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 70) || configUnlockDoors) {
if (gCurrLevelNum == LEVEL_CASTLE
&& (save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 70 || configUnlockDoors)) {
return;
}
@ -1022,14 +1020,10 @@ s32 play_mode_normal(void) {
}
// Override Mario if loaded from project file
if (override_mario_and_camera) {
override_mario_and_camera--;
if (override_mario) {
override_mario--;
vec3f_copy(gMarioState->pos, overriden_mario_pos);
gMarioState->faceAngle[1] = overriden_mario_angle;
if (override_mario_and_camera) {
*gCamera = overriden_camera_struct;
gLakituState = overriden_lakitu_struct;
}
}
return 0;
@ -1219,7 +1213,7 @@ s32 init_level(void) {
}
if (gCurrentArea != NULL) {
if (!override_mario_and_camera) reset_camera(gCurrentArea->camera);
if (!override_mario) reset_camera(gCurrentArea->camera);
if (gCurrDemoInput != NULL) {
set_mario_action(gMarioState, ACT_IDLE, 0);

View file

@ -102,12 +102,10 @@ struct HudDisplay {
extern struct HudDisplay gHudDisplay;
extern s8 gShouldNotPlayCastleMusic;
extern u8 override_mario_and_camera;
extern u8 dynos_override_mario_and_camera;
extern u8 override_mario;
extern u8 dynos_override_mario;
extern s16 overriden_mario_angle;
extern Vec3f overriden_mario_pos;
extern struct Camera overriden_camera_struct;
extern struct LakituState overriden_lakitu_struct;
enum HUDDisplayFlag {
HUD_DISPLAY_FLAG_LIVES = 0x0001,

View file

@ -0,0 +1,79 @@
#include "saturn_format.h"
#include <string>
#include <map>
#include <utility>
extern "C" {
#include "include/types.h"
#include "game/area.h"
#include "game/level_update.h"
}
std::map<int, std::map<std::string, std::pair<s16, std::array<float, 3>>>> locations = {};
void saturn_add_location_internal(int level, float x, float y, float z, s16 angle, char* name) {
if (locations.find(level) == locations.end()) {
std::map<std::string, std::pair<s16, std::array<float, 3>>> levelLocations;
levelLocations.insert({ std::string(name), { angle, { x, y, z } } });
locations.insert({ level, levelLocations });
}
else {
std::string locationName = std::string(name);
if (locations[level].find(name) == locations[level].end()) locations[level].insert({ locationName, { angle, { x, y, z } } });
else {
locations[level][locationName].first = angle;
locations[level][locationName].second[0] = x;
locations[level][locationName].second[1] = y;
locations[level][locationName].second[2] = z;
}
}
}
void saturn_location_data_handler(SaturnFormatStream* stream, int version) {
int count = saturn_format_read_int32(stream);
for (int i = 0; i < count; i++) {
int level = saturn_format_read_int16(stream);
s16 angle = saturn_format_read_int16(stream);
float x = saturn_format_read_float(stream);
float y = saturn_format_read_float(stream);
float z = saturn_format_read_float(stream);
char name[257];
saturn_format_read_string(stream, name);
name[256] = 0;
saturn_add_location_internal(level, x, y, z, angle, name);
}
}
void saturn_load_locations() {
saturn_format_input("dynos/locations.bin", "STLC", {
{ "DATA", saturn_location_data_handler }
});
}
void saturn_save_locations() {
SaturnFormatStream stream = saturn_format_output("STLC", 1);
saturn_format_new_section(&stream, "DATA");
int count = 0;
for (auto& levelEntry : locations) {
for (auto& locationEntry : levelEntry.second) {
count++;
}
}
saturn_format_write_int32(&stream, count);
for (auto& levelEntry : locations) {
for (auto& locationEntry : levelEntry.second) {
saturn_format_write_int16(&stream, levelEntry.first);
saturn_format_write_int16(&stream, locationEntry.second.first);
saturn_format_write_float(&stream, locationEntry.second.second[0]);
saturn_format_write_float(&stream, locationEntry.second.second[1]);
saturn_format_write_float(&stream, locationEntry.second.second[2]);
saturn_format_write_string(&stream, (char*)locationEntry.first.c_str());
}
}
saturn_format_close_section(&stream);
saturn_format_write("dynos/locations.bin", &stream);
}
std::map<std::string, std::pair<s16, std::array<float, 3>>>* saturn_get_locations() {
int level = (gCurrLevelNum << 8) | gCurrAreaIndex;
return &locations[level];
}
void saturn_add_location(char* name) {
saturn_add_location_internal((gCurrLevelNum << 8) | gCurrAreaIndex, gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], gMarioState->faceAngle[1], name);
}

View file

@ -0,0 +1,16 @@
#ifndef SaturnLocationFile
#define SaturnLocationFile
#include <string>
#include <map>
#include <utility>
extern "C" {
#include "include/types.h"
}
void saturn_load_locations();
void saturn_save_locations();
std::map<std::string, std::pair<s16, std::array<float, 3>>>* saturn_get_locations();
void saturn_add_location(char* name);
#endif

View file

@ -111,20 +111,16 @@ void saturn_project_game_handler(SaturnFormatStream* stream, int version) {
u8 level = saturn_format_read_int8(stream);
spin_mult = saturn_format_read_float(stream);
if (version == 1) {
overriden_camera_struct = *gCamera;
overriden_lakitu_struct = gLakituState;
gCamera->pos[0] = saturn_format_read_float(stream);
gCamera->pos[1] = saturn_format_read_float(stream);
gCamera->pos[2] = saturn_format_read_float(stream);
float yaw = saturn_format_read_float(stream);
float pitch = saturn_format_read_float(stream);
vec3f_set_dist_and_angle(gCamera->pos, gCamera->focus, 100, (s16)pitch, (s16)yaw);
vec3f_copy(overriden_camera_struct.pos, gCamera->pos);
vec3f_copy(overriden_camera_struct.focus, gCamera->focus);
vec3f_copy(overriden_lakitu_struct.goalPos, gCamera->pos);
vec3f_copy(overriden_lakitu_struct.goalFocus, gCamera->focus);
vec3f_copy(overriden_lakitu_struct.pos, gCamera->pos);
vec3f_copy(overriden_lakitu_struct.focus, gCamera->focus);
vec3f_copy(gLakituState.goalPos, gCamera->pos);
vec3f_copy(gLakituState.goalFocus, gCamera->focus);
vec3f_copy(gLakituState.pos, gCamera->pos);
vec3f_copy(gLakituState.focus, gCamera->focus);
}
camVelSpeed = saturn_format_read_float(stream);
camVelRSpeed = saturn_format_read_float(stream);
@ -160,10 +156,10 @@ void saturn_project_game_handler(SaturnFormatStream* stream, int version) {
}
k_previous_frame = -1;
u8 lvlID = (level >> 2) & 63;
if (lvlID != get_saturn_level_id(gCurrLevelNum) || (level & 3) != gCurrAreaIndex) {
warp_to_level(lvlID, level & 3, act);
if (lvlID == 0) dynos_override_mario_and_camera = 1;
override_mario_and_camera = 3; // We override for 3 frames otherwise it breaks :/
if (lvlID != get_saturn_level_id(gCurrLevelNum) || (level & 3) != gCurrAreaIndex - 1) {
warp_to_level(lvlID, (level & 3) + 1, act);
if (lvlID == 0) dynos_override_mario = 1;
override_mario = 3; // We override for 3 frames otherwise it breaks :/
}
}
@ -212,8 +208,67 @@ void saturn_project_keyframe_handler(SaturnFormatStream* stream, int version) {
}
void saturn_project_camera_handler(SaturnFormatStream* stream, int version) {
saturn_format_read_any(stream, &overriden_camera_struct, sizeof(struct Camera));
saturn_format_read_any(stream, &overriden_lakitu_struct, sizeof(struct LakituState));
gCamera->areaCenX = saturn_format_read_int32(stream);
gCamera->areaCenY = saturn_format_read_int32(stream);
gCamera->areaCenZ = saturn_format_read_int32(stream);
gCamera->cutscene = saturn_format_read_int8(stream);
gCamera->defMode = saturn_format_read_int8(stream);
gCamera->doorStatus = saturn_format_read_int8(stream);
gCamera->focus[0] = saturn_format_read_float(stream);
gCamera->focus[1] = saturn_format_read_float(stream);
gCamera->focus[2] = saturn_format_read_float(stream);
gCamera->mode = saturn_format_read_int8(stream);
gCamera->nextYaw = saturn_format_read_int16(stream);
gCamera->pos[0] = saturn_format_read_float(stream);
gCamera->pos[1] = saturn_format_read_float(stream);
gCamera->pos[2] = saturn_format_read_float(stream);
gCamera->yaw = saturn_format_read_int16(stream);
gLakituState.curFocus[0] = saturn_format_read_float(stream);
gLakituState.curFocus[1] = saturn_format_read_float(stream);
gLakituState.curFocus[2] = saturn_format_read_float(stream);
gLakituState.curPos[0] = saturn_format_read_float(stream);
gLakituState.curPos[1] = saturn_format_read_float(stream);
gLakituState.curPos[2] = saturn_format_read_float(stream);
gLakituState.defMode = saturn_format_read_int8(stream);
gLakituState.focHSpeed = saturn_format_read_float(stream);
gLakituState.focus[0] = saturn_format_read_float(stream);
gLakituState.focus[1] = saturn_format_read_float(stream);
gLakituState.focus[2] = saturn_format_read_float(stream);
gLakituState.focusDistance = saturn_format_read_float(stream);
gLakituState.focVSpeed = saturn_format_read_float(stream);
gLakituState.goalFocus[0] = saturn_format_read_float(stream);
gLakituState.goalFocus[1] = saturn_format_read_float(stream);
gLakituState.goalFocus[2] = saturn_format_read_float(stream);
gLakituState.goalPos[0] = saturn_format_read_float(stream);
gLakituState.goalPos[1] = saturn_format_read_float(stream);
gLakituState.goalPos[2] = saturn_format_read_float(stream);
gLakituState.keyDanceRoll = saturn_format_read_int16(stream);
gLakituState.lastFrameAction = saturn_format_read_int32(stream);
gLakituState.mode = saturn_format_read_int8(stream);
gLakituState.nextYaw = saturn_format_read_int16(stream);
gLakituState.oldPitch = saturn_format_read_int16(stream);
gLakituState.oldRoll = saturn_format_read_int16(stream);
gLakituState.oldYaw = saturn_format_read_int16(stream);
gLakituState.pos[0] = saturn_format_read_float(stream);
gLakituState.pos[1] = saturn_format_read_float(stream);
gLakituState.pos[2] = saturn_format_read_float(stream);
gLakituState.posHSpeed = saturn_format_read_float(stream);
gLakituState.posVSpeed = saturn_format_read_float(stream);
gLakituState.roll = saturn_format_read_int16(stream);
gLakituState.shakeMagnitude[0] = saturn_format_read_int16(stream);
gLakituState.shakeMagnitude[1] = saturn_format_read_int16(stream);
gLakituState.shakeMagnitude[2] = saturn_format_read_int16(stream);
gLakituState.shakePitchDecay = saturn_format_read_int16(stream);
gLakituState.shakePitchPhase = saturn_format_read_int16(stream);
gLakituState.shakePitchVel = saturn_format_read_int16(stream);
gLakituState.shakeRollDecay = saturn_format_read_int16(stream);
gLakituState.shakeRollPhase = saturn_format_read_int16(stream);
gLakituState.shakeRollVel = saturn_format_read_int16(stream);
gLakituState.shakeYawDecay = saturn_format_read_int16(stream);
gLakituState.shakeYawPhase = saturn_format_read_int16(stream);
gLakituState.shakeYawVel = saturn_format_read_int16(stream);
gLakituState.skipCameraInterpolationTimestamp = saturn_format_read_int32(stream);
gLakituState.yaw = saturn_format_read_int16(stream);
}
void saturn_load_project(char* filename) {
@ -266,7 +321,7 @@ void saturn_save_project(char* filename) {
walkpoint |= (gLevelEnv & 1) << 7;
saturn_format_write_int16(&stream, flags);
saturn_format_write_int8(&stream, walkpoint);
saturn_format_write_int8(&stream, (get_saturn_level_id(gCurrLevelNum) << 2) | gCurrAreaIndex);
saturn_format_write_int8(&stream, (get_saturn_level_id(gCurrLevelNum) << 2) | (gCurrAreaIndex - 1));
saturn_format_write_float(&stream, spin_mult);
/* Version 1
saturn_format_write_float(&stream, gLakituState.pos[0]);
@ -307,8 +362,67 @@ void saturn_save_project(char* filename) {
saturn_format_write_int8(&stream, gCurrActNum);
saturn_format_close_section(&stream);
saturn_format_new_section(&stream, SATURN_PROJECT_CAMERA_IDENTIFIER);
saturn_format_write_any(&stream, gCamera, sizeof(*gCamera));
saturn_format_write_any(&stream, &gLakituState, sizeof(gLakituState));
saturn_format_write_float(&stream, gCamera->areaCenX);
saturn_format_write_float(&stream, gCamera->areaCenY);
saturn_format_write_float(&stream, gCamera->areaCenZ);
saturn_format_write_int8(&stream, gCamera->cutscene);
saturn_format_write_int8(&stream, gCamera->defMode);
saturn_format_write_int8(&stream, gCamera->doorStatus);
saturn_format_write_float(&stream, gCamera->focus[0]);
saturn_format_write_float(&stream, gCamera->focus[1]);
saturn_format_write_float(&stream, gCamera->focus[2]);
saturn_format_write_int8(&stream, gCamera->mode);
saturn_format_write_int16(&stream, gCamera->nextYaw);
saturn_format_write_float(&stream, gCamera->pos[0]);
saturn_format_write_float(&stream, gCamera->pos[1]);
saturn_format_write_float(&stream, gCamera->pos[2]);
saturn_format_write_int16(&stream, gCamera->yaw);
saturn_format_write_float(&stream, gLakituState.curFocus[0]);
saturn_format_write_float(&stream, gLakituState.curFocus[1]);
saturn_format_write_float(&stream, gLakituState.curFocus[2]);
saturn_format_write_float(&stream, gLakituState.curPos[0]);
saturn_format_write_float(&stream, gLakituState.curPos[1]);
saturn_format_write_float(&stream, gLakituState.curPos[2]);
saturn_format_write_int8(&stream, gLakituState.defMode);
saturn_format_write_float(&stream, gLakituState.focHSpeed);
saturn_format_write_float(&stream, gLakituState.focus[0]);
saturn_format_write_float(&stream, gLakituState.focus[1]);
saturn_format_write_float(&stream, gLakituState.focus[2]);
saturn_format_write_float(&stream, gLakituState.focusDistance);
saturn_format_write_float(&stream, gLakituState.focVSpeed);
saturn_format_write_float(&stream, gLakituState.goalFocus[0]);
saturn_format_write_float(&stream, gLakituState.goalFocus[1]);
saturn_format_write_float(&stream, gLakituState.goalFocus[2]);
saturn_format_write_float(&stream, gLakituState.goalPos[0]);
saturn_format_write_float(&stream, gLakituState.goalPos[1]);
saturn_format_write_float(&stream, gLakituState.goalPos[2]);
saturn_format_write_int16(&stream, gLakituState.keyDanceRoll);
saturn_format_write_int32(&stream, gLakituState.lastFrameAction);
saturn_format_write_int8(&stream, gLakituState.mode);
saturn_format_write_int16(&stream, gLakituState.nextYaw);
saturn_format_write_int16(&stream, gLakituState.oldPitch);
saturn_format_write_int16(&stream, gLakituState.oldRoll);
saturn_format_write_int16(&stream, gLakituState.oldYaw);
saturn_format_write_float(&stream, gLakituState.pos[0]);
saturn_format_write_float(&stream, gLakituState.pos[1]);
saturn_format_write_float(&stream, gLakituState.pos[2]);
saturn_format_write_float(&stream, gLakituState.posHSpeed);
saturn_format_write_float(&stream, gLakituState.posVSpeed);
saturn_format_write_int16(&stream, gLakituState.roll);
saturn_format_write_int16(&stream, gLakituState.shakeMagnitude[0]);
saturn_format_write_int16(&stream, gLakituState.shakeMagnitude[1]);
saturn_format_write_int16(&stream, gLakituState.shakeMagnitude[2]);
saturn_format_write_int16(&stream, gLakituState.shakePitchDecay);
saturn_format_write_int16(&stream, gLakituState.shakePitchPhase);
saturn_format_write_int16(&stream, gLakituState.shakePitchVel);
saturn_format_write_int16(&stream, gLakituState.shakeRollDecay);
saturn_format_write_int16(&stream, gLakituState.shakeRollPhase);
saturn_format_write_int16(&stream, gLakituState.shakeRollVel);
saturn_format_write_int16(&stream, gLakituState.shakeYawDecay);
saturn_format_write_int16(&stream, gLakituState.shakeYawPhase);
saturn_format_write_int16(&stream, gLakituState.shakeYawVel);
saturn_format_write_int32(&stream, gLakituState.skipCameraInterpolationTimestamp);
saturn_format_write_int16(&stream, gLakituState.yaw);
saturn_format_close_section(&stream);
for (auto& entry : k_frame_keys) {
saturn_format_new_section(&stream, SATURN_PROJECT_TIMELINE_IDENTIFIER);

View file

@ -16,6 +16,7 @@
#include "saturn/saturn_obj_def.h"
#include "saturn_imgui.h"
#include "saturn/imgui/saturn_imgui_chroma.h"
#include "saturn/filesystem/saturn_locationfile.h"
#include "pc/controller/controller_keyboard.h"
#include <SDL2/SDL.h>
@ -55,6 +56,9 @@ int obj_beh_params[4];
int obj_model;
int obj_beh;
int current_location_index = 0;
char location_name[256];
s16 levelList[] = {
LEVEL_SA, LEVEL_CASTLE_GROUNDS, LEVEL_CASTLE, LEVEL_CASTLE_COURTYARD, LEVEL_BOB,
LEVEL_WF, LEVEL_PSS, LEVEL_TOTWC, LEVEL_JRB, LEVEL_CCM,
@ -254,6 +258,39 @@ void imgui_machinima_quick_options() {
// Erase existing timelines
k_frame_keys.clear();
}
auto locations = saturn_get_locations();
bool do_save = false;
std::vector<std::string> forRemoval = {};
if (ImGui::BeginMenu("Locations")) {
for (auto& entry : *locations) {
if (ImGui::Button((std::string(ICON_FK_PLAY "###warp_to_location_") + entry.first).c_str())) {
gMarioState->pos[0] = entry.second.second[0];
gMarioState->pos[1] = entry.second.second[1];
gMarioState->pos[2] = entry.second.second[2];
gMarioState->faceAngle[1] = entry.second.first;
do_save = true;
}
ImGui::SameLine();
if (ImGui::Button((std::string(ICON_FK_TRASH "###delete_location_") + entry.first).c_str())) {
forRemoval.push_back(entry.first);
do_save = true;
}
ImGui::SameLine();
ImGui::Text(entry.first.c_str());
}
if (ImGui::Button(ICON_FK_PLUS "###add_location")) {
saturn_add_location(location_name);
do_save = true;
}
ImGui::SameLine();
ImGui::InputText("###location_input", location_name, 256);
ImGui::EndMenu();
}
for (std::string key : forRemoval) {
locations->erase(key);
}
if (do_save) saturn_save_locations();
}
if (mario_exists) {
ImGui::Separator();

View file

@ -13,6 +13,7 @@
#include "pc/configfile.h"
#include "saturn/filesystem/saturn_projectfile.h"
#include "saturn/imgui/saturn_imgui_dynos.h"
#include "saturn/filesystem/saturn_locationfile.h"
bool mario_exists;
@ -571,6 +572,7 @@ const char* saturn_get_stage_name(int courseNum) {
void saturn_do_load() {
saturn_imgui_init();
saturn_load_locations();
}
void saturn_on_splash_finish() {
splash_finished = true;