Skip to content

Commit

Permalink
Merge pull request #3151 from Ghabry/issue-fix
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
fdelapena authored Nov 30, 2023
2 parents 148ce74 + aa5ac75 commit 3d91997
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 61 deletions.
9 changes: 9 additions & 0 deletions src/async_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ void AsyncHandler::CreateRequestMapping(const std::string& file) {
}

void AsyncHandler::ClearRequests() {
auto it = async_requests.begin();
while (it != async_requests.end()) {
auto& req = *it;
if (it->second.IsReady()) {
it = async_requests.erase(it);
} else {
++it;
}
}
async_requests.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion src/async_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace AsyncHandler {
void CreateRequestMapping(const std::string& file);

/**
* Clears all requests. They will hit the server again.
* Clears all finished requests. They will hit the server again.
* Called after changing the language to ensure the assets are replaced.
*/
void ClearRequests();
Expand Down
5 changes: 2 additions & 3 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ int EmptyAudio::BGM_GetTicks() const {
return (Player::GetFrames() - bgm_starttick + 1) / Game_Clock::GetTargetGameFps();
}

void EmptyAudio::vGetConfig(Game_ConfigAudio& cfg) const {
cfg.music_volume.SetOptionVisible(false);
cfg.sound_volume.SetOptionVisible(false);
void EmptyAudio::vGetConfig(Game_ConfigAudio&) const {
// Not supported. The audio menu is disabled.
}

bool EmptyAudio::BGM_PlayedOnce() const {
Expand Down
6 changes: 3 additions & 3 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace {
constexpr const auto SOUND_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mp3", ".wma");
constexpr const auto FONTS_TYPES = Utils::MakeSvArray(".fon", ".fnt", ".bdf", ".ttf", ".ttc", ".otf", ".woff2", ".woff");
constexpr const auto TEXT_TYPES = Utils::MakeSvArray(".txt", ".csv", ".svg", ".xml", ".json", ".yml", ".yaml");
constexpr const auto TEXT_TYPES = Utils::MakeSvArray(".txt", ".csv", ""); // "" = Complete Filename (incl. extension) provided by the user
}

FilesystemView FileFinder::Game() {
Expand Down Expand Up @@ -352,7 +352,7 @@ std::string find_generic(const DirectoryTree::Args& args) {
}

std::string find_generic_with_fallback(DirectoryTree::Args& args) {
std::string found = FileFinder::Save().FindFile(args);
std::string found = FileFinder::Save().FindFile(args);
if (found.empty()) {
return find_generic(args);
}
Expand Down Expand Up @@ -406,7 +406,7 @@ Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, Dir
}

Filesystem_Stream::InputStream open_generic_with_fallback(StringView dir, StringView name, DirectoryTree::Args& args) {
auto is = FileFinder::Save().OpenFile(args);
auto is = FileFinder::Save().OpenFile(args);
if (!is) { is = open_generic(dir, name, args); }
if (!is) {
Output::Debug("Unable to open in either Game or Save: {}/{}", dir, name);
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ bool Game_Interpreter::CommandChangeHeroName(lcf::rpg::EventCommand const& com)
return true;
}

actor->SetName(ToString(CommandStringOrVariableBitfield(com, 1, 1, 2)));
return true;
}

Expand Down
15 changes: 7 additions & 8 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,6 @@ void Game_Map::SetupFromSave(

map = std::move(map_in);
map_info = std::move(save_map);

if (!Player::IsRPG2k3E()) {
// RPG_RT bug: Substitutions are not loaded except in 2k3E
std::iota(map_info.lower_tiles.begin(), map_info.lower_tiles.end(), 0);
std::iota(map_info.upper_tiles.begin(), map_info.upper_tiles.end(), 0);
}

panorama = std::move(save_pan);

SetupCommon();
Expand Down Expand Up @@ -267,7 +260,13 @@ void Game_Map::SetupFromSave(
}

SetEncounterSteps(map_info.encounter_steps);
SetChipset(map_info.chipset_id);

// RPG_RT bug: Chipset is not loaded. Fixed in 2k3E
if (Player::IsRPG2k3E()) {
SetChipset(map_info.chipset_id);
} else {
SetChipset(0);
}

if (!is_map_save_compat) {
panorama = {};
Expand Down
45 changes: 34 additions & 11 deletions src/game_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "game_switches.h"
#include "game_variables.h"
#include "output.h"
#include "utils.h"

void Game_Strings::WarnGet(int id) const {
Output::Debug("Invalid read strvar[{}]!", id);
Expand Down Expand Up @@ -104,21 +105,43 @@ int Game_Strings::Split(Str_Params params, const std::string& delimiter, int str
return -1;
}

size_t index;
std::string token;

// always returns at least 1
int splits = 1;
int splits = 0;
std::string str = ToString(Get(params.string_id));

params.string_id = string_out_id;

for (index = str.find(delimiter); index != std::string::npos; index = str.find(delimiter)) {
token = str.substr(0, index);
Set(params, token);
params.string_id++;
splits++;
str.erase(0, index + delimiter.length());
if (delimiter.empty()) {
const char* iter = str.data();
const auto end = str.data() + str.size();

while (iter != end) {
const char* start_copy = iter;
auto ret = Utils::UTF8Next(iter, end);
iter = ret.next;

if (iter == end) {
break;
}

Set(params, std::string(start_copy, iter - start_copy));

params.string_id++;
splits++;
}
} else {
if (str.find(delimiter) == std::string::npos) {
// token not found -> 1 split
splits = 1;
} else {
std::string token;
for (auto index = str.find(delimiter); index != std::string::npos; index = str.find(delimiter)) {
token = str.substr(0, index);
Set(params, token);
params.string_id++;
splits++;
str.erase(0, index + delimiter.length());
}
}
}

// set the remaining string
Expand Down
4 changes: 2 additions & 2 deletions src/input_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ namespace Input {
"Middle mouse key",
"Scroll up key",
"Scroll down key",
"PLACEHOLDER",
"PLACEHOLDER",
"Run the game at x{} speed",
"Run the game at x{} speed",
"Toggle Fullscreen mode",
"Toggle Window Zoom level",
"Total Button Count");
Expand Down
11 changes: 4 additions & 7 deletions src/platform/sdl/sdl2_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@
#include "bitmap.h"
#include "lcf/scope_guard.h"

#if defined(__APPLE__) && TARGET_OS_OSX
# include "platform/macos/macos_utils.h"
#endif

#ifdef SUPPORT_AUDIO
# include "sdl_audio.h"

# if defined(__APPLE__) && TARGET_OS_OSX
# include "platform/macos/macos_utils.h"
# endif


AudioInterface& Sdl2Ui::GetAudio() {
return *audio_;
}
Expand Down Expand Up @@ -170,8 +169,6 @@ Sdl2Ui::Sdl2Ui(long width, long height, const Game_Config& cfg) : BaseUi(cfg)
audio_ = std::make_unique<SdlAudio>(cfg.audio);
return;
}
#else
audio_ = std::make_unique<EmptyAudio>(cfg.audio);
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/sdl/sdl2_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ class Sdl2Ui final : public BaseUi {

uint32_t texture_format = SDL_PIXELFORMAT_UNKNOWN;

#ifdef SUPPORT_AUDIO
std::unique_ptr<AudioInterface> audio_;
#endif
};

#endif
2 changes: 0 additions & 2 deletions src/platform/sdl/sdl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ SdlUi::SdlUi(long width, long height, const Game_Config& cfg) : BaseUi(cfg)
audio_ = std::make_unique<SdlAudio>(cfg.audio);
return;
}
#else
audio_ = std::make_unique<EmptyAudio>(cfg.audio);
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/sdl/sdl_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class SdlUi final : public BaseUi {
/** SDL_Surface handle to main_surface */
SDL_Surface* main_surface_sdl;

#ifdef SUPPORT_AUDIO
std::unique_ptr<AudioInterface> audio_;
#endif

SdlAxis sdl_axis;
};
Expand Down
2 changes: 0 additions & 2 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ void Scene::MainFunction() {
TransitionOut(next_scene);
}

Input::ResetNonSystemKeys();

init = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scene_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ void Scene_Debug::DoCallCommonEvent() {
}

void Scene_Debug::DoCallMapEvent() {
if (Scene::Find(Scene::Map) != nullptr) {
if (!Scene::Find(Scene::Map)) {
return;
}

Expand Down
16 changes: 15 additions & 1 deletion src/scene_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ void Scene_Settings::CreateMainWindow() {
main_window->SetHeight(176);
main_window->SetY((Player::screen_height - main_window->GetHeight()) / 2);
main_window->SetX((Player::screen_width - main_window->GetWidth()) / 2);

if (Player::no_audio_flag) {
main_window->SetItemEnabled(1, !Player::no_audio_flag);
}
#ifndef SUPPORT_AUDIO
main_window->DisableItem(1);
#endif
}

void Scene_Settings::CreateOptionsWindow() {
Expand Down Expand Up @@ -288,6 +295,13 @@ void Scene_Settings::UpdateMain() {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Game_System::SFX_Decision));
auto idx = main_window->GetIndex();

if (main_window->IsItemEnabled(idx)) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Game_System::SFX_Decision));
} else {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Game_System::SFX_Buzzer));
return;
}

if (modes[idx] == Window_Settings::eSave) {
SaveConfig();
return;
Expand Down Expand Up @@ -560,7 +574,7 @@ bool Scene_Settings::SaveConfig(bool silent) {

Game_Config cfg;
cfg.video = DisplayUi->GetConfig();
cfg.audio = DisplayUi->GetAudio().GetConfig();
cfg.audio = Audio().GetConfig();
cfg.input = Input::GetInputSource()->GetConfig();
cfg.player = Player::player_config;

Expand Down
35 changes: 15 additions & 20 deletions src/window_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ void Window_Settings::RefreshVideo() {
}

void Window_Settings::RefreshAudio() {
auto cfg = DisplayUi->GetAudio().GetConfig();
auto cfg = Audio().GetConfig();

AddOption(cfg.music_volume, [this](){ DisplayUi->GetAudio().BGM_SetGlobalVolume(GetCurrentOption().current_value); });
AddOption(cfg.sound_volume, [this](){ DisplayUi->GetAudio().SE_SetGlobalVolume(GetCurrentOption().current_value); });
AddOption(cfg.music_volume, [this](){ Audio().BGM_SetGlobalVolume(GetCurrentOption().current_value); });
AddOption(cfg.sound_volume, [this](){ Audio().SE_SetGlobalVolume(GetCurrentOption().current_value); });
/*AddOption("Midi Backend", LockedConfigParam<std::string>("Unknown"), "",
[](){},
"Which MIDI backend to use");
Expand All @@ -276,7 +276,7 @@ void Window_Settings::RefreshAudio() {
void Window_Settings::RefreshEngine() {
auto& cfg = Player::player_config;

// FIXME: Binding &cfg is not needed and generates a warning but requires it
// FIXME: Binding &cfg is not needed and generates a warning but MSVC requires it
#ifdef _MSC_VER
AddOption(cfg.settings_autosave, [&cfg](){ cfg.settings_autosave.Toggle(); });
AddOption(cfg.settings_in_title, [&cfg](){ cfg.settings_in_title.Toggle(); });
Expand Down Expand Up @@ -393,15 +393,6 @@ void Window_Settings::RefreshButtonCategory() {
[this]() { Push(eInputListButtonsDeveloper, 2); });
}

const char * GetFastForwardDescription(int index){
Game_ConfigInput& cfg = Input::GetInputSource()->GetConfig();
RangeConfigParam<int> config_arr[] = {cfg.speed_modifier_a, cfg.speed_modifier_b};
static char fast_forward_strs[2][64];

snprintf(fast_forward_strs[index], sizeof(fast_forward_strs[index]), "Run the game at x%i speed", config_arr[index].Get());
return fast_forward_strs[index];
}

void Window_Settings::RefreshButtonList() {
auto& mappings = Input::GetInputSource()->GetButtonMappings();
auto custom_names = Input::GetInputKeyNames();
Expand Down Expand Up @@ -445,8 +436,8 @@ void Window_Settings::RefreshButtonList() {
}
}

auto help = Input::kButtonHelp.tag(button);
std::string value = "";
std::string help = Input::kButtonHelp.tag(button);
std::string value;

// Append as many buttons as fit on the screen, then add ...
int contents_w = GetContents()->width();
Expand Down Expand Up @@ -479,13 +470,17 @@ void Window_Settings::RefreshButtonList() {
value_size += cur_value_size;
}

switch(button){
case Input::FAST_FORWARD_A:
help = GetFastForwardDescription(0);
switch (button) {
case Input::FAST_FORWARD_A: {
Game_ConfigInput& cfg = Input::GetInputSource()->GetConfig();
help = fmt::format(help, cfg.speed_modifier_a.Get());
break;
case Input::FAST_FORWARD_B:
help = GetFastForwardDescription(1);
}
case Input::FAST_FORWARD_B: {
Game_ConfigInput& cfg = Input::GetInputSource()->GetConfig();
help = fmt::format(help, cfg.speed_modifier_b.Get());
break;
}
default:
break;
}
Expand Down

0 comments on commit 3d91997

Please sign in to comment.