Browse Source

Make zoom a setting in the menu (#4931)

pull/5058/head
Trihedraf 4 years ago committed by Anders Jenbo
parent
commit
03986c0f46
  1. 2
      Source/controls/game_controls.cpp
  2. 5
      Source/cursor.cpp
  3. 4
      Source/diablo.cpp
  4. 1
      Source/diablo.h
  5. 2
      Source/options.cpp
  6. 2
      Source/options.h
  7. 2
      Source/player.cpp
  8. 2
      Source/qol/itemlabels.cpp
  9. 21
      Source/scrollrt.cpp
  10. 27
      test/scrollrt_test.cpp

2
Source/controls/game_controls.cpp

@ -302,7 +302,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
case ControllerButton_BUTTON_Y: // Top button case ControllerButton_BUTTON_Y: // Top button
#ifdef __3DS__ #ifdef __3DS__
if (!ctrlEvent.up) { if (!ctrlEvent.up) {
zoomflag = !zoomflag; sgOptions.Graphics.zoom.SetValue(!*sgOptions.Graphics.zoom);
CalcViewportGeometry(); CalcViewportGeometry();
} }
#else #else

5
Source/cursor.cpp

@ -19,6 +19,7 @@
#include "hwcursor.hpp" #include "hwcursor.hpp"
#include "inv.h" #include "inv.h"
#include "missiles.h" #include "missiles.h"
#include "options.h"
#include "qol/itemlabels.h" #include "qol/itemlabels.h"
#include "qol/stash.h" #include "qol/stash.h"
#include "towners.h" #include "towners.h"
@ -273,7 +274,7 @@ void CheckCursMove()
sy = GetMainPanel().position.y - 1; sy = GetMainPanel().position.y - 1;
} }
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
sx /= 2; sx /= 2;
sy /= 2; sy /= 2;
} }
@ -320,7 +321,7 @@ void CheckCursMove()
my++; my++;
} }
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
sy -= TILE_HEIGHT / 4; sy -= TILE_HEIGHT / 4;
} }

4
Source/diablo.cpp

@ -95,7 +95,6 @@ Point MousePosition;
bool gbRunGame; bool gbRunGame;
bool gbRunGameResult; bool gbRunGameResult;
bool ReturnToMainMenu; bool ReturnToMainMenu;
bool zoomflag;
/** Enable updating of player character, set to false once Diablo dies */ /** Enable updating of player character, set to false once Diablo dies */
bool gbProcessPlayers; bool gbProcessPlayers;
bool gbLoadGame; bool gbLoadGame;
@ -149,7 +148,6 @@ bool was_ui_init = false;
void StartGame(interface_mode uMsg) void StartGame(interface_mode uMsg)
{ {
zoomflag = true;
CalcViewportGeometry(); CalcViewportGeometry();
cineflag = false; cineflag = false;
InitCursor(); InitCursor();
@ -1638,7 +1636,7 @@ void InitKeymapActions()
N_("Zoom Game Screen."), N_("Zoom Game Screen."),
'Z', 'Z',
[] { [] {
zoomflag = !zoomflag; sgOptions.Graphics.zoom.SetValue(!*sgOptions.Graphics.zoom);
CalcViewportGeometry(); CalcViewportGeometry();
}, },
nullptr, nullptr,

1
Source/diablo.h

@ -65,7 +65,6 @@ extern Point MousePosition;
extern bool gbRunGame; extern bool gbRunGame;
extern bool gbRunGameResult; extern bool gbRunGameResult;
extern bool ReturnToMainMenu; extern bool ReturnToMainMenu;
extern DVL_API_FOR_TEST bool zoomflag;
extern bool gbProcessPlayers; extern bool gbProcessPlayers;
extern bool gbLoadGame; extern bool gbLoadGame;
extern bool cineflag; extern bool cineflag;

2
Source/options.cpp

@ -752,6 +752,7 @@ GraphicsOptions::GraphicsOptions()
, vSync("Vertical Sync", OptionEntryFlags::RecreateUI, N_("Vertical Sync"), N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."), true) , vSync("Vertical Sync", OptionEntryFlags::RecreateUI, N_("Vertical Sync"), N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."), true)
#endif #endif
, gammaCorrection("Gamma Correction", OptionEntryFlags::Invisible, "Gamma Correction", "Gamma correction level.", 100) , gammaCorrection("Gamma Correction", OptionEntryFlags::Invisible, "Gamma Correction", "Gamma correction level.", 100)
, zoom("Zoom", OptionEntryFlags::None, N_("Zoom"), N_("Zoom on when enabled."), false)
, colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true) , colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true)
, alternateNestArt("Alternate nest art", OptionEntryFlags::OnlyHellfire | OptionEntryFlags::CantChangeInGame, N_("Alternate nest art"), N_("The game will use an alternative palette for Hellfire’s nest tileset."), false) , alternateNestArt("Alternate nest art", OptionEntryFlags::OnlyHellfire | OptionEntryFlags::CantChangeInGame, N_("Alternate nest art"), N_("The game will use an alternative palette for Hellfire’s nest tileset."), false)
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
@ -795,6 +796,7 @@ std::vector<OptionEntryBase *> GraphicsOptions::GetEntries()
&vSync, &vSync,
#endif #endif
&gammaCorrection, &gammaCorrection,
&zoom,
&limitFPS, &limitFPS,
&showFPS, &showFPS,
&showHealthValues, &showHealthValues,

2
Source/options.h

@ -398,6 +398,8 @@ struct GraphicsOptions : OptionCategoryBase {
#endif #endif
/** @brief Gamma correction level. */ /** @brief Gamma correction level. */
OptionEntryInt<int> gammaCorrection; OptionEntryInt<int> gammaCorrection;
/** @brief Zoom on start. */
OptionEntryBoolean zoom;
/** @brief Enable color cycling animations. */ /** @brief Enable color cycling animations. */
OptionEntryBoolean colorCycling; OptionEntryBoolean colorCycling;
/** @brief Use alternate nest palette. */ /** @brief Use alternate nest palette. */

2
Source/player.cpp

@ -279,7 +279,7 @@ void ScrollViewPort(const Player &player, ScrollDirection dir)
{ {
ScrollInfo.tile = Point { 0, 0 } + (player.position.tile - ViewPosition); ScrollInfo.tile = Point { 0, 0 } + (player.position.tile - ViewPosition);
if (zoomflag) { if (!*sgOptions.Graphics.zoom) {
if (abs(ScrollInfo.tile.x) >= 3 || abs(ScrollInfo.tile.y) >= 3) { if (abs(ScrollInfo.tile.x) >= 3 || abs(ScrollInfo.tile.y) >= 3) {
ScrollInfo._sdir = ScrollDirection::None; ScrollInfo._sdir = ScrollDirection::None;
} else { } else {

2
Source/qol/itemlabels.cpp

@ -85,7 +85,7 @@ void AddItemToLabelQueue(int id, int x, int y)
x += *labelCenterOffsets[index]; x += *labelCenterOffsets[index];
y -= TILE_HEIGHT; y -= TILE_HEIGHT;
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
x *= 2; x *= 2;
y *= 2; y *= 2;
} }

21
Source/scrollrt.cpp

@ -27,6 +27,7 @@
#include "minitext.h" #include "minitext.h"
#include "missiles.h" #include "missiles.h"
#include "nthread.h" #include "nthread.h"
#include "options.h"
#include "panels/charpanel.hpp" #include "panels/charpanel.hpp"
#include "plrmsg.h" #include "plrmsg.h"
#include "qol/chatlog.h" #include "qol/chatlog.h"
@ -1081,7 +1082,7 @@ int tileRows;
void DrawGame(const Surface &fullOut, Point position) void DrawGame(const Surface &fullOut, Point position)
{ {
// Limit rendering to the view area // Limit rendering to the view area
const Surface &out = zoomflag const Surface &out = !*sgOptions.Graphics.zoom
? fullOut.subregionY(0, gnViewportHeight) ? fullOut.subregionY(0, gnViewportHeight)
: fullOut.subregionY(0, (gnViewportHeight + 1) / 2); : fullOut.subregionY(0, (gnViewportHeight + 1) / 2);
@ -1100,7 +1101,7 @@ void DrawGame(const Surface &fullOut, Point position)
// Skip rendering parts covered by the panels // Skip rendering parts covered by the panels
if (CanPanelsCoverView()) { if (CanPanelsCoverView()) {
if (zoomflag) { if (!*sgOptions.Graphics.zoom) {
if (IsLeftPanelOpen()) { if (IsLeftPanelOpen()) {
position += Displacement(Direction::East) * 2; position += Displacement(Direction::East) * 2;
columns -= 4; columns -= 4;
@ -1175,7 +1176,7 @@ void DrawGame(const Surface &fullOut, Point position)
DrawFloor(out, position, { sx, sy }, rows, columns); DrawFloor(out, position, { sx, sy }, rows, columns);
DrawTileContent(out, position, { sx, sy }, rows, columns); DrawTileContent(out, position, { sx, sy }, rows, columns);
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
Zoom(fullOut.subregionY(0, gnViewportHeight)); Zoom(fullOut.subregionY(0, gnViewportHeight));
} }
} }
@ -1209,11 +1210,11 @@ void DrawView(const Surface &out, Point startPosition)
Point pixelCoords = m.second; Point pixelCoords = m.second;
if (megaTiles) if (megaTiles)
pixelCoords += Displacement { 0, TILE_HEIGHT / 2 }; pixelCoords += Displacement { 0, TILE_HEIGHT / 2 };
if (!zoomflag) if (*sgOptions.Graphics.zoom)
pixelCoords *= 2; pixelCoords *= 2;
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) { if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) {
Size tileSize = { TILE_WIDTH, TILE_HEIGHT }; Size tileSize = { TILE_WIDTH, TILE_HEIGHT };
if (!zoomflag) if (*sgOptions.Graphics.zoom)
tileSize *= 2; tileSize *= 2;
DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter);
} }
@ -1239,7 +1240,7 @@ void DrawView(const Surface &out, Point startPosition)
Displacement hor = { TILE_WIDTH / 2, 0 }; Displacement hor = { TILE_WIDTH / 2, 0 };
Displacement ver = { 0, TILE_HEIGHT / 2 }; Displacement ver = { 0, TILE_HEIGHT / 2 };
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
hor *= 2; hor *= 2;
ver *= 2; ver *= 2;
} }
@ -1453,7 +1454,7 @@ int RowsCoveredByPanel()
} }
int rows = PANEL_HEIGHT / TILE_HEIGHT; int rows = PANEL_HEIGHT / TILE_HEIGHT;
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
rows /= 2; rows /= 2;
} }
@ -1468,7 +1469,7 @@ void CalcTileOffset(int *offsetX, int *offsetY)
int x; int x;
int y; int y;
if (zoomflag) { if (!*sgOptions.Graphics.zoom) {
x = screenWidth % TILE_WIDTH; x = screenWidth % TILE_WIDTH;
y = viewportHeight % TILE_HEIGHT; y = viewportHeight % TILE_HEIGHT;
} else { } else {
@ -1499,7 +1500,7 @@ void TilesInView(int *rcolumns, int *rrows)
rows++; rows++;
} }
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
// Half the number of tiles, rounded up // Half the number of tiles, rounded up
if ((columns & 1) != 0) { if ((columns & 1) != 0) {
columns++; columns++;
@ -1550,7 +1551,7 @@ void CalcViewportGeometry()
} }
// Slightly lower the zoomed view // Slightly lower the zoomed view
if (!zoomflag) { if (*sgOptions.Graphics.zoom) {
tileOffset.deltaY += TILE_HEIGHT / 4; tileOffset.deltaY += TILE_HEIGHT / 4;
if (yo < TILE_HEIGHT / 4) if (yo < TILE_HEIGHT / 4)
tileRows++; tileRows++;

27
test/scrollrt_test.cpp

@ -1,6 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "diablo.h" #include "diablo.h"
#include "options.h"
#include "scrollrt.h" #include "scrollrt.h"
#include "utils/ui_fwd.h" #include "utils/ui_fwd.h"
@ -13,7 +14,7 @@ TEST(Scroll_rt, calc_tiles_in_view_original)
gnScreenWidth = 640; gnScreenWidth = 640;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight - 128; gnViewportHeight = gnScreenHeight - 128;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int columns = 0; int columns = 0;
int rows = 0; int rows = 0;
TilesInView(&columns, &rows); TilesInView(&columns, &rows);
@ -26,7 +27,7 @@ TEST(Scroll_rt, calc_tiles_in_view_original_zoom)
gnScreenWidth = 640; gnScreenWidth = 640;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight - 128; gnViewportHeight = gnScreenHeight - 128;
zoomflag = false; sgOptions.Graphics.zoom.SetValue(true);
int columns = 0; int columns = 0;
int rows = 0; int rows = 0;
TilesInView(&columns, &rows); TilesInView(&columns, &rows);
@ -39,7 +40,7 @@ TEST(Scroll_rt, calc_tiles_in_view_960_540)
gnScreenWidth = 960; gnScreenWidth = 960;
gnScreenHeight = 540; gnScreenHeight = 540;
gnViewportHeight = gnScreenHeight; gnViewportHeight = gnScreenHeight;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int columns = 0; int columns = 0;
int rows = 0; int rows = 0;
TilesInView(&columns, &rows); TilesInView(&columns, &rows);
@ -52,7 +53,7 @@ TEST(Scroll_rt, calc_tiles_in_view_640_512)
gnScreenWidth = 640; gnScreenWidth = 640;
gnScreenHeight = 512; gnScreenHeight = 512;
gnViewportHeight = gnScreenHeight - 128; gnViewportHeight = gnScreenHeight - 128;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int columns = 0; int columns = 0;
int rows = 0; int rows = 0;
TilesInView(&columns, &rows); TilesInView(&columns, &rows);
@ -65,7 +66,7 @@ TEST(Scroll_rt, calc_tiles_in_view_768_480_zoom)
gnScreenWidth = 768; gnScreenWidth = 768;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight; gnViewportHeight = gnScreenHeight;
zoomflag = false; sgOptions.Graphics.zoom.SetValue(true);
int columns = 0; int columns = 0;
int rows = 0; int rows = 0;
TilesInView(&columns, &rows); TilesInView(&columns, &rows);
@ -80,7 +81,7 @@ TEST(Scroll_rt, calc_tile_offset_original)
gnScreenWidth = 640; gnScreenWidth = 640;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight - 128; gnViewportHeight = gnScreenHeight - 128;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int x = 0; int x = 0;
int y = 0; int y = 0;
CalcTileOffset(&x, &y); CalcTileOffset(&x, &y);
@ -93,7 +94,7 @@ TEST(Scroll_rt, calc_tile_offset_original_zoom)
gnScreenWidth = 640; gnScreenWidth = 640;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight - 128; gnViewportHeight = gnScreenHeight - 128;
zoomflag = false; sgOptions.Graphics.zoom.SetValue(true);
int x = 0; int x = 0;
int y = 0; int y = 0;
CalcTileOffset(&x, &y); CalcTileOffset(&x, &y);
@ -106,7 +107,7 @@ TEST(Scroll_rt, calc_tile_offset_960_540)
gnScreenWidth = 960; gnScreenWidth = 960;
gnScreenHeight = 540; gnScreenHeight = 540;
gnViewportHeight = gnScreenHeight; gnViewportHeight = gnScreenHeight;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int x = 0; int x = 0;
int y = 0; int y = 0;
CalcTileOffset(&x, &y); CalcTileOffset(&x, &y);
@ -119,7 +120,7 @@ TEST(Scroll_rt, calc_tile_offset_853_480)
gnScreenWidth = 853; gnScreenWidth = 853;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight; gnViewportHeight = gnScreenHeight;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
int x = 0; int x = 0;
int y = 0; int y = 0;
CalcTileOffset(&x, &y); CalcTileOffset(&x, &y);
@ -132,7 +133,7 @@ TEST(Scroll_rt, calc_tile_offset_768_480_zoom)
gnScreenWidth = 768; gnScreenWidth = 768;
gnScreenHeight = 480; gnScreenHeight = 480;
gnViewportHeight = gnScreenHeight; gnViewportHeight = gnScreenHeight;
zoomflag = false; sgOptions.Graphics.zoom.SetValue(true);
int x = 0; int x = 0;
int y = 0; int y = 0;
CalcTileOffset(&x, &y); CalcTileOffset(&x, &y);
@ -145,20 +146,20 @@ TEST(Scroll_rt, calc_tile_offset_768_480_zoom)
TEST(Scroll_rt, calc_tiles_covered_by_panel_original) TEST(Scroll_rt, calc_tiles_covered_by_panel_original)
{ {
gnScreenWidth = 640; gnScreenWidth = 640;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
EXPECT_EQ(RowsCoveredByPanel(), 0); EXPECT_EQ(RowsCoveredByPanel(), 0);
} }
TEST(Scroll_rt, calc_tiles_covered_by_panel_960) TEST(Scroll_rt, calc_tiles_covered_by_panel_960)
{ {
gnScreenWidth = 960; gnScreenWidth = 960;
zoomflag = true; sgOptions.Graphics.zoom.SetValue(false);
EXPECT_EQ(RowsCoveredByPanel(), 4); EXPECT_EQ(RowsCoveredByPanel(), 4);
} }
TEST(Scroll_rt, calc_tiles_covered_by_panel_960_zoom) TEST(Scroll_rt, calc_tiles_covered_by_panel_960_zoom)
{ {
gnScreenWidth = 960; gnScreenWidth = 960;
zoomflag = false; sgOptions.Graphics.zoom.SetValue(true);
EXPECT_EQ(RowsCoveredByPanel(), 2); EXPECT_EQ(RowsCoveredByPanel(), 2);
} }

Loading…
Cancel
Save