continuing to try to make simple world programs run.
This commit is contained in:
parent
a0b1c7e196
commit
b034624402
|
@ -73,6 +73,7 @@ EXPORTS['to-draw'] =
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
||||||
|
return new OnDraw(f);
|
||||||
// FILL ME IN
|
// FILL ME IN
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ EXPORTS['to-draw'] =
|
||||||
|
|
||||||
EXPORTS['stop-when'] =
|
EXPORTS['stop-when'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'to-draw',
|
'stop-when',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
||||||
|
|
|
@ -24,6 +24,8 @@ var bigBang = function(MACHINE, initW, handlers) {
|
||||||
var toplevelNode = $('<div/>').css('border', '2').appendTo(document.body);
|
var toplevelNode = $('<div/>').css('border', '2').appendTo(document.body);
|
||||||
|
|
||||||
var configs = [];
|
var configs = [];
|
||||||
|
var isOnDrawSeen = false;
|
||||||
|
|
||||||
for (var i = 0 ; i < handlers.length; i++) {
|
for (var i = 0 ; i < handlers.length; i++) {
|
||||||
if (isWorldConfigOption(handlers[i])) {
|
if (isWorldConfigOption(handlers[i])) {
|
||||||
configs.push(handlers[i].toRawHandler(MACHINE));
|
configs.push(handlers[i].toRawHandler(MACHINE));
|
||||||
|
@ -31,7 +33,14 @@ var bigBang = function(MACHINE, initW, handlers) {
|
||||||
else {
|
else {
|
||||||
configs.push(handlers[i]);
|
configs.push(handlers[i]);
|
||||||
}
|
}
|
||||||
|
if (isOnDraw(handlers[i])) { isOnDrawSeen = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we haven't seen an onDraw function, use the default one.
|
||||||
|
if (! isOnDrawSeen) {
|
||||||
|
configs.push(new DefaultOnDraw().toDrawHandler(MACHINE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PAUSE(function(restart) {
|
PAUSE(function(restart) {
|
||||||
|
|
||||||
|
@ -149,18 +158,20 @@ OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype);
|
||||||
|
|
||||||
OnTick.prototype.toRawHandler = function(MACHINE) {
|
OnTick.prototype.toRawHandler = function(MACHINE) {
|
||||||
var worldFunction = function(world, k) {
|
var worldFunction = function(world, k) {
|
||||||
plt.baselib.functions.internalCallDuringPause(
|
console.log('about to call the on-tick');
|
||||||
MACHINE,
|
k(world + 1);
|
||||||
this.handler,
|
// plt.baselib.functions.internalCallDuringPause(
|
||||||
function(v) {
|
// MACHINE,
|
||||||
k(v);
|
// this.handler,
|
||||||
},
|
// function(v) {
|
||||||
|
// k(v);
|
||||||
|
// },
|
||||||
|
|
||||||
function(err) {
|
// function(err) {
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
return rawJsworld.on_tick(worldFunction, this.delay);
|
return rawJsworld.on_tick(this.delay, worldFunction);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,6 +180,51 @@ OnTick.prototype.toRawHandler = function(MACHINE) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// OnDraw
|
||||||
|
|
||||||
|
var OnDraw = function(handler) {
|
||||||
|
WorldConfigOption.call(this, 'on-tick');
|
||||||
|
this.handler = handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
OnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype);
|
||||||
|
|
||||||
|
OnDraw.prototype.toRawHandler = function(MACHINE) {
|
||||||
|
var worldFunction = function(world, k) {
|
||||||
|
console.log('about to call the on-draw');
|
||||||
|
// FIXME: call the handler instead!
|
||||||
|
k(plt.baselib.format.toDomNode(world));
|
||||||
|
};
|
||||||
|
var cssFunction = function(w, k) { k([]); }
|
||||||
|
return rawJsworld.on_draw(worldFunction, cssFunction);
|
||||||
|
};
|
||||||
|
|
||||||
|
var isOnDraw = plt.baselib.makeClassPredicate(OnDraw);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var DefaultOnDraw = function() {
|
||||||
|
WorldConfigOption.call(this, 'on-tick');
|
||||||
|
};
|
||||||
|
|
||||||
|
DefaultOnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype);
|
||||||
|
|
||||||
|
DefaultOnDraw.prototype.toRawHandler = function(MACHINE) {
|
||||||
|
var worldFunction = function(world, k) {
|
||||||
|
console.log('about to call the on-draw');
|
||||||
|
k(plt.baselib.format.toDomNode(world));
|
||||||
|
};
|
||||||
|
var cssFunction = function(w, k) { k([]); }
|
||||||
|
return rawJsworld.on_draw(worldFunction, cssFunction);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user