From 8ea6a3c8621287d11296b8300029f32a27743d9a Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 16 Apr 2026 17:10:02 +0200 Subject: feature(checkpoint): checkpoint cleaning up base library --- .clangd | 25 +++++ Makefile | 4 +- run.sh | 8 -- source/base/base.h | 65 +++++------- source/base/base_arena.c | 17 ++-- source/base/base_arena.h | 36 +++---- source/base/base_error.h | 66 ++++++++++++ source/base/base_hash.c | 18 ---- source/base/base_include.h | 30 ++++-- source/base/base_mem.c | 17 ---- source/base/base_mem.h | 18 ++++ source/base/base_os.h | 132 ++++++++++++++++++++++++ source/base/base_parse.c | 98 ------------------ source/base/base_parse.h | 28 ----- source/base/base_platform.h | 18 ++++ source/base/base_rand.h | 29 ++++++ source/base/base_stack.c | 187 ---------------------------------- source/base/base_stack.h | 204 +++++++++++++++++++++++++++++++++++-- source/base/base_string.c | 77 ++++---------- source/base/base_string.h | 83 +++++++++++++-- source/base/base_test.c | 14 --- source/base/base_test.h | 61 ----------- source/base/bash_hash.h | 19 +++- source/core/core.c | 136 ------------------------- source/core/core.h | 5 - source/platform/platform.c | 12 --- source/platform/platform.h | 56 ---------- source/platform/platform_include.h | 7 -- source/tb/tb.c | 183 +++++++++++++++++++++++++++++++++ todo.db | Bin 12288 -> 0 bytes 30 files changed, 844 insertions(+), 809 deletions(-) create mode 100644 .clangd delete mode 100755 run.sh create mode 100644 source/base/base_error.h delete mode 100644 source/base/base_hash.c delete mode 100644 source/base/base_mem.c create mode 100644 source/base/base_os.h delete mode 100755 source/base/base_parse.c delete mode 100755 source/base/base_parse.h create mode 100644 source/base/base_platform.h create mode 100644 source/base/base_rand.h delete mode 100755 source/base/base_stack.c delete mode 100644 source/base/base_test.c delete mode 100644 source/base/base_test.h delete mode 100644 source/core/core.c delete mode 100644 source/core/core.h delete mode 100644 source/platform/platform.c delete mode 100644 source/platform/platform.h delete mode 100644 source/platform/platform_include.h create mode 100644 source/tb/tb.c delete mode 100644 todo.db diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..cff6010 --- /dev/null +++ b/.clangd @@ -0,0 +1,25 @@ +CompileFlags: + CompilationDatabase: . + Add: + - -g + - -O0 + - -I. + - -Wall + - -Wextra + - -Wno-unused-variable + - -Wno-unused-function + - -Wno-undefined-internal + - -Wno-implicit-function-declaration + - -lX11 + - -lm + + Remove: + - -O* + - -Ofast +Diagnostics: + Suppress: + - pp_file_not_found + - unused-command-line-argument + - unknown-warning-option +Index: + Background: Build diff --git a/Makefile b/Makefile index fc49e88..968ea4b 100755 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ .PHONY: all clean CC := gcc -CFLAGS := -I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable -DCORE_UNITY +CFLAGS := -I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable -Dtb_UNITY LDLIBS := -lX11 -lm BUILD_DIR := build TARGET := $(BUILD_DIR)/app -SOURCE := source/core/core.c +SOURCE := source/tb/tb.c all: $(TARGET) diff --git a/run.sh b/run.sh deleted file mode 100755 index a113e23..0000000 --- a/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -eu - -build_dir=~/projects/tb/build - -# Run -export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}:$build_dir" -"$build_dir/app" diff --git a/source/base/base.h b/source/base/base.h index 5fcf9e2..3fe9dca 100755 --- a/source/base/base.h +++ b/source/base/base.h @@ -1,34 +1,12 @@ #ifndef BASE_H #define BASE_H -#include -#include -#include -#include - /* assert an expression and output the file and the line */ - -#define internal static +#define internal static #define global_variable static -#define local_persist static - -#define ERR_OK 0 -#define ERR_IO 1 -#define ERR_PARSE 2 -#define ERR_PERM 3 -#define ERR_INVALID 4 - -#define KiB(n) (((u64)(n)) << 10) -#define MiB(n) (((u64)(n)) << 20) -#define GiB(n) (((u64)(n)) << 30) +#define local_persist static #define unused(x) (void)(x) - -#define PATH_MAX_LEN 128 -#define BUFF_SMALL 128 -#define BUFF_DEFAULT 256 -#define BUFF_LARGE 512 - #define NIL 0 #define DEPRECATED __attribute__((__deprecated__)) @@ -43,35 +21,44 @@ #define MemCpy(dest, src, len) memcpy((dest), (src), (len)) #define MemSet(dest, len) memset((dest), (0), (len)) +#if COMPILER_MSVC || (COMPILER_CLANG && OS_WINDOWS) +#pragma section(".rdata$", read) +#define read_only __declspec(allocate(".rdata$")) +#elif (COMPILER_CLANG && OS_LINUX) +#define read_only __attribute__((section(".rodata"))) +#else +#define read_only +#endif + typedef uint64_t u64; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; +typedef int64_t s64; typedef float f32; typedef double f64; -typedef i32 b32; -typedef i16 b16; -typedef u8 b8; +typedef s32 b32; +typedef s16 b16; +typedef s8 b8; typedef uintptr_t umm; typedef intptr_t smm; -#define TRUE (0 == 0) -#define FALSE (0 != 0) +#define True (1 == 1) +#define False (1 != 1) -typedef struct s8 s8; +#define Red "\x1b[31m" +#define Green "\x1b[32m" +#define Reset "\x1b[0m" +#define Blue "\x1b[34m" +#define Yellow "\x1b[33m" -struct s8 -{ - char *data; - umm size; -}; +#define Len(s) (sizeof(s) - 1) #endif diff --git a/source/base/base_arena.c b/source/base/base_arena.c index 76938bd..60133e0 100755 --- a/source/base/base_arena.c +++ b/source/base/base_arena.c @@ -30,21 +30,17 @@ arena_destroy(mem_arena *arena) { return; } - - int code = munmap(arena, arena->capacity + sizeof(mem_arena)); + munmap(arena, arena->capacity + sizeof(mem_arena)); } - internal void * -arena_alloc(mem_arena *arena, u64 size) +arena_alloc(mem_arena *arena, u64 size, b32 zero) { if (!arena) { return NULL; } - u64 aligned = Align(arena->current_position, ARENA_ALIGN); u64 new_pos = aligned + size; - if (new_pos > arena->capacity) { return NULL; @@ -55,7 +51,7 @@ arena_alloc(mem_arena *arena, u64 size) arena->previous_position = arena->current_position; arena->current_position = aligned + size; - MemSet(out, size); + if (zero) MemSet(out, size); return out; } @@ -92,7 +88,7 @@ arena_resize_align(mem_arena *arena, void *old_memory, u64 new_size, u64 old_siz if (old_memory == NULL || old_size == 0) { - return (mem_arena *)arena_alloc(arena, new_size); + return (mem_arena *)arena_alloc(arena, new_size, 0); } else if ((old_mem >= arena->base_position && old_mem < arena->base_position + arena->capacity)) { @@ -107,15 +103,16 @@ arena_resize_align(mem_arena *arena, void *old_memory, u64 new_size, u64 old_siz } else { - void *new_memory = arena_alloc(arena, new_size); + void *new_memory = arena_alloc(arena, new_size, 0); umm copy_size = old_size < new_size ? old_size : new_size; memmove(new_memory, old_mem, copy_size); } } else { - check(0); + warn(0); } + return NULL; } diff --git a/source/base/base_arena.h b/source/base/base_arena.h index 71d9e69..dc6dd73 100755 --- a/source/base/base_arena.h +++ b/source/base/base_arena.h @@ -1,14 +1,18 @@ -#ifndef ARENA_H -#define ARENA_H +#ifndef BASE_ARENA_H +#define BASE_ARENA_H #define Align(pointer, alignment) align((u64)(pointer), (umm)(alignment)) -#define PushStruct(arena, type) (type *)arena_alloc((arena), sizeof(type)) -#define PushArray(arena, type, len) (type *)arena_alloc((arena), sizeof(type) * (len)) -#define PushString(arena, len) (s8 *)arena_alloc((arena), sizeof(s8)*len)) +#define PushStruct(arena, type) (type *)arena_alloc((arena), sizeof(type), 0) +#define PushStructZero(arena, type) (type *)arena_alloc((arena), sizeof(type), 1) +#define PushArray(arena, type, len) (type *)arena_alloc((arena), sizeof(type) * (len), 0) +#define PushArrayZero(arena, type, len) (type *)arena_alloc((arena), sizeof(type) * (len), 1) -typedef struct mem_arena mem_arena; -typedef struct temp_arena temp_arena; +#define KiB(n) (((u64)(n)) << 10) +#define MiB(n) (((u64)(n)) << 20) +#define GiB(n) (((u64)(n)) << 30) + +typedef struct mem_arena mem_arena; struct mem_arena { u64 current_position; @@ -17,25 +21,11 @@ struct mem_arena u8 *base_position; }; +typedef struct temp_arena temp_arena; struct temp_arena { mem_arena *arena; u64 start_position; }; -internal mem_arena * -arena_resize_align( - mem_arena *arena, - void *old_memory, - u64 new_size, - u64 old_size, - umm alignment); - -internal mem_arena * -arena_resize( - mem_arena *arena, - void *old_memory, - u64 new_size, - u64 old_size); - -#endif +#endif /* BASE_ARENA_H */ diff --git a/source/base/base_error.h b/source/base/base_error.h new file mode 100644 index 0000000..e9f52b7 --- /dev/null +++ b/source/base/base_error.h @@ -0,0 +1,66 @@ +/* base library internal error checking system */ +#ifndef BASE_ERROR_H +#define BASE_ERROR_H + +#define error_at(msg) \ + do { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ + } while (0) + +#define warn(msg) \ + do { \ + write_string(STDERR_FD, Yellow "[WARN] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ + } while (0) + +#define assert_msg(expr, msg) \ + do { \ + if (!(expr)) { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ + _exit(1); \ + } \ + } while (0) + +#define show \ + do { \ + write_string(STDOUT_FD, __FILE__ ":"); \ + write_int(STDOUT_FD, __LINE__); \ + write_string(STDOUT_FD, ":" __func__ "\n"); \ + } while (0) + +#define test(expr) \ + do { \ + if ((expr) != 0) { \ + write_string(STDERR_FD, "[FAILED] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n"); \ + _exit(1); \ + } \ + } while (0) + +#define verify(expr) \ + do { \ + if ((expr) != 0) { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n" Reset); \ + _exit(1); \ + } else { \ + write_string(STDERR_FD, Green "[OK] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n" Reset); \ + } \ + } while (0) + +#endif /* BASE_ERROR_H */ diff --git a/source/base/base_hash.c b/source/base/base_hash.c deleted file mode 100644 index c309a9a..0000000 --- a/source/base/base_hash.c +++ /dev/null @@ -1,18 +0,0 @@ - -internal u64 -generate_hash() -{ - // TODO(nasr): - return 0; -} - -internal hash_map -make_hash_map -{ - - // TODO(nasr): - - return {0}; - -} - diff --git a/source/base/base_include.h b/source/base/base_include.h index 3f83fd7..55ef0db 100755 --- a/source/base/base_include.h +++ b/source/base/base_include.h @@ -4,27 +4,41 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include "base.h" #include "base_mem.h" + #include "base_arena.h" -#include "base_parse.h" #include "base_stack.h" -#include "base_test.h" -#if defined(TB_IMPLEMENTATION) +#include "base_string.h" +#include "base_string.c" -#include "base_mem.c" -#include "base_arena.c" -#include "base_parse.c" -#include "base_stack.c" -#include "base_test.c" +#ifdef BASE_PLATFORM +#include +#include +#include + +#include "base_platform.h" #endif +#include "base_error.h" +#include "base_os.h" + +#include "base_rand.h" + +#ifdef BASE_IMPLEMENTATION +#include "base_arena.c" +#endif + + #endif diff --git a/source/base/base_mem.c b/source/base/base_mem.c deleted file mode 100644 index f20ba39..0000000 --- a/source/base/base_mem.c +++ /dev/null @@ -1,17 +0,0 @@ -internal inline b8 -is_pow(umm x) -{ - return (x & (x - 1)) == 0; -} - -internal inline u64 -align(u64 pointer, umm alignment) -{ - if ((alignment & (alignment - 1)) == 0) - { - return pointer; - } - - return (pointer + alignment - 1) & ~(alignment - 1); -} - diff --git a/source/base/base_mem.h b/source/base/base_mem.h index 945f0ce..2778fce 100644 --- a/source/base/base_mem.h +++ b/source/base/base_mem.h @@ -5,4 +5,22 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +internal inline b8 +is_pow(umm x) +{ + return (x & (x - 1)) == 0; +} + +internal inline u64 +align(u64 pointer, umm alignment) +{ + if ((alignment & (alignment - 1)) == 0) + { + return pointer; + } + + return (pointer + alignment - 1) & ~(alignment - 1); +} + + #endif diff --git a/source/base/base_os.h b/source/base/base_os.h new file mode 100644 index 0000000..b87c946 --- /dev/null +++ b/source/base/base_os.h @@ -0,0 +1,132 @@ +#ifndef BASE_OS_H +#define BASE_OS_H + +#ifdef OS_LINUX + + +#define STDIN_FD 0 +#define STDOUT_FD 1 +#define STDERR_FD 2 + +#endif /* BASE_OS_H */ + +#ifdef BASE_IMPLEMENTATION + +internal string8 +load_file(mem_arena *arena, const char *path) +{ + string8 result = {0}; + struct stat sbuf = {0}; + + // TODO(nasr): abstract this to a platform layer + s32 file = open(path, O_RDONLY); + if(file == -1) + { + warn("fialed to open file. path could be invalid"); return (string8){0}; + } + + if(fstat(file, &sbuf) == -1) + { + warn("error: fstat failed"); + close(file); + return (string8){0}; + } + + + result = PushString8(arena, sbuf.st_size); + + result.size = (u64)sbuf.st_size; + if(result.size != 0) + { + result.data = (u8 *)mmap(0, result.size, PROT_READ, MAP_PRIVATE, file, 0); + } + + close(file); + return result; +} + +internal string8 +write_file(const char *path, string8 data) +{ + string8 result = {0}; + s32 file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if(file == -1) + { + warn("failed to open file for writing. path could be invalid"); + return (string8){0}; + } + + u64 written = 0; + while(written < data.size) + { + s64 err = write(file, data.data + written, data.size - written); + if(err == -1) + { + warn("write syscall failed"); + close(file); + return (string8){0}; + } + written += err; + } + + close(file); + result = data; + return result; +} + +#define os_write(void const *buf, u64 count) _os_write(STDIN, buf, count) +#define os_read(void const *buf, u64 count) _os_read(STDIN, buf, count) + +internal s64 +_os_write(s32 fd, void const *buf, u64 count) +{ + return syscall(SYS_write, fd, buf, count); +} + +internal s64 +_os_read(s32 fd, void *buf, u64 count) +{ + return syscall(SYS_read, fd, buf, count); +} + +internal void +print_s8(string8 s) +{ + os_write(s.data, s.size); +} + +internal void +print(const char *str) +{ + s32 len = 0; + while (str[len]) len++; + os_write(STDOUT_FILENO, str, len); + +} + +internal void +write_string(s32 fd, const char *str) +{ + s32 len = 0; + while (str[len]) len++; + os_write(fd, str, len); +} + +internal void +write_int(s32 num) +{ + + if (num < 0) + { + write(STDERR_FILENO, "-", 1); + num = -num; + } + if (num >= 10) write_int(num / 10); + + char digit = '0' + (num % 10); + + write(STDERR_FILENO, &digit, 1); +} + +#endif +#endif diff --git a/source/base/base_parse.c b/source/base/base_parse.c deleted file mode 100755 index 4f216bf..0000000 --- a/source/base/base_parse.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * is_numeric - Check if a string contains only digits - * @s: String to check - * - * Return: 1 if string contains only numeric characters, 0 otherwise - */ -internal b8 -is_numeric(char *s) -{ - for (; *s; ++s) - { - if (*s < '0' || *s > '9') - { - return 0; - } - } - return 1; -} - -/* - * TODO(nasr): checkout i think there is a buffer overflow happening somewhere - * */ -internal proc_file * -parse_proc_files(char *path, mem_arena *arena) -{ - if (!path || !arena) - { - return NULL; - } - - i32 fd = open(path, O_RDONLY); - if (fd < 0) - { - return NULL; - } - - char *buffer = PushArray(arena, char, KiB(4)); - u64 bytes = read(fd, buffer, KiB(4)); - close(fd); - - if (bytes == 0) - { - return NULL; - } - - /* guessing the count to 256 because i dont want to do a double pass of the buffer */ - proc_file *pf = PushStruct(arena, proc_file); - pf->entries = PushArray(arena, proc_entry, 256); - - u64 line_start = 0; - u64 delim = -1; - u64 entry_index = 0; - - for (u64 index = 0; index < bytes; ++index) - { - if (buffer[index] == ':' && delim == (u64)-1) - { - delim = index; - } - else if (buffer[index] == '\n') - { - if (delim != (-1.f)) - { - u64 key_len = delim - line_start; - if (key_len >= sizeof(pf->entries[entry_index].key)) - { - key_len = sizeof(pf->entries[entry_index].key) - 1; - } - - u64 val_start = delim + 1; - while (val_start < index && (buffer[val_start] == ' ' || buffer[val_start] == '\t')) - { - val_start++; - } - - u64 val_len = index - val_start; - if (val_len >= sizeof(pf->entries[entry_index].value)) - { - val_len = sizeof(pf->entries[entry_index].value) - 1; - } - - MemCpy(pf->entries[entry_index].key, buffer + line_start, key_len - 1); - MemCpy(pf->entries[entry_index].value, buffer + val_start, val_len); - - pf->entries[entry_index].key[key_len] = '\0'; - pf->entries[entry_index].value[val_len] = '\0'; - - ++pf->count; - ++entry_index; - } - - line_start = index + 1; - delim = (u64)-1; - } - } - - return (pf); -} diff --git a/source/base/base_parse.h b/source/base/base_parse.h deleted file mode 100755 index d66fd04..0000000 --- a/source/base/base_parse.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef BASE_PARSE_H -#define BASE_PARSE_H - -#define COMPARE_STRING(c1, c2) compare_string((char *)c1, (char *)c2) - -typedef struct proc_entry proc_entry; -typedef struct proc_file proc_file; - -struct proc_file -{ - i32 count; - proc_entry *entries; -}; - -struct proc_entry -{ - char value[16]; - char key[16]; -}; - -typedef struct -{ - i8 *start; - i8 *end; - umm len; -} Line; - -#endif diff --git a/source/base/base_platform.h b/source/base/base_platform.h new file mode 100644 index 0000000..91cd55d --- /dev/null +++ b/source/base/base_platform.h @@ -0,0 +1,18 @@ +#ifndef BASE_PLATFORM_H +#define BASE_PLATFORM_H + +#ifdef BASE_PLATFORM_IMPLEMENTATION +internal inline void +sleep_ms(long ms) +{ + struct timespec ts; + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000L; + + while (nanosleep(&ts, &ts)) + { + NULL; + } +} +#endif /* BASE_PLATFORM_IMPLEMENTATION */ +#endif /* BASE_PLATFORM_H */ diff --git a/source/base/base_rand.h b/source/base/base_rand.h new file mode 100644 index 0000000..86acafe --- /dev/null +++ b/source/base/base_rand.h @@ -0,0 +1,29 @@ +#ifndef BASE_RAND_H +#define BASE_RAND_H + +// source: https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64 + +#define RAND_CONSTANT 6364136223846793005 +#define GEN_RAND() _generate_random_u64(RAND_CONSTANT) + +#endif /* BASE_RAND_H */ + +#ifdef BASE_RAND_IMPLEMENTATION +internal u64 +generate_random_u64(u64 constant) +{ + + time_t current_time = time(NULL); + return current_time ^ constant; + + constant += 0x9e3779b97f4a7c15; + + u64 z = constant; + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; + z = (z ^ (z >> 27)) * 0x94d049bb133111eb; + z = z ^ (z >> 31); + + return z; +} + +#endif diff --git a/source/base/base_stack.c b/source/base/base_stack.c deleted file mode 100755 index 7cf0570..0000000 --- a/source/base/base_stack.c +++ /dev/null @@ -1,187 +0,0 @@ -internal mem_stack * -stack_create(u64 capacity) -{ - mem_stack *stack = (mem_stack *)mmap( - 0, - capacity + sizeof(mem_stack), - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, - -1, - 0); - - if (stack == MAP_FAILED) - { - return NULL; - } - - stack->capacity = capacity; - stack->base_position = (u8 *)stack + sizeof(mem_stack); - stack->current_offset = 0; - - return stack; -} - -internal umm -calculate_padding(umm pointer, umm alignment, umm header_size) -{ - umm modulo, padding; - - if (!is_pow(alignment)) - { - return 0; - } - - modulo = pointer & (alignment - 1); - - padding = 0; - - if (0 == modulo) - { - padding = alignment - modulo; - } - - if (padding < header_size) - { - header_size -= padding; - - if ((header_size & (alignment - 1)) != 0) - { - padding += alignment * (1 + (header_size / alignment)); - } - else - { - padding += alignment * (header_size / alignment); - } - } - - return padding; -} - -internal mem_stack * -stack_push_align(mem_stack *stack, u64 size, umm alignment) -{ - umm padding = 0; - - if (!is_pow(alignment)) - { - return (0); - } - - if (alignment > 128) - { - alignment = 128; - } - - umm current_address = (umm)stack->base_position + stack->current_offset; - padding = calculate_padding(current_address, alignment, sizeof(mem_stack_header)); - - if (stack->current_offset + padding + size > stack->capacity) - { - return 0; - } - - stack->current_offset += padding; - - umm next_address = current_address + (umm)padding; - mem_stack_header *header = (mem_stack_header *)(next_address - sizeof(mem_stack_header)); - header->padding = padding; - - stack->current_offset += size; - - return MemSet((void *)next_address, size); -} -internal void * -stack_push(mem_stack *stack, umm size) -{ - return stack_push_align(stack, size, ARENA_ALIGN); -} - -internal void -stack_pop(mem_stack *stack, void *pointer) -{ - if (pointer != NULL) - { - umm start, end, current_address; - mem_stack_header *header; - umm prev_offset; - - start = (umm)stack->base_position; - end = start + (umm)stack->capacity; - current_address = (umm)pointer; - - if (!(start <= current_address && current_address < end)) - { - if (0 && "Out of bounds memory address passed to stack allocator (free)") - { - return; - } - return; - } - - if (current_address >= start + (umm)stack->base_position) - { - return; - } - - header = (mem_stack_header *)(current_address - sizeof(mem_stack_header)); - prev_offset = (size_t)(current_address - (umm)header->padding - start); - stack->current_offset = prev_offset; - } -} - -internal mem_stack * -stack_resize_align(mem_stack *stack, void *pointer, u64 old_size, u64 new_size, u64 alignment) -{ - if (pointer == NULL) - { - return stack_push_align(stack, new_size, alignment); - } - else if (new_size == 0) - { - stack_pop(stack, pointer); - return NULL; - } - - umm start, end, current_address; - umm min_size = old_size < new_size ? old_size : new_size; - void *new_pointer; - - start = (umm)stack->base_position; - end = start + (umm)stack->capacity; - current_address = (umm)pointer; - if (!(start <= current_address && current_address < end)) - { - return NULL; - } - - if (current_address >= start + (umm)stack->current_offset) - { - return NULL; - } - - if (old_size == new_size) - { - return pointer; - } - - new_pointer = stack_push_align(stack, new_size, alignment); - memmove(new_pointer, pointer, min_size); - return new_pointer; -} - -internal void -stack_pop_all(mem_stack *stack) -{ - stack->current_offset = 0; -} - -internal void -stack_destroy(mem_stack *stack) -{ - if (!stack) - { - return; - } - - munmap(stack, stack->capacity + sizeof(mem_stack)); -} diff --git a/source/base/base_stack.h b/source/base/base_stack.h index fc80b20..43a7230 100755 --- a/source/base/base_stack.h +++ b/source/base/base_stack.h @@ -1,20 +1,210 @@ #ifndef STACK_H #define STACK_H -typedef struct mem_stack mem_stack; typedef struct mem_stack_header mem_stack_header; +struct mem_stack_header +{ + u8 padding; + u8 previous_offset; +}; + +typedef struct mem_stack mem_stack; struct mem_stack { + mem_stack_header *header; + + u64 current_offset; + u64 capacity; u8 *base_position; - umm current_offset; - umm capacity; }; -struct mem_stack_header +internal mem_stack * +stack_create(u64 capacity) { - u8 padding; - u8 previous_offset; -}; + mem_stack *stack = (mem_stack *)mmap( + 0, + capacity + sizeof(mem_stack), + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, + -1, + 0); + + if (stack == MAP_FAILED) + { + return NULL; + } + + stack->capacity = capacity; + stack->base_position = (u8 *)stack + sizeof(mem_stack); + stack->current_offset = 0; + + return stack; +} + +internal u8 +calculate_padding(u64 pointer, u8 alignment, u64 header_size) +{ + u8 modulo, padding; + + if (!is_pow(alignment)) + { + return 0; + } + + modulo = pointer & (u8)(alignment - 1); + + padding = 0; + + if (0 == modulo) + { + padding = alignment - modulo; + } + + if (padding < header_size) + { + header_size -= padding; + + if ((header_size & (alignment - 1)) != 0) + { + padding += alignment * (1 + (header_size / alignment)); + } + else + { + padding += alignment * (header_size / alignment); + } + } + + return padding; +} + +internal mem_stack * +stack_push_align(mem_stack *stack, u64 size, u8 alignment) +{ + u8 padding = 0; + + if (!is_pow(alignment)) + { + return (0); + } + + if (alignment > 128) + { + alignment = 128; + } + + u64 current_address = (u64)stack->base_position + stack->current_offset; + padding = calculate_padding(current_address, alignment, sizeof(mem_stack_header)); + + if (stack->current_offset + padding + size > stack->capacity) + { + return 0; + } + + stack->current_offset += padding; + + u64 next_address = current_address + (u64)padding; + mem_stack_header *header = (mem_stack_header *)(next_address - sizeof(mem_stack_header)); + header->padding = padding; + + stack->current_offset += size; + + return MemSet((void *)next_address, size); +} +internal void * +stack_push(mem_stack *stack, u64 size) +{ + return stack_push_align(stack, size, ARENA_ALIGN); +} + +internal void +stack_pop(mem_stack *stack, void *pointer) +{ + if (pointer != NULL) + { + u64 start, end, current_address; + mem_stack_header *header; + u64 prev_offset; + + start = (u64)stack->base_position; + end = start + (u64)stack->capacity; + current_address = (u64)pointer; + + if (!(start <= current_address && current_address < end)) + { + if (0 && "Out of bounds memory address passed to stack allocator (free)") + { + return; + } + return; + } + + if (current_address >= start + (u64)stack->base_position) + { + return; + } + + header = (mem_stack_header *)(current_address - sizeof(mem_stack_header)); + prev_offset = (size_t)(current_address - (u64)header->padding - start); + stack->current_offset = prev_offset; + } +} + +internal mem_stack * +stack_resize_align(mem_stack *stack, void *pointer, u64 old_size, u64 new_size, u8 alignment) +{ + if (pointer == NULL) + { + return stack_push_align(stack, new_size, alignment); + } + else if (new_size == 0) + { + stack_pop(stack, pointer); + return NULL; + } + + u64 start, end, current_address; + u64 min_size = old_size < new_size ? old_size : new_size; + void *new_pointer; + + start = (u64)stack->base_position; + end = start + (u64)stack->capacity; + current_address = (u64)pointer; + if (!(start <= current_address && current_address < end)) + { + return NULL; + } + + if (current_address >= start + (u64)stack->current_offset) + { + return NULL; + } + + if (old_size == new_size) + { + return pointer; + } + + new_pointer = stack_push_align(stack, new_size, alignment); + memmove(new_pointer, pointer, min_size); + return new_pointer; +} + +internal void +stack_pop_all(mem_stack *stack) +{ + stack->current_offset = 0; +} + +internal void +stack_destroy(mem_stack *stack) +{ + if (!stack) + { + return; + } + + munmap(stack, stack->capacity + sizeof(mem_stack)); +} #endif diff --git a/source/base/base_string.c b/source/base/base_string.c index cb2d71d..986fde5 100644 --- a/source/base/base_string.c +++ b/source/base/base_string.c @@ -1,73 +1,30 @@ -internal umm -skip_whitespaces(string *buffer) +internal b32 +is_alpha(u8 point) { - s32 index = 0; - while (buffer->size > index) - { - ++index; - } + return ((point >= 'a' && point <= 'z') || (point >= 'A' && point <= 'Z') || (point == '_')); } -internal b8 -compare_string_struct(string c1, string c2) +internal b32 +is_digit(u8 point) { - if (c1.size != c2.size) - { - return -1; - } - - for (s32 index = 0; - index < c1.size; - ++index) - { - if (c1.Data[index] != c2.Data[index]) - { - return -1; - } - } - - return 0; + return (point >= '0' && point <= '9'); } -internal b8 -compare_string(char *c1, char *c2) +internal b32 +is_alpha_num(u8 point) { - if (sizeof(*c1) != sizeof(*c2)) - { - return -1; - } - - for ( - u64 word_idx = 0; - word_idx <= sizeof(*c1); - ++word_idx) - { - if (*c1 != *c2) - { - return -1; - } - ++c1; - ++c2; - } + return (is_alpha(point) || is_digit(point)); +} - return 0; +internal b32 is_whitespace(u8 point) +{ + return (point == '\n' || point == '\r' || point == ' ' || point == '\t'); } -/** NOTE(nasr): Helper function to parse strings to int using ascii codes **/ -internal u64 -parse_u64(char *buf, umm len) +internal b32 +is_slash(u8 point) { - u64 value = 0; + return (point == '/' || point == '\\'); +} - for (umm buffer_idx = 0; buffer_idx < len; ++buffer_idx) - { - char c = buf[buffer_idx]; - if (c < '0' || c > '9') - { - break; - } - value = value * 10 + (c - '0'); - } - return value; -} diff --git a/source/base/base_string.h b/source/base/base_string.h index d879450..eb51e65 100644 --- a/source/base/base_string.h +++ b/source/base/base_string.h @@ -1,17 +1,84 @@ #ifndef BASE_STRING_H #define BASE_STRING_H -// let's use this for strings -// to better differentiate between stuff -typedef u8 s8; -typedef struct string string ; +#define PushString8(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } +#define PushString16(arena, count) (string16){ .data = (PushArrayZero(arena, u16, (count))), .size = (count) } +#define PushString32(arena, count) (string32){ .data = (PushArrayZero(arena, u32, (count))), .size = (count) } -struct string +#define String8(data, size) (string8){(u8 *)(data), (u64)(size) } +#define String16(data, size) (string16){(u16 *)(data), (u64)(size) } +#define String32(data, size) (string32){(u32 *)(data), (u64)(size) } + + + +#define StringFmt "%.*s" +#define ULongFmt "%lu" +#define ULLongFmt "%llu" + +typedef struct string8 string8; +struct string8 +{ + u8 *data; + u64 size; +}; + +typedef struct string16 string16; +struct string16 +{ + u16 *data; + u64 size; +}; + +typedef struct string32 string32; +struct string32 +{ + u32 *data; + u64 size; +}; + +//- string linked list implementation +typedef struct string8_node string8_node; +struct string8_node { - s8 *data; - umm size; + string8 *next; + string8 string; }; -// TODO(nasr): helper functions for string +typedef struct string8_list string8_list; +struct string8_list +{ + string8 *first; + string8 *last; + u64 count; +}; + +typedef struct string16_list string16_list; +struct string16_list +{ + string16 *next; + string16 string; +}; + +typedef struct string32_list string32_list; +struct string32_list +{ + string32 *first; + string32 *last; + u64 count; +}; + +internal b8 +string8_cmp(string8 a, string8 b) +{ + if (a.size != b.size) return 0; + return (b8)(memcmp(a.data, b.data, a.size) == 0); +} + +internal void +string8_appendc(string8 *buf, u8 c) +{ + buf->data[buf->size] = c; + buf->size += 1; +} #endif /* BASE_STRING_H */ diff --git a/source/base/base_test.c b/source/base/base_test.c deleted file mode 100644 index e44aa69..0000000 --- a/source/base/base_test.c +++ /dev/null @@ -1,14 +0,0 @@ -void -write_int(i32 num) -{ - if (num < 0) - { - write(STDERR_FILENO, "-", 1); - num = -num; - } - if (num >= 10) - write_int(num / 10); - char digit = '0' + (num % 10); - - write(STDERR_FILENO, &digit, 1); -} diff --git a/source/base/base_test.h b/source/base/base_test.h deleted file mode 100644 index 11028f4..0000000 --- a/source/base/base_test.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef BASE_TEST_H -#define BASE_TEST_H - -void -write_int(i32 num); - -#define RED "\x1b[31m" -#define GREEN "\x1b[32m" -#define RESET "\x1b[0m" -#define BLUE "\x1b[34m" - -#define LEN(s) (sizeof(s) - 1) - -#define show \ - do \ - { \ - write(STDOUT_FILENO, __FILE__, sizeof(__FILE__) - 1); \ - write(STDOUT_FILENO, ":", 1); \ - write(STDOUT_FILENO, __func__, sizeof(__func__) - 1); \ - write(STDOUT_FILENO, ":", 1); \ - write_int(__LINE__); \ - write(STDOUT_FILENO, "\n", 1); \ - } while (0) - -#define test(expr) \ - { \ - if ((expr) != 0) \ - { \ - write(STDERR_FILENO, "[FAILED] ", LEN("[FAILED] ")); \ - show; \ - _exit(1); \ - } \ - } - -#define check(expr) \ - { \ - if ((expr) != 0) \ - { \ - write(STDERR_FILENO, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ - show; \ - write(STDERR_FILENO, RESET, LEN(RESET)); \ - _exit(1); \ - } \ - else \ - { \ - write(STDERR_FILENO, GREEN "[SUCCESS] ", LEN(GREEN "[SUCCESS] ")); \ - show; \ - write(STDERR_FILENO, RESET, LEN(RESET)); \ - } \ - } - -#define checkpoint_output "<>\n" -#define checkpoint_end_output "^^^^^^^^^^^^^^\n\n\n" -#define checkpoint \ - { \ - write(STDERR_FILENO, BLUE checkpoint_output, LEN(BLUE checkpoint_output)); \ - show; \ - write(STDERR_FILENO, BLUE checkpoint_end_output, LEN(BLUE checkpoint_end_output)); \ - } - -#endif /* BASE_TEST_H */ diff --git a/source/base/bash_hash.h b/source/base/bash_hash.h index 2c286a2..758ef72 100644 --- a/source/base/bash_hash.h +++ b/source/base/bash_hash.h @@ -1,15 +1,24 @@ -##ifndef HEADER_H -#define HEADER_H +#ifndef BASH_HASH_H +#define BASH_HASH_H typedef struct hash_map hash_map; typedef struct hash hash; - -struct hash_map +struct map { + string8 + u64 capacity +}; +struct index +{ + string8 key; + string8 value; }; -#endif /* HEADER_H */ + +internal void + +#endif /* BASH_HASH_H */ diff --git a/source/core/core.c b/source/core/core.c deleted file mode 100644 index f9d062a..0000000 --- a/source/core/core.c +++ /dev/null @@ -1,136 +0,0 @@ -#define TB_IMPLEMENTATION -#include "core.h" -#include "../base/base_include.h" -#include "../platform/platform_include.h" - -int main() -{ - b32 running = 1; - - Display *MainDisplay = XOpenDisplay(0); - mem_arena *arena = arena_create(MiB(8)); - - Window root = XDefaultRootWindow(MainDisplay); - int screen = DefaultScreen(MainDisplay); - - Visual *v = DefaultVisual(MainDisplay, screen); - - XSetWindowAttributes wa = { - .background_pixmap = None, - .background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)), - .border_pixmap = CopyFromParent, - .border_pixel = 0, - .bit_gravity = ForgetGravity, - .win_gravity = NorthWestGravity, - .backing_store = NotUseful, - .backing_planes = 1, - .backing_pixel = 0, - .save_under = False, - .event_mask = 0, - .do_not_propagate_mask = 0, - .override_redirect = False, - .colormap = CopyFromParent, - .cursor = None - }; - - i32 dp_heigth = DisplayHeight(MainDisplay, screen); - i32 dp_width = DisplayWidth(MainDisplay, screen); - - WindowProperties p = { - - .x = dp_width / 2, - .y = dp_heigth / 2, - .height = (u32)800, - .width = (u32)1200, - .border_width = 0, - .window_depth = CopyFromParent, - .window_class = CopyFromParent, - .value_mask = CWBackPixel, - - }; - - Window window = - XCreateWindow( - MainDisplay, - root, - p.x, - p.y, - p.width, - p.height, - p.border_width, - p.window_depth, - p.window_class, - v, - p.value_mask, - &wa); - - XSetWindowBorder(MainDisplay, window, 60); - XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask | KeyPressMask); - XMapWindow(MainDisplay, window); - XEvent event; - - f32 DELTA = 2.5; - - u32 rect_width = 50; - u32 rect_height = 50; - - i32 rect_x_position = p.width / 2; - i32 rect_y_position = p.height / 2; - - i32 rect_enemy_x_position = (p.width / 2) + 300; - i32 rect_enemy_y_position = (p.height / 2) + 300; - - u64 color = 0x0FF0FF00; - - GC gc = XCreateGC(MainDisplay, window, 0, NIL); - XSetForeground(MainDisplay, gc, color); - - for (;running;) - { - //- handle enemy movement - { - if(rect_enemy_x_position < rect_x_position) rect_enemy_x_position += DELTA*0.5; - if(rect_enemy_y_position < rect_y_position) rect_enemy_y_position += DELTA*0.5; - - if(rect_enemy_x_position > rect_x_position) rect_enemy_x_position -= DELTA*0.5; - if(rect_enemy_y_position > rect_y_position) rect_enemy_y_position -= DELTA*0.5; - } - - XNextEvent(MainDisplay, &event); - - switch (event.type) - { - case(KeyPress): - { - - KeySym keysym = XLookupKeysym(&event.xkey, 0); - //- handle user movement - { - if(keysym == XK_h) rect_x_position -= DELTA*1.2; - else if(keysym == XK_l) rect_x_position += DELTA*1.2; - else if(keysym == XK_k) rect_y_position -= DELTA*1.2; - else if(keysym == XK_j) rect_y_position += DELTA*1.2; - else if(keysym == XK_s); - else if(keysym == XK_Escape || keysym == XK_q) goto exit; - } - - //- draw entities - { - XClearWindow(MainDisplay, window); - - //-- - XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); - XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); - - //-- - XDrawRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); - XFillRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); - } break; - } - default: - } - } -exit: - arena_clear(arena); - return 0; -} diff --git a/source/core/core.h b/source/core/core.h deleted file mode 100644 index c5821c5..0000000 --- a/source/core/core.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef CORE_H -#define CORE_H - - - #endif diff --git a/source/platform/platform.c b/source/platform/platform.c deleted file mode 100644 index 2e7bbad..0000000 --- a/source/platform/platform.c +++ /dev/null @@ -1,12 +0,0 @@ -internal inline void -sleep_ms(long ms) -{ - struct timespec ts; - ts.tv_sec = ms / 1000; - ts.tv_nsec = (ms % 1000) * 1000000L; - - while (nanosleep(&ts, &ts)) - { - NULL; - } -} diff --git a/source/platform/platform.h b/source/platform/platform.h deleted file mode 100644 index da8e065..0000000 --- a/source/platform/platform.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef PLATFORM_H -#define PLATFORM_H - -#define NIL 0 - -#include -#include - #include -#include -#include - -typedef struct WindowProperties WindowProperties; -struct WindowProperties -{ - i32 x; - i32 y; - u32 height; - u32 width; - u32 border_width; - i32 window_depth; - u32 window_class; - u64 value_mask; - -}; - -typedef struct vertex vertex; - -struct vertex -{ - i32 x; - i32 y; - i32 z; -}; - -typedef struct display_pos display_pos; - -struct display_pos -{ - i32 x; - i32 y; - -}; - -typedef struct pos pos; -struct pos -{ - i32 x; - i32 y; - i32 z; - -} ; - - - - -#endif /* PLATFORM_H */ diff --git a/source/platform/platform_include.h b/source/platform/platform_include.h deleted file mode 100644 index 886c6b8..0000000 --- a/source/platform/platform_include.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PLATFORM_INCLUDE_H -#define PLATFORM_INCLUDE_H - -#include "platform.h" -#include "platform.c" - -#endif /* PLATFORM_INCLUDE_H */ diff --git a/source/tb/tb.c b/source/tb/tb.c new file mode 100644 index 0000000..ed78dd2 --- /dev/null +++ b/source/tb/tb.c @@ -0,0 +1,183 @@ +#define BASE_IMPLEMENTATION +#define BASE_RAND_IMPLEMENTATION +#define BASE_MATH_IMPLEMENTATION +#define BASE_PLATFORM +#define BASE_PLATFORM_IMPLEMENTATION +#include "../base/base_include.h" + +#define WINDOW_WIDTH 800 +#define WINDOW_HEIGHT 1200 + +internal void +load_entities(Display *MainDisplay, Window *window, GC *gc, s32 entity_count) +{ + s32 x = (s32)generate_random_u64(RAND_CONSTANT); + s32 y = (s32)generate_random_u64(RAND_CONSTANT); + + for (s32 index = 0; index < entity_count; ++index) + { + s32 delta = (s32)generate_random_u64(RAND_CONSTANT); + + XDrawRectangle(MainDisplay, + *window, + *gc, + x * (1/delta), + y * (1/delta), + 50, + 50); + + XFillRectangle(MainDisplay, + *window, + *gc, + x * (1/delta), + y * (1/delta), + 50, + 50); + } +} + + +internal void +load_user(Display *MainDisplay, Window *window, GC *gc, s32 x, s32 y, u32 width, u32 height) +{ + XDrawRectangle(MainDisplay, *window, *gc, x, y, width, height); + XFillRectangle(MainDisplay, *window, *gc, x, y, width, height); +} + + +int main() +{ + b32 running = 1; + + Display *MainDisplay = XOpenDisplay(0); + mem_arena *arena = arena_create(MiB(8)); + + Window root = XDefaultRootWindow(MainDisplay); + int screen = DefaultScreen(MainDisplay); + + Visual *v = DefaultVisual(MainDisplay, screen); + + + XSetWindowAttributes wa = { + .background_pixmap = None, + .background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)), + .border_pixmap = CopyFromParent, + .border_pixel = 0, + .bit_gravity = ForgetGravity, + .win_gravity = NorthWestGravity, + .backing_store = NotUseful, + .backing_planes = 1, + .backing_pixel = 0, + .save_under = False, + .event_mask = 0, + .do_not_propagate_mask = 0, + .override_redirect = False, + .colormap = CopyFromParent, + .cursor = None + }; + + s32 dp_heigth = DisplayHeight(MainDisplay, screen); + s32 dp_width = DisplayWidth(MainDisplay, screen); + + + WindowProperties p = { + + .x = + .y = + .height = + .width = + .border_width = 0, + .window_depth = CopyFromParent, + .window_class = + .value_mask = + + }; + + Window window = XCreateWindow( MainDisplay, root, dp_width / 2, dp_heigth / 2, + (u32)WINDOW_WIDTH, (u32)WINDOW_HEIGHT, 0, CopyFromParent, v, CWBackPixel, &wa); + + XSetWindowBorder(MainDisplay, window, 60); + XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask | KeyPressMask); + XMapWindow(MainDisplay, window); + XEvent event; + + f32 DELTA = 2.5; + + u32 rect_width = 50; + u32 rect_height = 50; + + s32 rect_x_position = p.width / 2; + s32 rect_y_position = p.height / 2; + + s32 rect_enemy_x_position = (p.width / 2) + 300; + s32 rect_enemy_y_position = (p.height / 2) + 300; + + u64 color = 0x0FF0FF00; + + GC gc = XCreateGC(MainDisplay, window, 0, NIL); + XSetForeground(MainDisplay, gc, color); + + for (;running;) + { + //- handle collision detection + { + if(rect_y_position >= WINDOW_HEIGHT) DELTA = -DELTA; + if(rect_x_position >= WINDOW_WIDTH) DELTA = -DELTA; + + if(rect_enemy_y_position >= WINDOW_HEIGHT) DELTA = -DELTA; + if(rect_enemy_x_position >= WINDOW_WIDTH) DELTA = -DELTA; + } + + //- handle enemy movement + { + s32 dy = rect_y_position - rect_enemy_y_position; + s32 dx = rect_x_position - rect_enemy_x_position; + + //- normalize the distance | why this is needed? no clue + f32 distance = sqrtf(dx*dx + dy*dy); + + if(distance > 1.0f) { + f32 speed = DELTA * 0.5f; + rect_enemy_x_position += (s32)((dx / distance) * speed); + rect_enemy_y_position += (s32)((dy / distance) * speed); + } + } + + XNextEvent(MainDisplay, &event); + + switch (event.type) + { + case(KeyPress): + { + KeySym keysym = XLookupKeysym(&event.xkey, 0); + //- handle user movement + { + if(keysym == XK_h) rect_x_position -= DELTA*1.5; + else if(keysym == XK_l) rect_x_position += DELTA*1.5; + else if(keysym == XK_k) rect_y_position -= DELTA*1.5; + else if(keysym == XK_j) rect_y_position += DELTA*1.5; + else if(keysym == XK_s); + else if(keysym == XK_Escape || keysym == XK_q) goto exit; + } + + + // clear screen before drawing entities + + XClearWindow(MainDisplay, window); + + //- draw entities + { + } break; + } + default: + { + + } + } + } + + +exit: + arena_destroy(arena); + return 0; +} diff --git a/todo.db b/todo.db deleted file mode 100644 index e1abef7..0000000 Binary files a/todo.db and /dev/null differ -- cgit v1.3