Skip to content

Commit ca52e5e

Browse files
authored
Implement particle host calls (#364)
* Implement particle host calls * sort Cargo.toml + rustfmt * Fix clippy warnings
1 parent 68f9305 commit ca52e5e

12 files changed

Lines changed: 302 additions & 27 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ world/
1313
feather.toml
1414

1515
**/__pycache__/
16+
17+
.DS_STORE

Cargo.lock

Lines changed: 109 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ blocks = { path = "../blocks", package = "feather-blocks" }
1414
byteorder = "1"
1515
generated = { path = "../generated", package = "feather-generated" }
1616
hematite-nbt = { git = "https://github.com/PistonDevelopers/hematite_nbt" }
17-
libcraft-core = { git = "https://github.com/feather-rs/libcraft" }
17+
libcraft-blocks = { git = "https://github.com/feather-rs/libcraft", rev = "0b49cd0" }
18+
libcraft-core = { git = "https://github.com/feather-rs/libcraft", rev = "0b49cd0" }
19+
libcraft-items = { git = "https://github.com/feather-rs/libcraft", rev = "0b49cd0" }
20+
21+
libcraft-particles = { git = "https://github.com/feather-rs/libcraft", rev = "0b49cd0" }
1822
nom = "5"
1923
nom_locate = "2"
2024
num-derive = "0.3"
@@ -26,6 +30,7 @@ serde_with = "1"
2630
smallvec = "1"
2731
thiserror = "1"
2832
uuid = { version = "0.8", features = [ "serde" ] }
33+
2934
vek = "0.14"
3035

3136
[dev-dependencies]

crates/base/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ mod world;
1818

1919
pub use blocks::*;
2020
pub use chunk::{Chunk, ChunkSection, CHUNK_HEIGHT, CHUNK_WIDTH};
21-
pub use generated::{Area, Biome, EntityKind, Inventory, Item, ItemStack, Particle};
21+
pub use generated::{Area, Biome, EntityKind, Inventory, Item, ItemStack};
22+
pub use libcraft_blocks::{BlockKind, BlockState};
2223
pub use libcraft_core::{position, vec3, BlockPosition, ChunkPosition, Gamemode, Position, Vec3d};
24+
pub use libcraft_particles::{Particle, ParticleKind};
2325
#[doc(inline)]
2426
pub use metadata::EntityMetadata;
2527
pub use text::{deserialize_text, Text};

crates/common/src/game.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ impl Game {
100100
self.entity_spawn_callbacks.push(Box::new(callback));
101101
}
102102

103+
/// Creates an emtpy entity builder to create entities in
104+
/// the ecs world.
105+
pub fn create_empty_entity_builder(&mut self) -> EntityBuilder {
106+
mem::take(&mut self.entity_builder)
107+
}
108+
103109
/// Creates an entity builder with the default components
104110
/// for an entity of type `init`.
105111
pub fn create_entity_builder(&mut self, position: Position, init: EntityInit) -> EntityBuilder {

crates/plugin-host/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ feather-base = { path = "../base" }
1414
feather-common = { path = "../common" }
1515
feather-ecs = { path = "../ecs" }
1616
feather-plugin-host-macros = { path = "macros" }
17+
1718
libloading = "0.7"
1819
log = "0.4"
1920
paste = "1"
20-
quill-common = { git = "https://github.com/feather-rs/quill", rev = "d4da5b6" }
21-
quill-plugin-format = { git = "https://github.com/feather-rs/quill", rev = "d4da5b6" }
21+
quill-common = { git = "https://github.com/feather-rs/quill", rev = "bf63d1a" }
22+
quill-plugin-format = { git = "https://github.com/feather-rs/quill", rev = "bf63d1a" }
2223
serde = "1"
2324
tempfile = "3"
2425
vec-arena = "1"

crates/plugin-host/src/host_calls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ host_calls! {
5555
"register_system" => register_system,
5656
"entity_get_component" => entity_get_component,
5757
"entity_set_component" => entity_set_component,
58+
"entity_builder_new_empty" => entity_builder_new_empty,
5859
"entity_builder_new" => entity_builder_new,
5960
"entity_builder_add_component" => entity_builder_add_component,
6061
"entity_builder_finish" => entity_builder_finish,

crates/plugin-host/src/host_calls/entity_builder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ use quill_common::{component::ComponentVisitor, HostComponent};
55

66
use crate::context::{PluginContext, PluginPtr};
77

8+
#[host_function]
9+
pub fn entity_builder_new_empty(cx: &PluginContext) -> anyhow::Result<u32> {
10+
let builder = cx.game_mut().create_empty_entity_builder();
11+
let id = cx.entity_builders.borrow_mut().insert(builder);
12+
13+
if id > u32::MAX as usize {
14+
bail!("created too many entity builders!");
15+
}
16+
17+
Ok(id as u32)
18+
}
19+
820
#[host_function]
921
pub fn entity_builder_new(
1022
cx: &PluginContext,

0 commit comments

Comments
 (0)