Commit graph

38 commits

Author SHA1 Message Date
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 Johnson 842ddb4127
Optimize sending tracked entity data (#163) 2022-11-30 15:55:46 -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
Terminator e80bbc22b3
Avoid calling to_kind() in is_air() (#142)
This PR changes is_air() to not call to_kind() to increase performance.

Example flamegraphs of real usecase of parsing java chunks to
UnloadedChunk:

Before this change:

![flamegraph](https://user-images.githubusercontent.com/13693773/198851700-f455d055-a18d-495c-9989-110e3f569ad9.svg)



After this change:

![flamegraph](https://user-images.githubusercontent.com/13693773/198851673-01f2a6d8-1cb0-4ae7-b57b-6e47a38d9cee.svg)
2022-10-29 13:56:48 -07:00
Ryan Johnson ad153159dd
Add replaceable boolean to block states (#116) 2022-10-16 03:50:57 -07:00
Ryan Johnson 153cde1a04
Chunk Rewrite With Paletted Containers (#91)
The current approach to managing chunk data is misconceived. This new approach uses genuine paletted containers and does not suffer from complexities caused by caching. As a result, memory usage (according to htop) in the terrain example with render distance = 32 has gone from 785 megs to 137 megs. That's 17.4% of the memory it used to use. Terrain generation speed was not affected.
2022-10-07 15:52:55 -07:00
EmperialDev 1f996f7549
Add Items (#92)
Adding all the items, just like the blocks are. This will adress 1. and 2. bullet from issue #53
This will also make it easier to convert between block <-> item.
2022-10-05 09:28:08 -07:00
Ryan b330f97642 Remove top level object from enchantments 2022-10-04 23:16:48 -07:00
Terminator b83b9f76ed
Expose enchantments to Rust (#99)
* Expose extracted enchantments to Rust.

* Give enchantments a `level: i16` field.

* Update enchantment derive impls

* Restructure how enchants are exposed to Rust through C-like enums

* Update build/enchant.rs

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>

* Update build/enchant.rs

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>

* Move enchantment sources to their own struct.

* make id() function return it's discriminant instead of matching

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-10-03 13:19:42 -07:00
Ryan Johnson 94cfc41486 Fix formatting 2022-09-28 00:23:14 -07:00
Ryan Johnson 77df8b668d Fix nightly clippy lints in build/entity.rs 2022-09-28 00:17:43 -07:00
Ryan c8cc7a021c Add valence_nbt to valence 2022-08-29 19:28:19 -07:00
Ryan d61c3f1f6f Fix change detection bug in build script 2022-08-09 17:35:49 -07:00
Ryan cd110c3cbb Add translation keys to block kind 2022-08-06 16:50:50 -07:00
Ryan 9c67978e06 Add collision shapes to block states 2022-08-06 16:46:07 -07:00
Ryan 49d63a39c0 Clean up client and fix names 2022-08-05 12:36:34 -07:00
Ryan 6b5e795f81 Rename entity data 2022-08-02 19:02:05 -07:00
Ryan ffad0b4021 Use the extracted data in the block generator 2022-07-28 08:15:23 -07:00
Ryan 2e22946ffc Rewrite the entity generator 2022-07-27 07:10:35 -07:00
Ryan b604dafe73 Add combat example 2022-07-17 21:29:44 -07:00
Ryan 865ab76699 Add custom data 2022-07-15 20:40:39 -07:00
Ryan 4b83801066 Clean up docs and fix clippy issues 2022-07-14 23:18:20 -07:00
Ryan 4a12def900 Redesign the spatial index API and add raycast example 2022-07-14 03:40:26 -07:00
Ryan 3f150b4c8a Document most items 2022-07-11 05:08:02 -07:00
Ryan 3ac711ca74 Use idiomatic names
The Rust stdlib uses "Kind" instead of "Type".
2022-07-05 19:21:52 -07:00
Ryan fcda380f2a Improve entity event API 2022-07-05 18:08:40 -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 1aa4ca878e Add player metadata to client 2022-06-29 13:00:41 -07:00
Ryan 69ba704352 Implement the block change packets 2022-06-22 08:06:54 -07:00
Ryan c86b8286ce Update to 1.19
Authentication is currently broken. Looks like the EncryptionResponse
packet changed.
2022-06-21 04:55:32 -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 732183dd62 Rip out the ECS. 2022-04-29 00:48:41 -07:00
Ryan 5f2389f0e7 Add entity metadata to build script 2022-04-26 19:48:35 -07:00
Ryan 6be10bba5a Specify rerun-if-changed files manually 2022-04-19 23:45:34 -07:00
Ryan 1a27cb92ce Expand block state API 2022-04-19 23:40:33 -07:00
Ryan 064dcfbc0b Get the block state generator to match what the client expects 2022-04-18 00:43:34 -07:00
Ryan b5a88be024 cargo fmt 2022-04-17 17:06:13 -07:00
Ryan a997820b7a Add block state generator 2022-04-17 17:04:39 -07:00