This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ComponentId{ | |
case Velocity | |
case Position | |
case Size | |
func describe()->NSString{ | |
return "\(self.hashValue)" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation OMDeferred (FailWithResult) | |
-(void)fail:(NSError *)error withResult:(id)result{ | |
NSAssert(error, @"Error object should not be nil"); | |
NSAssert(error.domain, @"Error object should have a domain"); | |
if(result){ | |
NSMutableDictionary *newUserInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo]; | |
newUserInfo[ERROR_RESULT_KEY] = result; | |
error = [NSError errorWithDomain:error.domain code:error.code userInfo:newUserInfo.copy]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Entitas; | |
public class PositionComponent : IComponent { | |
public int x, y; | |
public PositionComponent(int x, int y) | |
{ | |
this.x = x; | |
this.y = y; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public typealias Action = ()->Void | |
/** | |
Bounced action takes interval and action to return another action, which limits the rate at which provided action can be fired. | |
It is like a bouncer at a discotheque. He will act on your questions only after you shut up for 'interval' of time. | |
This technique is important if you have action wich should fire on update, however the updates coming in to frequently sometimes. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private protocol List{ | |
var tail : List {get} | |
} | |
private struct EmptyList : List{ | |
var tail : List { | |
return EmptyList() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum EnumList<T> { | |
case Cons(T, EnumList<T>) | |
case Nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let list = 1 => 2 => 3 => nil | |
println("\(list.value)") //1 | |
for value in list { | |
println(value) // 1 2 3 | |
} | |
let l1 = list[0] | |
let l2 = list[5] | |
let l3 = list[2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func measureArray(){ | |
let time = NSDate() | |
var a = [0] | |
for i in 1...1_000{ | |
a.append(i) | |
} | |
let after = NSDate() | |
println("\(after.timeIntervalSince1970 - time.timeIntervalSince1970) Array 1K") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Box<T>{ | |
let value : T | |
init(_ value : T ){ | |
self.value = value | |
} | |
} | |
enum EList<T> { | |
case Cons(Box<T>, Box<EList>) // Box the value T to work around a runtime deadlock bug in Swift | |
case Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func measureList(){ | |
let time = NSDate() | |
var a = 0 => nil | |
for i in 1...1_000{ | |
a = i => a | |
} | |
let after = NSDate() | |
println("\(after.timeIntervalSince1970 - time.timeIntervalSince1970) List 1K") | |
} |
OlderNewer