debugging to-draw

This commit is contained in:
Danny Yoo 2011-07-19 14:07:26 -04:00
parent 0af05ce21a
commit 90b836ef12
5 changed files with 98 additions and 24 deletions

View File

@ -8,10 +8,16 @@ handler
"big bang should follow:" "big bang should follow:"
(define (draw w)
(circle w 'solid 'blue))
(big-bang 1 (big-bang 1
(on-tick add1 1) (on-tick add1 1)
;(on-tick (lambda (w) (* w 2)) 1) ;(on-tick (lambda (w) (* w 2)) 1)
(stop-when (lambda (w) (> w 10))) (stop-when (lambda (w) (> w 10)))
(to-draw draw)
) )

View File

@ -71,7 +71,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); return new ToDraw(f);
}); });

View File

@ -1,3 +1,7 @@
var imageLibrary = MACHINE.modules['whalesong/image/private/main.rkt'].privateExports;
var isImage = imageLibrary.isImage;
var PAUSE = plt.runtime.PAUSE; var PAUSE = plt.runtime.PAUSE;
@ -26,7 +30,7 @@ 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; var isOutputConfigSeen = 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])) {
@ -35,12 +39,12 @@ var bigBang = function(MACHINE, initW, handlers) {
else { else {
configs.push(handlers[i]); configs.push(handlers[i]);
} }
if (isOnDraw(handlers[i])) { isOnDrawSeen = true; } if (isOutputConfig(handlers[i])) { isOutputConfigSeen = true; }
} }
// If we haven't seen an onDraw function, use the default one. // If we haven't seen an onDraw function, use the default one.
if (! isOnDrawSeen) { if (! isOutputConfigSeen) {
configs.push(new DefaultOnDraw(toplevelNode.get(0)).toRawHandler(MACHINE)); configs.push(new DefaultDrawingOutput(toplevelNode.get(0)).toRawHandler(MACHINE));
} }
@ -160,40 +164,95 @@ OnTick.prototype.toRawHandler = function(MACHINE) {
// // OnDraw var OutputConfig = function() {}
OutputConfig.prototype = plt.baselib.heir(WorldConfigOption.prototype);
var isOutputConfig = plt.baselib.makeClassPredicate(OutputConfig);
var OnDraw = function(handler) {
WorldConfigOption.call(this, 'on-draw');
// // ToDraw
var ToDraw = function(handler) {
WorldConfigOption.call(this, 'to-draw');
this.handler = handler; this.handler = handler;
}; };
OnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype); ToDraw.prototype = plt.baselib.heir(OutputConfig.prototype);
OnDraw.prototype.toRawHandler = function(MACHINE) { ToDraw.prototype.toRawHandler = function(MACHINE) {
var worldFunction = function(world, k) { var that = this;
// FIXME: call the handler instead! var reusableCanvas;
k(plt.baselib.format.toDomNode(world)); var reusableCanvasNode;
var toplevelNode = this.toplevelNode;
var adaptedWorldFunction = adaptWorldFunction(this.handler);
var worldFunction = function(world, success) {
adaptedWorldFunction(
world,
function(v) {
// fixme: once jsworld supports fail continuations, use them
// to check the status of the scene object and make sure it's an
// image.
if (isImage(v) ) {
var width = v.getWidth();
var height = v.getHeight();
if (! reusableCanvas) {
reusableCanvas = imageLibrary.makeCanvas(width, height);
// Note: the canvas object may itself manage objects,
// as in the case of an excanvas. In that case, we must make
// sure jsworld doesn't try to disrupt its contents!
reusableCanvas.jsworldOpaque = true;
reusableCanvasNode = rawJsworld.node_to_tree(reusableCanvas);
}
reusableCanvas.width = width;
reusableCanvas.height = height;
var ctx = reusableCanvas.getContext("2d");
v.render(ctx, 0, 0);
success(rawJsworld.node_to_tree(reusableCanvasNode));
} else {
success(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(v)));
}
});
}; };
var cssFunction = function(w, k) { k([]); }
var cssFunction = function(w, k) {
if (reusableCanvas) {
k([[reusableCanvas,
["width", reusableCanvas.width + "px"],
["height", reusableCanvas.height + "px"]]]);
} else {
k([]);
}
}
return rawJsworld.on_draw(worldFunction, cssFunction); return rawJsworld.on_draw(worldFunction, cssFunction);
}; };
var isOnDraw = plt.baselib.makeClassPredicate(OnDraw);
var DefaultOnDraw = function(toplevelNode) {
WorldConfigOption.call(this, 'on-draw');
this.toplevelNode = toplevelNode;
var DefaultDrawingOutput = function(toplevelNode) {
WorldConfigOption.call(this, 'to-draw');
// this.toplevelNode = toplevelNode;
}; };
DefaultOnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype); DefaultDrawingOutput.prototype = plt.baselib.heir(WorldConfigOption.prototype);
DefaultOnDraw.prototype.toRawHandler = function(MACHINE) { DefaultDrawingOutput.prototype.toRawHandler = function(MACHINE) {
var that = this; var that = this;
var worldFunction = function(world, k) { var worldFunction = function(world, k) {
k([that.toplevelNode, // k([that.toplevelNode,
rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]); // rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]);
k(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world)));
}; };
var cssFunction = function(w, k) { k([]); } var cssFunction = function(w, k) { k([]); }
return rawJsworld.on_draw(worldFunction, cssFunction); return rawJsworld.on_draw(worldFunction, cssFunction);
@ -202,6 +261,10 @@ DefaultOnDraw.prototype.toRawHandler = function(MACHINE) {
//////////////////////////////////////////////////////////////////////
var StopWhen = function(handler) { var StopWhen = function(handler) {
WorldConfigOption.call(this, 'stop-when'); WorldConfigOption.call(this, 'stop-when');
this.handler = handler; this.handler = handler;

View File

@ -1,11 +1,13 @@
#lang s-exp "../lang/js/js.rkt" #lang s-exp "../lang/js/js.rkt"
(require "../image.rkt")
(declare-implementation (declare-implementation
#:racket "racket-impl.rkt" #:racket "racket-impl.rkt"
#:javascript ( #:javascript (
;; the raw implementation doesn't know anything about ;; the raw implementation doesn't know anything about
;; Whalesong. ;; Whalesong.
"private/raw-jsworld.js" "raw-jsworld.js"
;; We add Whalesong-specific things here. ;; We add Whalesong-specific things here.
"kernel.js" "kernel.js"
@ -14,4 +16,7 @@
#:provided-values (big-bang #:provided-values (big-bang
on-tick on-tick
to-draw to-draw
stop-when)) stop-when))