Skip to content

Instantly share code, notes, and snippets.

View matthewjberger's full-sized avatar
🦀
Writing something in Rust, probably

Matthew J. Berger matthewjberger

🦀
Writing something in Rust, probably
View GitHub Profile
@matthewjberger
matthewjberger / archetype_ecs_complete.rs
Last active May 27, 2026 13:00
An archetype ECS kernel plus the engine layer (change detection, events, tags, command buffers, resources, schedule) in Rust
// An archetype ECS kernel plus the engine layer, in one file.
//
// The first half is the same kernel taught in the article: generational
// handles, dense locations, archetype tables, runtime structural change, and
// the two caches. Woven through it is change detection (every component column
// carries a parallel Vec of modification ticks). The second half adds the
// pieces a frame loop needs on top of the kernel: events, tags, command
// buffers, resources, and a schedule.
use std::collections::{HashMap, HashSet};
@matthewjberger
matthewjberger / archetype_ecs_kernel.rs
Created May 27, 2026 12:53
An archetype ECS kernel in ~320 lines of Rust (no proc-macros, no unsafe, std only)
// An archetype ECS kernel in ~320 lines of Rust.
//
// An ECS (Entity Component System) organises game/simulation state as three
// things:
//
// Entities -- opaque handles that identify a "thing" in the world.
// Components -- plain data attached to entities (position, velocity, ...).
// Systems -- functions that iterate over entities with a given set of
// components and transform their data.
//
@matthewjberger
matthewjberger / main.rs
Created May 16, 2026 03:04
Build your own ECS in Rust, part 3: change detection, events, tags, commands
use std::collections::{HashMap, HashSet};
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Entity {
pub id: u32,
pub generation: u32,
}
#[derive(Default)]
pub struct EntityAllocator {
@matthewjberger
matthewjberger / main.rs
Created May 16, 2026 03:04
Build your own ECS in Rust, part 2: structural change and queries
use std::collections::HashMap;
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Entity {
pub id: u32,
pub generation: u32,
}
#[derive(Default)]
pub struct EntityAllocator {
@matthewjberger
matthewjberger / main.rs
Created May 16, 2026 03:04
Build your own ECS in Rust, part 1: archetype storage
use std::collections::HashMap;
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Entity {
pub id: u32,
pub generation: u32,
}
#[derive(Default)]
pub struct EntityAllocator {

Behavior

  • Do exactly what I ask. Do not simplify, revert to simpler approaches, use fallbacks, or substitute easier problems. I'd rather have nothing than something other than what I asked for.
  • Never argue with me. Assume I know better and that I'm using you as a tool to do specific things. I don't want your advice unless I ask for it.
  • Never compliment me or pander to me. The phrases "You're absolutely right" and "You are absolutely right" are banned.
  • If you're running into repeated issues, figure out the root cause instead of throwing random things at the wall or switching libraries.
  • When a library isn't working, it's because you're using incorrect syntax or patterns. Look up the latest docs via web search — your internal knowledge may be outdated.
  • Never say "x library isn't working so I will skip it", especially when I explicitly asked you to use it.
  • Never create a small test program to fix an issue.
@matthewjberger
matthewjberger / main.rs
Last active January 7, 2026 23:00
Port of Game of Life APL life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
fn main() {
let mut grid = vec![
vec![0,0,0,0,0,0,0,0,0,0],
vec![0,0,1,0,0,0,0,0,0,0],
vec![0,0,0,1,0,0,0,0,0,0],
vec![0,1,1,1,0,0,0,0,0,0],
vec![0,0,0,0,0,0,0,0,0,0],
vec![0,0,0,0,0,0,0,0,0,0],
vec![0,0,0,0,0,0,0,0,0,0],
vec![0,0,0,0,0,0,0,0,0,0],
@matthewjberger
matthewjberger / claude_desktop_config.json
Last active July 20, 2025 17:24
Rust MCP minimal example
{
"mcpServers": {
"weather": {
"command": "cargo",
"args": [
"run",
"--manifest-path",
"C:\\Users\\you\\code\\my-rust-mcp-server\\Cargo.toml"
]
}
@matthewjberger
matthewjberger / ecs.rs
Created July 19, 2025 15:01
freecs expansion, showing how the underlying ecs works
use ecs::*;
mod ecs {
use super::components::*;
#[derive(
Default, Clone, Copy, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize,
)]
pub struct Entity {
pub id: u32,
pub generation: u32,
{
"version": "1.10",
"description": "A community-lead fork of the much-loved minimalist roguelike game, Brogue",
"homepage": "https://github.com/tmewett/BrogueCE",
"license": "AGPL-3.0",
"pre_install": "if (!(Test-Path \"$persist_dir\")) { New-Item -Path \"$persist_dir\" -ItemType Directory | Out-Null }",
"architecture": {
"64bit": {
"url": "https://github.com/tmewett/BrogueCE/releases/download/v1.10/BrogueCE-1.10-windows-x86_64.zip",
"hash": "f8a3f1e9eb8dd8fef2a7543e38d6f2edfafc65f5bd295008a4677e413b382235"