Commit graph

42 commits

Author SHA1 Message Date
Ryan Johnson 2597e92b8f
Reorganize Packages (#180)
Moves all the packages to the `crates/` directory.
2022-12-29 16:51:05 -08:00
Ryan Johnson 5d3364d452
Update to 1.19.3 (#171)
Closes #165
2022-12-28 00:42:54 -08:00
Terminator 6de5de57a5
Anvil file support (blocks and biomes) (#145)
Adds the `valence_anvil` crate for loading anvil worlds. It can only read blocks and biomes currently. Support for saving data is to be added later.

Co-authored-by: Ryan <ryanj00a@gmail.com>
2022-12-26 06:55:52 -08:00
Terminator c73abacc98
Re-visit From impl for native data types found in NBT data format. (#169) 2022-12-15 18:38:52 -08:00
Ryan Johnson ae7eaf15fc
Big Optimizations (#164)
Closes #84

# Changes

- Implemented new algorithm for tracking loaded entities and chunks.
- The client does not need to maintain a list of loaded chunks and
entities anymore, as this information can be inferred using carefully
maintained data from the previous tick.
- Chunks are used as a spatial partition for entities. Entity visibility
is now based on chunk visibility rather than the euclidean distance to
clients.
- The BVH is no longer strictly necessary, so it has been moved to the
new `valence_spatial_index` crate.
- The API has been generalized to support things other than entities.
The crate does not have a dependency on the main `valence` crate.
- Chunk, entity, and player list packets are now aggressively cached to
increase performance.
- Chunk packets now include some filler light data. This makes the
vanilla client lag a lot less.
- Entities and chunks must now be marked as deleted before they are
removed.
- Improved `ChunkPos` interface.
- Added function to get the duration per tick.
- Added `Index` and `IndexMut` impls to collection types.

As a result of the above changes, performance under heavy load has
increased significantly. With the rust-mc-bot test on my machine, I went
from a max of ~1000 players to ~4000 players.
2022-12-11 02:37:02 -08:00
Ryan b61bdbb71d Fix conflicting Debug impl on bitfield structs 2022-12-09 17:02:37 -08:00
Ryan Johnson 842ddb4127
Optimize sending tracked entity data (#163) 2022-11-30 15:55:46 -08:00
Ryan Johnson 4226201fed
Replace log crate with tracing (#157)
The `tracing` crate seems to be the go-to
logging/profiling/instrumentation solution nowadays. Perhaps in the
future we could use `tracing` for profiling instead of (or in addition
to) the `perf`-based `cargo flamegraph` command. This would sidestep the
issue of `rayon` polluting the output. I conducted an initial experiment
by adding some more spans but wasn't very happy with the result.

Log messages have also been improved. There is some additional context
and events are raised when clients are added/removed from the server.
2022-11-16 18:22:44 -08:00
Ryan Johnson 420f2d1b7c
Move protocol code to valence_protocol + redesigns (#153)
Closes #83 

This PR aims to move all of Valence's networking code to the new
`valence_protocol` crate. Anything not specific to valence is going in
the new crate. It also redesigns the way packets are defined and makes a
huge number of small additions and improvements. It should be much
easier to see where code is supposed to go from now on.

`valence_protocol` is a new library which enables interactions with
Minecraft's protocol. It is completely decoupled from valence and can be
used to build new clients, servers, tools, etc.

There are two additions that will help with #5 especially:
- It is now easy to define new packets or modifications of existing
packets. Not all packets need to be bidirectional.
- The `CachedEncode` type has been created. This is used to safely cache
redundant calls to `Encode::encode`.
2022-11-13 06:10:42 -08:00
Ryan Johnson f4714cf255
Redesign packet processing and improve Client update procedure. (#146)
Closes #82
Closes #43
Closes #64

# Changes and Improvements
- Packet encoding/decoding happens within `Client` instead of being sent
over a channel first. This is better for performance and lays the
groundwork for #83.
- Reduce the amount of copying necessary by leveraging the `bytes` crate
and recent changes to `EncodePacket`. Performance is noticeably improved
with maximum players in the `rust-mc-bot` test going from 750 to 1050.
- Packet encoding/decoding code is decoupled from IO. This is easier to
understand and more suitable for a future protocol lib.
- Precise control over the number of bytes that are buffered for
sending/receiving. This is important for limiting maximum memory usage
correctly.
- "packet controllers" are introduced, which are convenient structures
for managing packet IO before and during the play state.
- `byte_channel` module is created to help implement the
`PlayPacketController`. This is essentially a channel of bytes
implemented with an `Arc<Mutex<BytesMut>>`.
- Error handling in the update procedure for clients was improved using
`anyhow::Result<()>` to exit as early as possible. The `client` module
is a bit cleaner as a result.
- The `LoginPlay` packet is always sent before all other play packets.
We no longer have to worry about the behavior of packets sent before
that packet. Most packet deferring performed currently can be
eliminated.
- The packet_inspector was rewritten in response to the above changes.
- Timeouts on IO operations behave better.

# Known Issues
- The packet_inspector now re-encodes packets rather than just decoding
them. This will cause problems when trying to use it with the vanilla
server because there are missing clientbound packets and other issues.
This will be fixed when the protocol module is moved to a separate
crate.
2022-11-01 03:11:51 -07:00
Ryan a20ed2ac21 Bump valence_nbt version 2022-10-30 15:26:47 -07:00
Tert0 c707ed1d04
Proxy Support (#48)
This PR adds Proxy Support.

Closes #39

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-10-21 19:50:13 -07:00
Ryan Johnson 71d82c5330
Add encoded_len method to Encode trait. (#125)
This allows packets to calculate their exact length up front.
This isn't currently tested or being used for anything, but that will come in later changes.
2022-10-19 01:52:02 -07:00
Ryan Johnson f58e6662dd
Add performance tests (#113)
Adds the performance_tests/ directory.

In the future we could use our own fake client software instead of
rust-mc-bot. This would make it easier to run the tests.
2022-10-14 21:18:03 -07:00
Ryan Johnson 7d0c254874
Rewrite ident module (again) (#111)
Ident is now a wrapper around any string type `S`.
2022-10-12 03:53:59 -07:00
Ryan cf5b9136df Bump valence_nbt version in valence 2022-10-01 15:47:59 -07:00
Ryan Johnson 9c62bc1b90
Move valence_nbt to main Valence repo. (#97)
This also adds another check in CI
2022-10-01 14:18:42 -07:00
Ryan Johnson 36b63e777e
Replace serde_nbt with valence_nbt (#80)
valence_nbt has a much nicer API and avoids the complications brought by integrating with serde. valence_nbt also fixes some bugs and is 3x faster according to benchmarks.
2022-09-23 04:03:21 -07:00
Ryan cc9cd0be2d Use exact versions of dependencies in Cargo.toml 2022-09-22 17:00:02 -07:00
Ryan Johnson ca4f47c768
Implement the player sample (#47)
Verify that it works by hovering your mouse over the player count in the
cow_sphere example.
2022-09-10 16:02:12 -07:00
XBagon a4c8b282a5
Change debug optimization levels (#33)
Changed the `Cargo.toml` to allow full optimization of dependencies and minimally optimize the binary to allow proper testing without timeouts and errors due to overload.
2022-09-08 04:40:42 -07:00
Ryan 4c5179de18 Move serde_nbt to a separate repo.
It is located at https://github.com/valence-rs/serde_nbt
2022-09-04 04:00:59 -07:00
Ryan ebbea74017 Prepare for public release 2022-09-03 16:48:11 -07:00
Ryan f7a35f356e Update rust docs 2022-09-02 00:06:45 -07:00
Ryan 27033c758e Update packet_inspector 2022-09-01 00:57:02 -07:00
Ryan c8cc7a021c Add valence_nbt to valence 2022-08-29 19:28:19 -07:00
Ryan c503e6eb78 NBT Value can now be round-trip encoded/decoded properly 2022-08-28 21:06:38 -07:00
Ryan 7568ff8b4b Add serde_nbt 2022-08-24 18:17:51 -07:00
Ryan 21e37c65c2 Update Cargo.toml 2022-07-18 02:02:37 -07:00
Ryan 878f2d1dcb Add conway example 2022-07-02 00:14:39 -07:00
Ryan a259bdf840 Add the packet inspector proxy 2022-07-01 15:29:31 -07:00
Ryan 6ef634ca2c Use Rust 1.62.0 features 2022-06-30 13:22:08 -07:00
Ryan 560163fd2e Expose the protocol API behind a feature flag
This could be useful for building proxies or clients in the future.
2022-06-30 11:53:57 -07:00
Ryan 055dd03ffc Implement the player list 2022-06-27 17:52:23 -07:00
Ryan 8ad9c8587a Upgrade the chunk example 2022-06-19 08:40:37 -07:00
Ryan 34d831f5fd Add R-Tree 2022-06-06 23:20:34 -07:00
Ryan 620c0bf287 Replace nalgebra-glm with vek
Vek has been pleasant to use in practice. nalgebra is slow to compile
and its documentation is difficult to traverse. Vek also comes with its
own AABB impl, so we use that instead.
2022-05-16 04:09:51 -07:00
Ryan adc8a4faae Give World ownership over entities, clients, and chunks.
This change was made to make it easier for invariants to be upheld. When
the spatial partition is added, we can ensure that changes to entities
are immediately reflected in the partition. Additionally, chunks being
shared between worlds was a leaky abstraction to begin with and is now
removed. A method in `Config` is now necessary to determine what world a
client should join.

Along with this, most mutable references have been wrapped in a newtype
to ensure that `mem::swap` cannot be used on them, which would break
invariants. This is analogous to `Pin<&mut T>`. The reason we can't use
Pin directly is because it would require unnecessary unsafe code
within the library.
2022-05-16 02:36:14 -07:00
Ryan a997820b7a Add block state generator 2022-04-17 17:04:39 -07:00
Ryan 5bbbb258d1 move from private repo 2022-04-14 14:55:45 -07:00
Ryan db0eae3a6c fix broken link 2022-01-20 06:41:24 -08:00
Ryan 8b29a04af8 prepare for crates.io 2022-01-20 06:39:49 -08:00