Skip to content

Instantly share code, notes, and snippets.

@laytan
laytan / renderer.odin
Last active August 1, 2026 17:16
Example Odin font renderer using fontstash and WebGPU
package vendor_wgpu_example_fontstash
import intr "base:intrinsics"
import "core:fmt"
import "core:math/linalg"
import sa "core:container/small_array"
import fs "vendor:fontstash"
import "vendor:wgpu"
@jakubtomsu
jakubtomsu / realtime_collision_detection.odin
Last active August 5, 2026 12:21
Port of some functions from 'Real Time Collision Detection' book by Christer Ericson to Odin
// Port of some collision functions to Odin by Jakub Tomšů.
//
// from Real-Time Collision Detection by Christer Ericson, published by Morgan Kaufmann Publishers, © 2005 Elsevier Inc
//
// This should serve as an reference implementation for common collision queries for games.
// The goal is good numerical robustness, handling edge cases and optimized math equations.
// The code isn't necessarily very optimized.
//
// There are a few cases you don't want to use the procedures below directly, but instead manually inline the math and adapt it to your needs.
// In my experience this method is clearer when writing complex level queries where I need to handle edge cases differently etc.
@jakubtomsu
jakubtomsu / pathtest.c
Created August 2, 2023 14:55
Simple program for testing known folder paths on windows, e.g. for storing savegames.
// This is a small program to print a number of known paths in Windows.
// Savegame files should be in FOLDERID_SavedGames!
// SHGetKnownFolderPath should probably be used only for compatibility.
//
// Compile with `cl pathtest.c`
//
// Day created: 02.08.2023
// Version: Windows 10 pro 22H2
//
// Output on my machine:
@jakubtomsu
jakubtomsu / ease.odin
Last active February 7, 2025 23:13
Easings library ported to Odin
package ease
// Adapted from functions here: https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c
// For previews go here: https://easings.net/
import "core:math"
Mode :: enum {
linear = 0,
quad_in,
@jakubtomsu
jakubtomsu / bitarray.h
Last active July 15, 2024 14:13
Super simple single-header bitarray example in C
// Simple bitarray example
// -----------------------
// Warning: no bounds checking
// Usually I'd use 'uint8_t' instead of an 'char' and 'size_t' instead of an 'int',
// but this way it can be copied anywhere without worrying about includes.
static inline int bitarray_get(const char* bitarray, const int index) {
return ((bitarray[index / 8]) >> (index % 8)) & 1;
}
// ----------------------------------------------------------------------------
// constexpr_hash_murmur.h
// ----------------------------------------------------------------------------
// compile time string hashing(murmur hash equivalent).
// @see also https://sites.google.com/site/murmurhash/
#pragma once
#include <stdint.h>
#if defined(_MSC_VER)
#pragma warning (push)
@aras-p
aras-p / preprocessor_fun.h
Last active August 15, 2026 15:30
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@1wErt3r
1wErt3r / SMBDIS.ASM
Created November 9, 2012 22:27
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no
@jboner
jboner / latency.txt
Last active August 29, 2026 22:58
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD