kubo/kubo_wall.c

42 lines
940 B
C

#include "kubo_wall.h"
struct kubo_wall *kubo_wall_init() {
struct kubo_wall *wall = malloc(sizeof(struct kubo_wall));
if (!wall)
return NULL;
wall->num_vertices_alloc = KUBO_WALL_INIT_VERTICES;
wall->vertices = malloc(sizeof(Vector2) * wall->num_vertices_alloc);
wall->num_vertices = 0;
wall->state = KUBO_WALL_INIT;
return wall;
}
void kubo_wall_cleanup(struct kubo_wall *wall) {
free(wall->vertices);
free(wall);
}
bool kubo_wall_append(struct kubo_wall *wall, Vector2 vertex) {
Vector2 *new_vertices;
if (wall->num_vertices == wall->num_vertices_alloc - 1) {
wall->num_vertices_alloc *= 2;
new_vertices =
realloc(wall->vertices, sizeof(Vector2) * wall->num_vertices_alloc);
if (!new_vertices)
return false;
wall->vertices = new_vertices;
}
wall->vertices[wall->num_vertices++] = vertex;
return true;
}