From 0a7fba00a554c324aade39ae8b3a31a35285eb2a Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Fri, 21 Apr 2023 00:43:41 +0200 Subject: [PATCH] AGS: Properly implement sprite batches for legacy modes This completes commit c06dc7dab97ba33d9fcf2edeffe37e8f36e0336a which was only partial and completely broke the mouse pointer and UI in old games --- engines/ags/engine/ac/draw.cpp | 13 +++++++------ engines/ags/engine/ac/game_state.cpp | 4 ---- engines/ags/engine/ac/game_state.h | 2 -- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp index de094ca39b7..4b10426e439 100644 --- a/engines/ags/engine/ac/draw.cpp +++ b/engines/ags/engine/ac/draw.cpp @@ -683,7 +683,7 @@ void render_to_screen() { // Stage: final plugin callback (still drawn on game screen if (pl_any_want_hook(AGSE_FINALSCREENDRAW)) { _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetMainViewport(), - SpriteTransform(0, _GP(play).shake_screen_yoff), (GraphicFlip)_GP(play).screen_flipped); + _GP(play).GetGlobalTransform(full_frame_rend), (GraphicFlip)_GP(play).screen_flipped); _G(gfxDriver)->DrawSprite(AGSE_FINALSCREENDRAW, 0, nullptr); _G(gfxDriver)->EndSpriteBatch(); } @@ -2085,7 +2085,7 @@ static void construct_room_view() { auto camera = viewport->GetCamera(); if (!camera) continue; - const Rect &view_rc = _GP(play).GetRoomViewportAbs(viewport->GetID()); + const Rect &view_rc = viewport->GetRect(); const Rect &cam_rc = camera->GetRect(); const float view_sx = (float)view_rc.GetWidth() / (float)cam_rc.GetWidth(); const float view_sy = (float)view_rc.GetHeight() / (float)cam_rc.GetHeight(); @@ -2137,7 +2137,7 @@ static void construct_room_view() { // Schedule ui rendering static void construct_ui_view() { - _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetUIViewportAbs()); + _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetUIViewport()); draw_gui_and_overlays(); _G(gfxDriver)->EndSpriteBatch(); clear_draw_list(); @@ -2220,7 +2220,7 @@ void construct_game_scene(bool full_redraw) { // Begin with the parent scene node, defining global offset and flip bool full_frame_rend = _G(gfxDriver)->RequiresFullRedrawEachFrame(); _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetMainViewport(), - SpriteTransform(0, _GP(play).shake_screen_yoff), + _GP(play).GetGlobalTransform(full_frame_rend), (GraphicFlip)_GP(play).screen_flipped); // Stage: room viewports @@ -2281,7 +2281,8 @@ void update_mouse_cursor() { void construct_game_screen_overlay(bool draw_mouse) { const bool full_frame_rend = _G(gfxDriver)->RequiresFullRedrawEachFrame(); _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetMainViewport(), - SpriteTransform(0, _GP(play).shake_screen_yoff), (GraphicFlip)_GP(play).screen_flipped); + _GP(play).GetGlobalTransform(full_frame_rend), + (GraphicFlip)_GP(play).screen_flipped); if (pl_any_want_hook(AGSE_POSTSCREENDRAW)) { _G(gfxDriver)->DrawSprite(AGSE_POSTSCREENDRAW, 0, nullptr); } @@ -2458,7 +2459,7 @@ void render_graphics(IDriverDependantBitmap *extraBitmap, int extraX, int extraY // TODO: extraBitmap is a hack, used to place an additional gui element // on top of the screen. Normally this should be a part of the game UI stage. if (extraBitmap != nullptr) { - _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetMainViewport(), SpriteTransform(0, _GP(play).shake_screen_yoff), + _G(gfxDriver)->BeginSpriteBatch(_GP(play).GetMainViewport(), _GP(play).GetGlobalTransform(_G(gfxDriver)->RequiresFullRedrawEachFrame()), (GraphicFlip)_GP(play).screen_flipped); invalidate_sprite(extraX, extraY, extraBitmap, false); _G(gfxDriver)->DrawSprite(extraX, extraY, extraBitmap); diff --git a/engines/ags/engine/ac/game_state.cpp b/engines/ags/engine/ac/game_state.cpp index 03918bac584..641341b7ead 100644 --- a/engines/ags/engine/ac/game_state.cpp +++ b/engines/ags/engine/ac/game_state.cpp @@ -107,10 +107,6 @@ PViewport GameState::GetRoomViewport(int index) const { return _roomViewports[index]; } -Rect GameState::GetUIViewportAbs() const { - return Rect::MoveBy(_uiViewport, _mainViewport.Left, _mainViewport.Top); -} - const std::vector &GameState::GetRoomViewportsZOrdered() const { return _roomViewportsSorted; } diff --git a/engines/ags/engine/ac/game_state.h b/engines/ags/engine/ac/game_state.h index 19f015671ee..95591f24172 100644 --- a/engines/ags/engine/ac/game_state.h +++ b/engines/ags/engine/ac/game_state.h @@ -288,8 +288,6 @@ struct GameState { const std::vector &GetRoomViewportsZOrdered() const; // Finds room viewport at the given screen coordinates; returns nullptr if non found PViewport GetRoomViewportAt(int x, int y) const; - // Returns UI viewport position in absolute coordinates (with main viewport offset) - Rect GetUIViewportAbs() const; // Returns Room viewport position in absolute coordinates (with main viewport offset); // this is a helper function, meant for peculiar cases. Rect GetRoomViewportAbs(int index) const;