added example turtle program
This commit is contained in:
parent
21387cd8e7
commit
0540cc465a
31
src/bin/turtle/Patrol.hx
Normal file
31
src/bin/turtle/Patrol.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package bin.turtle;
|
||||
|
||||
import kernel.turtle.TurtleMutex;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
|
||||
class Patrol implements Process {
|
||||
private var handle:ProcessHandle;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function run(handle:ProcessHandle) {
|
||||
this.handle = handle;
|
||||
|
||||
if (!handle.claimTurtleMutex()) {
|
||||
handle.writeLine("Failed to claim turtle mutex");
|
||||
handle.close();
|
||||
}
|
||||
|
||||
handle.writeLine("Patroling");
|
||||
|
||||
TurtleMutex.runInTThread(() -> {
|
||||
while (true) {
|
||||
kernel.turtle.Turtle.forward();
|
||||
kernel.turtle.Turtle.forward();
|
||||
kernel.turtle.Turtle.forward();
|
||||
kernel.turtle.Turtle.turnLeft();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package kernel.binstore;
|
||||
|
||||
import bin.turtle.Patrol;
|
||||
import bin.pathfinder.PFClient;
|
||||
import bin.ID;
|
||||
import bin.exporter.Res;
|
||||
@ -41,7 +42,8 @@ class BinStore {
|
||||
{c: ResManager, name: "ResManager", aliases: ["resmanager", "resmgr"]},
|
||||
{c: Res, name: "Res", aliases: ["res"]},
|
||||
{c: ID, name: "ID", aliases: ["id"]},
|
||||
{c: PFClient, name: "PFClient", aliases: ["pfclient"]}
|
||||
{c: PFClient, name: "PFClient", aliases: ["pfclient"]},
|
||||
{c: Patrol, name: "Patrol", aliases: ["patrol"]}
|
||||
];
|
||||
|
||||
public static function getBinByName(name:String):Null<Bin> {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package kernel.ps;
|
||||
|
||||
import kernel.turtle.TurtleMutex;
|
||||
import kernel.ps.ProcessManager.PID;
|
||||
import kernel.ui.WindowContext;
|
||||
import kernel.ui.WindowManager;
|
||||
@ -104,7 +105,19 @@ class ProcessHandle {
|
||||
this.deferFuncs.push(func);
|
||||
}
|
||||
|
||||
function get_args():ReadOnlyArray<String> {
|
||||
public function get_args():ReadOnlyArray<String> {
|
||||
return this.config.args;
|
||||
}
|
||||
|
||||
public function claimTurtleMutex():Bool {
|
||||
if (TurtleMutex.claim(this.pid)) {
|
||||
this.addDeferFunc(() -> {
|
||||
TurtleMutex.release(this.pid);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class TurtleMutex {
|
||||
private static function release(pid:PID) {
|
||||
if (claimedPid == pid) {
|
||||
claimedPid = -1;
|
||||
stopTurtleThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user