2019-01-11 23:18:34 +00:00
|
|
|
pub mod camera;
|
2019-01-13 20:53:55 +00:00
|
|
|
pub mod figure;
|
2020-02-29 03:59:11 +00:00
|
|
|
pub mod simple;
|
2019-09-06 10:38:02 +00:00
|
|
|
pub mod terrain;
|
2019-01-11 23:18:34 +00:00
|
|
|
|
2019-07-24 14:27:13 +00:00
|
|
|
use self::{
|
|
|
|
camera::{Camera, CameraMode},
|
|
|
|
figure::FigureMgr,
|
2019-09-06 10:38:02 +00:00
|
|
|
terrain::Terrain,
|
2019-07-24 14:27:13 +00:00
|
|
|
};
|
2019-01-12 13:56:34 +00:00
|
|
|
use crate::{
|
2020-01-26 00:22:48 +00:00
|
|
|
anim::character::SkeletonAttr,
|
2020-02-29 03:59:11 +00:00
|
|
|
audio::{music::MusicMgr, sfx::SfxMgr, AudioFrontend},
|
2019-01-12 13:56:34 +00:00
|
|
|
render::{
|
2019-07-21 15:04:36 +00:00
|
|
|
create_pp_mesh, create_skybox_mesh, Consts, Globals, Light, Model, PostProcessLocals,
|
2019-09-25 12:00:00 +00:00
|
|
|
PostProcessPipeline, Renderer, Shadow, SkyboxLocals, SkyboxPipeline,
|
2019-01-12 13:56:34 +00:00
|
|
|
},
|
|
|
|
window::Event,
|
2019-01-13 20:53:55 +00:00
|
|
|
};
|
2019-09-03 22:57:25 +00:00
|
|
|
use common::{
|
|
|
|
comp,
|
2020-02-29 03:59:11 +00:00
|
|
|
state::State,
|
2019-09-03 22:57:25 +00:00
|
|
|
terrain::{BlockKind, TerrainChunk},
|
|
|
|
vol::ReadVol,
|
|
|
|
};
|
2020-02-29 03:59:11 +00:00
|
|
|
use specs::{Entity as EcsEntity, Join, WorldExt};
|
2019-05-12 19:57:39 +00:00
|
|
|
use vek::*;
|
2019-01-13 20:53:55 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Don't hard-code this.
|
2019-01-13 20:53:55 +00:00
|
|
|
const CURSOR_PAN_SCALE: f32 = 0.005;
|
2019-01-11 23:18:34 +00:00
|
|
|
|
2019-07-21 15:37:41 +00:00
|
|
|
const MAX_LIGHT_COUNT: usize = 32;
|
2019-09-25 12:00:00 +00:00
|
|
|
const MAX_SHADOW_COUNT: usize = 24;
|
|
|
|
const LIGHT_DIST_RADIUS: f32 = 64.0; // The distance beyond which lights may not emit light from their origin
|
|
|
|
const SHADOW_DIST_RADIUS: f32 = 8.0;
|
|
|
|
const SHADOW_MAX_DIST: f32 = 96.0; // The distance beyond which shadows may not be visible
|
2019-07-21 15:04:36 +00:00
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
struct Skybox {
|
|
|
|
model: Model<SkyboxPipeline>,
|
|
|
|
locals: Consts<SkyboxLocals>,
|
|
|
|
}
|
|
|
|
|
2019-05-06 08:22:47 +00:00
|
|
|
struct PostProcess {
|
|
|
|
model: Model<PostProcessPipeline>,
|
|
|
|
locals: Consts<PostProcessLocals>,
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
pub struct Scene {
|
|
|
|
globals: Consts<Globals>,
|
2019-07-21 15:04:36 +00:00
|
|
|
lights: Consts<Light>,
|
2019-09-25 12:00:00 +00:00
|
|
|
shadows: Consts<Shadow>,
|
2019-01-15 15:13:11 +00:00
|
|
|
camera: Camera,
|
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
skybox: Skybox,
|
2019-05-06 08:22:47 +00:00
|
|
|
postprocess: PostProcess,
|
2019-09-03 22:57:25 +00:00
|
|
|
terrain: Terrain<TerrainChunk>,
|
2019-06-05 16:32:33 +00:00
|
|
|
loaded_distance: f32,
|
2019-09-26 10:43:03 +00:00
|
|
|
select_pos: Option<Vec3<i32>>,
|
2019-04-19 07:35:23 +00:00
|
|
|
|
2019-05-12 13:02:47 +00:00
|
|
|
figure_mgr: FigureMgr,
|
2019-11-23 08:26:39 +00:00
|
|
|
sfx_mgr: SfxMgr,
|
2020-02-03 11:55:32 +00:00
|
|
|
music_mgr: MusicMgr,
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 03:59:11 +00:00
|
|
|
pub struct SceneData<'a> {
|
|
|
|
pub state: &'a State,
|
|
|
|
pub player_entity: specs::Entity,
|
|
|
|
pub loaded_distance: f32,
|
|
|
|
pub view_distance: u32,
|
|
|
|
pub tick: u64,
|
|
|
|
pub thread_pool: &'a uvth::ThreadPool,
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
impl Scene {
|
|
|
|
/// Create a new `Scene` with default parameters.
|
2019-07-04 12:02:26 +00:00
|
|
|
pub fn new(renderer: &mut Renderer) -> Self {
|
2019-04-14 15:05:51 +00:00
|
|
|
let resolution = renderer.get_resolution().map(|e| e as f32);
|
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
Self {
|
2019-04-29 20:37:19 +00:00
|
|
|
globals: renderer.create_consts(&[Globals::default()]).unwrap(),
|
2019-09-25 12:00:00 +00:00
|
|
|
lights: renderer
|
|
|
|
.create_consts(&[Light::default(); MAX_LIGHT_COUNT])
|
|
|
|
.unwrap(),
|
|
|
|
shadows: renderer
|
|
|
|
.create_consts(&[Shadow::default(); MAX_SHADOW_COUNT])
|
|
|
|
.unwrap(),
|
2019-07-22 19:11:00 +00:00
|
|
|
camera: Camera::new(resolution.x / resolution.y, CameraMode::ThirdPerson),
|
2019-01-15 15:13:11 +00:00
|
|
|
|
2019-01-11 23:18:34 +00:00
|
|
|
skybox: Skybox {
|
2019-04-29 20:37:19 +00:00
|
|
|
model: renderer.create_model(&create_skybox_mesh()).unwrap(),
|
|
|
|
locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(),
|
2019-01-11 23:18:34 +00:00
|
|
|
},
|
2019-05-06 08:22:47 +00:00
|
|
|
postprocess: PostProcess {
|
|
|
|
model: renderer.create_model(&create_pp_mesh()).unwrap(),
|
|
|
|
locals: renderer
|
|
|
|
.create_consts(&[PostProcessLocals::default()])
|
|
|
|
.unwrap(),
|
|
|
|
},
|
2019-08-19 20:09:35 +00:00
|
|
|
terrain: Terrain::new(renderer),
|
2019-06-05 16:32:33 +00:00
|
|
|
loaded_distance: 0.0,
|
2019-09-26 10:43:03 +00:00
|
|
|
select_pos: None,
|
|
|
|
|
2019-05-12 13:02:47 +00:00
|
|
|
figure_mgr: FigureMgr::new(),
|
2019-11-23 08:26:39 +00:00
|
|
|
sfx_mgr: SfxMgr::new(),
|
2020-02-03 11:55:32 +00:00
|
|
|
music_mgr: MusicMgr::new(),
|
2019-01-11 23:18:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:13:33 +00:00
|
|
|
/// Get a reference to the scene's globals.
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn globals(&self) -> &Consts<Globals> { &self.globals }
|
2019-05-14 06:43:07 +00:00
|
|
|
|
2019-01-23 22:39:31 +00:00
|
|
|
/// Get a reference to the scene's camera.
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn camera(&self) -> &Camera { &self.camera }
|
2019-01-23 22:39:31 +00:00
|
|
|
|
2019-11-19 15:13:33 +00:00
|
|
|
/// Get a reference to the scene's terrain.
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn terrain(&self) -> &Terrain<TerrainChunk> { &self.terrain }
|
2019-11-19 15:13:33 +00:00
|
|
|
|
|
|
|
/// Get a reference to the scene's figure manager.
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn figure_mgr(&self) -> &FigureMgr { &self.figure_mgr }
|
2019-11-19 15:13:33 +00:00
|
|
|
|
2019-01-23 22:39:31 +00:00
|
|
|
/// Get a mutable reference to the scene's camera.
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn camera_mut(&mut self) -> &mut Camera { &mut self.camera }
|
2019-01-23 22:39:31 +00:00
|
|
|
|
2019-09-26 10:43:03 +00:00
|
|
|
/// Set the block position that the player is interacting with
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn set_select_pos(&mut self, pos: Option<Vec3<i32>>) { self.select_pos = pos; }
|
2019-09-26 10:43:03 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Handle an incoming user input event (e.g.: cursor moved, key pressed,
|
|
|
|
/// window closed).
|
2019-01-30 12:11:34 +00:00
|
|
|
///
|
2019-05-17 09:22:32 +00:00
|
|
|
/// If the event is handled, return true.
|
2019-01-12 13:56:34 +00:00
|
|
|
pub fn handle_input_event(&mut self, event: Event) -> bool {
|
|
|
|
match event {
|
2019-01-30 12:11:34 +00:00
|
|
|
// When the window is resized, change the camera's aspect ratio
|
|
|
|
Event::Resize(dims) => {
|
|
|
|
self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32);
|
|
|
|
true
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-01-12 13:56:34 +00:00
|
|
|
// Panning the cursor makes the camera rotate
|
|
|
|
Event::CursorPan(delta) => {
|
|
|
|
self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE);
|
|
|
|
true
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-01-30 12:11:34 +00:00
|
|
|
// Zoom the camera when a zoom event occurs
|
|
|
|
Event::Zoom(delta) => {
|
2019-10-09 19:28:05 +00:00
|
|
|
self.camera
|
|
|
|
.zoom_switch(delta * (0.05 + self.camera.get_distance() * 0.01));
|
2019-01-30 12:11:34 +00:00
|
|
|
true
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-01-12 13:56:34 +00:00
|
|
|
// All other events are unhandled
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Maintain data such as GPU constant buffers, models, etc. To be called
|
|
|
|
/// once per tick.
|
2019-09-06 10:38:02 +00:00
|
|
|
pub fn maintain(
|
|
|
|
&mut self,
|
|
|
|
renderer: &mut Renderer,
|
|
|
|
audio: &mut AudioFrontend,
|
2020-02-29 03:59:11 +00:00
|
|
|
scene_data: &SceneData,
|
2020-02-13 12:28:03 +00:00
|
|
|
gamma: f32,
|
2019-09-06 10:38:02 +00:00
|
|
|
) {
|
2019-05-17 09:22:32 +00:00
|
|
|
// Get player position.
|
2020-02-29 03:59:11 +00:00
|
|
|
let player_pos = scene_data
|
|
|
|
.state
|
2019-04-14 20:30:27 +00:00
|
|
|
.ecs()
|
2019-06-14 15:27:05 +00:00
|
|
|
.read_storage::<comp::Pos>()
|
2020-02-29 03:59:11 +00:00
|
|
|
.get(scene_data.player_entity)
|
2019-05-27 17:01:00 +00:00
|
|
|
.map_or(Vec3::zero(), |pos| pos.0);
|
2019-03-05 18:39:18 +00:00
|
|
|
|
2020-02-29 03:59:11 +00:00
|
|
|
let player_rolling = scene_data
|
|
|
|
.state
|
2019-09-06 11:29:52 +00:00
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::CharacterState>()
|
2020-02-29 03:59:11 +00:00
|
|
|
.get(scene_data.player_entity)
|
2019-12-03 06:30:08 +00:00
|
|
|
.map_or(false, |cs| cs.action.is_roll());
|
2019-09-06 11:29:52 +00:00
|
|
|
|
2020-02-29 03:59:11 +00:00
|
|
|
let player_scale = match scene_data
|
|
|
|
.state
|
2019-12-01 19:05:28 +00:00
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Body>()
|
2020-02-29 03:59:11 +00:00
|
|
|
.get(scene_data.player_entity)
|
2019-12-01 19:05:28 +00:00
|
|
|
{
|
|
|
|
Some(comp::Body::Humanoid(body)) => SkeletonAttr::calculate_scale(body),
|
|
|
|
_ => 1_f32,
|
|
|
|
};
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Alter camera position to match player.
|
2019-06-10 10:50:48 +00:00
|
|
|
let tilt = self.camera.get_orientation().y;
|
|
|
|
let dist = self.camera.get_distance();
|
2019-09-06 11:29:52 +00:00
|
|
|
|
|
|
|
let up = match self.camera.get_mode() {
|
|
|
|
CameraMode::FirstPerson => {
|
|
|
|
if player_rolling {
|
2019-12-01 19:05:28 +00:00
|
|
|
player_scale * 0.8_f32
|
2019-09-06 11:29:52 +00:00
|
|
|
} else {
|
2019-12-01 19:05:28 +00:00
|
|
|
player_scale * 1.6_f32
|
2019-09-06 11:29:52 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-09-06 11:29:52 +00:00
|
|
|
CameraMode::ThirdPerson => 1.2,
|
2019-08-06 15:00:14 +00:00
|
|
|
};
|
2019-09-06 11:29:52 +00:00
|
|
|
|
2019-07-21 12:42:45 +00:00
|
|
|
self.camera.set_focus_pos(
|
2019-08-06 15:00:14 +00:00
|
|
|
player_pos + Vec3::unit_z() * (up + dist * 0.15 - tilt.min(0.0) * dist * 0.75),
|
2019-07-21 12:42:45 +00:00
|
|
|
);
|
2019-05-05 15:17:57 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Tick camera for interpolation.
|
2020-02-29 03:59:11 +00:00
|
|
|
self.camera.update(scene_data.state.get_time());
|
2019-03-05 00:00:11 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Compute camera matrices.
|
2020-02-29 03:59:11 +00:00
|
|
|
self.camera.compute_dependents(&*scene_data.state.terrain());
|
|
|
|
let camera::Dependents {
|
|
|
|
view_mat,
|
|
|
|
proj_mat,
|
|
|
|
cam_pos,
|
|
|
|
} = self.camera.dependents();
|
2019-01-12 01:14:58 +00:00
|
|
|
|
2019-06-05 16:32:33 +00:00
|
|
|
// Update chunk loaded distance smoothly for nice shader fog
|
2020-02-29 03:59:11 +00:00
|
|
|
self.loaded_distance =
|
|
|
|
(0.98 * self.loaded_distance + 0.02 * scene_data.loaded_distance).max(0.01);
|
2019-06-05 16:32:33 +00:00
|
|
|
|
2019-07-21 15:04:36 +00:00
|
|
|
// Update light constants
|
2019-07-21 16:50:13 +00:00
|
|
|
let mut lights = (
|
2020-02-29 03:59:11 +00:00
|
|
|
&scene_data.state.ecs().read_storage::<comp::Pos>(),
|
|
|
|
scene_data.state.ecs().read_storage::<comp::Ori>().maybe(),
|
|
|
|
scene_data
|
|
|
|
.state
|
2020-01-10 00:33:38 +00:00
|
|
|
.ecs()
|
|
|
|
.read_storage::<crate::ecs::comp::Interpolated>()
|
|
|
|
.maybe(),
|
2020-02-29 03:59:11 +00:00
|
|
|
&scene_data.state.ecs().read_storage::<comp::LightEmitter>(),
|
2019-07-21 16:50:13 +00:00
|
|
|
)
|
2019-07-21 15:04:36 +00:00
|
|
|
.join()
|
2020-01-10 00:33:38 +00:00
|
|
|
.filter(|(pos, _, _, _)| {
|
2019-07-21 15:04:36 +00:00
|
|
|
(pos.0.distance_squared(player_pos) as f32)
|
|
|
|
< self.loaded_distance.powf(2.0) + LIGHT_DIST_RADIUS
|
|
|
|
})
|
2020-01-10 00:33:38 +00:00
|
|
|
.map(|(pos, ori, interpolated, light_emitter)| {
|
|
|
|
// Use interpolated values if they are available
|
|
|
|
let (pos, ori) =
|
|
|
|
interpolated.map_or((pos.0, ori.map(|o| o.0)), |i| (i.pos, Some(i.ori)));
|
2019-07-25 20:51:20 +00:00
|
|
|
let rot = {
|
|
|
|
if let Some(o) = ori {
|
2020-01-10 00:33:38 +00:00
|
|
|
Mat3::rotation_z(-o.x.atan2(o.y))
|
2019-07-25 20:51:20 +00:00
|
|
|
} else {
|
|
|
|
Mat3::identity()
|
|
|
|
}
|
|
|
|
};
|
2019-07-21 16:50:13 +00:00
|
|
|
Light::new(
|
2020-01-10 00:33:38 +00:00
|
|
|
pos + (rot * light_emitter.offset),
|
2019-07-21 16:50:13 +00:00
|
|
|
light_emitter.col,
|
|
|
|
light_emitter.strength,
|
|
|
|
)
|
2019-07-25 20:51:20 +00:00
|
|
|
})
|
2019-07-21 15:04:36 +00:00
|
|
|
.collect::<Vec<_>>();
|
2019-09-25 12:00:00 +00:00
|
|
|
lights.sort_by_key(|light| light.get_pos().distance_squared(player_pos) as i32);
|
2019-07-21 15:37:41 +00:00
|
|
|
lights.truncate(MAX_LIGHT_COUNT);
|
2019-07-21 15:04:36 +00:00
|
|
|
renderer
|
|
|
|
.update_consts(&mut self.lights, &lights)
|
|
|
|
.expect("Failed to update light constants");
|
|
|
|
|
2019-09-25 12:00:00 +00:00
|
|
|
// Update shadow constants
|
|
|
|
let mut shadows = (
|
2020-02-29 03:59:11 +00:00
|
|
|
&scene_data.state.ecs().read_storage::<comp::Pos>(),
|
|
|
|
scene_data
|
|
|
|
.state
|
2020-01-10 00:33:38 +00:00
|
|
|
.ecs()
|
|
|
|
.read_storage::<crate::ecs::comp::Interpolated>()
|
|
|
|
.maybe(),
|
2020-02-29 03:59:11 +00:00
|
|
|
scene_data.state.ecs().read_storage::<comp::Scale>().maybe(),
|
|
|
|
&scene_data.state.ecs().read_storage::<comp::Body>(),
|
|
|
|
&scene_data.state.ecs().read_storage::<comp::Stats>(),
|
2019-09-25 12:00:00 +00:00
|
|
|
)
|
|
|
|
.join()
|
2020-01-10 00:33:38 +00:00
|
|
|
.filter(|(_, _, _, _, stats)| !stats.is_dead)
|
|
|
|
.filter(|(pos, _, _, _, _)| {
|
2019-09-25 12:00:00 +00:00
|
|
|
(pos.0.distance_squared(player_pos) as f32)
|
2019-09-25 13:38:58 +00:00
|
|
|
< (self.loaded_distance.min(SHADOW_MAX_DIST) + SHADOW_DIST_RADIUS).powf(2.0)
|
2019-09-25 12:00:00 +00:00
|
|
|
})
|
2020-01-10 00:33:38 +00:00
|
|
|
.map(|(pos, interpolated, scale, _, _)| {
|
|
|
|
Shadow::new(
|
|
|
|
// Use interpolated values pos if it is available
|
|
|
|
interpolated.map_or(pos.0, |i| i.pos),
|
|
|
|
scale.map_or(1.0, |s| s.0),
|
|
|
|
)
|
|
|
|
})
|
2019-09-25 12:00:00 +00:00
|
|
|
.collect::<Vec<_>>();
|
|
|
|
shadows.sort_by_key(|shadow| shadow.get_pos().distance_squared(player_pos) as i32);
|
|
|
|
shadows.truncate(MAX_SHADOW_COUNT);
|
|
|
|
renderer
|
|
|
|
.update_consts(&mut self.shadows, &shadows)
|
|
|
|
.expect("Failed to update light constants");
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Update global constants.
|
2019-04-29 20:37:19 +00:00
|
|
|
renderer
|
2020-02-01 20:39:39 +00:00
|
|
|
.update_consts(&mut self.globals, &[Globals::new(
|
|
|
|
view_mat,
|
|
|
|
proj_mat,
|
|
|
|
cam_pos,
|
|
|
|
self.camera.get_focus_pos(),
|
|
|
|
self.loaded_distance,
|
2020-02-29 03:59:11 +00:00
|
|
|
scene_data.state.get_time_of_day(),
|
|
|
|
scene_data.state.get_time(),
|
2020-02-01 20:39:39 +00:00
|
|
|
renderer.get_resolution(),
|
|
|
|
lights.len(),
|
|
|
|
shadows.len(),
|
2020-02-29 03:59:11 +00:00
|
|
|
scene_data
|
|
|
|
.state
|
2020-02-01 20:39:39 +00:00
|
|
|
.terrain()
|
|
|
|
.get(cam_pos.map(|e| e.floor() as i32))
|
|
|
|
.map(|b| b.kind())
|
|
|
|
.unwrap_or(BlockKind::Air),
|
|
|
|
self.select_pos,
|
2020-02-13 12:28:03 +00:00
|
|
|
gamma,
|
2020-02-01 20:39:39 +00:00
|
|
|
)])
|
2019-01-12 01:14:58 +00:00
|
|
|
.expect("Failed to update global constants");
|
2019-01-13 20:53:55 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Maintain the terrain.
|
2019-06-06 09:04:37 +00:00
|
|
|
self.terrain.maintain(
|
|
|
|
renderer,
|
2020-02-29 03:59:11 +00:00
|
|
|
&scene_data,
|
2019-06-06 09:04:37 +00:00
|
|
|
self.camera.get_focus_pos(),
|
|
|
|
self.loaded_distance,
|
|
|
|
view_mat,
|
|
|
|
proj_mat,
|
|
|
|
);
|
2019-04-19 07:35:23 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Maintain the figures.
|
2020-02-29 03:59:11 +00:00
|
|
|
self.figure_mgr.maintain(renderer, scene_data, &self.camera);
|
2019-04-23 11:55:48 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Remove unused figures.
|
2020-02-29 03:59:11 +00:00
|
|
|
self.figure_mgr.clean(scene_data.tick);
|
2019-09-01 01:32:39 +00:00
|
|
|
|
2020-02-03 11:55:32 +00:00
|
|
|
// Maintain audio
|
2020-02-29 03:59:11 +00:00
|
|
|
self.sfx_mgr
|
|
|
|
.maintain(audio, scene_data.state, scene_data.player_entity);
|
|
|
|
self.music_mgr.maintain(audio, scene_data.state);
|
2019-01-12 01:14:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Render the scene using the provided `Renderer`.
|
2020-02-29 03:59:11 +00:00
|
|
|
pub fn render(
|
|
|
|
&mut self,
|
|
|
|
renderer: &mut Renderer,
|
|
|
|
state: &State,
|
|
|
|
player_entity: EcsEntity,
|
|
|
|
tick: u64,
|
|
|
|
) {
|
2019-05-17 09:22:32 +00:00
|
|
|
// Render terrain and figures.
|
2019-09-25 12:00:00 +00:00
|
|
|
self.figure_mgr.render(
|
|
|
|
renderer,
|
2020-02-29 03:59:11 +00:00
|
|
|
state,
|
|
|
|
player_entity,
|
|
|
|
tick,
|
2019-09-25 12:00:00 +00:00
|
|
|
&self.globals,
|
|
|
|
&self.lights,
|
|
|
|
&self.shadows,
|
|
|
|
&self.camera,
|
|
|
|
);
|
2019-08-19 21:54:16 +00:00
|
|
|
self.terrain.render(
|
|
|
|
renderer,
|
|
|
|
&self.globals,
|
|
|
|
&self.lights,
|
2019-09-25 12:00:00 +00:00
|
|
|
&self.shadows,
|
2019-08-19 21:54:16 +00:00
|
|
|
self.camera.get_focus_pos(),
|
|
|
|
);
|
2019-05-06 08:22:47 +00:00
|
|
|
|
2019-11-19 09:17:39 +00:00
|
|
|
// Render the skybox.
|
|
|
|
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
|
|
|
|
|
|
|
|
self.terrain.render_translucent(
|
|
|
|
renderer,
|
|
|
|
&self.globals,
|
|
|
|
&self.lights,
|
|
|
|
&self.shadows,
|
|
|
|
self.camera.get_focus_pos(),
|
|
|
|
);
|
|
|
|
|
2019-05-06 08:22:47 +00:00
|
|
|
renderer.render_post_process(
|
|
|
|
&self.postprocess.model,
|
|
|
|
&self.globals,
|
|
|
|
&self.postprocess.locals,
|
|
|
|
);
|
2019-01-11 23:18:34 +00:00
|
|
|
}
|
|
|
|
}
|