Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael "Z" Goddard mzgoddard

View GitHub Profile
View pack.c
// packing a float in glsl with multiplication and fract
vec4 packFloat( float depth ) {
const vec4 bit_shift = vec4(
256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4(
0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
// fract is the problem
vec4 res = fract( depth * bit_shift );
View pack.c
// packing a float in glsl with multiplication and mod
vec4 packFloat( float depth ) {
const vec4 bit_shift = vec4(
256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4(
0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
// combination of mod and multiplication and division works better
vec4 res = mod(
depth * bit_shift * vec4( 255 ),
View pack.js
// packing a float in javascript using multiplication and bitwise operators
function packFloat( texarray, posX, posY, num ) {
var index = ( posX + posY * texarray.width ) * 4;
texarray[ index ] = ( num * 256 * 256 * 256 * 256 ) & 255;
texarray[ index + 1 ] = ( num * 256 * 256 * 256 ) & 255;
texarray[ index + 2 ] = ( num * 256 * 256 ) & 255;
texarray[ index + 3 ] = ( num * 256 ) & 255;
}
@mzgoddard
mzgoddard / actionlist.js
Created Sep 18, 2012
GameLoop and Network stubs
View actionlist.js
// Actions should only store primitive values, when acting it'll look up stuff in a given idSetHash to act on
function Action() {}
// should be false if it shouldn't be cleared from a statebag, example player add / remove actions
Action.prototype.canClear = true
// some deserialized actions may produce a graphics effect, but otherwise their side effects should already be a part of the state?
// flags is an object determining if client, server, or under prediction or lockstep
Action.prototype.act = function( actionList, idSetHash, flags ) {}
// serialize for network transmission
Action.serialize = function( encoder, action ) {
// return argsArray as compressedString
@mzgoddard
mzgoddard / has_tests.js
Created Sep 20, 2012 — forked from tJener/gist:3758415
commonjs/amd boilerplate
View has_tests.js
// shamlessly stolen from lodash
/*global define:false*/
;(function( window, undefined ) {
var freeExports = false;
// must be loaded first!
var has = window.has;
if ( typeof exports === 'object' ) {
freeExports = exports;
@mzgoddard
mzgoddard / actionlist.js
Created Oct 10, 2012
ActionList buffer changes
View actionlist.js
// classes that are buffered
Action.prototype.useBuffer = false;
ActionList.prototype.bufferList = new ActionList
ActionList.prototype.store = function( Action, ... || [ Action... ] ) {
if ( action.useBuffer ) {
this.bufferList.store( action );
}
// normal store stuff
}
@mzgoddard
mzgoddard / gist:4146599
Created Nov 26, 2012
pillar of feathers
View gist:4146599
Tall, statuesque
A beam of support
or ancient ornamentation
a pillar
Short, feathered
A parent of life
or pest removal
an owl
@mzgoddard
mzgoddard / gist:4671039
Created Jan 30, 2013
build instructions for OSX box2d emscripten
View gist:4671039
# https://gist.github.com/1974955
brew install node spider-monkey closure-compiler yuicompressor
brew install llvm --with-clang
git clone git://github.com/kripken/emscripten.git
cd emscripten
./emcc
(mate|vim|emacs) ~/.emscripten
# Change EMSCRIPTEN and LLVM defaults
View gist:4760384
screech, called grandpa
the taletall sounds of him walking down the hall
the knock of his of his stubbed leg
the flap of his creaking wing
coming around the wall
into the lounge, giving me a stare
An aged look, longing for youth but arrogant in age.
"Everything does not tick on forever"
View gist:6276974
✓ field of asteroids
✓ ignore particles
✓ ignore particle group
✓ leaper particle and trigger
✓ spawn on surface
✓ jump
✓ stick to new surface
- angle once stuck
✓ camera
✓ renderer, shaders, and views
You can’t perform that action at this time.