Skip to content

Instantly share code, notes, and snippets.

// Symbols:
// Dropdowns rendering: [|----------------[v]|]
// Right Click -> New State Machine -> Name: "blnd_tree_loco_walk"
static struct anim_pose*
blnd_tree_loco_walk(struct anim_ctx *ctx, struct anim_sm *sm) {
struct anim_pose *res = 0;
{
// Right Click -> New Node -> Animation -> Walk Left
struct anim *walk_l = [|----------------[v]|];
@vurtun
vurtun / sort.c
Last active January 11, 2023 15:22
// ref: http://www.codercorner.com/RadixSortRevisited.htm
// http://stereopsis.com/radix.html
// int/float: https://github.com/lshamis/FloatRadixSort
// string: https://github.com/rantala/string-sorting/blob/master/src/msd_ce.cpp
struct str {
const char *str;
const char *end;
int len;
};
#include <stdio.h>
#define xglue(x, y) x##y
#define glue(x, y) xglue(x, y)
#define uniqid(name) glue(name, __LINE__)
#define scp_brk(name) goto xglue(___SCOPE___,name)
#define scp_file(name,f,p,fmt)\
xglue(___SCOPE___,name): for(int uniqid(_i_) = (f) ? 1 : ((((f) = fopen(p,fmt)) == 0) ? 1 : 0);\
(uniqid(_i_) == 0) ? 1 : ((f) ? (fclose(f), 0): 0); ++uniqid(_i_))
// http://0x80.pl/notesen/2018-10-03-simd-index-of-min.html
#define cpy3(d,s) ((d)[0]=(s)[0],(d)[1]=(s)[1],(d)[2]=(s)[2])
#define dot3(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
#if defined(__GNUC__) || defined(__clang__)
#define alignto(x) __attribute__((aligned(x)))
#elif defined(_MSC_VER)
#define alignto(x) __declspec(align(x))
#else
#define alignto(x) _Alignas(x)
enum gui_lay_type {
GUI_LAY_ROW,
GUI_LAY_COL
};
struct gui_lay {
struct gui_box box; /* in */
/* internal */
enum gui_lay_type type;
struct gui_box sub;
int idx, cnt;
@vurtun
vurtun / str_split.c
Last active April 18, 2021 19:34
string split (line splitting)
static int*
str_split(const char *in, int siz, char delim) {
int *eol = 0;
__m128i msk = _mm_set1_epi8(0x80);
__m128i sub = _mm_set1_epi8(0x01);
__m128i neg = _mm_set1_epi64(-1LL);
__m128i sep = _mm_set1_epi8(delim);
__m128i endmsk = _mm_set1_epi32(-1);
if (siz & 15) {
endmsk = _mm_slli_si128(endmsk, 16 - (siz & 15))
@vurtun
vurtun / cloth.c
Last active April 18, 2021 19:33
// https://github.com/dianedelallee/cloth-simulation
/* ---------------------------------------------------------------------------
* Vector3
* ---------------------------------------------------------------------------
*/
#define op(r,e,a,p,b,i,s) ((r) e (a) p ((b) i (s)))
#define lerp(r,a,b,t) ((r)=(a)+(t)*((b)-(a)))
#define rad(x) ((x)*3.141592653f/180.0f)
#define op3(r,e,a,p,b,i,s)\
@vurtun
vurtun / math.c
Last active February 16, 2021 19:54
basic math function approximations
#include <stdio.h>
#include <stdlib.h>
#define sgn(v) ((0 < (v)) - ((v) < 0))
#define abs(a) (((a) < 0) ? -(a) : (a))
static int
ilog2(int n) {
#ifdef _MSC_VER
unsigned long msbp = 0;
@vurtun
vurtun / gif.c
Last active December 25, 2020 21:04
#ifndef JO_GIF_H
#define JO_GIF_H
#include <stdio.h>
typedef struct jo_gif_kd_node_s {
unsigned char pnt[3];
unsigned char lhs, rhs;
unsigned char idx;
} jo_gif_kd_node_t;

API Design: Builder APIs (October-2020)

Some time has past (three years!) since I last wrote about API specifically about coroutines style APIs so I thought why not write another one about a different API type I encounter relatively often. The builder API.

Now first let me take a step back and put this into 20,000 feet view on where builder APIs are located in the grant scheme. In general everything in computing is separated into input, processing and finally output. In its most basic form I am currently typing on my keyboard. All pressed keys are processed from the OS up to the browser I am writing this in and finally rendered and displayed on the screen as output. Of course this example is very user centric