From 1dbada24c9d07a198c7a73cdd3019a9a25761bba Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:16:32 +0100 Subject: [PATCH 1/8] Always run game tests --- .github/workflows/linux.yml | 3 +-- .github/workflows/macos.yml | 3 +-- .github/workflows/windows.yml | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 987a257a73e5..73ae1dd5f565 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -119,7 +119,6 @@ jobs: make Run_UnitTest - name: Run game tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' working-directory: build run: | make Run_GameTest_Headless_Parallel @@ -127,7 +126,7 @@ jobs: OPENENROTH_MM7_PATH: /home/runner/work/OpenEnroth/OpenEnroth/OpenEnroth_GameData/mm7 - name: Run retrace tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug' + if: matrix.configuration != 'Debug' working-directory: build run: | make Run_RetraceTest_Headless_Parallel diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 76ced63a8c2b..c38d395a074e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -94,7 +94,6 @@ jobs: make Run_UnitTest - name: Run game tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' working-directory: build run: | make Run_GameTest_Headless_Parallel @@ -102,7 +101,7 @@ jobs: OPENENROTH_MM7_PATH: /Users/runner/work/OpenEnroth/OpenEnroth/OpenEnroth_GameData/mm7 - name: Run retrace tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug' + if: matrix.configuration != 'Debug' working-directory: build run: | make Run_RetraceTest_Headless_Parallel diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e2d17a881661..3cbd6d37e65d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -127,7 +127,6 @@ jobs: # Only run gametest if we restored game data. - name: Run game tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' working-directory: build run: | ninja Run_GameTest_Headless_Parallel @@ -135,7 +134,7 @@ jobs: OPENENROTH_MM7_PATH: 'D:\a\OpenEnroth\OpenEnroth\OpenEnroth_GameData\mm7' - name: Run retrace tests - if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug' + if: matrix.configuration != 'Debug' working-directory: build run: | ninja Run_RetraceTest_Headless_Parallel From d5d9c729f1c1f0a2c5bbd106946dda8cb1dde0b7 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:30:05 +0100 Subject: [PATCH 2/8] Some NullPlatform cleanup --- src/Library/Platform/Interface/Platform.h | 1 - src/Library/Platform/Null/NullEventLoop.cpp | 4 +++- src/Library/Platform/Null/NullPlatform.cpp | 19 ++++++++++++------- src/Library/Platform/Null/NullPlatform.h | 1 - .../Platform/Null/NullPlatformSharedState.h | 12 +++++++++++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Library/Platform/Interface/Platform.h b/src/Library/Platform/Interface/Platform.h index 6788a70ef854..c4033a8b2146 100644 --- a/src/Library/Platform/Interface/Platform.h +++ b/src/Library/Platform/Interface/Platform.h @@ -15,7 +15,6 @@ class PlatformWindow; class PlatformEventLoop; class PlatformEventHandler; class PlatformGamepad; -class Logger; /** * Platform abstraction layer. diff --git a/src/Library/Platform/Null/NullEventLoop.cpp b/src/Library/Platform/Null/NullEventLoop.cpp index fbda9bcf262f..7283d517f4e3 100644 --- a/src/Library/Platform/Null/NullEventLoop.cpp +++ b/src/Library/Platform/Null/NullEventLoop.cpp @@ -2,6 +2,8 @@ #include +#include "Library/Logger/Logger.h" + NullEventLoop::NullEventLoop(NullPlatformSharedState *state): _state(state) { assert(state); } @@ -22,5 +24,5 @@ void NullEventLoop::processMessages(PlatformEventHandler *eventHandler, int coun void NullEventLoop::waitForMessages() { // Null platform doesn't receive messages. In theory, we should deadlock here, but this makes no sense tbh. - // TODO(captainurist): take in a logger after all, and log. + logger->error("Calls to NullEventLoop::waitForMessages should never happen. Null platform never waits."); } diff --git a/src/Library/Platform/Null/NullPlatform.cpp b/src/Library/Platform/Null/NullPlatform.cpp index a5c714c35296..3526e1879975 100644 --- a/src/Library/Platform/Null/NullPlatform.cpp +++ b/src/Library/Platform/Null/NullPlatform.cpp @@ -5,12 +5,14 @@ #include #include +#include "Library/Logger/Logger.h" + #include "NullPlatformSharedState.h" #include "NullWindow.h" #include "NullEventLoop.h" -NullPlatform::NullPlatform(NullPlatformOptions options): _state(std::make_unique()) { - _state->options = std::move(options); +NullPlatform::NullPlatform(NullPlatformOptions options): _state(std::make_unique(std::move(options))) { + assert(logger); // Some of NullPlatform classes log. } NullPlatform::~NullPlatform() = default; @@ -28,19 +30,22 @@ std::vector NullPlatform::gamepads() { } void NullPlatform::setCursorShown(bool cursorShown) { - _cursorShown = cursorShown; + _state->cursorShown = cursorShown; } bool NullPlatform::isCursorShown() const { - return _cursorShown; + return _state->cursorShown; } Pointi NullPlatform::getCursorPosition() const { - return Pointi{}; // Okay? + return _state->cursorPos; } void NullPlatform::setCursorPosition(const Pointi &position) const { - // Okay? + const Recti &screen = _state->options.displayGeometries[0]; + + _state->cursorPos = Pointi(std::clamp(position.x, screen.x, screen.x + screen.w - 1), + std::clamp(position.y, screen.y, screen.y + screen.h - 1)); } std::vector NullPlatform::displayGeometries() const { @@ -48,7 +53,7 @@ std::vector NullPlatform::displayGeometries() const { } void NullPlatform::showMessageBox(const std::string &title, const std::string &message) const { - // Okay? + // No GUI in null platform. } int64_t NullPlatform::tickCount() const { diff --git a/src/Library/Platform/Null/NullPlatform.h b/src/Library/Platform/Null/NullPlatform.h index 9a555a466727..5e3a16d956af 100644 --- a/src/Library/Platform/Null/NullPlatform.h +++ b/src/Library/Platform/Null/NullPlatform.h @@ -28,5 +28,4 @@ class NullPlatform : public Platform { private: std::unique_ptr _state; - bool _cursorShown = true; }; diff --git a/src/Library/Platform/Null/NullPlatformSharedState.h b/src/Library/Platform/Null/NullPlatformSharedState.h index cdd99292e92b..6a4c4586b8fa 100644 --- a/src/Library/Platform/Null/NullPlatformSharedState.h +++ b/src/Library/Platform/Null/NullPlatformSharedState.h @@ -1,7 +1,9 @@ #pragma once +#include #include #include +#include #include "NullPlatformOptions.h" @@ -9,7 +11,15 @@ class NullOpenGLContext; class NullPlatformSharedState { public: + NullPlatformSharedState(NullPlatformOptions options) { + assert(!options.displayGeometries.empty()); + + cursorPos = options.displayGeometries[0].topLeft(); + this->options = std::move(options); + } + NullPlatformOptions options; - uintptr_t nextWinId = 1; std::unordered_map contextByThreadId; + bool cursorShown = true; + Pointi cursorPos; }; From a87417bdbb2c2db258a0646be99a634643131e80 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:35:36 +0000 Subject: [PATCH 3/8] Add PlatformWindow::warpMouse, fix game tests --- src/Application/GameWindowHandler.cpp | 4 ++++ .../Control/EngineControlComponent.cpp | 1 + .../Components/Control/EngineControlState.h | 1 - src/Io/Mouse.cpp | 12 ++++++------ src/Library/Platform/Interface/Platform.h | 12 ------------ src/Library/Platform/Interface/PlatformEnums.h | 2 +- src/Library/Platform/Interface/PlatformWindow.h | 14 +++++++++++++- src/Library/Platform/Null/NullPlatform.cpp | 11 ----------- src/Library/Platform/Null/NullPlatform.h | 2 -- .../Platform/Null/NullPlatformSharedState.h | 2 +- src/Library/Platform/Null/NullWindow.cpp | 4 ++++ src/Library/Platform/Null/NullWindow.h | 1 + src/Library/Platform/Proxy/ProxyPlatform.cpp | 8 -------- src/Library/Platform/Proxy/ProxyPlatform.h | 2 -- src/Library/Platform/Proxy/ProxyWindow.cpp | 4 ++++ src/Library/Platform/Proxy/ProxyWindow.h | 1 + src/Library/Platform/Sdl/SdlPlatform.cpp | 16 ---------------- src/Library/Platform/Sdl/SdlPlatform.h | 3 --- src/Library/Platform/Sdl/SdlWindow.cpp | 4 ++++ src/Library/Platform/Sdl/SdlWindow.h | 2 ++ 20 files changed, 42 insertions(+), 64 deletions(-) diff --git a/src/Application/GameWindowHandler.cpp b/src/Application/GameWindowHandler.cpp index 67a242efba10..1d19293542ab 100644 --- a/src/Application/GameWindowHandler.cpp +++ b/src/Application/GameWindowHandler.cpp @@ -207,6 +207,8 @@ void GameWindowHandler::OnMouseLeftClick(Pointi position) { } else { pMediaPlayer->StopMovie(); + mouse->SetMousePosition(position.x, position.y); + if (GetCurrentMenuID() == MENU_CREATEPARTY) { UI_OnKeyDown(PlatformKey::KEY_SELECT); } @@ -226,6 +228,8 @@ void GameWindowHandler::OnMouseRightClick(Pointi position) { } else { pMediaPlayer->StopMovie(); + mouse->SetMousePosition(position.x, position.y); + if (engine) { engine->PickMouse(pCamera3D->GetMouseInfoDepth(), position.x, position.y, &vis_allsprites_filter, &vis_door_filter); } diff --git a/src/Engine/Components/Control/EngineControlComponent.cpp b/src/Engine/Components/Control/EngineControlComponent.cpp index a4da1347ffa2..aefba52a8af7 100644 --- a/src/Engine/Components/Control/EngineControlComponent.cpp +++ b/src/Engine/Components/Control/EngineControlComponent.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "Library/Platform/Interface/PlatformEventHandler.h" diff --git a/src/Engine/Components/Control/EngineControlState.h b/src/Engine/Components/Control/EngineControlState.h index 476ac218fcfb..0b4e95a2ae0e 100644 --- a/src/Engine/Components/Control/EngineControlState.h +++ b/src/Engine/Components/Control/EngineControlState.h @@ -5,7 +5,6 @@ #include #include #include -#include #include "Utility/IndexedArray.h" diff --git a/src/Io/Mouse.cpp b/src/Io/Mouse.cpp index 2bf908425b06..5dcfe02bd2e1 100644 --- a/src/Io/Mouse.cpp +++ b/src/Io/Mouse.cpp @@ -210,7 +210,7 @@ void Io::Mouse::SetMousePosition(int x, int y) { _mouseLookChange.y = y - uMouseY; if (_mouseLookChange.x != 0 || _mouseLookChange.y != 0) { pPartyActionQueue->Add(PARTY_MouseLook); - platform->setCursorPosition({ uMouseX, uMouseY }); // TODO(pskelton): this causes another mouse move event - might be better to poll mouse position once per frame rather than on event + window->warpMouse({uMouseX, uMouseY}); // TODO(pskelton): this causes another mouse move event - might be better to poll mouse position once per frame rather than on event } } else { uMouseX = x; @@ -312,7 +312,7 @@ void Io::Mouse::UI_OnMouseLeftClick() { void Io::Mouse::SetMouseLook(bool enable) { _mouseLook = enable; if (enable) { - platform->setCursorPosition({ uMouseX, uMouseY }); + window->warpMouse({uMouseX, uMouseY}); } } @@ -326,10 +326,10 @@ void Io::Mouse::DoMouseLook() { } const float sensitivity = 5.0f; // TODO(pskelton): move to config value - float modX = engine->mouse->_mouseLookChange.x * sensitivity; - float modY = engine->mouse->_mouseLookChange.y * sensitivity; - engine->mouse->_mouseLookChange.x = 0; - engine->mouse->_mouseLookChange.y = 0; + float modX = _mouseLookChange.x * sensitivity; + float modY = _mouseLookChange.y * sensitivity; + _mouseLookChange.x = 0; + _mouseLookChange.y = 0; pParty->_viewPitch -= modY; pParty->_viewPitch = std::clamp(pParty->_viewPitch, -128, 128); pParty->_viewYaw -= modX; diff --git a/src/Library/Platform/Interface/Platform.h b/src/Library/Platform/Interface/Platform.h index c4033a8b2146..11e00db587bc 100644 --- a/src/Library/Platform/Interface/Platform.h +++ b/src/Library/Platform/Interface/Platform.h @@ -114,18 +114,6 @@ class Platform { */ virtual bool isCursorShown() const = 0; - /** - * Gets the global mouse cursor position. - */ - virtual Pointi getCursorPosition() const = 0; - - /** - * Sets the global mouse cursor position. - * - * @param pos Position of where to place the cursor. - */ - virtual void setCursorPosition(const Pointi &pos) const = 0; - /** * @return Geometries of all monitors on current system, or an empty vector in case of an * error. diff --git a/src/Library/Platform/Interface/PlatformEnums.h b/src/Library/Platform/Interface/PlatformEnums.h index 368e666a2c38..40b48e298e9a 100644 --- a/src/Library/Platform/Interface/PlatformEnums.h +++ b/src/Library/Platform/Interface/PlatformEnums.h @@ -60,7 +60,7 @@ enum class PlatformEventType { /** Gamepad axis event, sent as `PlatformGamepadAxisEvent`. */ EVENT_GAMEPAD_AXIS, - /** Gamepad axis event, sent as `PlatformTextInputEvent`. */ + /** Text input event, sent as `PlatformTextInputEvent`. */ EVENT_TEXT_INPUT, /** Native event, sent as `PlatformNativeEvent`. */ diff --git a/src/Library/Platform/Interface/PlatformWindow.h b/src/Library/Platform/Interface/PlatformWindow.h index 792d9d350e0e..6fb381d9453d 100644 --- a/src/Library/Platform/Interface/PlatformWindow.h +++ b/src/Library/Platform/Interface/PlatformWindow.h @@ -56,11 +56,23 @@ class PlatformWindow { virtual Marginsi frameMargins() const = 0; /** - * @return Pointer to the native window, e.g. `SDL_window` on SDL. + * @return Pointer to the native window, e.g. `SDL_window` on SDL. */ virtual void *nativeHandle() const = 0; virtual void activate() = 0; + /** + * Moves the mouse pointer inside this window. + * + * Note that this function has no corresponding getter, and this is intentional. Mouse pointer coords are passed + * in mouse events, and it's the only place to get them from. + * + * Also note that this call might generate an `EVENT_MOUSE_MOVE` event. + * + * @param position Position in window coordinates to move mouse pointer to. + */ + virtual void warpMouse(Pointi position) = 0; + virtual std::unique_ptr createOpenGLContext(const PlatformOpenGLOptions &options) = 0; }; diff --git a/src/Library/Platform/Null/NullPlatform.cpp b/src/Library/Platform/Null/NullPlatform.cpp index 3526e1879975..42bd51b965c8 100644 --- a/src/Library/Platform/Null/NullPlatform.cpp +++ b/src/Library/Platform/Null/NullPlatform.cpp @@ -37,17 +37,6 @@ bool NullPlatform::isCursorShown() const { return _state->cursorShown; } -Pointi NullPlatform::getCursorPosition() const { - return _state->cursorPos; -} - -void NullPlatform::setCursorPosition(const Pointi &position) const { - const Recti &screen = _state->options.displayGeometries[0]; - - _state->cursorPos = Pointi(std::clamp(position.x, screen.x, screen.x + screen.w - 1), - std::clamp(position.y, screen.y, screen.y + screen.h - 1)); -} - std::vector NullPlatform::displayGeometries() const { return _state->options.displayGeometries; } diff --git a/src/Library/Platform/Null/NullPlatform.h b/src/Library/Platform/Null/NullPlatform.h index 5e3a16d956af..f577b55bd4da 100644 --- a/src/Library/Platform/Null/NullPlatform.h +++ b/src/Library/Platform/Null/NullPlatform.h @@ -20,8 +20,6 @@ class NullPlatform : public Platform { virtual std::vector gamepads() override; virtual void setCursorShown(bool cursorShown) override; virtual bool isCursorShown() const override; - virtual Pointi getCursorPosition() const override; - virtual void setCursorPosition(const Pointi &position) const override; virtual std::vector displayGeometries() const override; virtual void showMessageBox(const std::string &title, const std::string &message) const override; virtual int64_t tickCount() const override; diff --git a/src/Library/Platform/Null/NullPlatformSharedState.h b/src/Library/Platform/Null/NullPlatformSharedState.h index 6a4c4586b8fa..699ae03a8e6d 100644 --- a/src/Library/Platform/Null/NullPlatformSharedState.h +++ b/src/Library/Platform/Null/NullPlatformSharedState.h @@ -11,7 +11,7 @@ class NullOpenGLContext; class NullPlatformSharedState { public: - NullPlatformSharedState(NullPlatformOptions options) { + explicit NullPlatformSharedState(NullPlatformOptions options) { assert(!options.displayGeometries.empty()); cursorPos = options.displayGeometries[0].topLeft(); diff --git a/src/Library/Platform/Null/NullWindow.cpp b/src/Library/Platform/Null/NullWindow.cpp index de2335f25386..5dfa9236c28c 100644 --- a/src/Library/Platform/Null/NullWindow.cpp +++ b/src/Library/Platform/Null/NullWindow.cpp @@ -96,6 +96,10 @@ void NullWindow::activate() { // Do nothing. } +void NullWindow::warpMouse(Pointi) { + // Do nothing. +} + std::unique_ptr NullWindow::createOpenGLContext(const PlatformOpenGLOptions &options) { return std::make_unique(_state); } diff --git a/src/Library/Platform/Null/NullWindow.h b/src/Library/Platform/Null/NullWindow.h index 4b717e0ca7d5..bba55881a1ef 100644 --- a/src/Library/Platform/Null/NullWindow.h +++ b/src/Library/Platform/Null/NullWindow.h @@ -31,6 +31,7 @@ class NullWindow : public PlatformWindow { virtual Marginsi frameMargins() const override; virtual void *nativeHandle() const override; virtual void activate() override; + virtual void warpMouse(Pointi position) override; virtual std::unique_ptr createOpenGLContext(const PlatformOpenGLOptions &options) override; private: diff --git a/src/Library/Platform/Proxy/ProxyPlatform.cpp b/src/Library/Platform/Proxy/ProxyPlatform.cpp index 28365b40d8c5..92788790f13e 100644 --- a/src/Library/Platform/Proxy/ProxyPlatform.cpp +++ b/src/Library/Platform/Proxy/ProxyPlatform.cpp @@ -29,14 +29,6 @@ bool ProxyPlatform::isCursorShown() const { return nonNullBase()->isCursorShown(); } -Pointi ProxyPlatform::getCursorPosition() const { - return nonNullBase()->getCursorPosition(); -} - -void ProxyPlatform::setCursorPosition(const Pointi& position) const { - nonNullBase()->setCursorPosition(position); -} - std::vector ProxyPlatform::displayGeometries() const { return nonNullBase()->displayGeometries(); } diff --git a/src/Library/Platform/Proxy/ProxyPlatform.h b/src/Library/Platform/Proxy/ProxyPlatform.h index 251729ca3b17..d4958d7c1838 100644 --- a/src/Library/Platform/Proxy/ProxyPlatform.h +++ b/src/Library/Platform/Proxy/ProxyPlatform.h @@ -19,8 +19,6 @@ class ProxyPlatform : public ProxyBase { virtual std::vector gamepads() override; virtual void setCursorShown(bool cursorShown) override; virtual bool isCursorShown() const override; - virtual Pointi getCursorPosition() const override; - virtual void setCursorPosition(const Pointi& position) const override; virtual std::vector displayGeometries() const override; virtual void showMessageBox(const std::string &title, const std::string &message) const override; virtual int64_t tickCount() const override; diff --git a/src/Library/Platform/Proxy/ProxyWindow.cpp b/src/Library/Platform/Proxy/ProxyWindow.cpp index db0116a0a8a5..0da41514e5cc 100644 --- a/src/Library/Platform/Proxy/ProxyWindow.cpp +++ b/src/Library/Platform/Proxy/ProxyWindow.cpp @@ -83,6 +83,10 @@ void ProxyWindow::activate() { nonNullBase()->activate(); } +void ProxyWindow::warpMouse(Pointi position) { + nonNullBase()->warpMouse(position); +} + std::unique_ptr ProxyWindow::createOpenGLContext(const PlatformOpenGLOptions &options) { return nonNullBase()->createOpenGLContext(options); } diff --git a/src/Library/Platform/Proxy/ProxyWindow.h b/src/Library/Platform/Proxy/ProxyWindow.h index eb3afb9b91d3..c8a575a3e2ea 100644 --- a/src/Library/Platform/Proxy/ProxyWindow.h +++ b/src/Library/Platform/Proxy/ProxyWindow.h @@ -31,5 +31,6 @@ class ProxyWindow : public ProxyBase { virtual Marginsi frameMargins() const override; virtual void *nativeHandle() const override; virtual void activate() override; + virtual void warpMouse(Pointi position) override; virtual std::unique_ptr createOpenGLContext(const PlatformOpenGLOptions &options) override; }; diff --git a/src/Library/Platform/Sdl/SdlPlatform.cpp b/src/Library/Platform/Sdl/SdlPlatform.cpp index 6101a99015f9..81e93077d634 100644 --- a/src/Library/Platform/Sdl/SdlPlatform.cpp +++ b/src/Library/Platform/Sdl/SdlPlatform.cpp @@ -103,22 +103,6 @@ bool SdlPlatform::isCursorShown() const { } } -Pointi SdlPlatform::getCursorPosition() const { - if (!_initialized) - return {}; - - Pointi result; - SDL_GetMouseState(&result.x, &result.y); - - return result; -} - -void SdlPlatform::setCursorPosition(const Pointi &position) const { - if (!_initialized) - return; - SDL_WarpMouseGlobal(position.x, position.y); -} - std::vector SdlPlatform::displayGeometries() const { if (!_initialized) return {}; diff --git a/src/Library/Platform/Sdl/SdlPlatform.h b/src/Library/Platform/Sdl/SdlPlatform.h index a9b55a3f7535..da6bdcceb20b 100644 --- a/src/Library/Platform/Sdl/SdlPlatform.h +++ b/src/Library/Platform/Sdl/SdlPlatform.h @@ -23,9 +23,6 @@ class SdlPlatform: public Platform { virtual void setCursorShown(bool cursorShown) override; virtual bool isCursorShown() const override; - virtual Pointi getCursorPosition() const override; - virtual void setCursorPosition(const Pointi& position) const override; - virtual std::vector displayGeometries() const override; virtual void showMessageBox(const std::string &title, const std::string &message) const override; diff --git a/src/Library/Platform/Sdl/SdlWindow.cpp b/src/Library/Platform/Sdl/SdlWindow.cpp index ec3d57c2303e..ac5c475bc51b 100644 --- a/src/Library/Platform/Sdl/SdlWindow.cpp +++ b/src/Library/Platform/Sdl/SdlWindow.cpp @@ -170,6 +170,10 @@ void SdlWindow::activate() { SDL_RaiseWindow(_window); } +void SdlWindow::warpMouse(Pointi position) { + SDL_WarpMouseInWindow(_window, position.x, position.y); +} + std::unique_ptr SdlWindow::createOpenGLContext(const PlatformOpenGLOptions &options) { int version; diff --git a/src/Library/Platform/Sdl/SdlWindow.h b/src/Library/Platform/Sdl/SdlWindow.h index f028db951b9c..e4ae591d76ea 100644 --- a/src/Library/Platform/Sdl/SdlWindow.h +++ b/src/Library/Platform/Sdl/SdlWindow.h @@ -45,6 +45,8 @@ class SdlWindow : public PlatformWindow { virtual void activate() override; + virtual void warpMouse(Pointi position) override; + virtual std::unique_ptr createOpenGLContext(const PlatformOpenGLOptions &options) override; uint32_t id() const { From 4faae138c3a820dda3583dcf3e80976c9d99461b Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:00:13 +0000 Subject: [PATCH 4/8] Revert "Merge pull request #1905 from pskelton/invpick" This reverts commit 620c65ff78f8243313304d0ebb5a7c8a32169736, reversing changes made to fe0ebb8169867fc696689e3a18a6b0a4301e7468. --- src/Engine/Objects/Character.cpp | 199 +++++++++++++++---------------- src/Engine/Objects/Character.h | 2 +- src/Engine/Objects/Chest.cpp | 19 +-- src/Engine/Party.cpp | 4 +- src/Engine/Party.h | 2 +- src/GUI/GUIWindow.h | 1 - src/GUI/UI/UICharacter.cpp | 22 ---- src/GUI/UI/UIChest.cpp | 5 - src/GUI/UI/UIHouses.cpp | 1 + src/Io/Mouse.cpp | 15 ++- src/Io/Mouse.h | 7 +- 11 files changed, 117 insertions(+), 160 deletions(-) diff --git a/src/Engine/Objects/Character.cpp b/src/Engine/Objects/Character.cpp index cf0e8845df66..d1cb95512eee 100644 --- a/src/Engine/Objects/Character.cpp +++ b/src/Engine/Objects/Character.cpp @@ -51,7 +51,6 @@ #include "GUI/UI/UISpell.h" #include "GUI/UI/UIDialogue.h" #include "GUI/UI/Books/AutonotesBook.h" -#include "GUI/UI/ItemGrid.h" #include "Library/Logger/Logger.h" @@ -651,7 +650,7 @@ int Character::CreateItemInInventory(unsigned int uSlot, ItemId uItemID) { return 0; } else { // place items - PutItemAtInventoryIndex(uItemID, freeSlot, uSlot); + PutItemArInventoryIndex(uItemID, freeSlot, uSlot); this->pInventoryItemList[freeSlot].uItemID = uItemID; } @@ -739,7 +738,7 @@ int Character::CreateItemInInventory2(unsigned int index, if (freeSlot == -1) { // no room result = 0; } else { - PutItemAtInventoryIndex(Src->uItemID, freeSlot, index); + PutItemArInventoryIndex(Src->uItemID, freeSlot, index); pInventoryItemList[freeSlot] = *Src; result = freeSlot + 1; } @@ -748,7 +747,7 @@ int Character::CreateItemInInventory2(unsigned int index, } //----- (0049298B) -------------------------------------------------------- -void Character::PutItemAtInventoryIndex( +void Character::PutItemArInventoryIndex( ItemId uItemID, int itemListPos, int index) { // originally accepted ItemGen *but needed only its uItemID @@ -6558,115 +6557,113 @@ void DamageCharacterFromMonster(Pid uObjID, ActorAbility dmgSource, signed int t } void Character::OnInventoryLeftClick() { - if (current_character_screen_window != WINDOW_CharacterWindow_Inventory) { - return; - } + ItemId pickedItemId; // esi@12 + unsigned int invItemIndex; // eax@12 + unsigned int itemPos; // eax@18 + ItemGen tmpItem; // [sp+Ch] [bp-3Ch]@1 + + CastSpellInfo *pSpellInfo; + + if (current_character_screen_window == WINDOW_CharacterWindow_Inventory) { + int pY; + int pX; + mouse->GetClickPos(&pX, &pY); + + int inventoryYCoord = (pY - 17) / 32; + int inventoryXCoord = (pX - 14) / 32; + int invMatrixIndex = inventoryXCoord + (INVENTORY_SLOTS_WIDTH * inventoryYCoord); + + if (inventoryYCoord >= 0 && inventoryYCoord < INVENTORY_SLOTS_HEIGHT && + inventoryXCoord >= 0 && inventoryXCoord < INVENTORY_SLOTS_WIDTH) { + if (IsEnchantingInProgress) { + unsigned int enchantedItemPos = this->GetItemListAtInventoryIndex(invMatrixIndex); + + if (enchantedItemPos) { + /* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &= + *0x7Fu; + *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) = + *pParty->activeCharacterIndex() - 1; + *((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = + *enchantedItemPos - 1; + *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = + *invMatrixIndex;*/ + pSpellInfo = pGUIWindow_CastTargetedSpell->spellInfo(); + pSpellInfo->flags &= ~ON_CAST_TargetedEnchantment; + pSpellInfo->targetCharacterIndex = pParty->activeCharacterIndex() - 1; + pSpellInfo->targetInventoryIndex = enchantedItemPos - 1; + ptr_50C9A4_ItemToEnchant = &this->pInventoryItemList[enchantedItemPos - 1]; + IsEnchantingInProgress = false; + + engine->_messageQueue->clear(); + + mouse->SetCursorImage("MICON1"); + AfterEnchClickEventId = UIMSG_Escape; + AfterEnchClickEventSecondParam = 0; + AfterEnchClickEventTimeout = Duration::fromRealtimeSeconds(2); + } - int pY; - int pX; - mouse->GetClickPos(&pX, &pY); - - int inventoryXCoord = (pX + mouse->pickedItemOffsetX - 14) / 32; - int inventoryYCoord = (pY + mouse->pickedItemOffsetY - 17) / 32; - int invMatrixIndex = inventoryXCoord + (INVENTORY_SLOTS_WIDTH * inventoryYCoord); - - if (inventoryYCoord >= 0 && inventoryYCoord < INVENTORY_SLOTS_HEIGHT && - inventoryXCoord >= 0 && inventoryXCoord < INVENTORY_SLOTS_WIDTH) { - if (IsEnchantingInProgress) { - unsigned int enchantedItemPos = this->GetItemListAtInventoryIndex(invMatrixIndex); - - if (enchantedItemPos) { - /* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &= - *0x7Fu; - *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) = - *pParty->activeCharacterIndex() - 1; - *((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = - *enchantedItemPos - 1; - *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = - *invMatrixIndex;*/ - CastSpellInfo* pSpellInfo; - pSpellInfo = pGUIWindow_CastTargetedSpell->spellInfo(); - pSpellInfo->flags &= ~ON_CAST_TargetedEnchantment; - pSpellInfo->targetCharacterIndex = pParty->activeCharacterIndex() - 1; - pSpellInfo->targetInventoryIndex = enchantedItemPos - 1; - ptr_50C9A4_ItemToEnchant = &this->pInventoryItemList[enchantedItemPos - 1]; - IsEnchantingInProgress = false; - - engine->_messageQueue->clear(); - - mouse->SetCursorImage("MICON1"); - AfterEnchClickEventId = UIMSG_Escape; - AfterEnchClickEventSecondParam = 0; - AfterEnchClickEventTimeout = Duration::fromRealtimeSeconds(2); + return; } - return; - } + if (ptr_50C9A4_ItemToEnchant) + return; - if (ptr_50C9A4_ItemToEnchant) - return; + pickedItemId = pParty->pPickedItem.uItemID; + invItemIndex = this->GetItemListAtInventoryIndex(invMatrixIndex); - auto item = this->GetItemAtInventoryIndex(invMatrixIndex); - if (!item && pParty->pPickedItem.uItemID == ITEM_NULL) { - return; // nothing to do - } - - // calc offsets of where on the item was clicked - // first need index of top left corner of the item - int cornerInd = GetItemMainInventoryIndex(invMatrixIndex); - int cornerX = cornerInd % INVENTORY_SLOTS_WIDTH; - int cornerY = cornerInd / INVENTORY_SLOTS_WIDTH; - int itemXOffset = pX + mouse->pickedItemOffsetX - 14 - (cornerX * 32); - int itemYOffset = pY + mouse->pickedItemOffsetY - 17 - (cornerY * 32); - - if (item) { - auto tex = assets->getImage_Alpha(item->GetIconName()); - itemXOffset -= itemOffset(tex->width()); - itemYOffset -= itemOffset(tex->height()); - } + if (pickedItemId == ITEM_NULL) { // no hold item + if (!invItemIndex) { + return; + } else { + pParty->pPickedItem = this->pInventoryItemList[invItemIndex - 1]; + this->RemoveItemAtInventoryIndex(invMatrixIndex); + pickedItemId = pParty->pPickedItem.uItemID; + mouse->SetCursorImage(pItemTable->pItems[pickedItemId].iconName); + return; + } + } else { // hold item + if (invItemIndex) { + ItemGen *invItemPtr = &this->pInventoryItemList[invItemIndex - 1]; + tmpItem = *invItemPtr; + int oldinvMatrixIndex = invMatrixIndex; + invMatrixIndex = GetItemMainInventoryIndex(invMatrixIndex); + this->RemoveItemAtInventoryIndex(oldinvMatrixIndex); + int emptyIndex = this->AddItem2(invMatrixIndex, &pParty->pPickedItem); - if (pParty->pPickedItem.uItemID == ITEM_NULL) { - // pick up the item - pParty->setHoldingItem(item, -itemXOffset, -itemYOffset); - this->RemoveItemAtInventoryIndex(invMatrixIndex); - return; - } else { - if (item) { - // swap items - ItemGen tmpItem = *item; - int oldinvMatrixIndex = invMatrixIndex; - this->RemoveItemAtInventoryIndex(invMatrixIndex); - invMatrixIndex = GetItemMainInventoryIndex(invMatrixIndex); - int invItemIndex = this->GetItemListAtInventoryIndex(invMatrixIndex); - - // try to add where we clicked - int emptyIndex = this->AddItem2(invMatrixIndex, &pParty->pPickedItem); - if (!emptyIndex) { - // try to add anywhere - emptyIndex = this->AddItem2(-1, &pParty->pPickedItem); if (!emptyIndex) { - // failed to add, put back the old item - this->PutItemAtInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex); + emptyIndex = this->AddItem2(-1, &pParty->pPickedItem); + if (!emptyIndex) { + this->PutItemArInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex); + *invItemPtr = tmpItem; + return; + } + } + + pParty->pPickedItem = tmpItem; + mouse->SetCursorImage(pParty->pPickedItem.GetIconName()); + return; + } else { + itemPos = this->AddItem(invMatrixIndex, pickedItemId); + + if (itemPos) { + this->pInventoryItemList[itemPos - 1] = pParty->pPickedItem; + mouse->RemoveHoldingItem(); return; } - } - mouse->RemoveHoldingItem(); - pParty->setHoldingItem(&tmpItem); - return; - } else { - // place picked item - int itemPos = this->AddItem(invMatrixIndex, pParty->pPickedItem.uItemID); + // itemPos = this->AddItem(-1, pickedItemId); - if (itemPos) { - this->pInventoryItemList[itemPos - 1] = pParty->pPickedItem; - mouse->RemoveHoldingItem(); - return; + // if ( itemPos ) { + // memcpy(&this->pInventoryItemList[itemPos-1], + // &pParty->pPickedItem, sizeof(ItemGen)); + // pMouse->RemoveHoldingItem(); + // return; + // } } - } - } - } -} + } // held item or no + } // limits + } // char wind +} // func bool Character::IsWeak() const { return this->conditions.Has(CONDITION_WEAK); diff --git a/src/Engine/Objects/Character.h b/src/Engine/Objects/Character.h index 9d53d06fab7d..e55a7e2f78e9 100644 --- a/src/Engine/Objects/Character.h +++ b/src/Engine/Objects/Character.h @@ -253,7 +253,7 @@ class Character { int AddItem(int uSlot, ItemId uItemID); int AddItem2(int uSlot, ItemGen *Src); int CreateItemInInventory2(unsigned int index, ItemGen *Src); - void PutItemAtInventoryIndex(ItemId uItemID, int itemListPos, int uSlot); + void PutItemArInventoryIndex(ItemId uItemID, int itemListPos, int uSlot); void RemoveItemAtInventoryIndex(unsigned int uSlot); bool CanAct() const; bool CanSteal() const; diff --git a/src/Engine/Objects/Chest.cpp b/src/Engine/Objects/Chest.cpp index 8bc927d7987d..a5a6c2580051 100644 --- a/src/Engine/Objects/Chest.cpp +++ b/src/Engine/Objects/Chest.cpp @@ -26,7 +26,6 @@ #include "GUI/UI/UIChest.h" #include "GUI/UI/UIStatusBar.h" -#include "GUI/UI/ItemGrid.h" #include "Io/Mouse.h" @@ -453,9 +452,9 @@ void Chest::OnChestLeftClick() { int pX; int pY; mouse->GetClickPos(&pX, &pY); + int inventoryYCoord = (pY - (pChestPixelOffsetY[chest->uChestBitmapID])) / 32; + int inventoryXCoord = (pX - (pChestPixelOffsetX[chest->uChestBitmapID])) / 32; - int inventoryYCoord = (pY + mouse->pickedItemOffsetY - (pChestPixelOffsetY[chest->uChestBitmapID])) / 32; - int inventoryXCoord = (pX + mouse->pickedItemOffsetX - (pChestPixelOffsetX[chest->uChestBitmapID])) / 32; int invMatrixIndex = inventoryXCoord + (chestheight * inventoryYCoord); if (inventoryYCoord >= 0 && inventoryYCoord < chestheight && @@ -477,19 +476,7 @@ void Chest::OnChestLeftClick() { if (chest->igChestItems[itemindex].isGold()) { pParty->partyFindsGold(chest->igChestItems[itemindex].goldAmount, GOLD_RECEIVE_SHARE); } else { - // calc offsets of where on the item was clicked - // first need index of top left corner of the item - int cornerX = invMatrixIndex % chestwidth; - int cornerY = invMatrixIndex / chestwidth; - int itemXOffset = pX + mouse->pickedItemOffsetX - pChestPixelOffsetX[chest->uChestBitmapID] - (cornerX * 32); - int itemYOffset = pY + mouse->pickedItemOffsetY - pChestPixelOffsetY[chest->uChestBitmapID] - (cornerY * 32); - - auto item = &chest->igChestItems[itemindex]; - auto tex = assets->getImage_Alpha(item->GetIconName()); - itemXOffset -= itemOffset(tex->width()); - itemYOffset -= itemOffset(tex->height()); - - pParty->setHoldingItem(item, -itemXOffset, -itemYOffset); + pParty->setHoldingItem(&chest->igChestItems[itemindex]); } RemoveItemAtChestIndex(invMatrixIndex); diff --git a/src/Engine/Party.cpp b/src/Engine/Party.cpp index 9e46b62aa9a0..9a3f8a25a106 100644 --- a/src/Engine/Party.cpp +++ b/src/Engine/Party.cpp @@ -189,12 +189,10 @@ int Party::canActCount() const { return result; } -void Party::setHoldingItem(ItemGen *pItem, int offsetX, int offsetY) { +void Party::setHoldingItem(ItemGen *pItem) { placeHeldItemInInventoryOrDrop(); pPickedItem = *pItem; mouse->SetCursorBitmapFromItemID(pPickedItem.uItemID); - mouse->pickedItemOffsetX = offsetX; - mouse->pickedItemOffsetY = offsetY; } void Party::setActiveToFirstCanAct() { // added to fix some nzi problems entering shops diff --git a/src/Engine/Party.h b/src/Engine/Party.h index dd23c623ab37..34834be63a64 100644 --- a/src/Engine/Party.h +++ b/src/Engine/Party.h @@ -79,7 +79,7 @@ struct Party { /** * @offset 0x4936E1 */ - void setHoldingItem(ItemGen *pItem, int offsetX = 0, int offsetY = 0); + void setHoldingItem(ItemGen *pItem); /** * Sets _activeCharacter to the first character that can act diff --git a/src/GUI/GUIWindow.h b/src/GUI/GUIWindow.h index a34769978add..430f87d1f606 100644 --- a/src/GUI/GUIWindow.h +++ b/src/GUI/GUIWindow.h @@ -260,7 +260,6 @@ void CharacterUI_InventoryTab_Draw(Character *player, bool a2); void CharacterUI_DrawPaperdoll(Character *player); void CharacterUI_DrawPaperdollWithRingOverlay(Character *player); void CharacterUI_ReleaseButtons(); -void CharacterUI_DrawPickedItemUnderlay(Vec2i offset); /** * @offset 0x417AD4 diff --git a/src/GUI/UI/UICharacter.cpp b/src/GUI/UI/UICharacter.cpp index a8845800c99e..240ee9ea1ca5 100644 --- a/src/GUI/UI/UICharacter.cpp +++ b/src/GUI/UI/UICharacter.cpp @@ -10,7 +10,6 @@ #include "Engine/AssetsManager.h" #include "Engine/Engine.h" #include "Engine/EngineGlobals.h" -#include "Engine/Objects/Character.h" #include "Engine/Objects/CharacterEnumFunctions.h" #include "Engine/Graphics/Renderer/Renderer.h" #include "Engine/Graphics/Viewport.h" @@ -1285,10 +1284,6 @@ void CharacterUI_InventoryTab_Draw(Character *player, bool Cover_Strip) { render->DrawTextureNew(8 / 640.0f, 305 / 480.0f, ui_character_inventory_background_strip); } - render->SetUIClipRect({ 14, 17, 32 * 14, 32 * 9 }); - CharacterUI_DrawPickedItemUnderlay({ 14, 17 }); - render->ResetUIClipRect(); - for (unsigned i = 0; i < 126; ++i) { if (player->pInventoryMatrix[i] <= 0) continue; if (player->pInventoryItemList[player->pInventoryMatrix[i] - 1].uItemID == ITEM_NULL) @@ -1304,23 +1299,6 @@ void CharacterUI_InventoryTab_Draw(Character *player, bool Cover_Strip) { } } -void CharacterUI_DrawPickedItemUnderlay(Vec2i offset) { - if (pParty->pPickedItem.uItemID != ITEM_NULL) { - // draw shadow of position - int pY; - int pX; - mouse->GetClickPos(&pX, &pY); - - int inventoryXCoord = (pX + mouse->pickedItemOffsetX - offset.x) / 32; - int inventoryYCoord = (pY + mouse->pickedItemOffsetY - offset.y) / 32; - auto img = assets->getImage_Alpha(pParty->pPickedItem.GetIconName()); - int itemWidth = GetSizeInInventorySlots(img->width()); - int itemHeight = GetSizeInInventorySlots(img->height()); - - render->FillRectFast(inventoryXCoord * 32 + offset.x, inventoryYCoord * 32 + offset.y, itemWidth * 32, itemHeight * 32, Color(96, 96, 96, 128)); - } -} - static void CharacterUI_DrawItem(int x, int y, ItemGen *item, int id, GraphicsImage *item_texture, bool doZDraw) { if (!item_texture) item_texture = assets->getImage_Alpha(item->GetIconName()); diff --git a/src/GUI/UI/UIChest.cpp b/src/GUI/UI/UIChest.cpp index c6e3dcaf46f7..d86a95655238 100644 --- a/src/GUI/UI/UIChest.cpp +++ b/src/GUI/UI/UIChest.cpp @@ -47,10 +47,6 @@ void GUIWindow_Chest::Update() { GraphicsImage *chest_background = assets->getImage_ColorKey(fmt::format("chest{:02}", pChestList->vChests[chestBitmapId].uTextureID)); render->DrawTextureNew(8 / 640.0f, 8 / 480.0f, chest_background); - render->SetUIClipRect({ chest_offs_x, chest_offs_y, 32 * chestWidthCells, 32 * chestHeghtCells }); - CharacterUI_DrawPickedItemUnderlay({ chest_offs_x, chest_offs_y }); - render->ResetUIClipRect(); - for (int item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter) { int chest_item_index = vChests[uChestID].pInventoryIndices[item_counter]; if (chest_item_index > 0) { @@ -65,7 +61,6 @@ void GUIWindow_Chest::Update() { render->DrawTextureNew(itemPixelPosX / 640.0f, itemPixelPosY / 480.0f, item_texture); } } - render->DrawTextureNew(pBtn_ExitCancel->uX / 640.0f, pBtn_ExitCancel->uY / 480.0f, ui_exit_cancel_button_background); } } diff --git a/src/GUI/UI/UIHouses.cpp b/src/GUI/UI/UIHouses.cpp index 993613f7e7e9..560d31324527 100644 --- a/src/GUI/UI/UIHouses.cpp +++ b/src/GUI/UI/UIHouses.cpp @@ -675,6 +675,7 @@ void createHouseUI(HouseId houseId) { // TODO(Nik-RE-dev): looks like this function is not needed anymore void BackToHouseMenu() { auto pMouse = EngineIocContainer::ResolveMouse(); + pMouse->ClearPickedItem(); // TODO(Nik-RE-dev): Looks like it's artifact of MM6 #if 0 if (window_SpeakInHouse && window_SpeakInHouse->houseId() == 165 && diff --git a/src/Io/Mouse.cpp b/src/Io/Mouse.cpp index 5dcfe02bd2e1..ef5146e1ab73 100644 --- a/src/Io/Mouse.cpp +++ b/src/Io/Mouse.cpp @@ -40,8 +40,6 @@ void Io::Mouse::RemoveHoldingItem() { if (this->cursor_name != "MICON2") { SetCursorImage("MICON1"); } - pickedItemOffsetX = 0; - pickedItemOffsetY = 0; } void Io::Mouse::SetCursorBitmapFromItemID(ItemId uItemID) { @@ -117,6 +115,8 @@ void Io::Mouse::DrawCursor() { if (pParty->pPickedItem.uItemID != ITEM_NULL) { DrawPickedItem(); } else { + ClearPickedItem(); + // for other cursor img ie target mouse if (this->cursor_img) { platform->setCursorShown(false); @@ -185,6 +185,8 @@ void Io::Mouse::DrawCursor() { */ } +void Io::Mouse::ClearPickedItem() { pPickedItem = nullptr; } + void Io::Mouse::DrawPickedItem() { if (pParty->pPickedItem.uItemID == ITEM_NULL) return; @@ -192,15 +194,12 @@ void Io::Mouse::DrawPickedItem() { GraphicsImage *pTexture = assets->getImage_Alpha(pParty->pPickedItem.GetIconName()); if (!pTexture) return; - float posX = (uMouseX + pickedItemOffsetX) / 640.0f; - float posY = (uMouseY + pickedItemOffsetY) / 480.0f; - if (pParty->pPickedItem.IsBroken()) { - render->DrawTransparentRedShade(posX, posY, pTexture); + render->DrawTransparentRedShade(uMouseX / 640.0f, uMouseY / 480.0f, pTexture); } else if (!pParty->pPickedItem.IsIdentified()) { - render->DrawTransparentGreenShade(posX, posY, pTexture); + render->DrawTransparentGreenShade(uMouseX / 640.0f, uMouseY / 480.0f, pTexture); } else { - render->DrawTextureNew(posX, posY, pTexture); + render->DrawTextureNew(uMouseX / 640.0f, uMouseY / 480.0f, pTexture); } } diff --git a/src/Io/Mouse.h b/src/Io/Mouse.h index 3f4238f9f845..469bf9e2a458 100644 --- a/src/Io/Mouse.h +++ b/src/Io/Mouse.h @@ -16,6 +16,7 @@ class Mouse { inline Mouse() : cursor_img(nullptr) { pCursorBitmap_sysmem = nullptr; pCursorBitmap2_sysmem = nullptr; + pPickedItem = nullptr; uMouseX = 0; uMouseY = 0; } @@ -31,6 +32,7 @@ class Mouse { Pointi GetCursorPos(); void Initialize(); void DrawCursor(); + void ClearPickedItem(); void DrawPickedItem(); void SetMousePosition(int x, int y); @@ -47,8 +49,9 @@ class Mouse { GraphicsImage *cursor_img = nullptr; uint16_t *pCursorBitmap_sysmem = nullptr; uint8_t *pCursorBitmap2_sysmem = nullptr; - int pickedItemOffsetX = 0; - int pickedItemOffsetY = 0; + GraphicsImage *pPickedItem = nullptr; + int uCursorWithItemX = 0; + int uCursorWithItemY = 0; Pointi pCursorBitmapPos{}; std::string cursor_name; int uMouseX = 0; From 2cb29e310d0caf1026e1d5e7aed219ea7b006ca0 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:09:58 +0000 Subject: [PATCH 5/8] Retrace for changes in character condition handling --- test/Bin/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Bin/CMakeLists.txt b/test/Bin/CMakeLists.txt index b55d5dfedd76..ead37ba08f73 100644 --- a/test/Bin/CMakeLists.txt +++ b/test/Bin/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) ExternalProject_Add(OpenEnroth_TestData PREFIX ${CMAKE_CURRENT_BINARY_DIR}/test_data_tmp GIT_REPOSITORY https://github.com/OpenEnroth/OpenEnroth_TestData.git - GIT_TAG c7806b37639ab428bc51ab401ecf38294d84fac8 + GIT_TAG 7c801f9423f5aa69a1a5c4571234871d599790db SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_data CONFIGURE_COMMAND "" BUILD_COMMAND "" From 6c37df7147bcc566f5692eba6bd71b96c8701fe6 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:15:49 +0000 Subject: [PATCH 6/8] Don't memset32 inventory matrix, this misses buffer overruns --- src/Engine/Objects/Character.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Engine/Objects/Character.cpp b/src/Engine/Objects/Character.cpp index d1cb95512eee..752e07ae34c3 100644 --- a/src/Engine/Objects/Character.cpp +++ b/src/Engine/Objects/Character.cpp @@ -755,15 +755,13 @@ void Character::PutItemArInventoryIndex( int slot_width = GetSizeInInventorySlots(img->width()); int slot_height = GetSizeInInventorySlots(img->height()); + // TODO(_): try to come up with a better + // solution. negative values are used when + // drawing the inventory - nothing is drawn if (slot_width > 0) { - int *pInvPos = &pInventoryMatrix[index]; - for (int i = 0; i < slot_height; i++) { - memset32(pInvPos, -1 - index, - slot_width); // TODO(_): try to come up with a better - // solution. negative values are used when - // drawing the inventory - nothing is drawn - pInvPos += INVENTORY_SLOTS_WIDTH; - } + for (int i = 0; i < slot_height; i++) + for (int j = 0; j < slot_width; j++) + pInventoryMatrix[index + i * INVENTORY_SLOTS_WIDTH + j] = -1 - index; } pInventoryMatrix[index] = itemListPos + 1; @@ -785,11 +783,9 @@ void Character::RemoveItemAtInventoryIndex(unsigned int index) { } if (slot_width > 0) { - int *pInvPos = &pInventoryMatrix[index]; - for (int i = 0; i < slot_height; i++) { - memset32(pInvPos, 0, slot_width); - pInvPos += INVENTORY_SLOTS_WIDTH; - } + for (int i = 0; i < slot_height; i++) + for (int j = 0; j < slot_width; j++) + pInventoryMatrix[index + i * INVENTORY_SLOTS_WIDTH + j] = 0; } } From 0068bf675d745f57f4e3dab0d5637e456351d7ad Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:16:07 +0000 Subject: [PATCH 7/8] Don't spam in retrace mode --- src/Bin/OpenEnroth/OpenEnrothOptions.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Bin/OpenEnroth/OpenEnrothOptions.cpp b/src/Bin/OpenEnroth/OpenEnrothOptions.cpp index 50af6de80bcc..0a33389dfe32 100644 --- a/src/Bin/OpenEnroth/OpenEnrothOptions.cpp +++ b/src/Bin/OpenEnroth/OpenEnrothOptions.cpp @@ -92,6 +92,9 @@ OpenEnrothOptions OpenEnrothOptions::parse(int argc, char **argv) { if (result.retrace.traces.empty()) throw Exception("No trace files to retrace."); + + if (!result.logLevel) + result.logLevel = LOG_ERROR; // Default log level for retracing is LOG_ERROR. } if (result.subcommand == SUBCOMMAND_PLAY) From b45dc0581af7f3437f9a264b22834e3a19dbcdd6 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:31:06 +0000 Subject: [PATCH 8/8] Drop unused code from NullPlatform --- src/Library/Platform/Null/NullPlatformSharedState.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Library/Platform/Null/NullPlatformSharedState.h b/src/Library/Platform/Null/NullPlatformSharedState.h index 699ae03a8e6d..cd55d641ea6b 100644 --- a/src/Library/Platform/Null/NullPlatformSharedState.h +++ b/src/Library/Platform/Null/NullPlatformSharedState.h @@ -14,12 +14,10 @@ class NullPlatformSharedState { explicit NullPlatformSharedState(NullPlatformOptions options) { assert(!options.displayGeometries.empty()); - cursorPos = options.displayGeometries[0].topLeft(); this->options = std::move(options); } NullPlatformOptions options; std::unordered_map contextByThreadId; bool cursorShown = true; - Pointi cursorPos; };