Skip to content

Commit

Permalink
Added default config settings profile support
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Feb 8, 2025
1 parent 825036c commit ac26310
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 79 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(Impacto_Src
src/minilua_impl.c
src/voicetable.cpp
src/animation.cpp
src/configsystem.cpp

src/renderer/renderer.cpp

Expand All @@ -49,6 +48,7 @@ set(Impacto_Src
src/profile/vm.cpp
src/profile/scriptvars.cpp
src/profile/scriptinput.cpp
src/profile/configsystem.cpp

src/profile/data/savesystem.cpp
src/profile/data/tipssystem.cpp
Expand Down Expand Up @@ -353,7 +353,6 @@ 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 All @@ -377,6 +376,7 @@ set(Impacto_Header
src/profile/vm.h
src/profile/scriptvars.h
src/profile/scriptinput.h
src/profile/configsystem.h

src/profile/data/savesystem.h
src/profile/data/tipssystem.h
Expand Down
24 changes: 24 additions & 0 deletions profiles/cclcc/configsystem.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root.ConfigSystem = {
ShowTipsNotification = true;
AdvanceTextOnDirectionalInput = false;
DirectionalInputForTrigger = false;
TriggerStopSkip = true;

TextSpeed = 768 / 60;
TextSpeedBounds = { X = 256 / 60, Y = 4096 / 60 };
AutoSpeed = 768 / 60;
AutoSpeedBounds = { X = 2048 / 60, Y = 256 / 60 };

SkipRead = true;
SyncVoice = true;
SkipVoice = false;

VoiceCount = 13;
VoiceMuted = {};
VoiceVolume = {};
};

for i = 1, root.ConfigSystem.VoiceCount do
root.ConfigSystem.VoiceMuted[i] = false;
root.ConfigSystem.VoiceVolume[i] = 1;
end
1 change: 1 addition & 0 deletions profiles/cclcc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ include('cclcc/charset.lua');
--include('cclcc/font-lb.lua');
include('cclcc/font-lb-italic.lua');
include('cclcc/dialogue.lua');
include('cclcc/configsystem.lua');
include('cclcc/hud/saveicon.lua');
include('cclcc/hud/loadingdisplay.lua');
include('cclcc/hud/datedisplay.lua');
Expand Down
10 changes: 3 additions & 7 deletions src/audio/audiosystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../log.h"
#include "../profile/game.h"
#include "../profile/scriptvars.h"
#include "../configsystem.h"
#include "../profile/configsystem.h"

#ifndef IMPACTO_DISABLE_OPENAL
#include "openal/audiobackend.h"
Expand Down Expand Up @@ -53,10 +53,6 @@ void AudioInit() {

if (!Backend->Init()) return;

for (int i = 0; i < ACG_Count; i++) {
GroupVolumes[i] = 0.5f;
}

for (int i = AC_SE0; i <= AC_SE2; i++)
Channels[i]->Init((AudioChannelId)i, ACG_SE);
for (int i = AC_VOICE0; i <= AC_REV; i++)
Expand All @@ -74,9 +70,9 @@ void AudioUpdate(float dt) {
const int charId = ScrWork[SW_ANIME0CHANO + (i - AC_VOICE0)];
const int mappedCharId = ScrWork[SW_CHARACTERIDMAPPING + charId];
const float voiceVolumeModifier =
ConfigSystem::VoiceMuted[mappedCharId]
Profile::ConfigSystem::VoiceMuted[mappedCharId]
? 0.0f
: ConfigSystem::VoiceVolume[mappedCharId];
: Profile::ConfigSystem::VoiceVolume[mappedCharId];
Channels[i]->Volume = voiceVolumeModifier;
}

Expand Down
14 changes: 0 additions & 14 deletions src/configsystem.cpp

This file was deleted.

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

#include "ui/ui.h"

Expand Down Expand Up @@ -40,6 +39,7 @@
#include "profile/scene3d.h"
#include "profile/vm.h"
#include "profile/scriptvars.h"
#include "profile/configsystem.h"
#include "profile/ui/selectionmenu.h"
#include "profile/ui/sysmesbox.h"
#include "profile/ui/systemmenu.h"
Expand Down Expand Up @@ -82,6 +82,8 @@ static void Init() {

memset(DrawComponents, DrawComponentType::None, sizeof(DrawComponents));

Profile::ConfigSystem::Configure();

if (Profile::GameFeatures & GameFeature::Audio) {
Audio::AudioInit();
}
Expand All @@ -93,8 +95,6 @@ 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
31 changes: 17 additions & 14 deletions src/games/cclcc/optionsmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "optionsmenu.h"

#include "../../configsystem.h"
#include "../../profile/configsystem.h"
#include "../../profile/game.h"
#include "../../profile/ui/optionsmenu.h"
#include "../../profile/games/cclcc/optionsmenu.h"
Expand All @@ -18,10 +18,10 @@ namespace CCLCC {
using namespace Impacto::Profile::OptionsMenu;
using namespace Impacto::Profile::CCLCC::OptionsMenu;
using namespace Impacto::Profile::ScriptVars;
using namespace Impacto::Profile::ConfigSystem;
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,
Expand Down Expand Up @@ -383,27 +383,30 @@ void OptionsMenu::Highlight(Widget* toHighlight) {
void OptionsMenu::ResetToDefault() {
switch (CurrentPage) {
case PageType::Basic: {
ShowTipsNotification = true;
AdvanceTextOnDirectionalInput = false;
DirectionalInputForTrigger = false;
TriggerStopSkip = true;
ShowTipsNotification = Default::ShowTipsNotification;
AdvanceTextOnDirectionalInput = Default::AdvanceTextOnDirectionalInput;
DirectionalInputForTrigger = Default::DirectionalInputForTrigger;
TriggerStopSkip = Default::TriggerStopSkip;
break;
}
case PageType::Text: {
TextSpeed = 768.0f / 60.0f;
AutoSpeed = 768.0f / 60.0f;
SkipRead = true;
TextSpeed = Default::TextSpeed;
AutoSpeed = Default::AutoSpeed;
SkipRead = Default::SkipRead;
break;
}
case PageType::Sound: {
std::fill_n(Audio::GroupVolumes, Audio::ACG_Count, 0.5f);
SyncVoice = true;
SkipVoice = false;
std::copy(std::begin(Default::GroupVolumes),
std::end(Default::GroupVolumes), Audio::GroupVolumes);
SyncVoice = Default::SyncVoice;
SkipVoice = Default::SkipVoice;
break;
}
case PageType::Voice: {
std::fill_n(VoiceMuted, VoiceCount, false);
std::fill_n(VoiceVolume, VoiceCount, 1.0f);
std::copy(std::begin(Default::VoiceMuted), std::end(Default::VoiceMuted),
VoiceMuted);
std::copy(std::begin(Default::VoiceVolume),
std::end(Default::VoiceVolume), VoiceVolume);
break;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions src/games/cclcc/savesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../../profile/vm.h"
#include "../../ui/mapsystem.h"
#include "../../renderer/renderer.h"
#include "../../configsystem.h"
#include "../../profile/configsystem.h"

#include "yesnotrigger.h"

Expand All @@ -24,7 +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;
using namespace Impacto::Profile::ConfigSystem;

SaveError SaveSystem::CheckSaveFile() {
std::error_code ec;
Expand Down
5 changes: 3 additions & 2 deletions src/hud/delusiontrigger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../profile/hud/delusiontrigger.h"
#include "../profile/configsystem.h"
#include "../text.h"
#include "../configsystem.h"

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

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

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

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

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

Expand Down
83 changes: 83 additions & 0 deletions src/profile/configsystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "configsystem.h"
#include "profile_internal.h"
#include "../audio/audiosystem.h"

namespace Impacto {
namespace Profile {
namespace ConfigSystem {

void Configure() {
std::fill_n(Default::VoiceMuted, VoiceCount, false);
std::fill_n(Default::VoiceVolume, VoiceCount, 1.0f);
std::fill_n(Default::GroupVolumes, Audio::ACG_Count, 0.5f);

if (TryPushMember("ConfigSystem")) {
AssertIs(LUA_TTABLE);

Default::ShowTipsNotification =
TryGetMemberBool("ShowTipsNotification")
.value_or(Default::ShowTipsNotification);
Default::AdvanceTextOnDirectionalInput =
TryGetMemberBool("AdvanceTextOnDirectionalInput")
.value_or(Default::AdvanceTextOnDirectionalInput);
Default::DirectionalInputForTrigger =
TryGetMemberBool("DirectionalInputForTrigger")
.value_or(Default::DirectionalInputForTrigger);
Default::TriggerStopSkip =
TryGetMemberBool("TriggerStopSkip").value_or(Default::TriggerStopSkip);

Default::TextSpeed =
TryGetMemberFloat("TextSpeed").value_or(Default::TextSpeed);
TextSpeedBounds =
TryGetMemberVec2("TextSpeedBounds").value_or(TextSpeedBounds);
Default::AutoSpeed =
TryGetMemberFloat("AutoSpeed").value_or(Default::AutoSpeed);
AutoSpeedBounds =
TryGetMemberVec2("AutoSpeedBounds").value_or(AutoSpeedBounds);

Default::SkipRead =
TryGetMemberBool("SkipRead").value_or(Default::SkipRead);
Default::SyncVoice =
TryGetMemberBool("SyncVoice").value_or(Default::SyncVoice);
Default::SkipVoice =
TryGetMemberBool("SkipVoice").value_or(Default::SkipVoice);

std::optional<Uint32> optionalVoiceCount = TryGetMemberUint("VoiceCount");
if (optionalVoiceCount) {
Uint32 voiceCount = optionalVoiceCount.value();
assert(voiceCount <= VoiceCount);

GetMemberBoolArray(Default::VoiceMuted, voiceCount, "VoiceMuted");
GetMemberFloatArray(Default::VoiceVolume, voiceCount, "VoiceVolume");
}

Pop();
}

ResetToDefault();
}

void ResetToDefault() {
ShowTipsNotification = Default::ShowTipsNotification;
AdvanceTextOnDirectionalInput = Default::AdvanceTextOnDirectionalInput;
DirectionalInputForTrigger = Default::DirectionalInputForTrigger;
TriggerStopSkip = Default::TriggerStopSkip;

TextSpeed = Default::TextSpeed;
AutoSpeed = Default::AutoSpeed;

SkipRead = Default::SkipRead;
SyncVoice = Default::SyncVoice;
SkipVoice = Default::SkipVoice;

std::copy(std::begin(Default::VoiceMuted), std::end(Default::VoiceMuted),
VoiceMuted);
std::copy(std::begin(Default::VoiceVolume), std::end(Default::VoiceVolume),
VoiceVolume);
std::copy(std::begin(Default::GroupVolumes), std::end(Default::GroupVolumes),
Audio::GroupVolumes);
}

} // namespace ConfigSystem
} // namespace Profile
} // namespace Impacto
Loading

0 comments on commit ac26310

Please sign in to comment.