diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index d22e7be..bfc7dfd 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -13,11 +13,14 @@ "/usr/include/spa-0.2", "/usr/include/libdrm", "/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", "defines": [ - "-D_REENTRANT" + "_REENTRANT", + "FXCG50", + "TARGET_FXCG50" ], "cStandard": "c17", "browse": { diff --git a/configure b/configure index 752a40e..a9ef698 100755 --- a/configure +++ b/configure @@ -146,8 +146,8 @@ case "${TARGET_HOST}" in linux) TARGET_HOST_CC="sh-elf-gcc" TARGET_HOST_AR="sh-elf-ar" - TARGET_HOST_CFLAGS="--std=c17 -Os" - TARGET_HOST_LDFLAGS="" + TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -DFXCG50 -DTARGET_FXCG50 -m4-nofpu" + TARGET_HOST_LDFLAGS="-T fxcg50.ld -lgint-cg -lgcc" TARGET_HOST_LIBCORE="libcore.a" ;; *) diff --git a/core/Makefile b/core/Makefile index a8ff7cd..19753d0 100644 --- a/core/Makefile +++ b/core/Makefile @@ -5,7 +5,6 @@ SOURCES += \ event_bus.c \ ecs.c \ asset_manager.c \ - inputs.c \ map.c INCLUDES += \ diff --git a/core/host/fxcg50/Makefile b/core/host/fxcg50/Makefile new file mode 100644 index 0000000..6613fbb --- /dev/null +++ b/core/host/fxcg50/Makefile @@ -0,0 +1,5 @@ +SOURCES += $(addprefix host/$(TARGET_HOST)/, \ + vector2d.c \ + inputs.c \ + update_time.c \ +) diff --git a/core/host/fxcg50/display.h b/core/host/fxcg50/display.h new file mode 100644 index 0000000..8f3e0e4 --- /dev/null +++ b/core/host/fxcg50/display.h @@ -0,0 +1,23 @@ +#ifndef DISPLAY_H +#define DISPLAY_H + +#include +#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 \ No newline at end of file diff --git a/core/host/fxcg50/inputs.c b/core/host/fxcg50/inputs.c new file mode 100644 index 0000000..5caf27b --- /dev/null +++ b/core/host/fxcg50/inputs.c @@ -0,0 +1,16 @@ +#include "inputs.h" + +#include + +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; +} diff --git a/core/inputs.h b/core/host/fxcg50/inputs.h similarity index 58% rename from core/inputs.h rename to core/host/fxcg50/inputs.h index ef2c7c7..92d1b67 100644 --- a/core/inputs.h +++ b/core/host/fxcg50/inputs.h @@ -1,16 +1,11 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include #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 { uint32_t type; - SDL_Scancode key; + int key; } input_event_t; int poll_event(input_event_t *event); diff --git a/core/host/fxcg50/keycodes.h b/core/host/fxcg50/keycodes.h new file mode 100644 index 0000000..113e16a --- /dev/null +++ b/core/host/fxcg50/keycodes.h @@ -0,0 +1,15 @@ +#ifndef KEYCODES_H +#define KEYCODES_H + +#include + +#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 \ No newline at end of file diff --git a/core/host/fxcg50/memory_alloc.h b/core/host/fxcg50/memory_alloc.h new file mode 100644 index 0000000..ef8e8b6 --- /dev/null +++ b/core/host/fxcg50/memory_alloc.h @@ -0,0 +1,6 @@ +#ifndef MEMORY_ALLOC_H +#define MEMORY_ALLOC_H + +#include + +#endif // MEMORY_ALLOC_H \ No newline at end of file diff --git a/core/host/fxcg50/texture.h b/core/host/fxcg50/texture.h new file mode 100644 index 0000000..ffa870a --- /dev/null +++ b/core/host/fxcg50/texture.h @@ -0,0 +1,16 @@ +#ifndef TEXTURE_H +#define TEXTURE_H + +#include + +#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 \ No newline at end of file diff --git a/core/host/fxcg50/update_time.c b/core/host/fxcg50/update_time.c new file mode 100644 index 0000000..c4ad525 --- /dev/null +++ b/core/host/fxcg50/update_time.c @@ -0,0 +1,13 @@ +#include "update_time.h" + +#include +#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; +} diff --git a/core/host/fxcg50/update_time.h b/core/host/fxcg50/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/fxcg50/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/host/fxcg50/vector2d.h b/core/host/fxcg50/vector2d.h index 81a5c2d..5370552 100644 --- a/core/host/fxcg50/vector2d.h +++ b/core/host/fxcg50/vector2d.h @@ -1,7 +1,7 @@ #ifndef VECTOR2D_H #define VECTOR2D_H -#include +#include #include /** diff --git a/core/host/generic/display.h b/core/host/generic/display.h index 6ab412f..a155b51 100644 --- a/core/host/generic/display.h +++ b/core/host/generic/display.h @@ -13,9 +13,6 @@ #define DISPLAY_WIDTH 720 #define DISPLAY_HEIGHT 480 -//#define DRIVERS NULL -#define DRIVERS "vulkan,gpu,software" - typedef struct display_t { } display_t; diff --git a/core/host/generic/inputs.h b/core/host/generic/inputs.h new file mode 100644 index 0000000..ac0c8d0 --- /dev/null +++ b/core/host/generic/inputs.h @@ -0,0 +1,19 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include +#include +#include "keycodes.h" + +typedef struct input_event_t { + uint32_t type; + int key; +} input_event_t; + +int poll_event(input_event_t *event); + +typedef struct inputs_t { + bool keys[MAX_KEYCODES]; +} inputs_t; + +#endif // KEYBOARD_H \ No newline at end of file diff --git a/core/host/generic/keycodes.h b/core/host/generic/keycodes.h new file mode 100644 index 0000000..2cbf8c2 --- /dev/null +++ b/core/host/generic/keycodes.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 \ No newline at end of file diff --git a/core/host/generic/update_time.h b/core/host/generic/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/generic/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/host/linux/Makefile b/core/host/linux/Makefile index 7b7c188..7961d48 100644 --- a/core/host/linux/Makefile +++ b/core/host/linux/Makefile @@ -2,4 +2,6 @@ SOURCES += $(addprefix host/$(TARGET_HOST)/, \ display.c \ vector2d.c \ texture.c \ + inputs.c \ + update_time.c \ ) diff --git a/core/inputs.c b/core/host/linux/inputs.c similarity index 100% rename from core/inputs.c rename to core/host/linux/inputs.c diff --git a/core/host/linux/inputs.h b/core/host/linux/inputs.h new file mode 100644 index 0000000..92d1b67 --- /dev/null +++ b/core/host/linux/inputs.h @@ -0,0 +1,17 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include "keycodes.h" + +typedef struct input_event_t { + uint32_t type; + int key; +} input_event_t; + +int poll_event(input_event_t *event); + +typedef struct inputs_t { + bool keys[MAX_KEYCODES]; +} inputs_t; + +#endif // KEYBOARD_H \ No newline at end of file diff --git a/core/keycodes.h b/core/host/linux/keycodes.h similarity index 71% rename from core/keycodes.h rename to core/host/linux/keycodes.h index 9783ac5..7ac90de 100644 --- a/core/keycodes.h +++ b/core/host/linux/keycodes.h @@ -12,4 +12,8 @@ #define KEY_MOD SDL_SCANCODE_LCTRL #define KEY_INTERACT SDL_SCANCODE_E +#define INPUT_EVENT_KEY_UP SDL_EVENT_KEY_UP +#define INPUT_EVENT_KEY_DOWN SDL_EVENT_KEY_DOWN +#define INPUT_EVENT_QUIT SDL_EVENT_QUIT + #endif // KEYCODES_H \ No newline at end of file diff --git a/core/host/linux/update_time.c b/core/host/linux/update_time.c new file mode 100644 index 0000000..0d74c0c --- /dev/null +++ b/core/host/linux/update_time.c @@ -0,0 +1,13 @@ +#include "update_time.h" + +#include +#include "game.h" + +inline void update_time(void) +{ + static uint32_t last_clock_state = 0; + uint64_t start_clock = SDL_GetTicksNS(); + game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state)); + if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; + last_clock_state = start_clock; +} diff --git a/core/host/linux/update_time.h b/core/host/linux/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/linux/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/main.c b/core/main.c index 09cb5b6..5020ddb 100644 --- a/core/main.c +++ b/core/main.c @@ -1,20 +1,11 @@ #include "game.h" -#include #include +#include "update_time.h" #include "errors.h" 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) { if(game_init()) goto_failure; diff --git a/src/Makefile b/src/Makefile index 4ff26f5..9753616 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ SOURCES += \ components/animation_system.c \ components/player_system.c \ components/lever_component.c \ - components/door_component.c \ + components/door_component.c# \ components/lua_component.c INCLUDES += \ diff --git a/src/components/components.def b/src/components/components.def index a00f213..9c63831 100644 --- a/src/components/components.def +++ b/src/components/components.def @@ -6,12 +6,12 @@ COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, DRAW) -COMPONENT(LUA_COMPONENT, lua_component, DRAW) +//COMPONENT(LUA_COMPONENT, lua_component, DRAW) #else COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_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 COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW) diff --git a/src/components/components.h b/src/components/components.h index 0082d1c..e15df97 100644 --- a/src/components/components.h +++ b/src/components/components.h @@ -10,7 +10,7 @@ #include "player_system.h" #include "lever_component.h" #include "door_component.h" -#include "lua_component.h" +//#include "lua_component.h" // Add new components header file here #endif // COMPONENTS_H \ No newline at end of file