typedef & PascalCase for ALL structs and enums

This commit is contained in:
2024-09-23 14:43:16 -03:00
parent e093a6d492
commit 73bf92e706
43 changed files with 795 additions and 793 deletions

View File

@ -8,8 +8,8 @@
#include <stb_perlin.h>
static void ingame_tick(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
static void ingame_tick(State *state) {
SceneIngame *scn = (SceneIngame *)state->scene;
world_drawdef(scn->world);
player_calc(scn->player);
@ -23,26 +23,26 @@ static void ingame_tick(struct state *state) {
const float yaw_rad = scn->yaw * (float)DEG2RAD;
const float pitch_rad = scn->pitch * (float)DEG2RAD;
scn->cam.target = m_vec_norm(((t_fvec3){
scn->cam.target = m_vec_norm(((Vec3){
cosf(yaw_rad) * cosf(pitch_rad),
sinf(pitch_rad),
sinf(yaw_rad) * cosf(pitch_rad)
}));
}
const t_fvec3 right = m_vec_norm(m_vec_cross(scn->cam.target, scn->cam.up));
const Vec3 right = m_vec_norm(m_vec_cross(scn->cam.target, scn->cam.up));
const float speed = 0.04f; /* TODO: put this in a better place */
if (input_is_action_pressed(&ctx.input, "player_left"))
scn->cam.pos = fvec3_sub(scn->cam.pos, m_vec_scale(right, speed));
scn->cam.pos = vec3_sub(scn->cam.pos, m_vec_scale(right, speed));
if (input_is_action_pressed(&ctx.input, "player_right"))
scn->cam.pos = fvec3_add(scn->cam.pos, m_vec_scale(right, speed));
scn->cam.pos = vec3_add(scn->cam.pos, m_vec_scale(right, speed));
if (input_is_action_pressed(&ctx.input, "player_forward"))
scn->cam.pos = fvec3_add(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
scn->cam.pos = vec3_add(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
if (input_is_action_pressed(&ctx.input, "player_backward"))
scn->cam.pos = fvec3_sub(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
scn->cam.pos = vec3_sub(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
if (input_is_action_pressed(&ctx.input, "player_jump"))
scn->cam.pos.y += speed;
@ -56,27 +56,27 @@ static void ingame_tick(struct state *state) {
}
m_sprite(m_set(path, "/assets/9slice.png"),
m_set(rect, ((t_frect){ 16, 16, 128, 128 })),
m_opt(texture_region, ((t_frect){ 0, 0, (float)(ctx.tick_count % 48), (float)(ctx.tick_count % 48) })));
m_set(rect, ((Rect){ 16, 16, 128, 128 })),
m_opt(texture_region, ((Rect){ 0, 0, (float)(ctx.tick_count % 48), (float)(ctx.tick_count % 48) })));
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 48, 64, 64, 64 })),
m_opt(color, ((t_color){ 255, 0, 0, 255 })));
m_set(rect, ((Rect){ 48, 64, 64, 64 })),
m_opt(color, ((Color){ 255, 0, 0, 255 })));
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 64, 64, 64, 64 })),
m_opt(color, ((t_color){ 0, 255, 0, 255 })));
m_set(rect, ((Rect){ 64, 64, 64, 64 })),
m_opt(color, ((Color){ 0, 255, 0, 255 })));
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 80, 64, 64, 64 })),
m_opt(color, ((t_color){ 0, 0, 255, 255 })));
m_set(rect, ((Rect){ 80, 64, 64, 64 })),
m_opt(color, ((Color){ 0, 0, 255, 255 })));
m_sprite(m_set(path, "/assets/player/baron-walk.png"),
m_set(rect, ((t_frect){ 32, 32, 64, 64 })),
m_set(rect, ((Rect){ 32, 32, 64, 64 })),
m_opt(rotation, (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64 ));
m_sprite(m_set(path, "/assets/player/baron-walk.png"),
m_set(rect, ((t_frect){ 128, 32, 128, 64 })),
m_set(rect, ((Rect){ 128, 32, 128, 64 })),
m_opt(rotation, (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64 ));
set_camera(&scn->cam);
@ -91,51 +91,51 @@ static void ingame_tick(struct state *state) {
float d3 = stb_perlin_noise3((float)x * TERRAIN_FREQUENCY, (float)(y - 1) * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 20 - 6;
unfurl_triangle("/assets/grass.gif",
(t_fvec3){ (float)x, d0, (float)y },
(t_fvec3){ (float)x + 1, d1, (float)y },
(t_fvec3){ (float)x, d3, (float)y - 1 },
(t_shvec2){ 1024, 768 },
(t_shvec2){ 1024, 0 },
(t_shvec2){ 0, 768 });
(Vec3){ (float)x, d0, (float)y },
(Vec3){ (float)x + 1, d1, (float)y },
(Vec3){ (float)x, d3, (float)y - 1 },
(Vec2sh){ 1024, 768 },
(Vec2sh){ 1024, 0 },
(Vec2sh){ 0, 768 });
unfurl_triangle("/assets/grass.gif",
(t_fvec3){ (float)x + 1, d1, (float)y },
(t_fvec3){ (float)x + 1, d2, (float)y - 1 },
(t_fvec3){ (float)x, d3, (float)y - 1 },
(t_shvec2){ 1024, 0 },
(t_shvec2){ 0, 0 },
(t_shvec2){ 0, 768 });
(Vec3){ (float)x + 1, d1, (float)y },
(Vec3){ (float)x + 1, d2, (float)y - 1 },
(Vec3){ (float)x, d3, (float)y - 1 },
(Vec2sh){ 1024, 0 },
(Vec2sh){ 0, 0 },
(Vec2sh){ 0, 768 });
}
}
}
static void ingame_end(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
static void ingame_end(State *state) {
SceneIngame *scn = (SceneIngame *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
free(state->scene);
}
struct scene *ingame_scene(struct state *state) {
Scene *ingame_scene(State *state) {
(void)state;
struct scene_ingame *new_scene = ccalloc(1, sizeof *new_scene);
SceneIngame *new_scene = ccalloc(1, sizeof *new_scene);
new_scene->base.tick = ingame_tick;
new_scene->base.end = ingame_end;
new_scene->world = world_create();
new_scene->player = player_create(new_scene->world);
new_scene->cam = (t_camera){ .pos = { 32, 0, 1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
new_scene->cam = (Camera){ .pos = { 32, 0, 1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
play_audio_ex("music/mod65.xm", "soundtrack", (t_play_audio_args){
audio_play_ex("music/mod65.xm", "soundtrack", (PlayAudioArgs){
.repeat = true,
.volume = 1.0f
});
input_set_mouse_captured(&ctx.input, true);
return (struct scene *)new_scene;
return (Scene *)new_scene;
}

View File

@ -9,22 +9,22 @@
#include "../world.h"
struct scene_ingame {
struct scene base;
typedef struct SceneIngame {
Scene base;
struct world *world;
struct player *player;
World *world;
Player *player;
t_camera cam;
Camera cam;
/* TODO: put this in a better place */
float yaw;
float pitch;
float roll;
};
} SceneIngame;
struct scene *ingame_scene(struct state *state);
Scene *ingame_scene(State *state);
#endif

View File

@ -2,7 +2,7 @@
#include "../state.h"
void switch_to(struct state *state, struct scene *(*scene_func)(struct state *)) {
void switch_to(State *state, Scene *(*scene_func)(State *)) {
state->next_scene = scene_func(state);
state->is_scene_switching = true;
}

View File

@ -2,15 +2,15 @@
#define SCENE_H
struct state;
struct scene {
typedef struct State State;
typedef struct Scene {
char *id;
void (*tick)(struct state *);
void (*end)(struct state *);
};
void (*tick)(State *);
void (*end)(State *);
} Scene;
void switch_to(struct state *state, struct scene *(*scene_func)(struct state *));
void switch_to(State *state, Scene *(*scene_func)(State *));
#endif

View File

@ -8,8 +8,8 @@
#include <stdio.h>
static void title_tick(struct state *state) {
struct scene_title *scn = (struct scene_title *)state->scene;
static void title_tick(State *state) {
SceneTitle *scn = (SceneTitle *)state->scene;
(void)scn;
if (input_is_action_just_pressed(&state->ctx->input, "ui_accept")) {
@ -17,7 +17,7 @@ static void title_tick(struct state *state) {
}
m_sprite("/assets/title.png", ((t_frect) {
m_sprite("/assets/title.png", ((Rect) {
((float)RENDER_BASE_WIDTH / 2) - ((float)320 / 2), 64, 320, 128 }));
@ -31,42 +31,42 @@ static void title_tick(struct state *state) {
int text_w = get_text_width(text_str, text_h, font);
push_rectangle(
(t_frect) {
(Rect) {
.x = 0,
.y = 0,
.w = (float)text_w,
.h = (float)text_h,
},
(t_color) { 0, 0, 0, 255 }
(Color) { 0, 0, 0, 255 }
);
push_text(
text_str,
(t_fvec2){ 0, 0 },
(Vec2){ 0, 0 },
text_h,
(t_color) { 255, 255, 255, 255 },
(Color) { 255, 255, 255, 255 },
font
);
free(text_str);
}
static void title_end(struct state *state) {
struct scene_title *scn = (struct scene_title *)state->scene;
static void title_end(State *state) {
SceneTitle *scn = (SceneTitle *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
free(state->scene);
}
struct scene *title_scene(struct state *state) {
Scene *title_scene(State *state) {
(void)state;
struct scene_title *new_scene = ccalloc(1, sizeof *new_scene);
SceneTitle *new_scene = ccalloc(1, sizeof *new_scene);
new_scene->base.tick = title_tick;
new_scene->base.end = title_end;
new_scene->world = world_create();
new_scene->player = player_create(new_scene->world);
return (struct scene *)new_scene;
return (Scene *)new_scene;
}

View File

@ -7,15 +7,15 @@
#include "../world.h"
struct scene_title {
struct scene base;
typedef struct SceneTitle {
Scene base;
struct world *world;
struct player *player;
};
World *world;
Player *player;
} SceneTitle;
struct scene *title_scene(struct state *state);
Scene *title_scene(State *state);
#endif