From 0b5d3892dd605423c25618e1f26d8f2d2952964c Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Sat, 26 Sep 2026 15:01:20 +0200 Subject: [PATCH] Windows almost supported, still needed to replace getdelim func. --- Makefile | 2 +- assets/maps/tiled-extensions/install.sh | 0 configure | 162 +++++++++--------------- core/host/windows/Makefile | 2 + core/host/windows/display.h | 4 +- core/host/windows/inputs.c | 14 ++ core/host/windows/inputs.h | 17 +++ core/host/windows/keycodes.h | 19 +++ core/host/windows/update_time.c | 13 ++ core/host/windows/update_time.h | 6 + 10 files changed, 134 insertions(+), 105 deletions(-) mode change 100755 => 100644 assets/maps/tiled-extensions/install.sh mode change 100755 => 100644 configure create mode 100644 core/host/windows/inputs.c create mode 100644 core/host/windows/inputs.h create mode 100644 core/host/windows/keycodes.h create mode 100644 core/host/windows/update_time.c create mode 100644 core/host/windows/update_time.h diff --git a/Makefile b/Makefile index b458077..eb2789f 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ ASSETS_DIR := $(ROOT)/$(ASSETS_DIR) ASSET_BUILDER_DIR := $(ROOT)/$(ASSET_BUILDER_DIR) OUTPUT := $(BUILD_DIR)/$(OUTPUT)$(OUTPUT_EXT) -LIBCORE := $(BUILD_DIR)/libcore$(LIB_OUTPUT_EXT) +LIBCORE := $(BUILD_DIR)/libcore$(STATIC_LIB_OUTPUT_EXT) ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT) ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/asset_builder/asset_builder$(OUTPUT_EXT) diff --git a/assets/maps/tiled-extensions/install.sh b/assets/maps/tiled-extensions/install.sh old mode 100755 new mode 100644 diff --git a/configure b/configure old mode 100755 new mode 100644 index a7c4f68..0ae54a2 --- a/configure +++ b/configure @@ -11,8 +11,6 @@ # CONFIG_FILE="config.mk" -CACHE_DIR="cache" -LIB_DIR="lib" # # Main @@ -79,7 +77,7 @@ done ## Clean if [ -n "${CLEAN}" ]; then make clean-all - rm -rf ${CONFIG_FILE} ${CACHE_DIR} ${LIB_DIR} + rm -rf ${CONFIG_FILE} fi if [ -n "${EXIT_AFTER_CLEAN}" ]; then @@ -93,10 +91,10 @@ if [ "${HOST}" = "guess" ]; then HOST="linux" ;; msys*|cygwin*) - CURRENT_HOST="windows" + HOST="windows" ;; # darwin*) -# CURRENT_HOST="macos" +# HOST="macos" # ;; *) exit_error_message "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." @@ -115,21 +113,29 @@ fi case "${HOST}" in linux) HOST_CC=gcc + HOST_PKG_CONFIG=pkg-config ASSET_BUILDER_CFLAGS=( "--std=c17" "-O2" ) ASSET_BUILDER_LDFLAGS=() ASSET_BUILDER_LIBS=( - "libpng|1.6.48" - "json-c|0.18" + "libpng|1.6.34" + "json-c|0.11" ) ;; + windows) - HOST_CC="x86_64-w64-mingw32-gcc" - HOST_AR="x86_64-w64-mingw32-ar" - ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell x86_64-w64-mingw32-pkg-config --cflags libpng json-c)" - ASSET_BUILDER_LDFLAGS="\$(shell x86_64-w64-mingw32-pkg-config --libs libpng json-c)" + HOST_CC=x86_64-w64-mingw32-gcc + HOST_PKG_CONFIG=x86_64-w64-mingw32-pkg-config + ASSET_BUILDER_CFLAGS=( + "--std=c17" "-O2" + ) + ASSET_BUILDER_LDFLAGS=() + ASSET_BUILDER_LIBS=( + "libpng|1.6.34" + "json-c|0.11" + ) ;; *) exit_error_message "Compiling from ${HOST} is not supported yet." @@ -145,13 +151,15 @@ case "${TARGET_HOST}" in linux) TARGET_HOST_CC=gcc TARGET_HOST_AR=ar + TARGET_HOST_PKG_CONFIG=pkg-config TARGET_HOST_CFLAGS=( "--std=c17" "-Os" "-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1" ) TARGET_HOST_LDFLAGS=() OUTPUT_EXT="" - LIB_OUTPUT_EXT=".a" + DYNAMIC_LIB_OUTPUT_EXT=".so" + STATIC_LIB_OUTPUT_EXT=".a" ;; *) exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." @@ -167,19 +175,30 @@ case "${TARGET_HOST}" in windows) echo "Configuring for target: ${TARGET_HOST}" - case "${CURRENT_HOST}" in + case "${HOST}" in windows) - TARGET_HOST_CC="x86_64-w64-mingw32-gcc" - TARGET_HOST_AR="x86_64-w64-mingw32-ar" - TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell x86_64-w64-mingw32-pkg-config --cflags sdl3 lua)" - TARGET_HOST_LDFLAGS="\$(shell x86_64-w64-mingw32-pkg-config --libs sdl3 lua) -lm" - TARGET_HOST_LIBCORE="libcore.dll" + TARGET_HOST_CC=x86_64-w64-mingw32-gcc + TARGET_HOST_AR=x86_64-w64-mingw32-gcc-ar + TARGET_HOST_PKG_CONFIG=x86_64-w64-mingw32-pkg-config + TARGET_HOST_CFLAGS=( + "--std=c17" "-Os" + "-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1" + ) + TARGET_HOST_LDFLAGS=() + OUTPUT_EXT=".exe" + DYNAMIC_LIB_OUTPUT_EXT=".dll" + STATIC_LIB_OUTPUT_EXT=".dll.a" ;; *) - print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet." + exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." ;; esac + + TARGET_HOST_LIBS=( + "sdl3|3.3.4" + "lua|5.4.7" + ) ;; fxcg50) @@ -197,13 +216,15 @@ case "${TARGET_HOST}" in ) TARGET_HOST_LDFLAGS="-T fxcg50.ld" OUTPUT_EXT="" - LIB_OUTPUT_EXT=".a" + DYNAMIC_LIB_OUTPUT_EXT=".so" + STATIC_LIB_OUTPUT_EXT=".a" ;; *) exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." ;; esac ;; + *) exit_error_message "Unsupported target host: ${TARGET_HOST}" esac @@ -226,45 +247,10 @@ for LIB in ${ASSET_BUILDER_LIBS[@]}; do LIB_NAME="$(echo ${LIB} | cut -d "|" -f 1)" LIB_MIN_VERSION="$(echo ${LIB} | cut -d "|" -f 2)" - if pkg-config --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then + if ${HOST_PKG_CONFIG} --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then echo " ${LIB_NAME} OK." else - LIB_URL=$(echo $LIB | cut -d "|" -f 3) - - if [ "${LIB_URL}" = "" ]; then - exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found and no precompiled binaries are available." - else - LIB_DOWNLOAD_CHECKSUM=$(echo $LIB | cut -d "|" -f 4) - LIB_DOWNLOAD_FILENAME="$(echo ${LIB_URL} | rev | cut -d "/" -f 1 | rev)" - LIB_DOWNLOAD_PATH="${CACHE_DIR}/${TARGET_HOST}/${LIB_DOWNLOAD_FILENAME}" - - case "${LIB_DOWNLOAD_FILENAME}" in - *.txz) - LIB_FOLDER_NAME="${LIB_DOWNLOAD_FILENAME%.txz}" - ;; - *) - exit_error_message "File ${LIB_DOWNLOAD_FILENAME} extension substitution is not supported." - esac - LIB_PATH="${LIB_DIR}/${TARGET_HOST}/${LIB_FOLDER_NAME}" - - echo " ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found but precompiled binaries are available." - - if [ ! -f "${LIB_DOWNLOAD_PATH}" ]; then - echo " downloading from ${LIB_URL}." - mkdir -p "$(dirname "${LIB_DOWNLOAD_PATH}")" - wget -q -O"${LIB_DOWNLOAD_PATH}" "${LIB_URL}" - fi - - if echo "${LIB_DOWNLOAD_CHECKSUM} ${LIB_DOWNLOAD_PATH}" | md5sum --check &> /dev/null; then - echo " ${LIB_DOWNLOAD_PATH} OK." - else - rm -rf "${LIB_DOWNLOAD_PATH}" - exit_error_message "Failed to verify checksum of ${LIB_DOWNLOAD_PATH}." - fi - - mkdir -p "${LIB_PATH}" - tar -xf "${LIB_DOWNLOAD_PATH}" -C "${LIB_PATH}" - fi + exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} not found." fi done @@ -287,50 +273,20 @@ for LIB in ${TARGET_HOST_LIBS[@]}; do LIB_NAME="$(echo ${LIB} | cut -d "|" -f 1)" LIB_MIN_VERSION="$(echo ${LIB} | cut -d "|" -f 2)" - if pkg-config --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then + if ${TARGET_HOST_PKG_CONFIG} --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then echo " ${LIB_NAME} OK." else - LIB_URL=$(echo $LIB | cut -d "|" -f 3) - - if [ "${LIB_URL}" = "" ]; then - exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found and no precompiled binaries are available." - else - LIB_DOWNLOAD_CHECKSUM=$(echo $LIB | cut -d "|" -f 4) - LIB_DOWNLOAD_FILENAME="$(echo ${LIB_URL} | rev | cut -d "/" -f 1 | rev)" - LIB_DOWNLOAD_PATH="${CACHE_DIR}/${TARGET_HOST}/${LIB_DOWNLOAD_FILENAME}" - - case "${LIB_DOWNLOAD_FILENAME}" in - *.txz) - LIB_FOLDER_NAME="${LIB_DOWNLOAD_FILENAME%.txz}" - ;; - *) - exit_error_message "File ${LIB_DOWNLOAD_FILENAME} extension substitution is not supported." - esac - LIB_PATH="${LIB_DIR}/${TARGET_HOST}/${LIB_FOLDER_NAME}" - - echo " ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found but precompiled binaries are available." - - if [ ! -f "${LIB_DOWNLOAD_PATH}" ]; then - echo " downloading from ${LIB_URL}." - mkdir -p "$(dirname "${LIB_DOWNLOAD_PATH}")" - wget -q -O"${LIB_DOWNLOAD_PATH}" "${LIB_URL}" - fi - - if echo "${LIB_DOWNLOAD_CHECKSUM} ${LIB_DOWNLOAD_PATH}" | md5sum --check &> /dev/null; then - echo " ${LIB_DOWNLOAD_PATH} OK." - else - rm -rf "${LIB_DOWNLOAD_PATH}" - exit_error_message "Failed to verify checksum of ${LIB_DOWNLOAD_PATH}." - fi - - mkdir -p "${LIB_PATH}" - tar -xf "${LIB_DOWNLOAD_PATH}" -C "${LIB_PATH}" - fi + exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} not found." fi done -echo "Writing config file." +# +# Config file +# + echo + +echo "Writing config file." echo "${CONFIG_FILE}:" echo "\`\`\`" @@ -338,20 +294,24 @@ tee "${CONFIG_FILE}" < + +inline int poll_event(input_event_t *event) +{ + SDL_Event sdl_event; + int ret = SDL_PollEvent(&sdl_event); + + event->type = sdl_event.type; + event->key = sdl_event.key.scancode; + + return ret; +} diff --git a/core/host/windows/inputs.h b/core/host/windows/inputs.h new file mode 100644 index 0000000..92d1b67 --- /dev/null +++ b/core/host/windows/inputs.h @@ -0,0 +1,17 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include "keycodes.h" + +typedef struct input_event_t { + uint32_t type; + int key; +} input_event_t; + +int poll_event(input_event_t *event); + +typedef struct inputs_t { + bool keys[MAX_KEYCODES]; +} inputs_t; + +#endif // KEYBOARD_H \ No newline at end of file diff --git a/core/host/windows/keycodes.h b/core/host/windows/keycodes.h new file mode 100644 index 0000000..7ac90de --- /dev/null +++ b/core/host/windows/keycodes.h @@ -0,0 +1,19 @@ +#ifndef KEYCODES_H +#define KEYCODES_H + +#include + +#define MAX_KEYCODES SDL_SCANCODE_COUNT + +#define KEY_UP SDL_SCANCODE_W +#define KEY_DOWN SDL_SCANCODE_S +#define KEY_LEFT SDL_SCANCODE_A +#define KEY_RIGHT SDL_SCANCODE_D +#define KEY_MOD SDL_SCANCODE_LCTRL +#define KEY_INTERACT SDL_SCANCODE_E + +#define INPUT_EVENT_KEY_UP SDL_EVENT_KEY_UP +#define INPUT_EVENT_KEY_DOWN SDL_EVENT_KEY_DOWN +#define INPUT_EVENT_QUIT SDL_EVENT_QUIT + +#endif // KEYCODES_H \ No newline at end of file diff --git a/core/host/windows/update_time.c b/core/host/windows/update_time.c new file mode 100644 index 0000000..3778b80 --- /dev/null +++ b/core/host/windows/update_time.c @@ -0,0 +1,13 @@ +#include "update_time.h" + +#include +#include "game.h" + +inline void update_time(void) +{ + static uint64_t last_clock_state = 0; + uint64_t start_clock = SDL_GetTicksNS(); + game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state)); + if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; + last_clock_state = start_clock; +} diff --git a/core/host/windows/update_time.h b/core/host/windows/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/windows/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file