Init, drawing walls semi-works

This commit is contained in:
Luka Jankovic 2025-06-15 17:11:20 +02:00
parent befe4a84c9
commit 09cc69d38d
8 changed files with 287 additions and 0 deletions

54
kubo_context.c Normal file
View file

@ -0,0 +1,54 @@
#include "kubo_context.h"
struct kubo_context *kubo_context_init() {
struct kubo_context *context = malloc(sizeof(struct kubo_context));
context->num_walls_alloc = KUBO_CONTEXT_NUM_WALLS_ALLOC;
context->walls =
malloc(sizeof(struct kubo_wall) * context->num_walls_alloc);
return context;
}
void kubo_context_cleanup(struct kubo_context *context) {
free(context->walls);
free(context);
}
bool kubo_context_add_wall(struct kubo_context *context,
struct kubo_wall *wall) {
struct kubo_wall **new_walls;
if (context->num_walls == context->num_walls_alloc - 1) {
context->num_walls_alloc *= 2;
new_walls = realloc(context->walls, sizeof(struct kubo_wall *) *
context->num_walls_alloc);
if (!new_walls)
return false;
context->walls = new_walls;
}
context->walls[context->num_walls++] = wall;
return true;
}
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
if (context->num_walls > 0 &&
(context->walls[context->num_walls - 1]->wall_state == KUBO_WALL_INIT ||
context->walls[context->num_walls - 1]->wall_state ==
KUBO_WALL_STARTED)) {
return context->walls[context->num_walls - 1];
}
struct kubo_wall *wall = kubo_wall_init();
kubo_context_add_wall(context, wall);
return wall;
}