fmc_protocol/lib.rs
1#![deny(
2 //missing_docs,
3 missing_debug_implementations,
4 // why does it need this
5 //missing_copy_implementations,
6 trivial_casts,
7 trivial_numeric_casts,
8 unsafe_code,
9 unstable_features,
10 unused_import_braces,
11 unused_qualifications,
12 clippy::unwrap_used
13)]
14#![allow(clippy::type_complexity)]
15
16mod network_message;
17
18pub mod messages;
19pub use network_message::{ClientBound, ServerBound};
20
21// TODO: I want to increase block ids from u16 to u32. Doubling the memory size is bad. Instead
22// replace the blocks a chunk holds with substitutes, and keep a mapping from substitute values to
23// block ids. Then you can have 'lookup: Vec<BlockId>' and 'blocks: Vec<u16>', take the value you want
24// from 'blocks' cast it to usize and index into the lookup with it, you now have the block id.
25// This may even allow reducing the in-transit size by using even smaller types. I need to measure
26// but I assume most chunks don't consist of more than a handful of blocks. Maybe it can go all the
27// way down to 4 bits per block for most chunks, in which case keeping it in memory is a good trade
28// off for not having to build the representation each time it is sent.
29//
30// TODO: Should probably define BlockState here too, to avoid hard to parse u16's and easier to
31// change data type.
32//
33/// Storage type of blocks.
34/// Used by both server and client.
35type BlockId = u16;
36
37#[derive(Debug, PartialEq, Eq)]
38#[repr(u8)]
39pub enum MessageType {
40 ClientIdentification,
41 ClientReady,
42 AssetRequest,
43 AssetResponse,
44 Disconnect,
45 ServerConfig,
46 Time,
47 Chunk,
48 BlockUpdates,
49 DeleteModel,
50 ModelPlayAnimation,
51 ModelUpdateAsset,
52 ModelUpdateTransform,
53 NewModel,
54 SpawnCustomModel,
55 LeftClick,
56 RightClick,
57 RenderDistance,
58 PlayerAabb,
59 PlayerCameraPosition,
60 PlayerCameraRotation,
61 PlayerPosition,
62 InterfaceEquipItem,
63 InterfaceInteraction,
64 InterfaceItemBoxUpdate,
65 InterfaceNodeVisibilityUpdate,
66 InterfaceTextInput,
67 InterfaceTextUpdate,
68 InterfaceVisibilityUpdate,
69 EnableClientAudio,
70 Sound,
71 ParticleEffect,
72 // XXX: Always keep this at the bottom, occupies highest discriminant spot, so that when you
73 // deserialize a MessageType, you can know that only values below 'MessageType::MAX as u8' are
74 // valid.
75 MAX,
76}