From acbb7ccba9d5ff736a6a63321207e7269a3b51ee Mon Sep 17 00:00:00 2001 From: Thegaming Life Date: Tue, 28 Feb 2023 10:00:53 +0000 Subject: [PATCH] Changed the chunk size to constant --- client/src/bin/swarm/main.rs | 22 ++++++++++------------ common/src/terrain/mod.rs | 29 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/client/src/bin/swarm/main.rs b/client/src/bin/swarm/main.rs index ae85810d01..735ad30b0c 100644 --- a/client/src/bin/swarm/main.rs +++ b/client/src/bin/swarm/main.rs @@ -1,4 +1,8 @@ -use common::comp; +use common::{ + comp, + terrain::{CoordinateConversions, TerrainChunkSize}, + vol::RectVolSize, +}; use hashbrown::HashSet; use std::{ sync::{ @@ -13,6 +17,8 @@ use tokio::runtime::Runtime; use vek::*; use veloren_client::{addr::ConnectionArgs, Client}; +const CHUNK_SIZE: f32 = TerrainChunkSize::RECT_SIZE.x as f32; + #[derive(Clone, Copy, StructOpt)] struct Opt { /// Number of clients to spin up @@ -210,12 +216,7 @@ fn run_client( } // Main loop - let chunk_size = 32.0; // TODO: replace with the actual constant - let world_center = client - .world_data() - .chunk_size() - .map(|e| e as f32 * chunk_size) - / 2.0; + let world_center = client.world_data().chunk_size().as_::().cpos_to_wpos() / 2.0; loop { // TODO: doesn't seem to produce an error when server is shutdown (process keeps // running) @@ -236,9 +237,6 @@ fn run_client( // Use client index, opts, and current system time to determine position fn position(index: u32, opt: Opt) -> Vec3 { - // TODO: replace 32 with constant for chunk size - let chunk_size = 32.0; - let width = (opt.size as f32).sqrt().round() as u32; let spacing = if opt.clustered { @@ -246,7 +244,7 @@ fn position(index: u32, opt: Opt) -> Vec3 { } else { use common::region::REGION_SIZE; // Attempt to make regions subscribed to by each client not overlapping - opt.vd as f32 * 2.0 * chunk_size + 2.0 * REGION_SIZE as f32 + opt.vd as f32 * 2.0 * CHUNK_SIZE + 2.0 * REGION_SIZE as f32 }; // Offset to center the grid of clients @@ -266,7 +264,7 @@ fn position(index: u32, opt: Opt) -> Vec3 { // move in a square route // in blocks - let route_side_length = chunk_size * opt.vd as f32 * 3.0; + let route_side_length = CHUNK_SIZE * opt.vd as f32 * 3.0; let route_length = route_side_length * 4.0; // in secs let route_time = route_length / SPEED; diff --git a/common/src/terrain/mod.rs b/common/src/terrain/mod.rs index a2d43bab20..3db2b2c92b 100644 --- a/common/src/terrain/mod.rs +++ b/common/src/terrain/mod.rs @@ -76,6 +76,23 @@ impl TerrainChunkSize { } } +pub trait CoordinateConversions { + fn wpos_to_cpos(&self) -> Self; + fn cpos_to_wpos(&self) -> Self; +} + +impl CoordinateConversions for Vec2 { + fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as i32) } + + fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32) } +} + +impl CoordinateConversions for Vec2 { + fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f32) } + + fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as f32) } +} + // TerrainChunkMeta #[derive(Debug, Clone, Serialize, Deserialize)] @@ -165,21 +182,15 @@ impl TerrainChunkMeta { pub fn tracks(&self) -> &[CubicBezier3] { &self.tracks } - pub fn add_track(&mut self, bezier: CubicBezier3) { - self.tracks.push(bezier); - } + pub fn add_track(&mut self, bezier: CubicBezier3) { self.tracks.push(bezier); } pub fn debug_points(&self) -> &[Vec3] { &self.debug_points } - pub fn add_debug_point(&mut self, point: Vec3) { - self.debug_points.push(point); - } + pub fn add_debug_point(&mut self, point: Vec3) { self.debug_points.push(point); } pub fn debug_lines(&self) -> &[LineSegment3] { &self.debug_lines } - pub fn add_debug_line(&mut self, line: LineSegment3) { - self.debug_lines.push(line); - } + pub fn add_debug_line(&mut self, line: LineSegment3) { self.debug_lines.push(line); } } // Terrain type aliases