Compare commits
No commits in common. "b640791963ea0bbecf4cf700bc05348f45fb9126" and "0b5d3892dd605423c25618e1f26d8f2d2952964c" have entirely different histories.
b640791963
...
0b5d3892dd
|
|
@ -7,21 +7,20 @@
|
|||
"${workspaceFolder}/src",
|
||||
"${workspaceFolder}/src/components",
|
||||
"${workspaceFolder}/core",
|
||||
"${workspaceFolder}/core/host/linux",
|
||||
"${workspaceFolder}/core/host/generic",
|
||||
"/usr/include/lua5.4",
|
||||
"/usr/include/pipewire-0.3",
|
||||
"/usr/include/spa-0.2",
|
||||
"/usr/include/libdrm",
|
||||
"/usr/include/libdecor-0",
|
||||
"/usr/include/x86_64-linux-gnu"//,
|
||||
// "${env:HOME}/.local/share/fxsdk/sysroot/sh3eb-elf/include"
|
||||
"/usr/include/x86_64-linux-gnu",
|
||||
"${env:HOME}/.local/share/fxsdk/sysroot/sh3eb-elf/include"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"defines": [
|
||||
"_REENTRANT",
|
||||
"FXCG50",
|
||||
"TARGET_FXCG50",
|
||||
"ASSET_FILE_NAME=\"game.data\""
|
||||
"TARGET_FXCG50"
|
||||
],
|
||||
"cStandard": "c17",
|
||||
"browse": {
|
||||
|
|
|
|||
3
Makefile
3
Makefile
|
|
@ -82,6 +82,7 @@ $(ASSET_OUTPUT): FORCE
|
|||
|
||||
FORCE:
|
||||
|
||||
.PHONY: clean clean-all run print-var-%
|
||||
clean:
|
||||
$(Q)rm -rf $(BUILD_DIR)
|
||||
|
||||
|
|
@ -93,5 +94,3 @@ run: all
|
|||
|
||||
print-var-% :
|
||||
@echo $($*)
|
||||
|
||||
.PHONY: clean clean-all run print-var-%
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#
|
||||
|
||||
#
|
||||
# Project settings
|
||||
# Project settings no matter current and target hosts
|
||||
#
|
||||
|
||||
CONFIG_FILE="config.mk"
|
||||
|
|
@ -34,23 +34,19 @@ for i in "$@"; do
|
|||
TARGET_HOST="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
|
||||
--current-host=*)
|
||||
HOST="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
|
||||
--clean)
|
||||
CLEAN=1
|
||||
EXIT_AFTER_CLEAN=1
|
||||
shift
|
||||
;;
|
||||
|
||||
--reconfigure)
|
||||
CLEAN=1
|
||||
shift
|
||||
;;
|
||||
|
||||
-h|--help)
|
||||
echo "Usage : ./configure [OPTION]..."
|
||||
echo "Add submodules depending on target host platform and"
|
||||
|
|
@ -70,11 +66,9 @@ for i in "$@"; do
|
|||
echo -e "\tshow help and exit"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
-*)
|
||||
exit_error_message "Unknown option $i"
|
||||
;;
|
||||
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
|
@ -108,7 +102,7 @@ if [ "${HOST}" = "guess" ]; then
|
|||
esac
|
||||
fi
|
||||
|
||||
echo "Configuring for host: ${HOST}"
|
||||
echo "Configuring for current host: ${HOST}"
|
||||
|
||||
# If target host is guess then configure for host
|
||||
if [ "${TARGET_HOST}" = "guess" ]; then
|
||||
|
|
@ -160,16 +154,13 @@ case "${TARGET_HOST}" in
|
|||
TARGET_HOST_PKG_CONFIG=pkg-config
|
||||
TARGET_HOST_CFLAGS=(
|
||||
"--std=c17" "-Os"
|
||||
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\""
|
||||
)
|
||||
TARGET_HOST_LDFLAGS=(
|
||||
"-lm"
|
||||
"-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1"
|
||||
)
|
||||
TARGET_HOST_LDFLAGS=()
|
||||
OUTPUT_EXT=""
|
||||
DYNAMIC_LIB_OUTPUT_EXT=".so"
|
||||
STATIC_LIB_OUTPUT_EXT=".a"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet."
|
||||
;;
|
||||
|
|
@ -177,6 +168,7 @@ case "${TARGET_HOST}" in
|
|||
|
||||
TARGET_HOST_LIBS=(
|
||||
"sdl3|3.2.10"
|
||||
"lua|5.4.7"
|
||||
)
|
||||
;;
|
||||
|
||||
|
|
@ -184,7 +176,7 @@ case "${TARGET_HOST}" in
|
|||
echo "Configuring for target: ${TARGET_HOST}"
|
||||
|
||||
case "${HOST}" in
|
||||
windows|linux)
|
||||
windows)
|
||||
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
|
||||
|
|
@ -205,6 +197,7 @@ case "${TARGET_HOST}" in
|
|||
|
||||
TARGET_HOST_LIBS=(
|
||||
"sdl3|3.3.4"
|
||||
"lua|5.4.7"
|
||||
)
|
||||
;;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,6 @@ int destroy_asset(asset_t *asset)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// No args
|
||||
int create_asset_header_def(asset_header_def_t *asset_header_def, va_list args)
|
||||
{
|
||||
asset_header_def->name = NULL;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int destroy_asset_header_def(asset_header_def_t *asset_header_def)
|
||||
{
|
||||
free(asset_header_def->name);
|
||||
|
|
@ -60,7 +52,7 @@ int destroy_asset_header_def(asset_header_def_t *asset_header_def)
|
|||
int asset_manager_init(void)
|
||||
{
|
||||
linked_list_init(&game.asset_manager.assets, sizeof(asset_t), (allocator_t)create_asset, (deleter_t)destroy_asset);
|
||||
linked_list_init(&game.asset_manager.assets_header_defs, sizeof(asset_header_def_t), (allocator_t)create_asset_header_def, (deleter_t)destroy_asset_header_def);
|
||||
linked_list_init(&game.asset_manager.assets_header_defs, sizeof(asset_header_def_t), NULL, (deleter_t)destroy_asset_header_def);
|
||||
|
||||
game.asset_manager.asset_file = fopen(ASSET_FILE_NAME, "rb");
|
||||
if(!game.asset_manager.asset_file)
|
||||
|
|
@ -72,7 +64,7 @@ int asset_manager_init(void)
|
|||
uint32_t nb_assets;
|
||||
if(fread(&nb_assets, sizeof(nb_assets), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read asset file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -84,33 +76,17 @@ int asset_manager_init(void)
|
|||
if(!asset_header_def_elem) return_failure_int;
|
||||
asset_header_def_t *asset_header_def = asset_header_def_elem->data;
|
||||
|
||||
size_t cap = 0;
|
||||
|
||||
if(getdelim(&asset_header_def->name, &cap, '\0', game.asset_manager.asset_file) == -1)
|
||||
{
|
||||
size_t name_size = 0;
|
||||
int ch = EOF;
|
||||
|
||||
do
|
||||
{
|
||||
name_size++;
|
||||
|
||||
asset_header_def->name = realloc(asset_header_def->name, name_size);
|
||||
|
||||
ch = fgetc(game.asset_manager.asset_file);
|
||||
if(ch == EOF)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
asset_header_def->name[name_size - 1] = ch;
|
||||
}
|
||||
while(ch != '\0');
|
||||
|
||||
asset_header_def->name[name_size] = '\0';
|
||||
error_printf("Failed to read asset file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(fread(&asset_header_def->start, sizeof(asset_header_def->start), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read asset file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ typedef struct asset_header_def_t {
|
|||
uint32_t start;
|
||||
} asset_header_def_t;
|
||||
|
||||
int create_asset_header_def(asset_header_def_t *asset_header_def, va_list args);
|
||||
int destroy_asset_header_def(asset_header_def_t *asset_header_def);
|
||||
|
||||
typedef struct asset_manager_t {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
#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
|
||||
|
||||
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,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 MEMORY_ALLOC_H
|
||||
#define MEMORY_ALLOC_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#endif // MEMORY_ALLOC_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,6 @@
|
|||
#ifndef TIME_H
|
||||
#define TIME_H
|
||||
|
||||
void update_time(void);
|
||||
|
||||
#endif // TIME_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
|
||||
|
|
@ -7,8 +7,6 @@
|
|||
#include "texture.h"
|
||||
#include "errors.h"
|
||||
|
||||
#define DRIVERS "vulkan,gpu,software"
|
||||
|
||||
inline int display_init(void)
|
||||
{
|
||||
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
|
||||
|
|
@ -31,13 +29,13 @@ inline int display_init(void)
|
|||
}
|
||||
|
||||
#ifdef DRIVERS
|
||||
warning_printf("This build of 2D_Engine_C only innitialize for the following drivers : %s", DRIVERS);
|
||||
|
||||
debug_printf("Listing available render drivers.");
|
||||
const int NB_DRIVERS = SDL_GetNumRenderDrivers();
|
||||
for(int i = 0; i < NB_DRIVERS; i++)
|
||||
debug_printf("%d : %s", i, SDL_GetRenderDriver(i));
|
||||
|
||||
warning_printf("This build of 2D_Engine_C only support the following drivers : %s", DRIVERS);
|
||||
|
||||
game.display.renderer = SDL_CreateRenderer(game.display.window, DRIVERS);
|
||||
#else
|
||||
game.display.renderer = SDL_CreateRenderer(game.display.window, NULL);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
#define DISPLAY_WIDTH 720
|
||||
#define DISPLAY_HEIGHT 480
|
||||
|
||||
#define DRIVERS "vulkan,gpu,software"
|
||||
|
||||
typedef struct display_t {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ texture_t *load_texture(void)
|
|||
|
||||
if(fread(&width, sizeof(width), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&height, sizeof(height), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ texture_t *load_texture(void)
|
|||
|
||||
if(fread(tmp_surface->pixels, sizeof(uint16_t), width * height, game.asset_manager.asset_file) != (size_t)width * (size_t)height)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read asset file.");
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
typedef SDL_Texture texture_t;
|
||||
|
||||
#define texture_get_width(T) T->w
|
||||
#define texture_get_height(T) T->h
|
||||
#define get_width(T) T->w
|
||||
#define get_height(T) T->h
|
||||
|
||||
texture_t *load_texture(void);
|
||||
void destroy_texture(texture_t *texture);
|
||||
|
|
|
|||
|
|
@ -46,25 +46,25 @@ inline int display_init(void)
|
|||
error_printf("Failed to create renderer : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/*
|
||||
|
||||
if(!SDL_SetRenderVSync(game.display.renderer, SDL_RENDERER_VSYNC_ADAPTIVE))
|
||||
{
|
||||
error_printf("Failed to activate adaptative vsync : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
*/
|
||||
|
||||
if(!SDL_SetRenderDrawBlendMode(game.display.renderer, SDL_BLENDMODE_BLEND))
|
||||
{
|
||||
error_printf("Failed to set renderer draw blend mode : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
if(!SDL_SetDefaultTextureScaleMode(game.display.renderer, SDL_SCALEMODE_NEAREST))
|
||||
{
|
||||
error_printf("Failed to set default texture scale mode : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
*/
|
||||
debug_printf("Initialized display.");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ texture_t *load_texture(void)
|
|||
|
||||
if(fread(&width, sizeof(width), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&height, sizeof(height), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ texture_t *load_texture(void)
|
|||
|
||||
if(fread(tmp_surface->pixels, sizeof(uint16_t), width * height, game.asset_manager.asset_file) != (size_t)width * (size_t)height)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read asset file.");
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
typedef SDL_Texture texture_t;
|
||||
|
||||
#define texture_get_width(T) T->w
|
||||
#define texture_get_height(T) T->h
|
||||
#define get_width(T) T->w
|
||||
#define get_height(T) T->h
|
||||
|
||||
texture_t *load_texture(void);
|
||||
void destroy_texture(texture_t *texture);
|
||||
|
|
|
|||
58
core/map.c
58
core/map.c
|
|
@ -15,19 +15,19 @@ map_t *load_map(void)
|
|||
|
||||
if(fread(&map->width, sizeof(map->width), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&map->height, sizeof(map->height), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&map->backgroundlayernb, sizeof(map->backgroundlayernb), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ map_t *load_map(void)
|
|||
uint16_t *backgroundlayer = backgroundlayer_elem->data;
|
||||
if(fread(backgroundlayer, sizeof(*backgroundlayer), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -52,20 +52,20 @@ map_t *load_map(void)
|
|||
map->foregroundlayer = malloc(map->width * map->height * sizeof(*map->foregroundlayer));
|
||||
if(fread(map->foregroundlayer, sizeof(*map->foregroundlayer), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
map->hitboxes = malloc(map->width * map->height * sizeof(*map->hitboxes));
|
||||
if(fread(map->hitboxes, sizeof(*map->hitboxes), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&map->entities_nb, sizeof(map->entities_nb), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +77,13 @@ map_t *load_map(void)
|
|||
|
||||
if(fread(&entity_def->id, sizeof(entity_def->id), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&entity_def->components_nb, sizeof(entity_def->components_nb), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ map_t *load_map(void)
|
|||
|
||||
if(fread(&component_def->type, sizeof(component_def->type), 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -109,35 +109,19 @@ map_t *load_map(void)
|
|||
component_def->attributes = malloc(data_size);
|
||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case SPRITE_COMPONENT:
|
||||
{
|
||||
size_t name_size = 0;
|
||||
int ch = EOF;
|
||||
|
||||
do
|
||||
size_t cap = 0;
|
||||
if(getdelim((char **)&component_def->attributes, &cap, '\0', game.asset_manager.asset_file) == -1)
|
||||
{
|
||||
name_size++;
|
||||
|
||||
component_def->attributes = realloc(component_def->attributes, name_size);
|
||||
|
||||
ch = fgetc(game.asset_manager.asset_file);
|
||||
if(ch == EOF)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((uint8_t *)component_def->attributes)[name_size - 1] = ch;
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
while(ch != '\0');
|
||||
|
||||
((uint8_t *)component_def->attributes)[name_size] = '\0';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +130,7 @@ map_t *load_map(void)
|
|||
component_def->attributes = malloc(data_size);
|
||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
|
@ -156,7 +140,7 @@ map_t *load_map(void)
|
|||
component_def->attributes = malloc(data_size);
|
||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
|
@ -166,7 +150,7 @@ map_t *load_map(void)
|
|||
component_def->attributes = malloc(data_size);
|
||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
|
@ -176,7 +160,7 @@ map_t *load_map(void)
|
|||
component_def->attributes = malloc(data_size);
|
||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
||||
{
|
||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
error_printf("Failed to read in asset file : %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
|
@ -422,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;
|
||||
|
||||
rect_t src_frect = {
|
||||
.x = tile_id * TILE_SIZE % texture_get_width(game.map->tileset),
|
||||
.y = tile_id * TILE_SIZE / texture_get_width(game.map->tileset) * TILE_SIZE,
|
||||
.x = tile_id * TILE_SIZE % get_width(game.map->tileset),
|
||||
.y = tile_id * TILE_SIZE / get_width(game.map->tileset) * TILE_SIZE,
|
||||
.w = TILE_SIZE,
|
||||
.h = TILE_SIZE
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue