Skip to content

Instantly share code, notes, and snippets.

@triplefox
triplefox / gist:0edbfd1a14af0f5513f1
Last active August 29, 2015 14:14
Version 3 - the "most correct" iteration
class Node
{
public var ci : Array<Int>; /* channel in */
public var co : Array<Int>; /* channel out */
public var i : Int; /* id */
public var b : Int; /* behavior */
public var a : Bool; /* alive */
public function new(i,a) { ci = []; co = []; this.i = i; this.b = -1; this.a = a; }
}
@triplefox
triplefox / bmp32.nim
Created February 10, 2015 11:25
BMP32 writer
import endians
import sdl2
import sdl2.image
discard IMG_Init
proc loadImage*(filename:string):PSurface=
var suce = IMG_Load(cstring(filename))
type
Array32Part{.unchecked.} = array[0..0, float32]
Buffer32 = ref object
samples: int
bytes: int
data: ptr Array32Part
proc AllocBuffer32(samples : int): Buffer32 =
let bytes = samples * (sizeof(float32))
Buffer32(samples: samples, bytes : bytes, data: cast[ptr Array32Part](alloc0(bytes)))
when isMainModule:
import strutils
import common
import vector2
import vector3
import euler
import quaternion
import math3
import math
type Thing = ref object
x* : float
var t0 : Thing; new(t0);
var r0 : ref float = cast[ref float](addr(t0.x))
t0.x = 10.0
doAssert(r0[] == 10.0)
discard """
Slactuate - a rude tweening library.
Copyright © 2015 James W. Hofmann
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense,
luastate.register("matchEntity", proc (state : PState):cint {.cdecl.} =
var i1 = (state.tointeger(-1)); state.pop(1)
var i0 = (state.tointeger(-1)); state.pop(1)
if not game.matchtile:
let arch0 = game.entity[game.matcha].d[0]
let arch1 = game.entity[game.matchb].d[0]
if (arch0 == i0 and arch1 == i1):
state.pushboolean(cint(true))
@triplefox
triplefox / gist:a052f52b11b664cce31f
Created March 24, 2015 19:16
Snippets from Urobo
/* Urobo, a videogame engine. Strength through self-reference.
* By James Walter Hofmann.
*/
/***********
ENUMS
***********/
enum AttributeType
{
#include <stdio.h>
#include <stdlib.h>
int collide(int data[25], int collision_mapping[3]) {
int collision = 0;
int i0 = 0;
for (i0 = 0; i0 < 25; i0++ )
{
collision += collision_mapping[data[i0]];
}
@triplefox
triplefox / Empty.hx
Last active November 10, 2015 07:15
Graphics1 problem
package;
import kha.Framebuffer;
import kha.Game;
import kha.Image;
import kha.Loader;
import kha.Configuration;
import kha.Scaler;
import kha.Color;