Receive renderablelines from python
This commit is contained in:
parent
483f021010
commit
0bd763ba5e
4 changed files with 48 additions and 10 deletions
31
examples/test_serialisation.rs
Normal file
31
examples/test_serialisation.rs
Normal file
File diff suppressed because one or more lines are too long
|
@ -43,8 +43,8 @@ fn main() {
|
|||
|
||||
.add_plugins(ZmqPlugin {
|
||||
// url: "tcp://localhost:5558".to_string(),
|
||||
// url: "tcp://100.109.175.82:99173".to_string(),
|
||||
url: "tcp://127.0.0.1:99173".to_string(),
|
||||
url: "tcp://100.109.175.82:99174".to_string(),
|
||||
// url: "tcp://127.0.0.1:99173".to_string(),
|
||||
filter: "".to_string(),
|
||||
target: ZmqReceiveTarget::LINES
|
||||
})
|
||||
|
|
|
@ -40,18 +40,18 @@ pub struct Track {
|
|||
}
|
||||
|
||||
// coordinates in world space. To be converted to laser::Point or a drawable point
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct RenderablePoint{
|
||||
pub position: Vec2,
|
||||
pub color: Color
|
||||
pub color: Srgba
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct RenderableLine{
|
||||
points: Vec<RenderablePoint>
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct RenderableLines{
|
||||
pub lines: Vec<RenderableLine>
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ impl From<&Track> for RenderableLines{
|
|||
for position in track.history.iter() {
|
||||
points.push(RenderablePoint{
|
||||
position: position.clone(),
|
||||
color: Color::linear_rgba(1.0, 0., 0., 1.0)
|
||||
color: Srgba::new(1.0, 0., 0., 1.0)
|
||||
});
|
||||
}
|
||||
lines.push(RenderableLine{points})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use zmq::Socket;
|
||||
use serde_json::Result;
|
||||
use bevy::{ecs::system::SystemState, prelude::*, render::Render};
|
||||
|
||||
use std::num::NonZero;
|
||||
use super::{laser::{LaserApi, LaserTimer}, tracks::{Frame, LaserPoints, RenderableLines, Track, TrackBundle}};
|
||||
|
||||
|
||||
|
@ -46,7 +46,8 @@ fn setup_zmq(world: &mut World, params: &mut SystemState<Res<ZmqSettings>>) {
|
|||
fn receive_zmq_lines(
|
||||
subscriber: NonSend<Socket>,
|
||||
mut lasers: Query<(&mut LaserApi, &mut LaserTimer)>,
|
||||
time: Res<Time>
|
||||
time: Res<Time>,
|
||||
mut exit: EventWriter<AppExit>
|
||||
) {
|
||||
let mut items = [
|
||||
subscriber.as_poll_item(zmq::POLLIN)
|
||||
|
@ -64,9 +65,14 @@ fn receive_zmq_lines(
|
|||
Ok(lines) => lines, // if Ok(255), set x to 255
|
||||
Err(_e) => {
|
||||
println!("No valid json? {json}");
|
||||
println!("{}", _e);
|
||||
|
||||
exit.send(AppExit::Error(NonZero::<u8>::new(10).unwrap()));
|
||||
return
|
||||
}, // if Err("some message"), panic with error message "some message"
|
||||
};
|
||||
|
||||
println!("receive {}", lines.lines.len());
|
||||
|
||||
for (laser_api, mut laser_timer) in lasers.iter_mut() {
|
||||
laser_timer.timer.tick(time.delta());
|
||||
|
@ -80,7 +86,7 @@ fn receive_zmq_lines(
|
|||
}
|
||||
}
|
||||
|
||||
fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>) {
|
||||
fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>, mut exit: EventWriter<AppExit>) {
|
||||
let mut items = [
|
||||
subscriber.as_poll_item(zmq::POLLIN)
|
||||
];
|
||||
|
@ -97,6 +103,7 @@ fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut t
|
|||
Ok(msg) => msg, // if Ok(255), set x to 255
|
||||
Err(_e) => {
|
||||
println!("No valid json? {json}");
|
||||
exit.send(AppExit::Error(NonZero::<u8>::new(10).unwrap()));
|
||||
return
|
||||
}, // if Err("some message"), panic with error message "some message"
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue