From b8e0a3703708ba5043361ae1e22f88d409f7a738 Mon Sep 17 00:00:00 2001 From: scemino Date: Sun, 18 Feb 2024 09:34:37 +0100 Subject: [PATCH] TWP: Fix several code review comments --- configure | 7 ++- engines/twp/POTFILES | 1 + engines/twp/actorlib.cpp | 10 ++-- engines/twp/actorswitcher.cpp | 99 ++++++++++++++++++----------------- engines/twp/actorswitcher.h | 2 +- engines/twp/audio.cpp | 36 ++++++------- engines/twp/audio.h | 7 ++- engines/twp/configure.engine | 2 +- engines/twp/credits.pl | 4 +- engines/twp/debugtools.cpp | 80 ++++++++++++++-------------- engines/twp/detection.h | 22 ++++---- engines/twp/graph.cpp | 2 - engines/twp/prefs.cpp | 3 +- engines/twp/sqgame.h | 3 +- engines/twp/tsv.cpp | 2 +- engines/twp/util.cpp | 16 ------ 16 files changed, 144 insertions(+), 152 deletions(-) diff --git a/configure b/configure index 001345619c5..f9dc9c74658 100755 --- a/configure +++ b/configure @@ -6773,8 +6773,11 @@ echo "$_discord" # # Check for Imgui # -define_in_config_if_yes "$_imgui" 'USE_IMGUI' -echo "$_imgui" +if test "$_opengl" = yes ; then + echocheck "Imgui" + define_in_config_if_yes "$_imgui" 'USE_IMGUI' + echo "$_imgui" +fi # # Enable vkeybd / event recorder diff --git a/engines/twp/POTFILES b/engines/twp/POTFILES index 388ceab2140..523f89adf63 100644 --- a/engines/twp/POTFILES +++ b/engines/twp/POTFILES @@ -1 +1,2 @@ +engines/twp/dialogs.cpp engines/twp/metaengine.cpp diff --git a/engines/twp/actorlib.cpp b/engines/twp/actorlib.cpp index c9816cfa81d..aa6aa33def6 100644 --- a/engines/twp/actorlib.cpp +++ b/engines/twp/actorlib.cpp @@ -214,7 +214,7 @@ static SQInteger actorDistanceWithin(HSQUIRRELVM v) { Common::SharedPtr obj = sqobj(v, 3); if (!obj) return sq_throwerror(v, "failed to get spot"); - if(actor1->_room != actor2->_room) + if (actor1->_room != actor2->_room) return false; // not sure about this, needs to be check one day ;) sqpush(v, distance((Vector2i)actor1->_node->getAbsPos(), (Vector2i)obj->getUsePos()) < distance((Vector2i)actor2->_node->getAbsPos(), (Vector2i)obj->getUsePos())); @@ -231,7 +231,7 @@ static SQInteger actorDistanceWithin(HSQUIRRELVM v) { int dist; if (SQ_FAILED(sqget(v, 4, dist))) return sq_throwerror(v, "failed to get distance"); - if(actor->_room != obj->_room) + if (actor->_room != obj->_room) return false; sqpush(v, distance((Vector2i)actor->_node->getAbsPos(), (Vector2i)obj->getUsePos()) < dist); return 1; @@ -334,8 +334,8 @@ static SQInteger actorInWalkbox(HSQUIRRELVM v) { Common::String name; if (SQ_FAILED(sqget(v, 3, name))) return sq_throwerror(v, "failed to get name"); - for (const auto & walkbox : g_engine->_room->_walkboxes) { - if (walkbox._name == name) { + for (const auto &walkbox : g_engine->_room->_walkboxes) { + if (walkbox._name == name) { if (walkbox.contains((Vector2i)actor->_node->getAbsPos())) { sqpush(v, true); return 1; @@ -932,7 +932,7 @@ static SQInteger isActorSelectable(HSQUIRRELVM v) { // If an actor is specified, returns true otherwise returns false. static SQInteger is_actor(HSQUIRRELVM v) { - Common::SharedPtr actor = sqactor(v, 2); + Common::SharedPtr actor(sqactor(v, 2)); sqpush(v, actor != nullptr); return 1; } diff --git a/engines/twp/actorswitcher.cpp b/engines/twp/actorswitcher.cpp index 45e0a97f1e7..f985aa9bbc9 100644 --- a/engines/twp/actorswitcher.cpp +++ b/engines/twp/actorswitcher.cpp @@ -31,16 +31,16 @@ namespace Twp { -ActorSwitcherSlot::ActorSwitcherSlot(const Common::String &icon, Color back, Color frame, SelectFunc *selectFunc, int id) { - this->icon = icon; - this->back = back; - this->frame = frame; - this->selectFunc = selectFunc; - this->id = id; +ActorSwitcherSlot::ActorSwitcherSlot(const Common::String &icon_, Color back_, Color frame_, SelectFunc *selectFunc_, int id_) { + icon = icon_; + this->back = back_; + this->frame = frame_; + this->selectFunc = selectFunc_; + this->id = id_; } void ActorSwitcherSlot::select() { - if(selectFunc) { + if (selectFunc) { selectFunc(id); } } @@ -101,7 +101,7 @@ void ActorSwitcher::drawSprite(const SpriteSheetFrame &sf, Texture *texture, Col } float ActorSwitcher::height() const { - float n = _mouseOver ? _slots.size() : 1; + float n = _mouseOver ? _slots.size() : 1.0f; return n * ACTOR_SEP; } @@ -116,50 +116,51 @@ Common::Rect ActorSwitcher::rect() const { } void ActorSwitcher::update(const Common::Array &slots, float elapsed) { - if (_visible) { - _slots = slots; + if (!_visible) + return; - // update flash icon - if ((_flash != 0) && ((_flash == -1) || (_flashElapsed < _flash))) { - _flashElapsed = _flashElapsed + elapsed; - _alpha = 0.6f + 0.4f * sin(M_PI * 2.f * _flashElapsed); - } else { - _flash = 0; - _flashElapsed = 0.f; - _alpha = INACTIVE_ALPHA; - } + _slots = slots; - // check if mouse is over actor icons or gear icon - Math::Vector2d scrPos = g_engine->winToScreen(g_engine->_cursor.pos); - bool oldMouseOver = _mouseOver; - _mouseOver = !_down && rect().contains(scrPos.getX(), scrPos.getY()); - - // update anim - _animElapsed = _animElapsed + elapsed; - - // stop anim or flash if necessary - if (oldMouseOver != _mouseOver) { - _animElapsed = 0.f; - if (_mouseOver) - _flash = 0; - } - - // update anim pos - _animPos = MIN(1.f, _animElapsed / ANIM_DURATION); - - // check if we select an actor or gear icon - if (_mouseOver && (g_engine->_cursor.leftDown) && !_down) { - _down = true; - // check if we allow to select an actor - size_t iconIdx = iconIndex(scrPos); - if ((_mode == asOn) || (iconIdx == (_slots.size() - 1))) { - if (_slots[iconIdx].selectFunc != nullptr) - _slots[iconIdx].select(); - } - } - if (!g_engine->_cursor.leftDown) - _down = false; + // update flash icon + if ((_flash != 0) && ((_flash == -1) || (_flashElapsed < _flash))) { + _flashElapsed = _flashElapsed + elapsed; + _alpha = 0.6f + 0.4f * sin(M_PI * 2.f * _flashElapsed); + } else { + _flash = 0; + _flashElapsed = 0.f; + _alpha = INACTIVE_ALPHA; } + + // check if mouse is over actor icons or gear icon + Math::Vector2d scrPos = g_engine->winToScreen(g_engine->_cursor.pos); + bool oldMouseOver = _mouseOver; + _mouseOver = !_down && rect().contains(scrPos.getX(), scrPos.getY()); + + // update anim + _animElapsed = _animElapsed + elapsed; + + // stop anim or flash if necessary + if (oldMouseOver != _mouseOver) { + _animElapsed = 0.f; + if (_mouseOver) + _flash = 0; + } + + // update anim pos + _animPos = MIN(1.f, _animElapsed / ANIM_DURATION); + + // check if we select an actor or gear icon + if (_mouseOver && (g_engine->_cursor.leftDown) && !_down) { + _down = true; + // check if we allow to select an actor + size_t iconIdx = iconIndex(scrPos); + if ((_mode == asOn) || (iconIdx == (_slots.size() - 1))) { + if (_slots[iconIdx].selectFunc != nullptr) + _slots[iconIdx].select(); + } + } + if (!g_engine->_cursor.leftDown) + _down = false; } } // namespace Twp diff --git a/engines/twp/actorswitcher.h b/engines/twp/actorswitcher.h index 4b56bd4e9f6..3d6a8a2a441 100644 --- a/engines/twp/actorswitcher.h +++ b/engines/twp/actorswitcher.h @@ -22,8 +22,8 @@ #ifndef TWP_ACTORSWITCHER_H #define TWP_ACTORSWITCHER_H -#include "twp/scenegraph.h" #include "common/func.h" +#include "twp/scenegraph.h" namespace Twp { diff --git a/engines/twp/audio.cpp b/engines/twp/audio.cpp index e4486c7c18e..b3214e464fd 100644 --- a/engines/twp/audio.cpp +++ b/engines/twp/audio.cpp @@ -70,13 +70,13 @@ void SoundDefinition::load() { bool AudioSystem::playing(int id) const { // channel ID ? - if (id >= 1 && id <= 32) { + if (id >= 1 && id <= NUM_AUDIO_SLOTS) { if (!_slots[id].busy) return false; id = g_engine->_mixer->getSoundID(_slots[id].handle); } // sound definition ID ? - for (const auto & _slot : _slots) { + for (const auto &_slot : _slots) { if (_slot.busy && _slot.sndDef->getId() == id) { return g_engine->_mixer->isSoundHandleActive(_slot.handle); } @@ -86,7 +86,7 @@ bool AudioSystem::playing(int id) const { } bool AudioSystem::playing(Common::SharedPtr soundDef) const { - for (const auto & _slot : _slots) { + for (const auto &_slot : _slots) { if (_slot.busy && _slot.sndDef == soundDef) { return g_engine->_mixer->isSoundHandleActive(_slot.handle); } @@ -98,7 +98,7 @@ void AudioSystem::fadeOut(int id, float fadeTime) { if (fadeTime < 0.01f) { stop(id); } else { - for (int i = 0; i < 32; i++) { + for (int i = 0; i < NUM_AUDIO_SLOTS; i++) { if (_slots[i].busy && _slots[i].id == id) { _slots[i].fadeOutTimeMs = fadeTime; } @@ -108,13 +108,13 @@ void AudioSystem::fadeOut(int id, float fadeTime) { void AudioSystem::stop(int id) { // channel ID ? - if (id >= 1 && id <= 32) { + if (id >= 1 && id <= NUM_AUDIO_SLOTS) { if (!_slots[id].busy) return; id = g_engine->_mixer->getSoundID(_slots[id].handle); } // sound definition ID ? - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { if (_slot.busy && _slot.sndDef->getId() == id) { _slot.loopTimes = 0; g_engine->_mixer->stopHandle(_slot.handle); @@ -128,7 +128,7 @@ void AudioSystem::setMasterVolume(float vol) { _masterVolume = Twp::clamp(vol, 0.f, 1.f); // update sounds - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { if (_slot.busy && g_engine->_mixer->isSoundHandleActive(_slot.handle)) { g_engine->_mixer->setChannelVolume(_slot.handle, _slot.volume * _masterVolume); } @@ -183,13 +183,13 @@ void AudioSystem::updateVolume(AudioSlot *slot) { void AudioSystem::setVolume(int id, float vol) { // channel ID ? - if (id >= 1 && id <= 32) { + if (id >= 1 && id <= NUM_AUDIO_SLOTS) { if (!_slots[id].busy) return; id = g_engine->_mixer->getSoundID(_slots[id].handle); } // sound definition ID or sound ID ? - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { if (_slot.busy && ((_slot.sndDef->getId() == id) || (g_engine->_mixer->getSoundID(_slot.handle) == id))) { _slot.volume = vol; updateVolume(&_slot); @@ -198,10 +198,10 @@ void AudioSystem::setVolume(int id, float vol) { } void AudioSystem::update(float) { - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { if (_slot.busy && !g_engine->_mixer->isSoundHandleActive(_slot.handle)) { - if((_slot.loopTimes == -1) || _slot.loopTimes > 0) { - if(_slot.loopTimes != -1) { + if ((_slot.loopTimes == -1) || _slot.loopTimes > 0) { + if (_slot.loopTimes != -1) { _slot.loopTimes--; } Audio::SeekableAudioStream *audioStream; @@ -212,7 +212,7 @@ void AudioSystem::update(float) { } else if (name.hasSuffixIgnoreCase(".wav")) { audioStream = Audio::makeWAVStream(&_slot.stream, DisposeAfterUse::NO); } else { - error("Unexpected audio format: %s", name.c_str()); + error("AudioSystem::update(): Unexpected audio format: %s", name.c_str()); } g_engine->_mixer->playStream(_slot.soundType, &_slot.handle, audioStream, _slot.id, _slot.volume); } else { @@ -221,7 +221,7 @@ void AudioSystem::update(float) { } } // sound definition ID or sound ID ? - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { if (_slot.busy) { updateVolume(&_slot); } @@ -229,7 +229,7 @@ void AudioSystem::update(float) { } AudioSlot *AudioSystem::getFreeSlot() { - for (auto & _slot : _slots) { + for (auto &_slot : _slots) { AudioSlot *slot = &_slot; if (!slot->busy || !g_engine->_mixer->isSoundHandleActive(slot->handle)) { slot->busy = false; @@ -255,7 +255,7 @@ int AudioSystem::play(Common::SharedPtr sndDef, Audio::Mixer::S } else { error("Unexpected audio format: %s", name.c_str()); } - if(!audioStream) + if (!audioStream) error("Failed to load audio: %s", name.c_str()); int id = newSoundId(); @@ -276,7 +276,7 @@ int AudioSystem::play(Common::SharedPtr sndDef, Audio::Mixer::S } int AudioSystem::getElapsed(int id) const { - for (const auto & _slot : _slots) { + for (const auto &_slot : _slots) { if (_slot.id == id) { Audio::Timestamp t = g_engine->_mixer->getElapsedTime(_slot.handle); return t.msecs(); @@ -286,7 +286,7 @@ int AudioSystem::getElapsed(int id) const { } int AudioSystem::getDuration(int id) const { - for (const auto & _slot : _slots) { + for (const auto &_slot : _slots) { if (_slot.id == id) { return _slot.total; } diff --git a/engines/twp/audio.h b/engines/twp/audio.h index 41d5ce9f9d4..b1dd4de42eb 100644 --- a/engines/twp/audio.h +++ b/engines/twp/audio.h @@ -29,11 +29,16 @@ #include "twp/ggpack.h" namespace Audio { + class SeekableAudioStream; } namespace Twp { +enum { + NUM_AUDIO_SLOTS = 32 +}; + class AudioChannel; class SoundDefinition; @@ -106,7 +111,7 @@ public: void update(float elapsed); Common::Array > _soundDefs; - AudioSlot _slots[32]; + AudioSlot _slots[NUM_AUDIO_SLOTS]; Common::SharedPtr _soundHover; // not used yet, should be used in the GUI private: diff --git a/engines/twp/configure.engine b/engines/twp/configure.engine index b23be5a4c60..78d5384d468 100644 --- a/engines/twp/configure.engine +++ b/engines/twp/configure.engine @@ -1,3 +1,3 @@ # This file is included from the main "configure" script # add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] -add_engine twp "Thimbleweed Park" yes "" "" "16bit highres vorbis png imgui opengl_game_shaders" +add_engine twp "Thimbleweed Park" yes "" "" "16bit highres vorbis png opengl_game_shaders" diff --git a/engines/twp/credits.pl b/engines/twp/credits.pl index 0ed5006e0c7..f0cd477b9dd 100644 --- a/engines/twp/credits.pl +++ b/engines/twp/credits.pl @@ -1,3 +1,3 @@ -begin_section("Twp"); - add_person("Name 1", "Handle 1", ""); +begin_section("Thimbleweed Park"); + add_person("Valéry Sablonnière", "Scemino", ""); end_section(); diff --git a/engines/twp/debugtools.cpp b/engines/twp/debugtools.cpp index b58a305b984..5b00fc352d4 100644 --- a/engines/twp/debugtools.cpp +++ b/engines/twp/debugtools.cpp @@ -1,23 +1,23 @@ /* ScummVM - Graphic Adventure Engine -* -* ScummVM is the legal property of its developers, whose names -* are too numerous to list here. Please refer to the COPYRIGHT -* file distributed with this source distribution. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*/ + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ #include "twp/debugtools.h" #include "imgui/imgui.h" @@ -37,7 +37,7 @@ static struct { bool _showResources = false; bool _showScenegraph = false; bool _showActor = false; - Node* _node = nullptr; + Node *_node = nullptr; ImGuiTextFilter _objFilter; ImGuiTextFilter _actorFilter; int _fadeEffect = 0; @@ -68,7 +68,7 @@ static void drawThreads() { ImGui::TableSetupColumn("Line"); ImGui::TableHeadersRow(); - if(g_engine->_cutscene) { + if (g_engine->_cutscene) { Common::SharedPtr thread(g_engine->_cutscene); SQStackInfos infos; sq_stackinfos(thread->getThread(), 0, &infos); @@ -179,7 +179,7 @@ static void drawActors() { ImGui::Begin("Actors", &state._showStack); state._actorFilter.Draw(); ImGui::BeginChild("Actor_List"); - for(auto& actor : g_engine->_actors) { + for (auto &actor : g_engine->_actors) { bool selected = actor->getId() == state._selectedActor; Common::String key(actor->_key); if (state._actorFilter.PassFilter(actor->_key.c_str())) { @@ -290,7 +290,7 @@ static void drawAudio() { ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); ImGui::Begin("Sounds", &state._showAudio); - ImGui::Text("# sounds: %d/32", count); + ImGui::Text("# sounds: %d/%d", count, NUM_AUDIO_SLOTS); ImGui::Separator(); if (ImGui::BeginTable("Threads", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) { @@ -303,7 +303,7 @@ static void drawAudio() { ImGui::TableSetupColumn("Pan"); ImGui::TableHeadersRow(); - for (int i = 0; i < 32; i++) { + for (int i = 0; i < NUM_AUDIO_SLOTS; i++) { auto &sound = g_engine->_audio._slots[i]; ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -380,16 +380,16 @@ static void drawGeneral() { ImGui::Separator(); bool isSwitcherOn = g_engine->_actorSwitcher._mode == asOn; - if(ImGui::Checkbox("Switcher ON", &isSwitcherOn)) { - if(isSwitcherOn) { + if (ImGui::Checkbox("Switcher ON", &isSwitcherOn)) { + if (isSwitcherOn) { g_engine->_actorSwitcher._mode |= asOn; } else { g_engine->_actorSwitcher._mode &= ~asOn; } } bool isTemporaryUnselectable = g_engine->_actorSwitcher._mode & asTemporaryUnselectable; - if(ImGui::Checkbox("Switcher Temp. Unselectable", &isTemporaryUnselectable)) { - if(isTemporaryUnselectable) { + if (ImGui::Checkbox("Switcher Temp. Unselectable", &isTemporaryUnselectable)) { + if (isTemporaryUnselectable) { g_engine->_actorSwitcher._mode |= asTemporaryUnselectable; } else { g_engine->_actorSwitcher._mode &= ~asTemporaryUnselectable; @@ -525,27 +525,27 @@ static void drawGeneral() { ImGui::End(); } -static void drawNode(Node* node) { +static void drawNode(Node *node) { auto children = node->getChildren(); bool selected = state._node == node; - if(children.empty()) { - if(ImGui::Selectable(node->getName().c_str(), &selected)) { + if (children.empty()) { + if (ImGui::Selectable(node->getName().c_str(), &selected)) { state._node = node; } } else { ImGui::PushID(node->getName().c_str()); - if(ImGui::TreeNode("")) { + if (ImGui::TreeNode("")) { ImGui::SameLine(); - if(ImGui::Selectable(node->getName().c_str(), &selected)) { + if (ImGui::Selectable(node->getName().c_str(), &selected)) { state._node = node; } - for(auto& child : children) { + for (auto &child : children) { drawNode(child); } ImGui::TreePop(); } else { ImGui::SameLine(); - if(ImGui::Selectable(node->getName().c_str(), &selected)) { + if (ImGui::Selectable(node->getName().c_str(), &selected)) { state._node = node; } } @@ -563,23 +563,23 @@ static void drawScenegraph() { ImGui::End(); ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); - if(state._node != nullptr) { + if (state._node != nullptr) { ImGui::Begin("Node"); state._node->isVisible(); bool visible = state._node->isVisible(); - if(ImGui::Checkbox(state._node->getName().c_str(), &visible)) { + if (ImGui::Checkbox(state._node->getName().c_str(), &visible)) { state._node->setVisible(visible); } int zsort = state._node->getZSort(); - if(ImGui::DragInt("Z-Sort", &zsort)) { + if (ImGui::DragInt("Z-Sort", &zsort)) { state._node->setZSort(zsort); } Math::Vector2d pos = state._node->getPos(); - if(ImGui::DragFloat2("Pos", pos.getData())) { + if (ImGui::DragFloat2("Pos", pos.getData())) { state._node->setPos(pos); } Math::Vector2d offset = state._node->getOffset(); - if(ImGui::DragFloat2("Offset", offset.getData())) { + if (ImGui::DragFloat2("Offset", offset.getData())) { state._node->setOffset(offset); } ImGui::End(); diff --git a/engines/twp/detection.h b/engines/twp/detection.h index 6ddf43d41d9..f5bebe1ff12 100644 --- a/engines/twp/detection.h +++ b/engines/twp/detection.h @@ -27,17 +27,17 @@ namespace Twp { enum TwpDebugChannels { - kDebugText = 1 << 0, - kDebugGGPack = 1 << 1, - kDebugRes = 1 << 2, - kDebugDialog = 1 << 3, - kDebugGenScript = 1 << 4, - kDebugObjScript = 1 << 5, - kDebugSysScript = 1 << 6, - kDebugRoomScript = 1 << 7, - kDebugActScript = 1 << 8, - kDebugSndScript = 1 << 9, - kDebugGame = 1 << 10, + kDebugText = 1, + kDebugGGPack, + kDebugRes, + kDebugDialog, + kDebugGenScript, + kDebugObjScript, + kDebugSysScript, + kDebugRoomScript, + kDebugActScript, + kDebugSndScript, + kDebugGame, }; extern const PlainGameDescriptor twpGames[]; diff --git a/engines/twp/graph.cpp b/engines/twp/graph.cpp index 8501f980dbe..74c723e1807 100644 --- a/engines/twp/graph.cpp +++ b/engines/twp/graph.cpp @@ -19,8 +19,6 @@ * */ -#define FORBIDDEN_SYMBOL_ALLOW_ALL - #include "twp/graph.h" namespace Twp { diff --git a/engines/twp/prefs.cpp b/engines/twp/prefs.cpp index 22590161236..4e4e11368a9 100644 --- a/engines/twp/prefs.cpp +++ b/engines/twp/prefs.cpp @@ -94,7 +94,8 @@ void Preferences::savePrefs() { } Common::String Preferences::getKey(const Common::String &path) { - Common::String t = Twp::replace(path, "_en", "_" + ConfMan.get("language")); + Common::String t(path); + replace(t, "_en", "_" + ConfMan.get("language")); return t; } diff --git a/engines/twp/sqgame.h b/engines/twp/sqgame.h index ff6d1105883..231a6c3fd8e 100644 --- a/engines/twp/sqgame.h +++ b/engines/twp/sqgame.h @@ -22,12 +22,11 @@ #ifndef TWP_SQGAME_H #define TWP_SQGAME_H -#include #include "twp/squirrel/squirrel.h" namespace Twp { -void regFunc(HSQUIRRELVM v, SQFUNCTION f, const SQChar *functionName, SQInteger nparamscheck = 0, const SQChar *typemask = NULL); +void regFunc(HSQUIRRELVM v, SQFUNCTION f, const SQChar *functionName, SQInteger nparamscheck = 0, const SQChar *typemask = nullptr); void sqgame_register_constants(HSQUIRRELVM v); void sqgame_register_syslib(HSQUIRRELVM v); void sqgame_register_objlib(HSQUIRRELVM v); diff --git a/engines/twp/tsv.cpp b/engines/twp/tsv.cpp index 8b0e210ba79..85b7a42f9b5 100644 --- a/engines/twp/tsv.cpp +++ b/engines/twp/tsv.cpp @@ -43,7 +43,7 @@ Common::String TextDb::getText(int id) { if (result.hasSuffix("#M") || result.hasSuffix("#F")) result = result.substr(0, result.size() - 2); // replace \" by "; - result = Twp::replace(result, "\\\"", "\""); + replace(result, "\\\"", "\""); } else { result = Common::String::format("Text %d not found", id); error("Text %d not found", id); diff --git a/engines/twp/util.cpp b/engines/twp/util.cpp index 62a68addadd..47b75c485ac 100644 --- a/engines/twp/util.cpp +++ b/engines/twp/util.cpp @@ -166,22 +166,6 @@ Common::String join(const Common::Array &array, const Common::St return result; } -Common::String replace(const Common::String &s, const Common::String &what, const Common::String &by) { - Common::String result; - uint i = 0; - uint whatSize = what.size(); - while (true) { - uint j = s.find(what, i); - if (j == Common::String::npos) - break; - result += s.substr(i, j - i); - result += by; - i = j + whatSize; - } - result += s.substr(i); - return result; -} - Common::String remove(const Common::String &txt, char startC, char endC) { if ((txt.size() > 0) && txt[0] == startC) { uint32 i = txt.find(endC);