From 44456e4a258d21e286b5a7ee697e45dc5f201870 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 17 Jul 2019 16:09:18 +0100 Subject: [PATCH] Add an SDL_Surface-based renderer Ha, my custom software renderer is faster! --- CMakeLists.txt | 6 +++++- Makefile | 4 ++++ README.md | 8 ++++++-- src/Backends/Rendering.h | 2 +- src/Backends/Rendering/SDLTexture.cpp | 4 ++-- src/Backends/Rendering/Software.cpp | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 540077e2..337312eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(JAPANESE "Enable the Japanese-language build" OFF) 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 @@ endif() 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 diff --git a/Makefile b/Makefile index af9ee0a6..c13e163d 100644 --- a/Makefile +++ b/Makefile @@ -210,8 +210,12 @@ endif 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))) diff --git a/README.md b/README.md index c9c734f6..dc05e23c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,10 @@ You can also add the following flags: * `-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 @@ Run 'make' in this folder, preferably with some of the following settings: * `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 diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 12c2d5e9..5670ac78 100644 --- 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); diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 543a377b..a35770e4 100644 --- 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 struct Backend_Surface *next; struct Backend_Surface *prev; -}; +} Backend_Surface; static SDL_Renderer *renderer; static SDL_Texture *screen_texture; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 77bd5d7f..6f6f1612 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -15,7 +15,7 @@ struct Backend_Surface unsigned int width; unsigned int height; unsigned int pitch; -}; +} Backend_Surface; static SDL_Window *window; static SDL_Surface *window_surface;