Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
@martinwells
martinwells / Int64Utils.hx
Created April 2, 2014 22:23
Convert an int64 to a float and back
import haxe.Int64;
class Int64Utils
{
private inline static var MAX_32_PRECISION = 4294967296;
public static function fromFloat(f:Float):Int64 {
return Int64.make(Std.int(f/MAX_32_PRECISION), Std.int(f-(f/MAX_32_PRECISION)));
}
@martinwells
martinwells / FPSCounter.hx
Last active August 29, 2015 13:57
Low impact FPS counter
class FPSCounter extends TextField
{
public var currentFPS (default, null):Float;
private var cacheCount:Int;
private var times:Array <Float>;
private var lastUIUpdate:Float;
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000, fontSize:Int=24) {
@martinwells
martinwells / gist:9539270
Created March 13, 2014 23:24
Cut up an image into chunks
var bitmapData = Assets.getBitmapData(bitmapPath);
_fullWidth = bitmapData.width;
_fullHeight = bitmapData.height;
_chunkSize = chunkSize;
_lastChunkRect = new Rectangle();
_currentChunkRect = new Rectangle();
// it's different! remove the old cached chunk data
FileUtils.rmdir(_cachePath);
@martinwells
martinwells / gist:9419622
Created March 7, 2014 20:41
Launch image for android
class Main extends Sprite
{
private var doneFrame:Bool;
public function new()
{
super();
doneFrame = false;
graphics.beginFill(0xff5555);
@martinwells
martinwells / gist:9243014
Created February 27, 2014 02:17
dump a sprite stack
public function dumpSpriteStack(sprite:Sprite)
{
trace(spriteToString(sprite));
var parent:Sprite = cast sprite.parent;
var c = 1;
while (parent != null)
{
var indent = '.';
for (i in 0...c)
@martinwells
martinwells / gist:8815829
Created February 5, 2014 01:24
Bash: find size of all files (recursively) using a given name/extension
find . -name "*.png" -mtime -1 | du | awk '{total+=$1} END{print total}'
@martinwells
martinwells / gist:8813653
Created February 4, 2014 22:29
Haxe generic type comparison
public function compareTypes(a:Dynamic, b:Dynamic)
{
return (Type.getClass(a) != null) ? (Type.getClass(a) == Type.getClass(b)) : (Type.typeof(a) == Type.typeof(b));
}
@martinwells
martinwells / gist:6108911
Created July 29, 2013 23:46
structs in haxe
@:publicFields class Struct
{
public function new() {}
}
class MyStruct extends Struct
{
var field1:String;
var field2:String;
var field3:Bool;
@martinwells
martinwells / gist:6091295
Created July 26, 2013 18:49
PrioritizedQueue class
import haxe.ds.ObjectMap;
/*
Simple prioritized queue. Throw objects at it and you'll always get back things according
to a priority you set. Priorities are retained internally, so you don't need to modify your
objects.
Usage:
// create a queue:
@martinwells
martinwells / gist:6084333
Created July 25, 2013 22:24
How to extend haxe map classes
// Since you can't do:
// class MyMap<String, String> extends Map<String, String>
// Try...
import haxe.ds.ObjectMap;
class ObjectMyMap extends ObjectMap<String, String>
{