feat: bound scene visibility rendering and continuous native input

This commit is contained in:
2026-11-11 00:53:21 +08:00
parent 15fc01542c
commit 32d5da5528
15 changed files with 900 additions and 134 deletions
+10 -1
View File
@@ -54,7 +54,16 @@ It does not publish a page or change revision. Console does not use this endpoin
All execution endpoints share the eight-entry queue. These are in-process bounded
host executions, not a complete untrusted-code sandbox or a process-isolation design.
## Page modes and camera
## Layout, scenes and cameras
Use Page with nested Row / Column / Overlay for finite layout, ScrollView for
scrolling, and CanvasViewport(width,height,Scene2D(...)) for a finite view into
2D world coordinates. Each viewport owns an explicit Camera2D by default;
assigning the same camera shares navigation. Viewport3D provides the analogous
finite view into Scene3D using programmable perspective/orthographic cameras.
See docs/scene-architecture.md and examples/world-ui.endor for the current model.
### Legacy Page compatibility
Page.mode is "window" (default), "vertical", "horizontal" or "canvas".
Window fills the available page viewport. Vertical constrains width and grows
+22
View File
@@ -5281,6 +5281,28 @@ fn world_ui_example_runs_with_window_constraints_and_programmable_actions() {
)
.unwrap();
document.validate().unwrap();
let viewports = std::collections::BTreeMap::from([(
crate::window::MAIN_WINDOW,
crate::layout::Size {
width: 1024.,
height: 800.,
},
)]);
for _ in 0..3 {
assert!(
session
.resize_windows_incremental(&viewports, true)
.unwrap()
.is_none(),
"unchanged viewport must stay idle"
);
assert!(
session
.poll_tasks_incremental(&viewports)
.unwrap()
.is_none()
);
}
assert!(
document
.frame
+109 -4
View File
@@ -3,7 +3,10 @@ use serde::{Deserialize, Serialize};
use std::{
io::{Read, Write},
net::TcpStream,
sync::mpsc::{SyncSender, sync_channel},
sync::{
Arc, RwLock,
mpsc::{SyncSender, sync_channel},
},
thread,
time::Duration,
};
@@ -150,14 +153,25 @@ impl Input {
}
}
#[derive(Clone)]
pub struct Client(SyncSender<Input>);
impl Client {
pub fn new(proxy: EventLoopProxy<crate::app::AppEvent>) -> anyhow::Result<Self> {
let (sender, receiver) = sync_channel::<Input>(8);
pub fn new(
proxy: EventLoopProxy<crate::app::AppEvent>,
namespace: Arc<RwLock<crate::document::NamespaceState>>,
) -> anyhow::Result<Self> {
let (sender, receiver) = sync_channel::<Input>(64);
thread::Builder::new()
.name("tessera-native-events".into())
.spawn(move || {
for input in receiver {
for mut input in receiver {
if let Ok(current) = namespace.read() {
if !refresh_continuous_input(&mut input, &current) {
continue;
}
} else {
continue;
}
if let Err(error) = send(&input) {
let _ = proxy.send_event(crate::app::AppEvent::RuntimeFailed {
message: error.to_string(),
@@ -172,6 +186,48 @@ impl Client {
}
}
// Native gestures retain the captured Mount across publications. Refresh only
// the version at dequeue, never session, window or target. HTTP callers and
// discrete actions still receive strict stale-frame rejection.
fn refresh_continuous_input(input: &mut Input, current: &crate::document::NamespaceState) -> bool {
if !matches!(
input.kind.as_str(),
"viewport-pan" | "viewport-zoom" | "scene-pan" | "scene-orbit" | "scene-zoom" | "scroll"
) {
return true;
}
let frame = if input.window == crate::window::MAIN_WINDOW {
Some(&current.document.frame)
} else {
current
.document
.windows
.get(&input.window)
.map(|document| &document.frame)
};
let Some(frame) = frame else {
return false;
};
if current.runtime_session != input.session
|| frame.session != input.session
|| frame.fault.is_some()
|| !frame.mounts.iter().any(|mount| {
mount.id == input.mount
&& if input.kind.starts_with("viewport-") {
mount.canvas_viewport
} else if input.kind.starts_with("scene-") {
mount.scene3d_viewport && mount.camera_controls
} else {
mount.scroll.is_some()
}
})
{
return false;
}
input.layout_version = frame.layout_version;
true
}
fn send(input: &Input) -> anyhow::Result<()> {
let body = serde_json::to_string(input)?;
let mut stream =
@@ -208,6 +264,55 @@ fn send(input: &Input) -> anyhow::Result<()> {
mod tests {
use super::*;
#[test]
fn queued_native_pan_keeps_each_delta_and_rejects_replaced_targets() {
let (mut session, document) = crate::endor_host::ReplSession::load(
"view=CanvasViewport(200,100,Scene2D(RectBlock(20,20,0)))\npage=Page()\npage.render(view)",
"app.main", 1, 912,
).unwrap();
let mount = document
.frame
.mounts
.iter()
.find(|mount| mount.canvas_viewport)
.unwrap()
.id;
let original = Input {
window: 1,
session: 912,
layout_version: document.frame.layout_version,
mount,
kind: "viewport-pan".into(),
point: Some([50., 50.]),
delta: Some([3., 0.]),
press_point: None,
tab_drop: None,
screen_position: None,
};
let mut current = crate::document::NamespaceState {
runtime_session: 912,
document,
..Default::default()
};
for _ in 0..12 {
let mut queued = original.clone();
assert!(refresh_continuous_input(&mut queued, &current));
current.document = session.dispatch(&queued).unwrap().document.unwrap();
}
assert_eq!(
session.execute("view.camera.x", "app.main").unwrap().value,
"36"
);
let mut click = original.clone();
click.kind = "click".into();
assert!(refresh_continuous_input(&mut click, &current));
assert_eq!(click.layout_version, original.layout_version);
current.runtime_session = 913;
assert!(!refresh_continuous_input(&mut original.clone(), &current));
current.runtime_session = 912;
current.document.frame.mounts.clear();
assert!(!refresh_continuous_input(&mut original.clone(), &current));
}
#[test]
fn drop_metadata_is_scoped_to_its_event_kind_and_bounded() {
let mut input:Input=serde_json::from_str(r#"{"window":1,"session":1,"layout_version":2,"mount":3,"kind":"tab-drop","tab_drop":{"window":2,"layout_version":4,"index":1}}"#).unwrap();
assert!(input.validate().is_ok());