fixed borrowck issue

This commit is contained in:
Ben Wallis
2021-06-20 22:28:40 +01:00
parent ff57cb93bc
commit 5fc224f109
5 changed files with 17 additions and 14 deletions

View File

@ -43,7 +43,7 @@ use crate::ui::egui::EguiState;
use crate::{
audio::AudioFrontend,
profile::Profile,
render::{Drawer, GlobalsBindGroup, Renderer},
render::{Drawer, GlobalsBindGroup},
settings::Settings,
window::{Event, Window},
};
@ -143,5 +143,5 @@ pub trait PlayState {
fn globals_bind_group(&self) -> &GlobalsBindGroup;
/// Draw the play state.
fn render<'a>(&'a mut self, drawer: &mut Drawer<'a>, settings: &Settings);
fn render<'a>(&'a self, drawer: &mut Drawer<'a>, settings: &Settings);
}

View File

@ -1,7 +1,7 @@
mod ui;
use crate::{
render::{Drawer, GlobalsBindGroup, Renderer},
render::{Drawer, GlobalsBindGroup},
scene::simple::{self as scene, Scene},
session::SessionState,
settings::Settings,
@ -20,7 +20,7 @@ pub struct CharSelectionState {
char_selection_ui: CharSelectionUi,
client: Rc<RefCell<Client>>,
scene: Scene,
need_shadow_clear: bool,
need_shadow_clear: RefCell<bool>,
}
impl CharSelectionState {
@ -37,7 +37,7 @@ impl CharSelectionState {
char_selection_ui,
client,
scene,
need_shadow_clear: false,
need_shadow_clear: RefCell::new(false),
}
}
@ -75,7 +75,7 @@ impl PlayState for CharSelectionState {
.set_scale_mode(global_state.settings.interface.ui_scale);
// Clear shadow textures since we don't render to them here
self.need_shadow_clear = true;
*self.need_shadow_clear.borrow_mut() = true;
}
fn tick(&mut self, global_state: &mut GlobalState, events: Vec<WinEvent>) -> PlayStateResult {
@ -236,10 +236,10 @@ impl PlayState for CharSelectionState {
fn globals_bind_group(&self) -> &GlobalsBindGroup { self.scene.global_bind_group() }
fn render<'a>(&'a mut self, mut drawer: &mut Drawer<'a>, _: &Settings) {
if self.need_shadow_clear {
fn render<'a>(&'a self, drawer: &mut Drawer<'a>, _: &Settings) {
if *self.need_shadow_clear.borrow() {
drawer.clear_shadows();
self.need_shadow_clear = false;
*self.need_shadow_clear.borrow_mut() = false;
}
let client = self.client.borrow();

View File

@ -7,7 +7,7 @@ use super::char_selection::CharSelectionState;
use crate::singleplayer::Singleplayer;
use crate::{
i18n::LocalizationHandle,
render::{Drawer, GlobalsBindGroup, Renderer},
render::{Drawer, GlobalsBindGroup},
settings::Settings,
window::Event,
Direction, GlobalState, PlayState, PlayStateResult,
@ -325,7 +325,7 @@ impl PlayState for MainMenuState {
fn globals_bind_group(&self) -> &GlobalsBindGroup { self.scene.global_bind_group() }
fn render<'a>(&'a mut self, mut drawer: &mut Drawer<'a>, _: &Settings) {
fn render<'a>(&'a self, drawer: &mut Drawer<'a>, _: &Settings) {
// Draw the UI to the screen.
let mut third_pass = drawer.third_pass();
if let Some(mut ui_drawer) = third_pass.draw_ui() {

View File

@ -169,6 +169,10 @@ fn handle_main_events_cleared(
let mut capped_fps = false;
drop(guard);
#[cfg(feature = "egui-ui")]
let scale_factor = global_state.window.window().scale_factor() as f32;
if let Some(last) = states.last_mut() {
capped_fps = last.capped_fps();
@ -185,7 +189,6 @@ fn handle_main_events_cleared(
#[cfg(feature = "egui-ui")]
if global_state.settings.interface.toggle_debug {
let scale_factor = global_state.window.window().scale_factor() as f32;
drawer.draw_egui(&mut global_state.egui_state.platform, scale_factor);
}
};

View File

@ -38,7 +38,7 @@ use crate::{
hud::{Event as HudEvent, Hud, HudInfo, LootMessage, PromptDialogSettings},
key_state::KeyState,
menu::char_selection::CharSelectionState,
render::{Drawer, GlobalsBindGroup, Renderer},
render::{Drawer, GlobalsBindGroup},
scene::{camera, terrain::Interaction, CameraMode, DebugShapeId, Scene, SceneData},
settings::Settings,
window::{AnalogGameInput, Event, GameInput},
@ -1413,7 +1413,7 @@ impl PlayState for SessionState {
/// Render the session to the screen.
///
/// This method should be called once per frame.
fn render<'a>(&'a mut self, mut drawer: &mut Drawer<'a>, settings: &Settings) {
fn render<'a>(&'a self, mut drawer: &mut Drawer<'a>, settings: &Settings) {
span!(_guard, "render", "<Session as PlayState>::render");
// Render world