From 10f98821083292c3e6180a195606dbe5eae9b204 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 00:00:13 +0100 Subject: [PATCH 01/46] Shut up a warning --- src/Backends/Platform/GLFW3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/Platform/GLFW3.cpp index 27772ed0..2269fa04 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/Platform/GLFW3.cpp @@ -252,6 +252,8 @@ void PlatformBackend_PostWindowCreation(void) BOOL PlatformBackend_GetBasePath(char *string_buffer) { + (void)string_buffer; + // GLFW3 doesn't seem to have a mechanism for this return FALSE; } From ddc2d795f5092b00fe89c77e4c67131675f2809c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 00:00:22 +0100 Subject: [PATCH 02/46] Add a missing CMake macro Was causing macOS Travis builds to fail --- cmake/FindOpenGLES2.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmake/FindOpenGLES2.cmake b/cmake/FindOpenGLES2.cmake index 04a486e5..e2e0a921 100644 --- a/cmake/FindOpenGLES2.cmake +++ b/cmake/FindOpenGLES2.cmake @@ -19,6 +19,21 @@ # Win32, Apple, and Android are not tested! # Linux tested and works +macro(create_search_paths PREFIX) + foreach(dir ${${PREFIX}_PREFIX_PATH}) + set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH} + ${dir}/include ${dir}/Include ${dir}/include/${PREFIX} ${dir}/Headers) + set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH} + ${dir}/lib ${dir}/Lib ${dir}/lib/${PREFIX} ${dir}/Libs) + set(${PREFIX}_BIN_SEARCH_PATH ${${PREFIX}_BIN_SEARCH_PATH} + ${dir}/bin) + endforeach(dir) + if(ANDROID) + set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH} ${OGRE_DEPENDENCIES_DIR}/lib/${ANDROID_ABI}) + endif() + set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH}) +endmacro(create_search_paths) + if(WIN32) if(CYGWIN) find_path(OPENGLES2_INCLUDE_DIR GLES2/gl2.h) From a093ebd0187410943a19fbbe222b00451e2957ab Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 01:05:24 +0100 Subject: [PATCH 03/46] Add another missing CMake macro --- cmake/FindOpenGLES2.cmake | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmake/FindOpenGLES2.cmake b/cmake/FindOpenGLES2.cmake index e2e0a921..c79b9b0e 100644 --- a/cmake/FindOpenGLES2.cmake +++ b/cmake/FindOpenGLES2.cmake @@ -19,6 +19,42 @@ # Win32, Apple, and Android are not tested! # Linux tested and works +# Slightly customised framework finder +macro(findpkg_framework fwk) + if(APPLE) + set(${fwk}_FRAMEWORK_PATH + ${${fwk}_FRAMEWORK_SEARCH_PATH} + ${CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /Library/Frameworks + /System/Library/Frameworks + /Network/Library/Frameworks + ${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Release + ${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Debug + ) + # These could be arrays of paths, add each individually to the search paths + foreach(i ${OGRE_PREFIX_PATH}) + set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/macosx/Release ${i}/lib/macosx/Debug) + endforeach(i) + + foreach(i ${OGRE_PREFIX_BUILD}) + set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/macosx/Release ${i}/lib/macosx/Debug) + endforeach(i) + + foreach(dir ${${fwk}_FRAMEWORK_PATH}) + set(fwkpath ${dir}/${fwk}.framework) + if(EXISTS ${fwkpath}) + set(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES} + ${fwkpath}/Headers ${fwkpath}/PrivateHeaders) + set(${fwk}_FRAMEWORK_PATH ${dir}) + if (NOT ${fwk}_LIBRARY_FWK) + set(${fwk}_LIBRARY_FWK "-framework ${fwk}") + endif () + endif(EXISTS ${fwkpath}) + endforeach(dir) + endif(APPLE) +endmacro(findpkg_framework) + macro(create_search_paths PREFIX) foreach(dir ${${PREFIX}_PREFIX_PATH}) set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH} From 5b996b345952a582cd151d395774d896fff9a663 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 01:34:47 +0100 Subject: [PATCH 04/46] Give glad a CMake file Today I learned that CMake will error if the project shares a dependency with a nested CMake file (which could be from an entirely-separate project that you have no control over). I'm starting to really hate CMake. --- CMakeLists.txt | 3 ++- DoConfig/CMakeLists.txt | 13 ++++++++++--- external/glad/CMakeLists.txt | 11 +++++++++++ external/glad/include/glad/glad.h | 2 +- external/glad/src/glad.c | 2 +- src/Backends/Rendering/OpenGL3.cpp | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 external/glad/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 609f8636..6e79bed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,7 +526,8 @@ else() endif() if(BACKEND_RENDERER MATCHES "OpenGL3") - target_sources(CSE2 PRIVATE "external/glad/src/glad.c" "external/glad/include/glad/glad.h" "external/glad/include/KHR/khrplatform.h") + add_subdirectory("external/glad" EXCLUDE_FROM_ALL) + target_link_libraries(CSE2 PRIVATE glad) find_package(OpenGL REQUIRED) target_link_libraries(CSE2 PRIVATE OpenGL::GL ${CMAKE_DL_LIBS}) diff --git a/DoConfig/CMakeLists.txt b/DoConfig/CMakeLists.txt index 6df9ec78..3edd211f 100644 --- a/DoConfig/CMakeLists.txt +++ b/DoConfig/CMakeLists.txt @@ -9,9 +9,6 @@ project(DoConfig LANGUAGES C CXX) add_executable(DoConfig WIN32 "icon.rc" - "../external/glad/include/glad/glad.h" - "../external/glad/include/KHR/khrplatform.h" - "../external/glad/src/glad.c" "DoConfig.cpp" "imgui/imconfig.h" "imgui/imgui.cpp" @@ -71,6 +68,16 @@ endif() # Dependencies # ################ +# glad + +if(NOT TARGET glad) + add_subdirectory("../external/glad" "glad" EXCLUDE_FROM_ALL) +endif() + +target_link_libraries(DoConfig PRIVATE glad) + +# GLFW3 + if(NOT FORCE_LOCAL_LIBS) find_package(PkgConfig QUIET) endif() diff --git a/external/glad/CMakeLists.txt b/external/glad/CMakeLists.txt new file mode 100644 index 00000000..2b6298c1 --- /dev/null +++ b/external/glad/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.12) + +project(glad LANGUAGES C) + +add_library(glad + "include/glad/glad.h" + "include/KHR/khrplatform.h" + "src/glad.c" +) + +target_include_directories(glad PUBLIC "include") diff --git a/external/glad/include/glad/glad.h b/external/glad/include/glad/glad.h index 1b59b588..39d8722e 100644 --- a/external/glad/include/glad/glad.h +++ b/external/glad/include/glad/glad.h @@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void); GLAPI int gladLoadGLLoader(GLADloadproc); -#include "../KHR/khrplatform.h" +#include typedef unsigned int GLenum; typedef unsigned char GLboolean; typedef unsigned int GLbitfield; diff --git a/external/glad/src/glad.c b/external/glad/src/glad.c index dfeaf6fc..6e1f11d9 100644 --- a/external/glad/src/glad.c +++ b/external/glad/src/glad.c @@ -22,7 +22,7 @@ #include #include #include -#include "../include/glad/glad.h" +#include static void* get_proc(const char *namez); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 65b1cd87..abd19e1f 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -10,7 +10,7 @@ #ifdef USE_OPENGLES2 #include #else -#include "../../../external/glad/include/glad/glad.h" +#include #endif #define SPRITEBATCH_IMPLEMENTATION From 5f1560ecdf419656c26c5616fad8fb2ae8b9b64f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 01:45:24 +0100 Subject: [PATCH 05/46] Make Travis ignore invalid setups --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8bb2cd99..45d8f219 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,6 +56,18 @@ env: - PLATFORM=GLFW3 AUDIO=miniaudio RENDERER=OpenGL3 - PLATFORM=GLFW3 AUDIO=miniaudio RENDERER=OpenGLES2 +jobs: + exclude: + # macOS doesn't support OpenGLES2, apparently + - os: osx + env: PLATFORM=SDL2 AUDIO=SDL2 RENDERER=OpenGLES2 + - os: osx + env: PLATFORM=GLFW3 AUDIO=miniaudio RENDERER=OpenGLES2 + # GCC is mysteriously broken when trying to parse macOS headers for miniaudio + - os: osx + compiler: gcc + env: PLATFORM=GLFW3 AUDIO=miniaudio RENDERER=OpenGL3 + before_install: # Set URL for Discord send script - DISCORD_SEND_SCRIPT_URL=https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh From f45758e845fd8ebedaeccfae5020def2c079b4d3 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 01:52:54 +0100 Subject: [PATCH 06/46] Add missing dependencies --- DoConfig/CMakeLists.txt | 3 +++ external/glad/CMakeLists.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/DoConfig/CMakeLists.txt b/DoConfig/CMakeLists.txt index 3edd211f..b7636f48 100644 --- a/DoConfig/CMakeLists.txt +++ b/DoConfig/CMakeLists.txt @@ -76,6 +76,9 @@ endif() target_link_libraries(DoConfig PRIVATE glad) +find_package(OpenGL REQUIRED) +target_link_libraries(DoConfig PRIVATE OpenGL::GL ${CMAKE_DL_LIBS}) + # GLFW3 if(NOT FORCE_LOCAL_LIBS) diff --git a/external/glad/CMakeLists.txt b/external/glad/CMakeLists.txt index 2b6298c1..56b8523e 100644 --- a/external/glad/CMakeLists.txt +++ b/external/glad/CMakeLists.txt @@ -9,3 +9,4 @@ add_library(glad ) target_include_directories(glad PUBLIC "include") +target_link_libraries(glad PRIVATE ${CMAKE_DL_LIBS}) From dded47f921b7bcad28d2d7a48faec90281e2fa99 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 02:00:51 +0100 Subject: [PATCH 07/46] Cleanup --- CMakeLists.txt | 2 +- DoConfig/CMakeLists.txt | 7 ++----- external/glad/CMakeLists.txt | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e79bed7..aa45c715 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -530,7 +530,7 @@ if(BACKEND_RENDERER MATCHES "OpenGL3") target_link_libraries(CSE2 PRIVATE glad) find_package(OpenGL REQUIRED) - target_link_libraries(CSE2 PRIVATE OpenGL::GL ${CMAKE_DL_LIBS}) + target_link_libraries(CSE2 PRIVATE OpenGL::GL) endif() if(BACKEND_RENDERER MATCHES "OpenGLES2") diff --git a/DoConfig/CMakeLists.txt b/DoConfig/CMakeLists.txt index b7636f48..1d23ce30 100644 --- a/DoConfig/CMakeLists.txt +++ b/DoConfig/CMakeLists.txt @@ -70,14 +70,11 @@ endif() # glad -if(NOT TARGET glad) - add_subdirectory("../external/glad" "glad" EXCLUDE_FROM_ALL) -endif() - +add_subdirectory("../external/glad" "glad" EXCLUDE_FROM_ALL) target_link_libraries(DoConfig PRIVATE glad) find_package(OpenGL REQUIRED) -target_link_libraries(DoConfig PRIVATE OpenGL::GL ${CMAKE_DL_LIBS}) +target_link_libraries(DoConfig PRIVATE OpenGL::GL) # GLFW3 diff --git a/external/glad/CMakeLists.txt b/external/glad/CMakeLists.txt index 56b8523e..e67a755f 100644 --- a/external/glad/CMakeLists.txt +++ b/external/glad/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.12) +if(NOT TARGET glad) + project(glad LANGUAGES C) add_library(glad @@ -10,3 +12,5 @@ add_library(glad target_include_directories(glad PUBLIC "include") target_link_libraries(glad PRIVATE ${CMAKE_DL_LIBS}) + +endif(NOT TARGET glad) From d68fb53710ecb534d1a9a43325ffc99e08371fd3 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 02:06:26 +0100 Subject: [PATCH 08/46] Shut-up another warning --- src/Backends/Controller/GLFW3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Backends/Controller/GLFW3.cpp b/src/Backends/Controller/GLFW3.cpp index 6968a549..88d6b057 100644 --- a/src/Backends/Controller/GLFW3.cpp +++ b/src/Backends/Controller/GLFW3.cpp @@ -14,6 +14,8 @@ BOOL ControllerBackend_Init(void) BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) { + (void)status; + return FALSE; } From 8266db337268af8465bbfde57f625de8b3d2278a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 02:08:19 +0100 Subject: [PATCH 09/46] Shut-up another warning --- src/Backends/Rendering/Software.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index fd9bf02a..5d5f32cf 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -306,8 +306,6 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width return NULL; } - unsigned char *destination_pointer = glyph->pixels; - for (unsigned int y = 0; y < height; ++y) memcpy(&glyph->pixels[y * width], &pixels[y * pitch], width); From 4f2f6ad4f4de59813fd35adaf8c2d1930b3d5653 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 02:10:28 +0100 Subject: [PATCH 10/46] More warnings --- src/Backends/Rendering/SDLSurface.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 30431bc2..5a7bfbd8 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -130,6 +130,9 @@ void Backend_RestoreSurface(Backend_Surface *surface) unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { + (void)width; + (void)height; + if (surface == NULL) return NULL; @@ -140,6 +143,8 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) { (void)surface; + (void)width; + (void)height; } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) From ee7cf6799bbdfa9ec811aaeb87e2f1f2e90b7190 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 02:12:06 +0100 Subject: [PATCH 11/46] Yet another warning --- src/Backends/Rendering/OpenGL3.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index abd19e1f..bbda58c8 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -380,6 +380,7 @@ static void GlyphBatch_Draw(spritebatch_sprite_t *sprites, int count, int textur static unsigned char last_green; static unsigned char last_blue; + (void)texture_h; (void)udata; if (glyph_destination_surface == NULL) From 40464a9fc096a106c2be1819810e92cbd1eca160 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 14:41:16 +0100 Subject: [PATCH 12/46] Move-around Backend files Hoping to introduce some degree of grouping --- CMakeLists.txt | 12 ++++++------ .../{Controller/GLFW3.cpp => GLFW3/Controller.cpp} | 0 src/Backends/GLFW3/GLFW3.h | 7 +++++++ src/Backends/{Platform/GLFW3.cpp => GLFW3/Misc.cpp} | 1 + .../GLFW3-OpenGL3.cpp => GLFW3/Window-OpenGL3.cpp} | 6 ++---- .../Window-OpenGLES2.cpp} | 0 src/Backends/Rendering/OpenGL3.cpp | 2 +- .../{Controller/SDL2.cpp => SDL2/Controller.cpp} | 0 src/Backends/{Platform/SDL2.cpp => SDL2/Misc.cpp} | 1 + src/Backends/SDL2/SDL2.h | 5 +++++ .../SDL2-OpenGL3.cpp => SDL2/Window-OpenGL3.cpp} | 5 ++--- .../SDL2-OpenGLES2.cpp => SDL2/Window-OpenGLES2.cpp} | 0 src/Backends/{Window.h => Window-OpenGL.h} | 0 13 files changed, 25 insertions(+), 14 deletions(-) rename src/Backends/{Controller/GLFW3.cpp => GLFW3/Controller.cpp} (100%) create mode 100644 src/Backends/GLFW3/GLFW3.h rename src/Backends/{Platform/GLFW3.cpp => GLFW3/Misc.cpp} (99%) rename src/Backends/{Window/GLFW3-OpenGL3.cpp => GLFW3/Window-OpenGL3.cpp} (96%) rename src/Backends/{Window/GLFW3-OpenGLES2.cpp => GLFW3/Window-OpenGLES2.cpp} (100%) rename src/Backends/{Controller/SDL2.cpp => SDL2/Controller.cpp} (100%) rename src/Backends/{Platform/SDL2.cpp => SDL2/Misc.cpp} (99%) create mode 100644 src/Backends/SDL2/SDL2.h rename src/Backends/{Window/SDL2-OpenGL3.cpp => SDL2/Window-OpenGL3.cpp} (98%) rename src/Backends/{Window/SDL2-OpenGLES2.cpp => SDL2/Window-OpenGLES2.cpp} (100%) rename src/Backends/{Window.h => Window-OpenGL.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa45c715..5d3907c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -326,22 +326,22 @@ else() endif() if(BACKEND_PLATFORM MATCHES "SDL2") - target_sources(CSE2 PRIVATE "src/Backends/Platform/SDL2.cpp" "src/Backends/Controller/SDL2.cpp") + target_sources(CSE2 PRIVATE "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Misc.cpp" "src/Backends/SDL2/SDL2.h") elseif(BACKEND_PLATFORM MATCHES "GLFW3") - target_sources(CSE2 PRIVATE "src/Backends/Platform/GLFW3.cpp" "src/Backends/Controller/GLFW3.cpp") + target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" "src/Backends/GLFW3/Misc.cpp" "src/Backends/GLFW3/GLFW3.h") endif() if(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "OpenGL3") - target_sources(CSE2 PRIVATE "src/Backends/Window/SDL2-OpenGL3.cpp") + target_sources(CSE2 PRIVATE "src/Backends/SDL2/Window-OpenGL3.cpp") elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "OpenGLES2") - target_sources(CSE2 PRIVATE "src/Backends/Window/SDL2-OpenGLES2.cpp") + target_sources(CSE2 PRIVATE "src/Backends/SDL2/Window-OpenGLES2.cpp") elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "SDLTexture") elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "SDLSurface") elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "Software") elseif(BACKEND_PLATFORM MATCHES "GLFW3" AND BACKEND_RENDERER MATCHES "OpenGL3") - target_sources(CSE2 PRIVATE "src/Backends/Window/GLFW3-OpenGL3.cpp") + target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Window-OpenGL3.cpp") elseif(BACKEND_PLATFORM MATCHES "GLFW3" AND BACKEND_RENDERER MATCHES "OpenGLES2") - target_sources(CSE2 PRIVATE "src/Backends/Window/GLFW3-OpenGLES2.cpp") + target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Window-OpenGLES2.cpp") else() message(FATAL_ERROR "Invalid BACKEND_PLATFORM/BACKEND_RENDERER combination") endif() diff --git a/src/Backends/Controller/GLFW3.cpp b/src/Backends/GLFW3/Controller.cpp similarity index 100% rename from src/Backends/Controller/GLFW3.cpp rename to src/Backends/GLFW3/Controller.cpp diff --git a/src/Backends/GLFW3/GLFW3.h b/src/Backends/GLFW3/GLFW3.h new file mode 100644 index 00000000..5087e303 --- /dev/null +++ b/src/Backends/GLFW3/GLFW3.h @@ -0,0 +1,7 @@ +#pragma once + +#define GLFW_INCLUDE_NONE +#include +#undef GLFW_INCLUDE_NONE + +extern GLFWwindow *window; diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/GLFW3/Misc.cpp similarity index 99% rename from src/Backends/Platform/GLFW3.cpp rename to src/Backends/GLFW3/Misc.cpp index 2269fa04..e88b0be5 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -12,6 +12,7 @@ #include "../../WindowsWrapper.h" +#include "GLFW3.h" #include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" diff --git a/src/Backends/Window/GLFW3-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp similarity index 96% rename from src/Backends/Window/GLFW3-OpenGL3.cpp rename to src/Backends/GLFW3/Window-OpenGL3.cpp index 7df4dc0a..8eda4e92 100644 --- a/src/Backends/Window/GLFW3-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -1,4 +1,4 @@ -#include "../Window.h" +#include "../Window-OpenGL.h" #include #include @@ -13,9 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" - -// Horrible hack -extern GLFWwindow *window; +#include "GLFW3.h" BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) { diff --git a/src/Backends/Window/GLFW3-OpenGLES2.cpp b/src/Backends/GLFW3/Window-OpenGLES2.cpp similarity index 100% rename from src/Backends/Window/GLFW3-OpenGLES2.cpp rename to src/Backends/GLFW3/Window-OpenGLES2.cpp diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index bbda58c8..957f0cc4 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -19,7 +19,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "../Window.h" +#include "../Window-OpenGL.h" #include "../../Resource.h" #define TOTAL_VBOS 8 diff --git a/src/Backends/Controller/SDL2.cpp b/src/Backends/SDL2/Controller.cpp similarity index 100% rename from src/Backends/Controller/SDL2.cpp rename to src/Backends/SDL2/Controller.cpp diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/SDL2/Misc.cpp similarity index 99% rename from src/Backends/Platform/SDL2.cpp rename to src/Backends/SDL2/Misc.cpp index 1c221881..74a1bb44 100644 --- a/src/Backends/Platform/SDL2.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -10,6 +10,7 @@ #include "../../WindowsWrapper.h" +#include "../SDL2.h" #include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" diff --git a/src/Backends/SDL2/SDL2.h b/src/Backends/SDL2/SDL2.h new file mode 100644 index 00000000..31829946 --- /dev/null +++ b/src/Backends/SDL2/SDL2.h @@ -0,0 +1,5 @@ +#pragma once + +#include "SDL.h" + +extern SDL_Window *window; diff --git a/src/Backends/Window/SDL2-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp similarity index 98% rename from src/Backends/Window/SDL2-OpenGL3.cpp rename to src/Backends/SDL2/Window-OpenGL3.cpp index 9a8fff5a..d25df01e 100644 --- a/src/Backends/Window/SDL2-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -1,4 +1,4 @@ -#include "../Window.h" +#include "../Window-OpenGL.h" #include @@ -12,10 +12,9 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" +#include "../SDL2.h" #include "../../Resource.h" -extern SDL_Window *window; - static SDL_GLContext context; BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) diff --git a/src/Backends/Window/SDL2-OpenGLES2.cpp b/src/Backends/SDL2/Window-OpenGLES2.cpp similarity index 100% rename from src/Backends/Window/SDL2-OpenGLES2.cpp rename to src/Backends/SDL2/Window-OpenGLES2.cpp diff --git a/src/Backends/Window.h b/src/Backends/Window-OpenGL.h similarity index 100% rename from src/Backends/Window.h rename to src/Backends/Window-OpenGL.h From 5bb839136bab80e2c4605e40442edb138ecb83b5 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 16:53:58 +0100 Subject: [PATCH 13/46] Added controller support to GLFW3 backend --- src/Backends/GLFW3/Controller.cpp | 64 +++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 88d6b057..eecd271e 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -1,7 +1,17 @@ #include "../Controller.h" +#define GLFW_INCLUDE_NONE +#include + #include "../../WindowsWrapper.h" +#define DEADZONE (10000.0f / 32767.0f) + +static BOOL joystick_connected; +static int connected_joystick_id; +static float joystick_neutral_x; +static float joystick_neutral_y; + void ControllerBackend_Deinit(void) { @@ -9,17 +19,63 @@ void ControllerBackend_Deinit(void) BOOL ControllerBackend_Init(void) { - return FALSE; + for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) + { + if (glfwJoystickPresent(i) == GLFW_TRUE && glfwJoystickIsGamepad(i) == GLFW_TRUE) + { + joystick_connected = TRUE; + connected_joystick_id = i; + break; + } + } + + return joystick_connected; } BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) { - (void)status; + if (!joystick_connected) + return FALSE; - return FALSE; + if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) + return FALSE; + + int total_axis; + const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); + + status->bLeft = axis[0] < joystick_neutral_x - DEADZONE; + status->bRight = axis[0] > joystick_neutral_x + DEADZONE; + status->bUp = axis[1] < joystick_neutral_x - DEADZONE; + status->bDown = axis[1] > joystick_neutral_x + DEADZONE; + + int total_buttons; + const unsigned char *buttons = glfwGetJoystickButtons(connected_joystick_id, &total_buttons); + + if (total_buttons > 32) + total_buttons = 32; + + for (int i = 0; i < total_buttons; ++i) + status->bButton[i] = buttons[i] == GLFW_PRESS; + + for (int i = total_buttons; i < 32; ++i) + status->bButton[i] = FALSE; + + return TRUE; } BOOL ControllerBackend_ResetJoystickStatus(void) { - return FALSE; + if (!joystick_connected) + return FALSE; + + if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) + return FALSE; + + int total_axis; + const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); + + joystick_neutral_x = axis[0]; + joystick_neutral_y = axis[1]; + + return TRUE; } From dac8f704cd3511b2ce2535e33384dcb9a51367d7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 17:02:02 +0100 Subject: [PATCH 14/46] Cleanup and debug prints --- src/Backends/GLFW3/Controller.cpp | 11 +++++++++-- src/Backends/SDL2/Controller.cpp | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index eecd271e..345ecf95 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -1,5 +1,7 @@ #include "../Controller.h" +#include + #define GLFW_INCLUDE_NONE #include @@ -19,17 +21,22 @@ void ControllerBackend_Deinit(void) BOOL ControllerBackend_Init(void) { + for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) + if (glfwJoystickPresent(i) == GLFW_TRUE) + printf("Joystick #%d name: %s\n", i, glfwGetJoystickName(i)); + for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) { if (glfwJoystickPresent(i) == GLFW_TRUE && glfwJoystickIsGamepad(i) == GLFW_TRUE) { + printf("Joystick #%d selected\n", i); joystick_connected = TRUE; connected_joystick_id = i; - break; + return TRUE; } } - return joystick_connected; + return FALSE; } BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index 05b30c2d..a3434bb5 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -2,7 +2,6 @@ #include #include -#include #include "SDL.h" @@ -54,7 +53,10 @@ BOOL FindAndOpenDirectInputDevice(void) // Break as soon as a joystick is properly opened if (joystick != NULL) + { + printf("Joystick #%d selected\n", i); return TRUE; + } } return FALSE; From 3c691732a61d4085ba88e00e30aee4b23355951d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 17:09:14 +0100 Subject: [PATCH 15/46] Update glad #include paths --- src/Backends/GLFW3/Window-OpenGL3.cpp | 2 +- src/Backends/SDL2/Window-OpenGL3.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/GLFW3/Window-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp index 8eda4e92..e1f41409 100644 --- a/src/Backends/GLFW3/Window-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -6,7 +6,7 @@ #ifdef USE_OPENGLES2 #include #else -#include "../../../external/glad/include/glad/glad.h" +#include #endif #include diff --git a/src/Backends/SDL2/Window-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp index d25df01e..095a11c4 100644 --- a/src/Backends/SDL2/Window-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -5,7 +5,7 @@ #ifdef USE_OPENGLES2 #include #else -#include "../../../external/glad/include/glad/glad.h" +#include #endif #include "SDL.h" From 61758671787624abb7524e4deb100c9eccaee649 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 17:57:11 +0100 Subject: [PATCH 16/46] Fix build errors --- src/Backends/SDL2/Misc.cpp | 2 +- src/Backends/SDL2/Window-OpenGL3.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index 74a1bb44..6777a726 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -10,7 +10,7 @@ #include "../../WindowsWrapper.h" -#include "../SDL2.h" +#include "SDL2.h" #include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" diff --git a/src/Backends/SDL2/Window-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp index 095a11c4..cd46e939 100644 --- a/src/Backends/SDL2/Window-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -12,7 +12,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "../SDL2.h" +#include "SDL2.h" #include "../../Resource.h" static SDL_GLContext context; From e15091b207674e2c629b10f3b62ad94069ca8511 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 18:01:01 +0100 Subject: [PATCH 17/46] More fixes --- src/Backends/GLFW3/Window-OpenGLES2.cpp | 2 +- src/Backends/SDL2/Window-OpenGLES2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/GLFW3/Window-OpenGLES2.cpp b/src/Backends/GLFW3/Window-OpenGLES2.cpp index dd6c2b04..1144f8e9 100644 --- a/src/Backends/GLFW3/Window-OpenGLES2.cpp +++ b/src/Backends/GLFW3/Window-OpenGLES2.cpp @@ -1,2 +1,2 @@ #define USE_OPENGLES2 -#include "GLFW3-OpenGL3.cpp" +#include "Window-OpenGL3.cpp" diff --git a/src/Backends/SDL2/Window-OpenGLES2.cpp b/src/Backends/SDL2/Window-OpenGLES2.cpp index 6c480c10..1144f8e9 100644 --- a/src/Backends/SDL2/Window-OpenGLES2.cpp +++ b/src/Backends/SDL2/Window-OpenGLES2.cpp @@ -1,2 +1,2 @@ #define USE_OPENGLES2 -#include "SDL2-OpenGL3.cpp" +#include "Window-OpenGL3.cpp" From f5480444641f82be6b6c4234e757fffb2afe5dbd Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 18:05:41 +0100 Subject: [PATCH 18/46] Cleanup --- src/Backends/Rendering/SDLSurface.cpp | 3 +-- src/Backends/Rendering/SDLTexture.cpp | 3 +-- src/Backends/Rendering/Software.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 5a7bfbd8..1d7b46aa 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -9,6 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" +#include "SDL2.h" typedef struct Backend_Surface { @@ -20,8 +21,6 @@ typedef struct Backend_Glyph SDL_Surface *sdlsurface; } Backend_Glyph; -extern SDL_Window *window; - static SDL_Surface *window_sdlsurface; static Backend_Surface framebuffer; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index e06ca06f..b5fb61b3 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -13,6 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" +#include "SDL2.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" @@ -37,8 +38,6 @@ typedef struct Backend_Glyph unsigned int height; } Backend_Glyph; -extern SDL_Window *window; - static SDL_Renderer *renderer; static Backend_Surface framebuffer; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 5d5f32cf..e1ddbd8f 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -9,6 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" +#include "SDL2.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -28,8 +29,6 @@ typedef struct Backend_Glyph unsigned int height; } Backend_Glyph; -extern SDL_Window *window; - static SDL_Surface *window_sdlsurface; static SDL_Surface *framebuffer_sdlsurface; static Backend_Surface framebuffer; From cb869a4fd1152749fae38bc5307df00a561f56bf Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 18:13:44 +0100 Subject: [PATCH 19/46] Support GLFW <3.3 Travis's Ubuntu Bionic uses 3.2, causing it to fail. --- src/Backends/GLFW3/Controller.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 345ecf95..e73b6b80 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -27,7 +27,11 @@ BOOL ControllerBackend_Init(void) for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) { +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) if (glfwJoystickPresent(i) == GLFW_TRUE && glfwJoystickIsGamepad(i) == GLFW_TRUE) +#else + if (glfwJoystickPresent(i) == GLFW_TRUE) +#endif { printf("Joystick #%d selected\n", i); joystick_connected = TRUE; @@ -44,7 +48,11 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (!joystick_connected) return FALSE; +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) +#else + if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE) +#endif return FALSE; int total_axis; @@ -75,7 +83,11 @@ BOOL ControllerBackend_ResetJoystickStatus(void) if (!joystick_connected) return FALSE; +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) +#else + if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE) +#endif return FALSE; int total_axis; From 1543521625747c42ea2aaa5e4d42c47f625c77b3 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 18:36:48 +0100 Subject: [PATCH 20/46] Fix more errors x_x --- src/Backends/Rendering/SDLSurface.cpp | 2 +- src/Backends/Rendering/SDLTexture.cpp | 2 +- src/Backends/Rendering/Software.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 1d7b46aa..554116c5 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "SDL2.h" +#include "../SDL2/SDL2.h" typedef struct Backend_Surface { diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index b5fb61b3..04d624c3 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "SDL2.h" +#include "SDL2/SDL2.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index e1ddbd8f..df91dc0e 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "SDL2.h" +#include "../SDL2/SDL2.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) From 264d555073dd108e4c62d23b8b961749e34fa7e8 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 18:51:43 +0100 Subject: [PATCH 21/46] Forgot to CTRL-F goddammit --- src/Backends/Rendering/SDLTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 04d624c3..edc79128 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "SDL2/SDL2.h" +#include "../SDL2/SDL2.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" From 90714cb7a4327823e305c50f9a4f92943c1c2471 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 23:16:40 +0100 Subject: [PATCH 22/46] Apply some missing BOOL constants --- src/BossAlmo2.cpp | 6 +++--- src/BossBallos.cpp | 6 +++--- src/BossIronH.cpp | 6 +++--- src/BossOhm.cpp | 2 +- src/BossPress.cpp | 4 ++-- src/BossTwinD.cpp | 2 +- src/BossX.cpp | 2 +- src/NpcAct000.cpp | 4 ++-- src/NpcAct160.cpp | 6 +++--- src/NpcAct240.cpp | 2 +- src/NpcAct260.cpp | 2 +- src/NpcAct280.cpp | 4 ++-- src/NpcAct300.cpp | 2 +- src/TextScr.cpp | 2 +- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/BossAlmo2.cpp b/src/BossAlmo2.cpp index 266b5540..8fcf6b36 100644 --- a/src/BossAlmo2.cpp +++ b/src/BossAlmo2.cpp @@ -610,7 +610,7 @@ void ActBossChar_Undead(void) for (i = 0; i < 100; ++i) SetNpChar(4, npc->x + (Random(-128, 128) * 0x200), npc->y + (Random(-64, 64) * 0x200), Random(-128, 128) * 0x200, Random(-128, 128) * 0x200, 0, NULL, 0); - DeleteNpCharCode(282, 1); + DeleteNpCharCode(282, TRUE); gBoss[11].bits &= ~NPC_SHOOTABLE; for (i = 0; i < 12; ++i) @@ -663,8 +663,8 @@ void ActBossChar_Undead(void) for (i = 0; i < 20; ++i) gBoss[i].cond = 0; - DeleteNpCharCode(158, 1); - DeleteNpCharCode(301, 1); + DeleteNpCharCode(158, TRUE); + DeleteNpCharCode(301, TRUE); } break; diff --git a/src/BossBallos.cpp b/src/BossBallos.cpp index f5d39e43..fd2c5a03 100644 --- a/src/BossBallos.cpp +++ b/src/BossBallos.cpp @@ -469,7 +469,7 @@ void ActBossChar_Ballos(void) npc->act_wait = 0; npc->xm = 0; npc->ym = 0; - DeleteNpCharCode(339, 0); + DeleteNpCharCode(339, FALSE); // Fallthrough case 401: npc->y += ((159 * 0x200) - npc->y) / 8; @@ -674,8 +674,8 @@ void ActBossChar_Ballos(void) gBoss[4].cond = 0; gBoss[5].cond = 0; - DeleteNpCharCode(350, 1); - DeleteNpCharCode(348, 1); + DeleteNpCharCode(350, TRUE); + DeleteNpCharCode(348, TRUE); } break; diff --git a/src/BossIronH.cpp b/src/BossIronH.cpp index 816df71c..e1cc4998 100644 --- a/src/BossIronH.cpp +++ b/src/BossIronH.cpp @@ -167,9 +167,9 @@ void ActBossChar_Ironhead(void) for (i = 0; i < 0x20; ++i) SetNpChar(4, npc->x + (Random(-128, 128) * 0x200), npc->y + (Random(-64, 64) * 0x200), Random(-128, 128) * 0x200, Random(-128, 128) * 0x200, 0, NULL, 0x100); - DeleteNpCharCode(197, 1); - DeleteNpCharCode(271, 1); - DeleteNpCharCode(272, 1); + DeleteNpCharCode(197, TRUE); + DeleteNpCharCode(271, TRUE); + DeleteNpCharCode(272, TRUE); // Fallthrough case 1001: npc->tgt_x -= 1 * 0x200; diff --git a/src/BossOhm.cpp b/src/BossOhm.cpp index 577da46a..5ebd7bf1 100644 --- a/src/BossOhm.cpp +++ b/src/BossOhm.cpp @@ -518,6 +518,6 @@ void ActBossChar_Omega(void) gBoss[0].act_wait = 0; gBoss[0].damage = 0; gBoss[5].damage = 0; - DeleteNpCharCode(48, 1); + DeleteNpCharCode(48, TRUE); } } diff --git a/src/BossPress.cpp b/src/BossPress.cpp index c219bad6..63edd596 100644 --- a/src/BossPress.cpp +++ b/src/BossPress.cpp @@ -152,8 +152,8 @@ void ActBossChar_Press(void) npc->act_wait = 0; npc->count1 = 0; - DeleteNpCharCode(325, 1); - DeleteNpCharCode(330, 1); + DeleteNpCharCode(325, TRUE); + DeleteNpCharCode(330, TRUE); // Fallthrough case 501: if (++npc->act_wait % 0x10 == 0) diff --git a/src/BossTwinD.cpp b/src/BossTwinD.cpp index c50d4654..5e9cac15 100644 --- a/src/BossTwinD.cpp +++ b/src/BossTwinD.cpp @@ -524,7 +524,7 @@ void ActBossChar_Twin(void) case 1020: if (++gBoss[0].act_wait > 50) { - DeleteNpCharCode(211, 1); + DeleteNpCharCode(211, TRUE); gBoss[0].cond = 0; gBoss[1].cond = 0; gBoss[2].cond = 0; diff --git a/src/BossX.cpp b/src/BossX.cpp index d107a886..b17128b3 100644 --- a/src/BossX.cpp +++ b/src/BossX.cpp @@ -858,7 +858,7 @@ void ActBossChar_MonstX(void) for (i = 0; i < 20; ++i) gBoss[i].cond = 0; - DeleteNpCharCode(158, 1); + DeleteNpCharCode(158, TRUE); SetNpChar(159, npc->x, npc->y - (24 * 0x200), 0, 0, 0, NULL, 0); } diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 901e0691..7afc6b01 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -1314,8 +1314,8 @@ void ActNpc012(NPCHAR *npc) npc->ani_no = 3; npc->ym = -0x800; npc->bits |= NPC_IGNORE_SOLIDITY; - DeleteNpCharCode(150, 0); - DeleteNpCharCode(117, 0); + DeleteNpCharCode(150, FALSE); + DeleteNpCharCode(117, FALSE); SetNpChar(355, 0, 0, 0, 0, 0, npc, 0x100); SetNpChar(355, 0, 0, 0, 0, 1, npc, 0x100); } diff --git a/src/NpcAct160.cpp b/src/NpcAct160.cpp index a4dc6f80..debee189 100644 --- a/src/NpcAct160.cpp +++ b/src/NpcAct160.cpp @@ -51,7 +51,7 @@ void ActNpc160(NPCHAR *npc) if (npc->flag & 8) { - DeleteNpCharCode(161, 1); + DeleteNpCharCode(161, TRUE); for (i = 0; i < 4; ++i) SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, NULL, 0x100); @@ -245,7 +245,7 @@ void ActNpc162(NPCHAR *npc) switch (npc->act_no) { case 0: - DeleteNpCharCode(161, 1); + DeleteNpCharCode(161, TRUE); PlaySoundObject(72, 1); for (i = 0; i < 10; ++i) @@ -315,7 +315,7 @@ void ActNpc162(NPCHAR *npc) if (++npc->count1 < 60) break; - DeleteNpCharCode(161, 1); + DeleteNpCharCode(161, TRUE); npc->cond = 0; break; diff --git a/src/NpcAct240.cpp b/src/NpcAct240.cpp index a92a310e..902f1d8d 100644 --- a/src/NpcAct240.cpp +++ b/src/NpcAct240.cpp @@ -778,7 +778,7 @@ void ActNpc247(NPCHAR *npc) npc->xm = 0; npc->ym = 0; - DeleteNpCharCode(252, 1); + DeleteNpCharCode(252, TRUE); SetNpChar(4, npc->x, npc->y, 0, 0, 0, NULL, 0x100); SetNpChar(4, npc->x, npc->y, 0, 0, 0, NULL, 0x100); diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index fe7e81e2..9285a3af 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -1003,7 +1003,7 @@ void ActNpc267(NPCHAR *npc) break; case 500: - DeleteNpCharCode(269, 1); + DeleteNpCharCode(269, TRUE); npc->bits &= ~NPC_SHOOTABLE; npc->ani_no = 4; npc->ym += 0x20; diff --git a/src/NpcAct280.cpp b/src/NpcAct280.cpp index 111902e3..a194993c 100644 --- a/src/NpcAct280.cpp +++ b/src/NpcAct280.cpp @@ -116,7 +116,7 @@ void ActNpc281(NPCHAR *npc) case 21: if (++npc->act_wait > 250) { - DeleteNpCharCode(270, 0); + DeleteNpCharCode(270, FALSE); npc->act_no = 22; } @@ -689,7 +689,7 @@ void ActNpc284(NPCHAR *npc) npc->view.top = 16 * 0x200; npc->view.back = 16 * 0x200; npc->view.front = 16 * 0x200; - DeleteNpCharCode(257, 1); + DeleteNpCharCode(257, TRUE); break; case 20: diff --git a/src/NpcAct300.cpp b/src/NpcAct300.cpp index 3ee8e87e..7e1fe5ae 100644 --- a/src/NpcAct300.cpp +++ b/src/NpcAct300.cpp @@ -1339,7 +1339,7 @@ void ActNpc313(NPCHAR *npc) npc->ani_no = 8; npc->tgt_x = npc->x; npc->damage = 0; - DeleteNpCharCode(315, 1); + DeleteNpCharCode(315, TRUE); // Fallthrough case 501: npc->ym += 0x20; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 809ec0e5..96c15e99 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -1092,7 +1092,7 @@ int TextScriptProc(void) else if (IS_COMMAND('D','N','A')) { z = GetTextScriptNo(gTS.p_read + 4); - DeleteNpCharCode(z, 1); + DeleteNpCharCode(z, TRUE); gTS.p_read += 8; } else if (IS_COMMAND('B','O','A')) From 5d373918824dc44b151361dd91bcf06ffd683747 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 00:13:20 +0100 Subject: [PATCH 23/46] Document bullets a little --- src/Bullet.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 668ec61f..cf1ae66c 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -100,53 +100,72 @@ void PutBullet(int fx, int fy) } } -BULLET_TABLE gBulTbl[46] = -{ +BULLET_TABLE gBulTbl[46] = { + // Null {0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}}, + // Snake {4, 1, 20, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, {6, 1, 23, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, {8, 1, 30, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, + // Polar Star {1, 1, 8, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, {2, 1, 12, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, {4, 1, 16, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, + // Fireball {2, 2, 100, 8, 8, 16, 4, 2, {8, 8, 8, 8}}, {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, + // Machine Gun {2, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, {4, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, {6, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, + // Missile Launcher {0, 10, 50, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, {0, 10, 70, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, {0, 10, 90, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, + // Missile Launcher explosion {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, + // Bubbler {1, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, {2, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, {2, 1, 20, 8, 4, 4, 4, 4, {4, 4, 4, 4}}, + // Bubbler level 3 thorns {3, 1, 32, 32, 2, 2, 2, 2, {4, 4, 4, 4}}, + // Blade slashes {0, 100, 0, 36, 8, 8, 8, 8, {12, 12, 12, 12}}, + // Falling spike that deals 127 damage {127, 1, 2, 4, 8, 4, 8, 4, {0, 0, 0, 0}}, + // Blade {15, 1, 30, 36, 8, 8, 4, 2, {8, 8, 8, 8}}, {6, 3, 18, 36, 10, 10, 4, 2, {12, 12, 12, 12}}, {1, 100, 30, 36, 6, 6, 4, 4, {12, 12, 12, 12}}, + // Super Missile Launcher {0, 10, 30, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, {0, 10, 40, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, {0, 10, 40, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, + // Super Missile Launcher explosion {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, + // Nemesis {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, {4, 2, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, {1, 1, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, + // Spur {4, 4, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, {8, 8, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, {12, 12, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, + // Spur trail {3, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, {6, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, {11, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, + // Curly's Nemesis {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, + // Screen-nuke that kills all enemies {0, 4, 4, 4, 0, 0, 0, 0, {0, 0, 0, 0}}, + // Whimsical Star {1, 1, 1, 36, 1, 1, 1, 1, {1, 1, 1, 1}} }; @@ -2258,6 +2277,7 @@ void ActBullet(void) switch (gBul[i].code_bullet) { + // Snake case 1: ActBullet_Frontia1(&gBul[i]); break; @@ -2267,6 +2287,8 @@ void ActBullet(void) case 3: ActBullet_Frontia2(&gBul[i], 3); break; + + // Polar Star case 4: ActBullet_PoleStar(&gBul[i], 1); break; @@ -2276,6 +2298,8 @@ void ActBullet(void) case 6: ActBullet_PoleStar(&gBul[i], 3); break; + + // Fireball case 7: ActBullet_FireBall(&gBul[i], 1); break; @@ -2285,6 +2309,8 @@ void ActBullet(void) case 9: ActBullet_FireBall(&gBul[i], 3); break; + + // Machine Gun case 10: ActBullet_MachineGun(&gBul[i], 1); break; @@ -2294,6 +2320,8 @@ void ActBullet(void) case 12: ActBullet_MachineGun(&gBul[i], 3); break; + + // Missile Launcher case 13: ActBullet_Missile(&gBul[i], 1); break; @@ -2303,6 +2331,8 @@ void ActBullet(void) case 15: ActBullet_Missile(&gBul[i], 3); break; + + // Missile Launcher explosion case 16: ActBullet_Bom(&gBul[i], 1); break; @@ -2312,6 +2342,8 @@ void ActBullet(void) case 18: ActBullet_Bom(&gBul[i], 3); break; + + // Bubbler case 19: ActBullet_Bubblin1(&gBul[i]); break; @@ -2321,15 +2353,23 @@ void ActBullet(void) case 21: ActBullet_Bubblin3(&gBul[i]); break; + + // Bubbler level 3 spines case 22: ActBullet_Spine(&gBul[i]); break; + + // Blade slashes case 23: ActBullet_Edge(&gBul[i]); break; + + // Falling spike that deals 127 damage case 24: ActBullet_Drop(&gBul[i]); break; + + // Blade case 25: ActBullet_Sword1(&gBul[i]); break; @@ -2339,6 +2379,8 @@ void ActBullet(void) case 27: ActBullet_Sword3(&gBul[i]); break; + + // Super Missile Launcher case 28: ActBullet_SuperMissile(&gBul[i], 1); break; @@ -2348,6 +2390,8 @@ void ActBullet(void) case 30: ActBullet_SuperMissile(&gBul[i], 3); break; + + // Super Missile Launcher explosion case 31: ActBullet_SuperBom(&gBul[i], 1); break; @@ -2357,6 +2401,8 @@ void ActBullet(void) case 33: ActBullet_SuperBom(&gBul[i], 3); break; + + // Nemesis case 34: // Identical to case 43 ActBullet_Nemesis(&gBul[i], 1); break; @@ -2366,6 +2412,8 @@ void ActBullet(void) case 36: ActBullet_Nemesis(&gBul[i], 3); break; + + // Spur case 37: ActBullet_Spur(&gBul[i], 1); break; @@ -2375,6 +2423,8 @@ void ActBullet(void) case 39: ActBullet_Spur(&gBul[i], 3); break; + + // Spur trail case 40: ActBullet_SpurTail(&gBul[i], 1); break; @@ -2384,12 +2434,18 @@ void ActBullet(void) case 42: ActBullet_SpurTail(&gBul[i], 3); break; + + // Curly's Nemesis case 43: // Identical to case 34 ActBullet_Nemesis(&gBul[i], 1); break; + + // Screen-nuke that kills all enemies case 44: ActBullet_EnemyClear(&gBul[i]); break; + + // Whimsical Star case 45: ActBullet_Star(&gBul[i]); break; From bd280414ea192b82b2ca8f9dfd9330f6e92eba61 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 00:43:06 +0100 Subject: [PATCH 24/46] Cleanup --- src/BossAlmo1.cpp | 2 ++ src/BossAlmo2.cpp | 2 ++ src/BossBallos.cpp | 2 ++ src/BossOhm.cpp | 4 ++-- src/BossX.cpp | 4 +++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/BossAlmo1.cpp b/src/BossAlmo1.cpp index 06f5a407..0204779a 100644 --- a/src/BossAlmo1.cpp +++ b/src/BossAlmo1.cpp @@ -1,5 +1,7 @@ #include "BossAlmo1.h" +#include + #include "WindowsWrapper.h" #include "Boss.h" diff --git a/src/BossAlmo2.cpp b/src/BossAlmo2.cpp index 8fcf6b36..3d8b2591 100644 --- a/src/BossAlmo2.cpp +++ b/src/BossAlmo2.cpp @@ -1,5 +1,7 @@ #include "BossAlmo2.h" +#include + #include "WindowsWrapper.h" #include "Boss.h" diff --git a/src/BossBallos.cpp b/src/BossBallos.cpp index fd2c5a03..21d9cd44 100644 --- a/src/BossBallos.cpp +++ b/src/BossBallos.cpp @@ -1,5 +1,7 @@ #include "BossBallos.h" +#include + #include "WindowsWrapper.h" #include "Boss.h" diff --git a/src/BossOhm.cpp b/src/BossOhm.cpp index 5ebd7bf1..7530f841 100644 --- a/src/BossOhm.cpp +++ b/src/BossOhm.cpp @@ -1,6 +1,6 @@ #include "BossOhm.h" -#include +#include #include "WindowsWrapper.h" @@ -381,7 +381,7 @@ void ActBossChar_Omega(void) gBoss[0].count1 = 0; } - if (gBoss[0].act_wait < 30 && !(gBoss[0].act_wait % 5)) + if (gBoss[0].act_wait < 30 && gBoss[0].act_wait % 5 == 0) { SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-341, 341), -0x333, 0, NULL, 0x100); PlaySoundObject(39, 1); diff --git a/src/BossX.cpp b/src/BossX.cpp index b17128b3..e4829cb7 100644 --- a/src/BossX.cpp +++ b/src/BossX.cpp @@ -1,5 +1,7 @@ #include "BossX.h" +#include + #include "WindowsWrapper.h" #include "Boss.h" @@ -259,7 +261,7 @@ static void ActBossChar03_02(NPCHAR *npc) break; } - SetNpChar(158, npc->x + x, npc->y + y, 0, 0, direct, 0, 0x100); + SetNpChar(158, npc->x + x, npc->y + y, 0, 0, direct, NULL, 0x100); PlaySoundObject(39, 1); npc->act_wait = 120; From 39ddfd97911fa42c5e3ebacc5490e0a03cdf207d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 17:42:56 +0100 Subject: [PATCH 25/46] Abstract-away keyboard input Now, instead of keyboard input being completely-handled in the backend, it's merely abstracted, while still otherwise being handled in the game itself. This will be useful for the enhanced branch's key-rebinding menu. --- src/Backends/GLFW3/Misc.cpp | 259 ++++++++++++++---------------------- src/Backends/Platform.h | 83 ++++++++++++ src/Backends/SDL2/Misc.cpp | 248 ++++++++++++---------------------- src/Main.cpp | 172 ++++++++++++++++++++++++ 4 files changed, 438 insertions(+), 324 deletions(-) diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index e88b0be5..f309cab2 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -13,15 +14,31 @@ #include "../../WindowsWrapper.h" #include "GLFW3.h" -#include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" #include "../../Resource.h" +#define DO_KEY(GLFW_KEY, BACKEND_KEY) \ + case GLFW_KEY: \ + switch (action) \ + { \ + case GLFW_PRESS: \ + backend_keyboard_state[BACKEND_KEY] = TRUE; \ + break; \ + \ + case GLFW_RELEASE: \ + backend_keyboard_state[BACKEND_KEY] = FALSE; \ + break; \ + } \ + \ + break; + GLFWwindow *window; BOOL bActive = TRUE; +BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; +BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; static GLFWcursor* cursor; @@ -33,171 +50,87 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i switch (action) { + case GLFW_RELEASE: case GLFW_PRESS: switch (key) { - case GLFW_KEY_ESCAPE: - gKey |= KEY_ESCAPE; - break; + DO_KEY(GLFW_KEY_A, BACKEND_KEYBOARD_A) + DO_KEY(GLFW_KEY_B, BACKEND_KEYBOARD_B) + DO_KEY(GLFW_KEY_C, BACKEND_KEYBOARD_C) + DO_KEY(GLFW_KEY_D, BACKEND_KEYBOARD_D) + DO_KEY(GLFW_KEY_E, BACKEND_KEYBOARD_E) + DO_KEY(GLFW_KEY_F, BACKEND_KEYBOARD_F) + DO_KEY(GLFW_KEY_G, BACKEND_KEYBOARD_G) + DO_KEY(GLFW_KEY_H, BACKEND_KEYBOARD_H) + DO_KEY(GLFW_KEY_I, BACKEND_KEYBOARD_I) + DO_KEY(GLFW_KEY_J, BACKEND_KEYBOARD_J) + DO_KEY(GLFW_KEY_K, BACKEND_KEYBOARD_K) + DO_KEY(GLFW_KEY_L, BACKEND_KEYBOARD_L) + DO_KEY(GLFW_KEY_M, BACKEND_KEYBOARD_M) + DO_KEY(GLFW_KEY_N, BACKEND_KEYBOARD_N) + DO_KEY(GLFW_KEY_O, BACKEND_KEYBOARD_O) + DO_KEY(GLFW_KEY_P, BACKEND_KEYBOARD_P) + DO_KEY(GLFW_KEY_Q, BACKEND_KEYBOARD_Q) + DO_KEY(GLFW_KEY_R, BACKEND_KEYBOARD_R) + DO_KEY(GLFW_KEY_S, BACKEND_KEYBOARD_S) + DO_KEY(GLFW_KEY_T, BACKEND_KEYBOARD_T) + DO_KEY(GLFW_KEY_U, BACKEND_KEYBOARD_U) + DO_KEY(GLFW_KEY_V, BACKEND_KEYBOARD_V) + DO_KEY(GLFW_KEY_W, BACKEND_KEYBOARD_W) + DO_KEY(GLFW_KEY_X, BACKEND_KEYBOARD_X) + DO_KEY(GLFW_KEY_Y, BACKEND_KEYBOARD_Y) + DO_KEY(GLFW_KEY_Z, BACKEND_KEYBOARD_Z) + DO_KEY(GLFW_KEY_0, BACKEND_KEYBOARD_0) + DO_KEY(GLFW_KEY_1, BACKEND_KEYBOARD_1) + DO_KEY(GLFW_KEY_2, BACKEND_KEYBOARD_2) + DO_KEY(GLFW_KEY_3, BACKEND_KEYBOARD_3) + DO_KEY(GLFW_KEY_4, BACKEND_KEYBOARD_4) + DO_KEY(GLFW_KEY_5, BACKEND_KEYBOARD_5) + DO_KEY(GLFW_KEY_6, BACKEND_KEYBOARD_6) + DO_KEY(GLFW_KEY_7, BACKEND_KEYBOARD_7) + DO_KEY(GLFW_KEY_8, BACKEND_KEYBOARD_8) + DO_KEY(GLFW_KEY_9, BACKEND_KEYBOARD_9) + DO_KEY(GLFW_KEY_F1, BACKEND_KEYBOARD_F1) + DO_KEY(GLFW_KEY_F2, BACKEND_KEYBOARD_F2) + DO_KEY(GLFW_KEY_F3, BACKEND_KEYBOARD_F3) + DO_KEY(GLFW_KEY_F4, BACKEND_KEYBOARD_F4) + DO_KEY(GLFW_KEY_F5, BACKEND_KEYBOARD_F5) + DO_KEY(GLFW_KEY_F6, BACKEND_KEYBOARD_F6) + DO_KEY(GLFW_KEY_F7, BACKEND_KEYBOARD_F7) + DO_KEY(GLFW_KEY_F8, BACKEND_KEYBOARD_F8) + DO_KEY(GLFW_KEY_F9, BACKEND_KEYBOARD_F9) + DO_KEY(GLFW_KEY_F10, BACKEND_KEYBOARD_F10) + DO_KEY(GLFW_KEY_F11, BACKEND_KEYBOARD_F11) + DO_KEY(GLFW_KEY_F12, BACKEND_KEYBOARD_F12) + DO_KEY(GLFW_KEY_UP, BACKEND_KEYBOARD_UP) + DO_KEY(GLFW_KEY_DOWN, BACKEND_KEYBOARD_DOWN) + DO_KEY(GLFW_KEY_LEFT, BACKEND_KEYBOARD_LEFT) + DO_KEY(GLFW_KEY_RIGHT, BACKEND_KEYBOARD_RIGHT) + DO_KEY(GLFW_KEY_ESCAPE, BACKEND_KEYBOARD_ESCAPE) + DO_KEY(GLFW_KEY_GRAVE_ACCENT, BACKEND_KEYBOARD_BACK_QUOTE) + DO_KEY(GLFW_KEY_TAB, BACKEND_KEYBOARD_TAB) + DO_KEY(GLFW_KEY_CAPS_LOCK, BACKEND_KEYBOARD_CAPS_LOCK) + DO_KEY(GLFW_KEY_LEFT_SHIFT, BACKEND_KEYBOARD_LEFT_SHIFT) + DO_KEY(GLFW_KEY_LEFT_CONTROL, BACKEND_KEYBOARD_LEFT_CTRL) + DO_KEY(GLFW_KEY_LEFT_ALT, BACKEND_KEYBOARD_LEFT_ALT) + DO_KEY(GLFW_KEY_SPACE, BACKEND_KEYBOARD_SPACE) + DO_KEY(GLFW_KEY_RIGHT_ALT, BACKEND_KEYBOARD_RIGHT_ALT) + DO_KEY(GLFW_KEY_RIGHT_CONTROL, BACKEND_KEYBOARD_RIGHT_CTRL) + DO_KEY(GLFW_KEY_RIGHT_SHIFT, BACKEND_KEYBOARD_RIGHT_SHIFT) + DO_KEY(GLFW_KEY_ENTER, BACKEND_KEYBOARD_ENTER) + DO_KEY(GLFW_KEY_BACKSPACE, BACKEND_KEYBOARD_BACKSPACE) + DO_KEY(GLFW_KEY_MINUS, BACKEND_KEYBOARD_MINUS) + DO_KEY(GLFW_KEY_EQUAL, BACKEND_KEYBOARD_EQUALS) + DO_KEY(GLFW_KEY_LEFT_BRACKET, BACKEND_KEYBOARD_LEFT_BRACKET) + DO_KEY(GLFW_KEY_RIGHT_BRACKET, BACKEND_KEYBOARD_RIGHT_BRACKET) + DO_KEY(GLFW_KEY_BACKSLASH, BACKEND_KEYBOARD_BACK_SLASH) + DO_KEY(GLFW_KEY_SEMICOLON, BACKEND_KEYBOARD_SEMICOLON) + DO_KEY(GLFW_KEY_APOSTROPHE, BACKEND_KEYBOARD_APOSTROPHE) + DO_KEY(GLFW_KEY_COMMA, BACKEND_KEYBOARD_COMMA) + DO_KEY(GLFW_KEY_PERIOD, BACKEND_KEYBOARD_PERIOD) + DO_KEY(GLFW_KEY_SLASH, BACKEND_KEYBOARD_FORWARD_SLASH) - case GLFW_KEY_W: - gKey |= KEY_MAP; - break; - - case GLFW_KEY_LEFT: - gKey |= KEY_LEFT; - break; - - case GLFW_KEY_RIGHT: - gKey |= KEY_RIGHT; - break; - - case GLFW_KEY_UP: - gKey |= KEY_UP; - break; - - case GLFW_KEY_DOWN: - gKey |= KEY_DOWN; - break; - - case GLFW_KEY_X: - gKey |= KEY_X; - break; - - case GLFW_KEY_Z: - gKey |= KEY_Z; - break; - - case GLFW_KEY_S: - gKey |= KEY_ARMS; - break; - - case GLFW_KEY_A: - gKey |= KEY_ARMSREV; - break; - - case GLFW_KEY_LEFT_SHIFT: - case GLFW_KEY_RIGHT_SHIFT: - gKey |= KEY_SHIFT; - break; - - case GLFW_KEY_F1: - gKey |= KEY_F1; - break; - - case GLFW_KEY_F2: - gKey |= KEY_F2; - break; - - case GLFW_KEY_Q: - gKey |= KEY_ITEM; - break; - - case GLFW_KEY_COMMA: - gKey |= KEY_ALT_LEFT; - break; - - case GLFW_KEY_PERIOD: - gKey |= KEY_ALT_DOWN; - break; - - case GLFW_KEY_SLASH: - gKey |= KEY_ALT_RIGHT; - break; - - case GLFW_KEY_L: - gKey |= KEY_L; - break; - - case GLFW_KEY_EQUAL: - gKey |= KEY_PLUS; - break; - - case GLFW_KEY_F5: - gbUseJoystick = FALSE; - break; - } - - break; - - case GLFW_RELEASE: - switch (key) - { - case GLFW_KEY_ESCAPE: - gKey &= ~KEY_ESCAPE; - break; - - case GLFW_KEY_W: - gKey &= ~KEY_MAP; - break; - - case GLFW_KEY_LEFT: - gKey &= ~KEY_LEFT; - break; - - case GLFW_KEY_RIGHT: - gKey &= ~KEY_RIGHT; - break; - - case GLFW_KEY_UP: - gKey &= ~KEY_UP; - break; - - case GLFW_KEY_DOWN: - gKey &= ~KEY_DOWN; - break; - - case GLFW_KEY_X: - gKey &= ~KEY_X; - break; - - case GLFW_KEY_Z: - gKey &= ~KEY_Z; - break; - - case GLFW_KEY_S: - gKey &= ~KEY_ARMS; - break; - - case GLFW_KEY_A: - gKey &= ~KEY_ARMSREV; - break; - - case GLFW_KEY_LEFT_SHIFT: - case GLFW_KEY_RIGHT_SHIFT: - gKey &= ~KEY_SHIFT; - break; - - case GLFW_KEY_F1: - gKey &= ~KEY_F1; - break; - - case GLFW_KEY_F2: - gKey &= ~KEY_F2; - break; - - case GLFW_KEY_Q: - gKey &= ~KEY_ITEM; - break; - - case GLFW_KEY_COMMA: - gKey &= ~KEY_ALT_LEFT; - break; - - case GLFW_KEY_PERIOD: - gKey &= ~KEY_ALT_DOWN; - break; - - case GLFW_KEY_SLASH: - gKey &= ~KEY_ALT_RIGHT; - break; - - case GLFW_KEY_L: - gKey &= ~KEY_L; - break; - - case GLFW_KEY_EQUAL: - gKey &= ~KEY_PLUS; + default: break; } @@ -344,6 +277,8 @@ BOOL PlatformBackend_SystemTask(void) return FALSE; } + memcpy(backend_previous_keyboard_state, backend_keyboard_state, sizeof(backend_keyboard_state)); + glfwPollEvents(); while (!bActive) diff --git a/src/Backends/Platform.h b/src/Backends/Platform.h index 544fdcd5..52c246f2 100644 --- a/src/Backends/Platform.h +++ b/src/Backends/Platform.h @@ -2,7 +2,90 @@ #include "../WindowsWrapper.h" +enum +{ + // Based on US QWERTY + BACKEND_KEYBOARD_A, + BACKEND_KEYBOARD_B, + BACKEND_KEYBOARD_C, + BACKEND_KEYBOARD_D, + BACKEND_KEYBOARD_E, + BACKEND_KEYBOARD_F, + BACKEND_KEYBOARD_G, + BACKEND_KEYBOARD_H, + BACKEND_KEYBOARD_I, + BACKEND_KEYBOARD_J, + BACKEND_KEYBOARD_K, + BACKEND_KEYBOARD_L, + BACKEND_KEYBOARD_M, + BACKEND_KEYBOARD_N, + BACKEND_KEYBOARD_O, + BACKEND_KEYBOARD_P, + BACKEND_KEYBOARD_Q, + BACKEND_KEYBOARD_R, + BACKEND_KEYBOARD_S, + BACKEND_KEYBOARD_T, + BACKEND_KEYBOARD_U, + BACKEND_KEYBOARD_V, + BACKEND_KEYBOARD_W, + BACKEND_KEYBOARD_X, + BACKEND_KEYBOARD_Y, + BACKEND_KEYBOARD_Z, + BACKEND_KEYBOARD_0, + BACKEND_KEYBOARD_1, + BACKEND_KEYBOARD_2, + BACKEND_KEYBOARD_3, + BACKEND_KEYBOARD_4, + BACKEND_KEYBOARD_5, + BACKEND_KEYBOARD_6, + BACKEND_KEYBOARD_7, + BACKEND_KEYBOARD_8, + BACKEND_KEYBOARD_9, + BACKEND_KEYBOARD_F1, + BACKEND_KEYBOARD_F2, + BACKEND_KEYBOARD_F3, + BACKEND_KEYBOARD_F4, + BACKEND_KEYBOARD_F5, + BACKEND_KEYBOARD_F6, + BACKEND_KEYBOARD_F7, + BACKEND_KEYBOARD_F8, + BACKEND_KEYBOARD_F9, + BACKEND_KEYBOARD_F10, + BACKEND_KEYBOARD_F11, + BACKEND_KEYBOARD_F12, + BACKEND_KEYBOARD_UP, + BACKEND_KEYBOARD_DOWN, + BACKEND_KEYBOARD_LEFT, + BACKEND_KEYBOARD_RIGHT, + BACKEND_KEYBOARD_ESCAPE, + BACKEND_KEYBOARD_BACK_QUOTE, + BACKEND_KEYBOARD_TAB, + BACKEND_KEYBOARD_CAPS_LOCK, + BACKEND_KEYBOARD_LEFT_SHIFT, + BACKEND_KEYBOARD_LEFT_CTRL, + BACKEND_KEYBOARD_LEFT_ALT, + BACKEND_KEYBOARD_SPACE, + BACKEND_KEYBOARD_RIGHT_ALT, + BACKEND_KEYBOARD_RIGHT_CTRL, + BACKEND_KEYBOARD_RIGHT_SHIFT, + BACKEND_KEYBOARD_ENTER, + BACKEND_KEYBOARD_BACKSPACE, + BACKEND_KEYBOARD_MINUS, + BACKEND_KEYBOARD_EQUALS, + BACKEND_KEYBOARD_LEFT_BRACKET, + BACKEND_KEYBOARD_RIGHT_BRACKET, + BACKEND_KEYBOARD_BACK_SLASH, + BACKEND_KEYBOARD_SEMICOLON, + BACKEND_KEYBOARD_APOSTROPHE, + BACKEND_KEYBOARD_COMMA, + BACKEND_KEYBOARD_PERIOD, + BACKEND_KEYBOARD_FORWARD_SLASH, + BACKEND_KEYBOARD_TOTAL +}; + extern BOOL bActive; +extern BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; +extern BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; void PlatformBackend_Init(void); void PlatformBackend_Deinit(void); diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index 6777a726..e5bb565f 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -11,15 +11,21 @@ #include "../../WindowsWrapper.h" #include "SDL2.h" -#include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" #include "../../Resource.h" +#define DO_KEY(SDL_KEY, BACKEND_KEY) \ + case SDL_KEY: \ + backend_keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \ + break; + SDL_Window *window; BOOL bActive = TRUE; +BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; +BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; static SDL_Surface *cursor_surface; static SDL_Cursor *cursor; @@ -93,6 +99,8 @@ void PlaybackBackend_EnableDragAndDrop(void) BOOL PlatformBackend_SystemTask(void) { + memcpy(backend_previous_keyboard_state, backend_keyboard_state, sizeof(backend_keyboard_state)); + while (SDL_PollEvent(NULL) || !bActive) { SDL_Event event; @@ -102,171 +110,87 @@ BOOL PlatformBackend_SystemTask(void) switch (event.type) { + case SDL_KEYUP: case SDL_KEYDOWN: switch (event.key.keysym.sym) { - case SDLK_ESCAPE: - gKey |= KEY_ESCAPE; - break; + DO_KEY(SDLK_a, BACKEND_KEYBOARD_A) + DO_KEY(SDLK_b, BACKEND_KEYBOARD_B) + DO_KEY(SDLK_c, BACKEND_KEYBOARD_C) + DO_KEY(SDLK_d, BACKEND_KEYBOARD_D) + DO_KEY(SDLK_e, BACKEND_KEYBOARD_E) + DO_KEY(SDLK_f, BACKEND_KEYBOARD_F) + DO_KEY(SDLK_g, BACKEND_KEYBOARD_G) + DO_KEY(SDLK_h, BACKEND_KEYBOARD_H) + DO_KEY(SDLK_i, BACKEND_KEYBOARD_I) + DO_KEY(SDLK_j, BACKEND_KEYBOARD_J) + DO_KEY(SDLK_k, BACKEND_KEYBOARD_K) + DO_KEY(SDLK_l, BACKEND_KEYBOARD_L) + DO_KEY(SDLK_m, BACKEND_KEYBOARD_M) + DO_KEY(SDLK_n, BACKEND_KEYBOARD_N) + DO_KEY(SDLK_o, BACKEND_KEYBOARD_O) + DO_KEY(SDLK_p, BACKEND_KEYBOARD_P) + DO_KEY(SDLK_q, BACKEND_KEYBOARD_Q) + DO_KEY(SDLK_r, BACKEND_KEYBOARD_R) + DO_KEY(SDLK_s, BACKEND_KEYBOARD_S) + DO_KEY(SDLK_t, BACKEND_KEYBOARD_T) + DO_KEY(SDLK_u, BACKEND_KEYBOARD_U) + DO_KEY(SDLK_v, BACKEND_KEYBOARD_V) + DO_KEY(SDLK_w, BACKEND_KEYBOARD_W) + DO_KEY(SDLK_x, BACKEND_KEYBOARD_X) + DO_KEY(SDLK_y, BACKEND_KEYBOARD_Y) + DO_KEY(SDLK_z, BACKEND_KEYBOARD_Z) + DO_KEY(SDLK_0, BACKEND_KEYBOARD_0) + DO_KEY(SDLK_1, BACKEND_KEYBOARD_1) + DO_KEY(SDLK_2, BACKEND_KEYBOARD_2) + DO_KEY(SDLK_3, BACKEND_KEYBOARD_3) + DO_KEY(SDLK_4, BACKEND_KEYBOARD_4) + DO_KEY(SDLK_5, BACKEND_KEYBOARD_5) + DO_KEY(SDLK_6, BACKEND_KEYBOARD_6) + DO_KEY(SDLK_7, BACKEND_KEYBOARD_7) + DO_KEY(SDLK_8, BACKEND_KEYBOARD_8) + DO_KEY(SDLK_9, BACKEND_KEYBOARD_9) + DO_KEY(SDLK_F1, BACKEND_KEYBOARD_F1) + DO_KEY(SDLK_F2, BACKEND_KEYBOARD_F2) + DO_KEY(SDLK_F3, BACKEND_KEYBOARD_F3) + DO_KEY(SDLK_F4, BACKEND_KEYBOARD_F4) + DO_KEY(SDLK_F5, BACKEND_KEYBOARD_F5) + DO_KEY(SDLK_F6, BACKEND_KEYBOARD_F6) + DO_KEY(SDLK_F7, BACKEND_KEYBOARD_F7) + DO_KEY(SDLK_F8, BACKEND_KEYBOARD_F8) + DO_KEY(SDLK_F9, BACKEND_KEYBOARD_F9) + DO_KEY(SDLK_F10, BACKEND_KEYBOARD_F10) + DO_KEY(SDLK_F11, BACKEND_KEYBOARD_F11) + DO_KEY(SDLK_F12, BACKEND_KEYBOARD_F12) + DO_KEY(SDLK_UP, BACKEND_KEYBOARD_UP) + DO_KEY(SDLK_DOWN, BACKEND_KEYBOARD_DOWN) + DO_KEY(SDLK_LEFT, BACKEND_KEYBOARD_LEFT) + DO_KEY(SDLK_RIGHT, BACKEND_KEYBOARD_RIGHT) + DO_KEY(SDLK_ESCAPE, BACKEND_KEYBOARD_ESCAPE) + DO_KEY(SDLK_BACKQUOTE, BACKEND_KEYBOARD_BACK_QUOTE) + DO_KEY(SDLK_TAB, BACKEND_KEYBOARD_TAB) + DO_KEY(SDLK_CAPSLOCK, BACKEND_KEYBOARD_CAPS_LOCK) + DO_KEY(SDLK_LSHIFT, BACKEND_KEYBOARD_LEFT_SHIFT) + DO_KEY(SDLK_LCTRL, BACKEND_KEYBOARD_LEFT_CTRL) + DO_KEY(SDLK_LALT, BACKEND_KEYBOARD_LEFT_ALT) + DO_KEY(SDLK_SPACE, BACKEND_KEYBOARD_SPACE) + DO_KEY(SDLK_RALT, BACKEND_KEYBOARD_RIGHT_ALT) + DO_KEY(SDLK_RCTRL, BACKEND_KEYBOARD_RIGHT_CTRL) + DO_KEY(SDLK_RSHIFT, BACKEND_KEYBOARD_RIGHT_SHIFT) + DO_KEY(SDLK_RETURN, BACKEND_KEYBOARD_ENTER) + DO_KEY(SDLK_BACKSPACE, BACKEND_KEYBOARD_BACKSPACE) + DO_KEY(SDLK_MINUS, BACKEND_KEYBOARD_MINUS) + DO_KEY(SDLK_EQUALS, BACKEND_KEYBOARD_EQUALS) + DO_KEY(SDLK_LEFTBRACKET, BACKEND_KEYBOARD_LEFT_BRACKET) + DO_KEY(SDLK_RIGHTBRACKET, BACKEND_KEYBOARD_RIGHT_BRACKET) + DO_KEY(SDLK_BACKSLASH, BACKEND_KEYBOARD_BACK_SLASH) + DO_KEY(SDLK_SEMICOLON, BACKEND_KEYBOARD_SEMICOLON) + DO_KEY(SDLK_QUOTE, BACKEND_KEYBOARD_APOSTROPHE) + DO_KEY(SDLK_COMMA, BACKEND_KEYBOARD_COMMA) + DO_KEY(SDLK_PERIOD, BACKEND_KEYBOARD_PERIOD) + DO_KEY(SDLK_SLASH, BACKEND_KEYBOARD_FORWARD_SLASH) - case SDLK_w: - gKey |= KEY_MAP; - break; - - case SDLK_LEFT: - gKey |= KEY_LEFT; - break; - - case SDLK_RIGHT: - gKey |= KEY_RIGHT; - break; - - case SDLK_UP: - gKey |= KEY_UP; - break; - - case SDLK_DOWN: - gKey |= KEY_DOWN; - break; - - case SDLK_x: - gKey |= KEY_X; - break; - - case SDLK_z: - gKey |= KEY_Z; - break; - - case SDLK_s: - gKey |= KEY_ARMS; - break; - - case SDLK_a: - gKey |= KEY_ARMSREV; - break; - - case SDLK_LSHIFT: - case SDLK_RSHIFT: - gKey |= KEY_SHIFT; - break; - - case SDLK_F1: - gKey |= KEY_F1; - break; - - case SDLK_F2: - gKey |= KEY_F2; - break; - - case SDLK_q: - gKey |= KEY_ITEM; - break; - - case SDLK_COMMA: - gKey |= KEY_ALT_LEFT; - break; - - case SDLK_PERIOD: - gKey |= KEY_ALT_DOWN; - break; - - case SDLK_SLASH: - gKey |= KEY_ALT_RIGHT; - break; - - case SDLK_l: - gKey |= KEY_L; - break; - - case SDLK_PLUS: - gKey |= KEY_PLUS; - break; - - case SDLK_F5: - gbUseJoystick = FALSE; - break; - } - - break; - - case SDL_KEYUP: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - gKey &= ~KEY_ESCAPE; - break; - - case SDLK_w: - gKey &= ~KEY_MAP; - break; - - case SDLK_LEFT: - gKey &= ~KEY_LEFT; - break; - - case SDLK_RIGHT: - gKey &= ~KEY_RIGHT; - break; - - case SDLK_UP: - gKey &= ~KEY_UP; - break; - - case SDLK_DOWN: - gKey &= ~KEY_DOWN; - break; - - case SDLK_x: - gKey &= ~KEY_X; - break; - - case SDLK_z: - gKey &= ~KEY_Z; - break; - - case SDLK_s: - gKey &= ~KEY_ARMS; - break; - - case SDLK_a: - gKey &= ~KEY_ARMSREV; - break; - - case SDLK_LSHIFT: - case SDLK_RSHIFT: - gKey &= ~KEY_SHIFT; - break; - - case SDLK_F1: - gKey &= ~KEY_F1; - break; - - case SDLK_F2: - gKey &= ~KEY_F2; - break; - - case SDLK_q: - gKey &= ~KEY_ITEM; - break; - - case SDLK_COMMA: - gKey &= ~KEY_ALT_LEFT; - break; - - case SDLK_PERIOD: - gKey &= ~KEY_ALT_DOWN; - break; - - case SDLK_SLASH: - gKey &= ~KEY_ALT_RIGHT; - break; - - case SDLK_l: - gKey &= ~KEY_L; - break; - - case SDLK_PLUS: - gKey &= ~KEY_PLUS; + default: break; } diff --git a/src/Main.cpp b/src/Main.cpp index 50b7dc06..a8faaf7a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -382,6 +382,178 @@ BOOL SystemTask(void) if (!PlatformBackend_SystemTask()) return FALSE; + for (unsigned int i = 0; i < BACKEND_KEYBOARD_TOTAL; ++i) + { + if ((backend_keyboard_state[i] ^ backend_previous_keyboard_state[i]) & backend_keyboard_state[i]) + { + switch (i) + { + case BACKEND_KEYBOARD_ESCAPE: + gKey |= KEY_ESCAPE; + break; + + case BACKEND_KEYBOARD_W: + gKey |= KEY_MAP; + break; + + case BACKEND_KEYBOARD_LEFT: + gKey |= KEY_LEFT; + break; + + case BACKEND_KEYBOARD_RIGHT: + gKey |= KEY_RIGHT; + break; + + case BACKEND_KEYBOARD_UP: + gKey |= KEY_UP; + break; + + case BACKEND_KEYBOARD_DOWN: + gKey |= KEY_DOWN; + break; + + case BACKEND_KEYBOARD_X: + gKey |= KEY_X; + break; + + case BACKEND_KEYBOARD_Z: + gKey |= KEY_Z; + break; + + case BACKEND_KEYBOARD_S: + gKey |= KEY_ARMS; + break; + + case BACKEND_KEYBOARD_A: + gKey |= KEY_ARMSREV; + break; + + case BACKEND_KEYBOARD_LEFT_SHIFT: + case BACKEND_KEYBOARD_RIGHT_SHIFT: + gKey |= KEY_SHIFT; + break; + + case BACKEND_KEYBOARD_F1: + gKey |= KEY_F1; + break; + + case BACKEND_KEYBOARD_F2: + gKey |= KEY_F2; + break; + + case BACKEND_KEYBOARD_Q: + gKey |= KEY_ITEM; + break; + + case BACKEND_KEYBOARD_COMMA: + gKey |= KEY_ALT_LEFT; + break; + + case BACKEND_KEYBOARD_PERIOD: + gKey |= KEY_ALT_DOWN; + break; + + case BACKEND_KEYBOARD_FORWARD_SLASH: + gKey |= KEY_ALT_RIGHT; + break; + + case BACKEND_KEYBOARD_L: + gKey |= KEY_L; + break; + + case BACKEND_KEYBOARD_EQUALS: + gKey |= KEY_PLUS; + break; + + case BACKEND_KEYBOARD_F5: + gbUseJoystick = FALSE; + break; + } + } + else if ((backend_keyboard_state[i] ^ backend_previous_keyboard_state[i]) & backend_previous_keyboard_state[i]) + { + switch (i) + { + case BACKEND_KEYBOARD_ESCAPE: + gKey &= ~KEY_ESCAPE; + break; + + case BACKEND_KEYBOARD_W: + gKey &= ~KEY_MAP; + break; + + case BACKEND_KEYBOARD_LEFT: + gKey &= ~KEY_LEFT; + break; + + case BACKEND_KEYBOARD_RIGHT: + gKey &= ~KEY_RIGHT; + break; + + case BACKEND_KEYBOARD_UP: + gKey &= ~KEY_UP; + break; + + case BACKEND_KEYBOARD_DOWN: + gKey &= ~KEY_DOWN; + break; + + case BACKEND_KEYBOARD_X: + gKey &= ~KEY_X; + break; + + case BACKEND_KEYBOARD_Z: + gKey &= ~KEY_Z; + break; + + case BACKEND_KEYBOARD_S: + gKey &= ~KEY_ARMS; + break; + + case BACKEND_KEYBOARD_A: + gKey &= ~KEY_ARMSREV; + break; + + case BACKEND_KEYBOARD_LEFT_SHIFT: + case BACKEND_KEYBOARD_RIGHT_SHIFT: + gKey &= ~KEY_SHIFT; + break; + + case BACKEND_KEYBOARD_F1: + gKey &= ~KEY_F1; + break; + + case BACKEND_KEYBOARD_F2: + gKey &= ~KEY_F2; + break; + + case BACKEND_KEYBOARD_Q: + gKey &= ~KEY_ITEM; + break; + + case BACKEND_KEYBOARD_COMMA: + gKey &= ~KEY_ALT_LEFT; + break; + + case BACKEND_KEYBOARD_PERIOD: + gKey &= ~KEY_ALT_DOWN; + break; + + case BACKEND_KEYBOARD_FORWARD_SLASH: + gKey &= ~KEY_ALT_RIGHT; + break; + + case BACKEND_KEYBOARD_L: + gKey &= ~KEY_L; + break; + + case BACKEND_KEYBOARD_EQUALS: + gKey &= ~KEY_PLUS; + break; + } + } + } + // Run joystick code if (gbUseJoystick) JoystickProc(); From b72b631e950479478d5a6516c6e9c3ccf1a27864 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 17:47:45 +0100 Subject: [PATCH 26/46] Simplify GLFW code --- src/Backends/GLFW3/Misc.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index f309cab2..df8e0f91 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -21,17 +21,7 @@ #define DO_KEY(GLFW_KEY, BACKEND_KEY) \ case GLFW_KEY: \ - switch (action) \ - { \ - case GLFW_PRESS: \ - backend_keyboard_state[BACKEND_KEY] = TRUE; \ - break; \ - \ - case GLFW_RELEASE: \ - backend_keyboard_state[BACKEND_KEY] = FALSE; \ - break; \ - } \ - \ + backend_keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \ break; GLFWwindow *window; From 0cf1a781b715fe35978724b7a16352823ab02624 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 18:38:56 +0100 Subject: [PATCH 27/46] Add hotplugging support to the GLFW3 backend The GLFW windowing backend supports window-resizing, so I don't think it's wrong to add enhancements to the backend code. It's not like the SDL2 backend emulates DirectDraw's unstable framerate or anything. --- src/Backends/GLFW3/Controller.cpp | 81 +++++++++++++++---------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index e73b6b80..69bd4b81 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -11,8 +11,38 @@ static BOOL joystick_connected; static int connected_joystick_id; -static float joystick_neutral_x; -static float joystick_neutral_y; + +static void JoystickCallback(int joystick_id, int event) +{ + switch (event) + { + case GLFW_CONNECTED: + printf("Joystick #%d connected - %s\n", joystick_id, glfwGetJoystickName(joystick_id)); + + if (!joystick_connected) + { +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) + if (glfwJoystickIsGamepad(joystick_id) == GLFW_TRUE) // Avoid selecting things like laptop touchpads +#endif + { + printf("Joystick #%d selected\n", joystick_id); + joystick_connected = TRUE; + connected_joystick_id = joystick_id; + } + } + + break; + + case GLFW_DISCONNECTED: + if (joystick_connected && joystick_id == connected_joystick_id) + { + printf("Joystick #%d disconnected\n", connected_joystick_id); + joystick_connected = FALSE; + } + + break; + } +} void ControllerBackend_Deinit(void) { @@ -23,24 +53,11 @@ BOOL ControllerBackend_Init(void) { for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) if (glfwJoystickPresent(i) == GLFW_TRUE) - printf("Joystick #%d name: %s\n", i, glfwGetJoystickName(i)); + JoystickCallback(i, GLFW_CONNECTED); - for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) - { -#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) - if (glfwJoystickPresent(i) == GLFW_TRUE && glfwJoystickIsGamepad(i) == GLFW_TRUE) -#else - if (glfwJoystickPresent(i) == GLFW_TRUE) -#endif - { - printf("Joystick #%d selected\n", i); - joystick_connected = TRUE; - connected_joystick_id = i; - return TRUE; - } - } + glfwSetJoystickCallback(JoystickCallback); - return FALSE; + return TRUE; } BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) @@ -48,20 +65,13 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (!joystick_connected) return FALSE; -#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) - if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) -#else - if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE) -#endif - return FALSE; - int total_axis; const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); - status->bLeft = axis[0] < joystick_neutral_x - DEADZONE; - status->bRight = axis[0] > joystick_neutral_x + DEADZONE; - status->bUp = axis[1] < joystick_neutral_x - DEADZONE; - status->bDown = axis[1] > joystick_neutral_x + DEADZONE; + status->bLeft = axis[0] < -DEADZONE; + status->bRight = axis[0] > DEADZONE; + status->bUp = axis[1] < -DEADZONE; + status->bDown = axis[1] > DEADZONE; int total_buttons; const unsigned char *buttons = glfwGetJoystickButtons(connected_joystick_id, &total_buttons); @@ -83,18 +93,5 @@ BOOL ControllerBackend_ResetJoystickStatus(void) if (!joystick_connected) return FALSE; -#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) - if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE || glfwJoystickIsGamepad(connected_joystick_id) == GLFW_FALSE) -#else - if (glfwJoystickPresent(connected_joystick_id) == GLFW_FALSE) -#endif - return FALSE; - - int total_axis; - const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); - - joystick_neutral_x = axis[0]; - joystick_neutral_y = axis[1]; - return TRUE; } From e874b7535722a72456a20d2182b28f65f79a4f60 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 18:55:44 +0100 Subject: [PATCH 28/46] Comment GLFW3 code, restore some vanilla behaviour --- src/Backends/GLFW3/Controller.cpp | 38 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 69bd4b81..1190cf43 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -11,6 +11,8 @@ static BOOL joystick_connected; static int connected_joystick_id; +static int joystick_neutral_x; +static int joystick_neutral_y; static void JoystickCallback(int joystick_id, int event) { @@ -21,13 +23,23 @@ static void JoystickCallback(int joystick_id, int event) if (!joystick_connected) { -#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) - if (glfwJoystickIsGamepad(joystick_id) == GLFW_TRUE) // Avoid selecting things like laptop touchpads -#endif + int total_axis; + const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); + + if (total_axis >= 2) { - printf("Joystick #%d selected\n", joystick_id); - joystick_connected = TRUE; - connected_joystick_id = joystick_id; +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) + if (glfwJoystickIsGamepad(joystick_id) == GLFW_TRUE) // Avoid selecting things like laptop touchpads +#endif + { + printf("Joystick #%d selected\n", joystick_id); + joystick_connected = TRUE; + connected_joystick_id = joystick_id; + + // Reset default stick positions (this is performed in ResetJoystickStatus in vanilla Cave Story + joystick_neutral_x = axis[0]; + joystick_neutral_y = axis[1]; + } } } @@ -51,10 +63,12 @@ void ControllerBackend_Deinit(void) BOOL ControllerBackend_Init(void) { + // Connect joysticks that are already plugged-in for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) if (glfwJoystickPresent(i) == GLFW_TRUE) JoystickCallback(i, GLFW_CONNECTED); + // Set-up the callback for future (dis)connections glfwSetJoystickCallback(JoystickCallback); return TRUE; @@ -65,14 +79,16 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (!joystick_connected) return FALSE; + // Read axis int total_axis; const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); - status->bLeft = axis[0] < -DEADZONE; - status->bRight = axis[0] > DEADZONE; - status->bUp = axis[1] < -DEADZONE; - status->bDown = axis[1] > DEADZONE; + status->bLeft = axis[0] < joystick_neutral_x - DEADZONE; + status->bRight = axis[0] > joystick_neutral_x + DEADZONE; + status->bUp = axis[1] < joystick_neutral_y - DEADZONE; + status->bDown = axis[1] > joystick_neutral_y + DEADZONE; + // Read buttons int total_buttons; const unsigned char *buttons = glfwGetJoystickButtons(connected_joystick_id, &total_buttons); @@ -93,5 +109,7 @@ BOOL ControllerBackend_ResetJoystickStatus(void) if (!joystick_connected) return FALSE; + // The code that would normally run here has been moved to JoystickCallback, to better-support hotplugging + return TRUE; } From 659f89ea85658e789eafb66d1447617d691d925f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:03:19 +0100 Subject: [PATCH 29/46] Cleanup and proper deinitialisation --- src/Backends/GLFW3/Controller.cpp | 9 ++++++++- src/Backends/SDL2/Controller.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 1190cf43..20553e1b 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -1,5 +1,6 @@ #include "../Controller.h" +#include #include #define GLFW_INCLUDE_NONE @@ -58,7 +59,12 @@ static void JoystickCallback(int joystick_id, int event) void ControllerBackend_Deinit(void) { - + glfwSetJoystickCallback(NULL); + + joystick_connected = FALSE; + connected_joystick_id = 0; + joystick_neutral_x = 0; + joystick_neutral_y = 0; } BOOL ControllerBackend_Init(void) @@ -92,6 +98,7 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) int total_buttons; const unsigned char *buttons = glfwGetJoystickButtons(connected_joystick_id, &total_buttons); + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) if (total_buttons > 32) total_buttons = 32; diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index a3434bb5..2072ef20 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -67,7 +67,7 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (joystick == NULL) return FALSE; - // The original Input.cpp assumed there were 32 buttons (because of DirectInput's 'DIJOYSTATE' struct) + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) int numButtons = SDL_JoystickNumButtons(joystick); if (numButtons > 32) numButtons = 32; From d957c40649890ef0ee40fe46b422198dbeb88fcf Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:04:20 +0100 Subject: [PATCH 30/46] Fix bug --- src/Backends/GLFW3/Controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 20553e1b..2810c7d2 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -25,7 +25,7 @@ static void JoystickCallback(int joystick_id, int event) if (!joystick_connected) { int total_axis; - const float *axis = glfwGetJoystickAxes(connected_joystick_id, &total_axis); + const float *axis = glfwGetJoystickAxes(joystick_id, &total_axis); if (total_axis >= 2) { From e00ad1cd78716b61bb75741c2e9baffe77eceea2 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:04:56 +0100 Subject: [PATCH 31/46] Shuffle code --- src/Backends/Controller.h | 2 +- src/Backends/GLFW3/Controller.cpp | 20 ++++++++++---------- src/Backends/SDL2/Controller.cpp | 24 ++++++++++++------------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Backends/Controller.h b/src/Backends/Controller.h index 1e9f60e2..21339234 100644 --- a/src/Backends/Controller.h +++ b/src/Backends/Controller.h @@ -4,7 +4,7 @@ #include "../Input.h" -void ControllerBackend_Deinit(void); BOOL ControllerBackend_Init(void); +void ControllerBackend_Deinit(void); BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status); BOOL ControllerBackend_ResetJoystickStatus(void); diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 2810c7d2..71e83122 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -57,16 +57,6 @@ static void JoystickCallback(int joystick_id, int event) } } -void ControllerBackend_Deinit(void) -{ - glfwSetJoystickCallback(NULL); - - joystick_connected = FALSE; - connected_joystick_id = 0; - joystick_neutral_x = 0; - joystick_neutral_y = 0; -} - BOOL ControllerBackend_Init(void) { // Connect joysticks that are already plugged-in @@ -80,6 +70,16 @@ BOOL ControllerBackend_Init(void) return TRUE; } +void ControllerBackend_Deinit(void) +{ + glfwSetJoystickCallback(NULL); + + joystick_connected = FALSE; + connected_joystick_id = 0; + joystick_neutral_x = 0; + joystick_neutral_y = 0; +} + BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) { if (!joystick_connected) diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index 2072ef20..2713753c 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -12,18 +12,6 @@ static SDL_Joystick *joystick = NULL; static int joystick_neutral_x = 0; static int joystick_neutral_y = 0; -void ControllerBackend_Deinit(void) -{ - // Close opened joystick (if exists) - if (joystick != NULL) - { - SDL_JoystickClose(joystick); - joystick = NULL; - } - - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); -} - // It looks like Pixel declared his functions early, so he could forward-reference BOOL FindAndOpenDirectInputDevice(void); @@ -37,6 +25,18 @@ BOOL ControllerBackend_Init(void) return TRUE; } +void ControllerBackend_Deinit(void) +{ + // Close opened joystick (if exists) + if (joystick != NULL) + { + SDL_JoystickClose(joystick); + joystick = NULL; + } + + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); +} + // The original name for this function and its variables are unknown. // This function finds and hooks the first available DirectInput device (or SDL Joystick, in this case). BOOL FindAndOpenDirectInputDevice(void) From 7f6574117d80090e6ceffaefef5e8ff2f0c0d5dc Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:14:40 +0100 Subject: [PATCH 32/46] Clean-up SDL2 controller backend --- src/Backends/SDL2/Controller.cpp | 50 ++++++++++---------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index 2713753c..288165e0 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -7,27 +7,32 @@ #include "../../WindowsWrapper.h" -// The original names for these variables are unknown -static SDL_Joystick *joystick = NULL; -static int joystick_neutral_x = 0; -static int joystick_neutral_y = 0; - -// It looks like Pixel declared his functions early, so he could forward-reference -BOOL FindAndOpenDirectInputDevice(void); +static SDL_Joystick *joystick; +static int joystick_neutral_x; +static int joystick_neutral_y; BOOL ControllerBackend_Init(void) { SDL_InitSubSystem(SDL_INIT_JOYSTICK); - if (!FindAndOpenDirectInputDevice()) - return FALSE; + for (int i = 0; i < SDL_NumJoysticks(); ++i) + { + printf("Joystick #%d connected - %s\n", i, SDL_JoystickNameForIndex(i)); + + if (joystick == NULL) + { + joystick = SDL_JoystickOpen(i); + + if (joystick != NULL) + printf("Joystick #%d selected\n", i); + } + } return TRUE; } void ControllerBackend_Deinit(void) { - // Close opened joystick (if exists) if (joystick != NULL) { SDL_JoystickClose(joystick); @@ -37,31 +42,6 @@ void ControllerBackend_Deinit(void) SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } -// The original name for this function and its variables are unknown. -// This function finds and hooks the first available DirectInput device (or SDL Joystick, in this case). -BOOL FindAndOpenDirectInputDevice(void) -{ - int i; - - for (i = 0; i < SDL_NumJoysticks(); ++i) - printf("Joystick #%d name: %s\n", i, SDL_JoystickNameForIndex(i)); - - // Open first available joystick - for (i = 0; i < SDL_NumJoysticks(); ++i) - { - joystick = SDL_JoystickOpen(i); - - // Break as soon as a joystick is properly opened - if (joystick != NULL) - { - printf("Joystick #%d selected\n", i); - return TRUE; - } - } - - return FALSE; -} - BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) { if (joystick == NULL) From 87e8a75df40c8f87ca280b4ca2b0d014b6b08742 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:18:46 +0100 Subject: [PATCH 33/46] Rename GLFW3.h/SDL2.h --- src/Backends/GLFW3/Misc.cpp | 2 +- src/Backends/GLFW3/{GLFW3.h => Platform.h} | 0 src/Backends/GLFW3/Window-OpenGL3.cpp | 2 +- src/Backends/Rendering/SDLSurface.cpp | 2 +- src/Backends/Rendering/SDLTexture.cpp | 2 +- src/Backends/Rendering/Software.cpp | 2 +- src/Backends/SDL2/Misc.cpp | 2 +- src/Backends/SDL2/{SDL2.h => Platform.h} | 0 src/Backends/SDL2/Window-OpenGL3.cpp | 2 +- 9 files changed, 7 insertions(+), 7 deletions(-) rename src/Backends/GLFW3/{GLFW3.h => Platform.h} (100%) rename src/Backends/SDL2/{SDL2.h => Platform.h} (100%) diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index df8e0f91..90ed9099 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" -#include "GLFW3.h" +#include "Platform.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" diff --git a/src/Backends/GLFW3/GLFW3.h b/src/Backends/GLFW3/Platform.h similarity index 100% rename from src/Backends/GLFW3/GLFW3.h rename to src/Backends/GLFW3/Platform.h diff --git a/src/Backends/GLFW3/Window-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp index e1f41409..0903c869 100644 --- a/src/Backends/GLFW3/Window-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "GLFW3.h" +#include "Platform.h" BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) { diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 554116c5..27aa6cd4 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "../SDL2/SDL2.h" +#include "../SDL2/Platform.h" typedef struct Backend_Surface { diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index edc79128..2af8a4ac 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "../SDL2/SDL2.h" +#include "../SDL2/Platform.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index df91dc0e..2e220355 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "../SDL2/SDL2.h" +#include "../SDL2/Platform.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index e5bb565f..dca9a6c7 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -10,7 +10,7 @@ #include "../../WindowsWrapper.h" -#include "SDL2.h" +#include "Platform.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" diff --git a/src/Backends/SDL2/SDL2.h b/src/Backends/SDL2/Platform.h similarity index 100% rename from src/Backends/SDL2/SDL2.h rename to src/Backends/SDL2/Platform.h diff --git a/src/Backends/SDL2/Window-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp index cd46e939..e33474af 100644 --- a/src/Backends/SDL2/Window-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -12,7 +12,7 @@ #include "../../WindowsWrapper.h" #include "../Platform.h" -#include "SDL2.h" +#include "Platform.h" #include "../../Resource.h" static SDL_GLContext context; From 7ee2e68c2e49fa5aa5706166e89c1aff7db7643b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:28:52 +0100 Subject: [PATCH 34/46] Fix --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d3907c9..a2592193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -326,9 +326,9 @@ else() endif() if(BACKEND_PLATFORM MATCHES "SDL2") - target_sources(CSE2 PRIVATE "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Misc.cpp" "src/Backends/SDL2/SDL2.h") + target_sources(CSE2 PRIVATE "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Misc.cpp" "src/Backends/SDL2/Platform.h") elseif(BACKEND_PLATFORM MATCHES "GLFW3") - target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" "src/Backends/GLFW3/Misc.cpp" "src/Backends/GLFW3/GLFW3.h") + target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" "src/Backends/GLFW3/Misc.cpp" "src/Backends/GLFW3/Platform.h") endif() if(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "OpenGL3") From 65325e2b34f68be94398df393e6156183a797590 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:50:52 +0100 Subject: [PATCH 35/46] Add hotplugging support to SDL2 backend --- src/Backends/GLFW3/Misc.cpp | 5 +- src/Backends/SDL2/Controller.cpp | 78 ++++++++++++++++---------------- src/Backends/SDL2/Misc.cpp | 14 ++++-- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index 90ed9099..f3034d8a 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -1,4 +1,5 @@ #include "../Platform.h" +#include "Platform.h" #include #include @@ -9,11 +10,9 @@ #include -#include "../Rendering.h" - #include "../../WindowsWrapper.h" -#include "Platform.h" +#include "../Rendering.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index 288165e0..ace9d913 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -1,4 +1,5 @@ #include "../Controller.h" +#include "Controller.h" #include #include @@ -11,23 +12,12 @@ static SDL_Joystick *joystick; static int joystick_neutral_x; static int joystick_neutral_y; +void ControllerBackend_JoystickCallback(int joystick_id, BOOL connected); + BOOL ControllerBackend_Init(void) { SDL_InitSubSystem(SDL_INIT_JOYSTICK); - for (int i = 0; i < SDL_NumJoysticks(); ++i) - { - printf("Joystick #%d connected - %s\n", i, SDL_JoystickNameForIndex(i)); - - if (joystick == NULL) - { - joystick = SDL_JoystickOpen(i); - - if (joystick != NULL) - printf("Joystick #%d selected\n", i); - } - } - return TRUE; } @@ -53,35 +43,20 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) numButtons = 32; // Read whatever buttons actually exist - int i = 0; - for (; i < numButtons; ++i) - { - if (SDL_JoystickGetButton(joystick, i) != 0) - status->bButton[i] = TRUE; - else - status->bButton[i] = FALSE; - } + for (int i = 0; i < numButtons; ++i) + status->bButton[i] = SDL_JoystickGetButton(joystick, i); // Blank the buttons that do not - for (; i < 32; ++i) + for (int i = numButtons; i < 32; ++i) status->bButton[i] = FALSE; - status->bDown = FALSE; - status->bRight = FALSE; - status->bUp = FALSE; - status->bLeft = FALSE; - const Sint16 joystick_x = SDL_JoystickGetAxis(joystick, 0); - if (joystick_x < joystick_neutral_x - 10000) - status->bLeft = TRUE; - else if (joystick_x > joystick_neutral_x + 10000) - status->bRight = TRUE; - const Sint16 joystick_y = SDL_JoystickGetAxis(joystick, 1); - if (joystick_y < joystick_neutral_y - 10000) - status->bUp = TRUE; - else if (joystick_y > joystick_neutral_y + 10000) - status->bDown = TRUE; + + status->bLeft = joystick_x < joystick_neutral_x - 10000; + status->bRight = joystick_x > joystick_neutral_x + 10000; + status->bUp = joystick_y < joystick_neutral_y - 10000; + status->bDown = joystick_y > joystick_neutral_y + 10000; return TRUE; } @@ -91,8 +66,35 @@ BOOL ControllerBackend_ResetJoystickStatus(void) if (joystick == NULL) return FALSE; - joystick_neutral_x = SDL_JoystickGetAxis(joystick, 0); - joystick_neutral_y = SDL_JoystickGetAxis(joystick, 1); + // The code that would normally run here has been moved to JoystickCallback, to better-support hotplugging return TRUE; } + +void ControllerBackend_JoystickConnect(Sint32 joystick_id) +{ + printf("Joystick #%d connected - %s\n", joystick_id, SDL_JoystickNameForIndex(joystick_id)); + + if (joystick == NULL) + { + joystick = SDL_JoystickOpen(joystick_id); + + if (joystick != NULL) + { + printf("Joystick #%d selected\n", joystick_id); + + // Reset default stick positions (this is performed in ResetJoystickStatus in vanilla Cave Story + joystick_neutral_x = SDL_JoystickGetAxis(joystick, 0); + joystick_neutral_y = SDL_JoystickGetAxis(joystick, 1); + } + } +} + +void ControllerBackend_JoystickDisconnect(Sint32 joystick_id) +{ + if (joystick_id == SDL_JoystickInstanceID(joystick)) + { + printf("Joystick #%d disconnected\n", joystick_id); + joystick = NULL; + } +} diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index dca9a6c7..827138c7 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -1,4 +1,5 @@ #include "../Platform.h" +#include "Platform.h" #include #include @@ -6,11 +7,10 @@ #include "SDL.h" -#include "../Rendering.h" - #include "../../WindowsWrapper.h" -#include "Platform.h" +#include "Controller.h" +#include "../Rendering.h" #include "../../Main.h" #include "../../Organya.h" #include "../../Profile.h" @@ -196,6 +196,14 @@ BOOL PlatformBackend_SystemTask(void) break; + case SDL_JOYDEVICEADDED: + ControllerBackend_JoystickConnect(event.jdevice.which); + break; + + case SDL_JOYDEVICEREMOVED: + ControllerBackend_JoystickDisconnect(event.jdevice.which); + break; + case SDL_DROPFILE: LoadProfile(event.drop.file); SDL_free(event.drop.file); From 4568d58c777c3a7f72463bea3d019b2617ef1287 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:53:16 +0100 Subject: [PATCH 36/46] Cleanup --- src/Backends/GLFW3/Controller.cpp | 2 ++ src/Backends/SDL2/Controller.cpp | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 71e83122..bc378cdc 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -102,9 +102,11 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (total_buttons > 32) total_buttons = 32; + // Read whatever buttons actually exist for (int i = 0; i < total_buttons; ++i) status->bButton[i] = buttons[i] == GLFW_PRESS; + // Blank the buttons that do not for (int i = total_buttons; i < 32; ++i) status->bButton[i] = FALSE; diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index ace9d913..bedc56d5 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -8,12 +8,12 @@ #include "../../WindowsWrapper.h" +#define DEADZONE 10000; + static SDL_Joystick *joystick; static int joystick_neutral_x; static int joystick_neutral_y; -void ControllerBackend_JoystickCallback(int joystick_id, BOOL connected); - BOOL ControllerBackend_Init(void) { SDL_InitSubSystem(SDL_INIT_JOYSTICK); @@ -37,6 +37,15 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (joystick == NULL) return FALSE; + // Read axis + const Sint16 joystick_x = SDL_JoystickGetAxis(joystick, 0); + const Sint16 joystick_y = SDL_JoystickGetAxis(joystick, 1); + + status->bLeft = joystick_x < joystick_neutral_x - DEADZONE; + status->bRight = joystick_x > joystick_neutral_x + DEADZONE; + status->bUp = joystick_y < joystick_neutral_y - DEADZONE; + status->bDown = joystick_y > joystick_neutral_y + DEADZONE; + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) int numButtons = SDL_JoystickNumButtons(joystick); if (numButtons > 32) @@ -50,14 +59,6 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) for (int i = numButtons; i < 32; ++i) status->bButton[i] = FALSE; - const Sint16 joystick_x = SDL_JoystickGetAxis(joystick, 0); - const Sint16 joystick_y = SDL_JoystickGetAxis(joystick, 1); - - status->bLeft = joystick_x < joystick_neutral_x - 10000; - status->bRight = joystick_x > joystick_neutral_x + 10000; - status->bUp = joystick_y < joystick_neutral_y - 10000; - status->bDown = joystick_y > joystick_neutral_y + 10000; - return TRUE; } From 8acdcface4d841539c04d022dc5b77e28819c7ae Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:56:57 +0100 Subject: [PATCH 37/46] Update CMakeLists.txt --- CMakeLists.txt | 25 ++++++++++++++++--- src/Backends/GLFW3/{Misc.cpp => Platform.cpp} | 0 src/Backends/SDL2/{Misc.cpp => Platform.cpp} | 0 3 files changed, 21 insertions(+), 4 deletions(-) rename src/Backends/GLFW3/{Misc.cpp => Platform.cpp} (100%) rename src/Backends/SDL2/{Misc.cpp => Platform.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2592193..db84b4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,9 +303,17 @@ else() endif() if(BACKEND_AUDIO MATCHES "SDL2") - target_sources(CSE2 PRIVATE "src/Backends/Audio/SDL2.cpp" "src/Backends/Audio/SoftwareMixer.cpp" "src/Backends/Audio/SoftwareMixer.h") + target_sources(CSE2 PRIVATE + "src/Backends/Audio/SDL2.cpp" + "src/Backends/Audio/SoftwareMixer.cpp" + "src/Backends/Audio/SoftwareMixer.h" + ) elseif(BACKEND_AUDIO MATCHES "miniaudio") - target_sources(CSE2 PRIVATE "src/Backends/Audio/miniaudio.cpp" "src/Backends/Audio/SoftwareMixer.cpp" "src/Backends/Audio/SoftwareMixer.h") + target_sources(CSE2 PRIVATE + "src/Backends/Audio/miniaudio.cpp" + "src/Backends/Audio/SoftwareMixer.cpp" + "src/Backends/Audio/SoftwareMixer.h" + ) # Link libdl, libm, and libpthread include(CheckLibraryExists) @@ -326,9 +334,18 @@ else() endif() if(BACKEND_PLATFORM MATCHES "SDL2") - target_sources(CSE2 PRIVATE "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Misc.cpp" "src/Backends/SDL2/Platform.h") + target_sources(CSE2 PRIVATE + "src/Backends/SDL2/Controller.cpp" + "src/Backends/SDL2/Controller.h" + "src/Backends/SDL2/Platform.cpp" + "src/Backends/SDL2/Platform.h" + ) elseif(BACKEND_PLATFORM MATCHES "GLFW3") - target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" "src/Backends/GLFW3/Misc.cpp" "src/Backends/GLFW3/Platform.h") + target_sources(CSE2 PRIVATE + "src/Backends/GLFW3/Controller.cpp" + "src/Backends/GLFW3/Platform.cpp" + "src/Backends/GLFW3/Platform.h" + ) endif() if(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "OpenGL3") diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Platform.cpp similarity index 100% rename from src/Backends/GLFW3/Misc.cpp rename to src/Backends/GLFW3/Platform.cpp diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Platform.cpp similarity index 100% rename from src/Backends/SDL2/Misc.cpp rename to src/Backends/SDL2/Platform.cpp From 4d322be866669d45e89870a5c0813ea6f5378e3c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:24:34 +0100 Subject: [PATCH 38/46] Change render backend namespace to RenderBackend_ --- src/Backends/GLFW3/Platform.cpp | 2 +- src/Backends/Rendering.h | 42 +++++++++--------- src/Backends/Rendering/OpenGL3.cpp | 56 ++++++++++++------------ src/Backends/Rendering/SDLSurface.cpp | 50 ++++++++++----------- src/Backends/Rendering/SDLTexture.cpp | 62 +++++++++++++-------------- src/Backends/Rendering/Software.cpp | 52 +++++++++++----------- src/Backends/SDL2/Platform.cpp | 4 +- src/Draw.cpp | 48 ++++++++++----------- src/Font.cpp | 14 +++--- src/Font.h | 2 +- 10 files changed, 166 insertions(+), 166 deletions(-) diff --git a/src/Backends/GLFW3/Platform.cpp b/src/Backends/GLFW3/Platform.cpp index f3034d8a..a43a5376 100644 --- a/src/Backends/GLFW3/Platform.cpp +++ b/src/Backends/GLFW3/Platform.cpp @@ -141,7 +141,7 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height) { (void)window; - Backend_HandleWindowResize(width, height); + RenderBackend_HandleWindowResize(width, height); } static void DragAndDropCallback(GLFWwindow *window, int count, const char **paths) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 8572fbbb..eb8c4e54 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -2,25 +2,25 @@ #include "../WindowsWrapper.h" -typedef struct Backend_Surface Backend_Surface; -typedef struct Backend_Glyph Backend_Glyph; +typedef struct RenderBackend_Surface RenderBackend_Surface; +typedef struct RenderBackend_Glyph RenderBackend_Glyph; -Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen); -void Backend_Deinit(void); -void Backend_DrawScreen(void); -void Backend_ClearScreen(void); -Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height); -void Backend_FreeSurface(Backend_Surface *surface); -BOOL Backend_IsSurfaceLost(Backend_Surface *surface); -void Backend_RestoreSurface(Backend_Surface *surface); -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height); -void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height); -void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key); -void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); -Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch); -void Backend_UnloadGlyph(Backend_Glyph *glyph); -void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const unsigned char *colour_channels); -void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y); -void Backend_FlushGlyphs(void); -void Backend_HandleRenderTargetLoss(void); -void Backend_HandleWindowResize(unsigned int width, unsigned int height); +RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen); +void RenderBackend_Deinit(void); +void RenderBackend_DrawScreen(void); +void RenderBackend_ClearScreen(void); +RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height); +void RenderBackend_FreeSurface(RenderBackend_Surface *surface); +BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface); +void RenderBackend_RestoreSurface(RenderBackend_Surface *surface); +unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height); +void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height); +void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key); +void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); +RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch); +void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph); +void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels); +void RenderBackend_DrawGlyph(RenderBackend_Glyph *glyph, long x, long y); +void RenderBackend_FlushGlyphs(void); +void RenderBackend_HandleRenderTargetLoss(void); +void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 957f0cc4..8d0e9c42 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -36,21 +36,21 @@ typedef enum RenderMode MODE_DRAW_GLYPH } RenderMode; -typedef struct Backend_Surface +typedef struct RenderBackend_Surface { GLuint texture_id; unsigned int width; unsigned int height; unsigned char *pixels; -} Backend_Surface; +} RenderBackend_Surface; -typedef struct Backend_Glyph +typedef struct RenderBackend_Glyph { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int pitch; -} Backend_Glyph; +} RenderBackend_Glyph; typedef struct Coordinate2D { @@ -91,10 +91,10 @@ static RenderMode last_render_mode; static GLuint last_source_texture; static GLuint last_destination_texture; -static Backend_Surface framebuffer; +static RenderBackend_Surface framebuffer; static unsigned char glyph_colour_channels[3]; -static Backend_Surface *glyph_destination_surface; +static RenderBackend_Surface *glyph_destination_surface; static spritebatch_t glyph_batcher; @@ -420,7 +420,7 @@ static void GlyphBatch_Draw(spritebatch_sprite_t *sprites, int count, int textur for (int i = 0; i < count; ++i) { - Backend_Glyph *glyph = (Backend_Glyph*)sprites[i].image_id; + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)sprites[i].image_id; const GLfloat texture_left = sprites[i].minx; const GLfloat texture_right = texture_left + ((GLfloat)glyph->width / (GLfloat)texture_w); // Account for width not matching pitch @@ -467,7 +467,7 @@ static void GlyphBatch_GetPixels(SPRITEBATCH_U64 image_id, void *buffer, int byt { (void)udata; - Backend_Glyph *glyph = (Backend_Glyph*)image_id; + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)image_id; memcpy(buffer, glyph->pixels, bytes_to_fill); } @@ -517,7 +517,7 @@ static void GlyphBatch_DestroyTexture(SPRITEBATCH_U64 texture_id, void *udata) // Render-backend initialisation // ==================== -Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { actual_screen_width = screen_width; actual_screen_height = screen_height; @@ -624,7 +624,7 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc return NULL; } -void Backend_Deinit(void) +void RenderBackend_Deinit(void) { free(local_vertex_buffer); @@ -644,7 +644,7 @@ void Backend_Deinit(void) WindowBackend_OpenGL_DestroyWindow(); } -void Backend_DrawScreen(void) +void RenderBackend_DrawScreen(void) { spritebatch_tick(&glyph_batcher); @@ -737,9 +737,9 @@ void Backend_DrawScreen(void) // Surface management // ==================== -Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); if (surface == NULL) return NULL; @@ -767,7 +767,7 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) return surface; } -void Backend_FreeSurface(Backend_Surface *surface) +void RenderBackend_FreeSurface(RenderBackend_Surface *surface) { if (surface == NULL) return; @@ -780,19 +780,19 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } -BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface) { (void)surface; return FALSE; } -void Backend_RestoreSurface(Backend_Surface *surface) +void RenderBackend_RestoreSurface(RenderBackend_Surface *surface) { (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) +unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { if (surface == NULL) return NULL; @@ -802,7 +802,7 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) +void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height) { if (surface == NULL) return; @@ -822,7 +822,7 @@ void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigne // Drawing // ==================== -void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key) { if (source_surface == NULL || destination_surface == NULL) return; @@ -898,7 +898,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur vertex_buffer_slot->vertices[1][2].vertex_coordinate.y = vertex_bottom; } -void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { static unsigned char last_red; static unsigned char last_green; @@ -963,9 +963,9 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha // Glyph management // ==================== -Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { - Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); if (glyph != NULL) { @@ -994,7 +994,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width return NULL; } -void Backend_UnloadGlyph(Backend_Glyph *glyph) +void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph) { if (glyph == NULL) return; @@ -1003,19 +1003,19 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) free(glyph); } -void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const unsigned char *colour_channels) +void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels) { glyph_destination_surface = destination_surface; memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels)); } -void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) +void RenderBackend_DrawGlyph(RenderBackend_Glyph *glyph, long x, long y) { spritebatch_push(&glyph_batcher, (SPRITEBATCH_U64)glyph, glyph->pitch, glyph->height, x, y, 1.0f, 1.0f, 0.0f, 0.0f, 0); } -void Backend_FlushGlyphs(void) +void RenderBackend_FlushGlyphs(void) { spritebatch_defrag(&glyph_batcher); spritebatch_flush(&glyph_batcher); @@ -1025,12 +1025,12 @@ void Backend_FlushGlyphs(void) // Misc. // ==================== -void Backend_HandleRenderTargetLoss(void) +void RenderBackend_HandleRenderTargetLoss(void) { // No problem for us } -void Backend_HandleWindowResize(unsigned int width, unsigned int height) +void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height) { actual_screen_width = width; actual_screen_height = height; diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 27aa6cd4..6feb9f89 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -11,19 +11,19 @@ #include "../Platform.h" #include "../SDL2/Platform.h" -typedef struct Backend_Surface +typedef struct RenderBackend_Surface { SDL_Surface *sdlsurface; -} Backend_Surface; +} RenderBackend_Surface; -typedef struct Backend_Glyph +typedef struct RenderBackend_Glyph { SDL_Surface *sdlsurface; -} Backend_Glyph; +} RenderBackend_Glyph; static SDL_Surface *window_sdlsurface; -static Backend_Surface framebuffer; +static RenderBackend_Surface framebuffer; static unsigned char glyph_colour_channels[3]; static SDL_Surface *glyph_destination_sdlsurface; @@ -42,7 +42,7 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } -Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0); @@ -76,21 +76,21 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc return NULL; } -void Backend_Deinit(void) +void RenderBackend_Deinit(void) { SDL_FreeSurface(framebuffer.sdlsurface); SDL_DestroyWindow(window); } -void Backend_DrawScreen(void) +void RenderBackend_DrawScreen(void) { SDL_BlitSurface(framebuffer.sdlsurface, NULL, window_sdlsurface, NULL); SDL_UpdateWindowSurface(window); } -Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); if (surface == NULL) return NULL; @@ -106,7 +106,7 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) return surface; } -void Backend_FreeSurface(Backend_Surface *surface) +void RenderBackend_FreeSurface(RenderBackend_Surface *surface) { if (surface == NULL) return; @@ -115,19 +115,19 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } -BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface) { (void)surface; return FALSE; } -void Backend_RestoreSurface(Backend_Surface *surface) +void RenderBackend_RestoreSurface(RenderBackend_Surface *surface) { (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) +unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { (void)width; (void)height; @@ -139,14 +139,14 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return (unsigned char*)surface->sdlsurface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) +void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height) { (void)surface; (void)width; (void)height; } -void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key) { if (source_surface == NULL || destination_surface == NULL) return; @@ -165,7 +165,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur SDL_BlitSurface(source_surface->sdlsurface, &source_rect, destination_surface->sdlsurface, &destination_rect); } -void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { if (surface == NULL) return; @@ -176,9 +176,9 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha SDL_FillRect(surface->sdlsurface, &destination_rect, SDL_MapRGB(surface->sdlsurface->format, red, green, blue)); } -Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { - Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); if (glyph == NULL) return NULL; @@ -208,7 +208,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width return glyph; } -void Backend_UnloadGlyph(Backend_Glyph *glyph) +void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph) { if (glyph == NULL) return; @@ -217,7 +217,7 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) free(glyph); } -void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const unsigned char *colour_channels) +void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels) { if (destination_surface == NULL) return; @@ -227,7 +227,7 @@ void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const uns memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels)); } -void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) +void RenderBackend_DrawGlyph(RenderBackend_Glyph *glyph, long x, long y) { if (glyph == NULL) return; @@ -243,17 +243,17 @@ void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) SDL_BlitSurface(glyph->sdlsurface, NULL, glyph_destination_sdlsurface, &rect); } -void Backend_FlushGlyphs(void) +void RenderBackend_FlushGlyphs(void) { } -void Backend_HandleRenderTargetLoss(void) +void RenderBackend_HandleRenderTargetLoss(void) { // No problem for us } -void Backend_HandleWindowResize(unsigned int width, unsigned int height) +void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height) { (void)width; (void)height; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 2af8a4ac..a3f9225a 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -19,7 +19,7 @@ #include "../../MapName.h" #include "../../TextScr.h" -typedef struct Backend_Surface +typedef struct RenderBackend_Surface { SDL_Texture *texture; unsigned char *pixels; @@ -27,22 +27,22 @@ typedef struct Backend_Surface unsigned int height; BOOL lost; - struct Backend_Surface *next; - struct Backend_Surface *prev; -} Backend_Surface; + struct RenderBackend_Surface *next; + struct RenderBackend_Surface *prev; +} RenderBackend_Surface; -typedef struct Backend_Glyph +typedef struct RenderBackend_Glyph { unsigned char *pixels; unsigned int width; unsigned int height; -} Backend_Glyph; +} RenderBackend_Glyph; static SDL_Renderer *renderer; -static Backend_Surface framebuffer; +static RenderBackend_Surface framebuffer; -static Backend_Surface *surface_list_head; +static RenderBackend_Surface *surface_list_head; static unsigned char glyph_colour_channels[3]; @@ -76,7 +76,7 @@ static void GlyphBatch_Draw(spritebatch_sprite_t *sprites, int count, int textur for (int i = 0; i < count; ++i) { - Backend_Glyph *glyph = (Backend_Glyph*)sprites[i].image_id; + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)sprites[i].image_id; SDL_Rect source_rect = {(int)(texture_w * sprites[i].minx), (int)(texture_h * sprites[i].maxy), (int)glyph->width, (int)glyph->height}; SDL_Rect destination_rect = {(int)sprites[i].x, (int)sprites[i].y, (int)glyph->width, (int)glyph->height}; @@ -90,7 +90,7 @@ static void GlyphBatch_GetPixels(SPRITEBATCH_U64 image_id, void *buffer, int byt { (void)udata; - Backend_Glyph *glyph = (Backend_Glyph*)image_id; + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)image_id; memcpy(buffer, glyph->pixels, bytes_to_fill); } @@ -115,7 +115,7 @@ static void GlyphBatch_DestroyTexture(SPRITEBATCH_U64 texture_id, void *udata) SDL_DestroyTexture((SDL_Texture*)texture_id); } -Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { puts("Available SDL2 render drivers:"); @@ -192,7 +192,7 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc return NULL; } -void Backend_Deinit(void) +void RenderBackend_Deinit(void) { spritebatch_term(&glyph_batcher); SDL_DestroyTexture(framebuffer.texture); @@ -200,7 +200,7 @@ void Backend_Deinit(void) SDL_DestroyWindow(window); } -void Backend_DrawScreen(void) +void RenderBackend_DrawScreen(void) { spritebatch_tick(&glyph_batcher); @@ -209,9 +209,9 @@ void Backend_DrawScreen(void) SDL_RenderPresent(renderer); } -Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); if (surface == NULL) return NULL; @@ -239,7 +239,7 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) return surface; } -void Backend_FreeSurface(Backend_Surface *surface) +void RenderBackend_FreeSurface(RenderBackend_Surface *surface) { if (surface == NULL) return; @@ -254,17 +254,17 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } -BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface) { return surface->lost; } -void Backend_RestoreSurface(Backend_Surface *surface) +void RenderBackend_RestoreSurface(RenderBackend_Surface *surface) { surface->lost = FALSE; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) +unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { if (surface == NULL) return NULL; @@ -276,7 +276,7 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) +void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height) { if (surface == NULL) return; @@ -312,7 +312,7 @@ void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigne free(buffer); } -void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key) { if (source_surface == NULL || destination_surface == NULL) return; @@ -328,7 +328,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur SDL_RenderCopy(renderer, source_surface->texture, &source_rect, &destination_rect); } -void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { if (surface == NULL) return; @@ -349,9 +349,9 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); } -Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { - Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); if (glyph == NULL) return NULL; @@ -385,7 +385,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width return glyph; } -void Backend_UnloadGlyph(Backend_Glyph *glyph) +void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph) { if (glyph == NULL) return; @@ -394,7 +394,7 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) free(glyph); } -void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const unsigned char *colour_channels) +void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels) { if (destination_surface == NULL) return; @@ -404,24 +404,24 @@ void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const uns memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels)); } -void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) +void RenderBackend_DrawGlyph(RenderBackend_Glyph *glyph, long x, long y) { spritebatch_push(&glyph_batcher, (SPRITEBATCH_U64)glyph, glyph->width, glyph->height, x, y, 1.0f, 1.0f, 0.0f, 0.0f, 0); } -void Backend_FlushGlyphs(void) +void RenderBackend_FlushGlyphs(void) { spritebatch_defrag(&glyph_batcher); spritebatch_flush(&glyph_batcher); } -void Backend_HandleRenderTargetLoss(void) +void RenderBackend_HandleRenderTargetLoss(void) { - for (Backend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next) + for (RenderBackend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next) surface->lost = TRUE; } -void Backend_HandleWindowResize(unsigned int width, unsigned int height) +void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height) { (void)width; (void)height; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 2e220355..1bd2878f 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -14,29 +14,29 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) -typedef struct Backend_Surface +typedef struct RenderBackend_Surface { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int pitch; -} Backend_Surface; +} RenderBackend_Surface; -typedef struct Backend_Glyph +typedef struct RenderBackend_Glyph { unsigned char *pixels; unsigned int width; unsigned int height; -} Backend_Glyph; +} RenderBackend_Glyph; static SDL_Surface *window_sdlsurface; static SDL_Surface *framebuffer_sdlsurface; -static Backend_Surface framebuffer; +static RenderBackend_Surface framebuffer; static unsigned char glyph_colour_channels[3]; -static Backend_Surface *glyph_destination_surface; +static RenderBackend_Surface *glyph_destination_surface; -Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0); @@ -75,21 +75,21 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc return NULL; } -void Backend_Deinit(void) +void RenderBackend_Deinit(void) { SDL_FreeSurface(framebuffer_sdlsurface); SDL_DestroyWindow(window); } -void Backend_DrawScreen(void) +void RenderBackend_DrawScreen(void) { SDL_BlitSurface(framebuffer_sdlsurface, NULL, window_sdlsurface, NULL); SDL_UpdateWindowSurface(window); } -Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); if (surface == NULL) return NULL; @@ -109,7 +109,7 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) return surface; } -void Backend_FreeSurface(Backend_Surface *surface) +void RenderBackend_FreeSurface(RenderBackend_Surface *surface) { if (surface == NULL) return; @@ -118,19 +118,19 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } -BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface) { (void)surface; return FALSE; } -void Backend_RestoreSurface(Backend_Surface *surface) +void RenderBackend_RestoreSurface(RenderBackend_Surface *surface) { (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) +unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { (void)width; (void)height; @@ -142,14 +142,14 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) +void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height) { (void)surface; (void)width; (void)height; } -void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key) { if (source_surface == NULL || destination_surface == NULL) return; @@ -232,7 +232,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur } } -void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { if (surface == NULL) return; @@ -290,9 +290,9 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha } } -Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { - Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); if (glyph == NULL) return NULL; @@ -314,7 +314,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width return glyph; } -void Backend_UnloadGlyph(Backend_Glyph *glyph) +void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph) { if (glyph == NULL) return; @@ -323,7 +323,7 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) free(glyph); } -void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const unsigned char *colour_channels) +void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels) { if (destination_surface == NULL) return; @@ -333,7 +333,7 @@ void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const uns memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels)); } -void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) +void RenderBackend_DrawGlyph(RenderBackend_Glyph *glyph, long x, long y) { if (glyph == NULL) return; @@ -357,17 +357,17 @@ void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y) } } -void Backend_FlushGlyphs(void) +void RenderBackend_FlushGlyphs(void) { } -void Backend_HandleRenderTargetLoss(void) +void RenderBackend_HandleRenderTargetLoss(void) { // No problem for us } -void Backend_HandleWindowResize(unsigned int width, unsigned int height) +void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height) { (void)width; (void)height; diff --git a/src/Backends/SDL2/Platform.cpp b/src/Backends/SDL2/Platform.cpp index 827138c7..44256411 100644 --- a/src/Backends/SDL2/Platform.cpp +++ b/src/Backends/SDL2/Platform.cpp @@ -222,7 +222,7 @@ BOOL PlatformBackend_SystemTask(void) case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_SIZE_CHANGED: - Backend_HandleWindowResize(event.window.data1, event.window.data2); + RenderBackend_HandleWindowResize(event.window.data1, event.window.data2); break; } @@ -233,7 +233,7 @@ BOOL PlatformBackend_SystemTask(void) return FALSE; case SDL_RENDER_TARGETS_RESET: - Backend_HandleRenderTargetLoss(); + RenderBackend_HandleRenderTargetLoss(); break; } diff --git a/src/Draw.cpp b/src/Draw.cpp index 6fbc6497..e3db6d76 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -32,9 +32,9 @@ RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; int magnification; BOOL fullscreen; -static Backend_Surface *framebuffer; +static RenderBackend_Surface *framebuffer; -static Backend_Surface *surf[SURFACE_ID_MAX]; +static RenderBackend_Surface *surf[SURFACE_ID_MAX]; static FontObject *font; @@ -72,7 +72,7 @@ BOOL Flip_SystemTask(void) else timePrev += 20; - Backend_DrawScreen(); + RenderBackend_DrawScreen(); if (RestoreSurfaces()) { @@ -106,7 +106,7 @@ BOOL StartDirectDraw(const char *title, int width, int height, int lMagnificatio break; } - framebuffer = Backend_Init(title, width, height, fullscreen); + framebuffer = RenderBackend_Init(title, width, height, fullscreen); if (framebuffer == NULL) return FALSE; @@ -123,14 +123,14 @@ void EndDirectDraw(void) { if (surf[i] != NULL) { - Backend_FreeSurface(surf[i]); + RenderBackend_FreeSurface(surf[i]); surf[i] = NULL; } } framebuffer = NULL; - Backend_Deinit(); + RenderBackend_Deinit(); memset(surface_metadata, 0, sizeof(surface_metadata)); } @@ -140,7 +140,7 @@ void ReleaseSurface(SurfaceID s) // Release the surface we want to release if (surf[s] != NULL) { - Backend_FreeSurface(surf[s]); + RenderBackend_FreeSurface(surf[s]); surf[s] = NULL; } @@ -151,7 +151,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width, { // IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT unsigned int pitch; - unsigned char *pixels = Backend_LockSurface(surf[surf_no], &pitch, width * magnification, height * magnification); + unsigned char *pixels = RenderBackend_LockSurface(surf[surf_no], &pitch, width * magnification, height * magnification); if (magnification == 1) { @@ -192,7 +192,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width, } } - Backend_UnlockSurface(surf[surf_no], width * magnification, height * magnification); + RenderBackend_UnlockSurface(surf[surf_no], width * magnification, height * magnification); return TRUE; } @@ -218,7 +218,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) if (image_buffer == NULL) return FALSE; - surf[surf_no] = Backend_CreateSurface(width * magnification, height * magnification); + surf[surf_no] = RenderBackend_CreateSurface(width * magnification, height * magnification); if (surf[surf_no] == NULL) { @@ -228,7 +228,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no)) { - Backend_FreeSurface(surf[surf_no]); + RenderBackend_FreeSurface(surf[surf_no]); FreeBitmap(image_buffer); return FALSE; } @@ -280,7 +280,7 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no) return FALSE; } - surf[surf_no] = Backend_CreateSurface(width * magnification, height * magnification); + surf[surf_no] = RenderBackend_CreateSurface(width * magnification, height * magnification); if (surf[surf_no] == NULL) { @@ -290,7 +290,7 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no) if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no)) { - Backend_FreeSurface(surf[surf_no]); + RenderBackend_FreeSurface(surf[surf_no]); FreeBitmap(image_buffer); return FALSE; } @@ -391,7 +391,7 @@ BOOL MakeSurface_Generic(int bxsize, int bysize, SurfaceID surf_no, BOOL bSystem if (surf[surf_no] != NULL) return FALSE; - surf[surf_no] = Backend_CreateSurface(bxsize * magnification, bysize * magnification); + surf[surf_no] = RenderBackend_CreateSurface(bxsize * magnification, bysize * magnification); if (surf[surf_no] == NULL) return FALSE; @@ -418,7 +418,7 @@ void BackupSurface(SurfaceID surf_no, const RECT *rect) scaled_rect.right = rect->right * magnification; scaled_rect.bottom = rect->bottom * magnification; - Backend_Blit(framebuffer, &scaled_rect, surf[surf_no], scaled_rect.left, scaled_rect.top, FALSE); + RenderBackend_Blit(framebuffer, &scaled_rect, surf[surf_no], scaled_rect.left, scaled_rect.top, FALSE); } void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no) // Transparency @@ -450,7 +450,7 @@ void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID su rcWork.right *= magnification; rcWork.bottom *= magnification; - Backend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, TRUE); + RenderBackend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, TRUE); } void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no) // No Transparency @@ -482,7 +482,7 @@ void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID su rcWork.right *= magnification; rcWork.bottom *= magnification; - Backend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, FALSE); + RenderBackend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, FALSE); } void Surface2Surface(int x, int y, const RECT *rect, int to, int from) @@ -494,7 +494,7 @@ void Surface2Surface(int x, int y, const RECT *rect, int to, int from) rcWork.right = rect->right * magnification; rcWork.bottom = rect->bottom * magnification; - Backend_Blit(surf[from], &rcWork, surf[to], x * magnification, y * magnification, TRUE); + RenderBackend_Blit(surf[from], &rcWork, surf[to], x * magnification, y * magnification, TRUE); } unsigned long GetCortBoxColor(unsigned long col) @@ -515,7 +515,7 @@ void CortBox(const RECT *rect, unsigned long col) const unsigned char green = (col >> 8) & 0xFF; const unsigned char blue = (col >> 16) & 0xFF; - Backend_ColourFill(framebuffer, &dst_rect, red, green, blue); + RenderBackend_ColourFill(framebuffer, &dst_rect, red, green, blue); } void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) @@ -532,7 +532,7 @@ void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) const unsigned char green = (col >> 8) & 0xFF; const unsigned char blue = (col >> 16) & 0xFF; - Backend_ColourFill(surf[surf_no], &dst_rect, red, green, blue); + RenderBackend_ColourFill(surf[surf_no], &dst_rect, red, green, blue); } BOOL DummiedOutLogFunction(int unknown) @@ -560,10 +560,10 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L if (framebuffer == NULL) return surfaces_regenerated; - if (Backend_IsSurfaceLost(framebuffer)) + if (RenderBackend_IsSurfaceLost(framebuffer)) { ++surfaces_regenerated; - Backend_RestoreSurface(framebuffer); + RenderBackend_RestoreSurface(framebuffer); DummiedOutLogFunction(0x62); } @@ -571,10 +571,10 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L { if (surf[s] != NULL) { - if (Backend_IsSurfaceLost(surf[s])) + if (RenderBackend_IsSurfaceLost(surf[s])) { ++surfaces_regenerated; - Backend_RestoreSurface(surf[s]); + RenderBackend_RestoreSurface(surf[s]); DummiedOutLogFunction(0x30 + s); if (!surface_metadata[s].bSystem) diff --git a/src/Font.cpp b/src/Font.cpp index 9d17cbed..5c7d44a8 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -32,7 +32,7 @@ typedef struct CachedGlyph int x; int y; int x_advance; - Backend_Glyph *backend; + RenderBackend_Glyph *backend; struct CachedGlyph *next; } CachedGlyph; @@ -1014,7 +1014,7 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod break; } - glyph->backend = Backend_LoadGlyph(bitmap.buffer, bitmap.width, bitmap.rows, bitmap.pitch); + glyph->backend = RenderBackend_LoadGlyph(bitmap.buffer, bitmap.width, bitmap.rows, bitmap.pitch); FT_Bitmap_Done(font_object->library, &bitmap); } @@ -1029,7 +1029,7 @@ static void UnloadCachedGlyphs(FontObject *font_object) { CachedGlyph *next_glyph = glyph->next; - Backend_UnloadGlyph(glyph->backend); + RenderBackend_UnloadGlyph(glyph->backend); free(glyph); glyph = next_glyph; @@ -1093,13 +1093,13 @@ FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigne return font_object; } -void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string) +void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string) { if (font_object != NULL) { const unsigned char colour_channels[3] = {(unsigned char)colour, (unsigned char)(colour >> 8), (unsigned char)(colour >> 16)}; - Backend_PrepareToDrawGlyphs(surface, colour_channels); + RenderBackend_PrepareToDrawGlyphs(surface, colour_channels); unsigned int pen_x = 0; @@ -1124,13 +1124,13 @@ void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, u const int letter_y = y + glyph->y; if (glyph->backend != NULL) - Backend_DrawGlyph(glyph->backend, letter_x, letter_y); + RenderBackend_DrawGlyph(glyph->backend, letter_x, letter_y); pen_x += glyph->x_advance; } } - Backend_FlushGlyphs(); + RenderBackend_FlushGlyphs(); } } diff --git a/src/Font.h b/src/Font.h index 46c96f83..7e707c37 100644 --- a/src/Font.h +++ b/src/Font.h @@ -8,5 +8,5 @@ typedef struct FontObject FontObject; FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height); FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height); -void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string); +void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string); void UnloadFont(FontObject *font_object); From daf5d3cc7ee8e5f96276678e0ec62d12b2132eff Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:25:12 +0100 Subject: [PATCH 39/46] Add missing file --- src/Backends/SDL2/Controller.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Backends/SDL2/Controller.h diff --git a/src/Backends/SDL2/Controller.h b/src/Backends/SDL2/Controller.h new file mode 100644 index 00000000..93f355ad --- /dev/null +++ b/src/Backends/SDL2/Controller.h @@ -0,0 +1,8 @@ +#pragma once + +#include "SDL.h" + +#include "../../WindowsWrapper.h" + +void ControllerBackend_JoystickConnect(Sint32 joystick_id); +void ControllerBackend_JoystickDisconnect(Sint32 joystick_id); From 135035bb1a11fed0d36d94dfd7baf0e0541e76e0 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:31:27 +0100 Subject: [PATCH 40/46] Change 'PlatformBackend' namespace to 'Backend' --- CMakeLists.txt | 10 +++---- src/Backends/GLFW3/{Platform.cpp => Misc.cpp} | 26 ++++++++--------- src/Backends/GLFW3/{Platform.h => Misc.h} | 0 src/Backends/GLFW3/Window-OpenGL3.cpp | 12 ++++---- src/Backends/{Platform.h => Misc.h} | 22 +++++++-------- src/Backends/Rendering/OpenGL3.cpp | 8 +++--- src/Backends/Rendering/SDLSurface.cpp | 6 ++-- src/Backends/Rendering/SDLTexture.cpp | 6 ++-- src/Backends/Rendering/Software.cpp | 10 +++---- src/Backends/SDL2/{Platform.cpp => Misc.cpp} | 26 ++++++++--------- src/Backends/SDL2/{Platform.h => Misc.h} | 0 src/Backends/SDL2/Window-OpenGL3.cpp | 16 +++++------ src/Draw.cpp | 6 ++-- src/Game.cpp | 18 ++++++------ src/Main.cpp | 28 +++++++++---------- src/Profile.cpp | 6 ++-- src/TextScr.cpp | 10 +++---- 17 files changed, 105 insertions(+), 105 deletions(-) rename src/Backends/GLFW3/{Platform.cpp => Misc.cpp} (91%) rename src/Backends/GLFW3/{Platform.h => Misc.h} (100%) rename src/Backends/{Platform.h => Misc.h} (76%) rename src/Backends/SDL2/{Platform.cpp => Misc.cpp} (90%) rename src/Backends/SDL2/{Platform.h => Misc.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index db84b4ab..fbe3d069 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ add_executable(CSE2 WIN32 "src/WindowsWrapper.h" "src/Backends/Audio.h" "src/Backends/Controller.h" - "src/Backends/Platform.h" + "src/Backends/Misc.h" "src/Backends/Rendering.h" ) @@ -337,14 +337,14 @@ if(BACKEND_PLATFORM MATCHES "SDL2") target_sources(CSE2 PRIVATE "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Controller.h" - "src/Backends/SDL2/Platform.cpp" - "src/Backends/SDL2/Platform.h" + "src/Backends/SDL2/Misc.cpp" + "src/Backends/SDL2/Misc.h" ) elseif(BACKEND_PLATFORM MATCHES "GLFW3") target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" - "src/Backends/GLFW3/Platform.cpp" - "src/Backends/GLFW3/Platform.h" + "src/Backends/GLFW3/Misc.cpp" + "src/Backends/GLFW3/Misc.h" ) endif() diff --git a/src/Backends/GLFW3/Platform.cpp b/src/Backends/GLFW3/Misc.cpp similarity index 91% rename from src/Backends/GLFW3/Platform.cpp rename to src/Backends/GLFW3/Misc.cpp index a43a5376..f881ae07 100644 --- a/src/Backends/GLFW3/Platform.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -1,5 +1,5 @@ -#include "../Platform.h" -#include "Platform.h" +#include "../Misc.h" +#include "Misc.h" #include #include @@ -152,12 +152,12 @@ static void DragAndDropCallback(GLFWwindow *window, int count, const char **path LoadProfile(paths[0]); } -void PlatformBackend_Init(void) +void Backend_Init(void) { glfwInit(); } -void PlatformBackend_Deinit(void) +void Backend_Deinit(void) { if (cursor != NULL) glfwDestroyCursor(cursor); @@ -165,7 +165,7 @@ void PlatformBackend_Deinit(void) glfwTerminate(); } -void PlatformBackend_PostWindowCreation(void) +void Backend_PostWindowCreation(void) { // Hook callbacks glfwSetKeyCallback(window, KeyCallback); @@ -173,7 +173,7 @@ void PlatformBackend_PostWindowCreation(void) glfwSetWindowSizeCallback(window, WindowSizeCallback); } -BOOL PlatformBackend_GetBasePath(char *string_buffer) +BOOL Backend_GetBasePath(char *string_buffer) { (void)string_buffer; @@ -181,12 +181,12 @@ BOOL PlatformBackend_GetBasePath(char *string_buffer) return FALSE; } -void PlatformBackend_HideMouse(void) +void Backend_HideMouse(void) { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } -void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) { // Convert to RGBA, since that's the only think GLFW3 accepts unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4); @@ -214,7 +214,7 @@ void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int } } -void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) { // Convert to RGBA, since that's the only think GLFW3 accepts unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4); @@ -258,7 +258,7 @@ void PlaybackBackend_EnableDragAndDrop(void) glfwSetDropCallback(window, DragAndDropCallback); } -BOOL PlatformBackend_SystemTask(void) +BOOL Backend_SystemTask(void) { if (glfwWindowShouldClose(window)) { @@ -276,18 +276,18 @@ BOOL PlatformBackend_SystemTask(void) return TRUE; } -void PlatformBackend_ShowMessageBox(const char *title, const char *message) +void Backend_ShowMessageBox(const char *title, const char *message) { // GLFW3 doesn't have a message box printf("ShowMessageBox - '%s' - '%s'\n", title, message); } -unsigned long PlatformBackend_GetTicks(void) +unsigned long Backend_GetTicks(void) { return (unsigned long)(glfwGetTime() * 1000.0); } -void PlatformBackend_Delay(unsigned int ticks) +void Backend_Delay(unsigned int ticks) { // GLFW3 doesn't have a delay function, so here's some butt-ugly C++11 std::this_thread::sleep_for(std::chrono::milliseconds(ticks)); diff --git a/src/Backends/GLFW3/Platform.h b/src/Backends/GLFW3/Misc.h similarity index 100% rename from src/Backends/GLFW3/Platform.h rename to src/Backends/GLFW3/Misc.h diff --git a/src/Backends/GLFW3/Window-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp index 0903c869..a8ce93ed 100644 --- a/src/Backends/GLFW3/Window-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -12,8 +12,8 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" -#include "Platform.h" +#include "../Misc.h" +#include "Misc.h" BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) { @@ -57,19 +57,19 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid if (GLAD_GL_VERSION_3_2) { #endif - PlatformBackend_PostWindowCreation(); + Backend_PostWindowCreation(); return TRUE; #ifndef USE_OPENGLES2 } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2"); } } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions"); } #endif @@ -77,7 +77,7 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window"); } return FALSE; diff --git a/src/Backends/Platform.h b/src/Backends/Misc.h similarity index 76% rename from src/Backends/Platform.h rename to src/Backends/Misc.h index 52c246f2..e6d11124 100644 --- a/src/Backends/Platform.h +++ b/src/Backends/Misc.h @@ -87,15 +87,15 @@ extern BOOL bActive; extern BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; extern BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; -void PlatformBackend_Init(void); -void PlatformBackend_Deinit(void); -void PlatformBackend_PostWindowCreation(void); -BOOL PlatformBackend_GetBasePath(char *string_buffer); -void PlatformBackend_HideMouse(void); -void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); -void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); +void Backend_Init(void); +void Backend_Deinit(void); +void Backend_PostWindowCreation(void); +BOOL Backend_GetBasePath(char *string_buffer); +void Backend_HideMouse(void); +void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); +void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); void PlaybackBackend_EnableDragAndDrop(void); -BOOL PlatformBackend_SystemTask(void); -void PlatformBackend_ShowMessageBox(const char *title, const char *message); -unsigned long PlatformBackend_GetTicks(void); -void PlatformBackend_Delay(unsigned int ticks); +BOOL Backend_SystemTask(void); +void Backend_ShowMessageBox(const char *title, const char *message); +unsigned long Backend_GetTicks(void); +void Backend_Delay(unsigned int ticks); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 8d0e9c42..fa6d8eab 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -18,7 +18,7 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" +#include "../Misc.h" #include "../Window-OpenGL.h" #include "../../Resource.h" @@ -275,7 +275,7 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme { char buffer[0x200]; glGetShaderInfoLog(vertex_shader, sizeof(buffer), NULL, buffer); - PlatformBackend_ShowMessageBox("Vertex shader error", buffer); + Backend_ShowMessageBox("Vertex shader error", buffer); return 0; } @@ -291,7 +291,7 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme { char buffer[0x200]; glGetShaderInfoLog(fragment_shader, sizeof(buffer), NULL, buffer); - PlatformBackend_ShowMessageBox("Fragment shader error", buffer); + Backend_ShowMessageBox("Fragment shader error", buffer); return 0; } @@ -308,7 +308,7 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme { char buffer[0x200]; glGetProgramInfoLog(program_id, sizeof(buffer), NULL, buffer); - PlatformBackend_ShowMessageBox("Shader linker error", buffer); + Backend_ShowMessageBox("Shader linker error", buffer); return 0; } diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 6feb9f89..db217baa 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -8,8 +8,8 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" -#include "../SDL2/Platform.h" +#include "../Misc.h" +#include "../SDL2/Misc.h" typedef struct RenderBackend_Surface { @@ -57,7 +57,7 @@ Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, if (framebuffer.sdlsurface != NULL) { - PlatformBackend_PostWindowCreation(); + Backend_PostWindowCreation(); return &framebuffer; } diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index a3f9225a..963b8bf5 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -12,8 +12,8 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" -#include "../SDL2/Platform.h" +#include "../Misc.h" +#include "../SDL2/Misc.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" @@ -165,7 +165,7 @@ Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, config.delete_texture_callback = GlyphBatch_DestroyTexture; spritebatch_init(&glyph_batcher, &config, NULL); - PlatformBackend_PostWindowCreation(); + Backend_PostWindowCreation(); return &framebuffer; } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 1bd2878f..db02d5f1 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -8,8 +8,8 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" -#include "../SDL2/Platform.h" +#include "../Misc.h" +#include "../SDL2/Misc.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -56,20 +56,20 @@ Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, framebuffer.height = framebuffer_sdlsurface->h; framebuffer.pitch = framebuffer_sdlsurface->pitch; - PlatformBackend_PostWindowCreation(); + Backend_PostWindowCreation(); return &framebuffer; } else { - PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create framebuffer surface"); + Backend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create framebuffer surface"); } SDL_DestroyWindow(window); } else { - PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create window"); + Backend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create window"); } return NULL; diff --git a/src/Backends/SDL2/Platform.cpp b/src/Backends/SDL2/Misc.cpp similarity index 90% rename from src/Backends/SDL2/Platform.cpp rename to src/Backends/SDL2/Misc.cpp index 44256411..773e523e 100644 --- a/src/Backends/SDL2/Platform.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -1,5 +1,5 @@ -#include "../Platform.h" -#include "Platform.h" +#include "../Misc.h" +#include "Misc.h" #include #include @@ -30,7 +30,7 @@ BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; static SDL_Surface *cursor_surface; static SDL_Cursor *cursor; -void PlatformBackend_Init(void) +void Backend_Init(void) { SDL_Init(SDL_INIT_EVENTS); @@ -44,7 +44,7 @@ void PlatformBackend_Init(void) printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver()); } -void PlatformBackend_Deinit(void) +void Backend_Deinit(void) { if (cursor != NULL) SDL_FreeCursor(cursor); @@ -55,12 +55,12 @@ void PlatformBackend_Deinit(void) SDL_Quit(); } -void PlatformBackend_PostWindowCreation(void) +void Backend_PostWindowCreation(void) { } -BOOL PlatformBackend_GetBasePath(char *string_buffer) +BOOL Backend_GetBasePath(char *string_buffer) { char *base_path = SDL_GetBasePath(); // Trim the trailing '/' @@ -72,19 +72,19 @@ BOOL PlatformBackend_GetBasePath(char *string_buffer) return TRUE; } -void PlatformBackend_HideMouse(void) +void Backend_HideMouse(void) { SDL_ShowCursor(SDL_DISABLE); } -void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) { SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24); SDL_SetWindowIcon(window, surface); SDL_FreeSurface(surface); } -void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) { cursor_surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24); SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF)); @@ -97,7 +97,7 @@ void PlaybackBackend_EnableDragAndDrop(void) SDL_EventState(SDL_DROPFILE, SDL_ENABLE); } -BOOL PlatformBackend_SystemTask(void) +BOOL Backend_SystemTask(void) { memcpy(backend_previous_keyboard_state, backend_keyboard_state, sizeof(backend_keyboard_state)); @@ -242,17 +242,17 @@ BOOL PlatformBackend_SystemTask(void) return TRUE; } -void PlatformBackend_ShowMessageBox(const char *title, const char *message) +void Backend_ShowMessageBox(const char *title, const char *message) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window); } -unsigned long PlatformBackend_GetTicks(void) +unsigned long Backend_GetTicks(void) { return SDL_GetTicks(); } -void PlatformBackend_Delay(unsigned int ticks) +void Backend_Delay(unsigned int ticks) { SDL_Delay(ticks); } diff --git a/src/Backends/SDL2/Platform.h b/src/Backends/SDL2/Misc.h similarity index 100% rename from src/Backends/SDL2/Platform.h rename to src/Backends/SDL2/Misc.h diff --git a/src/Backends/SDL2/Window-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp index e33474af..f0679dbe 100644 --- a/src/Backends/SDL2/Window-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -11,8 +11,8 @@ #include "../../WindowsWrapper.h" -#include "../Platform.h" -#include "Platform.h" +#include "../Misc.h" +#include "Misc.h" #include "../../Resource.h" static SDL_GLContext context; @@ -48,39 +48,39 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid if (GLAD_GL_VERSION_3_2) { #endif - PlatformBackend_PostWindowCreation(); + Backend_PostWindowCreation(); return TRUE; #ifndef USE_OPENGLES2 } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2"); } } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions"); } #endif } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed"); } SDL_GL_DeleteContext(context); } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create OpenGL context"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create OpenGL context"); } SDL_DestroyWindow(window); } else { - PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window"); } return FALSE; diff --git a/src/Draw.cpp b/src/Draw.cpp index e3db6d76..a03f8487 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -7,7 +7,7 @@ #include "WindowsWrapper.h" -#include "Backends/Platform.h" +#include "Backends/Misc.h" #include "Backends/Rendering.h" #include "Bitmap.h" #include "CommonDefines.h" @@ -59,12 +59,12 @@ BOOL Flip_SystemTask(void) return FALSE; // Framerate limiter - timeNow = PlatformBackend_GetTicks(); + timeNow = Backend_GetTicks(); if (timeNow >= timePrev + 20) break; - PlatformBackend_Delay(1); + Backend_Delay(1); } if (timeNow >= timePrev + 100) diff --git a/src/Game.cpp b/src/Game.cpp index 8ef8b97a..e2c9c6a1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -6,7 +6,7 @@ #include "WindowsWrapper.h" -#include "Backends/Platform.h" +#include "Backends/Misc.h" #include "ArmsItem.h" #include "Back.h" #include "Boss.h" @@ -214,8 +214,8 @@ int ModeOpening(void) ++gCounter; } - wait = PlatformBackend_GetTicks(); - while (PlatformBackend_GetTicks() < wait + 500) + wait = Backend_GetTicks(); + while (Backend_GetTicks() < wait + 500) { CortBox(&grcGame, 0x000000); PutFramePerSecound(); @@ -460,8 +460,8 @@ int ModeTitle(void) ChangeMusic(MUS_SILENCE); // Black screen when option is selected - wait = PlatformBackend_GetTicks(); - while (PlatformBackend_GetTicks() < wait + 1000) + wait = Backend_GetTicks(); + while (Backend_GetTicks() < wait + 1000) { CortBox(&grcGame, 0); PutFramePerSecound(); @@ -691,9 +691,9 @@ BOOL Game(void) if (!LoadGenericData()) { #ifdef JAPANESE - PlatformBackend_ShowMessageBox("エラー", "汎用ファイルが読めない"); + Backend_ShowMessageBox("エラー", "汎用ファイルが読めない"); #else - PlatformBackend_ShowMessageBox("Error", "Couldn't read general purpose files"); + Backend_ShowMessageBox("Error", "Couldn't read general purpose files"); #endif return FALSE; @@ -707,9 +707,9 @@ BOOL Game(void) if (!LoadNpcTable(path)) { #ifdef JAPANESE - PlatformBackend_ShowMessageBox("エラー", "NPCテーブルが読めない"); + Backend_ShowMessageBox("エラー", "NPCテーブルが読めない"); #else - PlatformBackend_ShowMessageBox("Error", "Couldn't read the NPC table"); + Backend_ShowMessageBox("Error", "Couldn't read the NPC table"); #endif return FALSE; diff --git a/src/Main.cpp b/src/Main.cpp index a8faaf7a..0980528f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -7,7 +7,7 @@ #include "WindowsWrapper.h" -#include "Backends/Platform.h" +#include "Backends/Misc.h" #include "Backends/Rendering.h" #include "Bitmap.h" #include "CommonDefines.h" @@ -64,11 +64,11 @@ unsigned long GetFramePerSecound(void) if (need_new_base_tick) { - base_tick = PlatformBackend_GetTicks(); + base_tick = Backend_GetTicks(); need_new_base_tick = FALSE; } - current_tick = PlatformBackend_GetTicks(); + current_tick = Backend_GetTicks(); ++current_frame; if (base_tick + 1000 <= current_tick) @@ -88,10 +88,10 @@ int main(int argc, char *argv[]) int i; - PlatformBackend_Init(); + Backend_Init(); // Get executable's path - if (!PlatformBackend_GetBasePath(gModulePath)) + if (!Backend_GetBasePath(gModulePath)) { // Fall back on argv[0] if the backend cannot provide a path strcpy(gModulePath, argv[0]); @@ -222,7 +222,7 @@ int main(int argc, char *argv[]) { if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0)) { - PlatformBackend_Deinit(); + Backend_Deinit(); return EXIT_FAILURE; } } @@ -230,7 +230,7 @@ int main(int argc, char *argv[]) { if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1)) { - PlatformBackend_Deinit(); + Backend_Deinit(); return EXIT_FAILURE; } } @@ -254,7 +254,7 @@ int main(int argc, char *argv[]) #ifdef FIX_BUGS if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2)) { - PlatformBackend_Deinit(); + Backend_Deinit(); return EXIT_FAILURE; } #else @@ -264,7 +264,7 @@ int main(int argc, char *argv[]) bFullscreen = TRUE; - PlatformBackend_HideMouse(); + Backend_HideMouse(); break; } @@ -282,7 +282,7 @@ int main(int argc, char *argv[]) if (window_icon_rgb_pixels != NULL) { - PlatformBackend_SetWindowIcon(window_icon_rgb_pixels, window_icon_width, window_icon_height); + Backend_SetWindowIcon(window_icon_rgb_pixels, window_icon_width, window_icon_height); FreeBitmap(window_icon_rgb_pixels); } #endif @@ -296,7 +296,7 @@ int main(int argc, char *argv[]) if (cursor_rgb_pixels != NULL) { - PlatformBackend_SetCursor(cursor_rgb_pixels, cursor_width, cursor_height); + Backend_SetCursor(cursor_rgb_pixels, cursor_width, cursor_height); FreeBitmap(cursor_rgb_pixels); } @@ -319,7 +319,7 @@ int main(int argc, char *argv[]) // Draw to screen if (!Flip_SystemTask()) { - PlatformBackend_Deinit(); + Backend_Deinit(); return EXIT_SUCCESS; } @@ -345,7 +345,7 @@ int main(int argc, char *argv[]) EndDirectSound(); EndDirectDraw(); - PlatformBackend_Deinit(); + Backend_Deinit(); return EXIT_SUCCESS; } @@ -379,7 +379,7 @@ void JoystickProc(void); BOOL SystemTask(void) { - if (!PlatformBackend_SystemTask()) + if (!Backend_SystemTask()) return FALSE; for (unsigned int i = 0; i < BACKEND_KEYBOARD_TOTAL; ++i) diff --git a/src/Profile.cpp b/src/Profile.cpp index 988b1b65..b9048bee 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -6,7 +6,7 @@ #include "WindowsWrapper.h" -#include "Backends/Platform.h" +#include "Backends/Misc.h" #include "ArmsItem.h" #include "BossLife.h" #include "Fade.h" @@ -247,9 +247,9 @@ BOOL InitializeGame(void) if (!TransferStage(13, 200, 10, 8)) { #ifdef JAPANESE - PlatformBackend_ShowMessageBox("エラー", "ステージの読み込みに失敗"); + Backend_ShowMessageBox("エラー", "ステージの読み込みに失敗"); #else - PlatformBackend_ShowMessageBox("Error", "Failed to load stage"); + Backend_ShowMessageBox("Error", "Failed to load stage"); #endif return FALSE; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index ee4c8582..240c8269 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -6,7 +6,7 @@ #include "WindowsWrapper.h" -#include "Backends/Platform.h" +#include "Backends/Misc.h" #include "ArmsItem.h" #include "Boss.h" #include "BossLife.h" @@ -726,9 +726,9 @@ int TextScriptProc(void) if (!TransferStage(z, w, x, y)) { #ifdef JAPANESE - PlatformBackend_ShowMessageBox("エラー", "ステージの読み込みに失敗"); + Backend_ShowMessageBox("エラー", "ステージの読み込みに失敗"); #else - PlatformBackend_ShowMessageBox("Error", "Failed to load stage"); + Backend_ShowMessageBox("Error", "Failed to load stage"); #endif return enum_ESCRETURN_exit; @@ -1283,10 +1283,10 @@ int TextScriptProc(void) char str_0[0x40]; #ifdef JAPANESE sprintf(str_0, "不明のコード:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); - PlatformBackend_ShowMessageBox("エラー", str_0); + Backend_ShowMessageBox("エラー", str_0); #else sprintf(str_0, "Unknown code:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); - PlatformBackend_ShowMessageBox("Error", str_0); + Backend_ShowMessageBox("Error", str_0); #endif return enum_ESCRETURN_exit; From cdd69496c440b2cde2b3c0c144c31ae1a526d600 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:34:51 +0100 Subject: [PATCH 41/46] Fixes --- src/Backends/Rendering/SDLSurface.cpp | 6 +++--- src/Backends/Rendering/SDLTexture.cpp | 6 +++--- src/Backends/Rendering/Software.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index db217baa..6e8a3ab7 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -42,7 +42,7 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } -Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0); @@ -88,7 +88,7 @@ void RenderBackend_DrawScreen(void) SDL_UpdateWindowSurface(window); } -Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) +RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); @@ -176,7 +176,7 @@ void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, SDL_FillRect(surface->sdlsurface, &destination_rect, SDL_MapRGB(surface->sdlsurface->format, red, green, blue)); } -Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 963b8bf5..41e0f7fd 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -115,7 +115,7 @@ static void GlyphBatch_DestroyTexture(SPRITEBATCH_U64 texture_id, void *udata) SDL_DestroyTexture((SDL_Texture*)texture_id); } -Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { puts("Available SDL2 render drivers:"); @@ -209,7 +209,7 @@ void RenderBackend_DrawScreen(void) SDL_RenderPresent(renderer); } -Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) +RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); @@ -349,7 +349,7 @@ void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); } -Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index db02d5f1..dc775717 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -36,7 +36,7 @@ static RenderBackend_Surface framebuffer; static unsigned char glyph_colour_channels[3]; static RenderBackend_Surface *glyph_destination_surface; -Backend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) +RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0); @@ -87,7 +87,7 @@ void RenderBackend_DrawScreen(void) SDL_UpdateWindowSurface(window); } -Backend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) +RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) { RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface)); @@ -290,7 +290,7 @@ void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, } } -Backend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) +RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) { RenderBackend_Glyph *glyph = (RenderBackend_Glyph*)malloc(sizeof(RenderBackend_Glyph)); From 630b5e36574e5683531cdc63ae25c4efead44ba4 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:40:02 +0100 Subject: [PATCH 42/46] Prevent console from appearing in Makefile builds --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 5cc0406d..fea71fa1 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ endif ALL_CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d ALL_LIBS += -lkernel32 -lgdi32 -lddraw -ldinput -ldsound -lversion -lshlwapi -limm32 -lwinmm -ldxguid +ALL_LDFLAGS += -mwindows ifeq ($(STATIC), 1) ALL_LDFLAGS += -static From 1ae63bea967e9952c60814d8f0caa36534262498 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:51:07 +0100 Subject: [PATCH 43/46] Move window ownership to the window backend --- CMakeLists.txt | 4 ++-- src/Backends/GLFW3/Misc.cpp | 4 +--- src/Backends/GLFW3/Window-OpenGL3.cpp | 4 +++- src/Backends/GLFW3/{Misc.h => Window.h} | 0 src/Backends/Rendering/SDLSurface.cpp | 4 +++- src/Backends/Rendering/SDLTexture.cpp | 4 +++- src/Backends/Rendering/Software.cpp | 4 +++- src/Backends/SDL2/Misc.cpp | 4 +--- src/Backends/SDL2/Window-OpenGL3.cpp | 4 +++- src/Backends/SDL2/{Misc.h => Window.h} | 0 10 files changed, 19 insertions(+), 13 deletions(-) rename src/Backends/GLFW3/{Misc.h => Window.h} (100%) rename src/Backends/SDL2/{Misc.h => Window.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbe3d069..13efa613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,13 +338,13 @@ if(BACKEND_PLATFORM MATCHES "SDL2") "src/Backends/SDL2/Controller.cpp" "src/Backends/SDL2/Controller.h" "src/Backends/SDL2/Misc.cpp" - "src/Backends/SDL2/Misc.h" + "src/Backends/SDL2/Window.h" ) elseif(BACKEND_PLATFORM MATCHES "GLFW3") target_sources(CSE2 PRIVATE "src/Backends/GLFW3/Controller.cpp" "src/Backends/GLFW3/Misc.cpp" - "src/Backends/GLFW3/Misc.h" + "src/Backends/GLFW3/Window.h" ) endif() diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index f881ae07..0a45eff3 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -1,5 +1,4 @@ #include "../Misc.h" -#include "Misc.h" #include #include @@ -12,6 +11,7 @@ #include "../../WindowsWrapper.h" +#include "Window.h" #include "../Rendering.h" #include "../../Main.h" #include "../../Organya.h" @@ -23,8 +23,6 @@ backend_keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \ break; -GLFWwindow *window; - BOOL bActive = TRUE; BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; diff --git a/src/Backends/GLFW3/Window-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp index a8ce93ed..07130be1 100644 --- a/src/Backends/GLFW3/Window-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -1,4 +1,5 @@ #include "../Window-OpenGL.h" +#include "Window.h" #include #include @@ -13,7 +14,8 @@ #include "../../WindowsWrapper.h" #include "../Misc.h" -#include "Misc.h" + +GLFWwindow *window; BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) { diff --git a/src/Backends/GLFW3/Misc.h b/src/Backends/GLFW3/Window.h similarity index 100% rename from src/Backends/GLFW3/Misc.h rename to src/Backends/GLFW3/Window.h diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 6e8a3ab7..d225750c 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Misc.h" -#include "../SDL2/Misc.h" +#include "../SDL2/Window.h" typedef struct RenderBackend_Surface { @@ -21,6 +21,8 @@ typedef struct RenderBackend_Glyph SDL_Surface *sdlsurface; } RenderBackend_Glyph; +SDL_Window *window; + static SDL_Surface *window_sdlsurface; static RenderBackend_Surface framebuffer; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 41e0f7fd..45d5dc7f 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -13,7 +13,7 @@ #include "../../WindowsWrapper.h" #include "../Misc.h" -#include "../SDL2/Misc.h" +#include "../SDL2/Window.h" #include "../../Draw.h" #include "../../Ending.h" #include "../../MapName.h" @@ -38,6 +38,8 @@ typedef struct RenderBackend_Glyph unsigned int height; } RenderBackend_Glyph; +SDL_Window *window; + static SDL_Renderer *renderer; static RenderBackend_Surface framebuffer; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index dc775717..0ad6c985 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -9,7 +9,7 @@ #include "../../WindowsWrapper.h" #include "../Misc.h" -#include "../SDL2/Misc.h" +#include "../SDL2/Window.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -36,6 +36,8 @@ static RenderBackend_Surface framebuffer; static unsigned char glyph_colour_channels[3]; static RenderBackend_Surface *glyph_destination_surface; +SDL_Window *window; + RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen) { window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0); diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index 773e523e..bb858d90 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -1,5 +1,4 @@ #include "../Misc.h" -#include "Misc.h" #include #include @@ -10,6 +9,7 @@ #include "../../WindowsWrapper.h" #include "Controller.h" +#include "Window.h" #include "../Rendering.h" #include "../../Main.h" #include "../../Organya.h" @@ -21,8 +21,6 @@ backend_keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \ break; -SDL_Window *window; - BOOL bActive = TRUE; BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL]; BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; diff --git a/src/Backends/SDL2/Window-OpenGL3.cpp b/src/Backends/SDL2/Window-OpenGL3.cpp index f0679dbe..d3caba49 100644 --- a/src/Backends/SDL2/Window-OpenGL3.cpp +++ b/src/Backends/SDL2/Window-OpenGL3.cpp @@ -1,4 +1,5 @@ #include "../Window-OpenGL.h" +#include "Window.h" #include @@ -12,9 +13,10 @@ #include "../../WindowsWrapper.h" #include "../Misc.h" -#include "Misc.h" #include "../../Resource.h" +SDL_Window *window; + static SDL_GLContext context; BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen) diff --git a/src/Backends/SDL2/Misc.h b/src/Backends/SDL2/Window.h similarity index 100% rename from src/Backends/SDL2/Misc.h rename to src/Backends/SDL2/Window.h From b3e40b047577ea6d11564daa27652470d6279e3c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:52:24 +0100 Subject: [PATCH 44/46] Fix SDL2 audio backend --- src/Backends/Audio/SDL2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index 6f6b75e3..dc1676e6 100644 --- a/src/Backends/Audio/SDL2.cpp +++ b/src/Backends/Audio/SDL2.cpp @@ -5,7 +5,7 @@ #include "SDL.h" -#include "../Platform.h" +#include "../Misc.h" #include "../../Organya.h" #include "../../WindowsWrapper.h" @@ -66,7 +66,7 @@ BOOL AudioBackend_Init(void) { if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { - PlatformBackend_ShowMessageBox("Fatal error (SDL2 audio backend)", "'SDL_InitSubSystem(SDL_INIT_AUDIO)' failed"); + Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", "'SDL_InitSubSystem(SDL_INIT_AUDIO)' failed"); return FALSE; } @@ -90,7 +90,7 @@ BOOL AudioBackend_Init(void) if (device_id == 0) { - PlatformBackend_ShowMessageBox("Fatal error (SDL2 audio backend)", "'SDL_OpenAudioDevice' failed"); + Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", "'SDL_OpenAudioDevice' failed"); return FALSE; } From 6ea58290f49945ef34d374bb0fc8f6c97aa7a4e7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:57:34 +0100 Subject: [PATCH 45/46] Set SDL2 audio backend to 48000Hz --- src/Backends/Audio/SDL2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index dc1676e6..2f4b9745 100644 --- a/src/Backends/Audio/SDL2.cpp +++ b/src/Backends/Audio/SDL2.cpp @@ -76,10 +76,10 @@ BOOL AudioBackend_Init(void) puts(SDL_GetAudioDriver(i)); SDL_AudioSpec specification; - specification.freq = 44100; + specification.freq = 48000; specification.format = AUDIO_F32; specification.channels = 2; - specification.samples = 0x400; // Roughly 10 milliseconds for 44100Hz + specification.samples = 0x400; // Roughly 10 milliseconds for 48000Hz specification.callback = Callback; specification.userdata = NULL; From 7c729af36f42271a9f0e0184cd36a7192f599917 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 20:58:12 +0100 Subject: [PATCH 46/46] Add a comment --- src/Backends/Audio/miniaudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Audio/miniaudio.cpp b/src/Backends/Audio/miniaudio.cpp index ec685da2..bd1257f9 100644 --- a/src/Backends/Audio/miniaudio.cpp +++ b/src/Backends/Audio/miniaudio.cpp @@ -76,7 +76,7 @@ BOOL AudioBackend_Init(void) config.playback.pDeviceID = NULL; config.playback.format = ma_format_f32; config.playback.channels = 2; - config.sampleRate = 0; + config.sampleRate = 0; // Let miniaudio decide what sample rate to use config.dataCallback = Callback; config.pUserData = NULL;