yet another api rework, removal of integer types in public api, optionals at the end, some cleaning

This commit is contained in:
veclavtalica
2024-10-29 12:25:24 +03:00
parent 6464d14b3e
commit 9121da0675
30 changed files with 191 additions and 342 deletions

View File

@ -23,14 +23,14 @@ void game_tick(void) {
State *state = ctx.udata;
input_bind_action_control("debug_toggle", CONTROL_BACKSPACE);
input_bind_action_control("debug_dump_atlases", CONTROL_HOME);
input_action("debug_toggle", CONTROL_BACKSPACE);
input_action("debug_dump_atlases", CONTROL_HOME);
if (input_is_action_just_pressed("debug_toggle")) {
if (input_action_just_pressed("debug_toggle")) {
ctx.debug = !ctx.debug;
}
if (input_is_action_just_pressed("debug_dump_atlases")) {
if (input_action_just_pressed("debug_dump_atlases")) {
textures_dump_atlases();
}

View File

@ -15,13 +15,13 @@
static void ingame_tick(State *state) {
SceneIngame *scn = (SceneIngame *)state->scene;
input_bind_action_control("player_left", CONTROL_A);
input_bind_action_control("player_right", CONTROL_D);
input_bind_action_control("player_forward", CONTROL_W);
input_bind_action_control("player_backward", CONTROL_S);
input_bind_action_control("player_jump", CONTROL_SPACE);
input_bind_action_control("player_run", CONTROL_LSHIFT);
input_bind_action_control("mouse_capture_toggle", CONTROL_ESCAPE);
input_action("player_left", CONTROL_A);
input_action("player_right", CONTROL_D);
input_action("player_forward", CONTROL_W);
input_action("player_backward", CONTROL_S);
input_action("player_jump", CONTROL_SPACE);
input_action("player_run", CONTROL_LSHIFT);
input_action("mouse_capture_toggle", CONTROL_ESCAPE);
if (scn->mouse_captured) {
const float sensitivity = 0.4f * (float)DEG2RAD; /* TODO: put this in a better place */
@ -35,36 +35,36 @@ static void ingame_tick(State *state) {
const Vec3 right = m_vec_norm(m_vec_cross(dir_and_up.direction, dir_and_up.up));
const float speed = 0.04f; /* TODO: put this in a better place */
if (input_is_action_pressed("player_left"))
if (input_action_pressed("player_left"))
scn->pos = vec3_sub(scn->pos, m_vec_scale(right, speed));
if (input_is_action_pressed("player_right"))
if (input_action_pressed("player_right"))
scn->pos = vec3_add(scn->pos, m_vec_scale(right, speed));
if (input_is_action_pressed("player_forward"))
if (input_action_pressed("player_forward"))
scn->pos = vec3_add(scn->pos, m_vec_scale(dir_and_up.direction, speed));
if (input_is_action_pressed("player_backward"))
if (input_action_pressed("player_backward"))
scn->pos = vec3_sub(scn->pos, m_vec_scale(dir_and_up.direction, speed));
if (input_is_action_pressed("player_jump"))
if (input_action_pressed("player_jump"))
scn->pos.y += speed;
if (input_is_action_pressed("player_run"))
if (input_action_pressed("player_run"))
scn->pos.y -= speed;
/* toggle mouse capture with end key */
if (input_is_action_just_pressed("mouse_capture_toggle"))
if (input_action_just_pressed("mouse_capture_toggle"))
scn->mouse_captured = !scn->mouse_captured;
input_set_mouse_captured(scn->mouse_captured);
input_mouse_captured(scn->mouse_captured);
#define TERRAIN_FREQUENCY 0.1f
for (int ly = 64; ly--;) {
for (int lx = 64; lx--;) {
float x = SDL_truncf(scn->pos.x + 32 - (float)lx);
float y = SDL_truncf(scn->pos.z + 32 - (float)ly);
for (int ly = 128; ly--;) {
for (int lx = 128; lx--;) {
float x = SDL_truncf(scn->pos.x + 64 - (float)lx);
float y = SDL_truncf(scn->pos.z + 64 - (float)ly);
float d0 = stb_perlin_noise3((float)x * TERRAIN_FREQUENCY, (float)y * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 3 - 6;
float d1 = stb_perlin_noise3((float)(x + 1) * TERRAIN_FREQUENCY, (float)y * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 3 - 6;
@ -112,7 +112,5 @@ Scene *ingame_scene(State *state) {
m_opt(channel, "soundtrack"),
m_opt(repeat, true));
input_set_mouse_captured(true);
return (Scene *)new_scene;
}

View File

@ -11,9 +11,9 @@ static void title_tick(State *state) {
SceneTitle *scn = (SceneTitle *)state->scene;
(void)scn;
input_bind_action_control("ui_accept", CONTROL_RETURN);
input_action("ui_accept", CONTROL_RETURN);
if (input_is_action_just_pressed("ui_accept")) {
if (input_action_just_pressed("ui_accept")) {
switch_to(state, ingame_scene);
return;
}
@ -22,20 +22,20 @@ static void title_tick(State *state) {
((float)ctx.resolution.x / 2) - ((float)320 / 2), 64, 320, 128 }));
/* draw the tick count as an example of dynamic text */
size_t text_str_len = snprintf(NULL, 0, "%llu", state->ctx->frame_number) + 1;
size_t text_str_len = snprintf(NULL, 0, "%llu", (unsigned long long)state->ctx->frame_number) + 1;
char *text_str = cmalloc(text_str_len);
snprintf(text_str, text_str_len, "%llu", state->ctx->frame_number);
snprintf(text_str, text_str_len, "%llu", (unsigned long long)state->ctx->frame_number);
const char *font = "/fonts/kenney-pixel.ttf";
int text_h = 32;
int text_w = draw_text_width(text_str, text_h, font);
float text_h = 32;
float text_w = draw_text_width(text_str, text_h, font);
draw_rectangle(
(Rect) {
.x = 0,
.y = 0,
.w = (float)text_w,
.h = (float)text_h,
.w = text_w,
.h = text_h,
},
(Color) { 0, 0, 0, 255 }
);