Skip to content

Commit

Permalink
Represent character path compactly
Browse files Browse the repository at this point in the history
Reduces space used to represent paths by half.
  • Loading branch information
Ralith committed Jul 28, 2024
1 parent 1a2879d commit cc43ae6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion save/src/protos.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ message Meta {

message Character {
// Graph edges to traverse from the origin to find the node containing the character's entity
repeated uint32 path = 1;
bytes path = 1;
}

message EntityNode {
Expand Down
4 changes: 2 additions & 2 deletions save/src/protos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Meta {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Character {
/// Graph edges to traverse from the origin to find the node containing the character's entity
#[prost(uint32, repeated, tag = "1")]
pub path: ::prost::alloc::vec::Vec<u32>,
#[prost(bytes = "vec", tag = "1")]
pub path: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
4 changes: 2 additions & 2 deletions server/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl Sim {
}

pub fn save(&mut self, save: &mut save::Save) -> Result<(), save::DbError> {
fn path_from_origin(graph: &Graph, mut node: NodeId) -> Vec<u32> {
fn path_from_origin(graph: &Graph, mut node: NodeId) -> Vec<u8> {
let mut result = Vec::new();
while let Some(parent) = graph.parent(node) {
result.push(parent as u32);
result.push(parent as u8);
node = graph.neighbor(node, parent).unwrap();
}
result.reverse();
Expand Down

0 comments on commit cc43ae6

Please sign in to comment.