shithub: cstory

Download patch

ref: 670f49db779619fdd28c1724e2e9b03026001e8f
parent: 76e7a6f857a99ad1be5543ecf044b3d4efbe4a39
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Apr 17 14:07:54 EDT 2020

Optimise Wii U video code a little

--- a/src/Backends/WiiU/Window-Software.cpp
+++ b/src/Backends/WiiU/Window-Software.cpp
@@ -61,7 +61,7 @@
 
 void WindowBackend_Software_Display(void)
 {
-	const size_t line_size = (drc_buffer_size / 480) / 2;
+	const size_t pitch = (drc_buffer_size / 480) / 2;
 
 	static bool flipflop;
 
@@ -69,17 +69,18 @@
 
 	if (framebuffer_width == 320 && framebuffer_height == 240)
 	{
-		for (size_t y = 0; y < framebuffer_height; ++y)
-		{
-			unsigned char *out_line = &drc_framebuffer[line_size * 2 * y];
+		const size_t line_size = framebuffer_width * 2 * 4;
+		const size_t line_delta = pitch - line_size;
 
-			if (!flipflop)
-				out_line += drc_buffer_size / 2;
+		unsigned char *out_pointer = drc_framebuffer;
 
-			out_line += ((854 - (framebuffer_width * 2)) * 4) / 2;
+		if (!flipflop)
+			out_pointer += drc_buffer_size / 2;
 
-			unsigned char *out_pointer = out_line;
+		out_pointer += ((854 - (framebuffer_width * 2)) * 4) / 2;
 
+		for (size_t y = 0; y < framebuffer_height; ++y)
+		{
 			for (size_t x = 0; x < framebuffer_width; ++x)
 			{
 				*out_pointer++ = in_pointer[0];
@@ -94,21 +95,25 @@
 				in_pointer += 3;
 			}
 
-			memcpy(out_line + line_size, out_line, framebuffer_width * 4 * 2);
+			memcpy(out_pointer + line_delta, out_pointer - line_size, line_size);
+
+			out_pointer += line_delta + pitch;
 		}
 	}
 	else
 	{
-		for (size_t y = 0; y < framebuffer_height; ++y)
-		{
-			unsigned char *out_pointer = &drc_framebuffer[line_size * y];
+		const size_t line_size = framebuffer_width * 4;
+		const size_t line_delta = pitch - line_size;
 
-			if (!flipflop)
-				out_pointer += drc_buffer_size / 2;
+		unsigned char *out_pointer = drc_framebuffer;
 
-			out_pointer += ((854 - framebuffer_width) * 4) / 2;
-			out_pointer += ((480 - framebuffer_height) * line_size) / 2;
+		if (!flipflop)
+			out_pointer += drc_buffer_size / 2;
 
+		out_pointer += ((854 - framebuffer_width) * 4) / 2;
+
+		for (size_t y = 0; y < framebuffer_height; ++y)
+		{
 			for (size_t x = 0; x < framebuffer_width; ++x)
 			{
 				*out_pointer++ = *in_pointer++;
@@ -116,6 +121,8 @@
 				*out_pointer++ = *in_pointer++;
 				*out_pointer++ = 0;
 			}
+
+			out_pointer += line_delta;
 		}
 	}