feat: fd passing

This commit is contained in:
Nova
2023-07-31 23:44:17 -04:00
parent 4bbe3ad8d0
commit 0736f99631
29 changed files with 484 additions and 309 deletions

View File

@@ -2,7 +2,7 @@ use crate::{
core::{client::Client, registry::Registry},
nodes::{
spatial::{find_spatial_parent, parse_transform, Spatial},
Node,
Message, Node,
},
};
use color_eyre::eyre::{bail, ensure, Result};
@@ -97,10 +97,14 @@ impl Lines {
draw_ctx.line_add_listv(points.make_contiguous());
}
pub fn set_points_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn set_points_flex(
node: &Node,
_calling_client: Arc<Client>,
message: Message,
) -> Result<()> {
let Some(Drawable::Lines(lines)) = node.drawable.get() else {bail!("Not a drawable??")};
let mut points: Vec<LinePointRaw> = deserialize(data)?;
let mut points: Vec<LinePointRaw> = deserialize(message.as_ref())?;
for p in &mut points {
p.color[0] = p.color[0].powf(2.2);
p.color[1] = p.color[1].powf(2.2);
@@ -109,10 +113,14 @@ impl Lines {
lines.data.lock().points = points;
Ok(())
}
pub fn set_cyclic_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn set_cyclic_flex(
node: &Node,
_calling_client: Arc<Client>,
message: Message,
) -> Result<()> {
let Some(Drawable::Lines(lines)) = node.drawable.get() else {bail!("Not a drawable??")};
lines.data.lock().cyclic = deserialize(data)?;
lines.data.lock().cyclic = deserialize(message.as_ref())?;
Ok(())
}
}
@@ -130,7 +138,7 @@ pub fn draw_all(draw_ctx: &impl StereoKitDraw) {
}
}
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, message: Message) -> Result<()> {
#[derive(Deserialize)]
struct CreateTextInfo<'a> {
name: &'a str,
@@ -139,7 +147,7 @@ pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Re
points: Vec<LinePointRaw>,
cyclic: bool,
}
let mut info: CreateTextInfo = deserialize(data)?;
let mut info: CreateTextInfo = deserialize(message.as_ref())?;
let node = Node::create(&calling_client, "/drawable/lines", info.name, true);
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
let transform = parse_transform(info.transform, true, true, true);

View File

@@ -9,7 +9,7 @@ use self::{
text::Text,
};
use super::Node;
use super::{Message, Node};
use crate::core::client::Client;
use color_eyre::eyre::Result;
use parking_lot::Mutex;
@@ -56,14 +56,14 @@ pub fn draw(sk: &impl StereoKitDraw) {
static QUEUED_SKYLIGHT: Mutex<Option<PathBuf>> = Mutex::new(None);
static QUEUED_SKYTEX: Mutex<Option<PathBuf>> = Mutex::new(None);
fn set_sky_file_flex(_node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
fn set_sky_file_flex(_node: &Node, _calling_client: Arc<Client>, message: Message) -> Result<()> {
#[derive(Deserialize)]
struct SkyFileInfo {
path: PathBuf,
skytex: Option<bool>,
skylight: Option<bool>,
}
let info: SkyFileInfo = deserialize(data)?;
let info: SkyFileInfo = deserialize(message.as_ref())?;
info.path.metadata()?;
if info.skytex.unwrap_or_default() {
QUEUED_SKYTEX.lock().replace(info.path.clone());

View File

@@ -5,6 +5,7 @@ use crate::core::registry::Registry;
use crate::core::resource::ResourceID;
use crate::nodes::drawable::Drawable;
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use crate::nodes::Message;
use crate::SK_MULTITHREAD;
use color_eyre::eyre::{bail, ensure, eyre, Result};
use glam::Mat4;
@@ -213,11 +214,11 @@ impl ModelPart {
fn set_material_parameter_flex(
node: &Node,
_calling_client: Arc<Client>,
data: &[u8],
message: Message,
) -> Result<()> {
let Some(Drawable::ModelPart(model_part)) = node.drawable.get() else {bail!("Not a drawable??")};
let (name, value): (String, MaterialParameter) = deserialize(data)?;
let (name, value): (String, MaterialParameter) = deserialize(message.as_ref())?;
model_part
.pending_material_parameters
@@ -342,7 +343,7 @@ pub fn draw_all(sk: &impl StereoKitDraw) {
}
}
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, message: Message) -> Result<()> {
#[derive(Deserialize)]
struct CreateModelInfo<'a> {
name: &'a str,
@@ -350,7 +351,7 @@ pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Re
transform: Transform,
resource: ResourceID,
}
let info: CreateModelInfo = deserialize(data)?;
let info: CreateModelInfo = deserialize(message.as_ref())?;
let node = Node::create(&calling_client, "/drawable/model", info.name, true);
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
let transform = parse_transform(info.transform, true, true, true);

View File

@@ -3,7 +3,7 @@ use crate::{
nodes::{
drawable::Drawable,
spatial::{find_spatial_parent, parse_transform, Spatial},
Node,
Message, Node,
},
};
use color_eyre::eyre::{bail, ensure, eyre, Result};
@@ -151,18 +151,22 @@ impl Text {
pub fn set_character_height_flex(
node: &Node,
_calling_client: Arc<Client>,
data: &[u8],
message: Message,
) -> Result<()> {
let Some(Drawable::Text(text)) = node.drawable.get() else {bail!("Not a drawable??")};
text.data.lock().character_height = deserialize(data)?;
text.data.lock().character_height = deserialize(message.as_ref())?;
Ok(())
}
pub fn set_text_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn set_text_flex(
node: &Node,
_calling_client: Arc<Client>,
message: Message,
) -> Result<()> {
let Some(Drawable::Text(text)) = node.drawable.get() else {bail!("Not a drawable??")};
text.data.lock().text = deserialize(data)?;
text.data.lock().text = deserialize(message.as_ref())?;
Ok(())
}
}
@@ -183,7 +187,7 @@ pub fn draw_all(sk: &impl StereoKitDraw) {
}
}
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
pub fn create_flex(_node: &Node, calling_client: Arc<Client>, message: Message) -> Result<()> {
#[derive(Deserialize)]
struct CreateTextInfo<'a> {
name: &'a str,
@@ -198,7 +202,7 @@ pub fn create_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Re
bounds_align: TextAlign,
color: [f32; 4],
}
let info: CreateTextInfo = deserialize(data)?;
let info: CreateTextInfo = deserialize(message.as_ref())?;
let node = Node::create(&calling_client, "/drawable/text", info.name, true);
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
let transform = parse_transform(info.transform, true, true, true);