-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No more attributes for derive macros. Use `alkahest` attribute. Unsized formulas never exactly-sized. Move packet writing into separate module
- Loading branch information
1 parent
47e162b
commit b8878f5
Showing
35 changed files
with
1,411 additions
and
1,250 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "alkahest" | ||
version = "0.2.0-rc.9" | ||
version = "0.3.0" | ||
edition = "2021" | ||
authors = ["Zakarum <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -14,19 +14,20 @@ description = "Fantastic serialization library with zero-overhead serialization | |
alloc = [] # enables impls for types from `alloc` crate. | ||
std = ["alloc"] | ||
derive = ["alkahest-proc"] | ||
inline-more = [] | ||
|
||
## TODO: Control on value or type level? | ||
## Keep features for defaults? | ||
fixed8 = [] # sets size of `FixedUsize` and `FixedIsize` to 8 bits. | ||
fixed16 = [] # sets size of `FixedUsize` and `FixedIsize` to 16 bits. | ||
fixed32 = [] # sets size of `FixedUsize` and `FixedIsize` to 32 bits. Default. | ||
fixed64 = [] # sets size of `FixedUsize` and `FixedIsize` to 64 bits. | ||
default = ["alloc", "fixed32"] | ||
default = ["alloc", "fixed32", "inline-more"] | ||
|
||
bincoded = ["bincode", "serde", "std"] | ||
|
||
[dependencies] | ||
alkahest-proc = { version = "=0.2.0-rc.9", path = "proc", optional = true } | ||
alkahest-proc = { version = "=0.3.0", path = "proc", optional = true } | ||
bincode = { version = "1.3", optional = true } | ||
serde = { version = "1.0", optional = true } | ||
|
||
|
@@ -37,5 +38,9 @@ rand = { version = "0.8", features = ["small_rng"] } | |
name = "test" | ||
required-features = ["derive", "alloc"] | ||
|
||
[[example]] | ||
name = "profile" | ||
required-features = ["derive", "alloc"] | ||
|
||
[workspace] | ||
members = ["proc", "benchmark"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::{hint::black_box, mem::size_of}; | ||
|
||
use alkahest::*; | ||
use rand::{distributions::Standard, prelude::Distribution, Rng}; | ||
|
||
#[derive(Clone, Copy)] | ||
#[alkahest(Formula, Serialize, SerializeRef, Deserialize)] | ||
pub struct Vector3 { | ||
pub x: f32, | ||
pub y: f32, | ||
pub z: f32, | ||
} | ||
|
||
impl Distribution<Vector3> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vector3 { | ||
Vector3 { | ||
x: rng.gen(), | ||
y: rng.gen(), | ||
z: rng.gen(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
#[alkahest(Formula, Serialize, SerializeRef, Deserialize)] | ||
pub struct Triangle { | ||
pub v0: Vector3, | ||
pub v1: Vector3, | ||
pub v2: Vector3, | ||
pub normal: Vector3, | ||
} | ||
|
||
impl Distribution<Triangle> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Triangle { | ||
let v0 = rng.gen(); | ||
let v1 = rng.gen(); | ||
let v2 = rng.gen(); | ||
let normal = rng.gen(); | ||
|
||
Triangle { v0, v1, v2, normal } | ||
} | ||
} | ||
|
||
#[alkahest(Formula)] | ||
pub struct MeshFormula { | ||
pub triangles: [Triangle], | ||
} | ||
|
||
#[derive(Clone)] | ||
#[alkahest(Serialize<MeshFormula>, SerializeRef<MeshFormula>, Deserialize<'_, MeshFormula>)] | ||
pub struct Mesh { | ||
pub triangles: Vec<Triangle>, | ||
} | ||
|
||
#[alkahest(Deserialize<'a, MeshFormula>)] | ||
pub struct LazyMesh<'a> { | ||
pub triangles: Lazy<'a, [Triangle]>, | ||
} | ||
|
||
#[inline(always)] | ||
fn do_serialize(mesh: &Mesh, buffer: &mut [u8]) -> usize { | ||
alkahest::write_packet_unchecked::<MeshFormula, _>(&mesh, buffer) | ||
} | ||
|
||
fn main() { | ||
const TRIG_COUNT: usize = 100_000; | ||
|
||
let mesh = Mesh { | ||
triangles: rand::thread_rng() | ||
.sample_iter(Standard) | ||
.take(TRIG_COUNT) | ||
.collect(), | ||
}; | ||
|
||
let mut mesh = black_box(mesh); | ||
|
||
let mut buffer = Vec::new(); | ||
buffer.resize(TRIG_COUNT * size_of::<Triangle>() + 32, 0); | ||
|
||
for _ in 0..10_000 { | ||
let size = do_serialize(&mesh, &mut buffer); | ||
black_box(&buffer[..size]); | ||
mesh = black_box(mesh); | ||
} | ||
} |
Oops, something went wrong.