Skip to content

Commit

Permalink
Add serde behind a feature (#31)
Browse files Browse the repository at this point in the history
* Add serde

* Revert bvh2d git url to original

---------

Co-authored-by: 66OJ66 <hi0obxud@anonaddy.me>
  • Loading branch information
66OJ66 and 66OJ66 committed Jun 19, 2023
1 parent d70b57f commit 37e0b9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ stats = []
verbose = []
async = []
no-default-baking = []
serde = ["glam/serde", "bvh2d/serde", "dep:serde"]

[dependencies]
tracing = { version = "0.1", optional = true }
hashbrown = { version = "0.13" }
glam = { version = "0.23", features = ["approx"] }
smallvec = { version = "1.9", features = ["union", "const_generics"] }
bvh2d = { version = "0.3", git = "https://github.com/mockersf/bvh2d" }
serde = { version = "1.0.164", features = ["derive"], optional = true }

[dev-dependencies]
criterion = "0.4"
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ use instance::{EdgeSide, InstanceStep};
#[cfg(feature = "tracing")]
use tracing::instrument;

#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

#[cfg(feature = "async")]
mod async_helpers;
mod helpers;
Expand All @@ -58,6 +61,7 @@ pub struct Path {

/// A navigation mesh
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Mesh {
/// List of `Vertex` in this mesh
pub vertices: Vec<Vertex>,
Expand Down
5 changes: 5 additions & 0 deletions src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ use tracing::instrument;

use glam::Vec2;

#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

/// A point that lies on an edge of a polygon in the navigation mesh.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Vertex {
/// Coordinates of that point.
pub coords: Vec2,
Expand All @@ -31,6 +35,7 @@ impl Vertex {

/// A polygon in the navigation mesh.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Polygon {
/// List of vertex making this polygon, in counter clockwise order.
pub vertices: Vec<u32>,
Expand Down

0 comments on commit 37e0b9a

Please sign in to comment.