Skip to content

Instantly share code, notes, and snippets.

View garettbass's full-sized avatar
🤓

Garett Bass garettbass

🤓
View GitHub Profile
@garettbass
garettbass / LocalPackageConverter.cs
Last active September 20, 2023 15:00
Convert Unity packages from Library/PackageCache into local packages. (more info in comments below)
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public static class LocalPackageConverter
@garettbass
garettbass / initialize.zig
Created June 22, 2022 03:47
Various utility functions for initialization in Zig
const std = @import("std");
const Elem = std.meta.Elem;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fn Default(comptime T: type) type {
return struct {
const value = default(T);
};
}
@garettbass
garettbass / component_registry.zig
Created June 13, 2022 14:58
Assigns a unique monotonically increasing integer to each registered type, and allows retrieval of runtime-accessible TypeInfo using the returned ComponentIndex.
const std = @import("std");
const type_info = @import("type_info.zig");
const component_index = @import("component_index.zig");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pub const ComponentRegistryError = error{
ComponentIndexIsOutOfBounds,
ComponentIndexIsUnregistered,
};
@garettbass
garettbass / type_map.zig
Created June 8, 2022 07:17
A generic type assigns an integer key to types at `comptime`, and allows values to be associated with the type at runtime.
const std = @import("std");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Creates a named section in the binary, mapping concrete types to
/// monotonically increasing keys of integer or enum type.
/// The value associated with a type may be assigned at runtime, and queried
/// with the key assigned to that concrete type at `comptime`.
pub fn TypeMap(
comptime name: []const u8,
@garettbass
garettbass / type_index_generator.zig
Last active June 7, 2022 15:49
A generic type that maps provided types to monotonically increasing integers.
const std = @import("std");
pub fn TypeIndexGenerator(comptime TIndex: type) type {
const index_info = @typeInfo(TIndex);
const TInt = switch (index_info) {
.Int => TIndex,
.Enum => |t| if (t.is_exhaustive)
@compileError("TIndex enum must be non-exhaustive")
else
t.tag_type,
@garettbass
garettbass / shaders.nim
Created March 15, 2021 01:19
WIP, translating Nim code to GLSL
import glm
import macros
import sets
import strformat
import strutils
import tables
macro shader*(n: typed) =
n.expectKind(nnkStmtList)
let astFile = n.lineInfoObj.filename & ".ast"
@garettbass
garettbass / bitset.h
Last active May 6, 2021 16:45
A generic-length bitset in C
#pragma once
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
//------------------------------------------------------------------------------
typedef uint64_t bitset_block_t;
using UnityEditor;
using UnityEngine;
using UnityEditor.Animations;
using System.IO;
public class CreateBlendTreeAsset
{
[MenuItem("Assets/Create/Animation Blend Tree", priority = 402)]
private static void CreateBlendTree()
{
@garettbass
garettbass / Utilities.cs
Created October 1, 2020 18:29
Some C# utility methods that came in handy recently
public static void Swap<T>(ref T a, ref T b) => (a,b)=(b,a);
public static void Sort<T>(ref T a, ref T b, ref T c, Comparison<T> comparison)
{
if (comparison(a, b) > 0) Swap(ref a, ref b);
if (comparison(a, c) > 0) Swap(ref a, ref c);
if (comparison(b, c) > 0) Swap(ref b, ref c);
}
@garettbass
garettbass / clang_sections.c
Last active June 23, 2020 20:28
Enumerating section symbols with clang/gcc (https://repl.it/@garettbass/clangsections)
#include <stdio.h>
#define CONCAT(A, B) _CONCAT(A, B)
#define _CONCAT(A, B) A##B
#define TOSTRING(...) _TOSTRING(__VA_ARGS__)
#define _TOSTRING(...) #__VA_ARGS__
#ifdef SECTION_DEFINITIONS
#define _section_declaration_definition(SECTION) section_definition(SECTION)