--wip-- [skip ci]

This commit is contained in:
2025-04-03 21:45:24 +02:00
parent 9934662d41
commit 14ec4e0022
3 changed files with 12 additions and 6 deletions

View File

@@ -5,6 +5,9 @@ clean:
compile:
gcc -W -Wall -Wextra -pedantic -o out/main src/main.c src/utils/arena.c src/utils/vector.c -Iinclude -Iutils -lpthread -Llib -lSDL3
debug:
gcc -W -Wall -Wextra -pedantic -g -O0 -o out/main_debug src/main.c src/utils/arena.c src/utils/vector.c -Iinclude -Iutils -lpthread -Llib -lSDL3
run:
make compile
./out/main

View File

@@ -1,4 +1,3 @@
#include "SDL3/SDL_stdinc.h"
#define SDL_MAIN_USE_CALLBACKS 1
#include "utils/arena.h"
#include "utils/vector.h"
@@ -44,10 +43,10 @@ typedef struct State {
static Arena arena;
#define INDEX_AT(row, col) ((row) * GRID_WIDTH + (col))
#define ROW_AT(index) (index / GRID_WIDTH)
#define COL_AT(index) (index % GRID_WIDTH)
#define SET_GRID_AT(grid, row, col, value) grid[INDEX_AT(row, col)] = value
#define GET_GRID_AT(grid, row, col) grid[INDEX_AT(row, col)]
#define ROW_AT(index) ((index) / GRID_WIDTH)
#define COL_AT(index) ((index) % GRID_WIDTH)
#define SET_GRID_AT(grid, row, col, value) (grid)[INDEX_AT((row), (col))] = (value)
#define GET_GRID_AT(grid, row, col) (grid)[INDEX_AT((row), (col))]
void log_game_grid(Uint8 *game_grid) {
char buf[GRID_WIDTH * 2];
@@ -184,7 +183,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
SDL_SetRenderDrawColor(renderer, COLOR_SNAKE);
for (int i = 0; i < playerptr->length; i++) {
int b = vector_pop(playerptr->body);
int b = playerptr->body->data[i];
rect.x = startx + ROW_AT(b) * (rect.w + GRID_PADDING);
rect.y = starty + COL_AT(b) * (rect.h + GRID_PADDING);
SDL_RenderFillRect(renderer, &rect);

View File

@@ -48,6 +48,10 @@ void vector_pusha(Vector *v, int *vals, int n) {
}
int vector_pop(Vector *v) {
if (v->size < 1) {
printf("vector_pop: popping empty vector");
return 0;
}
int val = v->data[v->size - 1];
v->size--;
return val;