From 7bab2f1b7a413ac1b73a1b9c626e9277ba6e43f2 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 22 May 2025 01:28:03 -0500 Subject: [PATCH] clean up graphics --- examples/chess/main.js | 7 +++++-- scripts/core/io.js | 1 - scripts/modules/draw2d.js | 38 ++----------------------------------- scripts/modules/graphics.js | 3 +++ 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/examples/chess/main.js b/examples/chess/main.js index ffe80095..1d62a2f1 100644 --- a/examples/chess/main.js +++ b/examples/chess/main.js @@ -262,9 +262,12 @@ function drawPieces() { } } +var graphics = use('graphics') + prosperon.on('draw', function() { drawBoard() drawPieces() + draw2d.text("HELL", [100,100]) }) prosperon.on('key_down', function(e) { @@ -317,14 +320,14 @@ function joinServer() { } $_.contact(contact_fn, { - address: "localhost", + address: "192.168.0.149", port: 5678 }); } var os = use('os') - // Set up IO actor subscription +// Set up IO actor subscription var ioguy = { __ACTORDATA__: { id: os.ioactor() diff --git a/scripts/core/io.js b/scripts/core/io.js index 66807baa..ac53fa72 100644 --- a/scripts/core/io.js +++ b/scripts/core/io.js @@ -11,7 +11,6 @@ var os = use('os') $_.receiver(e => { if (e.type === "subscribe") { if (!e.actor) throw Error('Got a subscribe message with no actor.'); - console.log('subscribing: ' + json.encode(e.actor)) subscribers.push(e.actor) return; } diff --git a/scripts/modules/draw2d.js b/scripts/modules/draw2d.js index 5c22afd4..55d4758a 100644 --- a/scripts/modules/draw2d.js +++ b/scripts/modules/draw2d.js @@ -419,33 +419,6 @@ draw.image = function image(image, rect = [0,0], rotation = 0, anchor = [0,0], s render.image(image, rect, rotation, anchor, shear, info) } -draw.images = function images(image, rects, config) { - if (!image) throw Error('Need an image to render.') - if (typeof image === "string") image = graphics.texture(image) - var bb = [] - bb.width = image.texture.width - bb.height = image.texture.height - var sprites = [] - for (var rect of rects) { - rect.__proto__ = bb - var sprite = graphics.make_sprite() - sprite.set_rect(rect) - sprite.set_image(image) - sprites.push(sprite) - } - var cmds = graphics.make_sprite_queue(sprites, prosperon.camera, undefined) - for (var i = 0; i < cmds.length; i++) - render.queue(cmds[i]) - return sprites -} -draw.images[prosperon.DOC] = ` -:param image: An image object or string path to a texture. -:param rects: An array of rectangle objects ({x, y, width, height}) to draw. -:param config: (Unused) Additional config data if needed. -:return: An array of sprite objects created and queued for rendering. -:raises Error: If no image is provided. -` - function software_circle(pos, radius) { if (radius <= 0) return // nothing to draw @@ -486,15 +459,8 @@ var sysfont = graphics.get_font('fonts/c64.ttf', 8) draw.text = function text(text, rect, font = sysfont, size = 0, color = Color.white, wrap = 0, pipeline) { if (typeof font === 'string') font = graphics.get_font(font) var mesh = graphics.make_text_buffer(text, rect, 0, color, wrap, font) - render.queue({ - type: 'geometry', - mesh, - image: font, - texture: font.texture, - pipeline, - first_index:0, - num_indices:mesh.num_indices - }) + console.log(json.encode(mesh)) + render.geometry(font, mesh) } draw.text[prosperon.DOC] = ` :param text: The string to draw. diff --git a/scripts/modules/graphics.js b/scripts/modules/graphics.js index 5fe1deea..b5b9c42c 100644 --- a/scripts/modules/graphics.js +++ b/scripts/modules/graphics.js @@ -308,6 +308,9 @@ graphics.get_font = function get_font(path, size) { var font = graphics.make_font(data,size) font.texture = render.load_texture(font.surface) + console.log('loaded font texture') + console.log(json.encode(font.texture)) + fontcache[fontstr] = font return font