Skip to content

Commit

Permalink
Moved config settings into new ConfigSystem namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Feb 8, 2025
1 parent 0150cc6 commit 825036c
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 85 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(Impacto_Src
src/minilua_impl.c
src/voicetable.cpp
src/animation.cpp
src/configsystem.cpp

src/renderer/renderer.cpp

Expand Down Expand Up @@ -352,6 +353,7 @@ set(Impacto_Header
src/rng.h
src/animation.h
src/minilua_impl.h
src/configsystem.h

src/renderer/renderer.h
src/renderer/window.h
Expand Down
2 changes: 0 additions & 2 deletions src/audio/audiocommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ enum AudioChannelState {
ACS_FadingOut
};

constexpr int VoiceCount = 33;

class AudioChannel;
class AudioStream;

Expand Down
8 changes: 4 additions & 4 deletions src/audio/audiosystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../log.h"
#include "../profile/game.h"
#include "../profile/scriptvars.h"
#include "../configsystem.h"

#ifndef IMPACTO_DISABLE_OPENAL
#include "openal/audiobackend.h"
Expand Down Expand Up @@ -64,9 +65,6 @@ void AudioInit() {
Channels[i]->Init((AudioChannelId)i, ACG_BGM);
Channels[AC_SSE]->Init(AC_SSE, ACG_SE);

std::fill_n(VoiceMuted, VoiceCount, false);
std::fill_n(VoiceVolume, VoiceCount, 1.0f);

IsInit = true;
}

Expand All @@ -76,7 +74,9 @@ void AudioUpdate(float dt) {
const int charId = ScrWork[SW_ANIME0CHANO + (i - AC_VOICE0)];
const int mappedCharId = ScrWork[SW_CHARACTERIDMAPPING + charId];
const float voiceVolumeModifier =
VoiceMuted[mappedCharId] ? 0.0f : VoiceVolume[mappedCharId];
ConfigSystem::VoiceMuted[mappedCharId]
? 0.0f
: ConfigSystem::VoiceVolume[mappedCharId];
Channels[i]->Volume = voiceVolumeModifier;
}

Expand Down
3 changes: 0 additions & 3 deletions src/audio/audiosystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ inline float MasterVolume = 1.0f;
inline float GroupVolumes[ACG_Count];
inline AudioChannel* Channels[AC_Count];

inline bool VoiceMuted[VoiceCount];
inline float VoiceVolume[VoiceCount];

} // namespace Audio
} // namespace Impacto
14 changes: 14 additions & 0 deletions src/configsystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "configsystem.h"

#include <algorithm>

namespace Impacto {
namespace ConfigSystem {

void Init() {
std::fill_n(VoiceMuted, VoiceCount, false);
std::fill_n(VoiceVolume, VoiceCount, 1.0f);
}

} // namespace ConfigSystem
} // namespace Impacto
47 changes: 47 additions & 0 deletions src/configsystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <algorithm>
#include <glm/glm.hpp>

namespace Impacto {
namespace ConfigSystem {

void Init();

// Add new tips to the tips notification rendering queue
inline bool ShowTipsNotification = true;

// Advance text on L/R stick, arrow keys, etc.
inline bool AdvanceTextOnDirectionalInput = false;

// Interact with trigger using left and right input in addition
// to their regular counterparts
inline bool DirectionalInputForTrigger = false;

// Stop skip mode when reaching a trigger
// (e.g. delusion trigger, phone trigger, etc.)
inline bool TriggerStopSkip = true;

// Typewriter animation speed
inline float TextSpeed = 768.0f / 60.0f;
constexpr inline glm::vec2 TextSpeedBounds = glm::vec2(256.0f, 4096.0f) / 60.0f;

// Speed to skip in auto mode (MessWaitSpeed)
inline float AutoSpeed = 768.0f / 60.0f;
// Menu is essentially auto *time* as opposed to auto *speed*
constexpr inline glm::vec2 AutoSpeedBounds = glm::vec2(2048.0f, 256.0f) / 60.0f;

// Only skip read text
inline bool SkipRead = true;

// Sync text speed with voice line duration
inline bool SyncVoice = true;

// Stop voice line after dialogue progression
inline bool SkipVoice = false;

// Individual character mute/volume settings
constexpr int VoiceCount = 33;
inline bool VoiceMuted[VoiceCount];
inline float VoiceVolume[VoiceCount];

} // namespace ConfigSystem
} // namespace Impacto
3 changes: 3 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "log.h"
#include "inputsystem.h"
#include "debugmenu.h"
#include "configsystem.h"

#include "ui/ui.h"

Expand Down Expand Up @@ -92,6 +93,8 @@ static void Init() {
memset(ScrWork, 0, sizeof(ScrWork));
memset(FlagWork, 0, sizeof(FlagWork));

ConfigSystem::Init();

if (Profile::GameFeatures & GameFeature::Renderer2D) {
Profile::LoadSpritesheets();
Profile::Charset::Load();
Expand Down
1 change: 0 additions & 1 deletion src/games/cclcc/delusiontrigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "../../vm/interface/input.h"
#include "../../profile/scriptvars.h"
#include "../../src/video/videosystem.h"
#include "../../inputsystem.h"

namespace Impacto {
namespace CCLCC {
Expand Down
39 changes: 19 additions & 20 deletions src/games/cclcc/optionsmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "optionsmenu.h"

#include "../../configsystem.h"
#include "../../profile/game.h"
#include "../../profile/ui/optionsmenu.h"
#include "../../profile/games/cclcc/optionsmenu.h"
Expand All @@ -8,8 +9,6 @@
#include "../../ui/widgets/cclcc/optionsbinarybutton.h"
#include "../../ui/widgets/cclcc/optionsslider.h"
#include "../../ui/widgets/cclcc/optionsvoiceslider.h"
#include "../../hud/tipsnotification.h"
#include "../../inputsystem.h"
#include "../../audio/audiosystem.h"

namespace Impacto {
Expand All @@ -22,29 +21,30 @@ using namespace Impacto::Profile::ScriptVars;
using namespace Impacto::UI::Widgets;
using namespace Impacto::UI::Widgets::CCLCC;
using namespace Impacto::Vm::Interface;
using namespace Impacto::ConfigSystem;

std::unique_ptr<Group> OptionsMenu::CreateBasicPage(
const std::function<void(OptionsEntry*)>& select,
const std::function<void(Widget*)>& highlight) {
const glm::vec4 highlightTint(HighlightColor, 1.0f);
std::unique_ptr<Group> basicPage = std::make_unique<Group>(this);

basicPage->Add(new OptionsBinaryButton(TipsNotification::ShowNotification,
BinaryBoxSprite, OnSprite, OffSprite,
LabelSprites[0], EntriesStartPosition,
highlightTint, select, highlight),
FDIR_DOWN);
basicPage->Add(
new OptionsBinaryButton(ShowTipsNotification, BinaryBoxSprite, OnSprite,
OffSprite, LabelSprites[0], EntriesStartPosition,
highlightTint, select, highlight),
FDIR_DOWN);
basicPage->Add(
new OptionsBinaryButton(
Input::AdvanceTextOnDirectionalInput, BinaryBoxSprite, OnSprite,
OffSprite, LabelSprites[1],
AdvanceTextOnDirectionalInput, BinaryBoxSprite, OnSprite, OffSprite,
LabelSprites[1],
EntriesStartPosition + glm::vec2(0.0f, EntriesVerticalOffset),
highlightTint, select, highlight),
FDIR_DOWN);
basicPage->Add(
new OptionsBinaryButton(
Input::DirectionalInputForTrigger, BinaryBoxSprite, OnSprite,
OffSprite, LabelSprites[2],
DirectionalInputForTrigger, BinaryBoxSprite, OnSprite, OffSprite,
LabelSprites[2],
EntriesStartPosition + glm::vec2(0.0f, EntriesVerticalOffset * 2),
highlightTint, select, highlight),
FDIR_DOWN);
Expand Down Expand Up @@ -152,10 +152,9 @@ std::unique_ptr<Group> OptionsMenu::CreateVoicePage(
VoiceEntriesOffset * glm::vec2(i % columns, i / columns);

Widget* widget = new OptionsVoiceSlider(
Audio::VoiceVolume[i], 0.0f, 1.0f, Audio::VoiceMuted[i],
VoiceSliderTrackSprite, NametagSprites[i], PortraitSprites[2 * i],
PortraitSprites[2 * i + 1], pos, highlightTint, SliderSpeed, select,
highlight);
VoiceVolume[i], 0.0f, 1.0f, VoiceMuted[i], VoiceSliderTrackSprite,
NametagSprites[i], PortraitSprites[2 * i], PortraitSprites[2 * i + 1],
pos, highlightTint, SliderSpeed, select, highlight);
voicePage->Add(widget, FDIR_RIGHT);
}

Expand Down Expand Up @@ -384,9 +383,9 @@ void OptionsMenu::Highlight(Widget* toHighlight) {
void OptionsMenu::ResetToDefault() {
switch (CurrentPage) {
case PageType::Basic: {
TipsNotification::ShowNotification = true;
Input::AdvanceTextOnDirectionalInput = false;
Input::DirectionalInputForTrigger = false;
ShowTipsNotification = true;
AdvanceTextOnDirectionalInput = false;
DirectionalInputForTrigger = false;
TriggerStopSkip = true;
break;
}
Expand All @@ -403,8 +402,8 @@ void OptionsMenu::ResetToDefault() {
break;
}
case PageType::Voice: {
std::fill_n(Audio::VoiceMuted, Audio::VoiceCount, false);
std::fill_n(Audio::VoiceVolume, Audio::VoiceCount, 1.0f);
std::fill_n(VoiceMuted, VoiceCount, false);
std::fill_n(VoiceVolume, VoiceCount, 1.0f);
break;
}
default:
Expand Down
25 changes: 12 additions & 13 deletions src/games/cclcc/savesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "../../profile/vm.h"
#include "../../ui/mapsystem.h"
#include "../../renderer/renderer.h"
#include "../../hud/tipsnotification.h"
#include "../../inputsystem.h"
#include "../../configsystem.h"

#include "yesnotrigger.h"

Expand All @@ -25,6 +24,7 @@ using namespace Impacto::Vm;
using namespace Impacto::Profile::SaveSystem;
using namespace Impacto::Profile::ScriptVars;
using namespace Impacto::Profile::Vm;
using namespace Impacto::ConfigSystem;

SaveError SaveSystem::CheckSaveFile() {
std::error_code ec;
Expand Down Expand Up @@ -128,18 +128,17 @@ SaveError SaveSystem::MountSaveFile() {
SkipRead = !Io::ReadLE<bool>(stream);

stream->Seek(0x8BE, SEEK_SET);
for (size_t i = 0; i < 33; i++) VoiceMuted[i] = !Io::ReadLE<bool>(stream);
for (size_t i = 0; i < 33; i++)
Audio::VoiceMuted[i] = !Io::ReadLE<bool>(stream);
for (size_t i = 0; i < 33; i++)
Audio::VoiceVolume[i] = Io::ReadLE<Uint8>(stream) / 128.0f;
VoiceVolume[i] = Io::ReadLE<Uint8>(stream) / 128.0f;

stream->Seek(0x901, SEEK_SET);
SkipVoice = Io::ReadLE<bool>(stream);
TipsNotification::ShowNotification = Io::ReadLE<bool>(stream);
ShowTipsNotification = Io::ReadLE<bool>(stream);

stream->Seek(0x905, SEEK_SET);
Input::AdvanceTextOnDirectionalInput = Io::ReadLE<bool>(stream);
Input::DirectionalInputForTrigger = Io::ReadLE<bool>(stream);
AdvanceTextOnDirectionalInput = Io::ReadLE<bool>(stream);
DirectionalInputForTrigger = Io::ReadLE<bool>(stream);
TriggerStopSkip = Io::ReadLE<bool>(stream);

// EV Flags
Expand Down Expand Up @@ -366,17 +365,17 @@ void SaveSystem::WriteSaveFile() {
Io::WriteLE(stream, !SkipRead);

stream->Seek(0x8BE, SEEK_SET);
for (size_t i = 0; i < 33; i++) Io::WriteLE(stream, !Audio::VoiceMuted[i]);
for (size_t i = 0; i < 33; i++) Io::WriteLE(stream, !VoiceMuted[i]);
for (size_t i = 0; i < 33; i++)
Io::WriteLE(stream, (Uint8)(Audio::VoiceVolume[i] * 128));
Io::WriteLE(stream, (Uint8)(VoiceVolume[i] * 128));

stream->Seek(0x901, SEEK_SET);
Io::WriteLE(stream, SkipVoice);
Io::WriteLE(stream, TipsNotification::ShowNotification);
Io::WriteLE(stream, ShowTipsNotification);

stream->Seek(0x905, SEEK_SET);
Io::WriteLE(stream, Input::AdvanceTextOnDirectionalInput);
Io::WriteLE(stream, Input::DirectionalInputForTrigger);
Io::WriteLE(stream, AdvanceTextOnDirectionalInput);
Io::WriteLE(stream, DirectionalInputForTrigger);
Io::WriteLE(stream, TriggerStopSkip);

// EV Flags
Expand Down
3 changes: 2 additions & 1 deletion src/hud/delusiontrigger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../profile/hud/delusiontrigger.h"
#include "../text.h"
#include "../configsystem.h"

namespace Impacto {
namespace DelusionTrigger {
Expand All @@ -15,7 +16,7 @@ void Show() {

bool Show(int bgMtrgSelBufferId, int bgMtrgNegaPosiBufferId, int param3) {
if (Implementation) {
if (TriggerStopSkip) MesSkipMode &= SkipModeFlags::Auto;
if (ConfigSystem::TriggerStopSkip) MesSkipMode &= SkipModeFlags::Auto;
return Implementation->Show(bgMtrgSelBufferId, bgMtrgNegaPosiBufferId,
param3);
}
Expand Down
4 changes: 3 additions & 1 deletion src/hud/tipsnotification.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "datedisplay.h"

#include "../configsystem.h"
#include "../profile/hud/tipsnotification.h"

namespace Impacto {
Expand All @@ -15,7 +16,8 @@ void Render() {
}

void AddTip(int tipId) {
if (Implementation && ShowNotification) Implementation->AddTip(tipId);
if (Implementation && ConfigSystem::ShowTipsNotification)
Implementation->AddTip(tipId);
}

} // namespace TipsNotification
Expand Down
1 change: 0 additions & 1 deletion src/hud/tipsnotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TipsNotificationBase {
};

inline TipsNotificationBase* Implementation = nullptr;
inline bool ShowNotification = true;

void Init();
void Update(float dt);
Expand Down
9 changes: 0 additions & 9 deletions src/inputsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,5 @@ inline bool KeyboardButtonIsDown[SDL_NUM_SCANCODES] = {false};
inline bool TouchIsDown[FingerTapMax]{};
inline bool TouchWentDown[FingerTapMax]{};

// Controller settings

// Advance text on L/R stick, arrow keys, etc.
inline bool AdvanceTextOnDirectionalInput = false;

// Interact with trigger using left and right input in addition
// to their regular counterparts
inline bool DirectionalInputForTrigger = false;

} // namespace Input
} // namespace Impacto
7 changes: 4 additions & 3 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "animation.h"
#include "mem.h"
#include "profile/scriptvars.h"
#include "configsystem.h"

#include "profile/charset.h"
#include "profile/dialogue.h"
Expand Down Expand Up @@ -660,9 +661,9 @@ void DialoguePage::AddString(Vm::Sc3VmThread* ctx, Audio::AudioStream* voice,

int typewriterCt = Glyphs.size() - typewriterStart;
float typewriterDur =
(SyncVoice && voice != nullptr)
(ConfigSystem::SyncVoice && voice != nullptr)
? Audio::Channels[Audio::AC_VOICE0]->DurationInSeconds()
: (float)typewriterCt / TextSpeed;
: (float)typewriterCt / ConfigSystem::TextSpeed;
Typewriter.Start(typewriterStart, typewriterCt, typewriterDur);
}

Expand All @@ -678,7 +679,7 @@ void DialoguePage::Update(float dt) {
}

if (TextIsFullyOpaque() && MesSkipMode & SkipModeFlags::Auto)
AutoWaitTime = std::max(0.0f, AutoWaitTime - AutoSpeed * dt);
AutoWaitTime = std::max(0.0f, AutoWaitTime - ConfigSystem::AutoSpeed * dt);

TextBox->Update(dt);
FadeAnimation.Update(dt);
Expand Down
Loading

0 comments on commit 825036c

Please sign in to comment.