Skip to content

Commit

Permalink
Merge pull request #133 from Davidster/prepare_cull_optimization_todo
Browse files Browse the repository at this point in the history
Prepare cull optimization todo
  • Loading branch information
Davidster authored Feb 18, 2024
2 parents 4ea8d2b + e76a8b1 commit 44f7ce9
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 392 deletions.
6 changes: 4 additions & 2 deletions example_game/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use winit::keyboard::NamedKey;
// graphics settings
pub const INITIAL_ENABLE_VSYNC: bool = true;
pub const INITIAL_ENABLE_DEPTH_PREPASS: bool = false;
pub const INITIAL_ENABLE_SHADOWS: bool = true;
pub const INITIAL_ENABLE_DIRECTIONAL_SHADOW_CULLING: bool = true;
pub const INITIAL_RENDER_SCALE: f32 = 1.0;
pub const INITIAL_TONE_MAPPING_EXPOSURE: f32 = 1.0;
Expand Down Expand Up @@ -256,10 +257,10 @@ async fn get_rainbow_texture(renderer_base: &BaseRenderer) -> Result<Texture> {
)
}

pub async fn init_game_state<'a>(
pub async fn init_game_state(
engine_state: &mut EngineState,
renderer: &mut Renderer,
surface_data: &mut SurfaceData<'a>,
surface_data: &mut SurfaceData,
window: &winit::window::Window,
) -> Result<GameState> {
log::info!("Controls:");
Expand All @@ -285,6 +286,7 @@ pub async fn init_game_state<'a>(

{
let mut renderer_data_guard = renderer.data.lock().unwrap();
renderer_data_guard.enable_shadows = INITIAL_ENABLE_SHADOWS;
renderer_data_guard.enable_bloom = INITIAL_ENABLE_BLOOM;
renderer_data_guard.bloom_threshold = INITIAL_BLOOM_THRESHOLD;
renderer_data_guard.bloom_ramp_size = INITIAL_BLOOM_RAMP_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion ikari/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<T: bytemuck::Pod, ID> ChunkedBuffer<T, ID> {
/// Only supports replace() for now, could maybe create an add_all function if we keep track of the biggest chunk length and fix the padding
/// at the end of the buffer
#[profiling::function]
pub fn replace(&mut self, chunks: impl Iterator<Item = (ID, Vec<T>)>, alignment: usize) {
pub fn replace(&mut self, chunks: impl Iterator<Item = (ID, Box<[T]>)>, alignment: usize) {
self.clear();

let stride = std::mem::size_of::<T>();
Expand Down
10 changes: 10 additions & 0 deletions ikari/src/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub struct Sphere {
pub radius: f32,
}

impl Default for Sphere {
fn default() -> Self {
Self {
center: Default::default(),
radius: 1.0,
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IntersectionResult {
FullyContained,
Expand Down Expand Up @@ -360,6 +369,7 @@ impl From<CameraFrustumDescriptor> for Frustum {
}

impl CameraFrustumDescriptor {
// TODO: this function is slow due to the calls to to_convex_polyhedron. should cache the convex polyhedra.
pub fn frustum_intersection_test(&self, other: &CameraFrustumDescriptor) -> bool {
rapier3d_f64::parry::query::intersection_test(
&rapier3d_f64::na::Isometry::identity(),
Expand Down
8 changes: 6 additions & 2 deletions ikari/src/gameloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct GameContext<'a, GameState> {
pub game_state: &'a mut GameState,
pub engine_state: &'a mut EngineState,
pub renderer: &'a mut Renderer,
pub surface_data: &'a mut SurfaceData<'static>,
pub surface_data: &'a mut SurfaceData,
pub window: &'a winit::window::Window,
pub elwt: &'a winit::event_loop::EventLoopWindowTarget<()>,
}
Expand All @@ -44,7 +44,7 @@ pub fn run<
mut game_state: GameStateType,
mut engine_state: EngineState,
mut renderer: Renderer,
mut surface_data: SurfaceData<'static>,
mut surface_data: SurfaceData,
mut on_update: OnUpdateFunction,
mut on_window_event: OnWindowEventFunction,
mut on_device_event: OnDeviceEventFunction,
Expand Down Expand Up @@ -77,6 +77,10 @@ pub fn run<

event_loop
.run(move |event, elwt| {
if elwt.exiting() {
return;
}

match event {
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
Expand Down
Loading

0 comments on commit 44f7ce9

Please sign in to comment.