From b9622a1b6e1ec0922f71e4b164d85e86772e2b9d Mon Sep 17 00:00:00 2001 From: Kayh Date: Thu, 27 Jun 2024 17:41:57 -0400 Subject: [PATCH] wired-input refactor --- spatial/wit/wired-event/emitter.wit | 4 ---- spatial/wit/wired-event/listener.wit | 2 -- spatial/wit/wired-event/world.wit | 6 ------ spatial/wit/wired-input/api.wit | 6 ------ spatial/wit/wired-input/deps/wired-gltf | 1 + spatial/wit/wired-input/deps/wired-math | 1 + spatial/wit/wired-input/handler.wit | 16 --------------- spatial/wit/wired-input/method.wit | 3 --- spatial/wit/wired-input/types.wit | 14 ++++++------- spatial/wit/wired-input/world.wit | 27 ++++++++++++++++++------- 10 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 spatial/wit/wired-event/emitter.wit delete mode 100644 spatial/wit/wired-event/listener.wit delete mode 100644 spatial/wit/wired-event/world.wit delete mode 100644 spatial/wit/wired-input/api.wit create mode 120000 spatial/wit/wired-input/deps/wired-gltf create mode 120000 spatial/wit/wired-input/deps/wired-math delete mode 100644 spatial/wit/wired-input/handler.wit delete mode 100644 spatial/wit/wired-input/method.wit diff --git a/spatial/wit/wired-event/emitter.wit b/spatial/wit/wired-event/emitter.wit deleted file mode 100644 index 755cf14..0000000 --- a/spatial/wit/wired-event/emitter.wit +++ /dev/null @@ -1,4 +0,0 @@ -/// Event emitter. -interface emitter { - emit: func(msg: string, data: any); -} diff --git a/spatial/wit/wired-event/listener.wit b/spatial/wit/wired-event/listener.wit deleted file mode 100644 index 691006a..0000000 --- a/spatial/wit/wired-event/listener.wit +++ /dev/null @@ -1,2 +0,0 @@ -/// Event listener. -interface listener {} diff --git a/spatial/wit/wired-event/world.wit b/spatial/wit/wired-event/world.wit deleted file mode 100644 index a92ae0c..0000000 --- a/spatial/wit/wired-event/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wired:event; - -world imports { - interface emitter; - interface listener; -} diff --git a/spatial/wit/wired-input/api.wit b/spatial/wit/wired-input/api.wit deleted file mode 100644 index 643374c..0000000 --- a/spatial/wit/wired-input/api.wit +++ /dev/null @@ -1,6 +0,0 @@ -interface api { - use handler.{spatial-handler}; - - register-handler: func(handler: spatial-handler) -> u32; - delete-handler: func(id: u32); -} diff --git a/spatial/wit/wired-input/deps/wired-gltf b/spatial/wit/wired-input/deps/wired-gltf new file mode 120000 index 0000000..93743e2 --- /dev/null +++ b/spatial/wit/wired-input/deps/wired-gltf @@ -0,0 +1 @@ +../../wired-gltf/ \ No newline at end of file diff --git a/spatial/wit/wired-input/deps/wired-math b/spatial/wit/wired-input/deps/wired-math new file mode 120000 index 0000000..967f496 --- /dev/null +++ b/spatial/wit/wired-input/deps/wired-math @@ -0,0 +1 @@ +../../wired-math/ \ No newline at end of file diff --git a/spatial/wit/wired-input/handler.wit b/spatial/wit/wired-input/handler.wit deleted file mode 100644 index 0b4f9c6..0000000 --- a/spatial/wit/wired-input/handler.wit +++ /dev/null @@ -1,16 +0,0 @@ -interface handler { - use types.{input-event}; - use wired:spatial/node.{node}; - - /// Input handler. - /// Represents an object in 3D space that can react to input. - /// Handlers can optionally capture the input method, stopping propagation to other handlers. - resource spatial-handler { - /// The node that this handler is attached to. - node: func() -> node; - - /// Called when an input event is received. - /// Return true to capture the event. - on-input: func(event: input-event) -> bool; - } -} diff --git a/spatial/wit/wired-input/method.wit b/spatial/wit/wired-input/method.wit deleted file mode 100644 index 5e3935f..0000000 --- a/spatial/wit/wired-input/method.wit +++ /dev/null @@ -1,3 +0,0 @@ -/// Input method. -/// Represents a single point of interaction (3D pointer, hand, finger tip). -interface method {} diff --git a/spatial/wit/wired-input/types.wit b/spatial/wit/wired-input/types.wit index c73efbe..4414325 100644 --- a/spatial/wit/wired-input/types.wit +++ b/spatial/wit/wired-input/types.wit @@ -19,7 +19,7 @@ interface types { metacarpal: joint, } - /// Hand tracking data. + // Hand tracking data. record hand { side: hand-side, @@ -34,13 +34,13 @@ interface types { elbow: option, } - /// A line with an origin and a direction. + // A line with an origin and a direction. record ray { origin: vec3, orientation: quat, } - /// A single point of interaction, such as the tip of a stylus. + // A single point of interaction, such as the tip of a stylus. record tip { origin: vec3, orientation: quat, @@ -54,13 +54,13 @@ interface types { } record input-event { - /// Unique id for the event. + // Unique id for the event. id: u64, - /// Spatial input data. + // Spatial input data. input: input-type, - /// Distance from the input method to the handler. + // Distance from the input method to the handler. distance: f32, - /// How many handlers received the event before this one. + // How many handlers received the event before this one. order: u32, } } diff --git a/spatial/wit/wired-input/world.wit b/spatial/wit/wired-input/world.wit index 10d5a9f..6fc0897 100644 --- a/spatial/wit/wired-input/world.wit +++ b/spatial/wit/wired-input/world.wit @@ -1,12 +1,25 @@ package wired:input; -world imports { +world host { import handler; - import method; - import types; - import api; } -world host { - export api; -} +interface handler { + use types.{input-event}; + use wired:gltf/node.{node}; + + // Input handler. + // Represents an object in 3D space that can react to input. + // Handlers can optionally capture the input method, stopping propagation to other handlers. + resource spatial-handler { + constructor(node: borrow); + + // Handle the next recieved input event. + // Events only last for one tick. + handle-input: func() -> option; + } +} + +// Input method. +// Represents a single point of interaction (3D pointer, hand, finger tip). +interface method {}