Compare commits

..

No commits in common. "6e1ed2079d2234d2238db33ec503b385455d1fd7" and "18c8e6b887be0ab037e00cd1f35a17831a045e6c" have entirely different histories.

29 changed files with 106 additions and 394 deletions

View File

@ -13,14 +13,11 @@
"/usr/include/spa-0.2", "/usr/include/spa-0.2",
"/usr/include/libdrm", "/usr/include/libdrm",
"/usr/include/libdecor-0", "/usr/include/libdecor-0",
"/usr/include/x86_64-linux-gnu", "/usr/include/x86_64-linux-gnu"
"${env:HOME}/.local/share/fxsdk/sysroot/sh3eb-elf/include"
], ],
"compilerPath": "/usr/bin/gcc", "compilerPath": "/usr/bin/gcc",
"defines": [ "defines": [
"_REENTRANT", "-D_REENTRANT"
"FXCG50",
"TARGET_FXCG50"
], ],
"cStandard": "c17", "cStandard": "c17",
"browse": { "browse": {

View File

@ -4,15 +4,6 @@ SHELL = /usr/bin/env bash
ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
# Import config
ifeq ($(filter clean-all,$(MAKECMDGOALS)),)
ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk)
$(error ERROR: Please run the configure script before building)
endif
include $(ROOT)/config.mk
endif
# #
# User settings # User settings
# #
@ -26,6 +17,7 @@ ASSET_BUILDER_DIR = asset_builder
OUTPUT = 2D_Engine OUTPUT = 2D_Engine
ASSET_OUTPUT = game.data ASSET_OUTPUT = game.data
ASSET_BUILDER_OUTPUT = asset_builder/asset_builder
ifneq ($(DEBUG),) ifneq ($(DEBUG),)
TARGET_HOST_CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \ TARGET_HOST_CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \
@ -47,6 +39,15 @@ endif
# End # End
# #
# Import config
ifeq ($(filter clean-all,$(MAKECMDGOALS)),)
ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk)
$(error ERROR: Please run the configure script before building)
endif
include $(ROOT)/config.mk
endif
# Relocate vars # Relocate vars
BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST) BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST)
@ -55,10 +56,10 @@ CORE_DIR := $(ROOT)/$(CORE_DIR)
ASSETS_DIR := $(ROOT)/$(ASSETS_DIR) ASSETS_DIR := $(ROOT)/$(ASSETS_DIR)
ASSET_BUILDER_DIR := $(ROOT)/$(ASSET_BUILDER_DIR) ASSET_BUILDER_DIR := $(ROOT)/$(ASSET_BUILDER_DIR)
OUTPUT := $(BUILD_DIR)/$(OUTPUT)$(OUTPUT_EXT) OUTPUT := $(BUILD_DIR)/$(OUTPUT)
LIBCORE := $(BUILD_DIR)/libcore$(LIB_OUTPUT_EXT) LIBCORE := $(BUILD_DIR)/$(LIBCORE)
ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT) ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT)
ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/asset_builder/asset_builder$(OUTPUT_EXT) ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/$(ASSET_BUILDER_OUTPUT)
# Verbosity # Verbosity
export Q := @ export Q := @

250
configure vendored
View File

@ -11,23 +11,22 @@
# #
CONFIG_FILE="config.mk" CONFIG_FILE="config.mk"
CACHE_DIR="cache"
LIB_DIR="lib" #LUA_VERSION="5.5.1"
#LUA_CHECKSUM="1c4b4068d67061f2a2231ad2b5422e77acea1487ea9890f6320af614f4373dce"
# #
# Main # Main
# #
set -e print_error()
exit_error_message()
{ {
echo -e "\033[31merror\033[m: $1" echo -e "\033[31merror\033[m: $1"
exit 0 exit 0
} }
## Parse args ## Parse args
HOST="guess" CURRENT_HOST="guess"
TARGET_HOST="guess" TARGET_HOST="guess"
for i in "$@"; do for i in "$@"; do
@ -37,7 +36,7 @@ for i in "$@"; do
shift shift
;; ;;
--current-host=*) --current-host=*)
HOST="${i#*=}" CURRENT_HOST="${i#*=}"
shift shift
;; ;;
--clean) --clean)
@ -69,7 +68,7 @@ for i in "$@"; do
exit 0 exit 0
;; ;;
-*) -*)
exit_error_message "Unknown option $i" print_error "Unknown option $i"
;; ;;
*) *)
;; ;;
@ -79,7 +78,7 @@ done
## Clean ## Clean
if [ -n "${CLEAN}" ]; then if [ -n "${CLEAN}" ]; then
make clean-all make clean-all
rm -rf ${CONFIG_FILE} ${CACHE_DIR} ${LIB_DIR} rm -rf ${CONFIG_FILE}
fi fi
if [ -n "${EXIT_AFTER_CLEAN}" ]; then if [ -n "${EXIT_AFTER_CLEAN}" ]; then
@ -87,10 +86,10 @@ if [ -n "${EXIT_AFTER_CLEAN}" ]; then
fi fi
## Deduce current and target hosts ## Deduce current and target hosts
if [ "${HOST}" = "guess" ]; then if [ "${CURRENT_HOST}" = "guess" ]; then
case "${OSTYPE}" in case "${OSTYPE}" in
linux*) linux*)
HOST="linux" CURRENT_HOST="linux"
;; ;;
# msys*|cygwin*) # msys*|cygwin*)
# CURRENT_HOST="windows" # CURRENT_HOST="windows"
@ -99,212 +98,67 @@ if [ "${HOST}" = "guess" ]; then
# CURRENT_HOST="macos" # CURRENT_HOST="macos"
# ;; # ;;
*) *)
exit_error_message "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations."
;; ;;
esac esac
fi fi
echo "Configuring for current host: ${HOST}" echo "Configuring for current host: ${CURRENT_HOST}"
# If target host is guess then configure for host
if [ "${TARGET_HOST}" = "guess" ]; then if [ "${TARGET_HOST}" = "guess" ]; then
TARGET_HOST=${HOST} TARGET_HOST=${CURRENT_HOST}
fi fi
# Set host compiler and asset builder flags case "${CURRENT_HOST}" in
case "${HOST}" in
linux) linux)
HOST_CC=gcc HOST_CC="gcc"
ASSET_BUILDER_CFLAGS=( HOST_AR="ar"
"--std=c17" ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell pkg-config --cflags libpng json-c)"
"-O2" ASSET_BUILDER_LDFLAGS="\$(shell pkg-config --libs libpng json-c)"
)
ASSET_BUILDER_LDFLAGS=()
ASSET_BUILDER_LIBS=(
"libpng|1.6.48"
"json-c|0.18"
)
;; ;;
*) *)
exit_error_message "Compiling from ${HOST} is not supported yet." print_error "Compiling from ${CURRENT_HOST} is not supported yet."
;; ;;
esac esac
# Set target host compiler, outputs extensions and flags
case "${TARGET_HOST}" in case "${TARGET_HOST}" in
linux) linux)
echo "Configuring for target: ${TARGET_HOST}" echo "Configuring for target: ${TARGET_HOST}"
case "${HOST}" in case "${CURRENT_HOST}" in
linux) linux)
TARGET_HOST_CC=gcc TARGET_HOST_CC="gcc"
TARGET_HOST_AR=ar TARGET_HOST_AR="ar"
TARGET_HOST_CFLAGS=( TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3 lua)"
"--std=c17" "-Os" TARGET_HOST_LDFLAGS="\$(shell pkg-config --libs sdl3 lua) -lm"
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1" TARGET_HOST_LIBCORE="libcore.a"
)
TARGET_HOST_LDFLAGS=()
OUTPUT_EXT=""
LIB_OUTPUT_EXT=".a"
;; ;;
*) *)
exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet."
;; ;;
esac esac
TARGET_HOST_LIBS=(
"sdl3|3.2.10"
"lua|5.4.7"
)
;; ;;
fxcg50) fxcg50)
echo "Configuring for target: ${TARGET_HOST}" echo "Configuring for target: ${TARGET_HOST}"
case "${HOST}" in case "${CURRENT_HOST}" in
linux) linux)
TARGET_HOST_CC=sh-elf-gcc TARGET_HOST_CC="sh-elf-gcc"
TARGET_HOST_AR=sh-elf-ar TARGET_HOST_AR="sh-elf-ar"
TARGET_HOST_CFLAGS=( TARGET_HOST_CFLAGS="--std=c17 -Os"
"--std=c17" "-Os" TARGET_HOST_LDFLAGS=""
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-DFXCG50" "-DTARGET_FXCG50" TARGET_HOST_LIBCORE="libcore.a"
"-mb" "-m4-nofpu"
"-ffreestanding" "-nostdlib" "-fstrict-volatile-bitfields"
)
TARGET_HOST_LDFLAGS="-T fxcg50.ld"
OUTPUT_EXT=""
LIB_OUTPUT_EXT=".a"
;; ;;
*) *)
exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet."
;; ;;
esac esac
;; ;;
*) *)
exit_error_message "Unsupported target host: ${TARGET_HOST}" print_error "Unsupported target host: ${TARGET_HOST}"
esac esac
#
# Checks
#
echo
echo "Checking host compiler \"${HOST_CC}\"."
if ${HOST_CC} --version &> /dev/null; then
echo " ${HOST_CC} OK."
else
exit_error_message "Compiler not working."
fi
echo "Checking asset builder libs."
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
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
fi
done
echo "Checking target host compiler \"${TARGET_HOST_CC}\"."
if ${TARGET_HOST_CC} --version &> /dev/null; then
echo " ${TARGET_HOST_CC} OK."
else
exit_error_message "Compiler not working."
fi
echo "Checking target host archiver \"${TARGET_HOST_AR}\"."
if ${TARGET_HOST_AR} --version &> /dev/null; then
echo " ${TARGET_HOST_AR} OK."
else
exit_error_message "Compiler not working."
fi
echo "Checking target host libs."
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
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
fi
done
echo "Writing config file." echo "Writing config file."
echo echo
echo "${CONFIG_FILE}:" echo "${CONFIG_FILE}:"
@ -314,17 +168,43 @@ tee "${CONFIG_FILE}" <<EOF
# This file was generated by the configure script. # This file was generated by the configure script.
TARGET_HOST = ${TARGET_HOST} TARGET_HOST = ${TARGET_HOST}
LIB_OUTPUT_EXT = ${LIB_OUTPUT_EXT} LIBCORE = ${TARGET_HOST_LIBCORE}
TARGET_HOST_CC = ${TARGET_HOST_CC} TARGET_HOST_CC = ${TARGET_HOST_CC}
TARGET_HOST_AR = ${TARGET_HOST_AR} TARGET_HOST_AR = ${TARGET_HOST_AR}
TARGET_HOST_CFLAGS = ${TARGET_HOST_CFLAGS[@]} TARGET_HOST_CFLAGS = ${TARGET_HOST_CFLAGS}
TARGET_HOST_LDFLAGS = ${TARGET_HOST_LDFLAGS[@]} TARGET_HOST_LDFLAGS = ${TARGET_HOST_LDFLAGS}
HOST_CC = ${HOST_CC} HOST_CC = ${HOST_CC}
ASSET_BUILDER_CFLAGS = ${ASSET_BUILDER_CFLAGS[@]} ASSET_BUILDER_CFLAGS = ${ASSET_BUILDER_CFLAGS}
ASSET_BUILDER_LDFLAGS = ${ASSET_BUILDER_LDFLAGS[@]} ASSET_BUILDER_LDFLAGS = ${ASSET_BUILDER_LDFLAGS}
EOF EOF
echo "\`\`\`" echo "\`\`\`"
#
### Download libs
#echo "===== downloading lua ====="
#
#LUA_TAR_GZ="${CACHE_DIR}/lua-${LUA_VERSION}.tar.gz"
#if [ ! -e "${LUA_TAR_GZ}" ]; then
# echo "Downloading lua source..."
# if ! curl --output "${LUA_TAR_GZ}" "https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz"; then
# print_error "Failed to download lua source."
# fi
#fi
#
#echo "Checking lua source sum..."
#if ! echo "${LUA_CHECKSUM} ${LUA_TAR_GZ}" | sha256sum -c; then
# CHECKSUM="$(sha256sum "${LUA_TAR_GZ}" | cut -d " " -f 1)"
# rm "${LUA_TAR_GZ}"
# print_error "Lua zip checksum not valid.\nExpected: \"${LUA_CHECKSUM}\"\nGot: \"${CHECKSUM}\"\nPlease rerun command to retry downloading."
#fi
#
#echo "Extracting lua source"
#if ! tar -xzf "${LUA_TAR_GZ}" --directory "${LIB_DIR}"; then
# print_error "Failed to extract lua source."
#fi
#

View File

@ -5,6 +5,7 @@ SOURCES += \
event_bus.c \ event_bus.c \
ecs.c \ ecs.c \
asset_manager.c \ asset_manager.c \
inputs.c \
map.c map.c
INCLUDES += \ INCLUDES += \

View File

@ -1,5 +0,0 @@
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
vector2d.c \
inputs.c \
update_time.c \
)

View File

@ -1,23 +0,0 @@
#ifndef DISPLAY_H
#define DISPLAY_H
#include <gint/display.h>
#include "texture.h"
#include "vector2d.h"
#define DISPLAY_WIDTH DWIDTH
#define DISPLAY_HEIGHT DHEIGHT
typedef struct display_t {
} display_t;
int display_init(void);
void display_exit(void);
int display_clear(void);
int display_update(void);
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip);
int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
#endif // DISPLAY_H

View File

@ -1,16 +0,0 @@
#include "inputs.h"
#include <gint/keyboard.h>
inline int poll_event(input_event_t *event)
{
key_event_t gint_event = pollevent();
if(gint_event.type = KEYEV_NONE)
return 0;
event->type = gint_event.type;
event->key = gint_event.key;
return 1;
}

View File

@ -1,17 +0,0 @@
#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

View File

@ -1,15 +0,0 @@
#ifndef KEYCODES_H
#define KEYCODES_H
#include <gint/keyboard.h>
#define MAX_KEYCODES 0xB0
#define KEY_MOD KEY_SHIFT
#define KEY_INTERACT KEY_ALPHA
#define INPUT_EVENT_KEY_UP KEYEV_UP
#define INPUT_EVENT_KEY_DOWN KEYEV_DOWN
#define INPUT_EVENT_QUIT 0xFF
#endif // KEYCODES_H

View File

@ -1,6 +0,0 @@
#ifndef MEMORY_ALLOC_H
#define MEMORY_ALLOC_H
#include <stdlib.h>
#endif // MEMORY_ALLOC_H

View File

@ -1,16 +0,0 @@
#ifndef TEXTURE_H
#define TEXTURE_H
#include <gint/display.h>
#define TEXTURE_TRANSPARENT_COLOR 0x0001
typedef bopti_image_t texture_t;
#define get_width(T) T->width
#define get_height(T) T->height
texture_t *load_texture(void);
void destroy_texture(texture_t *texture);
#endif // TEXTURE_H

View File

@ -1,13 +0,0 @@
#include "update_time.h"
#include <time.h>
#include "game.h"
inline void update_time(void)
{
static clock_t last_clock_state = 0;
clock_t start_clock = clock();
game.delta_time_ms = (float)(start_clock - last_clock_state) / (float)CLOCKS_PER_SEC;
if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f;
last_clock_state = start_clock;
}

View File

@ -1,6 +0,0 @@
#ifndef TIME_H
#define TIME_H
void update_time(void);
#endif // TIME_H

View File

@ -1,7 +1,7 @@
#ifndef VECTOR2D_H #ifndef VECTOR2D_H
#define VECTOR2D_H #define VECTOR2D_H
#include <stdbool.h> #include <SDL3/SDL_rect.h>
#include <math.h> #include <math.h>
/** /**

View File

@ -13,6 +13,9 @@
#define DISPLAY_WIDTH 720 #define DISPLAY_WIDTH 720
#define DISPLAY_HEIGHT 480 #define DISPLAY_HEIGHT 480
//#define DRIVERS NULL
#define DRIVERS "vulkan,gpu,software"
typedef struct display_t { typedef struct display_t {
} display_t; } display_t;

View File

@ -1,17 +0,0 @@
#ifndef KEYCODES_H
#define KEYCODES_H
#define MAX_KEYCODES 0xFF
#define KEY_UP 0x01
#define KEY_DOWN 0x02
#define KEY_LEFT 0x03
#define KEY_RIGHT 0x04
#define KEY_MOD 0x05
#define KEY_INTERACT 0x06
#define INPUT_EVENT_KEY_UP 0x01
#define INPUT_EVENT_KEY_DOWN 0x02
#define INPUT_EVENT_QUIT 0xFF
#endif // KEYCODES_H

View File

@ -1,6 +0,0 @@
#ifndef TIME_H
#define TIME_H
void update_time(void);
#endif // TIME_H

View File

@ -2,6 +2,4 @@ SOURCES += $(addprefix host/$(TARGET_HOST)/, \
display.c \ display.c \
vector2d.c \ vector2d.c \
texture.c \ texture.c \
inputs.c \
update_time.c \
) )

View File

@ -1,17 +0,0 @@
#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

View File

@ -1,13 +0,0 @@
#include "update_time.h"
#include <SDL3/SDL.h>
#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;
}

View File

@ -1,6 +0,0 @@
#ifndef TIME_H
#define TIME_H
void update_time(void);
#endif // TIME_H

View File

@ -1,13 +1,16 @@
#ifndef KEYBOARD_H #ifndef KEYBOARD_H
#define KEYBOARD_H #define KEYBOARD_H
#include <stdint.h> #include <SDL3/SDL_events.h>
#include <stdbool.h>
#include "keycodes.h" #include "keycodes.h"
#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
typedef struct input_event_t { typedef struct input_event_t {
uint32_t type; uint32_t type;
int key; SDL_Scancode key;
} input_event_t; } input_event_t;
int poll_event(input_event_t *event); int poll_event(input_event_t *event);

View File

@ -12,8 +12,4 @@
#define KEY_MOD SDL_SCANCODE_LCTRL #define KEY_MOD SDL_SCANCODE_LCTRL
#define KEY_INTERACT SDL_SCANCODE_E #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 #endif // KEYCODES_H

View File

@ -1,11 +1,20 @@
#include "game.h" #include "game.h"
#include <SDL3/SDL.h>
#include <stdlib.h> #include <stdlib.h>
#include "update_time.h"
#include "errors.h" #include "errors.h"
game_t game; game_t game;
static 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;
}
int main(void) int main(void)
{ {
if(game_init()) goto_failure; if(game_init()) goto_failure;

View File

@ -8,7 +8,7 @@ SOURCES += \
components/animation_system.c \ components/animation_system.c \
components/player_system.c \ components/player_system.c \
components/lever_component.c \ components/lever_component.c \
components/door_component.c# \ components/door_component.c \
components/lua_component.c components/lua_component.c
INCLUDES += \ INCLUDES += \

View File

@ -6,12 +6,12 @@
COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW) COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW)
COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW)
COMPONENT(INTERACT_COMPONENT, interact_component, DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, DRAW)
//COMPONENT(LUA_COMPONENT, lua_component, DRAW) COMPONENT(LUA_COMPONENT, lua_component, DRAW)
#else #else
COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW) COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW)
COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW)
COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW)
//COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW) COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW)
#endif // DEBUG >= 2 #endif // DEBUG >= 2
COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW) COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW)

View File

@ -10,7 +10,7 @@
#include "player_system.h" #include "player_system.h"
#include "lever_component.h" #include "lever_component.h"
#include "door_component.h" #include "door_component.h"
//#include "lua_component.h" #include "lua_component.h"
// Add new components header file here // Add new components header file here
#endif // COMPONENTS_H #endif // COMPONENTS_H

View File

@ -21,7 +21,7 @@ int game_init(void)
entity_manager_init(); entity_manager_init();
if(asset_manager_init()) return_failure_int; if(asset_manager_init()) return_failure_int;
asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP); asset_t *map_asset = asset_manager_load_asset("dungeon_entry", ASSET_MAP);
if(!map_asset) return_failure_int; if(!map_asset) return_failure_int;
game.map = map_asset->data; game.map = map_asset->data;