Skip to content

Commit

Permalink
CFG file comments + config for mario in mocap scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
headshot2017 committed Oct 30, 2024
1 parent a146945 commit a11feb3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void audio_thread_init()
{
if (audio_started) return;

if (config["use_wasapi_audio"])
if (getConfig("use_wasapi_audio"))
audio_api = new AudioAPI_WASAPI();
else
audio_api = new AudioAPI_SDL2();
Expand Down
24 changes: 17 additions & 7 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
#include <fstream>
#include <algorithm>

std::unordered_map<std::string, int> config = {
{"skip_sha1_checksum", 0},
{"use_wasapi_audio", 0},
{"autospawn_mario_on_start", 0},
std::unordered_map<std::string, ConfigElement> config = {
{"skip_sha1_checksum", {"Skips the ROM SHA-1 checksum. This allows using certain ROM hacks such as sound ROM hacks", 0}},
{"use_wasapi_audio", {"Prefer WASAPI audio backend over SDL2. Only works on Windows Vista and later.", 0}},
{"autospawn_mario_on_start", {"When loading a game, automatically spawn Mario.", 0}},
{"mario_in_mocap_cutscenes", {"Replaces CJ with Mario in the 'motion-capture' cutscenes. NOTE: This feature is not finished!", 0}},
};


int getConfig(std::string value)
{
return config.count(value) ? config[value].value : 0;
}

void saveConfig()
{
std::ofstream configfile(CONFIG_FILENAME);
for (const std::pair<std::string, int>& mapkey : config)
configfile << mapkey.first << ": " << mapkey.second << "\n";
for (auto& mapkey : config)
{
configfile << "# " << mapkey.second.desc << "\n";
configfile << mapkey.first << ": " << mapkey.second.value << "\n\n";
}

std::cout << "sm64-san-andreas.cfg saved\n";
}
Expand Down Expand Up @@ -51,7 +61,7 @@ void loadConfig()

try
{
config[key] = std::stoi(value);
config[key].value = std::stoi(value);
totalCfg++;
}
catch(...)
Expand Down
9 changes: 8 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
#include <string>
#include <unordered_map>

extern std::unordered_map<std::string, int> config;
struct ConfigElement
{
const std::string desc;
int value;
};

extern std::unordered_map<std::string, ConfigElement> config;

int getConfig(std::string value);
void saveConfig();
void loadConfig();

Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class sm64_san_andreas {
file.read((char*)romBuffer, romFileLength);
romBuffer[romFileLength] = 0;

if (!config["skip_sha1_checksum"])
if (!getConfig("skip_sha1_checksum"))
{
// check ROM SHA1 to avoid crash
sha1::SHA1 s;
Expand Down Expand Up @@ -128,7 +128,7 @@ class sm64_san_andreas {
if (!loaded) return;
if (marioSpawned()) marioDestroy();

if (config["autospawn_mario_on_start"]) marioSpawn();
if (getConfig("autospawn_mario_on_start")) marioSpawn();
}

static void destroy()
Expand Down
29 changes: 17 additions & 12 deletions mario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {

#include "d3d9_funcs.h"
#include "main.h"
#include "config.h"
#include "mario_render.h"
#include "mario_custom_anims.h"
#include "mario_ped_tasks.h"
Expand Down Expand Up @@ -866,20 +867,24 @@ void marioTick(float dt)
lastCutsceneRunning = true;
marioSetPos(ped->GetPosition());
}
/*
if (marioState.action != ACT_CUTSCENE)

if (getConfig("mario_in_mocap_cutscenes"))
{
sm64_set_mario_action(marioId, ACT_CUTSCENE);
sm64_set_mario_animation(marioId, MARIO_ANIM_CUSTOM_CUTSCENE);
}
// Implementation of Mario in motion-capture cutscenes
if (marioState.action != ACT_CUTSCENE)
{
sm64_set_mario_action(marioId, ACT_CUTSCENE);
sm64_set_mario_animation(marioId, MARIO_ANIM_CUSTOM_CUTSCENE);
}

ped->m_nPedFlags.bDontRender = 0;
ped->m_bIsVisible = 1;
ped->m_nPedFlags.bDontRender = 0;
ped->m_bIsVisible = 1;

for (uint32_t i=0; i<CCutsceneMgr::ms_numCutsceneObjs; i++)
{
if (CCutsceneMgr::ms_pCutsceneObjects[i]->m_nModelIndex == 1) // CJ
for (uint32_t i=0; i<CCutsceneMgr::ms_numCutsceneObjs; i++)
{
if (CCutsceneMgr::ms_pCutsceneObjects[i]->m_nModelIndex != 1)
continue;

float orX, orY, orZ;
auto getAngle = [](RwMatrix* m, float& orX, float& orY, float& orZ){
orX = asinf(m->up.z);
Expand Down Expand Up @@ -907,7 +912,7 @@ void marioTick(float dt)
sm64_set_mario_headangle(marioId, -neck->up.z, neck->at.z, -orY + M_PI_2);


/*
RwMatrix* lshoulder = &RpHAnimHierarchyGetMatrixArray(hier)[RpHAnimIDGetIndex(hier, BONE_LEFTSHOULDER)];
ConvertToEulerAngles(lshoulder, &orX, &orY, &orZ, EULER_ANGLES);
float lshoulderX = orX - M_PI;
Expand Down Expand Up @@ -1053,11 +1058,11 @@ void marioTick(float dt)
while (relbowZ < -M_PI) relbowZ += M_PI*2;
while (relbowZ > M_PI) relbowZ -= M_PI*2;
//sm64_set_mario_rightarm_angle(marioId, relbowX, relbowY, relbowZ);
*/

break;
}
}
*/
}
else if (!CCutsceneMgr::ms_running && lastCutsceneRunning)
{
Expand Down

0 comments on commit a11feb3

Please sign in to comment.