messing arround with asset loader
Need to figure out dynamic assets Need to switch to ron files
This commit is contained in:
33
game/main/src/assets/biome_painer.rs
Normal file
33
game/main/src/assets/biome_painer.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#[derive(AssetCollection, Serialize, Deserialize, Debug, TypePath, Asset, Clone)]
|
||||
pub struct BiomePainterAsset {
|
||||
#[asset(path)]
|
||||
pub biomes: Vec<Handle<BiomeAsset>>,
|
||||
}
|
||||
|
||||
impl BiomePainterAsset {
|
||||
pub fn sample_biome(&self, assets: &Assets<BiomeAsset>, data: &BiomeData) -> AssetId<BiomeAsset> {
|
||||
assert!(self.biomes.length() != 0, "There are no biomes");
|
||||
let mut biome = self.biomes.first().unwrap().id();
|
||||
let mut dist = f32::INFINITY;
|
||||
|
||||
for b in &self.biomes {
|
||||
let asset = assets.get(b.id()).unwrap();
|
||||
let d = asset.distance(data.into());
|
||||
if d < dist {
|
||||
biome = b.id();
|
||||
dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
return biome;
|
||||
}
|
||||
|
||||
pub fn build(&self, assets: &Assets<BiomeAsset>) -> BiomePainter {
|
||||
let mut biomes = Vec::with_capacity(self.biomes.len());
|
||||
for b in &self.biomes {
|
||||
let asset = assets.get(b.id()).unwrap();
|
||||
biomes.push(asset.clone());
|
||||
}
|
||||
return BiomePainter { biomes };
|
||||
}
|
||||
}
|
||||
1
game/main/src/assets/mod.rs
Normal file
1
game/main/src/assets/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod biome_painer;
|
||||
@@ -11,6 +11,7 @@ mod phos;
|
||||
mod prelude;
|
||||
mod shader_extensions;
|
||||
mod utlis;
|
||||
pub mod assets;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
|
||||
@@ -62,8 +62,8 @@ impl Plugin for MapInitPlugin {
|
||||
},
|
||||
));
|
||||
|
||||
app.add_systems(Startup, (load_textures, load_tiles).in_set(AssetLoaderSet));
|
||||
app.configure_sets(Startup, AssetLoaderSet.run_if(in_state(AssetLoadState::StartLoading)));
|
||||
//app.add_systems(Startup, (load_textures, load_tiles).in_set(AssetLoaderSet));
|
||||
//app.configure_sets(Startup, AssetLoaderSet.run_if(in_state(AssetLoadState::StartLoading)));
|
||||
|
||||
app.add_systems(
|
||||
Update,
|
||||
@@ -96,11 +96,9 @@ struct WaterInspect(Handle<ExtendedMaterial<StandardMaterial, WaterMaterial>>);
|
||||
|
||||
fn load_textures(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut atlas: ResMut<ChunkAtlas>,
|
||||
mut water_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, WaterMaterial>>>,
|
||||
) {
|
||||
let main_tex = asset_server.load("textures/world/Terra.png");
|
||||
|
||||
let water_material = water_materials.add(ExtendedMaterial {
|
||||
base: StandardMaterial {
|
||||
base_color: Color::srgba(0., 0.5, 1., 0.8),
|
||||
@@ -117,12 +115,7 @@ fn load_textures(
|
||||
},
|
||||
});
|
||||
commands.insert_resource(WaterInspect(water_material.clone()));
|
||||
commands.insert_resource(ChunkAtlas {
|
||||
handle: main_tex,
|
||||
is_loaded: false,
|
||||
chunk_material_handle: Handle::default(),
|
||||
water_material,
|
||||
});
|
||||
atlas.water_material = water_material;
|
||||
}
|
||||
|
||||
fn load_tiles(
|
||||
@@ -192,7 +185,6 @@ fn finalize_texture(
|
||||
let array_layers = image.height() / image.width();
|
||||
image.reinterpret_stacked_2d_as_array(array_layers);
|
||||
|
||||
atlas.is_loaded = true;
|
||||
let chunk_material = chunk_materials.add(ExtendedMaterial {
|
||||
base: StandardMaterial::default(),
|
||||
extension: ChunkMaterial {
|
||||
|
||||
@@ -6,13 +6,14 @@ use bevy::{
|
||||
pbr::{wireframe::WireframeConfig, CascadeShadowConfig},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
use bevy_rapier3d::dynamics::{Ccd, RigidBody, Velocity};
|
||||
use bevy_rapier3d::geometry::Collider;
|
||||
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
||||
use buildings::BuildingPugin;
|
||||
use iyes_perf_ui::prelude::*;
|
||||
use shared::despawn::DespawnPuglin;
|
||||
use shared::states::{GameplayState, MenuState};
|
||||
use shared::{despawn::DespawnPuglin, states::AssetLoadState};
|
||||
|
||||
pub struct PhosGamePlugin;
|
||||
|
||||
@@ -22,13 +23,18 @@ impl Plugin for PhosGamePlugin {
|
||||
PhosCameraPlugin,
|
||||
MapInitPlugin,
|
||||
RenderDistancePlugin,
|
||||
BuildingPugin,
|
||||
// BuildingPugin,
|
||||
DespawnPuglin,
|
||||
));
|
||||
|
||||
app.insert_state(MenuState::Startup);
|
||||
app.insert_state(AssetLoadState::Loading);
|
||||
app.insert_state(MenuState::Loading);
|
||||
app.insert_state(GameplayState::Waiting);
|
||||
|
||||
app.add_loading_state(
|
||||
LoadingState::new(AssetLoadState::Loading).continue_to_state(AssetLoadState::FinalizeAssets),
|
||||
);
|
||||
|
||||
//Systems - Startup
|
||||
app.add_systems(Startup, init_game);
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@ use bevy::asset::Handle;
|
||||
use bevy::pbr::ExtendedMaterial;
|
||||
use bevy::prelude::*;
|
||||
use bevy::prelude::{Component, Image, Resource};
|
||||
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||
|
||||
use crate::shader_extensions::chunk_material::ChunkMaterial;
|
||||
use crate::shader_extensions::water_material::WaterMaterial;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
#[derive(AssetCollection, Resource, Default)]
|
||||
pub struct ChunkAtlas {
|
||||
#[asset(path = "textures/world/Terra.png")]
|
||||
pub handle: Handle<Image>,
|
||||
pub chunk_material_handle: Handle<ExtendedMaterial<StandardMaterial, ChunkMaterial>>,
|
||||
pub water_material: Handle<ExtendedMaterial<StandardMaterial, WaterMaterial>>,
|
||||
pub is_loaded: bool,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
||||
Reference in New Issue
Block a user