aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-21 12:02:30 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-21 12:41:48 +0000
commit36f651c4e01143790b398cda3b5862cd7128e888 (patch)
tree3646609a745ebed9e8a07c20faecb5edf43c2cc4
parentlib: separate glsl-view video/tsv-input ops (diff)
downloadalive-36f651c4e01143790b398cda3b5862cd7128e888.tar.gz
alive-36f651c4e01143790b398cda3b5862cd7128e888.zip
lib: add love/tsv-output
-rw-r--r--alv-lib/love.moon41
-rw-r--r--alv/copilot/love/init.moon20
-rw-r--r--examples/love.alv4
3 files changed, 62 insertions, 3 deletions
diff --git a/alv-lib/love.moon b/alv-lib/love.moon
index 2fa7742..68a402f 100644
--- a/alv-lib/love.moon
+++ b/alv-lib/love.moon
@@ -1,5 +1,8 @@
import Constant, Op, PureOp, Input, Error, T, Array, any, sig from require 'alv.base'
import RTNode from require 'alv'
+tsv = do
+ ok, mod = pcall require, 'texture-share-vk'
+ ok and mod
unpack or= table.unpack
@@ -44,6 +47,28 @@ draw = Constant.meta
destroy: =>
COPILOT.drawlist[@state] = nil
+tsv_output = Constant.meta
+ meta:
+ name: 'tsv-output'
+ summary: "send rendered output via texture_share_vk."
+ examples: { '(love/tsv-output name)' }
+
+ value: class extends Op
+ setup: (inputs, scope) =>
+ name = sig.str\match inputs
+ @state or= tsv.new!
+
+ super
+ name: Input.hot name
+ size: Input.hot COPILOT.window_size
+
+ tick: =>
+ { :name, :size } = @unwrap_all!
+ COPILOT.tsv_canvas = @state\newSharedCanvas name, unpack size
+
+ destroy: =>
+ COPILOT.tsv_canvas = nil
+
no_shape = Constant.meta
meta:
name: 'no-shape'
@@ -446,6 +471,20 @@ If `key` is passed, outputs a bang! stream."
if event and event == key
@out\set true
+window_size = Constant.meta
+ meta:
+ name: 'window-size'
+ summary: "outputs window size."
+ examples: { '(love/window-size)' }
+ description: "vec2! stream of mouse wheel movements."
+
+ value: class extends Op
+ setup: (inputs) =>
+ assert #inputs == 0, Error "argument", "no arguments expected"
+ @out = COPILOT.window_size
+ super Input.hot @out
+
+ poll: =>
key_down = Constant.meta
meta:
@@ -524,6 +563,8 @@ macro [->>][]:
:translate, :rotate, :scale, :shear
:color, 'line-width': line_width
+ 'tsv-output': if tsv then tsv_output
+
'mouse-pos': mouse_pos
'mouse-delta': mouse_delta
'mouse-presses': mouse_presses
diff --git a/alv/copilot/love/init.moon b/alv/copilot/love/init.moon
index 83a45bf..f21e11d 100644
--- a/alv/copilot/love/init.moon
+++ b/alv/copilot/love/init.moon
@@ -25,14 +25,30 @@ class LoveCopilot extends CLICopilot
@key_releases = T.str\mk_evt!
@textinput = T.str\mk_evt!
+ w, h = love.window.getMode!
+ @window_size = vec2\mk_sig { w, h }
+
+ @tsv_canvas = nil
+
draw: =>
- love.graphics.origin!
+ love.graphics.reset!
love.graphics.clear!
+ if @tsv_canvas
+ love.graphics.setCanvas @tsv_canvas.canvas
+ love.graphics.clear!
+
for id, list in pairs @drawlist
for fn in *list
fn!
+ if @tsv_canvas
+ love.graphics.reset!
+
+ @tsv_canvas\send!
+ love.graphics.setBlendMode "alpha", "premultiplied"
+ love.graphics.draw @tsv_canvas.canvas
+
love.graphics.present!
run: =>
@@ -62,6 +78,8 @@ class LoveCopilot extends CLICopilot
@textinput\set a, true
when 'keyreleased'
@key_releases\set a, true
+ when 'resize'
+ @window_size\set { a, b }
--else
-- print "unhandled: '#{name}'", a,b,c,d,e,f
diff --git a/examples/love.alv b/examples/love.alv
index 113ea2d..0820085 100644
--- a/examples/love.alv
+++ b/examples/love.alv
@@ -24,5 +24,5 @@
([14]color smooth-color)
([15]scale ([34]smooth 0.2 ([16]switch ([17]mouse-down? 1) 0.5 1)))
([5]rotate ([9]ramp 2 tau)) #(rotate tau (2*PI) every 2 seconds)
- ([4]translate ([10]mouse-pos) #(move to mouse cursor)
-)))
+ ([4]translate ([10]mouse-pos)) #(move to mouse cursor)
+))