Skip to content

Instantly share code, notes, and snippets.

#+vet shadowing unused
package morton
import "base:intrinsics"
// https://fgiesen.wordpress.com/2022/09/09/morton-codes-addendum/
// https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
@(require_results)
morton_encode_2d_u8 :: proc "contextless" (p: [2]u8) -> u16 #no_bounds_check {
@jakubtomsu
jakubtomsu / new_odin_front_page_examples_draft.odin
Last active April 16, 2026 16:32
Proposal for new odin-lang.org front page examples.
/*
The examples on the front page of odin-lang.org aren't very good.
This is my proposal for a new replacement. The following examples
should introduce most of the core language features.
They were written with C, Go and Python programmers in mind.
I've tried to make the code relatively similar to what one
would write in practice in a real project, while keeping the line
@jakubtomsu
jakubtomsu / linalg_bench.odin
Created April 10, 2026 15:14
Making core:math/linalg a bit faster
/*
Odin core:math/linalg benchmarking code
Primarily optimizes 3xf32 math in -o:speed mode!
However I spent a lot of effort ensuring the code doesn't get significantly slower
in non-optimized builds.
The results can looks something like this (-o:speed, amd64 skylake)
NAME | Cycles/Elem | Total Cycles | Ms | Speedup
@jakubtomsu
jakubtomsu / cqoa.odin
Created February 26, 2026 16:08
Odin QOA encoding/decoding test https://github.com/phoboslab/qoa
// Bindings for qoa.h
package cqoa
foreign import lib "qoa.lib"
RECORD_TOTAL_ERROR :: true
MIN_FILESIZE :: 16
MAX_CHANNELS :: 8
package import_scan
import "core:strings"
import "core:strconv"
import "core:path/filepath"
import "core:fmt"
import "core:os/os2"
import "core:odin/ast"
import "core:odin/parser"
import "core:odin/tokenizer"
@jakubtomsu
jakubtomsu / fast_negative_exp.odin
Last active January 27, 2026 20:57
~11x faster exp(-x)
package foo
import "base:intrinsics"
import "core:math"
import "core:fmt"
import "core:time"
// https://www.desmos.com/calculator/i17pexccum
a: f32 = 1.0
@jakubtomsu
jakubtomsu / ufmt.odin
Created January 19, 2026 13:57
Extremely stripped down lightweight `core:fmt` alternative
// Micro-fmt
//
// Extremely stripped down `core:fmt` alternative.
// Supports only %s, %f, %i, %x, %%
// NOTE: curly braces don't need to be doubled ({{ and }}) like in `core:fmt`
//
// By Jakub Tomšů
package ufmt
import "base:runtime"
@jakubtomsu
jakubtomsu / poly_obb.odin
Created August 2, 2025 13:54
A demo app showing how to compute tightest possible oriented bounding box of a 2D polygon
// A demo app showing how to compute tightest possible oriented bounding box/rectangle of a convex polygon.
// The order of edges matters, so the points should be in order. In case of convex polygons you can just radially sort them.
//
// By Jakub Tomšů
package poly_obb_demo
import "core:fmt"
import "core:math/linalg"
import rl "vendor:raylib"
package fp_exceptions
import "core:log"
when ODIN_OS == .Windows {
foreign import libcmt "system:libcmt.lib"
}
@(default_calling_convention = "system")
foreign libcmt {
// Failed experiment for a hotreload system. Instead of passing a big global struct pointer, try copying DLL global data sections.
copy_dll_data_sections :: proc(
dst: windows.HMODULE,
src: windows.HMODULE,
) -> bool {
dst_header := get_dll_nt_header(dst) or_return
src_header := get_dll_nt_header(src) or_return
dst_sections := cast([^]windows_IMAGE_SECTION_HEADER)windows_image_first_section(dst_header)