Merge branch 'develop' into windows-support
This commit is contained in:
commit
7cf84ecd7a
|
|
@ -13,11 +13,14 @@
|
||||||
"/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": [
|
||||||
"-D_REENTRANT"
|
"_REENTRANT",
|
||||||
|
"FXCG50",
|
||||||
|
"TARGET_FXCG50"
|
||||||
],
|
],
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
"browse": {
|
"browse": {
|
||||||
|
|
|
||||||
25
Makefile
25
Makefile
|
|
@ -4,6 +4,15 @@ 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
|
||||||
#
|
#
|
||||||
|
|
@ -17,7 +26,6 @@ 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 \
|
||||||
|
|
@ -39,15 +47,6 @@ 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)
|
||||||
|
|
||||||
|
|
@ -56,10 +55,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 := $(BUILD_DIR)/$(OUTPUT)$(OUTPUT_EXT)
|
||||||
LIBCORE := $(BUILD_DIR)/$(LIBCORE)
|
LIBCORE := $(BUILD_DIR)/libcore$(LIB_OUTPUT_EXT)
|
||||||
ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT)
|
ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT)
|
||||||
ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/$(ASSET_BUILDER_OUTPUT)
|
ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/asset_builder/asset_builder$(OUTPUT_EXT)
|
||||||
|
|
||||||
# Verbosity
|
# Verbosity
|
||||||
export Q := @
|
export Q := @
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,23 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
CONFIG_FILE="config.mk"
|
CONFIG_FILE="config.mk"
|
||||||
|
CACHE_DIR="cache"
|
||||||
#LUA_VERSION="5.5.1"
|
LIB_DIR="lib"
|
||||||
#LUA_CHECKSUM="1c4b4068d67061f2a2231ad2b5422e77acea1487ea9890f6320af614f4373dce"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main
|
# Main
|
||||||
#
|
#
|
||||||
|
|
||||||
print_error()
|
set -e
|
||||||
|
|
||||||
|
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
|
||||||
CURRENT_HOST="guess"
|
HOST="guess"
|
||||||
TARGET_HOST="guess"
|
TARGET_HOST="guess"
|
||||||
|
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
|
|
@ -36,7 +37,7 @@ for i in "$@"; do
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--current-host=*)
|
--current-host=*)
|
||||||
CURRENT_HOST="${i#*=}"
|
HOST="${i#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--clean)
|
--clean)
|
||||||
|
|
@ -68,7 +69,7 @@ for i in "$@"; do
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
print_error "Unknown option $i"
|
exit_error_message "Unknown option $i"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
|
|
@ -78,7 +79,7 @@ done
|
||||||
## Clean
|
## Clean
|
||||||
if [ -n "${CLEAN}" ]; then
|
if [ -n "${CLEAN}" ]; then
|
||||||
make clean-all
|
make clean-all
|
||||||
rm -rf ${CONFIG_FILE}
|
rm -rf ${CONFIG_FILE} ${CACHE_DIR} ${LIB_DIR}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${EXIT_AFTER_CLEAN}" ]; then
|
if [ -n "${EXIT_AFTER_CLEAN}" ]; then
|
||||||
|
|
@ -86,10 +87,10 @@ if [ -n "${EXIT_AFTER_CLEAN}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Deduce current and target hosts
|
## Deduce current and target hosts
|
||||||
if [ "${CURRENT_HOST}" = "guess" ]; then
|
if [ "${HOST}" = "guess" ]; then
|
||||||
case "${OSTYPE}" in
|
case "${OSTYPE}" in
|
||||||
linux*)
|
linux*)
|
||||||
CURRENT_HOST="linux"
|
HOST="linux"
|
||||||
;;
|
;;
|
||||||
msys*|cygwin*)
|
msys*|cygwin*)
|
||||||
CURRENT_HOST="windows"
|
CURRENT_HOST="windows"
|
||||||
|
|
@ -98,23 +99,31 @@ if [ "${CURRENT_HOST}" = "guess" ]; then
|
||||||
# CURRENT_HOST="macos"
|
# CURRENT_HOST="macos"
|
||||||
# ;;
|
# ;;
|
||||||
*)
|
*)
|
||||||
print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations."
|
exit_error_message "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Configuring for current host: ${CURRENT_HOST}"
|
echo "Configuring for current host: ${HOST}"
|
||||||
|
|
||||||
|
# If target host is guess then configure for host
|
||||||
if [ "${TARGET_HOST}" = "guess" ]; then
|
if [ "${TARGET_HOST}" = "guess" ]; then
|
||||||
TARGET_HOST=${CURRENT_HOST}
|
TARGET_HOST=${HOST}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "${CURRENT_HOST}" in
|
# Set host compiler and asset builder flags
|
||||||
|
case "${HOST}" in
|
||||||
linux)
|
linux)
|
||||||
HOST_CC="gcc"
|
HOST_CC=gcc
|
||||||
HOST_AR="ar"
|
ASSET_BUILDER_CFLAGS=(
|
||||||
ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell pkg-config --cflags libpng json-c)"
|
"--std=c17"
|
||||||
ASSET_BUILDER_LDFLAGS="\$(shell pkg-config --libs libpng json-c)"
|
"-O2"
|
||||||
|
)
|
||||||
|
ASSET_BUILDER_LDFLAGS=()
|
||||||
|
ASSET_BUILDER_LIBS=(
|
||||||
|
"libpng|1.6.48"
|
||||||
|
"json-c|0.18"
|
||||||
|
)
|
||||||
;;
|
;;
|
||||||
windows)
|
windows)
|
||||||
HOST_CC="x86_64-w64-mingw32-gcc"
|
HOST_CC="x86_64-w64-mingw32-gcc"
|
||||||
|
|
@ -123,26 +132,36 @@ case "${CURRENT_HOST}" in
|
||||||
ASSET_BUILDER_LDFLAGS="\$(shell x86_64-w64-mingw32-pkg-config --libs libpng json-c)"
|
ASSET_BUILDER_LDFLAGS="\$(shell x86_64-w64-mingw32-pkg-config --libs libpng json-c)"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_error "Compiling from ${CURRENT_HOST} is not supported yet."
|
exit_error_message "Compiling from ${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 "${CURRENT_HOST}" in
|
case "${HOST}" in
|
||||||
linux)
|
linux)
|
||||||
TARGET_HOST_CC="gcc"
|
TARGET_HOST_CC=gcc
|
||||||
TARGET_HOST_AR="ar"
|
TARGET_HOST_AR=ar
|
||||||
TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3 lua)"
|
TARGET_HOST_CFLAGS=(
|
||||||
TARGET_HOST_LDFLAGS="\$(shell pkg-config --libs sdl3 lua) -lm"
|
"--std=c17" "-Os"
|
||||||
TARGET_HOST_LIBCORE="libcore.a"
|
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1"
|
||||||
|
)
|
||||||
|
TARGET_HOST_LDFLAGS=()
|
||||||
|
OUTPUT_EXT=""
|
||||||
|
LIB_OUTPUT_EXT=".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
|
esac
|
||||||
|
|
||||||
|
TARGET_HOST_LIBS=(
|
||||||
|
"sdl3|3.2.10"
|
||||||
|
"lua|5.4.7"
|
||||||
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
windows)
|
windows)
|
||||||
|
|
@ -166,23 +185,150 @@ case "${TARGET_HOST}" in
|
||||||
fxcg50)
|
fxcg50)
|
||||||
echo "Configuring for target: ${TARGET_HOST}"
|
echo "Configuring for target: ${TARGET_HOST}"
|
||||||
|
|
||||||
case "${CURRENT_HOST}" in
|
case "${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="--std=c17 -Os"
|
TARGET_HOST_CFLAGS=(
|
||||||
TARGET_HOST_LDFLAGS=""
|
"--std=c17" "-Os"
|
||||||
TARGET_HOST_LIBCORE="libcore.a"
|
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-DFXCG50" "-DTARGET_FXCG50"
|
||||||
|
"-mb" "-m4-nofpu"
|
||||||
|
"-ffreestanding" "-nostdlib" "-fstrict-volatile-bitfields"
|
||||||
|
)
|
||||||
|
TARGET_HOST_LDFLAGS="-T fxcg50.ld"
|
||||||
|
OUTPUT_EXT=""
|
||||||
|
LIB_OUTPUT_EXT=".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
|
esac
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_error "Unsupported target host: ${TARGET_HOST}"
|
exit_error_message "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}:"
|
||||||
|
|
@ -192,17 +338,17 @@ 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}
|
||||||
LIBCORE = ${TARGET_HOST_LIBCORE}
|
LIB_OUTPUT_EXT = ${LIB_OUTPUT_EXT}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
if [ "${CURRENT_HOST}" = "windows" ]; then
|
if [ "${CURRENT_HOST}" = "windows" ]; then
|
||||||
|
|
@ -214,29 +360,3 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ 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 += \
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
||||||
|
vector2d.c \
|
||||||
|
inputs.c \
|
||||||
|
update_time.c \
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#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
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
#ifndef KEYBOARD_H
|
#ifndef KEYBOARD_H
|
||||||
#define KEYBOARD_H
|
#define KEYBOARD_H
|
||||||
|
|
||||||
#include <SDL3/SDL_events.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;
|
||||||
SDL_Scancode key;
|
int key;
|
||||||
} input_event_t;
|
} input_event_t;
|
||||||
|
|
||||||
int poll_event(input_event_t *event);
|
int poll_event(input_event_t *event);
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#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
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef MEMORY_ALLOC_H
|
||||||
|
#define MEMORY_ALLOC_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#endif // MEMORY_ALLOC_H
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#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
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef TIME_H
|
||||||
|
#define TIME_H
|
||||||
|
|
||||||
|
void update_time(void);
|
||||||
|
|
||||||
|
#endif // TIME_H
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef VECTOR2D_H
|
#ifndef VECTOR2D_H
|
||||||
#define VECTOR2D_H
|
#define VECTOR2D_H
|
||||||
|
|
||||||
#include <SDL3/SDL_rect.h>
|
#include <stdbool.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,6 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef KEYBOARD_H
|
||||||
|
#define KEYBOARD_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.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
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#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
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef TIME_H
|
||||||
|
#define TIME_H
|
||||||
|
|
||||||
|
void update_time(void);
|
||||||
|
|
||||||
|
#endif // TIME_H
|
||||||
|
|
@ -2,4 +2,6 @@ SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
||||||
display.c \
|
display.c \
|
||||||
vector2d.c \
|
vector2d.c \
|
||||||
texture.c \
|
texture.c \
|
||||||
|
inputs.c \
|
||||||
|
update_time.c \
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -12,4 +12,8 @@
|
||||||
#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
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef TIME_H
|
||||||
|
#define TIME_H
|
||||||
|
|
||||||
|
void update_time(void);
|
||||||
|
|
||||||
|
#endif // TIME_H
|
||||||
11
core/main.c
11
core/main.c
|
|
@ -1,20 +1,11 @@
|
||||||
#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;
|
||||||
|
|
|
||||||
|
|
@ -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 += \
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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_entry", ASSET_MAP);
|
asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP);
|
||||||
if(!map_asset) return_failure_int;
|
if(!map_asset) return_failure_int;
|
||||||
|
|
||||||
game.map = map_asset->data;
|
game.map = map_asset->data;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue