shithub: cstory

Download patch

ref: f4f85f1f9d7530e9c66d561bbd6941e5f30828c8
parent: 02f570cec77ed77d5623c005640a2ca97c0dea3a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Apr 13 14:54:34 EDT 2020

Add Null platform backend

Also does absolute nothing.

The point of these things is so it's easier to test out new ports.
For example, with the Null backends and the software renderer, we
don't need to write any code to build for other platforms.

In addition, by having no platform-dependant code, this can be used
to trace crashes. For example, I was having crashes on the Wii U,
despite there being no Wii U-specific code at all - the cause turned
out to be that the executable wasn't stripped, and it had nothing to
do with the code at all.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,7 @@
 
 set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer")
 set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2', 'miniaudio', or 'Null'")
-set(BACKEND_PLATFORM "SDL2" CACHE STRING "Which platform backend the game should use: 'SDL2' or 'GLFW3'")
+set(BACKEND_PLATFORM "SDL2" CACHE STRING "Which platform backend the game should use: 'SDL2', 'GLFW3', or 'Null'")
 
 option(LTO "Enable link-time optimisation" OFF)
 option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files)" OFF)
@@ -350,6 +350,11 @@
 		"src/Backends/GLFW3/Misc.cpp"
 		"src/Backends/GLFW3/Window.h"
 	)
+elseif(BACKEND_PLATFORM MATCHES "Null")
+	target_sources(CSE2 PRIVATE
+		"src/Backends/Null/Controller.cpp"
+		"src/Backends/Null/Misc.cpp"
+	)
 endif()
 
 if(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "OpenGL3")
@@ -366,6 +371,8 @@
 	target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Window-OpenGLES2.cpp")
 elseif(BACKEND_PLATFORM MATCHES "GLFW3" AND BACKEND_RENDERER MATCHES "Software")
 	target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Window-Software.cpp")
+elseif(BACKEND_PLATFORM MATCHES "Null" AND BACKEND_RENDERER MATCHES "Software")
+	target_sources(CSE2 PRIVATE "src/Backends/Null/Window-Software.cpp")
 else()
 	message(FATAL_ERROR "Invalid BACKEND_PLATFORM/BACKEND_RENDERER combination")
 endif()
--- /dev/null
+++ b/src/Backends/Null/Controller.cpp
@@ -1,0 +1,21 @@
+#include "../Controller.h"
+
+bool ControllerBackend_Init(void)
+{
+	return false;
+}
+
+void ControllerBackend_Deinit(void)
+{
+	
+}
+
+bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count)
+{
+	(void)buttons;
+	(void)button_count;
+	(void)axes;
+	(void)axis_count;
+
+	return false;
+}
--- /dev/null
+++ b/src/Backends/Null/Misc.cpp
@@ -1,0 +1,89 @@
+#include "../Misc.h"
+
+bool Backend_Init(void)
+{
+	return true;
+}
+
+void Backend_Deinit(void)
+{
+	
+}
+
+void Backend_PostWindowCreation(void)
+{
+	
+}
+
+bool Backend_GetBasePath(char *string_buffer)
+{
+	(void)string_buffer;
+
+	return false;
+}
+
+void Backend_HideMouse(void)
+{
+	
+}
+
+void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
+{
+	(void)rgb_pixels;
+	(void)width;
+	(void)height;
+}
+
+void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
+{
+	(void)rgb_pixels;
+	(void)width;
+	(void)height;
+}
+
+void PlaybackBackend_EnableDragAndDrop(void)
+{
+	
+}
+
+bool Backend_SystemTask(bool active)
+{
+	(void)active;
+
+	return true;
+}
+
+void Backend_GetKeyboardState(bool *keyboard_state)
+{
+	(void)keyboard_state;
+}
+
+void Backend_ShowMessageBox(const char *title, const char *message)
+{
+	(void)title;
+	(void)message;
+}
+
+ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintError(const char *format, ...)
+{
+	(void)format;
+}
+
+ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintInfo(const char *format, ...)
+{
+	(void)format;
+}
+
+unsigned long Backend_GetTicks(void)
+{
+	static unsigned long fake_ticks = 0;
+
+	fake_ticks += 1000 / 50;
+
+	return fake_ticks;
+}
+
+void Backend_Delay(unsigned int ticks)
+{
+	(void)ticks;
+}
--- /dev/null
+++ b/src/Backends/Null/Window-Software.cpp
@@ -1,0 +1,39 @@
+#include "../Window-Software.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+
+static unsigned char *framebuffer;
+
+unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch)
+{
+	(void)window_title;
+	(void)fullscreen;
+
+	framebuffer = (unsigned char*)malloc(screen_width * screen_height * 3);
+
+	if (framebuffer != NULL)
+	{
+		*pitch = screen_width * 3;
+
+		return framebuffer;
+	}
+
+	return NULL;
+}
+
+void WindowBackend_Software_DestroyWindow(void)
+{
+	free(framebuffer);
+}
+
+void WindowBackend_Software_Display(void)
+{
+	
+}
+
+void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
+{
+	(void)width;
+	(void)height;
+}