Changed the chunk size to constant

This commit is contained in:
Thegaming Life 2023-02-28 10:00:53 +00:00 committed by Marcel
parent 01da8b6a82
commit acbb7ccba9
2 changed files with 30 additions and 21 deletions

View File

@ -1,4 +1,8 @@
use common::comp; use common::{
comp,
terrain::{CoordinateConversions, TerrainChunkSize},
vol::RectVolSize,
};
use hashbrown::HashSet; use hashbrown::HashSet;
use std::{ use std::{
sync::{ sync::{
@ -13,6 +17,8 @@ use tokio::runtime::Runtime;
use vek::*; use vek::*;
use veloren_client::{addr::ConnectionArgs, Client}; use veloren_client::{addr::ConnectionArgs, Client};
const CHUNK_SIZE: f32 = TerrainChunkSize::RECT_SIZE.x as f32;
#[derive(Clone, Copy, StructOpt)] #[derive(Clone, Copy, StructOpt)]
struct Opt { struct Opt {
/// Number of clients to spin up /// Number of clients to spin up
@ -210,12 +216,7 @@ fn run_client(
} }
// Main loop // Main loop
let chunk_size = 32.0; // TODO: replace with the actual constant let world_center = client.world_data().chunk_size().as_::<f32>().cpos_to_wpos() / 2.0;
let world_center = client
.world_data()
.chunk_size()
.map(|e| e as f32 * chunk_size)
/ 2.0;
loop { loop {
// TODO: doesn't seem to produce an error when server is shutdown (process keeps // TODO: doesn't seem to produce an error when server is shutdown (process keeps
// running) // running)
@ -236,9 +237,6 @@ fn run_client(
// Use client index, opts, and current system time to determine position // Use client index, opts, and current system time to determine position
fn position(index: u32, opt: Opt) -> Vec3<f32> { fn position(index: u32, opt: Opt) -> Vec3<f32> {
// TODO: replace 32 with constant for chunk size
let chunk_size = 32.0;
let width = (opt.size as f32).sqrt().round() as u32; let width = (opt.size as f32).sqrt().round() as u32;
let spacing = if opt.clustered { let spacing = if opt.clustered {
@ -246,7 +244,7 @@ fn position(index: u32, opt: Opt) -> Vec3<f32> {
} else { } else {
use common::region::REGION_SIZE; use common::region::REGION_SIZE;
// Attempt to make regions subscribed to by each client not overlapping // 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 // Offset to center the grid of clients
@ -266,7 +264,7 @@ fn position(index: u32, opt: Opt) -> Vec3<f32> {
// move in a square route // move in a square route
// in blocks // 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; let route_length = route_side_length * 4.0;
// in secs // in secs
let route_time = route_length / SPEED; let route_time = route_length / SPEED;

View File

@ -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<i32> {
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<f32> {
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 // TerrainChunkMeta
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -165,21 +182,15 @@ impl TerrainChunkMeta {
pub fn tracks(&self) -> &[CubicBezier3<f32>] { &self.tracks } pub fn tracks(&self) -> &[CubicBezier3<f32>] { &self.tracks }
pub fn add_track(&mut self, bezier: CubicBezier3<f32>) { pub fn add_track(&mut self, bezier: CubicBezier3<f32>) { self.tracks.push(bezier); }
self.tracks.push(bezier);
}
pub fn debug_points(&self) -> &[Vec3<f32>] { &self.debug_points } pub fn debug_points(&self) -> &[Vec3<f32>] { &self.debug_points }
pub fn add_debug_point(&mut self, point: Vec3<f32>) { pub fn add_debug_point(&mut self, point: Vec3<f32>) { self.debug_points.push(point); }
self.debug_points.push(point);
}
pub fn debug_lines(&self) -> &[LineSegment3<f32>] { &self.debug_lines } pub fn debug_lines(&self) -> &[LineSegment3<f32>] { &self.debug_lines }
pub fn add_debug_line(&mut self, line: LineSegment3<f32>) { pub fn add_debug_line(&mut self, line: LineSegment3<f32>) { self.debug_lines.push(line); }
self.debug_lines.push(line);
}
} }
// Terrain type aliases // Terrain type aliases