Skip to content

Instantly share code, notes, and snippets.

@rezich
rezich / widgets.jai
Last active February 28, 2026 22:50
Some ideas for how to structure a widget-based GUI editor system for a game, which demonstrate some advanced things you can do with the language—not all of which are necessarily advisable, but most if not all of which are hopefully educational
//
// Say you're making some kind of game that involves "Nodes" being placed around
// the game world, and you want to make an editor mode (disabled in release
// builds) that lets you create and manipulate these Nodes.
//
// Setting aside data serialization and an undo/redo system, here is a way that
// you could make such an editor system, that gives you an immediate-mode-ish
// API for easily creating editor-mode "widgets" each frame, with specific
// interaction and rendering behaviors for each different kind of "widget".
//
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rezich
rezich / Tagged_Union_Support.jai
Created January 26, 2026 22:08
Tagged enum set macro (Jai beta 0.2.025)
set :: (u: *$U, value: $T) {
TAG_CONSTANT_VALUE, TAG_MEMBER_OFFSET :: #run -> u64, s64 {
U_info, T_info := U.(*Type_Info_Struct), T.(*Type_Info);
TAGGED_UNION_FLAGS : Struct_Textual_Flags : .UNION | .UNION_IS_TAGGED;
assert(U_info.type == .STRUCT && U_info.textual_flags & TAGGED_UNION_FLAGS == TAGGED_UNION_FLAGS,
"% is not a tagged union.", U
);
assert(U_info.tagged_union_bindings.count > 0,
"% doesn't have any bindings.", U
# nch -- nim-based crappy hellhole
import sdl2, sdl2/gfx, sdl2.image, sdl2.ttf, basic2d, random, math
type
Input {.pure.} = enum none, quit, action
InputState {.pure.} = enum up, pressed, down, released
Game = ref object
input: array[Input, bool]
inputLast: array[Input, bool]
-- 11matches
module App exposing (..)
import Html exposing (..)
import Html.Attributes exposing (class, disabled)
import Html.Events exposing (onClick, onMouseDown, onMouseUp)
import Time exposing (Time, second)
module App exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Time exposing (Time, second)
-- MODEL
@rezich
rezich / citylib.cpp
Created March 3, 2017 20:30
Game Maker DLL example with state preserved between calls
#include <stdlib.h>
#define GMEXPORT extern "C" __declspec(dllexport)
struct City {
int population;
};
City *city;
GMEXPORT double city_init() {
@rezich
rezich / main.rs
Created January 5, 2017 20:46
learning Rust by making a game
/*
I'm learning Rust by making a game.
This game would be very simple to make, unsafely, in C/C++,
and I'm hoping that by making it in Rust, I'll learn the core concepts
of ownership and such.
But right now, I'm stuck.
Here's what I'm *trying* to do, in C++:

Keybase proof

I hereby claim:

  • I am adamrezich on github.
  • I am adamrezich (https://keybase.io/adamrezich) on keybase.
  • I have a public key whose fingerprint is 6FB9 D650 3CF3 8475 6730 3059 935F 087E 785F A003

To claim this, I am signing this object:

@rezich
rezich / nbajam.json
Created August 22, 2015 20:38
NBA Jam (arcade, v4.0) player stats in JSON form
[
{
"team": "Boston Celtics",
"name": "Xavier McDaniel",
"speed": 5,
"threePoint": 5,
"dunk": 5,
"pass": 1,
"power": 8,
"steal": 3,