Skip to content

Instantly share code, notes, and snippets.

View nickel-dev's full-sized avatar

Daniel Nickel nickel-dev

View GitHub Profile
@nickel-dev
nickel-dev / vector.h
Last active September 14, 2024 08:48
Single header game vectors in C using 100 lines of meta programming
// Types
#define TEMPLATE_Vec2t(t) \
typedef union Vec2##t {\
struct {t x, y;};\
t e[2];\
} Vec2##t;
#define TEMPLATE_Vec3t(t) \
typedef union Vec3##t {\
struct {t x, y, z;};\
@nickel-dev
nickel-dev / hashmap.c
Created September 27, 2024 20:32
Linear search Hashmap using linked lists in C, is uses my base layer.
intern u64
hash_str(const char* str) {
u64 hash = 14695981039346656037ULL; // FNV offset basis
i32 c;
while ((c = *str++)) {
hash ^= (u64)c;
hash *= 1099511628211ULL; // FNV prime
}
return hash;
}
@nickel-dev
nickel-dev / defer.hpp
Last active November 19, 2024 16:38
jai defer in C++ (as a macro)
// creates a variable called "__defer + line number" this variable is destructed at the end of the scope.
// on destruction it calls a lambda function that was generated by the macro.
// example:
// This program outputs "x: 1"
/*
{
int x = 0;
defer(printf("x: %d\n", x));
x++;