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