Skip to content

Instantly share code, notes, and snippets.

@tauoverpi
tauoverpi / build.go
Created November 22, 2023 17:33
When you don't want a Makefile
package main
import (
"os"
"os/exec"
"reflect"
"runtime"
)
func main() {
@tauoverpi
tauoverpi / main.zig
Last active November 18, 2023 19:18
ecs-mini.zig
data: Data = undefined,
len: Length,
systems: Systems = .{},
/// Run all systems for a single logical game update.
pub fn update(ecs: *EntityComponentSystem, dt: f64) void {
inline for (@typeInfo(Systems).Struct.fields) |field| {
@field(ecs.systems, field.name).run(&ecs.data, &ecs.len, dt);
}
}
@tauoverpi
tauoverpi / utility.py
Created October 18, 2023 16:49
Old utility example
import math
import random
from typing import List, Any, Dict, Union
random.seed(0xcafebabedeadbeef) # ensure reproducible results
# ---- infinite axis utility system -----
# The framework which you'll only need to write once
@tauoverpi
tauoverpi / demo.zig
Last active October 18, 2023 16:27
Scrap book: new AI system core
// How to write your very own MMO --- an introduction to multiplayer game design
// Copyright © 2023 Simon A. Nielsen Knights <levyelara@protonmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
Awesome stuff I cannot look at due to clean room design.
# Colour spaces
- https://github.com/nitrogenez/prism
@tauoverpi
tauoverpi / dynamic_row.zig
Last active September 4, 2023 20:32
Code examples
const std = @import("std");
const mem = std.mem;
const testing = std.testing;
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const Table = struct {
/// Each row consists of `stride` number of columns of string indices.
rows: std.ArrayListUnmanaged(String) = .{},
@tauoverpi
tauoverpi / stack_ub.zig
Created September 3, 2023 09:57
Diagrams used when explaining stuff
// stack over time
// ,-------------,
var outputTable = Table.init(4, allocator); // ,-> | outputTable |
// | |-------------|---,
for (alerts.value.data.alerts) |a| { // | | outputTable | a | stack location of `r`
// | |-------------|---|---,
var r = [_][]u8{ // | | outputTable | a | r | stack location of the fields of `a` when placed in the array of slices passed to `r` -------,
// | |-------------|---|---|-------------------, |
a.labels.instance, // f | | outputTable | a | r | a.labels.instance | |
//
@tauoverpi
tauoverpi / build.zig
Created September 2, 2023 17:14
Using the levy game project as a library
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "hook",
@tauoverpi
tauoverpi / mess.zig
Last active September 2, 2023 00:18
Comptime is a trap
pub fn dispatch(arena: Allocator, cwd: Dir, context: Context, argv: []const [*:0]const u8, comptime hooks: Self) !void {
const basename = fs.path.basename(mem.span(argv[0]));
const command = Self.map.get(basename) orelse return error.UnknownCommand;
switch (command) {
inline else => |tag| {
const com = @field(hooks, @tagName(tag));
const Fn = @TypeOf(com);
const info = @typeInfo(Fn).Fn;
var tuple: meta.ArgsTuple(Fn) = undefined;
@tauoverpi
tauoverpi / import.zig
Created August 15, 2023 07:04
fix all imports
const std = @import("std");
const mem = std.mem;
const assert = std.debug.assert;
const Ast = std.zig.Ast;
pub fn main() !void {
var instance = std.heap.GeneralPurposeAllocator(.{}){};
defer assert(instance.deinit() == .ok);
const gpa = instance.allocator();