shithub: cstory

Download patch

ref: 1582af91cff8435c5bea684b39f2f4a43f58ad7f
parent: c7a3e9c30833d032d5c74751c99731cdf132174e
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Jul 8 21:09:19 EDT 2020

Replace more float logic with integer-only

I hate floats >:(

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -738,12 +738,12 @@
 	GLsizei width;
 	GLsizei height;
 
-	if ((float)actual_screen_width / (float)actual_screen_height > (float)framebuffer.width / (float)framebuffer.height)
+	if (actual_screen_width * framebuffer.height > framebuffer.width * actual_screen_height)	// Fancy way to do `if (actual_screen_width / actual_screen_height > framebuffer.width / framebuffer.height)` without floats
 	{
 		y = 0;
 		height = actual_screen_height;
 
-		width = framebuffer.width * ((float)actual_screen_height / (float)framebuffer.height);
+		width = (framebuffer.width * actual_screen_height) / framebuffer.height;
 		x = (actual_screen_width - width) / 2;
 	}
 	else
@@ -751,7 +751,7 @@
 		x = 0;
 		width = actual_screen_width;
 
-		height = framebuffer.height * ((float)actual_screen_width / (float)framebuffer.width);
+		height = (framebuffer.height * actual_screen_width) / framebuffer.width;
 		y = (actual_screen_height - height) / 2;
 	}
 
--- a/src/Backends/Rendering/Window/Software/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/Software/GLFW3.cpp
@@ -130,7 +130,7 @@
 	GLsizei viewport_width;
 	GLsizei viewport_height;
 
-	if ((float)width / (float)height > (float)framebuffer_width / (float)framebuffer_height)
+	if (width * framebuffer_height > framebuffer_width * height) // Fancy way to do `if (width / height > framebuffer_width / framebuffer_height)` without floats
 	{
 		viewport_y = 0;
 		viewport_height = height;
--- a/src/Backends/Rendering/Window/Software/WiiU.cpp
+++ b/src/Backends/Rendering/Window/Software/WiiU.cpp
@@ -50,12 +50,12 @@
 
 static void CalculateViewport(unsigned int actual_screen_width, unsigned int actual_screen_height, Viewport *viewport)
 {
-	if ((float)actual_screen_width / (float)actual_screen_height > (float)fake_framebuffer_width / (float)fake_framebuffer_height)
+	if (actual_screen_width * fake_framebuffer_height > fake_framebuffer_width * actual_screen_height) // Fancy way to do `if (actual_screen_width / actual_screen_height > fake_framebuffer_width / fake_framebuffer_height)` without floats
 	{
 		viewport->y = 0.0f;
 		viewport->height = actual_screen_height;
 
-		viewport->width = fake_framebuffer_width * ((float)actual_screen_height / (float)fake_framebuffer_height);
+		viewport->width = (fake_framebuffer_width * actual_screen_height) / fake_framebuffer_height;
 		viewport->x = (actual_screen_width - viewport->width) / 2;
 	}
 	else
@@ -63,7 +63,7 @@
 		viewport->x = 0.0f;
 		viewport->width = actual_screen_width;
 
-		viewport->height = fake_framebuffer_height * ((float)actual_screen_width / (float)fake_framebuffer_width);
+		viewport->height = (fake_framebuffer_height * actual_screen_width) / fake_framebuffer_width;
 		viewport->y = (actual_screen_height - viewport->height) / 2;
 	}
 }