Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MarathonRecomp/api/Marathon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "CSD/Platform/csdTexList.h"
#include "Sonicteam/Actor.h"
#include "Sonicteam/AppMarathon.h"
#include "Sonicteam/AudioEngineXenon.h"
#include "Sonicteam/Camera/CameraMode.h"
#include "Sonicteam/Camera/Cameraman.h"
#include "Sonicteam/Camera/SonicCamera.h"
Expand Down Expand Up @@ -48,12 +49,15 @@
#include "Sonicteam/Player/State/Object2.h"
#include "Sonicteam/Player/State/TailsContext.h"
#include "Sonicteam/SoX/AI/StateMachine.h"
#include "Sonicteam/SoX/Audio/IAudioEngine.h"
#include "Sonicteam/SoX/Component.h"
#include "Sonicteam/SoX/Engine/Doc.h"
#include "Sonicteam/SoX/Engine/DocMode.h"
#include "Sonicteam/SoX/Engine/Task.h"
#include "Sonicteam/SoX/MessageReceiver.h"
#include "Sonicteam/SoX/Object.h"
#include "Sonicteam/System/CreateStatic.h"
#include "Sonicteam/System/Singleton.h"
#include "Sonicteam/TitleTask.h"
#include "boost/smart_ptr/make_shared_object.h"
#include "boost/smart_ptr/shared_ptr.h"
Expand Down
19 changes: 19 additions & 0 deletions MarathonRecomp/api/Sonicteam/AudioEngineXenon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <Marathon.inl>
#include <Sonicteam/SoX/Engine/Doc.h>
#include <Sonicteam/SoX/Audio/IAudioEngine.h>
#include <Sonicteam/System/CreateStatic.h>
#include <Sonicteam/System/Singleton.h>

namespace Sonicteam
{
class AudioEngineXenon : public SoX::Audio::IAudioEngine, public System::Singleton<AudioEngineXenon, 0x82D37AC8, System::CreateStatic<AudioEngineXenon, 0x824A5C78>>
{
public:
MARATHON_INSERT_PADDING(8);
be<float> m_MusicVolume;
be<float> m_EffectsVolume;
MARATHON_INSERT_PADDING(0x14);
};
}
12 changes: 12 additions & 0 deletions MarathonRecomp/api/Sonicteam/SoX/Audio/IAudioEngine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <Marathon.inl>

namespace Sonicteam::SoX::Audio
{
class IAudioEngine
{
public:
xpointer<void> m_pVftable;
};
}
14 changes: 14 additions & 0 deletions MarathonRecomp/api/Sonicteam/System/CreateStatic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Sonicteam::System
{
template <typename T, uint32_t TCreator>
class CreateStatic
{
public:
static T* Create()
{
return GuestToHostFunction<T*>(TCreator);
}
};
}
21 changes: 21 additions & 0 deletions MarathonRecomp/api/Sonicteam/System/Singleton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

namespace Sonicteam::System
{
template <typename T, const uint32_t Ptr, typename TCreator>
class Singleton
{
inline static TCreator ms_Creator{};

public:
static T* GetInstance()
{
auto pInstance = (xpointer<T>*)g_memory.Translate(Ptr);

if (!pInstance->ptr.get())
*pInstance = ms_Creator.Create();

return *pInstance;
}
};
}
19 changes: 15 additions & 4 deletions MarathonRecomp/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ void App::Restart(std::vector<std::string> restartArgs)

void App::Exit()
{
// TODO (Hyper): remove this once the new options menu is implemented.
if (auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance())
{
Config::MusicVolume = pAudioEngine->m_MusicVolume;
Config::EffectsVolume = pAudioEngine->m_EffectsVolume;
}

Config::Save();

#ifdef _WIN32
Expand All @@ -44,11 +51,15 @@ PPC_FUNC(sub_8262A568)
be<uint32_t> Height;
};

auto cfg = reinterpret_cast<RenderConfig*>(g_memory.Translate(ctx.r4.u32));
cfg->Width = Video::s_viewportWidth;
cfg->Height = Video::s_viewportHeight;
auto pRenderConfig = reinterpret_cast<RenderConfig*>(g_memory.Translate(ctx.r4.u32));
pRenderConfig->Width = Video::s_viewportWidth;
pRenderConfig->Height = Video::s_viewportHeight;

auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance();
pAudioEngine->m_MusicVolume = Config::MusicVolume * Config::MasterVolume;
pAudioEngine->m_EffectsVolume = Config::EffectsVolume * Config::MasterVolume;

LOGFN_UTILITY("Changed resolution: {}x{}", cfg->Width.get(), cfg->Height.get());
LOGFN_UTILITY("Changed resolution: {}x{}", pRenderConfig->Width.get(), pRenderConfig->Height.get());

__imp__sub_8262A568(ctx, base);

Expand Down
4 changes: 2 additions & 2 deletions MarathonRecomp/user/config_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ CONFIG_DEFINE_ENUM("Bindings", SDL_Scancode, Key_RightStickLeft, SDL_SCANCODE_UN
CONFIG_DEFINE_ENUM("Bindings", SDL_Scancode, Key_RightStickRight, SDL_SCANCODE_UNKNOWN);

CONFIG_DEFINE_LOCALISED("Audio", float, MasterVolume, 1.0f);
CONFIG_DEFINE_LOCALISED("Audio", float, MusicVolume, 1.0f);
CONFIG_DEFINE_LOCALISED("Audio", float, EffectsVolume, 1.0f);
CONFIG_DEFINE_LOCALISED("Audio", float, MusicVolume, 0.6f);
CONFIG_DEFINE_LOCALISED("Audio", float, EffectsVolume, 0.6f);
CONFIG_DEFINE_ENUM_LOCALISED("Audio", EChannelConfiguration, ChannelConfiguration, EChannelConfiguration::Stereo);
CONFIG_DEFINE_LOCALISED("Audio", bool, MusicAttenuation, false);

Expand Down
Loading