[Scummvm-git-logs] scummvm master -> c4e6a8f7a055d9b1e55fdef1a12af881ab112dd7
scemino
noreply at scummvm.org
Fri Apr 19 17:08:18 UTC 2024
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c5346fa0d2 TWP: Fix sound position
c4e6a8f7a0 TWP: Actors should keep a min distance between them
Commit: c5346fa0d2e45daf4b028353a973792e47e01ba4
https://github.com/scummvm/scummvm/commit/c5346fa0d2e45daf4b028353a973792e47e01ba4
Author: scemino (scemino74 at gmail.com)
Date: 2024-04-19T18:26:58+02:00
Commit Message:
TWP: Fix sound position
Changed paths:
engines/twp/debugtools.cpp
engines/twp/twp.cpp
diff --git a/engines/twp/debugtools.cpp b/engines/twp/debugtools.cpp
index a5c46db3103..d61973214c1 100644
--- a/engines/twp/debugtools.cpp
+++ b/engines/twp/debugtools.cpp
@@ -19,10 +19,9 @@
*
*/
+#include "twp/debugtools.h"
#include "backends/imgui/imgui.h"
#include "common/debug-channels.h"
-#include "twp/twp.h"
-#include "twp/debugtools.h"
#include "twp/detection.h"
#include "twp/dialog.h"
#include "twp/hud.h"
@@ -35,6 +34,7 @@
#include "twp/squtil.h"
#include "twp/thread.h"
#include "twp/tsv.h"
+#include "twp/twp.h"
namespace Twp {
@@ -58,7 +58,7 @@ typedef struct ImGuiState {
int _selectedObject = 0;
} ImGuiState;
-ImGuiState* _state = nullptr;
+ImGuiState *_state = nullptr;
ImVec4 gray(0.6f, 0.6f, 0.6f, 1.f);
@@ -90,7 +90,7 @@ static void drawThreads() {
ImGui::TableNextColumn();
ImGui::Text("%-56s", thread->getName().c_str());
ImGui::TableNextColumn();
- if(thread->getId() != g_twp->_cutscene.id) {
+ if (thread->getId() != g_twp->_cutscene.id) {
ImGui::Text("%-6s", thread->isGlobal() ? "global" : "local");
} else {
ImGui::Text("%-6s", "cutscene");
@@ -311,7 +311,7 @@ static void drawAudio() {
ImGui::Text("# sounds: %d/%d", count, NUM_AUDIO_SLOTS);
ImGui::Separator();
- if (ImGui::BeginTable("Threads", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) {
+ if (ImGui::BeginTable("Threads", 8, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("Id");
ImGui::TableSetupColumn("Category");
@@ -319,6 +319,7 @@ static void drawAudio() {
ImGui::TableSetupColumn("Loops");
ImGui::TableSetupColumn("Volume");
ImGui::TableSetupColumn("Pan");
+ ImGui::TableSetupColumn("Object");
ImGui::TableHeadersRow();
for (int i = 0; i < NUM_AUDIO_SLOTS; i++) {
@@ -345,6 +346,9 @@ static void drawAudio() {
if (ImGui::SmallButton("STOP")) {
g_twp->_audio->stop(sound.id);
}
+ ImGui::TableNextColumn();
+ Common::SharedPtr<Object> obj(sqobj(sound.objId));
+ ImGui::Text("%s", obj ? g_twp->getTextDb().getText(obj->getName()).c_str() : "(none)");
}
}
@@ -365,7 +369,7 @@ static void drawGeneral() {
ImGui::Text("%lld", size);
ImGui::TextColored(gray, "Cutscene:");
ImGui::SameLine();
- if(g_twp->_cutscene.id) {
+ if (g_twp->_cutscene.id) {
Common::SharedPtr<Thread> cutscene(sqthread(g_twp->_cutscene.id));
ImGui::Text("%s", cutscene->getName().c_str());
} else {
@@ -452,8 +456,7 @@ static void drawGeneral() {
ImGui::TextColored(gray, "moving:");
ImGui::SameLine();
ImGui::Text("%s", g_twp->_camera->isMoving() ? "yes" : "no");
- auto halfScreenSize = g_twp->_room->getScreenSize() / 2.0f;
- auto camPos = g_twp->cameraPos() - halfScreenSize;
+ auto camPos = g_twp->cameraPos();
if (ImGui::DragFloat2("Camera pos", camPos.getData())) {
g_twp->follow(nullptr);
g_twp->cameraAt(camPos);
diff --git a/engines/twp/twp.cpp b/engines/twp/twp.cpp
index 331bc0e7c84..86fe6648c76 100644
--- a/engines/twp/twp.cpp
+++ b/engines/twp/twp.cpp
@@ -488,9 +488,9 @@ void TwpEngine::update(float elapsed) {
// if cursor is in the margin of the screen and if camera can move again
// then show a left arrow or right arrow
Math::Vector2d screenSize = _room->getScreenSize();
- if ((scrPos.getX() < SCREEN_MARGIN) && (cameraPos().getX() >= 1.f)) {
+ if ((scrPos.getX() < SCREEN_MARGIN) && (_gfx.cameraPos().getX() >= 1.f)) {
_inputState.setCursorShape(CursorShape::Left);
- } else if ((scrPos.getX() > (SCREEN_WIDTH - SCREEN_MARGIN)) && cameraPos().getX() < (_room->_roomSize.getX() - screenSize.getX())) {
+ } else if ((scrPos.getX() > (SCREEN_WIDTH - SCREEN_MARGIN)) && _gfx.cameraPos().getX() < (_room->_roomSize.getX() - screenSize.getX())) {
_inputState.setCursorShape(CursorShape::Right);
} else if (_room->_fullscreen == FULLSCREENROOM && _noun1) {
// if the object is a door, it has a flag indicating its direction: left, right, front, back
@@ -876,7 +876,6 @@ Common::Error TwpEngine::run() {
Common::Event e;
uint time = _system->getMillis();
while (!shouldQuit()) {
- Math::Vector2d camPos = _gfx.cameraPos();
while (_system->getEventManager()->pollEvent(e)) {
switch (e.type) {
case Common::EVENT_CUSTOM_ENGINE_ACTION_START: {
@@ -1025,8 +1024,6 @@ Common::Error TwpEngine::run() {
}
}
- _gfx.cameraPos(camPos);
-
uint32 newTime = _system->getMillis();
uint32 delta = newTime - time;
time = newTime;
@@ -1497,10 +1494,6 @@ void TwpEngine::cameraAt(const Math::Vector2d &at) {
}
Math::Vector2d TwpEngine::cameraPos() {
- if (_room) {
- Math::Vector2d screenSize = _room->getScreenSize();
- return _camera->getAt() + screenSize / 2.0f;
- }
return _camera->getAt();
}
Commit: c4e6a8f7a055d9b1e55fdef1a12af881ab112dd7
https://github.com/scummvm/scummvm/commit/c4e6a8f7a055d9b1e55fdef1a12af881ab112dd7
Author: scemino (scemino74 at gmail.com)
Date: 2024-04-19T18:26:58+02:00
Commit Message:
TWP: Actors should keep a min distance between them
Changed paths:
engines/twp/object.cpp
engines/twp/twp.cpp
diff --git a/engines/twp/object.cpp b/engines/twp/object.cpp
index 19cd87dd41c..439963113ae 100644
--- a/engines/twp/object.cpp
+++ b/engines/twp/object.cpp
@@ -193,8 +193,8 @@ bool Object::playCore(const Common::String &state, bool loop, bool instant) {
return false;
}
-static Node* getChildByName(Node* node, const Common::String& name) {
- if(!node)
+static Node *getChildByName(Node *node, const Common::String &name) {
+ if (!node)
return nullptr;
for (auto child : node->getChildren()) {
if (child->getName() == name) {
@@ -204,11 +204,11 @@ static Node* getChildByName(Node* node, const Common::String& name) {
return nullptr;
}
-static Node* getLayerByName(Node* node, const Common::String& name) {
- Node* child = getChildByName(node, name);
- if(child)
+static Node *getLayerByName(Node *node, const Common::String &name) {
+ Node *child = getChildByName(node, name);
+ if (child)
return child;
- if(node->getChildren().size()==1) {
+ if (node->getChildren().size() == 1) {
return getChildByName(node->getChildren()[0], name);
}
return nullptr;
@@ -230,8 +230,8 @@ void Object::showLayer(const Common::String &layer, bool visible) {
if (index == -1)
_hiddenLayers.push_back(layer);
}
- Node* node = getLayerByName(_node.get(), layer);
- if(node)
+ Node *node = getLayerByName(_node.get(), layer);
+ if (node)
node->setVisible(visible);
}
@@ -312,12 +312,12 @@ bool Object::isTouchable() {
return false;
} else if (sqrawexists(_table, "_touchable")) {
bool result;
- if(SQ_FAILED(sqgetf(_table, "_touchable", result)))
+ if (SQ_FAILED(sqgetf(_table, "_touchable", result)))
error("Failed to get touchable");
return result;
} else if (sqrawexists(_table, "initTouchable")) {
bool result;
- if(SQ_FAILED(sqgetf(_table, "initTouchable", result)))
+ if (SQ_FAILED(sqgetf(_table, "initTouchable", result)))
error("Failed to get touchable");
return result;
} else {
@@ -521,8 +521,8 @@ Common::String Object::getAnimName(const Common::String &key) {
}
void Object::setHeadIndex(int head) {
- Node* node = getLayerByName(_node.get(), Common::String::format("%s%d", getAnimName(HEAD_ANIMNAME).c_str(), head));
- if(!node)
+ Node *node = getLayerByName(_node.get(), Common::String::format("%s%d", getAnimName(HEAD_ANIMNAME).c_str(), head));
+ if (!node)
return;
for (int i = 0; i <= 6; i++) {
showLayer(Common::String::format("%s%d", getAnimName(HEAD_ANIMNAME).c_str(), i), i == head);
@@ -823,11 +823,55 @@ void Object::walk(Common::SharedPtr<Object> obj, const Math::Vector2d &pos, int
obj->_walkTo = Common::SharedPtr<WalkTo>(new WalkTo(obj, pos, facing));
}
+static Facing angleToFacing(float angle) {
+ if(angle<45.f) return Facing::FACE_RIGHT;
+ if(angle<135.f) return Facing::FACE_BACK;
+ if(angle<215.f) return Facing::FACE_LEFT;
+ if(angle<305.f) return Facing::FACE_FRONT;
+ return Facing::FACE_RIGHT;
+}
+
// Walks an actor to the `obj` and then faces it.
void Object::walk(Common::SharedPtr<Object> actor, Common::SharedPtr<Object> obj) {
debugC(kDebugGame, "walk to obj %s: (%f,%f)", obj->_key.c_str(), obj->getUsePos().getX(), obj->getUsePos().getY());
+
int facing = static_cast<int>(obj->_useDir);
- walk(actor, obj->getUsePos(), facing);
+ Math::Vector2d dst(obj->getUsePos());
+
+ // if we walk to an actor we want to keep a minimun distance between them
+ if(g_twp->_resManager->isActor(obj->getId())) {
+ const Math::Vector2d src(actor->_node->getAbsPos());
+ const float dx = dst.getX() - src.getX();
+ const float dy = dst.getY() - src.getY();
+ const float minDistX = 30.f;
+ const float minDistY = 15.f;
+ if ((fabs(dx) > 1.f) || (fabs(dy) > 1.f)) {
+ float angle = atan2f(dy, dx) * 180.f / M_PI;
+ if (angle < 0.f)
+ angle += 360.f;
+ const Facing facing2 = angleToFacing(angle);
+ switch (facing2)
+ {
+ case Facing::FACE_BACK:
+ dst.setY(dst.getY() + minDistY);
+ break;
+ case Facing::FACE_FRONT:
+ dst.setY(dst.getY() - minDistY);
+ break;
+ case Facing::FACE_LEFT:
+ dst.setX(dst.getX() + minDistX);
+ break;
+ case Facing::FACE_RIGHT:
+ dst.setX(dst.getX() - minDistX);
+ break;
+ default:
+ break;
+ }
+ facing = (int)facing2;
+ }
+ }
+
+ walk(actor, dst, facing);
}
void Object::turn(Facing facing) {
diff --git a/engines/twp/twp.cpp b/engines/twp/twp.cpp
index 86fe6648c76..e490522853f 100644
--- a/engines/twp/twp.cpp
+++ b/engines/twp/twp.cpp
@@ -1581,6 +1581,8 @@ bool TwpEngine::selectable(Common::SharedPtr<Object> actor) {
static void giveTo(Common::SharedPtr<Object> actor1, Common::SharedPtr<Object> actor2, Common::SharedPtr<Object> obj) {
obj->_owner = actor2;
actor2->_inventory.push_back(obj);
+ // force actors to be face to face
+ actor2->setFacing(flip(actor1->getFacing()));
int index = find(actor1->_inventory, obj);
if (index != -1)
actor1->_inventory.remove_at(index);
More information about the Scummvm-git-logs
mailing list