Compare commits
7 Commits
bevy-16
...
c5da119109
| Author | SHA1 | Date | |
|---|---|---|---|
| c5da119109 | |||
| 945bb8c4de | |||
| b567dd00fd | |||
| e3ddd3b5d4 | |||
| 2bf3319181 | |||
| 45c1c072da | |||
| e8735b83b3 |
5839
Cargo.lock
generated
5839
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,14 @@
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"game/main",
|
"game/main",
|
||||||
"game/buildings",
|
|
||||||
"game/shared",
|
"game/shared",
|
||||||
|
"game/buildings",
|
||||||
|
"game/units",
|
||||||
|
"game/resources",
|
||||||
"engine/world_generation",
|
"engine/world_generation",
|
||||||
"engine/asset_loader", "game/buildings", "game/shared", "game/units", "engine/data", "game/resources", "engine/asset_loader_proc"]
|
"engine/asset_loader",
|
||||||
|
"engine/data",
|
||||||
|
]
|
||||||
|
|
||||||
# Enable a small amount of optimization in debug mode
|
# Enable a small amount of optimization in debug mode
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0.204"
|
serde = "1.0.228"
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.149"
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ macro_rules! create_asset_loader {
|
|||||||
$($string_array_name: ident -> $handle_array_name: ident)* ?
|
$($string_array_name: ident -> $handle_array_name: ident)* ?
|
||||||
) => {
|
) => {
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::asset::{AssetLoader, AssetEvent, AssetEvents, LoadContext, LoadState, AsyncReadExt, io::Reader};
|
use bevy::asset::{AssetLoader, AssetEvent, LoadContext, LoadState, AsyncReadExt, io::Reader};
|
||||||
pub struct $plugin_name;
|
pub struct $plugin_name;
|
||||||
impl Plugin for $plugin_name {
|
impl Plugin for $plugin_name {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
@@ -18,7 +18,7 @@ macro_rules! create_asset_loader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, TypePath)]
|
||||||
pub struct $loader_name;
|
pub struct $loader_name;
|
||||||
|
|
||||||
impl AssetLoader for $loader_name {
|
impl AssetLoader for $loader_name {
|
||||||
@@ -31,8 +31,8 @@ macro_rules! create_asset_loader {
|
|||||||
async fn load(
|
async fn load(
|
||||||
&self,
|
&self,
|
||||||
reader: &mut dyn bevy::asset::io::Reader,
|
reader: &mut dyn bevy::asset::io::Reader,
|
||||||
_: &Self::Settings,
|
settings: &Self::Settings,
|
||||||
load_context: &mut LoadContext<'_>,
|
load_context: &mut bevy::asset::LoadContext<'_>,
|
||||||
) -> Result<Self::Asset, Self::Error>{
|
) -> Result<Self::Asset, Self::Error>{
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
let read_result = reader.read_to_end(&mut bytes).await;
|
let read_result = reader.read_to_end(&mut bytes).await;
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "asset_loader_proc"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
serde = "1.0.204"
|
|
||||||
serde_json = "1.0.120"
|
|
||||||
bevy = "0.16.0"
|
|
||||||
ron = "0.8.1"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
@@ -6,19 +6,19 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
noise = "0.9.0"
|
noise = "0.9.0"
|
||||||
serde = { version = "1.0.203", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.149"
|
||||||
asset_loader = { path = "../asset_loader" }
|
asset_loader = { path = "../asset_loader" }
|
||||||
rayon = "1.10.0"
|
rayon = "1.11.0"
|
||||||
bevy-inspector-egui = "0.28.1"
|
bevy-inspector-egui = "0.36.0"
|
||||||
bevy_asset_loader = { version = "0.23.0-rc.3", features = [
|
bevy_asset_loader = { version = "0.25.0", features = [
|
||||||
"standard_dynamic_assets",
|
"standard_dynamic_assets",
|
||||||
"3d",
|
"3d",
|
||||||
] }
|
] }
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
image = "0.25.2"
|
image = "0.25.9"
|
||||||
num = "0.4.3"
|
num = "0.4.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use bevy::{
|
use bevy::{mesh::MeshVertexAttribute, prelude::*, render::render_resource::VertexFormat};
|
||||||
prelude::*,
|
|
||||||
render::{mesh::MeshVertexAttribute, render_resource::VertexFormat},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::hex_utils::{INNER_RADIUS, OUTER_RADIUS};
|
use crate::hex_utils::{INNER_RADIUS, OUTER_RADIUS};
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
use crate::hex_utils::HexCoord;
|
use crate::hex_utils::HexCoord;
|
||||||
use crate::{hex_utils::offset3d_to_world, prelude::*};
|
use crate::{hex_utils::offset3d_to_world, prelude::*};
|
||||||
|
use bevy::asset::RenderAssetUsages;
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use bevy::log::*;
|
use bevy::log::*;
|
||||||
use bevy::{
|
use bevy::mesh::{Indices, PrimitiveTopology};
|
||||||
prelude::*,
|
use bevy::prelude::*;
|
||||||
render::{
|
|
||||||
mesh::{Indices, PrimitiveTopology},
|
|
||||||
render_asset::RenderAssetUsages,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn generate_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
pub fn generate_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use crate::hex_utils::{offset3d_to_world, HexCoord};
|
use crate::hex_utils::HexCoord;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use bevy::asset::RenderAssetUsages;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
|
||||||
render::{
|
|
||||||
mesh::{Indices, PrimitiveTopology},
|
mesh::{Indices, PrimitiveTopology},
|
||||||
render_asset::RenderAssetUsages,
|
prelude::*,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn generate_packed_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
pub fn generate_packed_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
|
|
||||||
use bevy::{asset::AssetLoader, math::VectorSpace, prelude::*};
|
use bevy::{math::VectorSpace, prelude::*};
|
||||||
use image::ImageBuffer;
|
use image::ImageBuffer;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
@@ -13,7 +13,8 @@ pub fn render_image(
|
|||||||
data: &Vec<f32>,
|
data: &Vec<f32>,
|
||||||
color1: LinearRgba,
|
color1: LinearRgba,
|
||||||
color2: LinearRgba,
|
color2: LinearRgba,
|
||||||
) -> ImageBuffer<image::Rgba<u8>, Vec<u8>> {
|
) -> ImageBuffer<image::Rgba<u8>, Vec<u8>>
|
||||||
|
{
|
||||||
let mut image = ImageBuffer::new(size.x * Chunk::SIZE as u32, size.y * Chunk::SIZE as u32);
|
let mut image = ImageBuffer::new(size.x * Chunk::SIZE as u32, size.y * Chunk::SIZE as u32);
|
||||||
update_image(size, data, color1, color2, &mut image);
|
update_image(size, data, color1, color2, &mut image);
|
||||||
|
|
||||||
@@ -26,7 +27,8 @@ pub fn update_image(
|
|||||||
color1: LinearRgba,
|
color1: LinearRgba,
|
||||||
color2: LinearRgba,
|
color2: LinearRgba,
|
||||||
image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>,
|
image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let min = *data.iter().min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap_or(&0.0);
|
let min = *data.iter().min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap_or(&0.0);
|
||||||
let max = *data.iter().min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap_or(&1.0);
|
let max = *data.iter().min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap_or(&1.0);
|
||||||
|
|
||||||
@@ -41,7 +43,8 @@ pub fn update_image(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_pixel(col: &LinearRgba) -> image::Rgba<u8> {
|
fn to_pixel(col: &LinearRgba) -> image::Rgba<u8>
|
||||||
|
{
|
||||||
return image::Rgba([
|
return image::Rgba([
|
||||||
(col.red * 255.0) as u8,
|
(col.red * 255.0) as u8,
|
||||||
(col.green * 255.0) as u8,
|
(col.green * 255.0) as u8,
|
||||||
@@ -49,7 +52,8 @@ fn to_pixel(col: &LinearRgba) -> image::Rgba<u8> {
|
|||||||
255,
|
255,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
pub fn render_map(map: &Map, smooth: f32) -> ImageBuffer<image::Rgba<u8>, Vec<u8>> {
|
pub fn render_map(map: &Map, smooth: f32) -> ImageBuffer<image::Rgba<u8>, Vec<u8>>
|
||||||
|
{
|
||||||
let mut image = ImageBuffer::new(
|
let mut image = ImageBuffer::new(
|
||||||
map.width as u32 * Chunk::SIZE as u32,
|
map.width as u32 * Chunk::SIZE as u32,
|
||||||
map.height as u32 * Chunk::SIZE as u32,
|
map.height as u32 * Chunk::SIZE as u32,
|
||||||
@@ -57,18 +61,21 @@ pub fn render_map(map: &Map, smooth: f32) -> ImageBuffer<image::Rgba<u8>, Vec<u8
|
|||||||
update_map(map, smooth, &mut image);
|
update_map(map, smooth, &mut image);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
pub fn update_map(map: &Map, smooth: f32, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>) {
|
pub fn update_map(map: &Map, smooth: f32, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>)
|
||||||
|
{
|
||||||
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
||||||
let coord = HexCoord::from_grid_pos(x as usize, y as usize);
|
let coord = HexCoord::from_grid_pos(x as usize, y as usize);
|
||||||
let right = coord.get_neighbor(1);
|
let right = coord.get_neighbor(1);
|
||||||
let height = map.sample_height(&coord);
|
let height = map.sample_height(&coord);
|
||||||
|
|
||||||
let mut color = Hsla::hsl(138.0, 1.0, 0.4);
|
let mut color = Hsla::hsl(138.0, 1.0, 0.4);
|
||||||
if height < map.sealevel {
|
if height < map.sealevel
|
||||||
|
{
|
||||||
color.hue = 217.0;
|
color.hue = 217.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if map.is_in_bounds(&right) {
|
if map.is_in_bounds(&right)
|
||||||
|
{
|
||||||
let h2 = map.sample_height(&right);
|
let h2 = map.sample_height(&right);
|
||||||
color = get_height_color_blend(color, height, h2, smooth);
|
color = get_height_color_blend(color, height, h2, smooth);
|
||||||
}
|
}
|
||||||
@@ -77,22 +84,33 @@ pub fn update_map(map: &Map, smooth: f32, image: &mut ImageBuffer<image::Rgba<u8
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_height_color_blend(base_color: Hsla, height: f32, height2: f32, smooth: f32) -> Hsla {
|
fn get_height_color_blend(base_color: Hsla, height: f32, height2: f32, smooth: f32) -> Hsla
|
||||||
|
{
|
||||||
let mut color = base_color;
|
let mut color = base_color;
|
||||||
let mut d = height2 - height;
|
let mut d = height2 - height;
|
||||||
if smooth == 0.0 || d.abs() > smooth {
|
if smooth == 0.0 || d.abs() > smooth
|
||||||
if d > 0.0 {
|
{
|
||||||
|
if d > 0.0
|
||||||
|
{
|
||||||
color.lightness += 0.1;
|
color.lightness += 0.1;
|
||||||
} else if d < 0.0 {
|
}
|
||||||
|
else if d < 0.0
|
||||||
|
{
|
||||||
color.lightness -= 0.1;
|
color.lightness -= 0.1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if d.abs() <= smooth {
|
else
|
||||||
|
{
|
||||||
|
if d.abs() <= smooth
|
||||||
|
{
|
||||||
d /= smooth;
|
d /= smooth;
|
||||||
if d > 0.0 {
|
if d > 0.0
|
||||||
|
{
|
||||||
let c2: LinearRgba = color.with_lightness(color.lightness + 0.1).into();
|
let c2: LinearRgba = color.with_lightness(color.lightness + 0.1).into();
|
||||||
color = LinearRgba::lerp(color.into(), c2, d).into();
|
color = LinearRgba::lerp(color.into(), c2, d).into();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
let c2: LinearRgba = color.with_lightness(color.lightness - 0.1).into();
|
let c2: LinearRgba = color.with_lightness(color.lightness - 0.1).into();
|
||||||
color = LinearRgba::lerp(color.into(), c2, d.abs()).into();
|
color = LinearRgba::lerp(color.into(), c2, d.abs()).into();
|
||||||
}
|
}
|
||||||
@@ -102,13 +120,15 @@ fn get_height_color_blend(base_color: Hsla, height: f32, height2: f32, smooth: f
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_biome_noise_map(map: &BiomeMap, multi: Vec3) -> ImageBuffer<image::Rgba<u8>, Vec<u8>> {
|
pub fn render_biome_noise_map(map: &BiomeMap, multi: Vec3) -> ImageBuffer<image::Rgba<u8>, Vec<u8>>
|
||||||
|
{
|
||||||
let mut image = ImageBuffer::new(map.width as u32, map.height as u32);
|
let mut image = ImageBuffer::new(map.width as u32, map.height as u32);
|
||||||
update_biome_noise_map(map, multi, &mut image);
|
update_biome_noise_map(map, multi, &mut image);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_biome_noise_map(map: &BiomeMap, multi: Vec3, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>) {
|
pub fn update_biome_noise_map(map: &BiomeMap, multi: Vec3, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>)
|
||||||
|
{
|
||||||
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
||||||
let tile = map.get_biome_data(x as usize, y as usize);
|
let tile = map.get_biome_data(x as usize, y as usize);
|
||||||
|
|
||||||
@@ -121,7 +141,8 @@ pub fn update_biome_noise_map(map: &BiomeMap, multi: Vec3, image: &mut ImageBuff
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_biome_map(map: &Map, biome_map: &BiomeMap) -> ImageBuffer<image::Rgba<u8>, Vec<u8>> {
|
pub fn render_biome_map(map: &Map, biome_map: &BiomeMap) -> ImageBuffer<image::Rgba<u8>, Vec<u8>>
|
||||||
|
{
|
||||||
let mut image = ImageBuffer::new(
|
let mut image = ImageBuffer::new(
|
||||||
map.width as u32 * Chunk::SIZE as u32,
|
map.width as u32 * Chunk::SIZE as u32,
|
||||||
map.height as u32 * Chunk::SIZE as u32,
|
map.height as u32 * Chunk::SIZE as u32,
|
||||||
@@ -130,19 +151,22 @@ pub fn render_biome_map(map: &Map, biome_map: &BiomeMap) -> ImageBuffer<image::R
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_biome_map(map: &Map, biome_map: &BiomeMap, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>) {
|
pub fn update_biome_map(map: &Map, biome_map: &BiomeMap, image: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>)
|
||||||
|
{
|
||||||
let map_biome_count = map.biome_count as f32;
|
let map_biome_count = map.biome_count as f32;
|
||||||
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
image.par_enumerate_pixels_mut().for_each(|(x, y, pixel)| {
|
||||||
let coord = HexCoord::from_grid_pos(x as usize, y as usize);
|
let coord = HexCoord::from_grid_pos(x as usize, y as usize);
|
||||||
let biome_blend = biome_map.get_biome(x as i32, y as i32).unwrap();
|
let biome_blend = biome_map.get_biome(x as i32, y as i32).unwrap();
|
||||||
let right = coord.get_neighbor(1);
|
let right = coord.get_neighbor(1);
|
||||||
let mut color = Oklaba::BLACK;
|
let mut color = Oklaba::BLACK;
|
||||||
for i in 0..biome_blend.len() {
|
for i in 0..biome_blend.len()
|
||||||
|
{
|
||||||
let mut c: Oklaba = Hsla::hsl((i as f32 / map_biome_count) * 360.0, 0.8, 0.7).into();
|
let mut c: Oklaba = Hsla::hsl((i as f32 / map_biome_count) * 360.0, 0.8, 0.7).into();
|
||||||
c *= biome_blend[i];
|
c *= biome_blend[i];
|
||||||
color = Oklaba::add(c, color.into()).into();
|
color = Oklaba::add(c, color.into()).into();
|
||||||
}
|
}
|
||||||
if map.is_in_bounds(&right) {
|
if map.is_in_bounds(&right)
|
||||||
|
{
|
||||||
let h1 = map.sample_height(&coord);
|
let h1 = map.sample_height(&coord);
|
||||||
let h2 = map.sample_height(&right);
|
let h2 = map.sample_height(&right);
|
||||||
color = get_height_color_blend(color.into(), h1, h2, 0.5).into();
|
color = get_height_color_blend(color.into(), h1, h2, 0.5).into();
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use crate::hex_utils::HexCoord;
|
|||||||
|
|
||||||
use super::chunk::Chunk;
|
use super::chunk::Chunk;
|
||||||
|
|
||||||
pub struct MeshChunkData {
|
pub struct MeshChunkData
|
||||||
|
{
|
||||||
pub heights: [f32; Chunk::AREA],
|
pub heights: [f32; Chunk::AREA],
|
||||||
pub textures: [[u32; 2]; Chunk::AREA],
|
pub textures: [[u32; 2]; Chunk::AREA],
|
||||||
pub min_height: f32,
|
pub min_height: f32,
|
||||||
@@ -14,13 +15,17 @@ pub struct MeshChunkData {
|
|||||||
pub distance_to_land: [f32; Chunk::AREA],
|
pub distance_to_land: [f32; Chunk::AREA],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MeshChunkData {
|
impl MeshChunkData
|
||||||
pub fn get_neighbors(&self, coord: &HexCoord) -> [f32; 6] {
|
{
|
||||||
|
pub fn get_neighbors(&self, coord: &HexCoord) -> [f32; 6]
|
||||||
|
{
|
||||||
let mut data = [self.min_height; 6];
|
let mut data = [self.min_height; 6];
|
||||||
let n_tiles = coord.get_neighbors();
|
let n_tiles = coord.get_neighbors();
|
||||||
for i in 0..6 {
|
for i in 0..6
|
||||||
|
{
|
||||||
let n = n_tiles[i];
|
let n = n_tiles[i];
|
||||||
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE) {
|
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
data[i] = self.heights[n.to_index(Chunk::SIZE)];
|
data[i] = self.heights[n.to_index(Chunk::SIZE)];
|
||||||
@@ -29,56 +34,70 @@ impl MeshChunkData {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_neighbors_with_water_info(&self, coord: &HexCoord) -> ([(f32, Option<f32>); 6], bool) {
|
pub fn get_neighbors_with_water_info(&self, coord: &HexCoord) -> ([(f32, Option<f32>); 6], bool)
|
||||||
|
{
|
||||||
let mut has_land = false;
|
let mut has_land = false;
|
||||||
let mut data = [(self.min_height, None); 6];
|
let mut data = [(self.min_height, None); 6];
|
||||||
let n_tiles = coord.get_neighbors();
|
let n_tiles = coord.get_neighbors();
|
||||||
for i in 0..6 {
|
for i in 0..6
|
||||||
|
{
|
||||||
let n = n_tiles[i];
|
let n = n_tiles[i];
|
||||||
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE) {
|
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let idx = n.to_index(Chunk::SIZE);
|
let idx = n.to_index(Chunk::SIZE);
|
||||||
data[i] = (self.heights[idx], Some(self.distance_to_land[idx]));
|
data[i] = (self.heights[idx], Some(self.distance_to_land[idx]));
|
||||||
if data[i].0 > self.sealevel {
|
if data[i].0 > self.sealevel
|
||||||
|
{
|
||||||
has_land = true;
|
has_land = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (data, has_land);
|
return (data, has_land);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn caluclate_water_distances(data: &mut Vec<MeshChunkData>, height: usize, width: usize, range: usize) {
|
pub fn caluclate_water_distances(data: &mut Vec<MeshChunkData>, height: usize, width: usize, _range: usize)
|
||||||
|
{
|
||||||
let mut open: VecDeque<(HexCoord, f32, usize)> = VecDeque::new();
|
let mut open: VecDeque<(HexCoord, f32, usize)> = VecDeque::new();
|
||||||
let mut closed: Vec<(HexCoord, f32)> = Vec::new();
|
// let mut closed: Vec<(HexCoord, f32)> = Vec::new();
|
||||||
for z in 0..height {
|
for z in 0..height
|
||||||
for x in 0..width {
|
{
|
||||||
|
for x in 0..width
|
||||||
|
{
|
||||||
let chunk = &mut data[z * height + x];
|
let chunk = &mut data[z * height + x];
|
||||||
chunk.prepare_chunk_open(x * Chunk::SIZE, z * Chunk::SIZE, &mut open);
|
chunk.prepare_chunk_open(x * Chunk::SIZE, z * Chunk::SIZE, &mut open);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_chunk_open(&mut self, offset_x: usize, offset_z: usize, open: &mut VecDeque<(HexCoord, f32, usize)>) {
|
fn prepare_chunk_open(&mut self, offset_x: usize, offset_z: usize, open: &mut VecDeque<(HexCoord, f32, usize)>)
|
||||||
for z in 0..Chunk::SIZE {
|
{
|
||||||
for x in 0..Chunk::SIZE {
|
for z in 0..Chunk::SIZE
|
||||||
|
{
|
||||||
|
for x in 0..Chunk::SIZE
|
||||||
|
{
|
||||||
let coord = HexCoord::from_grid_pos(x + offset_x, z + offset_z);
|
let coord = HexCoord::from_grid_pos(x + offset_x, z + offset_z);
|
||||||
let idx = coord.to_chunk_local_index();
|
let idx = coord.to_chunk_local_index();
|
||||||
let h = self.heights[idx];
|
let h = self.heights[idx];
|
||||||
self.distance_to_land[idx] = if h > self.sealevel { 0.0 } else { 4.0 };
|
self.distance_to_land[idx] = if h > self.sealevel { 0.0 } else { 4.0 };
|
||||||
if h > self.sealevel {
|
if h > self.sealevel
|
||||||
|
{
|
||||||
open.push_back((coord, h, 0));
|
open.push_back((coord, h, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[allow(unused)]
|
||||||
fn fill_chunk_borders(
|
fn fill_chunk_borders(
|
||||||
&mut self,
|
&mut self,
|
||||||
chunks: &Vec<MeshChunkData>,
|
chunks: &Vec<MeshChunkData>,
|
||||||
offset: IVec2,
|
offset: IVec2,
|
||||||
open: &mut VecDeque<(HexCoord, f32, usize)>,
|
open: &mut VecDeque<(HexCoord, f32, usize)>,
|
||||||
closed: &mut Vec<(HexCoord, f32)>,
|
closed: &mut Vec<(HexCoord, f32)>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
self.prepare_chunk_open(offset.x as usize * Chunk::SIZE, offset.y as usize * Chunk::SIZE, open);
|
self.prepare_chunk_open(offset.x as usize * Chunk::SIZE, offset.y as usize * Chunk::SIZE, open);
|
||||||
todo!("Fill closed list with bordering tiles")
|
todo!("Fill closed list with bordering tiles")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
world_generation = { path = "../../engine/world_generation" }
|
world_generation = { path = "../../engine/world_generation" }
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
bevy_rapier3d = "0.29.0"
|
bevy_rapier3d = "0.33.0"
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
asset_loader = { path = "../../engine/asset_loader" }
|
asset_loader = { path = "../../engine/asset_loader" }
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.149"
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
bevy_asset_loader = { version = "0.23.0-rc.3", features = [
|
bevy_asset_loader = { version = "0.25.0", features = [
|
||||||
"standard_dynamic_assets",
|
"standard_dynamic_assets",
|
||||||
"3d",
|
"3d",
|
||||||
] }
|
] }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use bevy::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use shared::{component_defination::ComponentDefination, identifiers::ResourceIdentifier, prefab_defination::*};
|
use shared::identifiers::ResourceIdentifier;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
buildings::{
|
buildings::{
|
||||||
@@ -12,11 +12,11 @@ use crate::{
|
|||||||
resource_gathering::ResourceGatheringBuildingInfo,
|
resource_gathering::ResourceGatheringBuildingInfo,
|
||||||
},
|
},
|
||||||
footprint::BuildingFootprint,
|
footprint::BuildingFootprint,
|
||||||
prelude::Building,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
||||||
pub struct BuildingAsset {
|
pub struct BuildingAsset
|
||||||
|
{
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub footprint: BuildingFootprint,
|
pub footprint: BuildingFootprint,
|
||||||
@@ -32,10 +32,12 @@ pub struct BuildingAsset {
|
|||||||
pub health: u32,
|
pub health: u32,
|
||||||
|
|
||||||
pub building_type: BuildingType,
|
pub building_type: BuildingType,
|
||||||
pub components: Option<Vec<ComponentDefination>>,
|
// pub components: Option<Vec<ComponentDefination>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildingAsset {
|
impl BuildingAsset
|
||||||
|
{
|
||||||
|
#[allow(unused)]
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
&self,
|
&self,
|
||||||
pos: Vec3,
|
pos: Vec3,
|
||||||
@@ -44,82 +46,85 @@ impl BuildingAsset {
|
|||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
meshes: &Assets<GltfMesh>,
|
meshes: &Assets<GltfMesh>,
|
||||||
nodes: &Assets<GltfNode>,
|
nodes: &Assets<GltfNode>,
|
||||||
) -> Option<Entity> {
|
) -> Option<Entity>
|
||||||
let base_node = &gltf.named_nodes[&self.base_mesh_path.clone().into_boxed_str()];
|
{
|
||||||
if let Some(node) = nodes.get(base_node.id()) {
|
todo!("Update building spawning");
|
||||||
if let Some(mesh_handle) = &node.mesh {
|
// let base_node = &gltf.named_nodes[&self.base_mesh_path.clone().into_boxed_str()];
|
||||||
if let Some(gltf_mesh) = meshes.get(mesh_handle.id()) {
|
// if let Some(node) = nodes.get(base_node.id()) {
|
||||||
let (mesh, mat) = gltf_mesh.unpack();
|
// if let Some(mesh_handle) = &node.mesh {
|
||||||
let mut entity = commands.spawn((
|
// if let Some(gltf_mesh) = meshes.get(mesh_handle.id()) {
|
||||||
Mesh3d(mesh),
|
// let (mesh, mat) = gltf_mesh.unpack();
|
||||||
MeshMaterial3d(mat),
|
// let mut entity = commands.spawn((
|
||||||
Transform::from_translation(pos).with_rotation(rot),
|
// Mesh3d(mesh),
|
||||||
Building,
|
// MeshMaterial3d(mat),
|
||||||
));
|
// Transform::from_translation(pos).with_rotation(rot),
|
||||||
entity.with_children(|b| {
|
// Building,
|
||||||
for child in &node.children {
|
// ));
|
||||||
let child_node = nodes.get(child.id());
|
// entity.with_children(|b| {
|
||||||
if child_node.is_none() {
|
// for child in &node.children {
|
||||||
continue;
|
// let child_node = nodes.get(child.id());
|
||||||
}
|
// if child_node.is_none() {
|
||||||
self.process_node(child_node.unwrap(), meshes, nodes, b, &node.name);
|
// continue;
|
||||||
}
|
// }
|
||||||
});
|
// self.process_node(child_node.unwrap(), meshes, nodes, b, &node.name);
|
||||||
if let Some(component) = self.get_component_def(&format!("/{0}", &node.name)) {
|
// }
|
||||||
component.apply(&mut entity);
|
// });
|
||||||
}
|
// if let Some(component) = self.get_component_def(&format!("/{0}", &node.name)) {
|
||||||
return Some(entity.id());
|
// component.apply(&mut entity);
|
||||||
}
|
// }
|
||||||
}
|
// return Some(entity.id());
|
||||||
}
|
// }
|
||||||
return None;
|
// }
|
||||||
|
// }
|
||||||
|
// return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_node(
|
// fn process_node(
|
||||||
&self,
|
// &self,
|
||||||
node: &GltfNode,
|
// node: &GltfNode,
|
||||||
meshes: &Assets<GltfMesh>,
|
// meshes: &Assets<GltfMesh>,
|
||||||
nodes: &Assets<GltfNode>,
|
// nodes: &Assets<GltfNode>,
|
||||||
commands: &mut ChildBuilder,
|
// commands: &mut ChildBuilder,
|
||||||
parent: &String,
|
// parent: &String,
|
||||||
) -> Option<Entity> {
|
// ) -> Option<Entity> {
|
||||||
let path = format!("{0}/{1}", parent, node.name);
|
// let path = format!("{0}/{1}", parent, node.name);
|
||||||
if let Some(mesh) = &node.mesh {
|
// if let Some(mesh) = &node.mesh {
|
||||||
if let Some(gltf_mesh) = meshes.get(mesh.id()) {
|
// if let Some(gltf_mesh) = meshes.get(mesh.id()) {
|
||||||
let (mesh, mat) = gltf_mesh.unpack();
|
// let (mesh, mat) = gltf_mesh.unpack();
|
||||||
let mut entity = commands.spawn((Mesh3d(mesh), MeshMaterial3d(mat), node.transform, Building));
|
// let mut entity = commands.spawn((Mesh3d(mesh), MeshMaterial3d(mat), node.transform, Building));
|
||||||
entity.with_children(|b| {
|
// entity.with_children(|b| {
|
||||||
for child in &node.children {
|
// for child in &node.children {
|
||||||
let child_node = nodes.get(child.id());
|
// let child_node = nodes.get(child.id());
|
||||||
if child_node.is_none() {
|
// if child_node.is_none() {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
self.process_node(child_node.unwrap(), meshes, nodes, b, &path);
|
// self.process_node(child_node.unwrap(), meshes, nodes, b, &path);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
if let Some(component) = self.get_component_def(&path) {
|
// if let Some(component) = self.get_component_def(&path) {
|
||||||
component.apply(&mut entity);
|
// component.apply(&mut entity);
|
||||||
}
|
// }
|
||||||
return Some(entity.id());
|
// return Some(entity.id());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return None;
|
// return None;
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn get_component_def(&self, path: &String) -> Option<&ComponentDefination> {
|
// fn get_component_def(&self, path: &String) -> Option<&ComponentDefination> {
|
||||||
if let Some(components) = &self.components {
|
// if let Some(components) = &self.components {
|
||||||
for c in components {
|
// for c in components {
|
||||||
if c.path.ends_with(path) {
|
// if c.path.ends_with(path) {
|
||||||
return Some(c);
|
// return Some(c);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return None;
|
// return None;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, TypePath)]
|
#[derive(Serialize, Deserialize, Debug, TypePath)]
|
||||||
pub enum BuildingType {
|
pub enum BuildingType
|
||||||
|
{
|
||||||
Basic,
|
Basic,
|
||||||
Gathering(ResourceGatheringBuildingInfo),
|
Gathering(ResourceGatheringBuildingInfo),
|
||||||
FactoryBuildingInfo(FactoryBuildingInfo),
|
FactoryBuildingInfo(FactoryBuildingInfo),
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
use std::f32::consts::E;
|
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
ecs::world::CommandQueue,
|
ecs::world::CommandQueue,
|
||||||
gltf::{GltfMesh, GltfNode},
|
gltf::{GltfMesh, GltfNode},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
window::PrimaryWindow,
|
|
||||||
};
|
};
|
||||||
use bevy_asset_loader::loading_state::{
|
use bevy_asset_loader::loading_state::{
|
||||||
config::{ConfigureLoadingState, LoadingStateConfig},
|
config::{ConfigureLoadingState, LoadingStateConfig},
|
||||||
LoadingStateAppExt,
|
LoadingStateAppExt,
|
||||||
};
|
};
|
||||||
use bevy_rapier3d::{parry::transformation::utils::transform, pipeline::QueryFilter, plugin::RapierContext};
|
|
||||||
use shared::{
|
use shared::{
|
||||||
despawn::Despawn,
|
despawn::Despawn,
|
||||||
events::TileModifiedEvent,
|
events::TileModifiedEvent,
|
||||||
resources::TileUnderCursor,
|
resources::TileUnderCursor,
|
||||||
states::{AssetLoadState, GameplayState},
|
states::{AssetLoadState, GameplayState},
|
||||||
tags::MainCamera,
|
|
||||||
};
|
|
||||||
use world_generation::{
|
|
||||||
heightmap, hex_utils::HexCoord, map::map::Map, prelude::GenerationConfig, states::GeneratorState,
|
|
||||||
};
|
};
|
||||||
|
use world_generation::{map::map::Map, prelude::GenerationConfig, states::GeneratorState};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::{
|
assets::{
|
||||||
@@ -34,8 +27,10 @@ use crate::{
|
|||||||
|
|
||||||
pub struct BuildingPugin;
|
pub struct BuildingPugin;
|
||||||
|
|
||||||
impl Plugin for BuildingPugin {
|
impl Plugin for BuildingPugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.insert_resource(BuildQueue::default());
|
app.insert_resource(BuildQueue::default());
|
||||||
app.add_plugins(BuildingAssetPlugin);
|
app.add_plugins(BuildingAssetPlugin);
|
||||||
|
|
||||||
@@ -46,7 +41,7 @@ impl Plugin for BuildingPugin {
|
|||||||
app.add_systems(Update, init.run_if(in_state(AssetLoadState::Loading)));
|
app.add_systems(Update, init.run_if(in_state(AssetLoadState::Loading)));
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
hq_placement.run_if(in_state(GameplayState::PlaceHQ).and_then(in_state(GeneratorState::Idle))),
|
hq_placement.run_if(in_state(GameplayState::PlaceHQ).and(in_state(GeneratorState::Idle))),
|
||||||
);
|
);
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
@@ -62,12 +57,15 @@ impl Plugin for BuildingPugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_building_map(mut commands: Commands, cfg: Res<GenerationConfig>) {
|
fn prepare_building_map(mut commands: Commands, cfg: Res<GenerationConfig>)
|
||||||
|
{
|
||||||
commands.insert_resource(BuildingMap::new(cfg.size));
|
commands.insert_resource(BuildingMap::new(cfg.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn regernerate(mut commands: Commands, buildings: Query<Entity, With<Building>>, cfg: Res<GenerationConfig>) {
|
fn regernerate(mut commands: Commands, buildings: Query<Entity, With<Building>>, cfg: Res<GenerationConfig>)
|
||||||
for e in buildings.iter() {
|
{
|
||||||
|
for e in buildings.iter()
|
||||||
|
{
|
||||||
commands.entity(e).despawn();
|
commands.entity(e).despawn();
|
||||||
}
|
}
|
||||||
commands.insert_resource(BuildingMap::new(cfg.size));
|
commands.insert_resource(BuildingMap::new(cfg.size));
|
||||||
@@ -76,7 +74,8 @@ fn regernerate(mut commands: Commands, buildings: Query<Entity, With<Building>>,
|
|||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct IndicatorCube(Handle<Mesh>, Handle<StandardMaterial>);
|
struct IndicatorCube(Handle<Mesh>, Handle<StandardMaterial>);
|
||||||
|
|
||||||
fn init(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>) {
|
fn init(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>)
|
||||||
|
{
|
||||||
let cube = Cuboid::from_size(Vec3::splat(1.));
|
let cube = Cuboid::from_size(Vec3::splat(1.));
|
||||||
let mesh_handle = meshes.add(cube);
|
let mesh_handle = meshes.add(cube);
|
||||||
let mat_handle = materials.add(Color::WHITE);
|
let mat_handle = materials.add(Color::WHITE);
|
||||||
@@ -91,12 +90,15 @@ fn hq_placement(
|
|||||||
indicator: Res<IndicatorCube>,
|
indicator: Res<IndicatorCube>,
|
||||||
mut build_queue: ResMut<BuildQueue>,
|
mut build_queue: ResMut<BuildQueue>,
|
||||||
mut next_state: ResMut<NextState<GameplayState>>,
|
mut next_state: ResMut<NextState<GameplayState>>,
|
||||||
) {
|
)
|
||||||
if let Some(contact) = tile_under_cursor.0 {
|
{
|
||||||
|
if let Some(contact) = tile_under_cursor.0
|
||||||
|
{
|
||||||
let positions = map.hex_select(&contact.tile, 3, true, |pos, h, _| pos.to_world(h));
|
let positions = map.hex_select(&contact.tile, 3, true, |pos, h, _| pos.to_world(h));
|
||||||
show_indicators(positions, &mut commands, &indicator);
|
show_indicators(positions, &mut commands, &indicator);
|
||||||
|
|
||||||
if mouse.just_pressed(MouseButton::Left) {
|
if mouse.just_pressed(MouseButton::Left)
|
||||||
|
{
|
||||||
build_queue.queue.push(QueueEntry {
|
build_queue.queue.push(QueueEntry {
|
||||||
building: 0.into(),
|
building: 0.into(),
|
||||||
pos: contact.tile,
|
pos: contact.tile,
|
||||||
@@ -107,8 +109,10 @@ fn hq_placement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_indicators(positions: Vec<Vec3>, commands: &mut Commands, indicator: &IndicatorCube) {
|
fn show_indicators(positions: Vec<Vec3>, commands: &mut Commands, indicator: &IndicatorCube)
|
||||||
for p in positions {
|
{
|
||||||
|
for p in positions
|
||||||
|
{
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(indicator.0.clone()),
|
Mesh3d(indicator.0.clone()),
|
||||||
MeshMaterial3d(indicator.1.clone()),
|
MeshMaterial3d(indicator.1.clone()),
|
||||||
@@ -128,13 +132,17 @@ fn process_build_queue(
|
|||||||
gltf_nodes: Res<Assets<GltfNode>>,
|
gltf_nodes: Res<Assets<GltfNode>>,
|
||||||
mut building_map: ResMut<BuildingMap>,
|
mut building_map: ResMut<BuildingMap>,
|
||||||
heightmap: Res<Map>,
|
heightmap: Res<Map>,
|
||||||
) {
|
)
|
||||||
for item in &queue.queue {
|
{
|
||||||
|
for item in &queue.queue
|
||||||
|
{
|
||||||
let handle = &db.buildings[item.building.0];
|
let handle = &db.buildings[item.building.0];
|
||||||
if let Some(building) = building_assets.get(handle.id()) {
|
if let Some(building) = building_assets.get(handle.id())
|
||||||
|
{
|
||||||
let h = heightmap.sample_height(&item.pos);
|
let h = heightmap.sample_height(&item.pos);
|
||||||
println!("Spawning {} at {}", building.name, item.pos);
|
println!("Spawning {} at {}", building.name, item.pos);
|
||||||
if let Some(gltf) = gltf_assets.get(building.prefab.id()) {
|
if let Some(gltf) = gltf_assets.get(building.prefab.id())
|
||||||
|
{
|
||||||
let e = building.spawn(
|
let e = building.spawn(
|
||||||
item.pos.to_world(h),
|
item.pos.to_world(h),
|
||||||
Quat::IDENTITY,
|
Quat::IDENTITY,
|
||||||
@@ -143,10 +151,13 @@ fn process_build_queue(
|
|||||||
&gltf_meshes,
|
&gltf_meshes,
|
||||||
&gltf_nodes,
|
&gltf_nodes,
|
||||||
);
|
);
|
||||||
if let Some(b) = e {
|
if let Some(b) = e
|
||||||
|
{
|
||||||
building_map.add_building(BuildingEntry::new(item.pos, b));
|
building_map.add_building(BuildingEntry::new(item.pos, b));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
warn!("Failed to spawn building");
|
warn!("Failed to spawn building");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,20 +166,26 @@ fn process_build_queue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_building_heights(
|
fn update_building_heights(
|
||||||
mut tile_updates: EventReader<TileModifiedEvent>,
|
mut tile_updates: MessageReader<TileModifiedEvent>,
|
||||||
building_map: Res<BuildingMap>,
|
building_map: Res<BuildingMap>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
)
|
||||||
for event in tile_updates.read() {
|
{
|
||||||
match event {
|
for event in tile_updates.read()
|
||||||
TileModifiedEvent::HeightChanged(coord, new_height) => {
|
{
|
||||||
if let Some(building) = building_map.get_building(coord) {
|
match event
|
||||||
|
{
|
||||||
|
TileModifiedEvent::HeightChanged(coord, new_height) =>
|
||||||
|
{
|
||||||
|
if let Some(building) = building_map.get_building(coord)
|
||||||
|
{
|
||||||
let mut queue = CommandQueue::default();
|
let mut queue = CommandQueue::default();
|
||||||
let e = building.entity.clone();
|
let e = building.entity.clone();
|
||||||
let h = *new_height;
|
let h = *new_height;
|
||||||
queue.push(move |world: &mut World| {
|
queue.push(move |world: &mut World| {
|
||||||
let mut emut = world.entity_mut(e);
|
let mut emut = world.entity_mut(e);
|
||||||
if let Some(mut transform) = emut.get_mut::<Transform>() {
|
if let Some(mut transform) = emut.get_mut::<Transform>()
|
||||||
|
{
|
||||||
transform.translation.y = h;
|
transform.translation.y = h;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,32 +1,39 @@
|
|||||||
use bevy::math::{IVec2, Vec3Swizzles};
|
use bevy::math::{IVec2, Vec3Swizzles};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use shared::coords::CoordsCollection;
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct BuildingFootprint {
|
pub struct BuildingFootprint
|
||||||
|
{
|
||||||
pub footprint: Vec<IVec2>,
|
pub footprint: Vec<IVec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildingFootprint {
|
impl BuildingFootprint
|
||||||
pub fn get_footprint(&self, center: &HexCoord) -> Vec<HexCoord> {
|
{
|
||||||
let c = center.hex.xy();
|
pub fn get_footprint(&self, position: &HexCoord) -> CoordsCollection
|
||||||
return self.footprint.iter().map(|p| HexCoord::from_hex(*p + c)).collect();
|
{
|
||||||
|
CoordsCollection::from_points(self.footprint.clone()).with_translation(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_footprint_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
|
pub fn get_neighbors(&self, position: &HexCoord) -> CoordsCollection
|
||||||
let c = center.hex.xy();
|
{
|
||||||
return self
|
let n_points: Vec<IVec2> = self
|
||||||
.footprint
|
.footprint
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| HexCoord::from_hex(*p + c).rotate_around(center, rotation))
|
.flat_map(|p| HexCoord::from_hex(*p).get_neighbors())
|
||||||
|
.map(|c| c.hex.xy())
|
||||||
|
.filter(|p| !self.footprint.contains(p))
|
||||||
.collect();
|
.collect();
|
||||||
|
let mut out_points: Vec<IVec2> = Vec::with_capacity(n_points.len());
|
||||||
|
for p in n_points
|
||||||
|
{
|
||||||
|
if out_points.contains(&p)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
out_points.push(p);
|
||||||
pub fn get_neighbors(&self, center: &HexCoord) -> Vec<HexCoord> {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
|
return CoordsCollection::from_points(out_points).with_translation(position);
|
||||||
pub fn get_neighbors_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
|
|
||||||
todo!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,26 +7,26 @@ build = "build.rs"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.16.0", features = ["file_watcher"] }
|
bevy = { version = "0.18.0", features = ["file_watcher"] }
|
||||||
bevy-inspector-egui = "0.28.1"
|
bevy-inspector-egui = "0.36.0"
|
||||||
# iyes_perf_ui = "0.3.0"
|
# iyes_perf_ui = "0.3.0"
|
||||||
noise = "0.8.2"
|
noise = "0.9.0"
|
||||||
world_generation = { path = "../../engine/world_generation" }
|
world_generation = { path = "../../engine/world_generation" }
|
||||||
bevy_rapier3d = { version = "0.29.0", features = [
|
bevy_rapier3d = { version = "0.33.0", features = [
|
||||||
"simd-stable",
|
"simd-stable",
|
||||||
"parallel",
|
"parallel",
|
||||||
"debug-render-3d",
|
"debug-render-3d",
|
||||||
] }
|
] }
|
||||||
rayon = "1.10.0"
|
rayon = "1.11.0"
|
||||||
buildings = { path = "../buildings" }
|
buildings = { path = "../buildings" }
|
||||||
units = { path = "../units" }
|
units = { path = "../units" }
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
bevy_asset_loader = { version = "0.23.0-rc.3", features = [
|
bevy_asset_loader = { version = "0.25.0", features = [
|
||||||
"standard_dynamic_assets",
|
"standard_dynamic_assets",
|
||||||
"3d",
|
"3d",
|
||||||
] }
|
] }
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
image = "0.25.2"
|
image = "0.25.9"
|
||||||
# bevy_lunex = "0.2.4"
|
# bevy_lunex = "0.2.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
Submodule game/main/assets updated: f1c26c1519...9cd8a544d5
@@ -1,8 +1,8 @@
|
|||||||
use bevy::core_pipeline::experimental::taa::{TemporalAntiAliasBundle, TemporalAntiAliasPlugin, TemporalAntiAliasing};
|
use bevy::anti_alias::taa::TemporalAntiAliasing;
|
||||||
use bevy::core_pipeline::prepass::DepthPrepass;
|
use bevy::core_pipeline::prepass::DepthPrepass;
|
||||||
use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel};
|
use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::{CursorGrabMode, PrimaryWindow};
|
use bevy::window::{CursorGrabMode, CursorOptions, PrimaryWindow};
|
||||||
use shared::sets::GameplaySet;
|
use shared::sets::GameplaySet;
|
||||||
use shared::tags::MainCamera;
|
use shared::tags::MainCamera;
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
@@ -13,8 +13,10 @@ use super::components::*;
|
|||||||
|
|
||||||
pub struct PhosCameraPlugin;
|
pub struct PhosCameraPlugin;
|
||||||
|
|
||||||
impl Plugin for PhosCameraPlugin {
|
impl Plugin for PhosCameraPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.register_type::<PhosCamera>();
|
app.register_type::<PhosCamera>();
|
||||||
app.register_type::<PhosOrbitCamera>();
|
app.register_type::<PhosOrbitCamera>();
|
||||||
|
|
||||||
@@ -23,17 +25,12 @@ impl Plugin for PhosCameraPlugin {
|
|||||||
app.add_systems(Update, orbit_camera_upate.in_set(GameplaySet));
|
app.add_systems(Update, orbit_camera_upate.in_set(GameplaySet));
|
||||||
|
|
||||||
app.add_systems(Update, init_bounds.run_if(in_state(GeneratorState::SpawnMap)));
|
app.add_systems(Update, init_bounds.run_if(in_state(GeneratorState::SpawnMap)));
|
||||||
|
|
||||||
app.add_plugins(TemporalAntiAliasPlugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_bounds(
|
fn init_bounds(mut commands: Commands, cam: Single<(&mut Transform, Entity), With<PhosCamera>>, heightmap: Res<Map>)
|
||||||
mut commands: Commands,
|
{
|
||||||
mut cam: Query<(&mut Transform, Entity), With<PhosCamera>>,
|
let (mut cam_t, cam_entity) = cam.into_inner();
|
||||||
heightmap: Res<Map>,
|
|
||||||
) {
|
|
||||||
let (mut cam_t, cam_entity) = cam.single_mut();
|
|
||||||
cam_t.translation = heightmap.get_center();
|
cam_t.translation = heightmap.get_center();
|
||||||
commands
|
commands
|
||||||
.entity(cam_entity)
|
.entity(cam_entity)
|
||||||
@@ -44,7 +41,8 @@ fn init_bounds(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands) {
|
fn setup(mut commands: Commands)
|
||||||
|
{
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Camera3d::default(),
|
Camera3d::default(),
|
||||||
@@ -62,18 +60,18 @@ fn setup(mut commands: Commands) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn orbit_camera_upate(
|
fn orbit_camera_upate(
|
||||||
mut cam_query: Query<(&mut Transform, &PhosCamera, &mut PhosOrbitCamera, &CameraBounds)>,
|
cam_query: Single<(&mut Transform, &PhosCamera, &mut PhosOrbitCamera, &CameraBounds)>,
|
||||||
mut wheel: EventReader<MouseWheel>,
|
mut wheel: MessageReader<MouseWheel>,
|
||||||
mut mouse_motion: EventReader<MouseMotion>,
|
mut mouse_motion: MessageReader<MouseMotion>,
|
||||||
mouse: Res<ButtonInput<MouseButton>>,
|
mouse: Res<ButtonInput<MouseButton>>,
|
||||||
mut window_query: Query<&mut Window, With<PrimaryWindow>>,
|
mut cursor_options: Single<&mut CursorOptions, With<PrimaryWindow>>,
|
||||||
key: Res<ButtonInput<KeyCode>>,
|
key: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
map: Res<Map>,
|
map: Res<Map>,
|
||||||
#[cfg(debug_assertions)] mut gizmos: Gizmos,
|
#[cfg(debug_assertions)] mut gizmos: Gizmos,
|
||||||
) {
|
)
|
||||||
let (mut transform, config, mut orbit, bounds) = cam_query.single_mut();
|
{
|
||||||
let mut window = window_query.single_mut();
|
let (mut transform, config, mut orbit, bounds) = cam_query.into_inner();
|
||||||
|
|
||||||
let target = orbit.target;
|
let target = orbit.target;
|
||||||
let mut cam_pos = target;
|
let mut cam_pos = target;
|
||||||
@@ -81,9 +79,11 @@ fn orbit_camera_upate(
|
|||||||
//Apply Camera Dist
|
//Apply Camera Dist
|
||||||
cam_pos -= orbit.forward * orbit.distance;
|
cam_pos -= orbit.forward * orbit.distance;
|
||||||
|
|
||||||
if mouse.pressed(MouseButton::Middle) {
|
if mouse.pressed(MouseButton::Middle)
|
||||||
|
{
|
||||||
let mut orbit_move = Vec2::ZERO;
|
let mut orbit_move = Vec2::ZERO;
|
||||||
for e in mouse_motion.read() {
|
for e in mouse_motion.read()
|
||||||
|
{
|
||||||
orbit_move += e.delta;
|
orbit_move += e.delta;
|
||||||
}
|
}
|
||||||
orbit_move *= config.pan_speed * time.delta_secs() * -1.0;
|
orbit_move *= config.pan_speed * time.delta_secs() * -1.0;
|
||||||
@@ -93,41 +93,56 @@ fn orbit_camera_upate(
|
|||||||
orbit.forward = rot_x * rot_y * orbit.forward;
|
orbit.forward = rot_x * rot_y * orbit.forward;
|
||||||
// orbit.forward.y = orbit.forward.y.clamp(-0.9, 0.0);
|
// orbit.forward.y = orbit.forward.y.clamp(-0.9, 0.0);
|
||||||
orbit.forward = orbit.forward.normalize();
|
orbit.forward = orbit.forward.normalize();
|
||||||
window.cursor_options.grab_mode = CursorGrabMode::Locked;
|
cursor_options.grab_mode = CursorGrabMode::Locked;
|
||||||
window.cursor_options.visible = false;
|
cursor_options.visible = false;
|
||||||
} else {
|
|
||||||
window.cursor_options.grab_mode = CursorGrabMode::None;
|
|
||||||
window.cursor_options.visible = true;
|
|
||||||
}
|
}
|
||||||
if key.pressed(KeyCode::KeyE) {
|
else
|
||||||
|
{
|
||||||
|
cursor_options.grab_mode = CursorGrabMode::None;
|
||||||
|
cursor_options.visible = true;
|
||||||
|
}
|
||||||
|
if key.pressed(KeyCode::KeyE)
|
||||||
|
{
|
||||||
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(config.speed) * time.delta_secs());
|
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(config.speed) * time.delta_secs());
|
||||||
orbit.forward = rot * orbit.forward;
|
orbit.forward = rot * orbit.forward;
|
||||||
} else if key.pressed(KeyCode::KeyQ) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyQ)
|
||||||
|
{
|
||||||
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(-config.speed) * time.delta_secs());
|
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(-config.speed) * time.delta_secs());
|
||||||
orbit.forward = rot * orbit.forward;
|
orbit.forward = rot * orbit.forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cam_move = Vec3::ZERO;
|
let mut cam_move = Vec3::ZERO;
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyA) {
|
if key.pressed(KeyCode::KeyA)
|
||||||
|
{
|
||||||
cam_move.x = 1.;
|
cam_move.x = 1.;
|
||||||
} else if key.pressed(KeyCode::KeyD) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyD)
|
||||||
|
{
|
||||||
cam_move.x = -1.;
|
cam_move.x = -1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyW) {
|
if key.pressed(KeyCode::KeyW)
|
||||||
|
{
|
||||||
cam_move.z = 1.;
|
cam_move.z = 1.;
|
||||||
} else if key.pressed(KeyCode::KeyS) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyS)
|
||||||
|
{
|
||||||
cam_move.z = -1.;
|
cam_move.z = -1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
let move_speed = if key.pressed(KeyCode::ShiftLeft) {
|
let move_speed = if key.pressed(KeyCode::ShiftLeft)
|
||||||
|
{
|
||||||
config.speed * 2.0
|
config.speed * 2.0
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
config.speed
|
config.speed
|
||||||
};
|
};
|
||||||
|
|
||||||
if cam_move != Vec3::ZERO {
|
if cam_move != Vec3::ZERO
|
||||||
|
{
|
||||||
cam_move = cam_move.normalize();
|
cam_move = cam_move.normalize();
|
||||||
let move_fwd = Vec3::new(orbit.forward.x, 0., orbit.forward.z).normalize();
|
let move_fwd = Vec3::new(orbit.forward.x, 0., orbit.forward.z).normalize();
|
||||||
let move_rot = Quat::from_rotation_arc(Vec3::NEG_Z, move_fwd);
|
let move_rot = Quat::from_rotation_arc(Vec3::NEG_Z, move_fwd);
|
||||||
@@ -144,8 +159,10 @@ fn orbit_camera_upate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut scroll = 0.0;
|
let mut scroll = 0.0;
|
||||||
for e in wheel.read() {
|
for e in wheel.read()
|
||||||
match e.unit {
|
{
|
||||||
|
match e.unit
|
||||||
|
{
|
||||||
MouseScrollUnit::Line => scroll += e.y * 5.,
|
MouseScrollUnit::Line => scroll += e.y * 5.,
|
||||||
MouseScrollUnit::Pixel => scroll += e.y,
|
MouseScrollUnit::Pixel => scroll += e.y,
|
||||||
}
|
}
|
||||||
@@ -167,23 +184,31 @@ fn orbit_camera_upate(
|
|||||||
transform.look_at(target, Vec3::Y);
|
transform.look_at(target, Vec3::Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample_ground(pos: Vec3, heightmap: &Map) -> f32 {
|
fn sample_ground(pos: Vec3, heightmap: &Map) -> f32
|
||||||
|
{
|
||||||
let tile_under = HexCoord::from_world_pos(pos);
|
let tile_under = HexCoord::from_world_pos(pos);
|
||||||
let neighbors = heightmap.get_neighbors(&tile_under);
|
let neighbors = heightmap.get_neighbors(&tile_under);
|
||||||
let mut ground_height = if heightmap.is_in_bounds(&tile_under) {
|
let mut ground_height = if heightmap.is_in_bounds(&tile_under)
|
||||||
|
{
|
||||||
heightmap.sample_height(&tile_under)
|
heightmap.sample_height(&tile_under)
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
heightmap.sealevel
|
heightmap.sealevel
|
||||||
};
|
};
|
||||||
|
|
||||||
for n in neighbors {
|
for n in neighbors
|
||||||
if let Some(h) = n {
|
{
|
||||||
if h > ground_height {
|
if let Some(h) = n
|
||||||
|
{
|
||||||
|
if h > ground_height
|
||||||
|
{
|
||||||
ground_height = h;
|
ground_height = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ground_height < heightmap.sealevel {
|
if ground_height < heightmap.sealevel
|
||||||
|
{
|
||||||
ground_height = heightmap.sealevel;
|
ground_height = heightmap.sealevel;
|
||||||
}
|
}
|
||||||
return ground_height;
|
return ground_height;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use bevy::{math::Direction3d, prelude::*};
|
use bevy::prelude::*;
|
||||||
use rayon::str;
|
use rayon::str;
|
||||||
use world_generation::{hex_utils::SHORT_DIAGONAL, prelude::Chunk};
|
use world_generation::prelude::Chunk;
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct PhosCamera {
|
pub struct PhosCamera
|
||||||
|
{
|
||||||
pub min_height: f32,
|
pub min_height: f32,
|
||||||
pub max_height: f32,
|
pub max_height: f32,
|
||||||
pub speed: f32,
|
pub speed: f32,
|
||||||
@@ -14,8 +15,10 @@ pub struct PhosCamera {
|
|||||||
pub max_angle: f32,
|
pub max_angle: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PhosCamera {
|
impl Default for PhosCamera
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
min_height: 10.,
|
min_height: 10.,
|
||||||
max_height: 420.,
|
max_height: 420.,
|
||||||
@@ -28,14 +31,17 @@ impl Default for PhosCamera {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
pub struct PhosOrbitCamera {
|
pub struct PhosOrbitCamera
|
||||||
|
{
|
||||||
pub target: Vec3,
|
pub target: Vec3,
|
||||||
pub distance: f32,
|
pub distance: f32,
|
||||||
pub forward: Vec3,
|
pub forward: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PhosOrbitCamera {
|
impl Default for PhosOrbitCamera
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
target: Default::default(),
|
target: Default::default(),
|
||||||
distance: 40.0,
|
distance: 40.0,
|
||||||
@@ -45,13 +51,16 @@ impl Default for PhosOrbitCamera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
pub struct CameraBounds {
|
pub struct CameraBounds
|
||||||
|
{
|
||||||
pub min: Vec2,
|
pub min: Vec2,
|
||||||
pub max: Vec2,
|
pub max: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CameraBounds {
|
impl CameraBounds
|
||||||
pub fn from_size(world_size: Vec2) -> Self {
|
{
|
||||||
|
pub fn from_size(world_size: Vec2) -> Self
|
||||||
|
{
|
||||||
let padding = Chunk::WORLD_SIZE;
|
let padding = Chunk::WORLD_SIZE;
|
||||||
return Self {
|
return Self {
|
||||||
min: Vec2::ZERO - padding,
|
min: Vec2::ZERO - padding,
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use std::env;
|
|
||||||
|
|
||||||
use bevy::image::{ImageAddressMode, ImageFilterMode, ImageSamplerDescriptor};
|
use bevy::image::{ImageAddressMode, ImageFilterMode, ImageSamplerDescriptor};
|
||||||
use bevy::pbr::wireframe::WireframePlugin;
|
use bevy::pbr::wireframe::WireframePlugin;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::PresentMode;
|
use bevy::window::PresentMode;
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
use bevy::window::WindowResolution;
|
||||||
|
use bevy_inspector_egui::bevy_egui::EguiPlugin;
|
||||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||||
use phos::PhosGamePlugin;
|
use phos::PhosGamePlugin;
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ mod shader_extensions;
|
|||||||
mod ui;
|
mod ui;
|
||||||
mod utlis;
|
mod utlis;
|
||||||
|
|
||||||
fn main() {
|
fn main()
|
||||||
|
{
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins
|
DefaultPlugins
|
||||||
@@ -24,7 +26,7 @@ fn main() {
|
|||||||
title: "Phos".into(),
|
title: "Phos".into(),
|
||||||
name: Some("phos".into()),
|
name: Some("phos".into()),
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
resolution: (1920., 1080.).into(),
|
resolution: WindowResolution::new(1920, 1080),
|
||||||
present_mode: PresentMode::AutoNoVsync,
|
present_mode: PresentMode::AutoNoVsync,
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
||||||
@@ -45,8 +47,9 @@ fn main() {
|
|||||||
watch_for_changes_override: Some(true),
|
watch_for_changes_override: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
EguiPlugin::default(),
|
||||||
WorldInspectorPlugin::new(),
|
WorldInspectorPlugin::new(),
|
||||||
WireframePlugin,
|
WireframePlugin::default(),
|
||||||
PhosGamePlugin,
|
PhosGamePlugin,
|
||||||
))
|
))
|
||||||
.run();
|
.run();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use bevy::ecs::world::CommandQueue;
|
use bevy::ecs::world::CommandQueue;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::tasks::*;
|
use bevy::tasks::*;
|
||||||
use bevy::utils::futures;
|
|
||||||
use bevy_rapier3d::geometry::Collider;
|
use bevy_rapier3d::geometry::Collider;
|
||||||
use bevy_rapier3d::geometry::TriMeshFlags;
|
use bevy_rapier3d::geometry::TriMeshFlags;
|
||||||
use shared::events::ChunkModifiedEvent;
|
use shared::events::ChunkModifiedEvent;
|
||||||
@@ -10,6 +9,7 @@ use world_generation::prelude::Map;
|
|||||||
use world_generation::states::GeneratorState;
|
use world_generation::states::GeneratorState;
|
||||||
|
|
||||||
use crate::prelude::RebuildChunk;
|
use crate::prelude::RebuildChunk;
|
||||||
|
use crate::prelude::WaterMesh;
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::{PhosChunk, PhosChunkRegistry},
|
prelude::{PhosChunk, PhosChunkRegistry},
|
||||||
utlis::chunk_utils::prepare_chunk_mesh,
|
utlis::chunk_utils::prepare_chunk_mesh,
|
||||||
@@ -17,11 +17,13 @@ use crate::{
|
|||||||
|
|
||||||
pub struct ChunkRebuildPlugin;
|
pub struct ChunkRebuildPlugin;
|
||||||
|
|
||||||
impl Plugin for ChunkRebuildPlugin {
|
impl Plugin for ChunkRebuildPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.init_resource::<PhosChunkRegistry>();
|
app.init_resource::<PhosChunkRegistry>();
|
||||||
app.add_event::<ChunkModifiedEvent>();
|
app.add_message::<ChunkModifiedEvent>();
|
||||||
app.add_event::<TileModifiedEvent>();
|
app.add_message::<TileModifiedEvent>();
|
||||||
app.add_systems(PreUpdate, chunk_rebuilder.run_if(in_state(GeneratorState::Idle)));
|
app.add_systems(PreUpdate, chunk_rebuilder.run_if(in_state(GeneratorState::Idle)));
|
||||||
app.add_systems(PostUpdate, collider_task_resolver);
|
app.add_systems(PostUpdate, collider_task_resolver);
|
||||||
}
|
}
|
||||||
@@ -31,11 +33,13 @@ fn chunk_rebuilder(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
chunk_query: Query<(Entity, &PhosChunk), (With<RebuildChunk>, Without<ChunkRebuildTask>)>,
|
chunk_query: Query<(Entity, &PhosChunk), (With<RebuildChunk>, Without<ChunkRebuildTask>)>,
|
||||||
heightmap: Res<Map>,
|
heightmap: Res<Map>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let pool = AsyncComputeTaskPool::get();
|
let pool = AsyncComputeTaskPool::get();
|
||||||
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
||||||
|
|
||||||
for (chunk_entity, idx) in &chunk_query {
|
for (chunk_entity, idx) in &chunk_query
|
||||||
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let _spawn_span = info_span!("Rebuild Chunk").entered();
|
let _spawn_span = info_span!("Rebuild Chunk").entered();
|
||||||
info!("Rebuilding Chunk");
|
info!("Rebuilding Chunk");
|
||||||
@@ -55,14 +59,15 @@ fn chunk_rebuilder(
|
|||||||
collider_data.0,
|
collider_data.0,
|
||||||
collider_data.1,
|
collider_data.1,
|
||||||
TriMeshFlags::DELETE_DUPLICATE_TRIANGLES,
|
TriMeshFlags::DELETE_DUPLICATE_TRIANGLES,
|
||||||
);
|
)
|
||||||
|
.expect("Failed to build chunk mesh");
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
drop(trimesh_span);
|
drop(trimesh_span);
|
||||||
queue.push(move |world: &mut World| {
|
queue.push(move |world: &mut World| {
|
||||||
world.entity_mut(chunk_entity).insert(c).remove::<ChunkRebuildTask>();
|
world.entity_mut(chunk_entity).insert(c).remove::<ChunkRebuildTask>();
|
||||||
});
|
});
|
||||||
|
|
||||||
return (queue, mesh);
|
return (queue, mesh, water_mesh);
|
||||||
});
|
});
|
||||||
|
|
||||||
commands
|
commands
|
||||||
@@ -73,19 +78,28 @@ fn chunk_rebuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collider_task_resolver(
|
fn collider_task_resolver(
|
||||||
mut chunks: Query<(&mut ChunkRebuildTask, &Mesh3d), With<PhosChunk>>,
|
mut chunks: Query<(&mut ChunkRebuildTask, &Mesh3d, &WaterMesh), With<PhosChunk>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
) {
|
)
|
||||||
for (mut task, mesh_handle) in &mut chunks {
|
{
|
||||||
if let Some((mut c, mesh)) = futures::check_ready(&mut task.task) {
|
for (mut task, mesh_handle, water_mesh_handle) in &mut chunks
|
||||||
|
{
|
||||||
|
if let Some((mut c, chunk_mesh, water_mesh)) = futures::check_ready(&mut task.task)
|
||||||
|
{
|
||||||
commands.append(&mut c);
|
commands.append(&mut c);
|
||||||
meshes.insert(mesh_handle.id(), mesh);
|
meshes
|
||||||
|
.insert(mesh_handle.id(), chunk_mesh)
|
||||||
|
.expect("Failed to update chunk mesh");
|
||||||
|
meshes
|
||||||
|
.insert(water_mesh_handle.0, water_mesh)
|
||||||
|
.expect("Failed to update chink water mesh");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct ChunkRebuildTask {
|
struct ChunkRebuildTask
|
||||||
pub task: Task<(CommandQueue, Mesh)>,
|
{
|
||||||
|
pub task: Task<(CommandQueue, Mesh, Mesh)>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use bevy::log::*;
|
use bevy::log::*;
|
||||||
use bevy::{
|
use bevy::{light::NotShadowCaster, pbr::ExtendedMaterial, prelude::*};
|
||||||
pbr::{ExtendedMaterial, NotShadowCaster},
|
|
||||||
prelude::*,
|
|
||||||
render::render_resource::{ColorTargetState, FragmentState, RenderPipelineDescriptor},
|
|
||||||
};
|
|
||||||
use bevy_asset_loader::prelude::*;
|
use bevy_asset_loader::prelude::*;
|
||||||
|
|
||||||
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
|
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
|
||||||
@@ -22,7 +18,7 @@ use world_generation::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::{PhosAssets, PhosChunk, PhosChunkRegistry},
|
prelude::{PhosAssets, PhosChunk, PhosChunkRegistry, WaterMesh},
|
||||||
shader_extensions::{
|
shader_extensions::{
|
||||||
chunk_material::ChunkMaterial,
|
chunk_material::ChunkMaterial,
|
||||||
water_material::{WaterMaterial, WaterSettings},
|
water_material::{WaterMaterial, WaterSettings},
|
||||||
@@ -34,8 +30,10 @@ use super::{chunk_rebuild::ChunkRebuildPlugin, render_distance_system::RenderDis
|
|||||||
|
|
||||||
pub struct MapInitPlugin;
|
pub struct MapInitPlugin;
|
||||||
|
|
||||||
impl Plugin for MapInitPlugin {
|
impl Plugin for MapInitPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.insert_state(GeneratorState::Startup);
|
app.insert_state(GeneratorState::Startup);
|
||||||
app.insert_state(AssetLoadState::Loading);
|
app.insert_state(AssetLoadState::Loading);
|
||||||
|
|
||||||
@@ -51,10 +49,7 @@ impl Plugin for MapInitPlugin {
|
|||||||
ChunkRebuildPlugin,
|
ChunkRebuildPlugin,
|
||||||
// TerraFormingTestPlugin,
|
// TerraFormingTestPlugin,
|
||||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, ChunkMaterial>>::default(),
|
MaterialPlugin::<ExtendedMaterial<StandardMaterial, ChunkMaterial>>::default(),
|
||||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, WaterMaterial>> {
|
MaterialPlugin::<ExtendedMaterial<StandardMaterial, WaterMaterial>>::default(),
|
||||||
prepass_enabled: false,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
|
|
||||||
app.configure_loading_state(
|
app.configure_loading_state(
|
||||||
@@ -78,7 +73,7 @@ impl Plugin for MapInitPlugin {
|
|||||||
app.add_systems(Update, despawn_map.run_if(in_state(GeneratorState::Regenerate)));
|
app.add_systems(Update, despawn_map.run_if(in_state(GeneratorState::Regenerate)));
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
spawn_map.run_if(in_state(AssetLoadState::LoadComplete).and_then(in_state(GeneratorState::SpawnMap))),
|
spawn_map.run_if(in_state(AssetLoadState::LoadComplete).and(in_state(GeneratorState::SpawnMap))),
|
||||||
);
|
);
|
||||||
|
|
||||||
app.insert_resource(TileManager::default());
|
app.insert_resource(TileManager::default());
|
||||||
@@ -88,7 +83,8 @@ impl Plugin for MapInitPlugin {
|
|||||||
fn setup_materials(
|
fn setup_materials(
|
||||||
mut phos_assets: ResMut<PhosAssets>,
|
mut phos_assets: ResMut<PhosAssets>,
|
||||||
mut water_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, WaterMaterial>>>,
|
mut water_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, WaterMaterial>>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let water_material = water_materials.add(ExtendedMaterial {
|
let water_material = water_materials.add(ExtendedMaterial {
|
||||||
base: StandardMaterial {
|
base: StandardMaterial {
|
||||||
base_color: Color::srgb(0., 0.878, 1.),
|
base_color: Color::srgb(0., 0.878, 1.),
|
||||||
@@ -114,7 +110,8 @@ fn finalize_biome_painter(
|
|||||||
mut next_generator_state: ResMut<NextState<GeneratorState>>,
|
mut next_generator_state: ResMut<NextState<GeneratorState>>,
|
||||||
biome_painter: Res<BiomePainterAsset>,
|
biome_painter: Res<BiomePainterAsset>,
|
||||||
biomes: Res<Assets<BiomeAsset>>,
|
biomes: Res<Assets<BiomeAsset>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let painter = biome_painter.build(&biomes);
|
let painter = biome_painter.build(&biomes);
|
||||||
commands.insert_resource(painter);
|
commands.insert_resource(painter);
|
||||||
next_generator_state.set(GeneratorState::GenerateHeightmap);
|
next_generator_state.set(GeneratorState::GenerateHeightmap);
|
||||||
@@ -125,11 +122,14 @@ fn finalize_texture(
|
|||||||
mut images: ResMut<Assets<Image>>,
|
mut images: ResMut<Assets<Image>>,
|
||||||
mut chunk_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, ChunkMaterial>>>,
|
mut chunk_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, ChunkMaterial>>>,
|
||||||
mut next_load_state: ResMut<NextState<AssetLoadState>>,
|
mut next_load_state: ResMut<NextState<AssetLoadState>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let image = images.get_mut(atlas.handle.id()).unwrap();
|
let image = images.get_mut(atlas.handle.id()).unwrap();
|
||||||
|
|
||||||
let array_layers = image.height() / image.width();
|
let array_layers = image.height() / image.width();
|
||||||
image.reinterpret_stacked_2d_as_array(array_layers);
|
image
|
||||||
|
.reinterpret_stacked_2d_as_array(array_layers)
|
||||||
|
.expect("Failed to reinterpret as array");
|
||||||
|
|
||||||
let chunk_material = chunk_materials.add(ExtendedMaterial {
|
let chunk_material = chunk_materials.add(ExtendedMaterial {
|
||||||
base: StandardMaterial::default(),
|
base: StandardMaterial::default(),
|
||||||
@@ -146,7 +146,8 @@ fn create_heightmap(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut next_state: ResMut<NextState<GeneratorState>>,
|
mut next_state: ResMut<NextState<GeneratorState>>,
|
||||||
biome_painter: Res<BiomePainter>,
|
biome_painter: Res<BiomePainter>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let config = GenerationConfig {
|
let config = GenerationConfig {
|
||||||
biome_blend: 32,
|
biome_blend: 32,
|
||||||
biome_dither: 10.,
|
biome_dither: 10.,
|
||||||
@@ -217,7 +218,8 @@ fn spawn_map(
|
|||||||
mut game_state: ResMut<NextState<MenuState>>,
|
mut game_state: ResMut<NextState<MenuState>>,
|
||||||
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
||||||
biome_painter: Res<BiomePainter>,
|
biome_painter: Res<BiomePainter>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
paint_map(&mut heightmap, &biome_painter, &tile_assets, &tile_mappers);
|
paint_map(&mut heightmap, &biome_painter, &tile_assets, &tile_mappers);
|
||||||
|
|
||||||
//Prepare Mesh Data
|
//Prepare Mesh Data
|
||||||
@@ -248,21 +250,24 @@ fn spawn_map(
|
|||||||
0.,
|
0.,
|
||||||
(Chunk::SIZE / 2) as f32 * 1.5,
|
(Chunk::SIZE / 2) as f32 * 1.5,
|
||||||
);
|
);
|
||||||
for (chunk_mesh, water_mesh, collider, pos, index) in chunk_meshes {
|
for (chunk_mesh, water_mesh, collider, pos, index) in chunk_meshes
|
||||||
|
{
|
||||||
// let mesh_handle = meshes.a
|
// let mesh_handle = meshes.a
|
||||||
|
let water_mesh_handle = meshes.add(water_mesh);
|
||||||
let chunk = commands
|
let chunk = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Mesh3d(meshes.add(chunk_mesh)),
|
Mesh3d(meshes.add(chunk_mesh)),
|
||||||
MeshMaterial3d(atlas.chunk_material_handle.clone()),
|
MeshMaterial3d(atlas.chunk_material_handle.clone()),
|
||||||
Transform::from_translation(pos),
|
Transform::from_translation(pos),
|
||||||
PhosChunk::new(index),
|
PhosChunk::new(index),
|
||||||
|
WaterMesh(water_mesh_handle.id()),
|
||||||
RenderDistanceVisibility::default().with_offset(visibility_offset),
|
RenderDistanceVisibility::default().with_offset(visibility_offset),
|
||||||
collider,
|
collider,
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
let water = commands
|
let water = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Mesh3d(meshes.add(water_mesh)),
|
Mesh3d(water_mesh_handle),
|
||||||
MeshMaterial3d(atlas.water_material.clone()),
|
MeshMaterial3d(atlas.water_material.clone()),
|
||||||
Transform::from_translation(pos),
|
Transform::from_translation(pos),
|
||||||
PhosChunk::new(index),
|
PhosChunk::new(index),
|
||||||
@@ -277,7 +282,8 @@ fn spawn_map(
|
|||||||
|
|
||||||
commands.insert_resource(registry);
|
commands.insert_resource(registry);
|
||||||
generator_state.set(GeneratorState::Idle);
|
generator_state.set(GeneratorState::Idle);
|
||||||
if cur_game_state.get() != &MenuState::InGame {
|
if cur_game_state.get() != &MenuState::InGame
|
||||||
|
{
|
||||||
game_state.set(MenuState::InGame);
|
game_state.set(MenuState::InGame);
|
||||||
gameplay_state.set(GameplayState::PlaceHQ);
|
gameplay_state.set(GameplayState::PlaceHQ);
|
||||||
}
|
}
|
||||||
@@ -291,8 +297,10 @@ fn despawn_map(
|
|||||||
chunks: Query<Entity, With<PhosChunk>>,
|
chunks: Query<Entity, With<PhosChunk>>,
|
||||||
mut next_state: ResMut<NextState<GeneratorState>>,
|
mut next_state: ResMut<NextState<GeneratorState>>,
|
||||||
biome_painter: Res<BiomePainter>,
|
biome_painter: Res<BiomePainter>,
|
||||||
) {
|
)
|
||||||
for chunk in chunks.iter() {
|
{
|
||||||
|
for chunk in chunks.iter()
|
||||||
|
{
|
||||||
commands.entity(chunk).despawn();
|
commands.entity(chunk).despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
use world_generation::biome_painter::BiomePainterAsset;
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use shared::tags::MainCamera;
|
use shared::tags::MainCamera;
|
||||||
|
|
||||||
use crate::camera_system::components::PhosCamera;
|
|
||||||
|
|
||||||
pub struct RenderDistancePlugin;
|
pub struct RenderDistancePlugin;
|
||||||
|
|
||||||
impl Plugin for RenderDistancePlugin {
|
impl Plugin for RenderDistancePlugin
|
||||||
fn build(&self, app: &mut bevy::prelude::App) {
|
{
|
||||||
|
fn build(&self, app: &mut bevy::prelude::App)
|
||||||
|
{
|
||||||
app.register_type::<RenderDistanceSettings>();
|
app.register_type::<RenderDistanceSettings>();
|
||||||
app.add_systems(PostUpdate, render_distance_system)
|
app.add_systems(PostUpdate, render_distance_system)
|
||||||
.insert_resource(RenderDistanceSettings::default());
|
.insert_resource(RenderDistanceSettings::default());
|
||||||
@@ -15,54 +15,68 @@ impl Plugin for RenderDistancePlugin {
|
|||||||
|
|
||||||
#[derive(Resource, Reflect)]
|
#[derive(Resource, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct RenderDistanceSettings {
|
pub struct RenderDistanceSettings
|
||||||
|
{
|
||||||
pub render_distance: f32,
|
pub render_distance: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderDistanceSettings {
|
impl RenderDistanceSettings
|
||||||
pub fn new(distance: f32) -> Self {
|
{
|
||||||
|
pub fn new(distance: f32) -> Self
|
||||||
|
{
|
||||||
return Self {
|
return Self {
|
||||||
render_distance: distance,
|
render_distance: distance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RenderDistanceSettings {
|
impl Default for RenderDistanceSettings
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self::new(500.)
|
Self::new(500.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct RenderDistanceVisibility {
|
pub struct RenderDistanceVisibility
|
||||||
|
{
|
||||||
pub offset: Vec3,
|
pub offset: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderDistanceVisibility {
|
impl RenderDistanceVisibility
|
||||||
pub fn with_offset(mut self, offset: Vec3) -> Self {
|
{
|
||||||
|
pub fn with_offset(mut self, offset: Vec3) -> Self
|
||||||
|
{
|
||||||
self.offset = offset;
|
self.offset = offset;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RenderDistanceVisibility {
|
impl Default for RenderDistanceVisibility
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self { offset: Vec3::ZERO }
|
Self { offset: Vec3::ZERO }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_distance_system(
|
fn render_distance_system(
|
||||||
mut objects: Query<(&Transform, &mut Visibility, &RenderDistanceVisibility)>,
|
mut objects: Query<(&Transform, &mut Visibility, &RenderDistanceVisibility)>,
|
||||||
camera_query: Query<&Transform, With<MainCamera>>,
|
camera: Single<&Transform, With<MainCamera>>,
|
||||||
settings: Res<RenderDistanceSettings>,
|
settings: Res<RenderDistanceSettings>,
|
||||||
) {
|
)
|
||||||
let camera = camera_query.single();
|
{
|
||||||
let cam_pos = Vec3::new(camera.translation.x, 0.0, camera.translation.z);
|
let cam_pos = Vec3::new(camera.translation.x, 0.0, camera.translation.z);
|
||||||
for (t, mut vis, r) in objects.iter_mut() {
|
for (t, mut vis, r) in objects.iter_mut()
|
||||||
|
{
|
||||||
let dist = (cam_pos - (t.translation + r.offset)).length();
|
let dist = (cam_pos - (t.translation + r.offset)).length();
|
||||||
if settings.render_distance < dist {
|
if settings.render_distance < dist
|
||||||
|
{
|
||||||
*vis = Visibility::Hidden;
|
*vis = Visibility::Hidden;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
*vis = Visibility::Visible;
|
*vis = Visibility::Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
use bevy::{prelude::*, utils::hashbrown::HashSet, window::PrimaryWindow};
|
use bevy::{platform::collections::HashSet, prelude::*};
|
||||||
use bevy_rapier3d::{pipeline::QueryFilter, plugin::RapierContext};
|
|
||||||
use shared::{
|
use shared::{
|
||||||
events::{ChunkModifiedEvent, TileModifiedEvent},
|
events::{ChunkModifiedEvent, TileModifiedEvent},
|
||||||
resources::TileUnderCursor,
|
resources::TileUnderCursor,
|
||||||
states::GameplayState,
|
states::GameplayState,
|
||||||
};
|
};
|
||||||
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
use world_generation::{prelude::Map, states::GeneratorState};
|
||||||
|
|
||||||
use crate::{
|
use crate::prelude::{PhosChunkRegistry, RebuildChunk};
|
||||||
camera_system::components::PhosCamera,
|
|
||||||
prelude::{PhosChunkRegistry, RebuildChunk},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct TerraFormingTestPlugin;
|
pub struct TerraFormingTestPlugin;
|
||||||
|
|
||||||
impl Plugin for TerraFormingTestPlugin {
|
impl Plugin for TerraFormingTestPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
deform
|
deform
|
||||||
@@ -25,39 +24,48 @@ impl Plugin for TerraFormingTestPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn deform(
|
fn deform(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mouse: Res<ButtonInput<MouseButton>>,
|
mouse: Res<ButtonInput<MouseButton>>,
|
||||||
mut heightmap: ResMut<Map>,
|
mut heightmap: ResMut<Map>,
|
||||||
chunks: Res<PhosChunkRegistry>,
|
chunks: Res<PhosChunkRegistry>,
|
||||||
tile_under_cursor: Res<TileUnderCursor>,
|
tile_under_cursor: Res<TileUnderCursor>,
|
||||||
mut chunk_modified: EventWriter<ChunkModifiedEvent>,
|
mut chunk_modified: MessageWriter<ChunkModifiedEvent>,
|
||||||
mut tile_modified: EventWriter<TileModifiedEvent>,
|
mut tile_modified: MessageWriter<TileModifiedEvent>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let mut multi = 0.;
|
let mut multi = 0.;
|
||||||
if mouse.just_pressed(MouseButton::Left) {
|
if mouse.just_pressed(MouseButton::Left)
|
||||||
|
{
|
||||||
multi = 1.;
|
multi = 1.;
|
||||||
} else if mouse.just_pressed(MouseButton::Right) {
|
}
|
||||||
|
else if mouse.just_pressed(MouseButton::Right)
|
||||||
|
{
|
||||||
multi = -1.;
|
multi = -1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
if multi == 0. {
|
if multi == 0.
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(contact) = tile_under_cursor.0 {
|
if let Some(contact) = tile_under_cursor.0
|
||||||
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let span = info_span!("Deform Mesh").entered();
|
let span = info_span!("Deform Mesh").entered();
|
||||||
let modified_tiles = heightmap.create_crater(&contact.tile, 5, 5. * multi);
|
let modified_tiles = heightmap.create_crater(&contact.tile, 5, 5. * multi);
|
||||||
let mut chunk_set: HashSet<usize> = HashSet::new();
|
let mut chunk_set: HashSet<usize> = HashSet::new();
|
||||||
for (tile, height) in modified_tiles {
|
for (tile, height) in modified_tiles
|
||||||
|
{
|
||||||
let chunk = tile.to_chunk_index(heightmap.width);
|
let chunk = tile.to_chunk_index(heightmap.width);
|
||||||
if !chunk_set.contains(&chunk) {
|
if !chunk_set.contains(&chunk)
|
||||||
chunk_modified.send(ChunkModifiedEvent { index: chunk });
|
{
|
||||||
|
chunk_modified.write(ChunkModifiedEvent { index: chunk });
|
||||||
chunk_set.insert(chunk);
|
chunk_set.insert(chunk);
|
||||||
commands.entity(chunks.chunks[chunk]).insert(RebuildChunk);
|
commands.entity(chunks.chunks[chunk]).insert(RebuildChunk);
|
||||||
}
|
}
|
||||||
tile_modified.send(TileModifiedEvent::HeightChanged(tile, height));
|
tile_modified.write(TileModifiedEvent::HeightChanged(tile, height));
|
||||||
}
|
}
|
||||||
// commands.entity(e).insert(RebuildChunk);
|
// commands.entity(e).insert(RebuildChunk);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,28 @@ use crate::ui::build_ui::BuildUIPlugin;
|
|||||||
use crate::utlis::editor_plugin::EditorPlugin;
|
use crate::utlis::editor_plugin::EditorPlugin;
|
||||||
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
|
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
|
||||||
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
|
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
|
||||||
use bevy::{
|
use bevy::diagnostic::{EntityCountDiagnosticsPlugin, FrameTimeDiagnosticsPlugin};
|
||||||
pbr::{wireframe::WireframeConfig, CascadeShadowConfig},
|
use bevy::light::CascadeShadowConfig;
|
||||||
prelude::*,
|
use bevy::{pbr::wireframe::WireframeConfig, prelude::*};
|
||||||
};
|
|
||||||
use bevy_asset_loader::prelude::*;
|
use bevy_asset_loader::prelude::*;
|
||||||
use bevy_rapier3d::dynamics::{Ccd, RigidBody, Velocity};
|
use bevy_rapier3d::dynamics::{Ccd, RigidBody, Velocity};
|
||||||
use bevy_rapier3d::geometry::Collider;
|
use bevy_rapier3d::geometry::Collider;
|
||||||
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
||||||
use buildings::BuildingPugin;
|
// use buildings::BuildingPugin;
|
||||||
// use iyes_perf_ui::prelude::*;
|
// use iyes_perf_ui::prelude::*;
|
||||||
use shared::animation_plugin::SimpleAnimationPlugin;
|
// use shared::animation_plugin::SimpleAnimationPlugin;
|
||||||
use shared::sets::GameplaySet;
|
use shared::sets::GameplaySet;
|
||||||
use shared::states::{GameplayState, MenuState};
|
use shared::states::{GameplayState, MenuState};
|
||||||
use shared::{despawn::DespawnPuglin, states::AssetLoadState};
|
use shared::{despawn::DespawnPuglin, states::AssetLoadState};
|
||||||
use units::units_plugin::UnitsPlugin;
|
// use units::units_plugin::UnitsPlugin;
|
||||||
use world_generation::states::GeneratorState;
|
use world_generation::states::GeneratorState;
|
||||||
|
|
||||||
pub struct PhosGamePlugin;
|
pub struct PhosGamePlugin;
|
||||||
|
|
||||||
impl Plugin for PhosGamePlugin {
|
impl Plugin for PhosGamePlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.insert_state(AssetLoadState::Loading);
|
app.insert_state(AssetLoadState::Loading);
|
||||||
app.insert_state(MenuState::Loading);
|
app.insert_state(MenuState::Loading);
|
||||||
app.insert_state(GameplayState::Waiting);
|
app.insert_state(GameplayState::Waiting);
|
||||||
@@ -38,10 +39,10 @@ impl Plugin for PhosGamePlugin {
|
|||||||
PhosCameraPlugin,
|
PhosCameraPlugin,
|
||||||
MapInitPlugin,
|
MapInitPlugin,
|
||||||
RenderDistancePlugin,
|
RenderDistancePlugin,
|
||||||
BuildingPugin,
|
// BuildingPugin,
|
||||||
BuildUIPlugin,
|
BuildUIPlugin,
|
||||||
SimpleAnimationPlugin,
|
// SimpleAnimationPlugin,
|
||||||
UnitsPlugin,
|
// UnitsPlugin,
|
||||||
DespawnPuglin,
|
DespawnPuglin,
|
||||||
TileSelectionPlugin,
|
TileSelectionPlugin,
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -59,8 +60,8 @@ impl Plugin for PhosGamePlugin {
|
|||||||
app.add_systems(Update, spawn_sphere);
|
app.add_systems(Update, spawn_sphere);
|
||||||
|
|
||||||
//Perf UI
|
//Perf UI
|
||||||
app.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
|
app.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||||
.add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin)
|
.add_plugins(EntityCountDiagnosticsPlugin::default())
|
||||||
.add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin);
|
.add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin);
|
||||||
// .add_plugins(PerfUiPlugin);
|
// .add_plugins(PerfUiPlugin);
|
||||||
|
|
||||||
@@ -75,7 +76,8 @@ impl Plugin for PhosGamePlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_gameplay_set(app: &mut App) {
|
fn configure_gameplay_set(app: &mut App)
|
||||||
|
{
|
||||||
app.configure_sets(
|
app.configure_sets(
|
||||||
Update,
|
Update,
|
||||||
GameplaySet.run_if(in_state(GeneratorState::Idle).and(in_state(MenuState::InGame))),
|
GameplaySet.run_if(in_state(GeneratorState::Idle).and(in_state(MenuState::InGame))),
|
||||||
@@ -103,7 +105,8 @@ fn configure_gameplay_set(app: &mut App) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_game(mut commands: Commands, mut materials: ResMut<Assets<StandardMaterial>>) {
|
fn init_game(mut commands: Commands, mut materials: ResMut<Assets<StandardMaterial>>)
|
||||||
|
{
|
||||||
// commands.spawn((
|
// commands.spawn((
|
||||||
// PerfUiRoot::default(),
|
// PerfUiRoot::default(),
|
||||||
// PerfUiEntryFPS::default(),
|
// PerfUiEntryFPS::default(),
|
||||||
@@ -137,21 +140,22 @@ struct SphereMat(Handle<StandardMaterial>);
|
|||||||
|
|
||||||
fn spawn_sphere(
|
fn spawn_sphere(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
cam: Query<&Transform, With<PhosCamera>>,
|
cam: Single<&Transform, With<PhosCamera>>,
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mat: Res<SphereMat>,
|
mat: Res<SphereMat>,
|
||||||
) {
|
)
|
||||||
if keyboard_input.just_pressed(KeyCode::KeyF) {
|
{
|
||||||
let cam_transform = cam.single();
|
if keyboard_input.just_pressed(KeyCode::KeyF)
|
||||||
|
{
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(meshes.add(Sphere::new(0.3))),
|
Mesh3d(meshes.add(Sphere::new(0.3))),
|
||||||
MeshMaterial3d(mat.0.clone()),
|
MeshMaterial3d(mat.0.clone()),
|
||||||
Transform::from_translation(cam_transform.translation),
|
Transform::from_translation(cam.translation),
|
||||||
Collider::ball(0.3),
|
Collider::ball(0.3),
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
Ccd::enabled(),
|
Ccd::enabled(),
|
||||||
Velocity::linear(cam_transform.forward() * 50.),
|
Velocity::linear(cam.forward() * 50.),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ use bevy::pbr::ExtendedMaterial;
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::prelude::{Component, Image, Resource};
|
use bevy::prelude::{Component, Image, Resource};
|
||||||
use bevy_asset_loader::asset_collection::AssetCollection;
|
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||||
use world_generation::biome_painter::BiomePainterAsset;
|
|
||||||
|
|
||||||
use crate::shader_extensions::chunk_material::ChunkMaterial;
|
use crate::shader_extensions::chunk_material::ChunkMaterial;
|
||||||
use crate::shader_extensions::water_material::WaterMaterial;
|
use crate::shader_extensions::water_material::WaterMaterial;
|
||||||
|
|
||||||
#[derive(AssetCollection, Resource, Default)]
|
#[derive(AssetCollection, Resource, Default)]
|
||||||
pub struct PhosAssets {
|
pub struct PhosAssets
|
||||||
|
{
|
||||||
#[asset(key = "chunk_atlas")]
|
#[asset(key = "chunk_atlas")]
|
||||||
pub handle: Handle<Image>,
|
pub handle: Handle<Image>,
|
||||||
pub chunk_material_handle: Handle<ExtendedMaterial<StandardMaterial, ChunkMaterial>>,
|
pub chunk_material_handle: Handle<ExtendedMaterial<StandardMaterial, ChunkMaterial>>,
|
||||||
@@ -17,24 +17,33 @@ pub struct PhosAssets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct PhosChunk {
|
pub struct PhosChunk
|
||||||
|
{
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PhosChunk {
|
impl PhosChunk
|
||||||
pub fn new(index: usize) -> Self {
|
{
|
||||||
|
pub fn new(index: usize) -> Self
|
||||||
|
{
|
||||||
return Self { index };
|
return Self { index };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct WaterMesh(pub AssetId<Mesh>);
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct PhosChunkRegistry {
|
pub struct PhosChunkRegistry
|
||||||
|
{
|
||||||
pub chunks: Vec<Entity>,
|
pub chunks: Vec<Entity>,
|
||||||
pub waters: Vec<Entity>,
|
pub waters: Vec<Entity>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PhosChunkRegistry {
|
impl PhosChunkRegistry
|
||||||
pub fn new(size: usize) -> Self {
|
{
|
||||||
|
pub fn new(size: usize) -> Self
|
||||||
|
{
|
||||||
return Self {
|
return Self {
|
||||||
chunks: Vec::with_capacity(size),
|
chunks: Vec::with_capacity(size),
|
||||||
waters: Vec::with_capacity(size),
|
waters: Vec::with_capacity(size),
|
||||||
|
|||||||
@@ -2,40 +2,49 @@ use bevy::asset::{Asset, Handle};
|
|||||||
use bevy::image::Image;
|
use bevy::image::Image;
|
||||||
use bevy::pbr::{Material, MaterialExtension};
|
use bevy::pbr::{Material, MaterialExtension};
|
||||||
use bevy::reflect::TypePath;
|
use bevy::reflect::TypePath;
|
||||||
use bevy::render::mesh::{MeshVertexAttribute, MeshVertexBufferLayoutRef};
|
use bevy::render::render_resource::AsBindGroup;
|
||||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
use bevy::shader::ShaderRef;
|
||||||
use world_generation::consts::{ATTRIBUTE_PACKED_VERTEX_DATA, ATTRIBUTE_VERTEX_HEIGHT};
|
use world_generation::consts::{ATTRIBUTE_PACKED_VERTEX_DATA, ATTRIBUTE_VERTEX_HEIGHT};
|
||||||
|
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
pub struct ChunkMaterial {
|
pub struct ChunkMaterial
|
||||||
|
{
|
||||||
#[texture(100, dimension = "2d_array")]
|
#[texture(100, dimension = "2d_array")]
|
||||||
#[sampler(101)]
|
#[sampler(101)]
|
||||||
pub array_texture: Handle<Image>,
|
pub array_texture: Handle<Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaterialExtension for ChunkMaterial {
|
impl MaterialExtension for ChunkMaterial
|
||||||
fn fragment_shader() -> ShaderRef {
|
{
|
||||||
|
fn fragment_shader() -> ShaderRef
|
||||||
|
{
|
||||||
"shaders/world/chunk.wgsl".into()
|
"shaders/world/chunk.wgsl".into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
pub struct PackedChunkMaterial {
|
pub struct PackedChunkMaterial
|
||||||
|
{
|
||||||
#[texture(100, dimension = "2d_array")]
|
#[texture(100, dimension = "2d_array")]
|
||||||
#[sampler(101)]
|
#[sampler(101)]
|
||||||
pub array_texture: Handle<Image>,
|
pub array_texture: Handle<Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material for PackedChunkMaterial {
|
impl Material for PackedChunkMaterial
|
||||||
fn fragment_shader() -> ShaderRef {
|
{
|
||||||
|
fn fragment_shader() -> ShaderRef
|
||||||
|
{
|
||||||
"shaders/world/chunk.wgsl".into()
|
"shaders/world/chunk.wgsl".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vertex_shader() -> ShaderRef {
|
fn vertex_shader() -> ShaderRef
|
||||||
|
{
|
||||||
"shaders/world/chunk_packed.wgsl".into()
|
"shaders/world/chunk_packed.wgsl".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepass_vertex_shader() -> ShaderRef {
|
fn prepass_vertex_shader() -> ShaderRef
|
||||||
|
{
|
||||||
"shaders/world/chunk_packed.wgsl".into()
|
"shaders/world/chunk_packed.wgsl".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +57,12 @@ impl Material for PackedChunkMaterial {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
fn specialize(
|
fn specialize(
|
||||||
_pipeline: &bevy::pbr::MaterialPipeline<Self>,
|
_pipeline: &bevy::pbr::MaterialPipeline,
|
||||||
descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
||||||
layout: &MeshVertexBufferLayoutRef,
|
layout: &bevy::mesh::MeshVertexBufferLayoutRef,
|
||||||
_key: bevy::pbr::MaterialPipelineKey<Self>,
|
_key: bevy::pbr::MaterialPipelineKey<Self>,
|
||||||
) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
) -> bevy::ecs::error::Result<(), bevy::render::render_resource::SpecializedMeshPipelineError>
|
||||||
|
{
|
||||||
let vertex_layout = layout.0.get_layout(&[
|
let vertex_layout = layout.0.get_layout(&[
|
||||||
// Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
// Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||||
// Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
// Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
use bevy::asset::Asset;
|
use bevy::asset::Asset;
|
||||||
use bevy::math::VectorSpace;
|
|
||||||
use bevy::pbr::MaterialExtension;
|
use bevy::pbr::MaterialExtension;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::reflect::Reflect;
|
use bevy::reflect::Reflect;
|
||||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef, ShaderType};
|
use bevy::render::render_resource::{AsBindGroup, ShaderType};
|
||||||
|
use bevy::shader::ShaderRef;
|
||||||
|
|
||||||
#[derive(Asset, Reflect, AsBindGroup, Debug, Clone, Default)]
|
#[derive(Asset, Reflect, AsBindGroup, Debug, Clone, Default)]
|
||||||
pub struct WaterMaterial {
|
pub struct WaterMaterial
|
||||||
|
{
|
||||||
#[uniform(100)]
|
#[uniform(100)]
|
||||||
pub settings: WaterSettings,
|
pub settings: WaterSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, ShaderType, Reflect)]
|
#[derive(Debug, Clone, ShaderType, Reflect)]
|
||||||
pub struct WaterSettings {
|
pub struct WaterSettings
|
||||||
|
{
|
||||||
pub offset: f32,
|
pub offset: f32,
|
||||||
pub scale: f32,
|
pub scale: f32,
|
||||||
pub f_power: f32,
|
pub f_power: f32,
|
||||||
pub deep_color: LinearRgba,
|
pub deep_color: LinearRgba,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WaterSettings {
|
impl Default for WaterSettings
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
offset: 0.0,
|
offset: 0.0,
|
||||||
scale: 1.0,
|
scale: 1.0,
|
||||||
@@ -30,18 +34,21 @@ impl Default for WaterSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaterialExtension for WaterMaterial {
|
impl MaterialExtension for WaterMaterial
|
||||||
fn fragment_shader() -> ShaderRef {
|
{
|
||||||
|
fn fragment_shader() -> ShaderRef
|
||||||
|
{
|
||||||
"shaders/world/water.wgsl".into()
|
"shaders/world/water.wgsl".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn specialize(
|
// fn specialize(
|
||||||
// _pipeline: &bevy::pbr::MaterialExtensionPipeline,
|
// pipeline: &bevy::pbr::MaterialExtensionPipeline,
|
||||||
// descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
// descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
||||||
// layout: &bevy::render::mesh::MeshVertexBufferLayout,
|
// layout: &bevy::mesh::MeshVertexBufferLayoutRef,
|
||||||
// _key: bevy::pbr::MaterialExtensionKey<Self>,
|
// key: bevy::pbr::MaterialExtensionKey<Self>,
|
||||||
// ) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
// ) -> std::result::Result<(), bevy::render::render_resource::SpecializedMeshPipelineError>
|
||||||
// let vertex_layout = layout.get_layout(&[
|
// {
|
||||||
|
// let vertex_layout = layout.0.get_layout(&[
|
||||||
// // Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
// // Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||||
// // Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
// // Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
||||||
// // Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
// // Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
use bevy::{
|
use bevy::{camera::visibility::RenderLayers, prelude::*};
|
||||||
prelude::*,
|
use shared::states::AssetLoadState;
|
||||||
render::{camera::RenderTarget, view::RenderLayers},
|
|
||||||
};
|
|
||||||
use shared::{states::AssetLoadState, tags::MainCamera};
|
|
||||||
pub struct BuildUIPlugin;
|
pub struct BuildUIPlugin;
|
||||||
|
|
||||||
impl Plugin for BuildUIPlugin {
|
impl Plugin for BuildUIPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.add_systems(Startup, setup_cameras);
|
app.add_systems(Startup, setup_cameras);
|
||||||
app.add_systems(Update, spawn_ui.run_if(in_state(AssetLoadState::LoadComplete)));
|
app.add_systems(Update, spawn_ui.run_if(in_state(AssetLoadState::LoadComplete)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_cameras(mut commands: Commands) {
|
fn setup_cameras(mut commands: Commands)
|
||||||
commands.spawn((Camera2d, IsDefaultUiCamera, UiBoxShadowSamples(6)));
|
{
|
||||||
|
commands.spawn((Camera2d, IsDefaultUiCamera, RenderLayers::layer(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_ui(mut commands: Commands) {
|
fn spawn_ui(mut commands: Commands)
|
||||||
|
{
|
||||||
commands
|
commands
|
||||||
.spawn((Node {
|
.spawn((Node {
|
||||||
width: Val::Percent(100.),
|
width: Val::Percent(100.),
|
||||||
@@ -25,7 +26,7 @@ fn spawn_ui(mut commands: Commands) {
|
|||||||
align_items: AlignItems::End,
|
align_items: AlignItems::End,
|
||||||
..default()
|
..default()
|
||||||
},))
|
},))
|
||||||
.insert(PickingBehavior::IGNORE)
|
// .insert(PickingBehavior::IGNORE)
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
Node {
|
Node {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use bevy::{
|
|||||||
asset::Assets,
|
asset::Assets,
|
||||||
ecs::system::Res,
|
ecs::system::Res,
|
||||||
math::{IVec2, UVec2, Vec3},
|
math::{IVec2, UVec2, Vec3},
|
||||||
render::mesh::Mesh,
|
mesh::Mesh,
|
||||||
};
|
};
|
||||||
use bevy_rapier3d::geometry::{Collider, TriMeshFlags};
|
use bevy_rapier3d::geometry::{Collider, TriMeshFlags};
|
||||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||||
@@ -13,7 +13,6 @@ use world_generation::{
|
|||||||
generators::{
|
generators::{
|
||||||
chunk_colliders::generate_chunk_collider,
|
chunk_colliders::generate_chunk_collider,
|
||||||
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
||||||
packed_mesh_generator::generate_packed_chunk_mesh,
|
|
||||||
},
|
},
|
||||||
hex_utils::offset_to_world,
|
hex_utils::offset_to_world,
|
||||||
prelude::{Chunk, Map, MeshChunkData},
|
prelude::{Chunk, Map, MeshChunkData},
|
||||||
@@ -26,7 +25,8 @@ pub fn paint_map(
|
|||||||
painter: &BiomePainter,
|
painter: &BiomePainter,
|
||||||
tiles: &Res<Assets<TileAsset>>,
|
tiles: &Res<Assets<TileAsset>>,
|
||||||
mappers: &Res<Assets<TileMapperAsset>>,
|
mappers: &Res<Assets<TileMapperAsset>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
map.chunks.par_iter_mut().for_each(|chunk: &mut Chunk| {
|
map.chunks.par_iter_mut().for_each(|chunk: &mut Chunk| {
|
||||||
paint_chunk(chunk, painter, tiles, mappers);
|
paint_chunk(chunk, painter, tiles, mappers);
|
||||||
});
|
});
|
||||||
@@ -37,9 +37,12 @@ pub fn paint_chunk(
|
|||||||
painter: &BiomePainter,
|
painter: &BiomePainter,
|
||||||
tiles: &Res<Assets<TileAsset>>,
|
tiles: &Res<Assets<TileAsset>>,
|
||||||
mappers: &Res<Assets<TileMapperAsset>>,
|
mappers: &Res<Assets<TileMapperAsset>>,
|
||||||
) {
|
)
|
||||||
for z in 0..Chunk::SIZE {
|
{
|
||||||
for x in 0..Chunk::SIZE {
|
for z in 0..Chunk::SIZE
|
||||||
|
{
|
||||||
|
for x in 0..Chunk::SIZE
|
||||||
|
{
|
||||||
let idx = x + z * Chunk::SIZE;
|
let idx = x + z * Chunk::SIZE;
|
||||||
let height = chunk.heights[idx];
|
let height = chunk.heights[idx];
|
||||||
let biome_id = chunk.biome_id[idx];
|
let biome_id = chunk.biome_id[idx];
|
||||||
@@ -58,7 +61,8 @@ pub fn prepare_chunk_mesh(
|
|||||||
chunk_offset: IVec2,
|
chunk_offset: IVec2,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
map_size: UVec2,
|
map_size: UVec2,
|
||||||
) -> (Mesh, Mesh, (Vec<Vec3>, Vec<[u32; 3]>), Vec3, usize) {
|
) -> (Mesh, Mesh, (Vec<Vec3>, Vec<[u32; 3]>), Vec3, usize)
|
||||||
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let _gen_mesh = info_span!("Generate Chunk").entered();
|
let _gen_mesh = info_span!("Generate Chunk").entered();
|
||||||
let chunk_mesh = generate_chunk_mesh(chunk);
|
let chunk_mesh = generate_chunk_mesh(chunk);
|
||||||
@@ -80,14 +84,16 @@ pub fn prepare_chunk_mesh_with_collider(
|
|||||||
chunk_offset: IVec2,
|
chunk_offset: IVec2,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
map_size: UVec2,
|
map_size: UVec2,
|
||||||
) -> (Mesh, Mesh, Collider, Vec3, usize) {
|
) -> (Mesh, Mesh, Collider, Vec3, usize)
|
||||||
|
{
|
||||||
let (chunk_mesh, water_mesh, (col_verts, col_indicies), pos, index) =
|
let (chunk_mesh, water_mesh, (col_verts, col_indicies), pos, index) =
|
||||||
prepare_chunk_mesh(chunk, sealevel, chunk_offset, chunk_index, map_size);
|
prepare_chunk_mesh(chunk, sealevel, chunk_offset, chunk_index, map_size);
|
||||||
let collider: Collider;
|
let collider: Collider;
|
||||||
{
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let _collider_span = info_span!("Create Collider Trimesh").entered();
|
let _collider_span = info_span!("Create Collider Trimesh").entered();
|
||||||
collider = Collider::trimesh_with_flags(col_verts, col_indicies, TriMeshFlags::DELETE_DUPLICATE_TRIANGLES);
|
collider = Collider::trimesh_with_flags(col_verts, col_indicies, TriMeshFlags::DELETE_DUPLICATE_TRIANGLES)
|
||||||
|
.expect("Failed to generate chunk collision mesh");
|
||||||
}
|
}
|
||||||
return (chunk_mesh, water_mesh, collider, pos, index);
|
return (chunk_mesh, water_mesh, collider, pos, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use bevy::{gizmos::gizmos, prelude::*};
|
use bevy::prelude::*;
|
||||||
use shared::states::GameplayState;
|
use shared::states::GameplayState;
|
||||||
use shared::{resources::TileUnderCursor, sets::GameplaySet};
|
use shared::{resources::TileUnderCursor, sets::GameplaySet};
|
||||||
use world_generation::{
|
use world_generation::{
|
||||||
@@ -11,8 +11,10 @@ use crate::camera_system::components::{PhosCamera, PhosOrbitCamera};
|
|||||||
|
|
||||||
pub struct DebugPlugin;
|
pub struct DebugPlugin;
|
||||||
|
|
||||||
impl Plugin for DebugPlugin {
|
impl Plugin for DebugPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.insert_state(DebugState::Base);
|
app.insert_state(DebugState::Base);
|
||||||
|
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
@@ -29,7 +31,7 @@ impl Plugin for DebugPlugin {
|
|||||||
.run_if(in_state(DebugState::Verbose)),
|
.run_if(in_state(DebugState::Verbose)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// app.add_systems(Update, camera_debug.in_set(GameplaySet));
|
app.add_systems(Update, camera_debug.in_set(GameplaySet));
|
||||||
app.add_systems(Update, regenerate_map.run_if(in_state(GeneratorState::Idle)));
|
app.add_systems(Update, regenerate_map.run_if(in_state(GeneratorState::Idle)));
|
||||||
|
|
||||||
app.insert_resource(Shape(Polyline3d::new([
|
app.insert_resource(Shape(Polyline3d::new([
|
||||||
@@ -45,10 +47,11 @@ impl Plugin for DebugPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct Shape(pub Polyline3d<7>);
|
struct Shape(pub Polyline3d);
|
||||||
|
|
||||||
#[derive(States, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(States, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum DebugState {
|
pub enum DebugState
|
||||||
|
{
|
||||||
Base,
|
Base,
|
||||||
None,
|
None,
|
||||||
Verbose,
|
Verbose,
|
||||||
@@ -58,15 +61,19 @@ fn regenerate_map(
|
|||||||
mut generator_state: ResMut<NextState<GeneratorState>>,
|
mut generator_state: ResMut<NextState<GeneratorState>>,
|
||||||
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
||||||
input: Res<ButtonInput<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
)
|
||||||
if input.just_pressed(KeyCode::KeyR) {
|
{
|
||||||
|
if input.just_pressed(KeyCode::KeyR)
|
||||||
|
{
|
||||||
generator_state.set(GeneratorState::Regenerate);
|
generator_state.set(GeneratorState::Regenerate);
|
||||||
gameplay_state.set(GameplayState::PlaceHQ);
|
gameplay_state.set(GameplayState::PlaceHQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_tile_heights(map: Res<Map>, mut gizmos: Gizmos, shape: Res<Shape>, tile_under_cursor: Res<TileUnderCursor>) {
|
fn show_tile_heights(map: Res<Map>, mut gizmos: Gizmos, shape: Res<Shape>, tile_under_cursor: Res<TileUnderCursor>)
|
||||||
if let Some(contact) = tile_under_cursor.0 {
|
{
|
||||||
|
if let Some(contact) = tile_under_cursor.0
|
||||||
|
{
|
||||||
let height = map.sample_height(&contact.tile);
|
let height = map.sample_height(&contact.tile);
|
||||||
gizmos.primitive_3d(&shape.0, contact.tile.to_world(height + 0.01), Color::WHITE);
|
gizmos.primitive_3d(&shape.0, contact.tile.to_world(height + 0.01), Color::WHITE);
|
||||||
|
|
||||||
@@ -78,8 +85,11 @@ fn show_tile_heights(map: Res<Map>, mut gizmos: Gizmos, shape: Res<Shape>, tile_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_water_corners(pos: Vec3, gizmos: &mut Gizmos) {
|
#[allow(dead_code)]
|
||||||
for i in 0..WATER_HEX_CORNERS.len() {
|
fn show_water_corners(pos: Vec3, gizmos: &mut Gizmos)
|
||||||
|
{
|
||||||
|
for i in 0..WATER_HEX_CORNERS.len()
|
||||||
|
{
|
||||||
let p = pos + WATER_HEX_CORNERS[i];
|
let p = pos + WATER_HEX_CORNERS[i];
|
||||||
let p2 = pos + WATER_HEX_CORNERS[(i + 1) % WATER_HEX_CORNERS.len()];
|
let p2 = pos + WATER_HEX_CORNERS[(i + 1) % WATER_HEX_CORNERS.len()];
|
||||||
|
|
||||||
@@ -87,8 +97,9 @@ fn show_water_corners(pos: Vec3, gizmos: &mut Gizmos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn camera_debug(mut cam_query: Query<(&PhosCamera, &PhosOrbitCamera)>, mut gizmos: Gizmos) {
|
fn camera_debug(cam_query: Single<(&PhosCamera, &PhosOrbitCamera)>, mut gizmos: Gizmos)
|
||||||
let (config, orbit) = cam_query.single();
|
{
|
||||||
|
let (_config, orbit) = cam_query.into_inner();
|
||||||
|
|
||||||
gizmos.sphere(orbit.target, 0.3, LinearRgba::RED);
|
gizmos.sphere(orbit.target, 0.3, LinearRgba::RED);
|
||||||
let cam_proxy = orbit.target - (orbit.forward * 10.0);
|
let cam_proxy = orbit.target - (orbit.forward * 10.0);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use bevy::{prelude::*, render::render_asset::RenderAssetUsages};
|
use bevy::asset::RenderAssetUsages;
|
||||||
|
use bevy::prelude::*;
|
||||||
use bevy_inspector_egui::bevy_egui::EguiContexts;
|
use bevy_inspector_egui::bevy_egui::EguiContexts;
|
||||||
use bevy_inspector_egui::egui::{self};
|
use bevy_inspector_egui::egui::{self};
|
||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
@@ -10,22 +11,25 @@ use world_generation::{map::map_utils::render_map, prelude::Map, states::Generat
|
|||||||
|
|
||||||
pub struct EditorPlugin;
|
pub struct EditorPlugin;
|
||||||
|
|
||||||
impl Plugin for EditorPlugin {
|
impl Plugin for EditorPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.init_resource::<UIState>();
|
app.init_resource::<UIState>();
|
||||||
|
|
||||||
// app.add_systems(PostUpdate, prepare_image.run_if(in_state(GeneratorState::SpawnMap)));
|
app.add_systems(PostUpdate, prepare_image.run_if(in_state(GeneratorState::SpawnMap)));
|
||||||
// app.add_systems(
|
app.add_systems(
|
||||||
// Update,
|
Update,
|
||||||
// (render_map_ui, update_map_render, asset_reloaded).run_if(in_state(GeneratorState::Idle)),
|
(render_map_ui, update_map_render, asset_reloaded).run_if(in_state(GeneratorState::Idle)),
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct MapImage(pub Handle<Image>);
|
struct MapImage(pub Handle<Image>);
|
||||||
|
|
||||||
pub fn prepare_image(mut images: ResMut<Assets<Image>>, heightmap: Res<Map>, mut commands: Commands) {
|
pub fn prepare_image(mut images: ResMut<Assets<Image>>, heightmap: Res<Map>, mut commands: Commands)
|
||||||
|
{
|
||||||
let image = render_map(&heightmap, 0.1);
|
let image = render_map(&heightmap, 0.1);
|
||||||
let handle = images.add(Image::from_dynamic(image.into(), true, RenderAssetUsages::RENDER_WORLD));
|
let handle = images.add(Image::from_dynamic(image.into(), true, RenderAssetUsages::RENDER_WORLD));
|
||||||
|
|
||||||
@@ -33,14 +37,17 @@ pub fn prepare_image(mut images: ResMut<Assets<Image>>, heightmap: Res<Map>, mut
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct UIState {
|
struct UIState
|
||||||
|
{
|
||||||
pub is_open: bool,
|
pub is_open: bool,
|
||||||
pub target_map_type: MapDisplayType,
|
pub target_map_type: MapDisplayType,
|
||||||
pub cur_map_type: MapDisplayType,
|
pub cur_map_type: MapDisplayType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UIState {
|
impl Default for UIState
|
||||||
fn default() -> Self {
|
{
|
||||||
|
fn default() -> Self
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
is_open: true,
|
is_open: true,
|
||||||
target_map_type: default(),
|
target_map_type: default(),
|
||||||
@@ -50,7 +57,8 @@ impl Default for UIState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
|
||||||
enum MapDisplayType {
|
enum MapDisplayType
|
||||||
|
{
|
||||||
#[default]
|
#[default]
|
||||||
HeightMap,
|
HeightMap,
|
||||||
Biomes,
|
Biomes,
|
||||||
@@ -61,35 +69,39 @@ enum MapDisplayType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn asset_reloaded(
|
fn asset_reloaded(
|
||||||
mut asset_events: EventReader<AssetEvent<BiomeAsset>>,
|
mut asset_events: MessageReader<AssetEvent<BiomeAsset>>,
|
||||||
mut biomes: ResMut<Assets<BiomeAsset>>,
|
biomes: Res<Assets<BiomeAsset>>,
|
||||||
biome_painter: Res<BiomePainterAsset>,
|
biome_painter: Res<BiomePainterAsset>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let mut rebuild = false;
|
let mut rebuild = false;
|
||||||
for event in asset_events.read() {
|
for event in asset_events.read()
|
||||||
match event {
|
{
|
||||||
|
match event
|
||||||
|
{
|
||||||
AssetEvent::Modified { .. } => rebuild = true,
|
AssetEvent::Modified { .. } => rebuild = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rebuild {
|
if rebuild
|
||||||
|
{
|
||||||
let painter = biome_painter.build(&biomes);
|
let painter = biome_painter.build(&biomes);
|
||||||
commands.insert_resource(painter);
|
commands.insert_resource(painter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_map_ui(
|
fn render_map_ui(
|
||||||
image: Res<MapImage>,
|
// image: Res<MapImage>,
|
||||||
heightmap: Res<Map>,
|
heightmap: Res<Map>,
|
||||||
biome_map: Res<BiomeMap>,
|
biome_map: Res<BiomeMap>,
|
||||||
mut contexts: EguiContexts,
|
mut contexts: EguiContexts,
|
||||||
mut state: ResMut<UIState>,
|
mut state: ResMut<UIState>,
|
||||||
) {
|
)
|
||||||
let id = contexts.add_image(image.0.clone_weak());
|
{
|
||||||
|
// let id = contexts.add_image(image.0.);
|
||||||
let mut map_type = state.target_map_type;
|
let mut map_type = state.target_map_type;
|
||||||
let ctx = contexts.ctx_mut();
|
let ctx = contexts.ctx_mut().expect("Failed to get egui context");
|
||||||
egui::Window::new("Map").open(&mut state.is_open).show(ctx, |ui| {
|
egui::Window::new("Map").open(&mut state.is_open).show(ctx, |ui| {
|
||||||
ui.label("Map Test");
|
ui.label("Map Test");
|
||||||
egui::ComboBox::from_label("Display Type")
|
egui::ComboBox::from_label("Display Type")
|
||||||
@@ -115,12 +127,13 @@ fn render_map_ui(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add(egui::widgets::Image::new(egui::load::SizedTexture::new(
|
// ui.add(egui::widgets::Image::new(egui::load::SizedTexture::new(
|
||||||
id,
|
// id,
|
||||||
[512.0, 512.0],
|
// [512.0, 512.0],
|
||||||
)));
|
// )));
|
||||||
|
|
||||||
if ui.button("Save Image").clicked() {
|
if ui.button("Save Image").clicked()
|
||||||
|
{
|
||||||
let img = get_map_image(&heightmap, &biome_map, map_type);
|
let img = get_map_image(&heightmap, &biome_map, map_type);
|
||||||
_ = img.save(format!("{:?}.png", map_type));
|
_ = img.save(format!("{:?}.png", map_type));
|
||||||
}
|
}
|
||||||
@@ -135,22 +148,28 @@ fn update_map_render(
|
|||||||
heightmap: Res<Map>,
|
heightmap: Res<Map>,
|
||||||
biome_map: Res<BiomeMap>,
|
biome_map: Res<BiomeMap>,
|
||||||
image: Res<MapImage>,
|
image: Res<MapImage>,
|
||||||
) {
|
)
|
||||||
if state.cur_map_type == state.target_map_type {
|
{
|
||||||
|
if state.cur_map_type == state.target_map_type
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = get_map_image(&heightmap, &biome_map, state.target_map_type);
|
let result = get_map_image(&heightmap, &biome_map, state.target_map_type);
|
||||||
images.insert(
|
images
|
||||||
|
.insert(
|
||||||
image.0.id(),
|
image.0.id(),
|
||||||
Image::from_dynamic(result.into(), true, RenderAssetUsages::RENDER_WORLD),
|
Image::from_dynamic(result.into(), true, RenderAssetUsages::RENDER_WORLD),
|
||||||
);
|
)
|
||||||
|
.expect("Failed to update map image");
|
||||||
|
|
||||||
state.cur_map_type = state.target_map_type;
|
state.cur_map_type = state.target_map_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_map_image(heightmap: &Map, biome_map: &BiomeMap, map_type: MapDisplayType) -> ImageBuffer<Rgba<u8>, Vec<u8>> {
|
fn get_map_image(heightmap: &Map, biome_map: &BiomeMap, map_type: MapDisplayType) -> ImageBuffer<Rgba<u8>, Vec<u8>>
|
||||||
return match map_type {
|
{
|
||||||
|
return match map_type
|
||||||
|
{
|
||||||
MapDisplayType::HeightMap => render_map(&heightmap, 0.1),
|
MapDisplayType::HeightMap => render_map(&heightmap, 0.1),
|
||||||
MapDisplayType::Biomes => render_biome_map(&heightmap, &biome_map),
|
MapDisplayType::Biomes => render_biome_map(&heightmap, &biome_map),
|
||||||
MapDisplayType::BiomeNoise => render_biome_noise_map(&biome_map, Vec3::ONE),
|
MapDisplayType::BiomeNoise => render_biome_noise_map(&biome_map, Vec3::ONE),
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use bevy::{prelude::*, window::PrimaryWindow};
|
use bevy::{prelude::*, window::PrimaryWindow};
|
||||||
use bevy_rapier3d::{
|
use bevy_rapier3d::{plugin::ReadRapierContext, prelude::QueryFilter};
|
||||||
plugin::{RapierContext, ReadDefaultRapierContext},
|
|
||||||
prelude::QueryFilter,
|
|
||||||
};
|
|
||||||
use shared::{
|
use shared::{
|
||||||
resources::{TileContact, TileUnderCursor},
|
resources::{TileContact, TileUnderCursor},
|
||||||
tags::MainCamera,
|
tags::MainCamera,
|
||||||
@@ -10,8 +7,10 @@ use shared::{
|
|||||||
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
||||||
pub struct TileSelectionPlugin;
|
pub struct TileSelectionPlugin;
|
||||||
|
|
||||||
impl Plugin for TileSelectionPlugin {
|
impl Plugin for TileSelectionPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.init_resource::<TileUnderCursor>();
|
app.init_resource::<TileUnderCursor>();
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
@@ -21,28 +20,29 @@ impl Plugin for TileSelectionPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_tile_under_cursor(
|
fn update_tile_under_cursor(
|
||||||
cam_query: Query<(&GlobalTransform, &Camera), With<MainCamera>>,
|
cam_query: Single<(&GlobalTransform, &Camera), With<MainCamera>>,
|
||||||
window: Query<&Window, With<PrimaryWindow>>,
|
window: Single<&Window, With<PrimaryWindow>>,
|
||||||
rapier_context: ReadDefaultRapierContext,
|
rapier: ReadRapierContext,
|
||||||
map: Res<Map>,
|
map: Res<Map>,
|
||||||
mut tile_under_cursor: ResMut<TileUnderCursor>,
|
mut tile_under_cursor: ResMut<TileUnderCursor>,
|
||||||
) {
|
)
|
||||||
let win_r = window.get_single();
|
{
|
||||||
if win_r.is_err() {
|
let (cam_transform, camera) = cam_query.into_inner();
|
||||||
return;
|
let Some(cursor_pos) = window.cursor_position()
|
||||||
}
|
else
|
||||||
let win = win_r.unwrap();
|
{
|
||||||
|
|
||||||
let (cam_transform, camera) = cam_query.single();
|
|
||||||
let Some(cursor_pos) = win.cursor_position() else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(cam_ray) = camera.viewport_to_world(cam_transform, cursor_pos) else {
|
let Ok(cam_ray) = camera.viewport_to_world(cam_transform, cursor_pos)
|
||||||
|
else
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let collision = rapier_context.cast_ray(
|
let ctx = rapier.single().expect("Failed to get rapier read context");
|
||||||
|
|
||||||
|
let collision = ctx.cast_ray(
|
||||||
cam_ray.origin,
|
cam_ray.origin,
|
||||||
cam_ray.direction.into(),
|
cam_ray.direction.into(),
|
||||||
500.,
|
500.,
|
||||||
@@ -50,11 +50,13 @@ fn update_tile_under_cursor(
|
|||||||
QueryFilter::only_fixed(),
|
QueryFilter::only_fixed(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((_e, dist)) = collision {
|
if let Some((_e, dist)) = collision
|
||||||
|
{
|
||||||
let contact_point = cam_ray.get_point(dist);
|
let contact_point = cam_ray.get_point(dist);
|
||||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||||
//todo: handle correct tile detection when contacting a tile from the side
|
//todo: handle correct tile detection when contacting a tile from the side
|
||||||
if !map.is_in_bounds(&contact_coord) {
|
if !map.is_in_bounds(&contact_coord)
|
||||||
|
{
|
||||||
tile_under_cursor.0 = None;
|
tile_under_cursor.0 = None;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -64,7 +66,9 @@ fn update_tile_under_cursor(
|
|||||||
contact_point,
|
contact_point,
|
||||||
contact_coord.to_world(surface),
|
contact_coord.to_world(surface),
|
||||||
));
|
));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tile_under_cursor.0 = None;
|
tile_under_cursor.0 = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
world_generation = { path = "../../engine/world_generation" }
|
world_generation = { path = "../../engine/world_generation" }
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
asset_loader = { path = "../../engine/asset_loader" }
|
asset_loader = { path = "../../engine/asset_loader" }
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.149"
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
bevy_asset_loader = { version = "0.23.0-rc.3", features = [
|
bevy_asset_loader = { version = "0.25.0", features = [
|
||||||
"standard_dynamic_assets",
|
"standard_dynamic_assets",
|
||||||
"3d",
|
"3d",
|
||||||
] }
|
] }
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
world_generation = { path = "../../engine/world_generation" }
|
world_generation = { path = "../../engine/world_generation" }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
69
game/shared/src/coords.rs
Normal file
69
game/shared/src/coords.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Reflect)]
|
||||||
|
pub struct CoordsCollection
|
||||||
|
{
|
||||||
|
points: Vec<IVec2>,
|
||||||
|
origin: IVec2,
|
||||||
|
translation: IVec2,
|
||||||
|
rotation: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CoordsCollection
|
||||||
|
{
|
||||||
|
pub fn from_hex(coords: Vec<HexCoord>) -> Self
|
||||||
|
{
|
||||||
|
CoordsCollection {
|
||||||
|
points: coords.iter().map(|c| c.hex.xy()).collect(),
|
||||||
|
..default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_points(points: Vec<IVec2>) -> Self
|
||||||
|
{
|
||||||
|
CoordsCollection { points, ..default() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_translation(mut self, translation: &HexCoord) -> Self
|
||||||
|
{
|
||||||
|
self.translation = translation.hex.xy();
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_translation_vec(mut self, translation: IVec2) -> Self
|
||||||
|
{
|
||||||
|
self.translation = translation;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_origin(mut self, orign: &HexCoord) -> Self
|
||||||
|
{
|
||||||
|
self.origin = orign.hex.xy();
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_rotation(mut self, rotation: i32) -> Self
|
||||||
|
{
|
||||||
|
self.rotation = rotation;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_coords(&self) -> Vec<HexCoord>
|
||||||
|
{
|
||||||
|
let center = HexCoord::from_hex(self.origin);
|
||||||
|
return self
|
||||||
|
.points
|
||||||
|
.iter()
|
||||||
|
.map(|p| HexCoord::from_hex(p + self.origin).rotate_around(¢er, self.rotation))
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<Vec<HexCoord>> for CoordsCollection
|
||||||
|
{
|
||||||
|
fn into(self) -> Vec<HexCoord>
|
||||||
|
{
|
||||||
|
self.get_coords()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ fn despawn_at(mut commands: Commands, time: Res<Time>, entities: Query<(Entity,
|
|||||||
fn despawn_after(mut commands: Commands, mut entities: Query<(&mut DespawnAfter, Entity)>, time: Res<Time>) {
|
fn despawn_after(mut commands: Commands, mut entities: Query<(&mut DespawnAfter, Entity)>, time: Res<Time>) {
|
||||||
for (mut after, entity) in &mut entities.iter_mut() {
|
for (mut after, entity) in &mut entities.iter_mut() {
|
||||||
after.0.tick(time.delta());
|
after.0.tick(time.delta());
|
||||||
if after.0.finished() {
|
if after.0.is_finished() {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use world_generation::hex_utils::*;
|
use world_generation::hex_utils::*;
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Message)]
|
||||||
pub enum TileModifiedEvent {
|
pub enum TileModifiedEvent {
|
||||||
HeightChanged(HexCoord, f32),
|
HeightChanged(HexCoord, f32),
|
||||||
TypeChanged(HexCoord, usize),
|
TypeChanged(HexCoord, usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Message)]
|
||||||
pub struct ChunkModifiedEvent {
|
pub struct ChunkModifiedEvent {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use bevy::reflect::Reflect;
|
use bevy::reflect::Reflect;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use world_generation::hex_utils::HexCoord;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
||||||
pub struct ResourceIdentifier {
|
pub struct ResourceIdentifier
|
||||||
|
{
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub qty: u32,
|
pub qty: u32,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use bevy::reflect::Reflect;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod building;
|
pub mod building;
|
||||||
|
pub mod coords;
|
||||||
pub mod despawn;
|
pub mod despawn;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod identifiers;
|
pub mod identifiers;
|
||||||
@@ -9,12 +10,13 @@ pub mod resources;
|
|||||||
pub mod sets;
|
pub mod sets;
|
||||||
pub mod states;
|
pub mod states;
|
||||||
pub mod tags;
|
pub mod tags;
|
||||||
pub mod prefab_defination;
|
// pub mod prefab_defination;
|
||||||
pub mod component_defination;
|
// pub mod animation_plugin;
|
||||||
pub mod animation_plugin;
|
// pub mod component_defination;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum Tier {
|
pub enum Tier
|
||||||
|
{
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
@@ -23,7 +25,8 @@ pub enum Tier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
||||||
pub enum StatusEffect {
|
pub enum StatusEffect
|
||||||
|
{
|
||||||
UnitRange(f32),
|
UnitRange(f32),
|
||||||
UnitAttack(f32),
|
UnitAttack(f32),
|
||||||
UnitHealth(f32),
|
UnitHealth(f32),
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16.0"
|
bevy = "0.18.0"
|
||||||
world_generation = { path = "../../engine/world_generation" }
|
world_generation = { path = "../../engine/world_generation" }
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
bevy_rapier3d = "0.29.0"
|
bevy_rapier3d = "0.33.0"
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
asset_loader = { path = "../../engine/asset_loader" }
|
asset_loader = { path = "../../engine/asset_loader" }
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.149"
|
||||||
ron = "0.8.1"
|
ron = "0.12.0"
|
||||||
bevy_asset_loader = { version = "0.23.0-rc.3", features = [
|
bevy_asset_loader = { version = "0.25.0", features = [
|
||||||
"standard_dynamic_assets",
|
"standard_dynamic_assets",
|
||||||
"3d",
|
"3d",
|
||||||
] }
|
] }
|
||||||
quadtree_rs = "0.1.3"
|
quadtree_rs = "0.1.3"
|
||||||
pathfinding = "4.11.0"
|
pathfinding = "4.14.0"
|
||||||
ordered-float = "4.3.0"
|
ordered-float = "5.1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tracing = ["bevy/trace_tracy"]
|
tracing = ["bevy/trace_tracy"]
|
||||||
|
|||||||
@@ -20,13 +20,7 @@ impl UnitAsset {
|
|||||||
pub fn spawn(&self, transform: Transform) -> CommandQueue {
|
pub fn spawn(&self, transform: Transform) -> CommandQueue {
|
||||||
let mut commands = CommandQueue::default();
|
let mut commands = CommandQueue::default();
|
||||||
|
|
||||||
let bundle = (
|
let bundle = (transform, Unit);
|
||||||
PbrBundle {
|
|
||||||
transform: transform,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
Unit,
|
|
||||||
);
|
|
||||||
let domain = self.domain.clone();
|
let domain = self.domain.clone();
|
||||||
commands.push(move |world: &mut World| {
|
commands.push(move |world: &mut World| {
|
||||||
let mut e = world.spawn(bundle);
|
let mut e = world.spawn(bundle);
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
use bevy::reflect::Reflect;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod nav_data;
|
pub mod nav_data;
|
||||||
@@ -11,6 +8,7 @@ pub mod units_plugin;
|
|||||||
pub mod units_spacial_set;
|
pub mod units_spacial_set;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum UnitType {
|
pub enum UnitType
|
||||||
|
{
|
||||||
Basic,
|
Basic,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use bevy::{ecs::world::CommandQueue, prelude::*, tasks::AsyncComputeTaskPool, utils::futures};
|
use bevy::{
|
||||||
|
ecs::world::CommandQueue,
|
||||||
|
prelude::*,
|
||||||
|
tasks::{futures, AsyncComputeTaskPool},
|
||||||
|
};
|
||||||
use pathfinding::prelude::astar;
|
use pathfinding::prelude::astar;
|
||||||
use shared::{events::TileModifiedEvent, resources::TileUnderCursor, sets::GameplaySet};
|
use shared::{events::TileModifiedEvent, resources::TileUnderCursor, sets::GameplaySet};
|
||||||
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
||||||
@@ -41,7 +45,7 @@ fn build_navdata(mut commands: Commands, map: Res<Map>) {
|
|||||||
commands.insert_resource(nav_data);
|
commands.insert_resource(nav_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_navdata(mut tile_updates: EventReader<TileModifiedEvent>, mut nav_data: ResMut<NavData>) {
|
fn update_navdata(mut tile_updates: MessageReader<TileModifiedEvent>, mut nav_data: ResMut<NavData>) {
|
||||||
for event in tile_updates.read() {
|
for event in tile_updates.read() {
|
||||||
match event {
|
match event {
|
||||||
TileModifiedEvent::HeightChanged(coord, new_height) => {
|
TileModifiedEvent::HeightChanged(coord, new_height) => {
|
||||||
|
|||||||
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "nightly"
|
||||||
Reference in New Issue
Block a user