Remove globe_view feature

it's really just not worth the effort imho
This commit is contained in:
Tobias Berger 2022-11-07 12:29:56 +01:00
parent 8c101386db
commit ba0651296f
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
9 changed files with 39 additions and 220 deletions

View file

@ -10,18 +10,6 @@ jobs:
strategy: strategy:
matrix: matrix:
include: include:
- target: x86_64-apple-darwin
os: macos-latest
features: globe_view
- target: aarch64-apple-darwin
os: macos-latest
features: globe_view
- target: x86_64-pc-windows-msvc
os: windows-latest
features: globe_view
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: globe_view
- target: x86_64-apple-darwin - target: x86_64-apple-darwin
os: macos-latest os: macos-latest
features: render features: render
@ -46,6 +34,30 @@ jobs:
- target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-gnu
os: ubuntu-latest os: ubuntu-latest
features: "" features: ""
- target: x86_64-apple-darwin
os: macos-latest
features: render,logging
- target: aarch64-apple-darwin
os: macos-latest
features: render,logging
- target: x86_64-pc-windows-msvc
os: windows-latest
features: render,logging
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: render,logging
- target: x86_64-apple-darwin
os: macos-latest
features: logging
- target: aarch64-apple-darwin
os: macos-latest
features: logging
- target: x86_64-pc-windows-msvc
os: windows-latest
features: logging
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: logging
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout

View file

@ -27,9 +27,8 @@ codegen-units = 1
# bevy/trace_chrome for tracing by function # bevy/trace_chrome for tracing by function
# https://github.com/bevyengine/bevy/blob/main/docs/profiling.md # https://github.com/bevyengine/bevy/blob/main/docs/profiling.md
logging = ["planet/logging"] logging = ["planet/logging"]
globe_view = ["planet/globe_view", "render"]
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:fxhash", "dep:bevy_egui"] render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:fxhash", "dep:bevy_egui"]
default = ["render", "logging", "globe_view"] default = ["render", "logging"]
[dependencies.planet] [dependencies.planet]
path = "planet" path = "planet"

View file

@ -1,26 +1,18 @@
#!/bin/env /bin/sh #!/bin/env /bin/sh
echo "Debug-build features: minimal" echo "Debug-build with features: minimal"
cargo build --no-default-features --features= && cargo build --no-default-features --features= &&
echo "Debug-build features: logging" && echo "Debug-build with features: logging" &&
cargo build --no-default-features --features=logging && cargo build --no-default-features --features=logging &&
echo "Debug-build features: render" && echo "Debug-build with features: render" &&
cargo build --no-default-features --features=render && cargo build --no-default-features --features=render &&
echo "Debug-build features: logging,render" && echo "Debug-build with features: logging render" &&
cargo build --no-default-features --features=logging,render && cargo build --no-default-features --features=logging,render &&
echo "Debug-build features: globe_view" && echo "Release-build with features: minimal"
cargo build --no-default-features --features=globe_view &&
echo "Debug-build features: logging,globe_view" &&
cargo build --no-default-features --features=logging,globe_view &&
echo "Release-build features: minimal"
cargo build --release --no-default-features --features= && cargo build --release --no-default-features --features= &&
echo "Release-build features: logging" && echo "Release-build with features: logging" &&
cargo build --release --no-default-features --features=logging && cargo build --release --no-default-features --features=logging &&
echo "Release-build features: render" && echo "Release-build with features: render" &&
cargo build --release --no-default-features --features=render && cargo build --release --no-default-features --features=render &&
echo "Release-build features: logging,render" && echo "Release-build with features: logging render" &&
cargo build --release --no-default-features --features=logging,render && cargo build --release --no-default-features --features=logging,render &&
echo "Release-build features: globe_view" &&
cargo build --release --no-default-features --features=globe_view &&
echo "Release-build features: logging,globe_view" &&
cargo build --release --no-default-features --features=logging,globe_view &&
echo "Done!" echo "Done!"

View file

@ -8,9 +8,8 @@ release = { strip = "symbols", lto = "thin", opt-level = "z" }
[features] [features]
logging = [] logging = []
globe_view = ["render"]
render = ["bevy/render"] render = ["bevy/render"]
default = ["render", "logging", "globe_view"] default = ["render", "logging"]
[dependencies.rand] [dependencies.rand]
version = "0.8.5" version = "0.8.5"

View file

@ -1,12 +1,8 @@
#[cfg(all(feature = "logging", feature = "render"))] #[cfg(all(feature = "logging", feature = "render"))]
use bevy::log::debug; use bevy::log::debug;
#[cfg(feature = "logging")]
use bevy::utils::default;
#[cfg(all(feature = "render", feature = "globe_view"))]
use std::f32::consts::PI;
use { use {
crate::{macros::iterable_enum, World, WorldGenError}, crate::{macros::iterable_enum, World, WorldGenError},
bevy::log::warn, bevy::{log::warn, utils::default},
rand::random, rand::random,
std::{ std::{
error::Error, error::Error,
@ -94,11 +90,7 @@ iterable_enum!(PlanetView { Biomes, Altitude });
#[cfg(feature = "render")] #[cfg(feature = "render")]
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct WorldRenderSettings { pub struct WorldRenderSettings {
pub map_image_handle_id: Option<HandleId>, pub map_image_handle_id: Option<HandleId>,
#[cfg(feature = "globe_view")]
pub globe_image_handle_id: Option<HandleId>,
#[cfg(feature = "globe_view")]
pub globe_material_handle_id: Option<HandleId>,
rainfall_visible: bool, rainfall_visible: bool,
temperature_visible: bool, temperature_visible: bool,
@ -422,46 +414,4 @@ impl WorldManager {
}) })
.collect() .collect()
} }
#[cfg(all(feature = "render", feature = "globe_view"))]
#[must_use]
fn globe_colors(&self) -> Vec<Color> {
let world = self.world();
let width = world.width as usize;
let height = world.height as usize;
let mut colors = vec![Color::PINK; height * width];
for y in 0..world.height as usize * 2 {
for x in 0..world.width as usize {
let factor_y = (1.0 - f32::cos(PI * y as f32 / (world.height * 2) as f32)) / 2.0;
let real_y = f32::floor(world.height as f32 * factor_y) as usize;
#[cfg(feature = "logging")]
assert!(
real_y < world.height as usize,
"Trying to get cell off of planet. {}/{}",
real_y,
world.height
);
colors[real_y * width + x] = self.generate_color(&world.terrain[real_y][x]);
}
}
colors
}
#[cfg(all(feature = "render", feature = "globe_view"))]
#[must_use]
pub fn globe_color_bytes(&self) -> Vec<u8> {
self.globe_colors()
.iter()
.flat_map(|color| {
color
.as_rgba_f32()
.iter()
.flat_map(|num| num.to_le_bytes())
.collect::<Vec<u8>>()
})
.collect()
}
} }

View file

@ -1,12 +1,3 @@
#[cfg(feature = "globe_view")]
use {
crate::components::panning::Pan2d,
bevy::{
core_pipeline::{core_2d::Camera2d, core_3d::Camera3d},
ecs::query::{With, Without},
render::camera::Camera,
},
};
use { use {
crate::{ crate::{
gui::{open_window, update_textures, windows::Overlay, WidgetId, WidgetSystem}, gui::{open_window, update_textures, windows::Overlay, WidgetId, WidgetSystem},
@ -29,7 +20,6 @@ use {
std::marker::PhantomData, std::marker::PhantomData,
}; };
#[cfg(not(feature = "globe_view"))]
iterable_enum!(ToolbarButton { iterable_enum!(ToolbarButton {
GenerateWorld, GenerateWorld,
SaveWorld, SaveWorld,
@ -37,15 +27,6 @@ iterable_enum!(ToolbarButton {
Overlays, Overlays,
ToggleBiomes, ToggleBiomes,
}); });
#[cfg(feature = "globe_view")]
iterable_enum!(ToolbarButton {
GenerateWorld,
SaveWorld,
LoadWorld,
Overlays,
ToggleBiomes,
GlobeView,
});
impl ToolbarButton { impl ToolbarButton {
fn clicked(self, world: &mut World) { fn clicked(self, world: &mut World) {
@ -78,18 +59,6 @@ impl ToolbarButton {
world_manager.render_settings.cycle_view(); world_manager.render_settings.cycle_view();
update_textures(&world_manager, &mut world.resource_mut::<Assets<Image>>()); update_textures(&world_manager, &mut world.resource_mut::<Assets<Image>>());
}, },
#[cfg(feature = "globe_view")]
ToolbarButton::GlobeView => {
let mut camera_3d = world
.query_filtered::<&mut Camera, (With<Camera3d>, Without<Camera2d>)>()
.single_mut(world);
camera_3d.is_active = !camera_3d.is_active;
let (mut camera_2d, mut pancam) = world
.query_filtered::<(&mut Camera, &mut Pan2d), (With<Camera2d>, Without<Camera3d>)>()
.single_mut(world);
camera_2d.is_active = !camera_2d.is_active;
pancam.enabled = camera_2d.is_active;
},
}; };
}); });
} }
@ -103,8 +72,6 @@ impl From<ToolbarButton> for &'static str {
ToolbarButton::GenerateWorld => "Generate new world", ToolbarButton::GenerateWorld => "Generate new world",
ToolbarButton::SaveWorld => "Save", ToolbarButton::SaveWorld => "Save",
ToolbarButton::LoadWorld => "Load", ToolbarButton::LoadWorld => "Load",
#[cfg(feature = "globe_view")]
ToolbarButton::GlobeView => "Toggle globe",
} }
} }
} }

View file

@ -42,13 +42,13 @@ impl WindowSystem for TileInfo<'_, '_> {
} = &world_manager.world().terrain[cursor_y as usize][cursor_x as usize]; } = &world_manager.world().terrain[cursor_y as usize][cursor_x as usize];
_ = ui.label("Altitude"); _ = ui.label("Altitude");
_ = ui.label(format!("{:.2}", altitude)); _ = ui.label(format!("{altitude:.2}"));
ui.end_row(); ui.end_row();
_ = ui.label("Rainfall"); _ = ui.label("Rainfall");
_ = ui.label(format!("{:.2}", rainfall)); _ = ui.label(format!("{rainfall:.2}"));
ui.end_row(); ui.end_row();
_ = ui.label("Temperature"); _ = ui.label("Temperature");
_ = ui.label(format!("{:.2}", temperature)); _ = ui.label(format!("{temperature:.2}"));
ui.end_row(); ui.end_row();
ui.end_row(); ui.end_row();

View file

@ -57,20 +57,6 @@ use {
gui::{render_windows, widget, widgets::ToolbarWidget, window::open_window, windows::TileInfo}, gui::{render_windows, widget, widgets::ToolbarWidget, window::open_window, windows::TileInfo},
resources::{CursorMapPosition, OpenedWindows}, resources::{CursorMapPosition, OpenedWindows},
}; };
#[cfg(all(feature = "render", feature = "globe_view"))]
use {
bevy::{
asset::Handle,
core_pipeline::core_3d::Camera3dBundle,
pbr::{PbrBundle, PointLight, PointLightBundle, StandardMaterial},
prelude::{Quat, Vec3},
render::camera::OrthographicProjection,
render::mesh::{shape::UVSphere, Mesh},
time::Time,
transform::components::Transform,
},
std::f32::consts::FRAC_PI_2,
};
#[cfg(feature = "render")] #[cfg(feature = "render")]
fn update_cursor_map_position( fn update_cursor_map_position(
@ -104,26 +90,12 @@ fn update_cursor_map_position(
} }
} }
#[cfg(all(feature = "render", feature = "globe_view"))]
const GLOBE_ROTATIONS_PER_SECOND: f32 = std::f32::consts::TAU / 15.0;
#[cfg(all(feature = "render", feature = "globe_view"))]
fn rotate_globe(
mut globe_transform: Query<'_, '_, &mut Transform, With<Handle<Mesh>>>,
time: Res<Time>,
) {
globe_transform
.single_mut()
.rotate_y(GLOBE_ROTATIONS_PER_SECOND * time.delta_seconds());
}
#[cfg(feature = "render")] #[cfg(feature = "render")]
fn generate_graphics( fn generate_graphics(
mut commands: Commands<'_, '_>, mut commands: Commands<'_, '_>,
mut world_manager: ResMut<'_, WorldManager>, mut world_manager: ResMut<'_, WorldManager>,
mut images: ResMut<'_, Assets<Image>>, mut images: ResMut<'_, Assets<Image>>,
mut egui_context: ResMut<'_, EguiContext>, mut egui_context: ResMut<'_, EguiContext>,
#[cfg(feature = "globe_view")] mut materials: ResMut<'_, Assets<StandardMaterial>>,
#[cfg(feature = "globe_view")] mut meshes: ResMut<'_, Assets<Mesh>>,
) { ) {
// Add Julia-Mono font to egui // Add Julia-Mono font to egui
{ {
@ -187,69 +159,6 @@ fn generate_graphics(
}); });
} }
#[cfg(feature = "globe_view")]
{
let world = world_manager.world();
let globe_image_handle = images.add(Image {
data: world_manager.globe_color_bytes(),
texture_descriptor: TextureDescriptor {
label: None,
size: Extent3d {
width: world.width,
height: world.height,
..default()
},
dimension: TextureDimension::D2,
format: TextureFormat::Rgba32Float,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING,
},
..default()
});
world_manager.render_settings.globe_image_handle_id = Some(globe_image_handle.id);
_ = commands.spawn_bundle(Camera3dBundle {
camera: Camera {
is_active: false,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(default(), Vec3::Y),
projection: OrthographicProjection {
scale: 0.01,
..default()
}
.into(),
..default()
});
let globe_material_handle = materials.add(
images
.get_handle(world_manager.render_settings.globe_image_handle_id.unwrap())
.into(),
);
world_manager.render_settings.globe_material_handle_id = Some(globe_material_handle.id);
// TODO: Globe texture is mirrored east-to-west.
_ = commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(UVSphere {
radius: 2.0,
..default()
})),
material: globe_material_handle,
transform: Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)),
..default()
});
_ = commands.spawn_bundle(PointLightBundle {
transform: Transform::from_xyz(-20.0, 0.0, 50.0),
point_light: PointLight {
intensity: 600000.,
range: 100.,
..default()
},
..default()
});
}
} }
#[cfg(feature = "render")] #[cfg(feature = "render")]
@ -317,10 +226,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_system(update_gui.exclusive_system()) .add_system(update_gui.exclusive_system())
.add_system(update_cursor_map_position) .add_system(update_cursor_map_position)
.add_system(open_tile_info); .add_system(open_tile_info);
#[cfg(all(feature = "render", feature = "globe_view"))]
{
_ = app.add_system(rotate_globe);
}
} }
#[cfg(not(feature = "render"))] #[cfg(not(feature = "render"))]
{ {

View file

@ -47,11 +47,6 @@ impl PluginGroup for WorldPlugins {
.add(UiPlugin) .add(UiPlugin)
.add(PanningPlugin) .add(PanningPlugin)
.add(EguiPlugin); .add(EguiPlugin);
#[cfg(feature = "globe_view")]
{
use bevy::pbr::PbrPlugin;
_ = group.add(PbrPlugin)
}
} }
#[cfg(not(feature = "render"))] #[cfg(not(feature = "render"))]
{ {