Skip to content

Instantly share code, notes, and snippets.

View laytan's full-sized avatar

Laytan laytan

  • The Netherlands
  • 11:29 (UTC +01:00)
  • X @laytanl_
View GitHub Profile
@laytan
laytan / city.odin
Created November 13, 2024 18:40
city hash odin
city64 :: proc(data: []byte) -> u64 {
// Some primes between 2^63 and 2^64 for various uses.
K0 :: 0xc3a5c85c97cb3127
K1 :: 0xb492b66fbe98f273
K2 :: 0x9ae16a3b2f90404f
fetch64 :: proc(p: [^]byte) -> u64 {
res := intrinsics.unaligned_load((^u64)(p))
when ODIN_ENDIAN == .Big {
@laytan
laytan / case_map.odin
Last active November 13, 2024 18:41
Case insensitive map in Odin (very basic)
package main
import "base:intrinsics"
import "base:runtime"
import "core:hash"
import "core:mem"
import "core:strings"
import "core:unicode"
import "core:unicode/utf8"
@laytan
laytan / index.html
Created October 23, 2024 17:12
Very simple sound abstraction in Odin over WebAudio and MiniAudio
<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Yo</title>
</head>
<body id="body" style="height: 100%; padding: 0; margin: 0; overflow: hidden;">
<canvas id="wgpu-canvas"></canvas>
@laytan
laytan / deep.odin
Created September 6, 2024 18:58
Odin Deep Clone (WIP)
deep_clone :: proc(value: $T, allocator := context.allocator, temp_allocator := context.temp_allocator) -> (clone: T) {
internal_deep_clone :: proc(value: any, clone: any, ptrs: ^map[rawptr]rawptr) {
// Forgive me father for I have sinned.
using reflect
value_core := any_core(value)
clone_core := any_core(clone)
assert(value_core.id == clone_core.id)
fti := type_info_of(value_core.id)
@laytan
laytan / raw.odin
Last active August 29, 2024 17:36
Odin raw mode terminal
package main
import "core:c/libc"
import "core:fmt"
import "core:io"
import "core:os"
import "core:time"
import "core:unicode/utf8"
@(require)
@laytan
laytan / renderer.odin
Last active July 15, 2024 16:36
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"
@laytan
laytan / Makefile
Created June 30, 2024 21:11
Odin with C entry point
program: entry.c program.odin
odin build . -out:program -no-entry-point -build-mode:object
clang entry.c program.o -o program
rm program.o
@laytan
laytan / rlights.odin
Created June 20, 2024 15:33
rlights port
package rlights
import rl "vendor:raylib"
MAX_LIGHTS :: 4
Light :: struct {
type: LightType,
enabled: b32,
position: [3]f32,
@laytan
laytan / odin.py
Created April 25, 2024 17:40
LLDB script to visualise Odin slices, maps, and strings
import lldb
def is_slice_type(t, internal_dict):
return t.name.startswith("[]") or t.name.startswith("[dynamic]")
class SliceChildProvider:
def __init__(self, val, dict):
self.val = val
def num_children(self):
@laytan
laytan / main.odin
Last active September 10, 2024 15:27
Graphviz Odin dependencies
package main
import "core:fmt"
import "core:io"
import "core:odin/ast"
import "core:odin/parser"
import "core:os"
import "core:path/filepath"
import "core:slice"
import "core:strings"