Build chain compiling engine.
This commit is contained in:
parent
d0dda33a7a
commit
124e30281b
|
|
@ -1,4 +1,3 @@
|
||||||
.vscode/ccls-cache
|
.vscode/ccls-cache
|
||||||
.cache
|
config.mk
|
||||||
.config
|
|
||||||
build
|
build
|
||||||
|
|
|
||||||
74
Makefile
74
Makefile
|
|
@ -1,12 +1,41 @@
|
||||||
SHELL = /usr/bin/env bash
|
SHELL = /usr/bin/env bash
|
||||||
|
|
||||||
# Build folder
|
ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
BUILD_DIR = build
|
|
||||||
|
|
||||||
# Outputs target name and path
|
ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk)
|
||||||
SOURCE_OUTPUT = $(BUILD_DIR)/2D_Engine
|
$(error ERROR: Please run the configure script before building.)
|
||||||
CORE_OUTPUT = $(BUILD_DIR)/libcore.a
|
endif
|
||||||
ASSET_OUTPUT = $(BUILD_DIR)/game.data
|
|
||||||
|
include $(ROOT)/config.mk
|
||||||
|
|
||||||
|
#
|
||||||
|
# User config
|
||||||
|
#
|
||||||
|
|
||||||
|
BUILD_DIR_NAME = build
|
||||||
|
|
||||||
|
SOURCE_DIR = src
|
||||||
|
CORE_DIR = core
|
||||||
|
HOST_DIR = host
|
||||||
|
|
||||||
|
OUTPUT = 2D_Engine
|
||||||
|
ASSET_OUTPUT = game.data
|
||||||
|
|
||||||
|
ifneq ($(DEBUG),)
|
||||||
|
CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \
|
||||||
|
-Wno-missing-field-initializers -Wformat=2 -Wswitch-default -Wswitch \
|
||||||
|
-Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
|
||||||
|
-Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual \
|
||||||
|
-Wshadow -Wunreachable-code -Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 \
|
||||||
|
-Wredundant-decls -Wold-style-definition
|
||||||
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# End
|
||||||
|
#
|
||||||
|
|
||||||
|
# Relocate build dir
|
||||||
|
BUILD_DIR := $(ROOT)/$(BUILD_DIR_NAME)/$(HOST)
|
||||||
|
|
||||||
# Verbosity
|
# Verbosity
|
||||||
Q := @
|
Q := @
|
||||||
|
|
@ -15,33 +44,26 @@ Q :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
export GREEN := \033[32m
|
GREEN := \033[32m
|
||||||
export YELLOW := \033[33m
|
YELLOW := \033[33m
|
||||||
export RESET := \033[m
|
RESET := \033[m
|
||||||
|
|
||||||
# Default targets
|
# Default targets
|
||||||
all: $(SOURCE_OUTPUT)
|
all: setup $(BUILD_DIR)/$(OUTPUT)
|
||||||
|
|
||||||
# Sub Makefiles
|
include $(ROOT)/$(SOURCE_DIR)/Makefile
|
||||||
SOURCE_DIR = src
|
include $(ROOT)/$(CORE_DIR)/Makefile
|
||||||
CORE_DIR = core/src
|
|
||||||
ASSETS_DIR = assets
|
|
||||||
|
|
||||||
include $(SOURCE_DIR)/Makefile
|
setup:
|
||||||
include $(CORE_DIR)/Makefile
|
$(eval export TOTAL_BUILD_FILES := $(shell echo $$(($$(make -n $(OBJECTS) $(CORE_OBJECTS) 2>/dev/null | grep -c $(CC)) + 2))))
|
||||||
include $(ASSETS_DIR)/Makefile
|
$(Q)mkdir -p $(dir $(OBJECTS) $(CORE_OBJECTS))
|
||||||
|
|
||||||
# Clean
|
.PHONY: clean run print-var-%
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
clean:
|
||||||
$(Q)rm -rf $(BUILD_DIR)
|
$(Q)rm -rf $(dir $(BUILD_DIR))
|
||||||
@echo "Build dir cleaned"
|
|
||||||
|
|
||||||
# Run executable
|
|
||||||
.PHONY: run
|
|
||||||
run: all
|
run: all
|
||||||
$(Q)cd $(BUILD_DIR) && ./$(notdir $(SOURCE_OUTPUT))
|
$(Q)cd $(BUILD_DIR) && ./$(OUTPUT)
|
||||||
|
|
||||||
.PHONY: print-%
|
print-var-% :
|
||||||
print-% :
|
|
||||||
@echo $($*)
|
@echo $($*)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ ASSETS := $(addprefix $(ASSETS_DIR)/,$(ASSETS))
|
||||||
|
|
||||||
ASSETS_OBJECTS = $(ASSETS:%=$(BUILD_DIR)/%.o)
|
ASSETS_OBJECTS = $(ASSETS:%=$(BUILD_DIR)/%.o)
|
||||||
|
|
||||||
|
|
||||||
ASSET_BUILDER_DIR = $(ASSETS_DIR)/asset_builder/src
|
ASSET_BUILDER_DIR = $(ASSETS_DIR)/asset_builder/src
|
||||||
ASSET_BUILDER_OUTPUT = $(BUILD_DIR)/$(ASSETS_DIR)/asset_builder/asset_builder
|
ASSET_BUILDER_OUTPUT = $(BUILD_DIR)/$(ASSETS_DIR)/asset_builder/asset_builder
|
||||||
include $(ASSET_BUILDER_DIR)/Makefile
|
include $(ASSET_BUILDER_DIR)/Makefile
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
gcc
|
gcc
|
||||||
# Headers
|
# Headers
|
||||||
-Iassets/asset_builder/src/headers
|
-Iassets/asset_builder/src/headers
|
||||||
-Isrc/components/headers
|
-Isrc/components
|
||||||
|
|
||||||
# Macros
|
# Macros
|
||||||
-DDEBUG=2
|
-DDEBUG=2
|
||||||
|
|
@ -10,9 +10,7 @@
|
||||||
# Project settings no matter current and target hosts
|
# Project settings no matter current and target hosts
|
||||||
#
|
#
|
||||||
|
|
||||||
#CACHE_DIR=".cache"
|
CONFIG_FILE="config.mk"
|
||||||
#LIB_DIR="lib"
|
|
||||||
#CONFIG_FILE=".config"
|
|
||||||
|
|
||||||
#LUA_VERSION="5.5.1"
|
#LUA_VERSION="5.5.1"
|
||||||
#LUA_CHECKSUM="1c4b4068d67061f2a2231ad2b5422e77acea1487ea9890f6320af614f4373dce"
|
#LUA_CHECKSUM="1c4b4068d67061f2a2231ad2b5422e77acea1487ea9890f6320af614f4373dce"
|
||||||
|
|
@ -21,11 +19,6 @@
|
||||||
# Main
|
# Main
|
||||||
#
|
#
|
||||||
|
|
||||||
### Setup dirs and logs
|
|
||||||
#
|
|
||||||
## Cache dir
|
|
||||||
#mkdir -p "${CACHE_DIR}"
|
|
||||||
|
|
||||||
print_error()
|
print_error()
|
||||||
{
|
{
|
||||||
echo -e "\033[31merror\033[m: $1"
|
echo -e "\033[31merror\033[m: $1"
|
||||||
|
|
@ -77,8 +70,7 @@ done
|
||||||
## Clean
|
## Clean
|
||||||
if [ -n "${CLEAN}" ]; then
|
if [ -n "${CLEAN}" ]; then
|
||||||
make clean
|
make clean
|
||||||
rm -rf .config .cache lib
|
rm -rf ${CONFIG_FILE}
|
||||||
echo "Cleaned project."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${EXIT_AFTER_CLEAN}" ]; then
|
if [ -n "${EXIT_AFTER_CLEAN}" ]; then
|
||||||
|
|
@ -118,6 +110,55 @@ esac
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
if [ "${CURRENT_HOST}" != "${TARGET_HOST}" ]; then
|
||||||
|
CROSS_COMPILE=TRUE
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${CROSS_COMPILE}" ]; then
|
||||||
|
case "${TARGET_HOST}" in
|
||||||
|
fxcg50)
|
||||||
|
case "${CURRENT_HOST}" in
|
||||||
|
linux)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CC="sh-elf-gcc"
|
||||||
|
AR="sh-elf-ar"
|
||||||
|
LIBCORE="libcore.a"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
case "${TARGET_HOST}" in
|
||||||
|
linux)
|
||||||
|
CC="gcc"
|
||||||
|
AR="ar"
|
||||||
|
CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3)"
|
||||||
|
LDFLAGS="\$(shell pkg-config --libs sdl3) -lm"
|
||||||
|
|
||||||
|
LIBCORE="libcore.a"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Writing config file."
|
||||||
|
echo
|
||||||
|
echo "${CONFIG_FILE}:"
|
||||||
|
echo "\`\`\`"
|
||||||
|
echo "HOST = ${TARGET_HOST}" | tee ${CONFIG_FILE}
|
||||||
|
echo | tee -a ${CONFIG_FILE}
|
||||||
|
echo "CC = ${CC}" | tee -a ${CONFIG_FILE}
|
||||||
|
echo "AR = ${AR}" | tee -a ${CONFIG_FILE}
|
||||||
|
echo "CFLAGS = ${CFLAGS}" | tee -a ${CONFIG_FILE}
|
||||||
|
echo "LDFLAGS = ${LDFLAGS}" | tee -a ${CONFIG_FILE}
|
||||||
|
echo | tee -a ${CONFIG_FILE}
|
||||||
|
echo "LIBCORE = ${LIBCORE}" | tee -a ${CONFIG_FILE}
|
||||||
|
echo "\`\`\`"
|
||||||
|
|
||||||
#
|
#
|
||||||
### Download libs
|
### Download libs
|
||||||
#echo "===== downloading lua ====="
|
#echo "===== downloading lua ====="
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
gcc
|
||||||
|
# Headers
|
||||||
|
-Icore
|
||||||
|
-Icore/host/generic
|
||||||
|
-Isrc/components
|
||||||
|
|
||||||
|
# Macros
|
||||||
|
-DASSET_FILE_NAME="$(make print-var-ASSET_OUTPUT)"
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
CORE_SOURCES += \
|
||||||
|
main.c \
|
||||||
|
camera.c \
|
||||||
|
linked_list.c \
|
||||||
|
event_bus.c \
|
||||||
|
ecs.c \
|
||||||
|
asset_manager.c \
|
||||||
|
inputs.c \
|
||||||
|
map.c
|
||||||
|
|
||||||
|
CORE_INCLUDES += \
|
||||||
|
$(CORE_DIR) \
|
||||||
|
$(CORE_DIR)/$(HOST_DIR)/$(HOST) \
|
||||||
|
$(SOURCE_DIR)/components
|
||||||
|
|
||||||
|
include $(ROOT)/$(CORE_DIR)/$(HOST_DIR)/$(HOST)/Makefile
|
||||||
|
CORE_OBJECTS := $(CORE_SOURCES:%=$(BUILD_DIR)/$(CORE_DIR)/%.o)
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(LIBCORE): $(CORE_OBJECTS)
|
||||||
|
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE) + 1))))
|
||||||
|
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE) * 100 / $(TOTAL_BUILD_FILES)))))
|
||||||
|
@echo -e "[$(PERCENTAGE)%] $(YELLOW)Creating Static Lib $@$(RESET)"
|
||||||
|
$(Q)$(AR) rcs $@ $(CORE_OBJECTS)
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(CORE_DIR)/%.c.o: $(ROOT)/$(CORE_DIR)/%.c
|
||||||
|
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE) + 1))))
|
||||||
|
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE) * 100 / $(TOTAL_BUILD_FILES)))))
|
||||||
|
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
|
||||||
|
$(Q)$(CC) $(CFLAGS) $(CORE_INCLUDES:%=-I%) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
-include $(CORE_OBJECTS:.o=.d)
|
||||||
|
|
@ -102,11 +102,14 @@ int asset_manager_exit(void)
|
||||||
if(linked_list_exit(&game.asset_manager.assets_header_defs)) return_failure_int;
|
if(linked_list_exit(&game.asset_manager.assets_header_defs)) return_failure_int;
|
||||||
if(linked_list_exit(&game.asset_manager.assets)) return_failure_int;
|
if(linked_list_exit(&game.asset_manager.assets)) return_failure_int;
|
||||||
|
|
||||||
|
if(game.asset_manager.asset_file)
|
||||||
|
{
|
||||||
if(fclose(game.asset_manager.asset_file))
|
if(fclose(game.asset_manager.asset_file))
|
||||||
{
|
{
|
||||||
error_printf("Failed to close asset file : %d", errno);
|
error_printf("Failed to close asset file : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug_printf("Exited asset manager.");
|
debug_printf("Exited asset manager.");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
@ -16,6 +16,19 @@
|
||||||
fputc('\n', stderr); \
|
fputc('\n', stderr); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define warning_printf(...) \
|
||||||
|
do { \
|
||||||
|
fprintf(stderr, "\033[35mWARNING\033[m: " __VA_ARGS__); \
|
||||||
|
fputc('\n', stderr); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define error_printf(...) \
|
||||||
|
do { \
|
||||||
|
fprintf(stderr, "\033[31mERROR\033[m: %s:%d:%s(): ", __FILE__, __LINE__, __func__); \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
fputc('\n', stderr); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define return_failure_int \
|
#define return_failure_int \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
||||||
|
|
@ -36,11 +49,6 @@
|
||||||
#else
|
#else
|
||||||
#define debug_printf(...)
|
#define debug_printf(...)
|
||||||
|
|
||||||
#define return_failure_int return EXIT_FAILURE;
|
|
||||||
#define return_failure_ptr return NULL;
|
|
||||||
#define goto_failure goto failure;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define warning_printf(...) \
|
#define warning_printf(...) \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "\033[35mWARNING\033[m: " __VA_ARGS__); \
|
fprintf(stderr, "\033[35mWARNING\033[m: " __VA_ARGS__); \
|
||||||
|
|
@ -49,9 +57,13 @@
|
||||||
|
|
||||||
#define error_printf(...) \
|
#define error_printf(...) \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "\033[31mERROR\033[m: %s:%d:%s(): ", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "\033[31mERROR\033[m: " __VA_ARGS__); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
|
||||||
fputc('\n', stderr); \
|
fputc('\n', stderr); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define return_failure_int return EXIT_FAILURE;
|
||||||
|
#define return_failure_ptr return NULL;
|
||||||
|
#define goto_failure goto failure;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // ERRORS_H
|
#endif // ERRORS_H
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
#include "vector2d.h"
|
||||||
|
|
||||||
|
void rect_to_frect(const rect_t *rect, frect_t *frect)
|
||||||
|
{
|
||||||
|
frect->x = (float)rect->x;
|
||||||
|
frect->y = (float)rect->y;
|
||||||
|
frect->w = (float)rect->w;
|
||||||
|
frect->h = (float)rect->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
void frect_to_rect(const frect_t *frect, rect_t *rect)
|
||||||
|
{
|
||||||
|
rect->x = (int)frect->x;
|
||||||
|
rect->y = (int)frect->y;
|
||||||
|
rect->w = (int)frect->w;
|
||||||
|
rect->h = (int)frect->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool point_in_rect(const vector2d_t *p, const rect_t *r)
|
||||||
|
{
|
||||||
|
return (p && r && (p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h)));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool fpoint_in_rect(const fvector2d_t *p, const frect_t *r)
|
||||||
|
{
|
||||||
|
return (p && r && (p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h)));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool rect_empty(const rect_t *r)
|
||||||
|
{
|
||||||
|
return ((!r) || (r->w <= 0) || (r->h <= 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool frect_empty(const frect_t *r)
|
||||||
|
{
|
||||||
|
return ((!r) || (r->w <= 0) || (r->h <= 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool has_intersection(const rect_t *a, const rect_t *b)
|
||||||
|
{
|
||||||
|
int amin, amax, bmin, bmax;
|
||||||
|
|
||||||
|
// Horizontal intersection
|
||||||
|
amin = a->x;
|
||||||
|
amax = amin + a->w;
|
||||||
|
bmin = b->x;
|
||||||
|
bmax = bmin + b->w;
|
||||||
|
if(bmin > amin) amin = bmin;
|
||||||
|
if(bmax < amax) amax = bmax;
|
||||||
|
|
||||||
|
if((amax - EPSILON) < amin) return false;
|
||||||
|
|
||||||
|
// Vertical intersection
|
||||||
|
amin = a->y;
|
||||||
|
amax = amin + a->h;
|
||||||
|
bmin = b->y;
|
||||||
|
bmax = bmin + b->h;
|
||||||
|
if(bmin > amin) amin = bmin;
|
||||||
|
if(bmax < amax) amax = bmax;
|
||||||
|
|
||||||
|
if((amax - EPSILON) < amin) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool fhas_intersection(const frect_t *a, const frect_t *b)
|
||||||
|
{
|
||||||
|
float amin, amax, bmin, bmax;
|
||||||
|
|
||||||
|
// Horizontal intersection
|
||||||
|
amin = a->x;
|
||||||
|
amax = amin + a->w;
|
||||||
|
bmin = b->x;
|
||||||
|
bmax = bmin + b->w;
|
||||||
|
if(bmin > amin) amin = bmin;
|
||||||
|
if(bmax < amax) amax = bmax;
|
||||||
|
|
||||||
|
if((amax - EPSILON) < amin) return false;
|
||||||
|
|
||||||
|
// Vertical intersection
|
||||||
|
amin = a->y;
|
||||||
|
amax = amin + a->h;
|
||||||
|
bmin = b->y;
|
||||||
|
bmax = bmin + b->h;
|
||||||
|
if(bmin > amin) amin = bmin;
|
||||||
|
if(bmax < amax) amax = bmax;
|
||||||
|
|
||||||
|
if((amax - EPSILON) < amin) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool intersect_rect(const rect_t *a, const rect_t *b, rect_t *result)
|
||||||
|
{
|
||||||
|
int amin, amax, bmin, bmax;
|
||||||
|
|
||||||
|
// Horizontal intersection
|
||||||
|
amin = a->x;
|
||||||
|
amax = amin + a->w;
|
||||||
|
bmin = a->x;
|
||||||
|
bmax = bmin + a->w;
|
||||||
|
if (bmin > amin) amin = bmin;
|
||||||
|
result->x = amin;
|
||||||
|
if (bmax < amax) amax = bmax;
|
||||||
|
result->w = amax - amin;
|
||||||
|
|
||||||
|
// Vertical intersection
|
||||||
|
amin = a->y;
|
||||||
|
amax = amin + a->h;
|
||||||
|
bmin = b->y;
|
||||||
|
bmax = bmin + b->h;
|
||||||
|
if (bmin > amin) amin = bmin;
|
||||||
|
result->y = amin;
|
||||||
|
if (bmax < amax) amax = bmax;
|
||||||
|
result->h = amax - amin;
|
||||||
|
|
||||||
|
return !rect_empty(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool intersect_frect(const frect_t *a, const frect_t *b, frect_t *result)
|
||||||
|
{
|
||||||
|
float Amin, Amax, Bmin, Bmax;
|
||||||
|
|
||||||
|
// Horizontal intersection
|
||||||
|
Amin = a->x;
|
||||||
|
Amax = Amin + a->w;
|
||||||
|
Bmin = a->x;
|
||||||
|
Bmax = Bmin + a->w;
|
||||||
|
if (Bmin > Amin) {
|
||||||
|
Amin = Bmin;
|
||||||
|
}
|
||||||
|
result->x = Amin;
|
||||||
|
if (Bmax < Amax) {
|
||||||
|
Amax = Bmax;
|
||||||
|
}
|
||||||
|
result->w = Amax - Amin;
|
||||||
|
|
||||||
|
// Vertical intersection
|
||||||
|
Amin = a->y;
|
||||||
|
Amax = Amin + a->h;
|
||||||
|
Bmin = b->y;
|
||||||
|
Bmax = Bmin + b->h;
|
||||||
|
if (Bmin > Amin) {
|
||||||
|
Amin = Bmin;
|
||||||
|
}
|
||||||
|
result->y = Amin;
|
||||||
|
if (Bmax < Amax) {
|
||||||
|
Amax = Bmax;
|
||||||
|
}
|
||||||
|
result->h = Amax - Amin;
|
||||||
|
|
||||||
|
return !frect_empty(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float lerp(float a, float b, float s)
|
||||||
|
{
|
||||||
|
return a * (1 - s) + b * s;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float lerp_time(float a, float b, float s, float t)
|
||||||
|
{
|
||||||
|
return lerp(a, b, 1 - powf(1 - s, t * 60.0f));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
#ifndef VECTOR2D_H
|
||||||
|
#define VECTOR2D_H
|
||||||
|
|
||||||
|
#include <SDL3/SDL_rect.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Point struct. (int)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
*/
|
||||||
|
typedef struct vector2d_t {
|
||||||
|
int x, y;
|
||||||
|
} vector2d_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Point struct. (float)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
*/
|
||||||
|
typedef struct fvector2d_t {
|
||||||
|
float x, y;
|
||||||
|
} fvector2d_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Rectangle struct. (int)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
* @param w Width
|
||||||
|
* @param h Height
|
||||||
|
*/
|
||||||
|
typedef struct rect_t {
|
||||||
|
int x, y;
|
||||||
|
int w, h;
|
||||||
|
} rect_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Rectangle struct. (float)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
* @param w Width
|
||||||
|
* @param h Height
|
||||||
|
*/
|
||||||
|
typedef struct frect_t {
|
||||||
|
float x, y;
|
||||||
|
float w, h;
|
||||||
|
} frect_t;
|
||||||
|
|
||||||
|
#define EPSILON 0.0f
|
||||||
|
|
||||||
|
#define f_is_zero(X) (fabsf(X) <= EPSILON)
|
||||||
|
|
||||||
|
#define f_is_not_zero(X) (fabsf(X) > EPSILON)
|
||||||
|
|
||||||
|
void rect_to_frect(const rect_t *rect, frect_t *frect);
|
||||||
|
|
||||||
|
void frect_to_rect(const frect_t *frect, rect_t *rect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a point is in a rectangle. (int)
|
||||||
|
*
|
||||||
|
* @param p Vector2d
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the point is in the rectangle, else false.
|
||||||
|
*/
|
||||||
|
bool point_in_rect(const vector2d_t *p, const rect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a point is in a rectangle. (float)
|
||||||
|
*
|
||||||
|
* @param p Vector2d
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the point is in the rectangle, else false.
|
||||||
|
*/
|
||||||
|
bool fpoint_in_rect(const fvector2d_t *p, const frect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a rectangle is empty
|
||||||
|
*
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the rectangle is empty, else false.
|
||||||
|
*/
|
||||||
|
bool rect_empty(const rect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a rectangle is empty
|
||||||
|
*
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the rectangle is empty, else false.
|
||||||
|
*/
|
||||||
|
bool frect_empty(const frect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is a intersction between two rectangles. (int)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool has_intersection(const rect_t *a, const rect_t *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is a intersction between two rectangles. (float)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool fhas_intersection(const frect_t *a, const frect_t *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is an intersection between two rectangles and get the intersection rectangle. (int)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
* @param result The intersection rectangle
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool intersect_rect(const rect_t *a, const rect_t *b, rect_t *result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is an intersection between two rectangles and get the intersection rectangle. (float)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
* @param result The intersection rectangle
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool intersect_frect(const frect_t *a, const frect_t *b, frect_t *result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lerp a to b with smoothing factor s.
|
||||||
|
*
|
||||||
|
* @param a Current value
|
||||||
|
* @param b Target value
|
||||||
|
* @param s Smoothing factor
|
||||||
|
*/
|
||||||
|
float lerp(float a, float b, float s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lerp a to b with smoothing factor s and time basis t.
|
||||||
|
* Smoothing factor is for 60 fps call time.
|
||||||
|
*
|
||||||
|
* @param a Current value
|
||||||
|
* @param b Target value
|
||||||
|
* @param s Smoothing factor
|
||||||
|
* @param t Delta time
|
||||||
|
*/
|
||||||
|
float lerp_time(float a, float b, float s, float t);
|
||||||
|
|
||||||
|
#endif // VECTOR2D_H
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef DISPLAY_H
|
||||||
|
#define DISPLAY_H
|
||||||
|
|
||||||
|
#include "texture.h"
|
||||||
|
#include "vector2d.h"
|
||||||
|
|
||||||
|
#define C_BLACK 0, 0, 0
|
||||||
|
#define C_RED 255, 0, 0
|
||||||
|
#define C_GREEN 0, 255, 0
|
||||||
|
#define C_BLUE 0, 0, 255
|
||||||
|
#define C_WHITE 255, 255, 255
|
||||||
|
|
||||||
|
#define DISPLAY_WIDTH 720
|
||||||
|
#define DISPLAY_HEIGHT 480
|
||||||
|
|
||||||
|
//#define DRIVERS NULL
|
||||||
|
#define DRIVERS "vulkan,gpu,software"
|
||||||
|
|
||||||
|
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,14 @@
|
||||||
|
#ifndef TEXTURE_H
|
||||||
|
#define TEXTURE_H
|
||||||
|
|
||||||
|
#define TEXTURE_TRANSPARENT_COLOR 0x0001
|
||||||
|
|
||||||
|
typedef struct texture_t texture_t;
|
||||||
|
|
||||||
|
#define get_width(T) 1
|
||||||
|
#define get_height(T) 1
|
||||||
|
|
||||||
|
texture_t *load_texture(void);
|
||||||
|
void destroy_texture(texture_t *texture);
|
||||||
|
|
||||||
|
#endif // TEXTURE_H
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
#ifndef VECTOR2D_H
|
||||||
|
#define VECTOR2D_H
|
||||||
|
|
||||||
|
#include <SDL3/SDL_rect.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Point struct. (int)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
*/
|
||||||
|
typedef struct vector2d_t {
|
||||||
|
int x, y;
|
||||||
|
} vector2d_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Point struct. (float)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
*/
|
||||||
|
typedef struct fvector2d_t {
|
||||||
|
float x, y;
|
||||||
|
} fvector2d_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Rectangle struct. (int)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
* @param w Width
|
||||||
|
* @param h Height
|
||||||
|
*/
|
||||||
|
typedef struct rect_t {
|
||||||
|
int x, y;
|
||||||
|
int w, h;
|
||||||
|
} rect_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Rectangle struct. (float)
|
||||||
|
*
|
||||||
|
* @param x X pos
|
||||||
|
* @param y Y pos
|
||||||
|
* @param w Width
|
||||||
|
* @param h Height
|
||||||
|
*/
|
||||||
|
typedef struct frect_t {
|
||||||
|
float x, y;
|
||||||
|
float w, h;
|
||||||
|
} frect_t;
|
||||||
|
|
||||||
|
#define EPSILON 0.0f
|
||||||
|
|
||||||
|
#define f_is_zero(X) (fabsf(X) <= EPSILON)
|
||||||
|
|
||||||
|
#define f_is_not_zero(X) (fabsf(X) > EPSILON)
|
||||||
|
|
||||||
|
void rect_to_frect(const rect_t *rect, frect_t *frect);
|
||||||
|
|
||||||
|
void frect_to_rect(const frect_t *frect, rect_t *rect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a point is in a rectangle. (int)
|
||||||
|
*
|
||||||
|
* @param p Vector2d
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the point is in the rectangle, else false.
|
||||||
|
*/
|
||||||
|
bool point_in_rect(const vector2d_t *p, const rect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a point is in a rectangle. (float)
|
||||||
|
*
|
||||||
|
* @param p Vector2d
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the point is in the rectangle, else false.
|
||||||
|
*/
|
||||||
|
bool fpoint_in_rect(const fvector2d_t *p, const frect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a rectangle is empty
|
||||||
|
*
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the rectangle is empty, else false.
|
||||||
|
*/
|
||||||
|
bool rect_empty(const rect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if a rectangle is empty
|
||||||
|
*
|
||||||
|
* @param r Rectangle
|
||||||
|
*
|
||||||
|
* @return True if the rectangle is empty, else false.
|
||||||
|
*/
|
||||||
|
bool frect_empty(const frect_t *r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is a intersction between two rectangles. (int)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool has_intersection(const rect_t *a, const rect_t *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is a intersction between two rectangles. (float)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool fhas_intersection(const frect_t *a, const frect_t *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is an intersection between two rectangles and get the intersection rectangle. (int)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
* @param result The intersection rectangle
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool intersect_rect(const rect_t *a, const rect_t *b, rect_t *result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verify if there is an intersection between two rectangles and get the intersection rectangle. (float)
|
||||||
|
*
|
||||||
|
* @param A Rectangle A
|
||||||
|
* @param B Rectangle B
|
||||||
|
* @param result The intersection rectangle
|
||||||
|
*
|
||||||
|
* @return True if there is an intersection, else false.
|
||||||
|
*/
|
||||||
|
bool intersect_frect(const frect_t *a, const frect_t *b, frect_t *result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lerp a to b with smoothing factor s.
|
||||||
|
*
|
||||||
|
* @param a Current value
|
||||||
|
* @param b Target value
|
||||||
|
* @param s Smoothing factor
|
||||||
|
*/
|
||||||
|
float lerp(float a, float b, float s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lerp a to b with smoothing factor s and time basis t.
|
||||||
|
* Smoothing factor is for 60 fps call time.
|
||||||
|
*
|
||||||
|
* @param a Current value
|
||||||
|
* @param b Target value
|
||||||
|
* @param s Smoothing factor
|
||||||
|
* @param t Delta time
|
||||||
|
*/
|
||||||
|
float lerp_time(float a, float b, float s, float t);
|
||||||
|
|
||||||
|
#endif // VECTOR2D_H
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
gcc
|
||||||
|
# Headers
|
||||||
|
-Icore
|
||||||
|
-Icore/host/linux
|
||||||
|
-Isrc/components
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
CORE_SOURCES += \
|
||||||
|
$(HOST_DIR)/$(HOST)/display.c \
|
||||||
|
$(HOST_DIR)/$(HOST)/vector2d.c \
|
||||||
|
$(HOST_DIR)/$(HOST)/texture.c
|
||||||
|
|
||||||
|
CORE_INCLUDES += \
|
||||||
|
$(CORE_DIRE)
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#define DISPLAY_H
|
#define DISPLAY_H
|
||||||
|
|
||||||
#include <SDL3/SDL_render.h>
|
#include <SDL3/SDL_render.h>
|
||||||
#include "asset_manager.h"
|
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef MEMORY_ALLOC_H
|
||||||
|
#define MEMORY_ALLOC_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#endif // MEMORY_ALLOC_H
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
typedef SDL_Texture texture_t;
|
typedef SDL_Texture texture_t;
|
||||||
|
|
||||||
|
#define get_width(T) T->w
|
||||||
|
#define get_height(T) T->h
|
||||||
|
|
||||||
texture_t *load_texture(void);
|
texture_t *load_texture(void);
|
||||||
void destroy_texture(texture_t *texture);
|
void destroy_texture(texture_t *texture);
|
||||||
|
|
||||||
|
|
@ -1,13 +1,5 @@
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
void rect_to_frect(const rect_t *rect, frect_t *frect)
|
|
||||||
{
|
|
||||||
frect->x = (float)rect->x;
|
|
||||||
frect->y = (float)rect->y;
|
|
||||||
frect->w = (float)rect->w;
|
|
||||||
frect->h = (float)rect->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void frect_to_rect(const frect_t *frect, rect_t *rect)
|
void frect_to_rect(const frect_t *frect, rect_t *rect)
|
||||||
{
|
{
|
||||||
rect->x = (int)frect->x;
|
rect->x = (int)frect->x;
|
||||||
|
|
@ -40,13 +40,13 @@ typedef SDL_Rect rect_t;
|
||||||
*/
|
*/
|
||||||
typedef SDL_FRect frect_t;
|
typedef SDL_FRect frect_t;
|
||||||
|
|
||||||
#define EPSILON 0.000001f
|
#define EPSILON 0.0f
|
||||||
|
|
||||||
#define f_is_zero(X) (fabsf(X) <= EPSILON)
|
#define f_is_zero(X) (fabsf(X) <= EPSILON)
|
||||||
|
|
||||||
#define f_is_not_zero(X) (fabsf(X) > EPSILON)
|
#define f_is_not_zero(X) (fabsf(X) > EPSILON)
|
||||||
|
|
||||||
void rect_to_frect(const rect_t *rect, frect_t *frect);
|
#define rect_to_frect(R, FR) SDL_RectToFRect(R, FR)
|
||||||
|
|
||||||
void frect_to_rect(const frect_t *frect, rect_t *rect);
|
void frect_to_rect(const frect_t *frect, rect_t *rect);
|
||||||
|
|
||||||
|
|
@ -406,8 +406,8 @@ static inline int draw_tile(uint16_t tile_x, uint16_t tile_y, uint16_t tile_id)
|
||||||
if(!tile_id) return EXIT_SUCCESS;
|
if(!tile_id) return EXIT_SUCCESS;
|
||||||
|
|
||||||
rect_t src_frect = {
|
rect_t src_frect = {
|
||||||
.x = tile_id * TILE_SIZE % game.map->tileset->w,
|
.x = tile_id * TILE_SIZE % get_width(game.map->tileset),
|
||||||
.y = tile_id * TILE_SIZE / game.map->tileset->w * TILE_SIZE,
|
.y = tile_id * TILE_SIZE / get_height(game.map->tileset) * TILE_SIZE,
|
||||||
.w = TILE_SIZE,
|
.w = TILE_SIZE,
|
||||||
.h = TILE_SIZE
|
.h = TILE_SIZE
|
||||||
};
|
};
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
gcc
|
|
||||||
# Headers
|
|
||||||
-Icore/src
|
|
||||||
-Isrc/components
|
|
||||||
|
|
||||||
# Macros
|
|
||||||
-DDEBUG=2
|
|
||||||
-DASSET_FILE_NAME="$(make print-ASSET_OUTPUT)"
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
# Source files
|
|
||||||
CORE_SOURCES := \
|
|
||||||
linked_list.c \
|
|
||||||
vector2d.c \
|
|
||||||
inputs.c \
|
|
||||||
asset_manager.c \
|
|
||||||
texture.c \
|
|
||||||
map.c \
|
|
||||||
camera.c \
|
|
||||||
event_bus.c \
|
|
||||||
ecs.c \
|
|
||||||
display.c \
|
|
||||||
main.c
|
|
||||||
|
|
||||||
# Compiler and flags
|
|
||||||
CORE_CC = gcc
|
|
||||||
ifeq ($(RELEASE), 1)
|
|
||||||
CORE_CFLAGS = --std=c17 --pedantic -O3 -DASSET_FILE_NAME=\"$(notdir $(ASSET_OUTPUT))\" -D_GNU_SOURCE=1 $(shell pkg-config --cflags sdl3) # RELEASE
|
|
||||||
else
|
|
||||||
CORE_CFLAGS = --std=c17 --pedantic -O1 -g -DDEBUG=2 -DASSET_FILE_NAME=\"$(notdir $(ASSET_OUTPUT))\" -D_GNU_SOURCE=1 $(shell pkg-config --cflags sdl3) \
|
|
||||||
-Wall -Wno-missing-braces -Wextra -Wno-missing-field-initializers \
|
|
||||||
-Wformat=2 -Wswitch-default -Wswitch -Wcast-align \
|
|
||||||
-Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
|
|
||||||
-Wstrict-prototypes -Winline -Wundef -Wnested-externs \
|
|
||||||
-Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op \
|
|
||||||
-Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
|
|
||||||
-Wold-style-definition # DEVELOPEMENT
|
|
||||||
endif
|
|
||||||
|
|
||||||
CORE_INCLUDE_DIRS = $(SOURCE_DIR)/components $(CORE_DIR)
|
|
||||||
CORE_INCLUDE_DIRS := $(addprefix -I, $(CORE_INCLUDE_DIRS))
|
|
||||||
|
|
||||||
CORE_AR = ar
|
|
||||||
CORE_ARFLAGS =
|
|
||||||
|
|
||||||
# Used in final linking.
|
|
||||||
CORE_DEPS_FLAGS = $(shell pkg-config --libs sdl3) -lm
|
|
||||||
|
|
||||||
# Deduce objects
|
|
||||||
CORE_OBJECTS = $(CORE_SOURCES:%.c=$(BUILD_DIR)/$(CORE_DIR)/%.o)
|
|
||||||
|
|
||||||
# Current file nb to process
|
|
||||||
CURRENT_CORE_FILE := 0
|
|
||||||
|
|
||||||
# Build core target
|
|
||||||
build_core: core_setup count_core_build core_end
|
|
||||||
|
|
||||||
# Core build directories
|
|
||||||
core_setup:
|
|
||||||
@echo "Building $(notdir $(CORE_OUTPUT))"
|
|
||||||
$(Q)mkdir -p $(dir $(CORE_OBJECTS))
|
|
||||||
|
|
||||||
# Count nb of files to build
|
|
||||||
count_core_build:
|
|
||||||
$(eval export TOTAL_CORE_FILES := $(shell echo $$(($$(make -n $(CORE_OBJECTS) 2>/dev/null | grep -c "Building") + 1))))
|
|
||||||
|
|
||||||
# Link core target
|
|
||||||
$(CORE_OUTPUT): $(CORE_OBJECTS)
|
|
||||||
@echo -e "[100%] $(YELLOW)Linking $(notdir $(CORE_OUTPUT))$(RESET)"
|
|
||||||
$(Q)$(CORE_AR) rcs $(CORE_ARFLAGS) $@ $^
|
|
||||||
|
|
||||||
# Build .o files
|
|
||||||
$(BUILD_DIR)/$(CORE_DIR)/%.o: $(CORE_DIR)/%.c
|
|
||||||
$(eval CURRENT_CORE_FILE := $(shell echo $$(($(CURRENT_CORE_FILE)+1))))
|
|
||||||
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_CORE_FILE)*100/$(TOTAL_CORE_FILES)))))
|
|
||||||
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
|
|
||||||
$(Q)$(CORE_CC) $(CORE_CFLAGS) $(CORE_INCLUDE_DIRS) -MMD -MP -c $< -o $@
|
|
||||||
|
|
||||||
# Print ending message
|
|
||||||
core_end: $(CORE_OUTPUT)
|
|
||||||
@echo "Built target $(notdir $(CORE_OUTPUT))"
|
|
||||||
|
|
||||||
# Source files dependencies
|
|
||||||
-include $(CORE_OBJECTS:.o=.d)
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
gcc
|
gcc
|
||||||
# Headers
|
# Headers
|
||||||
-Isrc/components
|
-Isrc/components
|
||||||
-Icore/src
|
-Icore
|
||||||
|
-Icore/host/generic
|
||||||
# Macros
|
|
||||||
-DDEBUG=2
|
|
||||||
|
|
|
||||||
69
src/Makefile
69
src/Makefile
|
|
@ -1,5 +1,4 @@
|
||||||
# Source files
|
SOURCES += \
|
||||||
SOURCES := \
|
|
||||||
game.c \
|
game.c \
|
||||||
components/transform_component.c \
|
components/transform_component.c \
|
||||||
components/sprite_component.c \
|
components/sprite_component.c \
|
||||||
|
|
@ -12,61 +11,21 @@ SOURCES := \
|
||||||
components/door_component.c \
|
components/door_component.c \
|
||||||
components/lua_component.c
|
components/lua_component.c
|
||||||
|
|
||||||
# Compiler and flags
|
INCLUDES += \
|
||||||
SRC_CC = gcc
|
$(SOURCE_DIR)/components \
|
||||||
ifeq ($(RELEASE), 1)
|
$(CORE_DIR) \
|
||||||
SRC_CFLAGS = --std=c17 --pedantic -O3 # RELEASE
|
$(CORE_DIR)/$(HOST_DIR)/$(HOST)
|
||||||
|
|
||||||
SRC_LDFLAGS = -O3
|
OBJECTS := $(SOURCES:%=$(BUILD_DIR)/$(SOURCE_DIR)/%.o)
|
||||||
else
|
|
||||||
SRC_CFLAGS = --std=c17 --pedantic -O1 -g -DDEBUG=2 \
|
|
||||||
-Wall -Wno-missing-braces -Wextra -Wno-missing-field-initializers \
|
|
||||||
-Wformat=2 -Wswitch-default -Wswitch -Wcast-align \
|
|
||||||
-Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
|
|
||||||
-Wstrict-prototypes -Winline -Wundef -Wnested-externs \
|
|
||||||
-Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op \
|
|
||||||
-Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
|
|
||||||
-Wold-style-definition # DEVELOPEMENT
|
|
||||||
|
|
||||||
SRC_LDFLAGS = -O1
|
$(BUILD_DIR)/$(OUTPUT): $(BUILD_DIR)/$(LIBCORE) $(OBJECTS)
|
||||||
endif
|
@echo -e "[100%] $(YELLOW)Linking $(OUTPUT)$(RESET)"
|
||||||
|
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(BUILD_DIR)/$(LIBCORE) -o $@
|
||||||
|
|
||||||
SRC_INCLUDE_DIRS = $(SOURCE_DIR)/components $(CORE_DIR)
|
$(BUILD_DIR)/$(SOURCE_DIR)/%.c.o: $(ROOT)/$(SOURCE_DIR)/%.c
|
||||||
SRC_INCLUDE_DIRS := $(addprefix -I, $(SRC_INCLUDE_DIRS))
|
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE) + 1))))
|
||||||
|
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE) * 100 / $(TOTAL_BUILD_FILES)))))
|
||||||
# Deduce objects
|
|
||||||
SOURCE_OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/$(SOURCE_DIR)/%.o)
|
|
||||||
|
|
||||||
# Current file nb to process
|
|
||||||
CURRENT_SRC_FILE := 0
|
|
||||||
|
|
||||||
# Build src target
|
|
||||||
build_src: src_setup count_src_build src_end
|
|
||||||
|
|
||||||
# Source build directories
|
|
||||||
src_setup:
|
|
||||||
@echo "Building $(notdir $(SOURCE_OUTPUT))"
|
|
||||||
$(Q)mkdir -p $(dir $(SOURCE_OBJECTS))
|
|
||||||
|
|
||||||
# Count nb of files to build
|
|
||||||
count_src_build:
|
|
||||||
$(eval export TOTAL_SRC_FILES := $(shell echo $$(($$(make -n $(SOURCE_OBJECTS) 2>/dev/null | grep -c "Building") + 1))))
|
|
||||||
|
|
||||||
# Link game target
|
|
||||||
$(SOURCE_OUTPUT): $(SOURCE_OBJECTS) $(CORE_OUTPUT)
|
|
||||||
@echo -e "[100%] $(YELLOW)Linking $(notdir $(SOURCE_OUTPUT))$(RESET)"
|
|
||||||
$(Q)$(SRC_CC) $(SOURCE_OBJECTS) -L./$(BUILD_DIR) $(CORE_OUTPUT) -o $@ $(SRC_LDFLAGS) $(CORE_DEPS_FLAGS)
|
|
||||||
|
|
||||||
# Build .o files
|
|
||||||
$(BUILD_DIR)/$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
|
|
||||||
$(eval CURRENT_SRC_FILE := $(shell echo $$(($(CURRENT_SRC_FILE)+1))))
|
|
||||||
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_SRC_FILE)*100/$(TOTAL_SRC_FILES)))))
|
|
||||||
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
|
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
|
||||||
$(Q)$(SRC_CC) $(SRC_CFLAGS) $(SRC_INCLUDE_DIRS) -MMD -MP -c $< -o $@
|
$(Q)$(CC) $(CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
# Print ending message
|
-include $(OBJECTS:.o=.d)
|
||||||
src_end: $(SOURCE_OUTPUT)
|
|
||||||
@echo "Built target $(notdir $(SOURCE_OUTPUT))"
|
|
||||||
|
|
||||||
# Source files dependencies
|
|
||||||
-include $(SOURCE_OBJECTS:.o=.d)
|
|
||||||
|
|
|
||||||
|
|
@ -96,11 +96,11 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
|
|
||||||
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
|
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
|
||||||
const frect_t *target_hitbox_bounds = &target_hitbox_component_data->bounds;
|
const frect_t *target_hitbox_bounds = &target_hitbox_component_data->bounds;
|
||||||
frect_t intersect_frect;
|
frect_t intersect;
|
||||||
|
|
||||||
if(intersect_frect(hitbox_bounds, target_hitbox_bounds, &intersect_frect))
|
if(intersect_frect(hitbox_bounds, target_hitbox_bounds, &intersect))
|
||||||
{
|
{
|
||||||
if(intersect_frect.w < intersect_frect.h)
|
if(intersect.w < intersect.h)
|
||||||
{
|
{
|
||||||
const float left_correction = hitbox_bounds->x + hitbox_bounds->w - target_hitbox_bounds->x;
|
const float left_correction = hitbox_bounds->x + hitbox_bounds->w - target_hitbox_bounds->x;
|
||||||
const float right_correction = target_hitbox_bounds->x + target_hitbox_bounds->w - hitbox_bounds->x;
|
const float right_correction = target_hitbox_bounds->x + target_hitbox_bounds->w - hitbox_bounds->x;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue