refactor: change logic_step to frame event
This commit is contained in:
@@ -185,7 +185,7 @@ fn main() -> Result<()> {
|
||||
right_controller.update(sk);
|
||||
}
|
||||
input::process_input();
|
||||
nodes::root::Root::logic_step(sk.time_elapsed());
|
||||
nodes::root::Root::send_frame_events(sk.time_elapsed());
|
||||
{
|
||||
let frame_delta = Duration::from_secs_f64(sk.time_elapsed_unscaled());
|
||||
if last_frame_delta < frame_delta {
|
||||
|
||||
@@ -14,13 +14,13 @@ static ROOT_REGISTRY: Registry<Root> = Registry::new();
|
||||
|
||||
pub struct Root {
|
||||
node: Arc<Node>,
|
||||
logic_step: AtomicBool,
|
||||
send_frame_event: AtomicBool,
|
||||
}
|
||||
impl Root {
|
||||
pub fn create(client: &Arc<Client>) -> Result<Arc<Self>> {
|
||||
let node = Node::create(client, "", "", false);
|
||||
node.add_local_signal("subscribe_logic_step", Root::subscribe_logic_step);
|
||||
node.add_local_signal("set_base_prefixes", Root::set_base_prefixes);
|
||||
node.add_local_signal("subscribe_frame", Root::subscribe_frame_flex);
|
||||
node.add_local_signal("set_base_prefixes", Root::set_base_prefixes_flex);
|
||||
let node = node.add_to_scenegraph()?;
|
||||
let _ = Spatial::add_to(
|
||||
&node,
|
||||
@@ -35,32 +35,36 @@ impl Root {
|
||||
|
||||
Ok(ROOT_REGISTRY.add(Root {
|
||||
node,
|
||||
logic_step: AtomicBool::from(false),
|
||||
send_frame_event: AtomicBool::from(false),
|
||||
}))
|
||||
}
|
||||
|
||||
fn subscribe_logic_step(_node: &Node, calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
||||
fn subscribe_frame_flex(_node: &Node, calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
||||
calling_client
|
||||
.root
|
||||
.get()
|
||||
.unwrap()
|
||||
.logic_step
|
||||
.send_frame_event
|
||||
.store(true, Ordering::Relaxed);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(level = "debug")]
|
||||
pub fn logic_step(delta: f64) {
|
||||
pub fn send_frame_events(delta: f64) {
|
||||
if let Ok(data) = serialize((delta, 0.0)) {
|
||||
for root in ROOT_REGISTRY.get_valid_contents() {
|
||||
if root.logic_step.load(Ordering::Relaxed) {
|
||||
let _ = root.node.send_remote_signal("logic_step", &data);
|
||||
if root.send_frame_event.load(Ordering::Relaxed) {
|
||||
let _ = root.node.send_remote_signal("frame", &data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_base_prefixes(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||
fn set_base_prefixes_flex(
|
||||
_node: &Node,
|
||||
calling_client: Arc<Client>,
|
||||
data: &[u8],
|
||||
) -> Result<()> {
|
||||
*calling_client.base_resource_prefixes.lock() = deserialize(data)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user