Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load item and arrow entities from chunk save (#102) #125

Merged
merged 7 commits into from
Sep 11, 2019

Conversation

aramperes
Copy link
Contributor

@aramperes aramperes commented Sep 10, 2019

#102

  • Load item NBT
  • Load arrow NBT
  • Spawn item and arrow into world
  • Add tests

core/src/save/region.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 10, 2019

Codecov Report

Merging #125 into develop will decrease coverage by 0.2%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #125      +/-   ##
===========================================
- Coverage    58.76%   58.55%   -0.21%     
===========================================
  Files           60       61       +1     
  Lines         8230     8259      +29     
===========================================
  Hits          4836     4836              
- Misses        3394     3423      +29
Impacted Files Coverage Δ
core/src/save/entity.rs 0% <0%> (ø)
core/src/save/region.rs 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02dab41...e9d86c5. Read the comment docs.

@caelunshun
Copy link
Member

What's your idea for spawning the loaded entities?

@aramperes
Copy link
Contributor Author

I'm not decided yet, but here's what I'm thinking:

Since level deserialization is in feather-core, I figure the entities would be stored in the Chunk struct. When ChunkLoadSystem (in feather-server) receives a Reply with a loaded chunk, it fires a ChunkLoadEvent. There could be another system in feather-server that listens on ChunkLoadEvent and spawns the entities depending on their data.

However, consider the case where an an entity is stored in Chunk A. It is added to the world when ChunkLoadEvent is fired for Chunk A. The entity then crosses to Chunk B. Chunk A is later unloaded, and then loaded again. The entity would then be duplicated in the world. Not too sure how to prevent that.

@caelunshun
Copy link
Member

caelunshun commented Sep 10, 2019

I'm not decided yet, but here's what I'm thinking:

Since level deserialization is in feather-core, I figure the entities would be stored in the Chunk struct. When ChunkLoadSystem (in feather-server) receives a Reply with a loaded chunk, it fires a ChunkLoadEvent. There could be another system in feather-server that listens on ChunkLoadEvent and spawns the entities depending on their data.

However, consider the case where an an entity is stored in Chunk A. It is added to the world when ChunkLoadEvent is fired for Chunk A. The entity then crosses to Chunk B. Chunk A is later unloaded, and then loaded again. The entity would then be duplicated in the world. Not too sure how to prevent that.

Storing entities in Chunk isn't ideal in my opinion, since they aren't needed past when the chunk is loaded (all entities are stored in the World). It would probably be preferable to add a Vec<EntityData> field to chunkworker::Reply.

As for the entity duplication issue, I don't think there's a clean way around this until world persistence is implemented. I plan to do this within the next few weeks, so the issue shouldn't be present for that long. Might want to add a comment that notes this, though, so we don't forget.

@codecov-io
Copy link

Codecov Report

Merging #125 into develop will decrease coverage by 0.2%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #125      +/-   ##
===========================================
- Coverage    58.76%   58.55%   -0.21%     
===========================================
  Files           60       61       +1     
  Lines         8230     8259      +29     
===========================================
  Hits          4836     4836              
- Misses        3394     3423      +29
Impacted Files Coverage Δ
core/src/save/entity.rs 0% <0%> (ø)
core/src/save/region.rs 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02dab41...d7d5c05. Read the comment docs.

@feather-rs feather-rs deleted a comment from codecov-io Sep 10, 2019
@codecov
Copy link

codecov bot commented Sep 10, 2019

Codecov Report

Merging #125 into develop will decrease coverage by 0.09%.
The diff coverage is 47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #125     +/-   ##
==========================================
- Coverage    58.76%   58.66%   -0.1%     
==========================================
  Files           60       61      +1     
  Lines         8230     8324     +94     
==========================================
+ Hits          4836     4883     +47     
- Misses        3394     3441     +47
Impacted Files Coverage Δ
core/src/lib.rs 9.8% <ø> (ø) ⬆️
core/src/save/entity.rs 0% <0%> (ø)
server/src/chunkworker.rs 24.17% <0%> (ø) ⬆️
core/src/save/region.rs 0% <0%> (ø) ⬆️
server/src/entity/mod.rs 100% <100%> (ø) ⬆️
server/src/chunk_logic.rs 63.93% <60%> (-0.16%) ⬇️
server/src/entity/chunk.rs 97.94% <93.47%> (-1.39%) ⬇️
server/src/player/movement.rs 31.55% <0%> (+1.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02dab41...d790293. Read the comment docs.

@aramperes
Copy link
Contributor Author

aramperes commented Sep 10, 2019

Would it make sense to add the Vec<EntityData> to ChunkLoadEvent, or firing a separate event? I'm thinking the code to spawn the entities should be its own system.

@caelunshun
Copy link
Member

caelunshun commented Sep 10, 2019

A separate system makes the most sense in this case, yes.

You should probably also use Util::spawn_xx for spawning the entities, come to think of it, since this will also handle sending them to clients.

@aramperes
Copy link
Contributor Author

aramperes commented Sep 10, 2019

You should probably also use Util::spawn_xx for spawning the entities, come to think of it, since this will also handle sending them to clients.

Yeah that's what I'm doing atm, though it's fetching the Util resource lazily. Would that still be beneficial in a separate system, or should I just use Read<'a, Util> directly?

@caelunshun
Copy link
Member

caelunshun commented Sep 10, 2019

Still a separate system, I think, because the match expression will grow very long with more entities being added. Also, the behavior is separate from chunk loading itself, so using another system would be cleaner.

@aramperes
Copy link
Contributor Author

Oh yeah I'm for sure separating it, I was just wondering if there'd be a purpose in using LazyUpdate in that new system, instead of referencing Util directly. I guess I'm not clear on what LazyUpdate actually does.

@caelunshun
Copy link
Member

Oh, sorry for misunderstanding.

LazyUpdate::exec causes the provided closure to be execute lazily, i.e. at the end of the tick. Its benefit is that you can access any resource or component from the world without specifying system data, but you also lose concurrency by doing this.

If you use the separate system, there shouldn't be a need to use it. The main motivation for utilizing it is if you need access to tons of components which would be unclean to write in a SystemData. (In the issue, I wrote that LazyUpdate should be used, but this was before util::spawn_xx was implemented.)

@aramperes
Copy link
Contributor Author

Hmm so if I add Vec<EntityData> to ChunkLoadEvent, I get an error since Vec doesn't implement the Copy trait. Does that mean I can't pass a Vec in an event?

@caelunshun
Copy link
Member

You should just be able to remove the Copy derive on ChunkLoadEvent (unless there's some reason it's needed).

@aramperes aramperes changed the title [WIP] Load item and arrow entities from chunk save (#102) Load item and arrow entities from chunk save (#102) Sep 11, 2019
@aramperes
Copy link
Contributor Author

Ready for review

@caelunshun
Copy link
Member

Thanks!

@caelunshun caelunshun merged commit a790c57 into feather-rs:develop Sep 11, 2019
@aramperes aramperes deleted the feature/load-chunk-entities branch September 11, 2019 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants