organization and buidings db
This commit is contained in:
13
game/buildings/Cargo.toml
Normal file
13
game/buildings/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "buildings"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.13.2"
|
||||
world_generation = {path = "../../engine/world_generation"}
|
||||
|
||||
[features]
|
||||
tracing = []
|
||||
65
game/buildings/src/buildings_database.rs
Normal file
65
game/buildings/src/buildings_database.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use bevy::prelude::*;
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct BuildingDatabase {
|
||||
pub chunks: Vec<BuildingChunk>,
|
||||
}
|
||||
|
||||
impl BuildingDatabase {
|
||||
pub fn new(size: UVec2) -> Self {
|
||||
let mut db = BuildingDatabase {
|
||||
chunks: Vec::with_capacity(size.length_squared() as usize),
|
||||
};
|
||||
|
||||
for y in 0..size.y as i32 {
|
||||
for x in 0..size.x as i32 {
|
||||
let offset = IVec2::new(x, y);
|
||||
let index = (x + y * size.x as i32) as usize;
|
||||
db.chunks.push(BuildingChunk::new(offset, index));
|
||||
}
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
pub fn get_buildings_in_range(&self, coord: &HexCoord, radius: usize) -> Option<Vec<&BuildingEntry>> {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
todo!();
|
||||
}
|
||||
|
||||
pub fn get_building(&self, coord: &HexCoord) -> Option<&BuildingEntry> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BuildingChunk {
|
||||
pub entries: Vec<BuildingChunk>,
|
||||
pub index: usize,
|
||||
pub offset: IVec2,
|
||||
}
|
||||
|
||||
impl BuildingChunk {
|
||||
pub fn new(offset: IVec2, index: usize) -> Self {
|
||||
return BuildingChunk {
|
||||
entries: Vec::new(),
|
||||
index,
|
||||
offset,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_building(&self, coord: &HexCoord) -> Option<&BuildingEntry> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BuildingEntry {
|
||||
pub coord: HexCoord,
|
||||
pub entity: Entity,
|
||||
}
|
||||
|
||||
impl BuildingEntry {
|
||||
pub fn new(coord: HexCoord, entity: Entity) -> Self {
|
||||
return BuildingEntry { coord, entity };
|
||||
}
|
||||
}
|
||||
1
game/buildings/src/lib.rs
Normal file
1
game/buildings/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod buildings_database;
|
||||
@@ -14,7 +14,7 @@ noise = "0.8.2"
|
||||
world_generation ={path="../../engine/world_generation"}
|
||||
bevy_rapier3d = { version = "0.25.0", features = [ "simd-stable","parallel" ] }
|
||||
rayon = "1.10.0"
|
||||
|
||||
buildings = {path="../buildings"}
|
||||
|
||||
[features]
|
||||
tracing = ["bevy/trace_tracy", "world_generation/tracing"]
|
||||
tracing = ["bevy/trace_tracy", "world_generation/tracing", "buildings/tracing"]
|
||||
@@ -10,9 +10,8 @@ use bevy_rapier3d::geometry::{Collider, TriMeshFlags};
|
||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||
use world_generation::{
|
||||
biome_painter::BiomePainterAsset,
|
||||
chunk_colliders::generate_chunk_collider,
|
||||
hex_utils::{offset_to_index, offset_to_world},
|
||||
mesh_generator::generate_chunk_mesh,
|
||||
generators::{chunk_colliders::generate_chunk_collider, mesh_generator::generate_chunk_mesh},
|
||||
hex_utils::offset_to_world,
|
||||
prelude::{Chunk, Map, MeshChunkData},
|
||||
tile_manager::TileAsset,
|
||||
tile_mapper::TileMapperAsset,
|
||||
|
||||
@@ -34,7 +34,6 @@ impl Default for RenderDistanceSettings {
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct RenderDistanceVisibility {
|
||||
pub distance_multiplier: f32,
|
||||
pub offset: Vec3,
|
||||
}
|
||||
|
||||
@@ -43,19 +42,11 @@ impl RenderDistanceVisibility {
|
||||
self.offset = offset;
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn with_multiplier(mut self, distance_multiplier: f32) -> Self {
|
||||
self.distance_multiplier = distance_multiplier;
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RenderDistanceVisibility {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
distance_multiplier: 1.,
|
||||
offset: Vec3::ZERO,
|
||||
}
|
||||
Self { offset: Vec3::ZERO }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +57,7 @@ fn render_distance_system(
|
||||
) {
|
||||
let camera = camera_query.single();
|
||||
for (t, mut vis, r) in objects.iter_mut() {
|
||||
let dist = (camera.translation - (t.translation + r.offset)).length() * r.distance_multiplier;
|
||||
let dist = (camera.translation - (t.translation + r.offset)).length();
|
||||
if settings.render_distance < dist {
|
||||
*vis = Visibility::Hidden;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user