Nicolas Cannasse 13 vuotta sitten
vanhempi
commit
feeeafd096
3 muutettua tiedostoa jossa 0 lisäystä ja 134 poistoa
  1. 0 63
      Key.hx
  2. 0 42
      Rand.hx
  3. 0 29
      Timer.hx

+ 0 - 63
Key.hx

@@ -1,63 +0,0 @@
-class Key {
-
-	static var fl_initDone = false;
-	static var kcodes = new Array<Null<Int>>();
-
-	static var ktime = 0;
-
-	public static function init() {
-		var stage = flash.Lib.current.stage;
-		if (fl_initDone) {
-			stage.removeEventListener(flash.events.Event.ENTER_FRAME,onEnterFrame);
-			stage.addEventListener(flash.events.Event.ENTER_FRAME,onEnterFrame);
-			return;
-		}
-		fl_initDone = true;
-		
-		
-		stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN,callback(onKey,true));
-		stage.addEventListener(flash.events.KeyboardEvent.KEY_UP,callback(onKey,false));
-		stage.addEventListener(flash.events.Event.DEACTIVATE,function(_) kcodes = new Array());
-		stage.addEventListener(flash.events.Event.ENTER_FRAME,onEnterFrame);
-	}
-	
-	static function onEnterFrame(_) {
-		ktime++;
-	}
-
-	static function onKey( down, e : flash.events.KeyboardEvent ) {
-		event(e.keyCode, down);
-	}
-
-	public static function event( code, down ) {
-		kcodes[code] = down ? ktime : null;
-		// release Ctrl when Alt pressed (AltGr generates Ctrl+Alt)
-		if( code == 18 && !down )
-			kcodes[17] = null;
-	}
-
-
-	public static function isDown(c) {
-		return kcodes[c] != null;
-	}
-
-	public static function isToggled(c) {
-		return kcodes[c] == ktime;
-	}
-	
-	public static function stopAll() {
-		kcodes = [];
-	}
-
-	public static function enableJSKeys(objName:String) {
-		try {
-			flash.external.ExternalInterface.addCallback("onKeyEvent",#if !flash9 null,#end event);
-			var r : Null<Bool> = flash.external.ExternalInterface.call("function() { var fla = window.document['"+objName+"']; if( fla == null ) return false; document.onkeydown = function(e) { if( e == null ) e = window.event; fla.onKeyEvent(e.keyCode,true); }; document.onkeyup = function(e) { if( e == null ) e = window.event; fla.onKeyEvent(e.keyCode,false); }; return true; }");
-			if( r == null ) r = false;
-			return r;
-		} catch( e : Dynamic ) {
-			return false;
-		}
-	}
-
-}

+ 0 - 42
Rand.hx

@@ -1,42 +0,0 @@
-// Parker-Miller-Carta LCG
-
-
-class Rand {
-
-	var seed : Float;
-
-	public function new( seed : Int ) {
-		this.seed = hash(((seed < 0) ? -seed : seed) + 151);
-	}
-
-	public static function hash(n) {
-		for( i in 0...5 ) {
-			n ^= (n << 7) & 0x2b5b2500;
-			n ^= (n << 15) & 0x1b8b0000;
-			n ^= n >>> 16;
-			n &= 0x3FFFFFFF;
-			var h = 5381;
-			h = (h << 5) + h + (n & 0xFF);
-			h = (h << 5) + h + ((n >> 8) & 0xFF);
-			h = (h << 5) + h + ((n >> 16) & 0xFF);
-			h = (h << 5) + h + (n >> 24);
-			n = h & 0x3FFFFFFF;
-		}
-		return n;
-	}
-
-	public inline function random( n ) {
-		return int() % n;
-	}
-
-	public inline function rand() {
-		// we can't use a divider > 16807 or else two consecutive seeds
-		// might generate a similar float
-		return (int() % 10007) / 10007.0;
-	}
-
-	inline function int() : Int {
-		return Std.int(seed = (seed * 16807.0) % 2147483647.0) & 0x3FFFFFFF;
-	}
-
-}

+ 0 - 29
Timer.hx

@@ -1,29 +0,0 @@
-
-class Timer {
-
-	public static var wantedFPS = 32;
-	public static var maxDeltaTime = 0.5;
-	public static var oldTime = flash.Lib.getTimer();
-	public static var tmod_factor = 0.95;
-	public static var calc_tmod : Float = 1;
-	public static var tmod : Float = 1;
-	public static var deltaT : Float = 1;
-	static var frameCount = 0;
-
-	public inline static function update() {
-		frameCount++;
-		var newTime = flash.Lib.getTimer();
-		deltaT = (newTime - oldTime) / 1000.0;
-		oldTime = newTime;
-		if( deltaT < maxDeltaTime )
-			calc_tmod = calc_tmod * tmod_factor + (1 - tmod_factor) * deltaT * wantedFPS;
-		else
-			deltaT = 1 / wantedFPS;
-		tmod = calc_tmod;
-	}
-
-	public inline static function fps() : Float {
-		return wantedFPS/tmod ;
-	}
-
-}