From fdebdd3ca29c1ddc4741f4e8ff3b468cf1c3c77c Mon Sep 17 00:00:00 2001 From: n0ffie Date: Fri, 7 Feb 2025 11:46:09 +0100 Subject: [PATCH] Setup cammera2d and types --- alyson/includes/{alyson.hpp => alyson.h} | 14 +++- alyson/includes/types.h | 98 ++++++++++++++++++++++++ alyson/src/alyson.c | 86 +++++++++++++++++++++ alyson/src/alyson.cpp | 60 --------------- include/colysis.h | 2 + src/main.cpp | 4 +- 6 files changed, 201 insertions(+), 63 deletions(-) rename alyson/includes/{alyson.hpp => alyson.h} (58%) create mode 100644 alyson/includes/types.h create mode 100644 alyson/src/alyson.c delete mode 100644 alyson/src/alyson.cpp diff --git a/alyson/includes/alyson.hpp b/alyson/includes/alyson.h similarity index 58% rename from alyson/includes/alyson.hpp rename to alyson/includes/alyson.h index 357e244..1452260 100644 --- a/alyson/includes/alyson.hpp +++ b/alyson/includes/alyson.h @@ -8,12 +8,22 @@ #define MANGLE_RES_PATH(path) ASSETS_PATH "/" path -#include +#ifdef __cplusplus +extern "C" { +#endif -size_t init(size_t task); +#include + +#include "types.h" + +usx init(usx task); void update(float dt); void render(float dt); +#ifdef __cplusplus +} +#endif + #endif // ALYSON_HPP \ No newline at end of file diff --git a/alyson/includes/types.h b/alyson/includes/types.h new file mode 100644 index 0000000..3d6dc8b --- /dev/null +++ b/alyson/includes/types.h @@ -0,0 +1,98 @@ +// +// Created by n0ffie on 07/02/25. +// + +#ifndef TYPES_H +#define TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include + + /* + * Basic types + * + * u8 - unsigned 8-bit integer + * u16 - unsigned 16-bit integer + * u32 - unsigned 32-bit integer + * u64 - unsigned 64-bit integer + * + * i8 - signed 8-bit integer + * i16 - signed 16-bit integer + * i32 - signed 32-bit integer + * i64 - signed 64-bit integer + * + * f32 - 32-bit floating point number + * f64 - 64-bit floating point number + * + * usx - unsigned size_t + * isx - signed size_t + */ + typedef uint64_t u64; + typedef uint32_t u32; + typedef uint16_t u16; + typedef uint8_t u8; + + typedef int64_t i64; + typedef int32_t i32; + typedef int16_t i16; + typedef int8_t i8; + + typedef float f32; + typedef double f64; + + typedef size_t usx; + typedef ptrdiff_t isx; + + /* + * Vectors and Matrices + */ + #define ALYSON_DEFINE_VECTOR2_TYPE(type, ...) typedef struct { type x; type y; } __VA_ARGS__ + #define ALYSON_DEFINE_VECTOR3_TYPE(type, ...) typedef struct { type x; type y; type z; } __VA_ARGS__ + #define ALYSON_DEFINE_VECTOR4_TYPE(type, ...) typedef struct { type x; type y; type z; type w; } __VA_ARGS__ + + ALYSON_DEFINE_VECTOR2_TYPE(f32, vec2, vec2f); + ALYSON_DEFINE_VECTOR3_TYPE(f32, vec3, vec3f); + ALYSON_DEFINE_VECTOR4_TYPE(f32, vec4, vec4f); + + ALYSON_DEFINE_VECTOR2_TYPE(f64, vecd2); + ALYSON_DEFINE_VECTOR3_TYPE(f64, vecd3); + ALYSON_DEFINE_VECTOR4_TYPE(f64, vecd4); + + ALYSON_DEFINE_VECTOR2_TYPE(i32, veci2); + ALYSON_DEFINE_VECTOR3_TYPE(i32, veci3); + ALYSON_DEFINE_VECTOR4_TYPE(i32, veci4); + + ALYSON_DEFINE_VECTOR2_TYPE(u32, uveci2); + ALYSON_DEFINE_VECTOR3_TYPE(u32, uveci3); + ALYSON_DEFINE_VECTOR4_TYPE(u32, uveci4); + + #define ALYSON_DEFINE_MATRIX_2x2_TYPE(type, ...) typedef struct { type m00; type m01; type m10; type m11; } __VA_ARGS__ + #define ALYSON_DEFINE_MATRIX_3x3_TYPE(type, ...) typedef struct { type m00; type m01; type m02; type m10; type m11; type m12; type m20; type m21; type m22; } __VA_ARGS__ + #define ALYSON_DEFINE_MATRIX_4x4_TYPE(type, ...) typedef struct { type m00; type m01; type m02; type m03; type m10; type m11; type m12; type m13; type m20; type m21; type m22; type m23; type m30; type m31; type m32; type m33; } __VA_ARGS__ + + ALYSON_DEFINE_MATRIX_2x2_TYPE(f32, mat2, fmat2); + ALYSON_DEFINE_MATRIX_3x3_TYPE(f32, mat3, fmat3); + ALYSON_DEFINE_MATRIX_4x4_TYPE(f32, mat4, fmat4); + + ALYSON_DEFINE_MATRIX_2x2_TYPE(f64, dmat2); + ALYSON_DEFINE_MATRIX_3x3_TYPE(f64, dmat3); + ALYSON_DEFINE_MATRIX_4x4_TYPE(f64, dmat4); + + ALYSON_DEFINE_MATRIX_2x2_TYPE(i32, imat2); + ALYSON_DEFINE_MATRIX_3x3_TYPE(i32, imat3); + ALYSON_DEFINE_MATRIX_4x4_TYPE(i32, imat4); + + ALYSON_DEFINE_MATRIX_2x2_TYPE(u32, umat2); + ALYSON_DEFINE_MATRIX_3x3_TYPE(u32, umat3); + ALYSON_DEFINE_MATRIX_4x4_TYPE(u32, umat4); + +#ifdef __cplusplus +} +#endif + +#endif //TYPES_H diff --git a/alyson/src/alyson.c b/alyson/src/alyson.c new file mode 100644 index 0000000..c2e9f16 --- /dev/null +++ b/alyson/src/alyson.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#include "../../cmake-build-minsizerel/_deps/raylib-src/src/raymath.h" + +#define WINDOW_TITLE "Alyson Engine" + +int main(int argc, char *argv[]) { + + SetTargetFPS(60); + + InitWindow(900, 500, WINDOW_TITLE " -- 900x500"); + + + Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png")); + + + + Camera2D camera = { 0 }; + camera.target = (Vector2){ + (float)(GetScreenWidth()) / 2.f, + (float)(GetScreenHeight()) / 2.f + }; + camera.offset = (Vector2){ (float)(GetScreenWidth()) / 2.f, + (float)(GetScreenHeight()) / 2.f }; + camera.rotation = 0.0f; + camera.zoom = 1.0f; + + init(0); + + while (!WindowShouldClose()) { + const float dt = GetFrameTime(); + + if (IsWindowResized()) { + SetWindowTitle(TextFormat("%s -- %dx%d", WINDOW_TITLE, GetScreenWidth(), GetScreenHeight())); + } + + BeginDrawing(); + BeginMode2D(camera); + ClearBackground(RAYWHITE); + + camera.rotation += dt * 10.f; + if (camera.rotation > 360.f) { + camera.rotation -= 360.f; + } + + DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE); + DrawTextFull( + GetFontDefault(), + WINDOW_TITLE, + (Vector2) { + (float)(GetScreenWidth()) / 2.f, + (float)(GetScreenHeight()) - 60.f + }, + TEXT_ORIENTATION_CENTER, 0.f, + 40.f, 5.f, + 0.f, BLACK + ); + + update(dt); + render(dt); + + EndMode2D(); + + // log the delta time + DrawTextFull( + GetFontDefault(), + TextFormat("%.3f", dt), + (Vector2) { + 30.f, + 30.f + }, + TEXT_ORIENTATION_RIGHT, 0.0f, + 20.f, 5.f, + 0.f, BLACK + ); + + EndDrawing(); + } + + UnloadTexture(logo); + CloseWindow(); + return 0; +} diff --git a/alyson/src/alyson.cpp b/alyson/src/alyson.cpp deleted file mode 100644 index d8cb8ba..0000000 --- a/alyson/src/alyson.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include -#include - -#define WINDOW_TITLE "Alyson Engine" - -int main(int argc, char *argv[]) { - - SetTargetFPS(60); - - InitWindow(900, 500, WINDOW_TITLE " -- 900x500"); - - - Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png")); - - - Camera2D camera = { 0 }; - camera.target = (Vector2){ 0, 0 }; - camera.offset = (Vector2){ 0, 0 }; - camera.rotation = 0.0f; - camera.zoom = 1.0f; - - init(0); - - while (!WindowShouldClose()) { - float dt = GetFrameTime(); - - if (IsWindowResized()) { - SetWindowTitle((std::string(WINDOW_TITLE) + " -- " + std::to_string(GetScreenWidth()) + "x" + std::to_string(GetScreenHeight())).c_str()); - } - - BeginDrawing(); - BeginMode2D(camera); - ClearBackground(RAYWHITE); - camera.rotation += dt; - camera.rotation = (int)camera.rotation % 360; - - DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE); - DrawTextFull( - GetFontDefault(), - WINDOW_TITLE, - { GetScreenWidth() / 2.f, GetScreenHeight() - 60.f }, - TEXT_ORIENTATION_CENTER, 0.f, - 40.f, 5.f, - 0.f, BLACK - ); - - update(dt); - render(dt); - - EndMode2D(); - EndDrawing(); - } - - UnloadTexture(logo); - CloseWindow(); - return 0; -} diff --git a/include/colysis.h b/include/colysis.h index 4ba3ec6..1843995 100644 --- a/include/colysis.h +++ b/include/colysis.h @@ -1,6 +1,8 @@ #ifndef COLYSIS_H #define COLYSIS_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/main.cpp b/src/main.cpp index c499942..49b29a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include + #include -#include + +#include size_t init(size_t task) { if(task == 0)