This commit is contained in:
Daniel Ledda
2025-11-10 03:15:14 +01:00
parent db92620d65
commit a580e7b1cb
6 changed files with 41 additions and 30 deletions

31
core.h
View File

@@ -2,10 +2,8 @@
#define CORE_H
// cstdlib includes
#include "math.h"
#include "stdbool.h"
#include "stdint.h" // necessary for int type sizes
#include "stdio.h"
#include "time.h" // TODO(djledda): try not to depend on this one
// ### Misc macros ###
@@ -139,7 +137,7 @@ inline function Vec4 vec4(real32 x, real32 y, real32 z, real32 w) {
typedef struct {\
type* data;\
size_t length;\
size_t head;\
size_t capacity;\
} prefix ## List
DefineList(string, String);
@@ -152,12 +150,14 @@ DefineList(string, String);
#define ArrayAsList(type, array) (type){ array, ArrayCount(array), ArrayCount(array) }
#define AppendList(list, element) \
if ((list)->head < (list)->length) { \
(list)->data[(list)->head++] = (element); \
if ((list)->length < (list)->capacity) { \
(list)->data[(list)->length++] = (element); \
}
#define ZeroListFull(list) memset((list)->data, 0, (list)->head * sizeof(T))
#define ZeroList(list) (list)->head = 0; \
memset((list)->data, 0, (list)->head * sizeof(T));
#define ZeroListFull(list) memset((list)->data, 0, (list)->length * sizeof(T))
#define ZeroList(list) (list)->length = 0; \
memset((list)->data, 0, (list)->length * sizeof(T));
#define ListSlice(list, start, stop) (stop > list.length || start > stop ? {0} : { list.data + start, stop - start, stop - start, })
#define ListTail(list, start) ListSlice(list, list.length)
// ### Strings ###
struct string {
@@ -189,9 +189,16 @@ StringList strSplit(Arena *arena, string splitStr, string inputStr);
string strPrintfv(Arena *arena, const char *fmt, va_list args);
string strPrintf(Arena *arena, const char *fmt, ...);
typedef struct { uint8 result; bool valid; } ParsePositiveIntResult;
typedef struct {
uint8 result;
bool valid;
} ParsePositiveIntResult;
ParsePositiveIntResult parsePositiveInt(string str, size_t *lengthPointer);
typedef struct { real32 result; bool valid; } ParsePositiveReal32Result;
typedef struct {
real32 result;
bool valid;
} ParsePositiveReal32Result;
ParsePositiveReal32Result parsePositiveReal32(string str, size_t *lengthPointer);
inline function bool isNumeric(char c);
@@ -272,8 +279,8 @@ void printStrList(StringList l);
extern void (*print)(const char *fmt, ...);
// ### Loops ###
#define EachIn(list, it) size_t it = 0; it < (list).head; it++
#define EachInReversed(list, it) size_t it = (list).head - 1; it >= 0 && it < (list).head; it--
#define EachIn(list, it) size_t it = 0; it < (list).length; it++
#define EachInReversed(list, it) size_t it = (list).length - 1; it >= 0 && it < (list).length; it--
#define EachInArray(arr, it) size_t it = 0; it < ArrayCount(arr); ++it
// ### Misc ###