Skip to content

Instantly share code, notes, and snippets.

View ncannasse's full-sized avatar

Nicolas Cannasse ncannasse

View GitHub Profile
@ncannasse
ncannasse / Test.hx
Created December 16, 2013 12:56
Perfs Check
class Test {
static function fib(x) {
if( x <= 0 ) return 1;
return fib(x-1) + fib(x-2);
}
static function writeFile() {
var b = haxe.io.Bytes.alloc(65000);
for( i in 0...2 ) {
enum Error<T> {
Code( i : Int ) : Error<Int>;
Message( s : String ) : Error<String>;
}
function getError<T>( e : Error<T> ) : T {
switch( e ) {
case Code(c): return c;
case Message(s): return s;
}
package haxe;
class MainEvent {
var f : Void -> Void;
var prev : MainEvent;
var next : MainEvent;
public var priority(default,null) : Int;
public function new(f,p) {
@ncannasse
ncannasse / MainLoop.hx
Created March 6, 2016 16:09
version 2, adds delay()
package haxe;
class MainEvent {
var f : Void -> Void;
var prev : MainEvent;
var next : MainEvent;
public var nextRun(default,null) : Float;
public var priority(default,null) : Int;
package haxe;
/**
If haxe.MainLoop is kept from DCE, then we will insert an haxe.EntryPoint.run() call just at then end of main().
This class can be redefined by custom frameworks so they can handle their own main loop logic.
**/
class EntryPoint {
/**
Wakeup a sleeping run()
class NormalShader2D extends hxsl.Shader {
static var SRC = {
@:import h3d.shader.Base2d;
@param var normalMap : Sampler2d;
function fragment() {
var n = unpackNormal(normalMap.get(calculatedUV));
var light = vec3(1,2,3).normalize();
var lum = light.dot(n).saturate();
pixelColor.rgb *= lum;
}
# go to Northgard install dir
cd "~/Library/Application Support/Steam/SteamApps/common/Northgard/osx"
# fallback fo newest dir
cd "~/Library/Application Support/Steam/steamapps/common/Northgard/osx"
# remove shipped libraries which requires AVX CPU support
rm -rf libmbed* libogg* libvorbis* libopenal* libpng* libSDL* libturbojpeg*
# download and install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install required libraries
brew install libpng jpeg-turbo libvorbis sdl2 mbedtls openal-soft libuv
package domkit;
using StringTools;
enum abstract MToken(Int) {
var IGNORE_SPACES;
var BEGIN;
var BEGIN_NODE;
var BEGIN_CODE;
var CODE_IDENT;
abstract MyArray<T>(#if java java.NativeArray<T> #else Array<T> #end) {
public inline function new(size:Int) {
#if java
this = new java.NativeArray(size);
#else
this = new Array();
if( size > 0 ) this[size-1] = cast null;
#end
}
abstract MyArray<T>(#if java java.NativeArray<T> #else Array<T> #end) {
public inline function new(size:Int) {
#if java
this = new java.NativeArray(size);
#else
this = new Array();
if( size > 0 ) this[size-1] = cast null;
#end
}