Skip to content

Instantly share code, notes, and snippets.

[header one]
a$[]thing
a$[]other thing
b[,]1,2,3,4
[header two]
a[]thing
a[]other thing
b[,]1,2,3,4
package com.ludamix.ds;
class Deli
{
/*
Deli - "Better than your usual hashmap"
A syntax that maps text data to lists of numbers and strings by declaration,
vs. by position and context as in most textual formats.
@triplefox
triplefox / Slactuate.hx
Created December 20, 2014 08:43
Slactuate, a one file tween library for Haxe
class Slactuate
{
/* how to use: build your own abstraction on m() and p() to ease the setting of properties. call u() each frame you update, then call c() to cleanup. */
public var td /*tween datas*/ = new Array<SlacTween>();
public function new(){}
public function u/*update to the given time*/(t : Float) { for (n in td) n.u(t); }
public function c/*clear tweens updated to past their end time, and return the removed ones*/() {
var i = td.length - 1; var r = new Array<SlacTween>(); if (td.length < 1) return r;
while (i >= 0) { var n = td[i]; if (n.ci > 1.) {r.push(td.splice(i, 1)[0]); } i -= 1; }
return r; }
@triplefox
triplefox / Main.hx
Created December 20, 2014 08:49
demo for Slactuate
import flash.Lib;
import flash.display.Shape;
class Main
{
public static var sp : Shape;
public static var slac : Slactuate;
static function main()
@triplefox
triplefox / ExampleEventSys.hx
Created December 20, 2014 11:55
Example event system
class Eventsys
{
public var entities = new Map<Int, IEntity>();
public function new(){}
/* raw spawning tools. instantiate and assign parameters to entities with your own configuration mechanism. */
public function spawn(e : IEntity, id : Int) { if (entities.exists(id)) { throw "overlapping entity id"; } e.id = id; entities.set(id, e); }
public function despawn(e : IEntity) { entities.remove(e.id); }
# Generate and playback a sine tone
import sdl2
import sdl2/audio
import math
# Audio settings:
const Channels = 1
const RQSizeInSamples = 4096 * Channels
type Uniforms = object
faefar:GLint # fade factor
tee:array[0..1,GLint] # textures
type Attributes = object
pon:GLint # position
type Resources = object
vexbur, eltbur:GLuint # vertex, element buffers
tee:array[0..1,GLuint] # textures
vexshr, frtshr:GLuint # vertex, element shaders
prm:GLuint # program
# Generate and playback a sine tone
import sdl2
import sdl2/audio
import math
# Audio settings requested:
const RQBufferSizeInSamples = 4096
const RQBytesPerSample = 2 # 16 bit PCM
const RQBufferSizeInBytes = RQBufferSizeInSamples * RQBytesPerSample
@triplefox
triplefox / gist:b64eb859b4152dc5ae5c
Created January 16, 2015 11:53
Data types for 2d sprite packing tool
type
DataEntry* = object
k:string # key
v:int # value
Rect* = object
x:int
y:int
w:int # width
h:int # height
d:seq[DataEntry] # metadata
type
GLFloatBufferPart{.unchecked.} = array[0..0, GLfloat]
GLFloatBuffer* = ref tuple
data : ptr GLFloatBufferPart
samples : int
bytes : int
# i want to expand this to all the GL numeric types through a generic: