Setup cammera2d and types

This commit is contained in:
n0ffie 2025-02-07 11:46:09 +01:00
parent 39abfaa978
commit fdebdd3ca2
6 changed files with 201 additions and 63 deletions

View file

@ -8,12 +8,22 @@
#define MANGLE_RES_PATH(path) ASSETS_PATH "/" path #define MANGLE_RES_PATH(path) ASSETS_PATH "/" path
#include <stdlib.h> #ifdef __cplusplus
extern "C" {
#endif
size_t init(size_t task); #include <stddef.h>
#include "types.h"
usx init(usx task);
void update(float dt); void update(float dt);
void render(float dt); void render(float dt);
#ifdef __cplusplus
}
#endif
#endif // ALYSON_HPP #endif // ALYSON_HPP

98
alyson/includes/types.h Normal file
View file

@ -0,0 +1,98 @@
//
// Created by n0ffie on 07/02/25.
//
#ifndef TYPES_H
#define TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
/*
* 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

86
alyson/src/alyson.c Normal file
View file

@ -0,0 +1,86 @@
#include <alyson.h>
#include <raylib.h>
#include <stdio.h>
#include <rlyson.h>
#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;
}

View file

@ -1,60 +0,0 @@
#include <alyson.hpp>
#include <raylib.h>
#include <iostream>
#include <string>
#include <rlyson.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){ 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;
}

View file

@ -1,6 +1,8 @@
#ifndef COLYSIS_H #ifndef COLYSIS_H
#define COLYSIS_H #define COLYSIS_H
#include <alyson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -1,6 +1,8 @@
#include <colysis.h> #include <colysis.h>
#include <iostream> #include <iostream>
#include <alyson.hpp>
#include <alyson.h>
size_t init(size_t task) { size_t init(size_t task) {
if(task == 0) if(task == 0)