feat: logic step
This commit is contained in:
@@ -4,6 +4,7 @@ mod nodes;
|
|||||||
use self::core::eventloop::EventLoop;
|
use self::core::eventloop::EventLoop;
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use stereokit_rs as sk;
|
||||||
use stereokit_rs::enums::DisplayMode;
|
use stereokit_rs::enums::DisplayMode;
|
||||||
use stereokit_rs::functions::*;
|
use stereokit_rs::functions::*;
|
||||||
|
|
||||||
@@ -30,7 +31,8 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
sk_run(
|
sk_run(
|
||||||
&mut Box::new(&mut || {
|
&mut Box::new(&mut || {
|
||||||
// println!("hii uwu");
|
let time = unsafe { sk::sys::time_get() };
|
||||||
|
nodes::root::logic_step(time);
|
||||||
}),
|
}),
|
||||||
&mut Box::new(&mut || {
|
&mut Box::new(&mut || {
|
||||||
println!("Shutting down...");
|
println!("Shutting down...");
|
||||||
|
|||||||
@@ -1,10 +1,35 @@
|
|||||||
use super::core::Node;
|
use super::core::Node;
|
||||||
use super::spatial::Spatial;
|
use super::spatial::Spatial;
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
|
use crate::core::registry::Registry;
|
||||||
|
use anyhow::Result;
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use libstardustxr::flex::flexbuffer_from_vector_arguments;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref LOGIC_STEP_REGISTRY: Registry<Node> = Registry::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn logic_step(delta: f64) {
|
||||||
|
let data = flexbuffer_from_vector_arguments(move |fbb| {
|
||||||
|
fbb.push(delta);
|
||||||
|
fbb.push(0_f64);
|
||||||
|
});
|
||||||
|
for root in LOGIC_STEP_REGISTRY.get_valid_contents() {
|
||||||
|
root.send_remote_signal("logicStep", &data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_root(client: &Arc<Client>) {
|
pub fn create_root(client: &Arc<Client>) {
|
||||||
let node = Node::create(client, "", "", false).add_to_scenegraph();
|
let node = Node::create(client, "", "", false);
|
||||||
|
node.add_local_signal("subscribeLogicStep", subscribe_logic_step);
|
||||||
|
let node = node.add_to_scenegraph();
|
||||||
let _ = Spatial::add_to(&node, None, Mat4::IDENTITY);
|
let _ = Spatial::add_to(&node, None, Mat4::IDENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subscribe_logic_step(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
|
LOGIC_STEP_REGISTRY.add_raw(&calling_client.scenegraph.get_node("/").unwrap());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user