From 9bd533ebe4cee1dfef9725f32fe0b9ca42f5680d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Dec 2019 10:58:03 -0500 Subject: VideoCommon/BoundingBox: Make interface for querying bounding box data Rather than expose the bounding box members directly, we can instead provide an interface for code to use. This makes it nicer to transition from global data, as the interface function names are already in place. --- Source/Core/VideoCommon/BoundingBox.cpp | 63 +++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'Source/Core/VideoCommon/BoundingBox.cpp') diff --git a/Source/Core/VideoCommon/BoundingBox.cpp b/Source/Core/VideoCommon/BoundingBox.cpp index 4c9b6c4c3b..7c2127d353 100644 --- a/Source/Core/VideoCommon/BoundingBox.cpp +++ b/Source/Core/VideoCommon/BoundingBox.cpp @@ -3,20 +3,71 @@ // Refer to the license.txt file included. #include "VideoCommon/BoundingBox.h" + +#include +#include + #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" namespace BoundingBox { -// External vars -bool active = false; -u16 coords[4] = {0x80, 0xA0, 0x80, 0xA0}; +namespace +{ +// Whether or not bounding box is enabled. +bool s_is_active = false; + +// Current bounding box coordinates. +std::array s_coordinates{ + 0x80, + 0xA0, + 0x80, + 0xA0, +}; +} // Anonymous namespace + +void Enable() +{ + s_is_active = true; +} + +void Disable() +{ + s_is_active = false; +} + +bool IsEnabled() +{ + return s_is_active; +} + +u16 GetCoordinate(Coordinate coordinate) +{ + return s_coordinates[static_cast(coordinate)]; +} + +void SetCoordinate(Coordinate coordinate, u16 value) +{ + s_coordinates[static_cast(coordinate)] = value; +} + +void Update(u16 left, u16 right, u16 top, u16 bottom) +{ + const u16 new_left = std::min(left, GetCoordinate(Coordinate::Left)); + const u16 new_right = std::max(right, GetCoordinate(Coordinate::Right)); + const u16 new_top = std::min(top, GetCoordinate(Coordinate::Top)); + const u16 new_bottom = std::max(bottom, GetCoordinate(Coordinate::Bottom)); + + SetCoordinate(Coordinate::Left, new_left); + SetCoordinate(Coordinate::Right, new_right); + SetCoordinate(Coordinate::Top, new_top); + SetCoordinate(Coordinate::Bottom, new_bottom); +} -// Save state void DoState(PointerWrap& p) { - p.Do(active); - p.Do(coords); + p.Do(s_is_active); + p.DoArray(s_coordinates); } } // namespace BoundingBox -- cgit v1.2.3