Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowAfterlife committed Jul 28, 2015
1 parent 7a7a8c8 commit 63cdd5e
Show file tree
Hide file tree
Showing 28 changed files with 1,991 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
dump/
Nothing__
hxpico8.hxproj
p8demo/
35 changes: 35 additions & 0 deletions Array.hx
@@ -0,0 +1,35 @@
package;

/**
* ...
* @author YellowAfterlife
*/
#if !macro
class Array<T> {

}
#else
extern class Array<T> {
var length(default,null) : Int;
function new() : Void;
function concat( a : Array<T> ) : Array<T>;
function join( sep : String ) : String;
function pop() : Null<T>;
function push(x : T) : Int;
function reverse() : Void;
function shift() : Null<T>;
function slice( pos : Int, ?end : Int ) : Array<T>;
function sort( f : T -> T -> Int ) : Void;
function splice( pos : Int, len : Int ) : Array<T>;
function toString() : String;
function unshift( x : T ) : Void;
function insert( pos : Int, x : T ) : Void;
function remove( x : T ) : Bool;
function indexOf( x : T, ?fromIndex:Int ) : Int;
function lastIndexOf( x : T, ?fromIndex:Int ) : Int;
function copy() : Array<T>;
function iterator() : Iterator<T>;
function map<S>( f : T -> S ) : Array<S>;
function filter( f : T -> Bool ) : Array<T>;
}
#end
25 changes: 25 additions & 0 deletions Collection.hx
@@ -0,0 +1,25 @@
package;

/**
* List maps to a Lua array.
* Indexes start at 1.
* @author YellowAfterlife
*/
abstract Collection<T>(Array<T>) {
public inline function new() {
this = [];
}
@:from public static inline function create<T>(values:Array<T>):Collection<T> {
return Pico.collection(values);
}
//
public var size(get, never):Int;
private inline function get_size():Int return Pico.count(this);
//
public inline function add(value:T):Void Pico.add(this, value);
public inline function del(value:T):Void Pico.del(this, value);
public inline function remove(value:T):Void Pico.del(this, value);
public inline function iterator():Iterator<T> {
return Pico.all(this);
}
}
7 changes: 7 additions & 0 deletions Fixed.hx
@@ -0,0 +1,7 @@
package;

/**
*
* @author YellowAfterlife
*/
typedef Fixed = Float;
14 changes: 14 additions & 0 deletions HxOverrides.hx
@@ -0,0 +1,14 @@
package;

@:noDoc
extern class HxOverrides {
static function dateStr( date :Date ) : String;
static function strDate( s : String ) : Date;
static function cca( s : String, index : Int ) : Null<Int>;
static function substr( s : String, pos : Int, ?len : Int ) : String;
static function indexOf<T>( a : Array<T>, obj : T, i : Int) : Void;
static function lastIndexOf<T>( a : Array<T>, obj : T, i : Int) : Void;
static function remove<T>( a : Array<T>, obj : T ) : Void;
static function iter<T>( a : Array<T> ) : Iterator<T>;

}
141 changes: 141 additions & 0 deletions Map.hx
@@ -0,0 +1,141 @@
package;
#if !macro
//{ Pico
/**
* Map equivalent in GameMaker. No GC/ARC - call destroy() to free memory.
* @author YellowAfterlife
*/
@:forward abstract Map<K, V>(Dynamic) {
public inline function new() {
this = { };
}
@:arrayAccess public inline function get(key:K):V {
return untyped this[key];
}
public inline function set(key:K, value:V):Void {
untyped this[key] = value;
}
@:arrayAccess public inline function arrayWrite(key:K, value:V):V {
return untyped this[key] = value;
}
}
//}
#elseif (haxe_ver >= 3.2)
//{ Haxe >= 3.2
import haxe.ds.StringMap;
import haxe.ds.IntMap;
import haxe.ds.HashMap;
import haxe.ds.ObjectMap;
import haxe.ds.WeakMap;
import haxe.ds.EnumValueMap;
import haxe.Constraints.IMap;

@:multiType(K) abstract Map<K,V>(IMap<K,V> ) {
public function new();
public inline function set(key:K, value:V) this.set(key, value);
@:arrayAccess public inline function get(key:K) return this.get(key);
public inline function exists(key:K) return this.exists(key);
public inline function remove(key:K) return this.remove(key);
public inline function keys():Iterator<K> {
return this.keys();
}
public inline function iterator():Iterator<V> {
return this.iterator();
}
public inline function toString():String {
return this.toString();
}
@:arrayAccess @:noCompletion public inline function arrayWrite(k:K, v:V):V {
this.set(k, v);
return v;
}
@:to static inline function toStringMap<K:String,V>(t:IMap<K,V>):StringMap<V> {
return new StringMap<V>();
}
@:to static inline function toIntMap<K:Int,V>(t:IMap<K,V>):IntMap<V> {
return new IntMap<V>();
}
@:to static inline function toEnumValueMapMap<K:EnumValue,V>(t:IMap<K,V>):EnumValueMap<K,V> {
return new EnumValueMap<K, V>();
}
@:to static inline function toObjectMap<K:{ },V>(t:IMap<K,V>):ObjectMap<K,V> {
return new ObjectMap<K, V>();
}
@:from static inline function fromStringMap<V>(map:StringMap<V>):Map< String, V > {
return cast map;
}
@:from static inline function fromIntMap<V>(map:IntMap<V>):Map< Int, V > {
return cast map;
}
@:from static inline function fromObjectMap<K:{ }, V>(map:ObjectMap<K,V>):Map<K,V> {
return cast map;
}
}

@:deprecated typedef IMap<K, V> = haxe.Constraints.IMap<K, V>;
//}
#else
//{ Haxe < 3.2
import haxe.ds.StringMap;
import haxe.ds.IntMap;
import haxe.ds.HashMap;
import haxe.ds.ObjectMap;
import haxe.ds.WeakMap;
import haxe.ds.EnumValueMap;
@:multiType(K) abstract Map<K,V>(IMap<K,V> ) {
public function new();
public inline function set(key:K, value:V) this.set(key, value);
@:arrayAccess public inline function get(key:K) return this.get(key);
public inline function exists(key:K) return this.exists(key);
public inline function remove(key:K) return this.remove(key);
public inline function keys():Iterator<K> {
return this.keys();
}
public inline function iterator():Iterator<V> {
return this.iterator();
}
public inline function toString():String {
return this.toString();
}
@:arrayAccess @:noCompletion public inline function arrayWrite(k:K, v:V):V {
this.set(k, v);
return v;
}
@:to static inline function toStringMap(t:IMap<String,V>):StringMap<V> {
return new StringMap<V>();
}
@:to static inline function toIntMap(t:IMap<Int,V>):IntMap<V> {
return new IntMap<V>();
}
@:to static inline function toEnumValueMapMap<K:EnumValue>(t:IMap<K,V>):EnumValueMap<K,V> {
return new EnumValueMap<K, V>();
}
@:to static inline function toObjectMap<K:{ }>(t:IMap<K,V>):ObjectMap<K,V> {
return new ObjectMap<K, V>();
}
@:from static inline function fromStringMap<V>(map:StringMap<V>):Map< String, V > {
return map;
}
@:from static inline function fromIntMap<V>(map:IntMap<V>):Map< Int, V > {
return map;
}
@:from static inline function fromObjectMap<K:{ }, V>(map:ObjectMap<K,V>):Map<K,V> {
return map;
}
}

interface IMap<K,V> {
public function get(k:K):Null<V>;
public function set(k:K, v:V):Void;
public function exists(k:K):Bool;
public function remove(k:K):Bool;
public function keys():Iterator<K>;
public function iterator():Iterator<V>;
public function toString():String;
}

private typedef Hashable = {
function hashCode():Int;
}
//}
#end
41 changes: 41 additions & 0 deletions Math.hx
@@ -0,0 +1,41 @@
package;

/**
* ...
* @author YellowAfterlife
*/
extern class Math {
static inline function abs(f:Float):Float return Pico.abs(f);
static inline function sign(f:Float):Int return Pico.sign(f);
static inline function min(a:Float, b:Float):Float return Pico.min(a, b);
static inline function max(a:Float, b:Float):Float return Pico.max(a, b);
static inline function mid(a:Float, b:Float, c:Float):Float return Pico.mid(a, b, c);
static inline function clamp(f:Float, a:Float, b:Float):Float {
return Pico.mid(f, a, b);
}
// integer shortcuts:
static inline function iabs(i:Int):Int return cast Pico.abs(i);
static inline function imin(a:Int, b:Int):Int return cast Pico.min(a, b);
static inline function imax(a:Int, b:Int):Int return cast Pico.max(a, b);
static inline function imid(a:Int, b:Int, c:Int):Int return cast Pico.mid(a, b, c);
static inline function iclamp(f:Int, a:Int, b:Int):Int {
return cast Pico.mid(f, a, b);
}
// trig:
static inline var PI:Float = 1.0;
static inline function sin(r:Float):Float return Pico.sin(r);
static inline function cos(r:Float):Float return Pico.cos(r);
static inline function tan(r:Float):Float {
return sin(r) / cos(r);
}
static inline function atan2(y:Float, x:Float):Float {
return Pico.atan2(x, y);
}
//
static inline function sqrt(f:Float):Float return Pico.sqrt(f);
//
static inline function floor(f:Float):Int return Pico.flr(f);
static inline function ceil(f:Float):Int return -Pico.flr( -f);
//
static inline function random():Float return Pico.rand(1);
}

0 comments on commit 63cdd5e

Please sign in to comment.