Skip to content

Instantly share code, notes, and snippets.

@TheGag96
TheGag96 / Game_Of_Life.jai
Created September 23, 2024 21:48
GPU-accelerated Conway's Game of Life
Simp :: #import "Simp";
Input :: #import "Input";
#import "Basic";
#import "Random";
#import "Math";
#import "Window_Creation";
#import "GL";
Render_Texture :: struct {
@TheGag96
TheGag96 / Bitfields.jai
Last active August 2, 2024 20:39
An implementation of bitfields in Jai
// Tries to implement bitfields in the most ergonomic way I can think of.
// Inspired in part by what D's standard library did before the language supported bitfields.
#insert #run bitfields_struct(
"Thing",
bf("a", u32, 4),
bf("b", u32, 4),
bf("c", s32, 4),
bf("d", u32, 4),
);
@TheGag96
TheGag96 / build_cross_gcc
Last active July 23, 2023 17:27 — forked from preshing/build_cross_gcc
Raspberry Pi x64 Cross GCC build script
#! /bin/bash
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT
#-------------------------------------------------------------------------------------------
# This script will download packages for, configure, build and install a GCC cross-compiler.
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
# If you get an error and need to resume the script from some point in the middle,
# just delete/comment the preceding lines before running it again.
@TheGag96
TheGag96 / main.c
Created May 26, 2020 02:40
gpusprites example, but print out spritesheet load time
// Simple citro2d sprite drawing example
// Images borrowed from:
// https://kenney.nl/assets/space-shooter-redux
#include <citro2d.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@TheGag96
TheGag96 / staticforeach.d
Last active March 28, 2020 20:04
Static foreach example
void func(size_t size)() {
static foreach (p; 0..size) {
perform_some_action(p);
}
}
void perform_some_action(size_t p) {
import std.stdio : writeln;
writeln(p);
}
@TheGag96
TheGag96 / soa.d
Created March 11, 2020 02:32
D SOA example
import std.string : format;
struct Soa(T, long n) {
static foreach (member; T.tupleof) {
mixin(format("typeof(member)[n] %s;", member.stringof));
}
T opIndex(size_t index) const {
T result = void;
// Simple citro2d sprite drawing example
// Images borrowed from:
// https://kenney.nl/assets/space-shooter-redux
#include <citro2d.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
import std.stdio, std.range, std.algorithm;
static immutable int[] KEYS = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4];
void main() {
stdin.byLine.dropOne.each!((i, line) => writefln("Case #%d: %d", i+1, line.map!(c => (c == ' ' ? 1 : KEYS[c - 'a'])).sum));
}