shithub: cstory

Download patch

ref: 44456e4a258d21e286b5a7ee697e45dc5f201870
parent: f21f17f4c2fd8c4ba4d1fcf1dcf0976fd1d251ab
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Jul 17 12:09:18 EDT 2019

Add an SDL_Surface-based renderer

Ha, my custom software renderer is faster!

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@
 option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF)
 option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF)
 option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
-set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, and 'Software' for a handwritten software renderer")
+set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer")
 
 project(CSE2 LANGUAGES C CXX)
 
@@ -248,8 +248,12 @@
 
 if(RENDERER MATCHES "Texture")
 	target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp")
+elseif(RENDERER MATCHES "Surface")
+	target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLSurface.cpp")
 elseif(RENDERER MATCHES "Software")
 	target_sources(CSE2 PRIVATE "src/Backends/Rendering/Software.cpp")
+else()
+	message(FATAL_ERROR "Invalid RENDERER selected")
 endif()
 
 # Make some tweaks if we're targetting Windows
--- a/Makefile
+++ b/Makefile
@@ -210,8 +210,12 @@
 
 ifeq ($(RENDERER), Texture)
 	SOURCES += Backends/Rendering/SDLTexture
+else ifeq ($(RENDERER), Surface)
+	SOURCES += Backends/Rendering/Software
 else ifeq ($(RENDERER), Software)
 	SOURCES += Backends/Rendering/Software
+else
+	@echo Invalid RENDERER selected; this build will fail
 endif
 
 OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES)))
--- a/README.md
+++ b/README.md
@@ -30,7 +30,10 @@
 * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used
 * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones
 * `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default)
-* `-DRENDERER=Software` - Use the software renderer
+* `-DRENDERER=Surface` - Use SDL2's software-renderer Surface API
+* `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default)
+* `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer
+* `-DRENDERER=Software` - Use a handwritten software renderer
 
 Then compile CSE2 with this command:
 
@@ -56,7 +59,8 @@
 * `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis
 * `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used
 * `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default)
-* `RENDERER=Software` - Use the software renderer
+* `RENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer
+* `RENDERER=Software` - Use a hand-written software renderer
 
 ### Visual Studio .NET 2003
 
--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -6,7 +6,7 @@
 
 #include "../Font.h"
 
-struct Backend_Surface;
+typedef struct Backend_Surface Backend_Surface;
 
 BOOL Backend_Init(SDL_Window *window);
 void Backend_Deinit(void);
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -9,7 +9,7 @@
 
 #include "../../Font.h"
 
-struct Backend_Surface
+typedef struct Backend_Surface
 {
 	BOOL needs_syncing;
 	SDL_Surface *sdl_surface;
@@ -17,7 +17,7 @@
 
 	struct Backend_Surface *next;
 	struct Backend_Surface *prev;
-};
+} Backend_Surface;
 
 static SDL_Renderer *renderer;
 static SDL_Texture *screen_texture;
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -15,7 +15,7 @@
 	unsigned int width;
 	unsigned int height;
 	unsigned int pitch;
-};
+} Backend_Surface;
 
 static SDL_Window *window;
 static SDL_Surface *window_surface;