This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stack | |
empty : Π(τ:U) Stack_(τ,Z) | |
push : Π(τ:U, t:τ, s:Stack_(τ,n)) Stack_(τ,n+1) | |
pop : Π(τ:U, s:Stack_(τ,S(n))) (τ × Stack_(τ,n)) | |
pop_push : Π(τ:U, s:Stack_(τ,n), i:τ) (pop ∘ push i) s ≡ i × s | |
Vector | |
peek : Π(τ:U, n:N, i:Fin_n, Vector_(τ,i)) τ | |
poke : Π(τ:U, n:N, i:Fin_n, t:τ, Vector_(τ,i)) Vector_(τ,i) | |
peek_poke : Π(τ:U, n:N, i:Fin_n, v:Vector_(τ,i), t:τ) (peek i ∘ poke i t) v ≡ t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Unity.Entities; | |
[Serializable] | |
[GenerateAuthoringComponent] | |
public struct FluidLike : IComponentData { | |
public float density; | |
public float lagrangeMultiplier; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Unity.NetCode; | |
using Unity.Entities; | |
[Serializable] | |
[GenerateAuthoringComponent] | |
public struct TriggerPlate : IComponentData { | |
public enum TriggerState { JustTriggered, Triggered, JustUnTriggered, UnTriggered } | |
[GhostField] public bool Active; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parse_int = | |
then(or(match('-'), of('')), => s | |
then(many(isNumber), => digits | |
of(Number(s + digits)))) | |
/* | |
in ML-style lang, this might look like this: | |
parse_int = do | |
s <- match '-' <|> unit '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HDR = '#SOURCE' | |
const compile = (f) => { try { return eval(f) } catch (e) { return new Error(f) } } | |
const ser = (_, f) => f instanceof Error ? HDR + f.message : f instanceof Function ? HDR + f.toString() : f | |
const des = (_, f) => f.indexOf && f.indexOf(0, HDR) ? compile(f.slice(HDR.length)) : f | |
var o = { | |
goodFn: () => 5, | |
badFn: new Error('() =>< 6') | |
} | |
var o2 = JSON.parse(JSON.stringify(o, ser), des) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function raf<T> (f: (t: T) => Promise<T>, t: T): Promise<T> { | |
return new Promise(res => requestAnimationFrame(_ => res(f(t)))) as Promise<T> | |
} | |
async function forever<T> (f: (t: T) => Promise<T>, t: T): Promise<T> { | |
return await f(t).then(t1 => forever(f, t1)) | |
} | |
async function update (state: T): Promise<T> { | |
// Your update logic here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
There are often sequences of behavior that happen over time in complex applications. Sometimes these | |
are animations, sometimes sequences of async actions, and sometimes both. We would thus like to define | |
a simple way to express our intent without having to jump through incredible mental hurdles or use limited | |
features of libaries/frameworks (state transitions and tweens being chief among these) to get the work done. | |
Here is some code that shows an approach I have been developing for modeling these behaviors in javascript itself | |
using the re-entrant properties of generators. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
When creating typed arrays (Float32Array etc) in javascript you often need | |
to first create a plan Array and then pass it to the typed array constructor | |
to get out the final memory-packed typed array. | |
In a tight gameloop, these arrays can be very large and allocating the | |
javascript array is undesireable as it puts additional GC pressure on your | |
app which has memory implications and also may produce jutter on devices that | |
interupt the main javascript thread to do GC. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This gist is just a quick example of the same function written | |
in a composable manner (using prodash.js). Please understand | |
that the functions exported by prodash are almost ALL curried | |
by default allowing them to be partially applied. | |
The goal of this code is to iterate through a list of "particles" | |
and return a Float32Array of their x,y,z components. Only living | |
particles should be included. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Object -> Node -- constructor | |
let Node = (hash) => { | |
this.id = hash.id || new UUID() | |
this.value = hash | |
this.parentId = null | |
this.childIds = [] | |
} | |
//-> Graph -- constructor | |
let Graph = () => { |
NewerOlder