Skip to content

Commit

Permalink
Merge pull request #3059 from Ghabry/more_fixes
Browse files Browse the repository at this point in the history
Various small fixes
  • Loading branch information
fdelapena authored Sep 19, 2023
2 parents 23ac5cf + b22134c commit 322b8c3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 42 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ Documentation is available at the documentation wiki: https://wiki.easyrpg.org

### extended / recommended

- FreeType2 for external font support (+ HarfBuzz for Unicode text shaping)
- mpg123 for better MP3 audio support
- WildMIDI for better MIDI audio support
- Libvorbis / Tremor for Ogg Vorbis audio support
- opusfile for Opus audio support
- libsndfile for better WAVE audio support
- libxmp for better tracker music support
- SpeexDSP for proper audio resampling
- FreeType2 for external font support (+ HarfBuzz for Unicode text shaping).
- mpg123 for MP3 audio support.
- WildMIDI for MIDI audio support using GUS patches.
- FluidSynth for MIDI audio support using soundfonts.
- Libvorbis / Tremor for Ogg Vorbis audio support.
- opusfile for Opus audio support.
- libsndfile for better WAVE audio support.
- libxmp for tracker music support.
- SpeexDSP or libsamplerate for proper audio resampling.

SDL 1.2 is still supported, but deprecated.

Expand Down
1 change: 1 addition & 0 deletions src/decoder_drwav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bool DrWavDecoder::Seek(std::streamoff offset, std::ios_base::seekdir origin) {
if (origin == std::ios_base::beg) {
finished = false;
drwav_seek_to_pcm_frame(&handle, offset);
decoded_samples = 0;
return true;
}
return false;
Expand Down
8 changes: 7 additions & 1 deletion src/game_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ int Game_Actor::SetEquipment(int equip_type, int new_item_id) {
}

void Game_Actor::ChangeEquipment(int equip_type, int item_id) {
if (!IsItemUsable(item_id)) {
return;
}

int prev_item = SetEquipment(equip_type, item_id);

if (prev_item != 0) {
Expand Down Expand Up @@ -390,7 +394,9 @@ void Game_Actor::RemoveWholeEquipment() {
int Game_Actor::GetItemCount(int item_id) {
int number = 0;

if (item_id > 0) {
// quirk: 0 is "no item in slot"
// This can be used to count how many slots are empty
if (item_id >= 0) {
for (int16_t i : GetWholeEquipment()) {
if (item_id == i) {
++number;
Expand Down
25 changes: 15 additions & 10 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,10 +1862,6 @@ bool Game_Interpreter::CommandChangeEquipment(lcf::rpg::EventCommand const& com)
continue;
}

if (Main_Data::game_party->GetItemCount(item_id) == 0 && !actor->IsEquipped(item_id)) {
Main_Data::game_party->AddItem(item_id, 1);
}

if (actor->HasTwoWeapons() && slot == lcf::rpg::Item::Type_weapon && item_id != 0) {
lcf::rpg::Item* new_equipment = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
lcf::rpg::Item* equipment1 = lcf::ReaderUtil::GetElement(lcf::Data::items, actor->GetWeaponId());
Expand Down Expand Up @@ -2613,9 +2609,13 @@ bool Game_Interpreter::CommandShakeScreen(lcf::rpg::EventCommand const& com) { /

switch (shake_cmd) {
case 0:
screen->ShakeOnce(strength, speed, tenths * DEFAULT_FPS / 10);
if (wait) {
SetupWait(tenths);
if (tenths > 0) {
screen->ShakeOnce(strength, speed, tenths * DEFAULT_FPS / 10);
if (wait) {
SetupWait(tenths);
}
} else {
screen->ShakeEnd();
}
break;
case 1:
Expand Down Expand Up @@ -2910,7 +2910,10 @@ bool Game_Interpreter::CommandMovePicture(lcf::rpg::EventCommand const& com) { /
} else if (blend_mode == 3) {
params.blend_mode = (int)Bitmap::BlendMode::Overlay;
}
params.duration = ValueOrVariableBitfield(com.parameters[17], 2, params.duration);

if (param_size > 17) {
params.duration = ValueOrVariableBitfield(com.parameters[17], 2, params.duration);
}
params.flip_x = (flags & 16) == 16;
params.flip_y = (flags & 32) == 32;
params.origin = com.parameters[1] >> 8;
Expand Down Expand Up @@ -3088,7 +3091,7 @@ int Game_Interpreter::KeyInputState::CheckInput() const {
return 1001;
}

if (keys[Keys::eMouseScrollUp] && check(Input::SCROLL_DOWN)) {
if (keys[Keys::eMouseScrollUp] && check(Input::SCROLL_UP)) {
return 1004;
}

Expand Down Expand Up @@ -3306,7 +3309,9 @@ bool Game_Interpreter::CommandChangePBG(lcf::rpg::EventCommand const& com) { //
Game_Map::Parallax::ChangeBG(params);

if (!params.name.empty()) {
_async_op = AsyncOp::MakeYield();
if (!AsyncHandler::RequestFile("Panorama", params.name)->IsReady()) {
_async_op = AsyncOp::MakeYield();
}
}

return true;
Expand Down
18 changes: 11 additions & 7 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sstream>
#include <algorithm>
#include <climits>
#include <numeric>

#include "async_handler.h"
#include "options.h"
Expand Down Expand Up @@ -125,6 +126,7 @@ void Game_Map::InitCommonEvents() {
for (const lcf::rpg::CommonEvent& ev : lcf::Data::commonevents) {
common_events.emplace_back(ev.ID);
}
translation_changed = false;
}

void Game_Map::Dispose() {
Expand Down Expand Up @@ -162,12 +164,8 @@ void Game_Map::Setup(std::unique_ptr<lcf::rpg::Map> map_in) {
SetEncounterSteps(GetMapInfo().encounter_steps);
SetChipset(map->chipset_id);

for (size_t i = 0; i < map_info.lower_tiles.size(); i++) {
map_info.lower_tiles[i] = i;
}
for (size_t i = 0; i < map_info.upper_tiles.size(); i++) {
map_info.upper_tiles[i] = i;
}
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);

// Save allowed
const auto* current_info = &GetMapInfo();
Expand Down Expand Up @@ -227,6 +225,13 @@ 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 @@ -346,7 +351,6 @@ void Game_Map::SetupCommon() {
// Restart all common events after translation change
// Otherwise new strings are not applied
if (translation_changed) {
translation_changed = false;
InitCommonEvents();
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int Game_Party::GetItemCount(int item_id) const {

int Game_Party::GetEquippedItemCount(int item_id) const {
int number = 0;
if (item_id > 0) {
if (item_id >= 0) {
for (int i = 0; i < (int) data.party.size(); i++) {
Game_Actor* actor = Main_Data::game_actors->GetActor(data.party[i]);
number += actor->GetItemCount(item_id);
Expand Down
1 change: 1 addition & 0 deletions src/platform/libretro/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ RETRO_API bool retro_load_game(const struct retro_game_info* game) {
// Convert RetroArch archive paths to paths our VFS understands
game_path = Utils::ReplaceAll(game_path, ".zip#", ".zip/");
game_path = Utils::ReplaceAll(game_path, ".easyrpg#", ".easyrpg/");
game_path = FileFinder::MakeCanonical(game_path, 0);

auto fs = FileFinder::Root().Create(game_path);
if (!fs) {
Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ bool Player::IsBig5() {
return Tr::GetCurrentLanguageCode() == "zh_TW";
}

return (encoding == "Big5" || encoding == "950");
return (encoding == "Big5" || encoding == "windows-950" || encoding == "950");
}

bool Player::IsCP936() {
Expand Down
2 changes: 2 additions & 0 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "game_system.h"
#include "main_data.h"
#include "scene_settings.h"
#include "game_map.h"

#ifndef NDEBUG
#define DEBUG_VALIDATE(x) Scene::DebugValidate(x)
Expand Down Expand Up @@ -403,4 +404,5 @@ void Scene::OnTranslationChanged() {
if (Main_Data::game_actors) {
Main_Data::game_actors->ReloadActors();
}
Game_Map::OnTranslationChanged();
}
16 changes: 11 additions & 5 deletions src/scene_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void Scene_Debug::UpdateRangeListWindow() {
addItem("Level");
} else {
addItem("Call ComEvent");
addItem("Call MapEvent", !is_battle);
addItem("Call MapEvent", Scene::Find(Scene::Map) != nullptr);
addItem("Call BtlEvent", is_battle);
addItem("Open Menu", !is_battle);
}
Expand Down Expand Up @@ -793,7 +793,7 @@ void Scene_Debug::DoCallCommonEvent() {
}

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

Expand All @@ -810,9 +810,15 @@ void Scene_Debug::DoCallMapEvent() {
return;
}

Game_Map::GetInterpreter().Push(me, page, false);
Scene::PopUntil(Scene::Map);
Output::Debug("Debug Scene Forced execution of map event {} page {} on the map foreground interpreter.", me->GetId(), page->ID);
if (Game_Battle::IsBattleRunning()) {
Game_Battle::GetInterpreter().Push(me, page, false);
Scene::PopUntil(Scene::Battle);
Output::Debug("Debug Scene Forced execution of map event {} page {} on the battle foreground interpreter.", me->GetId(), page->ID);
} else {
Game_Map::GetInterpreter().Push(me, page, false);
Scene::PopUntil(Scene::Map);
Output::Debug("Debug Scene Forced execution of map event {} page {} on the map foreground interpreter.", me->GetId(), page->ID);
}
}

void Scene_Debug::DoCallBattleEvent() {
Expand Down
1 change: 0 additions & 1 deletion src/scene_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ void Scene_Map::OnTranslationChanged() {
// FIXME: Map events are not reloaded
// They require leaving and reentering the map
Scene::OnTranslationChanged();
Game_Map::OnTranslationChanged();
}

void Scene_Map::PreUpdate(MapUpdateAsyncContext& actx) {
Expand Down
2 changes: 1 addition & 1 deletion src/transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void Transition::SetAttributesTransitions() {
case TransitionZoomIn:
case TransitionZoomOut:
if (scene != nullptr && scene->type == Scene::Map) {
auto map = static_cast<Scene_Map*>(Scene::instance.get());
auto map = static_cast<Scene_Map*>(scene);

zoom_position[0] = std::max(0, std::min(Main_Data::game_player->GetScreenX() + map->spriteset->GetRenderOx(), (int)Player::screen_width));
zoom_position[1] = std::max(0, std::min(Main_Data::game_player->GetScreenY() - 8 + map->spriteset->GetRenderOy(), (int)Player::screen_height));
Expand Down
13 changes: 7 additions & 6 deletions src/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ void Dictionary::addEntry(const Entry& entry)
}

// Returns success
void Dictionary::FromPo(Dictionary& res, std::istream& in) {
void Dictionary::FromPo(Dictionary& res, Filesystem_Stream::InputStream& in) {
std::string line;
lcf::StringView line_view;
bool found_header = false;
Expand All @@ -831,7 +831,7 @@ void Dictionary::FromPo(Dictionary& res, std::istream& in) {

auto extract_string = [&](size_t offset) -> std::string {
if (offset >= line_view.size()) {
Output::Error("Parse error (Line {}) is empty", line_number);
Output::Error("{}\n\nParse error (Line {}) is empty", FileFinder::GetPathInsideGamePath(in.GetName()), line_number);
return "";
}

Expand All @@ -847,7 +847,7 @@ void Dictionary::FromPo(Dictionary& res, std::istream& in) {
first_quote = true;
continue;
}
Output::Error(R"(Parse error (Line {}): Expected ", got "{}": {})", line_number, c, line);
Output::Error("{}\n\nParse error (Line {}): Expected \", got \"{}\":\n{}", FileFinder::GetPathInsideGamePath(in.GetName()), line_number, c, line);
return "";
}

Expand All @@ -865,9 +865,10 @@ void Dictionary::FromPo(Dictionary& res, std::istream& in) {
case '"':
out << '"';
break;
default:
Output::Error(R"(Parse error (Line {}): Expected \, \n or ", got "{}": {})", line_number, c, line);
default: {
Output::Error("{}\n\nParse error (Line {}): Expected \\, \\n or \", got \"{}\":\n{}", FileFinder::GetPathInsideGamePath(in.GetName()), line_number, c, line);
break;
}
}
} else {
// no-slash
Expand All @@ -879,7 +880,7 @@ void Dictionary::FromPo(Dictionary& res, std::istream& in) {
}
}

Output::Error("Parse error (Line {}): Unterminated line: {}", line_number, line);
Output::Error("{}\n\nParse error (Line {}): Unterminated line:\n{}", FileFinder::GetPathInsideGamePath(in.GetName()), line_number, line);
return out.str();
};

Expand Down
2 changes: 1 addition & 1 deletion src/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Dictionary {
* @param res The dictionary to store the translated entries in.
* @param in The stream to load the translated entries from.
*/
static void FromPo(Dictionary& res, std::istream& in);
static void FromPo(Dictionary& res, Filesystem_Stream::InputStream& in);

/**
* Replace an original string with the translated string.
Expand Down

0 comments on commit 322b8c3

Please sign in to comment.