From b1230534c5942501bca25a115a548dd227c31fe6 Mon Sep 17 00:00:00 2001 From: n0ffie Date: Wed, 12 Feb 2025 23:24:58 +0100 Subject: [PATCH] stuff --- .gitignore | 4 +- CMakeLists.txt | 42 ++- alyson/CMakeLists.txt | 21 ++ alyson/includes/alargs.h | 22 ++ alyson/includes/alyson.h | 44 +-- alyson/includes/animation/sprite.h | 4 +- alyson/includes/resources/alpath.h | 36 +++ alyson/includes/resources/alresource.h | 26 ++ .../includes/resources/alresource_manager.h | 0 alyson/includes/types.h | 4 +- alyson/src/alargs.c | 20 ++ alyson/src/alyson.c | 279 ------------------ alyson/src/animation/sprite.c | 13 +- alyson/src/resources/alpath.c | 210 +++++++++++++ alyson/src/resources/alresource.c | 54 ++++ alyson/src/resources/alresource_manager.c | 0 alyson/src/rlyson.c | 5 - alyson/tests/ALPath.c | 86 ------ alyson/tests/ALPath.cpp | 65 ++++ assets/gery.png | Bin 0 -> 697 bytes assets/gery_hand.png | Bin 0 -> 870 bytes src/main.c | 41 ++- 22 files changed, 547 insertions(+), 429 deletions(-) create mode 100644 alyson/includes/alargs.h create mode 100644 alyson/includes/resources/alpath.h create mode 100644 alyson/includes/resources/alresource.h create mode 100644 alyson/includes/resources/alresource_manager.h create mode 100644 alyson/src/alargs.c create mode 100644 alyson/src/resources/alpath.c create mode 100644 alyson/src/resources/alresource.c create mode 100644 alyson/src/resources/alresource_manager.c delete mode 100644 alyson/tests/ALPath.c create mode 100644 alyson/tests/ALPath.cpp create mode 100644 assets/gery.png create mode 100644 assets/gery_hand.png diff --git a/.gitignore b/.gitignore index 280a3fe..26b99e6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ bin build .cache .idea -cmake-** \ No newline at end of file +cmake-** +.kdev4 +*.kdev4 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index bd23c79..7f9094a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,23 +22,30 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Build static libraries by include(FetchContent) -# Raylib 5.5 -FetchContent_Declare( - raylib - GIT_REPOSITORY https://github.com/raysan5/raylib.git - GIT_TAG 5.5 -) -FetchContent_MakeAvailable(raylib) +# Raylib 5.5 +find_package(raylib 5.5) +if(NOT raylib_FOUND) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 5.5 + ) + + FetchContent_MakeAvailable(raylib) +endif() # Flecs -FetchContent_Declare( - flecs - GIT_REPOSITORY https://github.com/SanderMertens/flecs.git - GIT_TAG v4.0.4 -) - -FetchContent_MakeAvailable(flecs) +find_package(flecs QUIET) +if(NOT flecs_FOUND) + FetchContent_Declare( + flecs + GIT_REPOSITORY https://github.com/SanderMertens/flecs.git + GIT_TAG v4.0.4 + ) + + FetchContent_MakeAvailable(flecs) +endif() ## alyson engine (needs flecs and raylib) set(ASSETS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/assets/") @@ -69,5 +76,10 @@ target_include_directories(colysis PUBLIC include # put the assets folder path as a C preprocessor define target_compile_definitions(colysis PRIVATE ASSETS_PATH="${ASSETS_PATH}") -put_targets_into_folder(FOLDER "vendor/raylib" TARGETS raylib uninstall) + +# if the os is windows, add the uninstall target to the vendor/raylib folder +if(WIN32) + put_targets_into_folder(FOLDER "vendor/raylib" TARGETS uninstall) +endif() +put_targets_into_folder(FOLDER "vendor/raylib" TARGETS raylib) put_targets_into_folder(FOLDER "vendor/flecs" TARGETS flecs::flecs flecs::flecs_static) diff --git a/alyson/CMakeLists.txt b/alyson/CMakeLists.txt index a41b2c1..ad438af 100644 --- a/alyson/CMakeLists.txt +++ b/alyson/CMakeLists.txt @@ -26,3 +26,24 @@ target_sources(alyson PRIVATE ${alyson_src}) # set(ALYSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/alyson/include) +# google tests + +find_package(GTest QUIET) +if(NOT GTest_FOUND) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.12.1 + ) + + FetchContent_MakeAvailable(googletest) +endif() + +find_files(alyson_test_src tests cpp hpp cxx hxx c h) +add_executable(alyson_test ${alyson_test_src}) +target_link_libraries(alyson_test PRIVATE alyson) +target_link_libraries(alyson_test PRIVATE GTest::gtest) +target_link_libraries(alyson_test PRIVATE GTest::gtest_main) + +target_include_directories(alyson_test PRIVATE ${GTEST_INCLUDE_DIRS}) + diff --git a/alyson/includes/alargs.h b/alyson/includes/alargs.h new file mode 100644 index 0000000..97f08c4 --- /dev/null +++ b/alyson/includes/alargs.h @@ -0,0 +1,22 @@ +#ifndef ALARGS_H_INCLUDED +#define ALARGS_H_INCLUDED + + + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct { + int argc; + char** argv; + } alyson_args_t, *ALArgs; + + ALArgs al_args_create(int argc, char** argv); + void al_args_destroy(ALArgs args); + +#ifdef __cplusplus +} +#endif + +#endif // ALARGS_H_INCLUDED diff --git a/alyson/includes/alyson.h b/alyson/includes/alyson.h index 6e1800b..f759531 100644 --- a/alyson/includes/alyson.h +++ b/alyson/includes/alyson.h @@ -6,8 +6,6 @@ #define ASSETS_PATH "./assets/" #endif -#define MANGLE_RES_PATH(path) ASSETS_PATH "/" path - #ifdef __cplusplus extern "C" { #endif @@ -18,45 +16,19 @@ extern "C" { #define ALYSIS_ENGINE_WINDOW_TITLE "Alyson Engine" - typedef struct { - char type[4 + 1]; - char group[26 + 1]; - char* name; - char* path; - } alyson_path_t, *ALPath; +#include "alargs.h" - /* - * @function: demangle_path - * @description: Demangles a path - * @param path: path to resource - * @return: ALPath - */ - ALPath al_demangle_path(const char* path); - char* al_mangle_path(const ALPath path); - ALPath al_create_path( - const char* type, - const char* path, - const char* name, - const char* group - ); - void al_destroy_path(ALPath path); +#include "resources/alpath.h" - typedef struct { - int argc; - char** argv; - } alyson_args_t, *ALArgs; +#include "resources/alresource.h" - ALArgs al_args_create(int argc, char** argv); - void al_args_destroy(ALArgs args); + #if defined(RAYLIB_BACKEND) + #include + #include - typedef struct { - usx id; - alyson_path_t path; - } alyson_resource_t, *ALResource; + #include + #endif - ALResource al_resource_create(ALPath path); - ALResource al_resource_create_from_file(char* name, char* path); - void al_resource_destroy(ALResource resource); /* TODO : implement typedef struct { diff --git a/alyson/includes/animation/sprite.h b/alyson/includes/animation/sprite.h index 63e1629..2573a5e 100644 --- a/alyson/includes/animation/sprite.h +++ b/alyson/includes/animation/sprite.h @@ -23,7 +23,7 @@ typedef struct { float time; } sprite_animation_t, *SpriteAnimation; -SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount); +SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed); void UpdateSpriteAnimation(SpriteAnimation spriteAnimation, float dt); @@ -35,4 +35,4 @@ void DestroySpriteAnimation(SpriteAnimation spriteAnimation); } #endif -#endif // ANIMATION_SPRITE_H \ No newline at end of file +#endif // ANIMATION_SPRITE_H diff --git a/alyson/includes/resources/alpath.h b/alyson/includes/resources/alpath.h new file mode 100644 index 0000000..f070819 --- /dev/null +++ b/alyson/includes/resources/alpath.h @@ -0,0 +1,36 @@ +#ifndef ALPATH_H_INCLUDED +#define ALPATH_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif +#include "../types.h" + +typedef struct { + char type[4 + 1]; + char group[26 + 1]; + char* name; + char* path; +} alyson_path_t, *ALPath; + +/* + * @function: demangle_path + * @description: Demangles a path + * @param path: path to resource + * @return: ALPath + */ +ALPath al_demangle_path(const char* path); +char* al_mangle_path(const ALPath path); +ALPath al_create_path( + const char* type, + const char* path, + const char* name, + const char* group +); +void al_destroy_path(ALPath path); + +#ifdef __cplusplus +} +#endif + +#endif // ALPATH_H_INCLUDED diff --git a/alyson/includes/resources/alresource.h b/alyson/includes/resources/alresource.h new file mode 100644 index 0000000..056435e --- /dev/null +++ b/alyson/includes/resources/alresource.h @@ -0,0 +1,26 @@ +#ifndef ALRESOURCE_H_INCLUDED +#define ALRESOURCE_H_INCLUDED + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../types.h" +#include "alpath.h" + +typedef struct { + usx id; + alyson_path_t path; +} alyson_resource_t, *ALResource; + +ALResource al_resource_create(ALPath path); +ALResource al_resource_create_from_file(char* name, char* path); +void al_resource_destroy(ALResource resource); + + +#ifdef __cplusplus +} +#endif + +#endif // ALRESOURCE_H_INCLUDED diff --git a/alyson/includes/resources/alresource_manager.h b/alyson/includes/resources/alresource_manager.h new file mode 100644 index 0000000..e69de29 diff --git a/alyson/includes/types.h b/alyson/includes/types.h index 3d6dc8b..b15893f 100644 --- a/alyson/includes/types.h +++ b/alyson/includes/types.h @@ -12,7 +12,7 @@ extern "C" { #include #include - +#include /* * Basic types * @@ -48,6 +48,8 @@ extern "C" { typedef size_t usx; typedef ptrdiff_t isx; + typedef bool boolean; + /* * Vectors and Matrices */ diff --git a/alyson/src/alargs.c b/alyson/src/alargs.c new file mode 100644 index 0000000..c5e9ee3 --- /dev/null +++ b/alyson/src/alargs.c @@ -0,0 +1,20 @@ +#include + +#include + +/* + * ALArgs + */ +ALArgs al_args_create(int argc, char** argv) +{ + ALArgs args = malloc(sizeof(alyson_args_t)); + args->argc = argc; + args->argv = argv; + + return args; +} + +void al_args_destroy(ALArgs args) +{ + free(args); +} diff --git a/alyson/src/alyson.c b/alyson/src/alyson.c index 08b3cb5..9658144 100644 --- a/alyson/src/alyson.c +++ b/alyson/src/alyson.c @@ -1,287 +1,8 @@ #include - -#include -#include - -#include - - #include #include #include #include -/* - * ALArgs - */ -ALArgs al_args_create(int argc, char** argv) -{ - ALArgs args = malloc(sizeof(alyson_args_t)); - args->argc = argc; - args->argv = argv; - - return args; -} - -void al_args_destroy(ALArgs args) -{ - free(args); -} - -/* - * ALResource -*/ - - -ALPath al_demangle_path(const char* path) -{ - /* - * mangled path format: - * ://(/): - * - * e.g. res://test:/tests/test.png - * type: "res" - * group: "" - * name: "test" - * path: "/tests/test.png" - * - * - * demangled path format: - * .// - * - * e.g. - * type_path: res -> ./assets/ - * demangled_path: tests/test.png - * -> ./assets/tests/test.png - * - * type max length: 4 - * - * smallest possible path: ://:a (5 chars) - * - * groups max length: 26 - * groups: - * e.g. res://image/test:/tests/test.png - * type: "res" - * group: "image" - * name: "test" - * path: "/tests/test.png" - * -> ./assets/tests/test.png - */ - const ALPath res = malloc(sizeof(alyson_path_t)); - res->type[0] = '\0'; - res->group[0] = '\0'; - res->name = NULL; - res->path = NULL; - - const usx len = strlen(path); - usx back_ptr = 0; - - if (len < 5) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; too short\n", path); - al_destroy_path(res); - return NULL; - } - - // type - for (usx i = 0; i < 4; i++) - { - if (path[i] == ':') - { - res->type[i] = '\0'; - back_ptr = i + 1; - break; - } - res->type[i] = path[i]; - } - if (back_ptr == 0) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not found\n", path); - al_destroy_path(res); - return NULL; - } - - if (path[back_ptr] != '/' || path[back_ptr+1] != '/') { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not followed by '://'\n", path); - al_destroy_path(res); - return NULL; - } - back_ptr += 2; - - // group + name - for (usx i = back_ptr; i < len; i++) - { - if (path[i] == '/') - { - if (res->group[0] != '\0') - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; group already set\n", path); - al_destroy_path(res); - return NULL; - } - if (back_ptr == i) break; - strncpy(res->group, (char*)path + back_ptr, i - back_ptr); - res->group[i-back_ptr] = '\0'; - back_ptr = i + 1; - } - - if (path[i] == ':') - { - res->name = malloc(sizeof(char) * (i - back_ptr + 1)); - strncpy(res->name, (char*)path + back_ptr, i - back_ptr); - res->name[i - back_ptr] = '\0'; - back_ptr = i + 1; - break; - } - } - - // path - if (back_ptr == len) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; path not found\n", path); - al_destroy_path(res); - return NULL; - } - res->path = malloc(sizeof(char) * (len - back_ptr + 1)); - strncpy(res->path, (char*)path + back_ptr, len - back_ptr); - res->path[len - back_ptr] = '\0'; - - return res; -} - -char* al_mangle_path(const ALPath path) -{ - char* str = malloc(sizeof(char) * ( - strlen(path->type) + - strlen(path->group) + - strlen(path->name) + - strlen(path->path) + - 5 )); - if (path->group[0] != '\0') - { - sprintf(str, "%s://%s/%s:%s", path->type, path->group, path->name, path->path); - } - else - { - sprintf(str, "%s://%s:%s", path->type, path->name, path->path); - } - return str; -} - -ALPath al_create_path(const char* type, const char* path, const char* name, const char* group) -{ - const ALPath res = malloc(sizeof(alyson_path_t)); - res->type[0] = '\0'; - res->name = NULL; - res->path = NULL; - - if (type != NULL) - { - if (strlen(type) > 4) - { - fprintf(stderr, "[ALResource] Type name too long: %s\n", type); - return NULL; - } - strncpy(res->type, type, strlen(type)); - res->type[4] = '\0'; - } - - if (path != NULL) - { - res->path = strdup(path); - res->path[strlen(path)] = '\0'; - } - - if (name != NULL) - { - res->name = malloc(sizeof(char) * (strlen(name) + 1)); - strncpy(res->name, name, strlen(name)); - res->name[strlen(name)] = '\0'; - } - - if (group != NULL) - { - if (strlen(group) > 26) - { - fprintf(stderr, "[ALResource] Group name too long: %s\n", group); - al_destroy_path(res); - return NULL; - } - strncpy(res->group, group, strlen(group)); - res->group[strlen(group)] = '\0'; - } - - return res; -} - -void al_destroy_path(ALPath path) -{ - if (path->name != NULL) - { - free(path->name); - path->name = NULL; - } - if (path->path != NULL) - { - free(path->path); - path->path = NULL; - } - free(path); - path = NULL; -} - - - - - -ALResource al_resource_create(ALPath path) -{ - ALResource resource = malloc(sizeof(alyson_resource_t)); - resource->id = 0; - memcpy(&resource->path, path, sizeof(alyson_path_t)); - - return resource; -} - -ALResource al_resource_create_from_file(char* name, char* path) -{ - ALResource resource = malloc(sizeof(alyson_resource_t)); - resource->id = 0; - - usx len = strlen(path); - resource->path.path = malloc(sizeof(char) * (len + 1)); - memcpy(resource->path.path, path, sizeof(char) * len); - resource->path.path[len] = '\0'; - - memcpy(&resource->path.type, "res", 4); - resource->path.type[4] = '\0'; - - len = strlen(name); - resource->path.name = malloc(sizeof(char) * len + 1); - memcpy(resource->path.name, name, sizeof(char) * len); - resource->path.name[len] = '\0'; - - memcpy(&resource->path.group, "runtime", 7); - resource->path.group[7] = '\0'; - - return resource; -} - -void al_destroy_resource(ALResource resource) -{ - if (resource->path.name != NULL) - { - free(resource->path.name); - resource->path.name = NULL; - } - if (resource->path.path != NULL) - { - free(resource->path.path); - resource->path.path = NULL; - } - - free(resource); - resource = NULL; -} diff --git a/alyson/src/animation/sprite.c b/alyson/src/animation/sprite.c index 8dddabd..62f9a3c 100644 --- a/alyson/src/animation/sprite.c +++ b/alyson/src/animation/sprite.c @@ -4,7 +4,8 @@ #include "raylib.h" #include "raymath.h" -SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount) { +SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed) +{ SpriteAnimation spriteAnimation = malloc(sizeof(sprite_animation_t)); spriteAnimation->texture = texture; spriteAnimation->dimentions = sprite_texture_dimentions; @@ -15,7 +16,7 @@ SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_ spriteAnimation->frameCount = frameCount; spriteAnimation->currentFrame = 0; spriteAnimation->time = 0.f; - spriteAnimation->speed = 1.f; + spriteAnimation->speed = speed; return spriteAnimation; } @@ -55,4 +56,10 @@ void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) { spriteAnimation->rotation, WHITE ); -} \ No newline at end of file +} + +void DestroySpriteAnimation(SpriteAnimation spriteAnimation) +{ + free(spriteAnimation); +} + diff --git a/alyson/src/resources/alpath.c b/alyson/src/resources/alpath.c new file mode 100644 index 0000000..bf4259b --- /dev/null +++ b/alyson/src/resources/alpath.c @@ -0,0 +1,210 @@ +#include + +#include +#include +#include + + +/* + * mangled path format: + * ://(/): + * + * e.g. res://test:/tests/test.png + * type: "res" + * group: "" + * name: "test" + * path: "/tests/test.png" + * + * + * demangled path format: + * .// + * + * e.g. + * type_path: res -> ./assets/ + * demangled_path: tests/test.png + * -> ./assets/tests/test.png + * + * type max length: 4 + * + * smallest possible path: ://:a (5 chars) + * + * groups max length: 26 + * groups: + * e.g. res://image/test:/tests/test.png + * type: "res" + * group: "image" + * name: "test" + * path: "/tests/test.png" + * -> ./assets/tests/test.png + */ + + +// Path + +ALPath al_demangle_path(const char* path) +{ + + const ALPath res = malloc(sizeof(alyson_path_t)); + res->type[0] = '\0'; + res->group[0] = '\0'; + res->name = NULL; + res->path = NULL; + + const usx len = strlen(path); + usx back_ptr = 0; + + if (len < 5) + { + fprintf(stderr, "[ALResource] Invalid path: \"%s\"; too short\n", path); + al_destroy_path(res); + return NULL; + } + + // type + for (usx i = 0; i < sizeof(res->type); i++) + { + if (path[i] == ':') + { + res->type[i] = '\0'; + back_ptr = i + 1; + break; + } + res->type[i] = path[i]; + } + if (back_ptr == 0) + { + fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not found\n", path); + al_destroy_path(res); + return NULL; + } + + if (path[back_ptr] != '/' || path[back_ptr+1] != '/') { + fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not followed by '://'\n", path); + al_destroy_path(res); + return NULL; + } + back_ptr += 2; + + // group + name + for (usx i = back_ptr; i < len; i++) + { + if (path[i] == '/') + { + if (res->group[0] != '\0') + { + fprintf(stderr, "[ALResource] Invalid path: \"%s\"; group already set\n", path); + al_destroy_path(res); + return NULL; + } + if (back_ptr == i) break; + strncpy(res->group, (char*)path + back_ptr, i - back_ptr); + res->group[i-back_ptr] = '\0'; + back_ptr = i + 1; + } + + if (path[i] == ':') + { + res->name = malloc(sizeof(char) * (i - back_ptr + 1)); + strncpy(res->name, (char*)path + back_ptr, i - back_ptr); + res->name[i - back_ptr] = '\0'; + back_ptr = i + 1; + break; + } + } + + // path + if (back_ptr == len) + { + fprintf(stderr, "[ALResource] Invalid path: \"%s\"; path not found\n", path); + al_destroy_path(res); + return NULL; + } + res->path = malloc(sizeof(char) * (len - back_ptr + 1)); + strncpy(res->path, (char*)path + back_ptr, len - back_ptr); + res->path[len - back_ptr] = '\0'; + + return res; +} + +char* al_mangle_path(const ALPath path) +{ + char* str = malloc(sizeof(char) * ( + strlen(path->type) + + strlen(path->group) + + strlen(path->name) + + strlen(path->path) + + 5 )); + if (path->group[0] != '\0') + { + sprintf(str, "%s://%s/%s:%s", path->type, path->group, path->name, path->path); + } + else + { + sprintf(str, "%s://%s:%s", path->type, path->name, path->path); + } + return str; +} + +ALPath al_create_path(const char* type, const char* path, const char* name, const char* group) +{ + const ALPath res = malloc(sizeof(alyson_path_t)); + res->type[0] = '\0'; + res->name = NULL; + res->path = NULL; + + if (type != NULL) + { + if (strlen(type) > 4) + { + fprintf(stderr, "[ALResource] Type name too long: %s\n", type); + return NULL; + } + strncpy(res->type, type, strlen(type)); + res->type[4] = '\0'; + } + + if (path != NULL) + { + usx len = strlen(path); + res->path = malloc(sizeof(char) * (len + 1)); + strncpy(res->path, path, len); + res->path[len] = '\0'; + } + + if (name != NULL) + { + res->name = malloc(sizeof(char) * (strlen(name) + 1)); + strncpy(res->name, name, strlen(name)); + res->name[strlen(name)] = '\0'; + } + + if (group != NULL) + { + if (strlen(group) > 26) + { + fprintf(stderr, "[ALResource] Group name too long: %s\n", group); + al_destroy_path(res); + return NULL; + } + strncpy(res->group, group, strlen(group)); + res->group[strlen(group)] = '\0'; + } + + return res; +} + +void al_destroy_path(ALPath path) +{ + if (path->name != NULL) + { + free(path->name); + path->name = NULL; + } + if (path->path != NULL) + { + free(path->path); + path->path = NULL; + } + free(path); + path = NULL; +} diff --git a/alyson/src/resources/alresource.c b/alyson/src/resources/alresource.c new file mode 100644 index 0000000..21e305d --- /dev/null +++ b/alyson/src/resources/alresource.c @@ -0,0 +1,54 @@ +#include + +#include +#include + +ALResource al_resource_create(ALPath path) +{ + ALResource resource = malloc(sizeof(alyson_resource_t)); + resource->id = 0; + memcpy(&resource->path, path, sizeof(alyson_path_t)); + + return resource; +} + +ALResource al_resource_create_from_file(char* name, char* path) +{ + ALResource resource = malloc(sizeof(alyson_resource_t)); + resource->id = 0; + + usx len = strlen(path); + resource->path.path = malloc(sizeof(char) * (len + 1)); + memcpy(resource->path.path, path, sizeof(char) * len); + resource->path.path[len] = '\0'; + + memcpy(&resource->path.type, "res", 4); + resource->path.type[4] = '\0'; + + len = strlen(name); + resource->path.name = malloc(sizeof(char) * len + 1); + memcpy(resource->path.name, name, sizeof(char) * len); + resource->path.name[len] = '\0'; + + memcpy(&resource->path.group, "runtime", 7); + resource->path.group[7] = '\0'; + + return resource; +} + +void al_destroy_resource(ALResource resource) +{ + if (resource->path.name != NULL) + { + free(resource->path.name); + resource->path.name = NULL; + } + if (resource->path.path != NULL) + { + free(resource->path.path); + resource->path.path = NULL; + } + + free(resource); + resource = NULL; +} diff --git a/alyson/src/resources/alresource_manager.c b/alyson/src/resources/alresource_manager.c new file mode 100644 index 0000000..e69de29 diff --git a/alyson/src/rlyson.c b/alyson/src/rlyson.c index c8aa816..f72647e 100644 --- a/alyson/src/rlyson.c +++ b/alyson/src/rlyson.c @@ -18,8 +18,6 @@ void DrawTextFull( { const Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing); - DrawCircleV(origin, 10, RED); - const Vector2 pos = origin; origin = (Vector2){0,0}; @@ -37,9 +35,6 @@ void DrawTextFull( } origin.y += textSize.y / 2; - - DrawCircleV(Vector2Add(origin, pos), 10, DARKGREEN); - SetTextLineSpacing((int)lineSpacing); DrawTextPro(font, text, pos, origin, rotation, fontSize, spacing, tint); diff --git a/alyson/tests/ALPath.c b/alyson/tests/ALPath.c deleted file mode 100644 index 7973f31..0000000 --- a/alyson/tests/ALPath.c +++ /dev/null @@ -1,86 +0,0 @@ -// -// Created by n0ffie on 10/02/2025. -// - - -#include -#include - -int main(int argc, char** argv) -{ - ALPath path = al_demangle_path("res://test:/test.png"); - printf("1. %s\n", al_mangle_path(path)); - al_destroy_path(path); - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("res://image/test:/gay/test.png"); - printf("2. %s\n", al_mangle_path(path)); - al_destroy_path(path); - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("res:/test:/test.png"); - if (path != NULL) - { - printf("3. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("://test:/test.png"); - if (path != NULL) - { - printf("4. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("img://:/test.png"); - if (path != NULL) - { - printf("6. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("://:a"); - if (path != NULL) - { - printf("7. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("g://a:"); - if (path != NULL) - { - printf("8. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - path = al_demangle_path("image://gay/guy:/a/b"); - if (path != NULL) - { - printf("9. %s\n", al_mangle_path(path)); - al_destroy_path(path); - } - - fflush(stdout); - fflush(stderr); - - return 0; -} diff --git a/alyson/tests/ALPath.cpp b/alyson/tests/ALPath.cpp new file mode 100644 index 0000000..9be2ca4 --- /dev/null +++ b/alyson/tests/ALPath.cpp @@ -0,0 +1,65 @@ +// +// Created by n0ffie on 10/02/2025. +// + + +#include +#include +#include +#include + +// gtests +#include + + +bool test_path(const char* path) +{ + if (path == NULL) + return false; + + ALPath al_path = al_demangle_path(path); + if (al_path == NULL) + return false; + + if (al_path->path == NULL) + return false; + + printf("Path: %s\n", al_path->path); + + char* string = al_mangle_path(al_path); + if (strcmp(string, path) != 0) { + printf("%s : %s\n", path, string); + return false; + } + printf("\t%s\n", string); + free(string); + + al_destroy_path(al_path); + return true; +} + +void pathEQ_test(const char* string) { + ALPath al_path = al_demangle_path(string); + char* s2 = al_mangle_path(al_path); + EXPECT_STREQ(string, s2); + free(s2); + al_destroy_path(al_path); +} + + +TEST(PathEqual, normal) { + pathEQ_test("res://normal:path/this.is"); +} + +TEST(PathEqual, group_long_type) { + pathEQ_test("gays://i/love:gays/iam.one/kind.of"); +} + +TEST(PathEqual, group_type) { + pathEQ_test("g/es://this/is:shit"); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/assets/gery.png b/assets/gery.png new file mode 100644 index 0000000000000000000000000000000000000000..8cd747d7162ef861247af1d660666a8b5db187d1 GIT binary patch literal 697 zcmeAS@N?(olHy`uVBq!ia0y~yU~~Yo9XQy4WcKrQazKi)ILO_JVcj{ImkbO{#hxyX zAr*7p-r1XXIY6S}A^(v8f#jnH0;X?DFy6^U-J0 zJ-2I%{{5x=W%@n)7YsR%ZqJ%~QBdA+l6XVi-`Ue%>MyUKP~SNF<^F#AcsrgAs+BLU z@7MoZ`RjcR!#4lg?8Wi*E&rTf%0J=Rpug{R)Pcp**SFu8qVwhT`>16=mmbV-epy^n zGpYFN&6n5XHw*pR%;(TBXA<9mb(il)y#R^)1{(CP`s3zWshYB?x(nMGfabroyxi^S zqpv0ynErp&oxh&v8D=-%D=Vof`fZ%{OFeu4dcH=fU*ex5b)Idm`2O$ht;buxO#kug zd=>A8=WZvouH3k9%90gaU4P`)>;%0?wuH~_2H(o}=xzOO?zKm4ir3lW`<9p=e8OB% zWw`QD$$sy*e|x2Vuh(1u_|>Ofr@p!U?$Q4)P$JFadDV^~V*2l`1<#p3y#KzQ{jcV= z|CiR=e>Z!w#k<~9{uj@u-V0~_ZhQ;1SS|MX=E3_+7cQ)~cdB3ew|3V%!KiOK(!zi5 z_P>_j|L9k69P=G9i*GO2@1Os#PG zAr*7p-r1Wc5-!2^pr7MpP}7#(Zc&n2bA)y_iG+COMt;(bxWgoVNVh;VreURqP=)|+ zP|~FhPK`%e*S4gsWNZ8SreFE&%*Vy^+;1IvJvBXU{`;EG`vrkE;RPkT&8{@Lm)FlM z-&_Cr&zoEC)%P!pll55j?bmtL|6fzQvm(XplpY=aZht2Ez%d`GojwhUSK|I#KJ~xH z5Z=1JlkLLVFKhwTf1gjY&t!hX_5c2F`=E7BVkQk%SAnXY`Cnrw=CNnteXx4gvHd_J zP5&!AXV_g+^G#)2eVxUZtS@Pik54b;2wJi8fX*h}_L$JtNQ zEf}BNx2f-3cj(Xmb?fbGfTr2sxZT;jcW(Z@{Pz2^-hJEp<6!Qj{VB)(7yb0k`4^t} zr#ic#clr9XT79ML)t{aRFw`3V`}BOxb+#GRKla6{)n`^S2#SBUuPS(dD1BD1!{q<> z_y5y*CZ_Ope*M2V=?9PApXZ*T=2x zmqzWqxAOm=&)@4f_GCl~XT&XCwUKd+kz{YOkyLo0>Yj_CzXeOL)GKfQdH;3j1E5n1 zH*6Q)%s>CpkGGzo;RlrVoxMM`+DOXX<;a_}rA5SWKVx@7N)@qc%C}-}OY( zTfO{Q!M7CO|G)T-G5Ye|j?bHyoId|7GGT$Aa~{W}7*@O5+CAR_et-E|c*n+G`mdKI;Vst0FDr^WB>pF literal 0 HcmV?d00001 diff --git a/src/main.c b/src/main.c index 36a71fa..892cbc8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,11 +1,50 @@ #include +#define RAYLIB_BACKEND + #include #include +#include +#include + + +#include + +#include +#include + +#include + int main(int argc, char** argv) { - ALArgs args = al_args_create(argc, argv); + InitWindow(900, 600, "Colysis"); + + SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_UNDECORATED); + Texture2D gery = LoadTexture(ASSETS_PATH "/gery_hand.png"); + + SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*5,64}, (Vector2){64,64}, 0.f, 1.f, 5, 0.2f); + + while (!WindowShouldClose()) { + ClearBackground((Color){ 0x00, 0x6d, 0xfb }); + float dt = GetFrameTime(); + UpdateSpriteAnimation(geryanim, dt); + + + BeginDrawing(); + { + DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE); + + DrawSpriteAnimation(geryanim, (Vector2){GetScreenWidth()/2.f, GetScreenHeight()/2.f}); + } + + EndDrawing(); + } + + DestroySpriteAnimation(geryanim); + UnloadTexture(gery); + + return 0; }