TWP: Fix several code review comments

This commit is contained in:
scemino 2024-02-18 09:34:37 +01:00 committed by Eugene Sandulenko
parent 16e9235d42
commit b8e0a37037
16 changed files with 144 additions and 152 deletions

7
configure vendored
View File

@ -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

View File

@ -1 +1,2 @@
engines/twp/dialogs.cpp
engines/twp/metaengine.cpp

View File

@ -214,7 +214,7 @@ static SQInteger actorDistanceWithin(HSQUIRRELVM v) {
Common::SharedPtr<Object> 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<Object> actor = sqactor(v, 2);
Common::SharedPtr<Object> actor(sqactor(v, 2));
sqpush(v, actor != nullptr);
return 1;
}

View File

@ -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<ActorSwitcherSlot> &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

View File

@ -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 {

View File

@ -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<SoundDefinition> 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<SoundDefinition> 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<SoundDefinition> 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;
}

View File

@ -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<Common::SharedPtr<SoundDefinition> > _soundDefs;
AudioSlot _slots[32];
AudioSlot _slots[NUM_AUDIO_SLOTS];
Common::SharedPtr<SoundDefinition> _soundHover; // not used yet, should be used in the GUI
private:

View File

@ -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"

View File

@ -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();

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#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<ThreadBase> 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();

View File

@ -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[];

View File

@ -19,8 +19,6 @@
*
*/
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "twp/graph.h"
namespace Twp {

View File

@ -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;
}

View File

@ -22,12 +22,11 @@
#ifndef TWP_SQGAME_H
#define TWP_SQGAME_H
#include <stddef.h>
#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);

View File

@ -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);

View File

@ -166,22 +166,6 @@ Common::String join(const Common::Array<Common::String> &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);