Created
May 27, 2013 08:17
-
-
Save aliyome/28015e3e60d4c0bec419 to your computer and use it in GitHub Desktop.
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 std.stdio : writeln; | |
import std.array : empty; | |
import core.thread : Fiber; | |
//class C { | |
//public: | |
// void onload(void delegate() f) { | |
// f(); | |
// } | |
// void start() { | |
// actor.update(); | |
// } | |
// Actor actor; | |
//} | |
class Actor { | |
this(int x, int y) { | |
_x = x; | |
_y =y; | |
} | |
void update() { | |
//if (!_updates.empty) { | |
// _updates[0](); | |
// writeln(_x, `,`, _y); | |
//} | |
if (!_fibers.empty) { | |
writeln(_fibers[0].call(true)); | |
writeln(_x, `,`, _y); | |
} | |
} | |
auto moveBy(int x, int y, int f) { | |
//_updates ~= { | |
// auto fiber = new Fiber({ | |
// foreach (i; 0 .. f) { | |
// writeln(i); | |
// _x += x; | |
// _y += y; | |
// Fiber.yield(); | |
// } | |
// }); | |
// fiber.call(); | |
//}; | |
_fibers ~= new Fiber({ | |
foreach (i; 0 .. f) { | |
writeln(i); | |
_x += x; | |
_y += y; | |
Fiber.yield(); | |
} | |
}); | |
writeln("hoge"); | |
return this; | |
} | |
private: | |
int _x, _y; | |
void delegate()[] _updates; | |
Fiber[] _fibers; | |
} | |
unittest { | |
auto a = new Actor(0, 0); | |
a.moveBy(10, 0, 10); | |
foreach (i; 0 .. 50) | |
a.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment