Skip to content

Instantly share code, notes, and snippets.

@EmmaEwert
EmmaEwert / cpu.rs
Created August 8, 2021 08:36
Rust code for the CPU of a Game Boy
use std::mem::MaybeUninit;
use crate::log;
use crate::emulator::*;
pub struct CPU {
pub emulator: *mut Emulator,
b: u8,
c: u8,
d: u8,
e: u8,
@EmmaEwert
EmmaEwert / Blit.cs
Created March 17, 2021 12:28
Distortion Blit in Universal Render Pipeline
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class Blit : ScriptableRendererFeature {
public Settings settings = new Settings();
private Pass pass;
public override void Create() =>

StarCat Signal

StarCat Signal seeks to emulate a universe as we expect it to be 7.4 billion years from now, enabling you and me to discover its secrets.

This document describes the technical approaches in StarCat Signal

Apple Pie

A procedure for generating the vast variability in the structure of space -- which gives rise to an entire universe -- is elusive.

Application of such a procedure in a technically feasible way is doubly elusive. Computers, while unbelievably efficient, are not able to simulate even the number of galaxies (~1 trillion) in our universe, much less the hundreds of billions of individual stars and planets in each of those galaxies.

namespace Project {
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[UpdateInGroup(typeof(SimulationSystemGroup))]
public class DigTaskStartSystem : JobComponentSystem {
@EmmaEwert
EmmaEwert / Reflection.shader
Last active April 11, 2019 20:58
Reflection Camera -> Render Texture -> Material with Reflection shader
Shader "Unlit/Custom/Reflection" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Tint ("Tint", Color) = (1,1,1,1)
_Intensity ("Intensity", Range(0, 1)) = 0.5
_Speed ("Speed", Range(0, 1)) = 0.5
_Scale ("Scale", Range(0, 1)) = 0.5
_Contrast ("Contrast", Range(0, 1)) = 0.5
}
SubShader {

Pokémon Mercury (codename) for Gameboy/Color

Possible name duos, from best to worst:

  • Cyan & Magenta (CMYK, but Yellow is already taken)
  • Rose & Lavender (flowers, why not)
  • Amethyst & Lapis (my favourite gemstones)
  • Dark & Light (unused concepts)
  • Mercury & Lead (metals like Gold and Silver)

Enable socket recycle and reuse, connection settings:

# as root
echo "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn = 1024" >> /etc/sysctl.conf

Enable zswap, tweak swappiness:

@EmmaEwert
EmmaEwert / FastLog2.cs
Created August 23, 2018 15:09
Very fast C# implementation of `Log2`, returns nearest integer rounding up.
int FastLog2(float x) => (x.GetHashCode() >> 23) - 127;
@EmmaEwert
EmmaEwert / FirstPersonInputModule.cs
Created August 17, 2018 13:19
Replacement for Unity's StandaloneInputModule, world-space UI now reacts to first person locked cursor, screen center being the pointer position.
using UnityEngine;
using UnityEngine.EventSystems;
public class FirstPersonInputModule : StandaloneInputModule {
protected override MouseState GetMousePointerEventData(int id) {
var lockState = Cursor.lockState;
Cursor.lockState = CursorLockMode.None;
var mouseState = base.GetMousePointerEventData(id);
Cursor.lockState = lockState;
return mouseState;
@EmmaEwert
EmmaEwert / BayerMatrix64.shader
Created August 9, 2018 00:06
Precomputed 64×64 Bayer Matrix for realtime dithering
static const int Indices[4096] = {
0, 3584, 896, 3360, 224, 3808, 840, 3528, 56, 3640, 952, 3347, 211, 3795, 883, 3571, 15, 3599, 911, 3375, 239, 3823, 836, 3524, 52, 3636, 948, 3356, 220, 3804, 892, 3580, 2, 3586, 898, 3362, 226, 3810, 842, 3530, 58, 3642, 954, 3345, 209, 3793, 881, 3569, 13, 3597, 909, 3373, 237, 3821, 838, 3526, 54, 3638, 950, 3358, 222, 3806, 894, 3582,
2987, 1792, 2240, 1120, 2912, 2016, 2072, 1176, 2968, 1848, 2296, 1107, 2899, 2003, 2087, 1191, 2983, 1807, 2255, 1135, 2927, 2031, 2068, 1172, 2964, 1844, 2292, 1116, 2908, 2012, 2089, 1193, 2985, 1794, 2242, 1122, 2914, 2018, 2074, 1178, 2970, 1850, 2298, 1105, 2897, 2001, 2085, 1189, 2981, 1805, 2253, 1133, 2925, 2029, 2070, 1174, 2966, 1846, 2294, 1118, 2910, 2014, 2091, 1195,
747, 3136, 448, 4032, 560, 3248, 280, 3864, 728, 3192, 504, 4088, 519, 3207, 295, 3879, 743, 3151, 463, 4047, 575, 3263, 276, 3860, 724, 3188, 500, 4084, 521, 3209, 297, 3881, 745, 3138, 450, 4034, 562, 3250, 282, 3866, 730, 3194, 506, 4090, 517, 3205, 293,