Skip to content

Commit

Permalink
Merge pull request #30 from Froggy618157725/settings_fixup
Browse files Browse the repository at this point in the history
Settings fixup
  • Loading branch information
Froggy618157725 authored Jul 8, 2024
2 parents 65b66db + f60c22a commit a98af45
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 54 deletions.
2 changes: 0 additions & 2 deletions crates/alkahest-renderer/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ pub struct RendererSettings {
pub stage_decals_additive: bool,

pub debug_view: RenderDebugView,
pub node_nametags: bool,
}

impl Default for RendererSettings {
Expand All @@ -435,7 +434,6 @@ impl Default for RendererSettings {
stage_decals_additive: true,

debug_view: RenderDebugView::None,
node_nametags: false,
}
}
}
Expand Down
27 changes: 12 additions & 15 deletions crates/alkahest/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alkahest_renderer::{
gpu::GpuContext,
gpu_event,
input::InputState,
renderer::{Renderer, RendererSettings, RendererShared},
renderer::{Renderer, RendererShared},
};
use egui::{Key, KeyboardShortcut, Modifiers};
use glam::Vec2;
Expand Down Expand Up @@ -94,7 +94,6 @@ impl AlkahestApp {
resources.insert(CurrentActivity(args.activity));
resources.insert(SelectedEntity::default());
resources.insert(args);
resources.insert(config!().renderer.clone());
resources.insert(MapList::default());
resources.insert(SelectionGizmoMode::default());
resources.insert(HiddenWindows::default());
Expand Down Expand Up @@ -148,19 +147,13 @@ impl AlkahestApp {
}

let mut node_filter_set = NodeFilterSet::default();
for nf in NodeFilter::iter() {
if !matches!(
nf,
NodeFilter::PlayerContainmentVolume
| NodeFilter::SlipSurfaceVolume
| NodeFilter::TurnbackBarrier
| NodeFilter::InstakillBarrier
| NodeFilter::Cubemap
| NodeFilter::NamedArea
) {
node_filter_set.insert(nf);
config::with(|c| {
for nf in NodeFilter::iter() {
if c.visual.node_filters.contains(&nf.to_string()) {
node_filter_set.insert(nf);
}
}
}
});
resources.insert(node_filter_set);

Self {
Expand Down Expand Up @@ -297,6 +290,10 @@ impl AlkahestApp {
size: glam::UVec2::new(new_dims.width, new_dims.height),
origin: glam::UVec2::ZERO,
});

config::with_mut(|c| {
(c.window.width, c.window.height) = (new_dims.width, new_dims.height)
});
}
WindowEvent::RedrawRequested => {
resources.get_mut::<SelectedEntity>().changed_this_frame = false;
Expand Down Expand Up @@ -411,7 +408,7 @@ impl AlkahestApp {
});

window.pre_present_notify();
gctx.present(resources.get::<RendererSettings>().vsync);
gctx.present(config::with(|c| c.renderer.vsync));

window.request_redraw();
profiling::finish_frame!();
Expand Down
43 changes: 36 additions & 7 deletions crates/alkahest/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use alkahest_renderer::renderer::RendererSettings;
use alkahest_renderer::{ecs::tags::NodeFilter, renderer::RendererSettings};
use directories::ProjectDirs;
use egui::ahash::HashSet;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;

use crate::{updater::UpdateChannel, util::RwLock};

Expand Down Expand Up @@ -71,16 +73,43 @@ macro_rules! config {
pub struct Config {
pub window: WindowConfig,
pub renderer: RendererSettings,
// pub render_settings: RenderConfig,
pub visual: VisualSettings,
pub update_channel: Option<UpdateChannel>,
pub packages_directory: Option<String>,
}

// #[derive(Serialize, Deserialize, Default)]
// #[serde(default)]
// pub struct RenderConfig {
// pub draw_crosshair: bool,
// }
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct VisualSettings {
pub draw_crosshair: bool,
pub node_nametags: bool,
pub node_filters: HashSet<String>,
}

impl Default for VisualSettings {
fn default() -> Self {
Self {
draw_crosshair: false,
node_nametags: false,
node_filters: NodeFilter::iter()
.filter_map(|nf| {
if !matches!(
nf,
NodeFilter::PlayerContainmentVolume
| NodeFilter::SlipSurfaceVolume
| NodeFilter::InstakillBarrier
| NodeFilter::Cubemap
| NodeFilter::NamedArea
) {
Some(nf.to_string())
} else {
None
}
})
.collect(),
}
}
}

#[derive(Serialize, Deserialize)]
#[serde(default)]
Expand Down
51 changes: 26 additions & 25 deletions crates/alkahest/src/gui/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use transform_gizmo_egui::{EnumSet, GizmoMode};
use winit::window::Window;

use crate::{
gui::context::{GuiCtx, GuiView, ViewResult},
resources::Resources,
config, gui::context::{GuiCtx, GuiView, ViewResult}, resources::Resources
};

pub struct RenderSettingsPanel;
Expand All @@ -26,12 +25,12 @@ impl GuiView for RenderSettingsPanel {
_gui: &GuiCtx<'_>,
) -> Option<ViewResult> {
egui::Window::new("Settings").show(ctx, |ui| {
config::with_mut(|c|{
ui.heading("Graphics");
let mut settings = resources.get_mut::<RendererSettings>();
ui.checkbox(&mut settings.vsync, "VSync");
ui.checkbox(&mut settings.matcap, "Matcap");
ui.checkbox(&mut settings.shadows, "Shadows");
ui.checkbox(&mut settings.ssao, "SSAO");
ui.checkbox(&mut c.renderer.vsync, "VSync");
ui.checkbox(&mut c.renderer.matcap, "Matcap");
ui.checkbox(&mut c.renderer.shadows, "Shadows");
ui.checkbox(&mut c.renderer.ssao, "SSAO");
ui.collapsing("SSAO Settings", |ui| {
let renderer = resources.get::<RendererShared>();
let ssao_data = renderer.ssao.scope.data();
Expand All @@ -53,8 +52,8 @@ impl GuiView for RenderSettingsPanel {
.ui(ui);
});
});

render_feat_vis(ui, "Node Visualization", &mut settings.node_nametags);
render_feat_vis(ui, "Crosshair", &mut c.visual.draw_crosshair);
render_feat_vis(ui, "Node Visualization", &mut c.visual.node_nametags);
ui.collapsing("Node filters", |ui| {
let mut filters = resources.get_mut::<NodeFilterSet>();
for filter in NodeFilter::iter() {
Expand All @@ -69,19 +68,21 @@ impl GuiView for RenderSettingsPanel {
if ui.checkbox(&mut checked, filter_text).changed() {
if checked {
filters.insert(filter);
c.visual.node_filters.insert(filter.to_string());
} else {
filters.remove(&filter);
c.visual.node_filters.remove(&filter.to_string());
}
}
}
});

egui::ComboBox::from_label("Debug View")
.selected_text(settings.debug_view.to_string().split_pascalcase())
.selected_text(c.renderer.debug_view.to_string().split_pascalcase())
.show_ui(ui, |ui| {
for view in RenderDebugView::iter() {
ui.selectable_value(
&mut settings.debug_view,
&mut c.renderer.debug_view,
view,
view.to_string().split_pascalcase(),
);
Expand All @@ -90,25 +91,25 @@ impl GuiView for RenderSettingsPanel {

ui.separator();
ui.heading("Feature Renderers");
render_feat_vis_select(ui, "Statics", &mut settings.feature_statics);
render_feat_vis_select(ui, "Terrain", &mut settings.feature_terrain);
render_feat_vis_select(ui, "Dynamics", &mut settings.feature_dynamics);
render_feat_vis_select(ui, "Sky Objects", &mut settings.feature_sky);
render_feat_vis_select(ui, "Water", &mut settings.feature_water);
render_feat_vis_select(ui, "Trees/Decorators", &mut settings.feature_decorators);
render_feat_vis(ui, "Atmosphere", &mut settings.feature_atmosphere);
render_feat_vis(ui, "Cubemaps", &mut settings.feature_cubemaps);
render_feat_vis(ui, "Global Lighting", &mut settings.feature_global_lighting);
render_feat_vis_select(ui, "Statics", &mut c.renderer.feature_statics);
render_feat_vis_select(ui, "Terrain", &mut c.renderer.feature_terrain);
render_feat_vis_select(ui, "Dynamics", &mut c.renderer.feature_dynamics);
render_feat_vis_select(ui, "Sky Objects", &mut c.renderer.feature_sky);
render_feat_vis_select(ui, "Water", &mut c.renderer.feature_water);
render_feat_vis_select(ui, "Trees/Decorators", &mut c.renderer.feature_decorators);
render_feat_vis(ui, "Atmosphere", &mut c.renderer.feature_atmosphere);
render_feat_vis(ui, "Cubemaps", &mut c.renderer.feature_cubemaps);
render_feat_vis(ui, "Global Lighting", &mut c.renderer.feature_global_lighting);

ui.separator();
ui.heading("Render Stages");
ui.checkbox(&mut settings.stage_transparent, "Transparents");
ui.checkbox(&mut settings.stage_decals, "Decals");
ui.checkbox(&mut settings.stage_decals_additive, "Decals (additive)");
ui.checkbox(&mut c.renderer.stage_transparent, "Transparents");
ui.checkbox(&mut c.renderer.stage_decals, "Decals");
ui.checkbox(&mut c.renderer.stage_decals_additive, "Decals (additive)");

resources
.get::<RendererShared>()
.set_render_settings(settings.clone());
.set_render_settings(c.renderer.clone());

ui.separator();

Expand Down Expand Up @@ -148,7 +149,7 @@ impl GuiView for RenderSettingsPanel {
.ui(ui);
ui.label("Smooth look");
});
});
})});

None
}
Expand Down
2 changes: 2 additions & 0 deletions crates/alkahest/src/gui/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
inspector::InspectorPanel,
menu::MenuBar,
node_gizmos::NodeGizmoOverlay,
crosshair::CrosshairOverlay,
outliner::OutlinerPanel,
profiler::PuffinProfiler,
tfx::{TfxErrorViewer, TfxExternEditor},
Expand Down Expand Up @@ -203,6 +204,7 @@ impl GuiViewManager {
views.insert(ConsolePanel::default());
views.insert(PuffinProfiler);
views.insert(NodeGizmoOverlay);
views.insert(CrosshairOverlay);

views.insert_overlay(FpsDisplayOverlay::default());

Expand Down
42 changes: 42 additions & 0 deletions crates/alkahest/src/gui/crosshair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use alkahest_renderer::{resources::Resources};
use egui::{Color32, Context, Stroke};
use winit::window::Window;

use crate::{
config, gui::context::{GuiCtx, GuiView, ViewResult}, maplist::{MapList, MapLoadState}
};

pub struct CrosshairOverlay;

impl GuiView for CrosshairOverlay {
fn draw(
&mut self,
ctx: &Context,
_window: &Window,
resources: &Resources,
_gui: &GuiCtx<'_>,
) -> Option<ViewResult> {
let maps = resources.get::<MapList>();
if maps.current_map().map_or(true, |m|m.load_state != MapLoadState::Loaded) {
return None
}
if config::with(|c|!c.visual.draw_crosshair) {
return None;
}

let painter = ctx.layer_painter(egui::LayerId::background());


let center = ctx.screen_rect().center();
let width = 2.0;
let size = 8.0;
let stroke = Stroke {
width,
color: Color32::WHITE,
};

painter.line_segment([center + (size, 0.0).into(), center + (-size, 0.0).into()], stroke);
painter.line_segment([center + (0.0, size).into(), center + (0.0, -size).into()], stroke);
None
}
}
1 change: 1 addition & 0 deletions crates/alkahest/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod console;
pub mod gizmo;
mod menu;
mod node_gizmos;
mod crosshair;
mod outliner;
mod profiler;
pub(crate) mod updater;
Expand Down
7 changes: 2 additions & 5 deletions crates/alkahest/src/gui/node_gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use alkahest_renderer::{
transform::Transform,
},
icons::ICON_HELP,
renderer::RendererShared,
resources::Resources,
ColorExt,
};
Expand All @@ -16,8 +15,7 @@ use glam::Vec2;
use winit::window::Window;

use crate::{
gui::context::{GuiCtx, GuiView, ViewResult},
maplist::MapList,
config, gui::context::{GuiCtx, GuiView, ViewResult}, maplist::MapList
};

pub struct NodeGizmoOverlay;
Expand All @@ -30,8 +28,7 @@ impl GuiView for NodeGizmoOverlay {
resources: &Resources,
gui: &GuiCtx<'_>,
) -> Option<ViewResult> {
let renderer = resources.get::<RendererShared>();
if !renderer.render_settings.node_nametags {
if config::with(|c| !c.visual.node_nametags) {
return None;
}

Expand Down

0 comments on commit a98af45

Please sign in to comment.