Merge pull request #4666 from FearlessTobi/port-2167
Port yuzu-emu/yuzu#2167: "common: Move Quaternion, Rectangle, Vec2, Vec3, and Vec4 into the Common namespace"
This commit is contained in:
commit
9560060f04
46 changed files with 390 additions and 380 deletions
|
@ -22,12 +22,12 @@ u16 FramebufferLayout::GetScalingRatio() const {
|
|||
|
||||
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
||||
template <class T>
|
||||
static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area,
|
||||
float screen_aspect_ratio) {
|
||||
static Common::Rectangle<T> maxRectangle(Common::Rectangle<T> window_area,
|
||||
float screen_aspect_ratio) {
|
||||
float scale = std::min(static_cast<float>(window_area.GetWidth()),
|
||||
window_area.GetHeight() / screen_aspect_ratio);
|
||||
return MathUtil::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)),
|
||||
static_cast<T>(std::round(scale * screen_aspect_ratio))};
|
||||
return Common::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)),
|
||||
static_cast<T>(std::round(scale * screen_aspect_ratio))};
|
||||
}
|
||||
|
||||
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) {
|
||||
|
@ -36,10 +36,10 @@ FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapp
|
|||
|
||||
FramebufferLayout res{width, height, true, true, {}, {}};
|
||||
// Default layout gives equal screen sizes to the top and bottom screen
|
||||
MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height / 2};
|
||||
MathUtil::Rectangle<unsigned> top_screen =
|
||||
Common::Rectangle<unsigned> screen_window_area{0, 0, width, height / 2};
|
||||
Common::Rectangle<unsigned> top_screen =
|
||||
maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
||||
MathUtil::Rectangle<unsigned> bot_screen =
|
||||
Common::Rectangle<unsigned> bot_screen =
|
||||
maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||
|
||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
||||
|
@ -77,10 +77,10 @@ FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool swappe
|
|||
// so just calculate them both even if the other isn't showing.
|
||||
FramebufferLayout res{width, height, !swapped, swapped, {}, {}};
|
||||
|
||||
MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
MathUtil::Rectangle<unsigned> top_screen =
|
||||
Common::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
Common::Rectangle<unsigned> top_screen =
|
||||
maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
||||
MathUtil::Rectangle<unsigned> bot_screen =
|
||||
Common::Rectangle<unsigned> bot_screen =
|
||||
maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||
|
||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
||||
|
@ -116,13 +116,12 @@ FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped
|
|||
float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO;
|
||||
float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO;
|
||||
|
||||
MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
MathUtil::Rectangle<unsigned> total_rect =
|
||||
Common::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
Common::Rectangle<unsigned> total_rect =
|
||||
maxRectangle(screen_window_area, emulation_aspect_ratio);
|
||||
MathUtil::Rectangle<unsigned> large_screen =
|
||||
maxRectangle(total_rect, large_screen_aspect_ratio);
|
||||
MathUtil::Rectangle<unsigned> fourth_size_rect = total_rect.Scale(.25f);
|
||||
MathUtil::Rectangle<unsigned> small_screen =
|
||||
Common::Rectangle<unsigned> large_screen = maxRectangle(total_rect, large_screen_aspect_ratio);
|
||||
Common::Rectangle<unsigned> fourth_size_rect = total_rect.Scale(.25f);
|
||||
Common::Rectangle<unsigned> small_screen =
|
||||
maxRectangle(fourth_size_rect, small_screen_aspect_ratio);
|
||||
|
||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
||||
|
@ -149,13 +148,13 @@ FramebufferLayout SideFrameLayout(unsigned width, unsigned height, bool swapped)
|
|||
const float emulation_aspect_ratio = static_cast<float>(Core::kScreenTopHeight) /
|
||||
(Core::kScreenTopWidth + Core::kScreenBottomWidth);
|
||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
||||
MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
Common::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
||||
// Find largest Rectangle that can fit in the window size with the given aspect ratio
|
||||
MathUtil::Rectangle<unsigned> screen_rect =
|
||||
Common::Rectangle<unsigned> screen_rect =
|
||||
maxRectangle(screen_window_area, emulation_aspect_ratio);
|
||||
// Find sizes of top and bottom screen
|
||||
MathUtil::Rectangle<unsigned> top_screen = maxRectangle(screen_rect, TOP_SCREEN_ASPECT_RATIO);
|
||||
MathUtil::Rectangle<unsigned> bot_screen = maxRectangle(screen_rect, BOT_SCREEN_ASPECT_RATIO);
|
||||
Common::Rectangle<unsigned> top_screen = maxRectangle(screen_rect, TOP_SCREEN_ASPECT_RATIO);
|
||||
Common::Rectangle<unsigned> bot_screen = maxRectangle(screen_rect, BOT_SCREEN_ASPECT_RATIO);
|
||||
|
||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
||||
// Apply borders to the left and right sides of the window.
|
||||
|
@ -180,10 +179,10 @@ FramebufferLayout CustomFrameLayout(unsigned width, unsigned height) {
|
|||
|
||||
FramebufferLayout res{width, height, true, true, {}, {}};
|
||||
|
||||
MathUtil::Rectangle<unsigned> top_screen{
|
||||
Common::Rectangle<unsigned> top_screen{
|
||||
Settings::values.custom_top_left, Settings::values.custom_top_top,
|
||||
Settings::values.custom_top_right, Settings::values.custom_top_bottom};
|
||||
MathUtil::Rectangle<unsigned> bot_screen{
|
||||
Common::Rectangle<unsigned> bot_screen{
|
||||
Settings::values.custom_bottom_left, Settings::values.custom_bottom_top,
|
||||
Settings::values.custom_bottom_right, Settings::values.custom_bottom_bottom};
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ struct FramebufferLayout {
|
|||
unsigned height;
|
||||
bool top_screen_enabled;
|
||||
bool bottom_screen_enabled;
|
||||
MathUtil::Rectangle<unsigned> top_screen;
|
||||
MathUtil::Rectangle<unsigned> bottom_screen;
|
||||
Common::Rectangle<unsigned> top_screen;
|
||||
Common::Rectangle<unsigned> bottom_screen;
|
||||
|
||||
/**
|
||||
* Returns the ration of pixel size of the top screen, compared to the native size of the 3DS
|
||||
|
|
|
@ -124,7 +124,7 @@ using AnalogDevice = InputDevice<std::tuple<float, float>>;
|
|||
* Orientation is determined by right-hand rule.
|
||||
* Units: deg/sec
|
||||
*/
|
||||
using MotionDevice = InputDevice<std::tuple<Math::Vec3<float>, Math::Vec3<float>>>;
|
||||
using MotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>>>;
|
||||
|
||||
/**
|
||||
* A touch device is an input device that returns a tuple of two floats and a bool. The floats are
|
||||
|
|
|
@ -179,7 +179,7 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
|
|||
mem->accelerometer.index = next_accelerometer_index;
|
||||
next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size();
|
||||
|
||||
Math::Vec3<float> accel;
|
||||
Common::Vec3<float> accel;
|
||||
std::tie(accel, std::ignore) = motion_device->GetStatus();
|
||||
accel *= accelerometer_coef;
|
||||
// TODO(wwylele): do a time stretch like the one in UpdateGyroscopeCallback
|
||||
|
@ -226,7 +226,7 @@ void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
|
|||
|
||||
GyroscopeDataEntry& gyroscope_entry = mem->gyroscope.entries[mem->gyroscope.index];
|
||||
|
||||
Math::Vec3<float> gyro;
|
||||
Common::Vec3<float> gyro;
|
||||
std::tie(std::ignore, gyro) = motion_device->GetStatus();
|
||||
double stretch = system.perf_stats.GetLastFrameTimeScale();
|
||||
gyro *= gyroscope_coef * static_cast<float>(stretch);
|
||||
|
|
|
@ -48,7 +48,7 @@ inline void Read(T& var, const u32 raw_addr) {
|
|||
var = g_regs[addr / 4];
|
||||
}
|
||||
|
||||
static Math::Vec4<u8> DecodePixel(Regs::PixelFormat input_format, const u8* src_pixel) {
|
||||
static Common::Vec4<u8> DecodePixel(Regs::PixelFormat input_format, const u8* src_pixel) {
|
||||
switch (input_format) {
|
||||
case Regs::PixelFormat::RGBA8:
|
||||
return Color::DecodeRGBA8(src_pixel);
|
||||
|
@ -196,7 +196,7 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) {
|
|||
|
||||
for (u32 y = 0; y < output_height; ++y) {
|
||||
for (u32 x = 0; x < output_width; ++x) {
|
||||
Math::Vec4<u8> src_color;
|
||||
Common::Vec4<u8> src_color;
|
||||
|
||||
// Calculate the [x,y] position of the input image
|
||||
// based on the current output position and the scale
|
||||
|
@ -259,15 +259,15 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) {
|
|||
const u8* src_pixel = src_pointer + src_offset;
|
||||
src_color = DecodePixel(config.input_format, src_pixel);
|
||||
if (config.scaling == config.ScaleX) {
|
||||
Math::Vec4<u8> pixel =
|
||||
Common::Vec4<u8> pixel =
|
||||
DecodePixel(config.input_format, src_pixel + src_bytes_per_pixel);
|
||||
src_color = ((src_color + pixel) / 2).Cast<u8>();
|
||||
} else if (config.scaling == config.ScaleXY) {
|
||||
Math::Vec4<u8> pixel1 =
|
||||
Common::Vec4<u8> pixel1 =
|
||||
DecodePixel(config.input_format, src_pixel + 1 * src_bytes_per_pixel);
|
||||
Math::Vec4<u8> pixel2 =
|
||||
Common::Vec4<u8> pixel2 =
|
||||
DecodePixel(config.input_format, src_pixel + 2 * src_bytes_per_pixel);
|
||||
Math::Vec4<u8> pixel3 =
|
||||
Common::Vec4<u8> pixel3 =
|
||||
DecodePixel(config.input_format, src_pixel + 3 * src_bytes_per_pixel);
|
||||
src_color = (((src_color + pixel1) + (pixel2 + pixel3)) / 4).Cast<u8>();
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ static void SendData(const u32* input, ConversionBuffer& buf, int amount_of_data
|
|||
u8* unit_end = output + buf.transfer_unit;
|
||||
while (output < unit_end) {
|
||||
u32 color = *input++;
|
||||
Math::Vec4<u8> col_vec{(u8)(color >> 24), (u8)(color >> 16), (u8)(color >> 8), alpha};
|
||||
Common::Vec4<u8> col_vec{(u8)(color >> 24), (u8)(color >> 16), (u8)(color >> 8), alpha};
|
||||
|
||||
switch (output_format) {
|
||||
case OutputFormat::RGBA8:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue