summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/mod.rs36
-rw-r--r--src/renderer/ui.rs19
2 files changed, 33 insertions, 22 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 233d66b..403eeb2 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -12,9 +12,10 @@ use crate::{
renderer::ui::draw_egui,
sim::{
cell::materials::MaterialId,
- cell_sim::world::World,
- particle_sim::ParticleManager,
- rb_sim::{RbSimManager, debug_render::DebugVertex, rb_entity::RbEntity},
+ cell_manager::manager::CellManager,
+ particle_manager::ParticleManager,
+ rb_manager::{RbManager, debug_render::DebugVertex, rb_entity::RbEntity},
+ sim_manager::SimManager,
},
};
@@ -573,9 +574,7 @@ impl RendererState {
pub fn render(
&mut self,
- world: &mut World,
- rb_sim_manager: &mut RbSimManager,
- particle_manager: &mut ParticleManager,
+ sim: &mut SimManager,
camera: &mut Camera,
config: &mut Config,
diagnostics: &Diagnostics,
@@ -627,7 +626,7 @@ impl RendererState {
.resizable(false)
// TODO collapse button
.show_collapsible(ui, &mut true, |panel_ui| {
- draw_egui(panel_ui, config, camera, diagnostics, input, world)
+ draw_egui(panel_ui, config, camera, diagnostics, input, sim)
});
});
@@ -671,8 +670,8 @@ impl RendererState {
{
puffin::profile_scope!("Upload chunk cells");
- for &idx in world.chunk_position_to_chunk_idx.values() {
- let chunk = &mut world.chunks[idx];
+ for &idx in sim.cell_manager.chunk_position_to_chunk_idx.values() {
+ let chunk = &mut sim.cell_manager.chunks[idx];
if !chunk.needs_texture_update {
continue;
}
@@ -694,7 +693,7 @@ impl RendererState {
puffin::profile_scope!("Upload entity cells");
// TODO optimize, this is very inefficient, just build it per frame with positions and skip the lookup?
self.renderer_rb_entities.drain();
- for entity in rb_sim_manager.rb_entities.values() {
+ for entity in sim.rb_manager.rb_entities.values() {
// TODO add "needs texture update"?
for i in 0..entity.cells.len() {
cell_buffer[i] = entity.cells[i].material as u8;
@@ -717,15 +716,17 @@ impl RendererState {
{
puffin::profile_scope!("Build instances");
let (xl, xu, yl, yu) = camera.viewport_bounds_world();
- let ((cxl, cyl), _) = World::split_game_position(xl.floor() as i32, yl.floor() as i32);
- let ((cxu, cyu), _) = World::split_game_position(xu.floor() as i32, yu.floor() as i32);
+ let ((cxl, cyl), _) =
+ CellManager::split_game_position(xl.floor() as i32, yl.floor() as i32);
+ let ((cxu, cyu), _) =
+ CellManager::split_game_position(xu.floor() as i32, yu.floor() as i32);
let half_size = [CHUNK_SIZE as f32 / 2.0, CHUNK_SIZE as f32 / 2.0];
let dims = [CHUNK_SIZE as u32, CHUNK_SIZE as u32];
for cx in cxl..=cxu {
for cy in cyl..=cyu {
- if let Some(idx) = world.chunk_position_to_chunk_idx.get(&(cx, cy)) {
+ if let Some(idx) = sim.cell_manager.chunk_position_to_chunk_idx.get(&(cx, cy)) {
instances.push(RendererInstance {
centre: [
(cx * CHUNK_SIZE) as f32 + half_size[0],
@@ -742,8 +743,8 @@ impl RendererState {
}
for (id, slot) in &self.renderer_rb_entities {
- if let Some(&RbEntity { width, height, .. }) = rb_sim_manager.rb_entities.get(id)
- && let Some((x, y, cos, sin)) = rb_sim_manager.get_rb_entity_transform(*id)
+ if let Some(&RbEntity { width, height, .. }) = sim.rb_manager.rb_entities.get(id)
+ && let Some((x, y, cos, sin)) = sim.rb_manager.get_rb_entity_transform(*id)
{
instances.push(RendererInstance {
centre: [x, y],
@@ -765,7 +766,8 @@ impl RendererState {
{
puffin::profile_scope!("Build particles");
// TODO could cull this to visible, maybe it's slower?
- particles = particle_manager
+ particles = sim
+ .particle_manager
.particles
.iter()
.map(|p| RendererParticle {
@@ -781,7 +783,7 @@ impl RendererState {
let debug_vertex_count = if config.debug_render {
puffin::profile_scope!("Build physics debug lines");
- let vertices = rb_sim_manager.debug_render(config.debug_render_mode);
+ let vertices = sim.rb_manager.debug_render(config.debug_render_mode);
if vertices.is_empty() {
0
diff --git a/src/renderer/ui.rs b/src/renderer/ui.rs
index c4f7585..4c6d61c 100644
--- a/src/renderer/ui.rs
+++ b/src/renderer/ui.rs
@@ -2,7 +2,10 @@ use egui::{Color32, Stroke, Ui, epaint::CircleShape};
use crate::{
Camera, Config, Diagnostics, Input,
- sim::{cell::materials::MaterialId, cell_sim::world::World, rb_sim::DebugRenderMode},
+ sim::{
+ cell::materials::MaterialId, cell_manager::manager::CellManager,
+ rb_manager::DebugRenderMode, sim_manager::SimManager,
+ },
};
const DEBUG_RENDER_MODES: [(&str, DebugRenderMode); 6] = [
@@ -20,7 +23,7 @@ pub fn draw_egui<'a>(
camera: &mut Camera,
diagnostics: &Diagnostics,
input: &Input,
- world: &World,
+ sim: &SimManager,
) {
puffin::profile_function!();
ui.heading("Config");
@@ -109,8 +112,11 @@ pub fn draw_egui<'a>(
if let Some(p) = input.last_mouse_chunk_pos {
ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,));
- if let Some(&chunk) = world.chunk_position_to_chunk_idx.get(&p) {
- ui.label(format!("Sleeping={}", world.chunks[chunk].sleeping));
+ if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&p) {
+ ui.label(format!(
+ "Sleeping={}",
+ sim.cell_manager.chunks[chunk].sleeping
+ ));
}
}
@@ -120,7 +126,10 @@ pub fn draw_egui<'a>(
if let Some((x, y)) = input.last_mouse_world_pos {
ui.heading("Entity");
- if let Some(cell) = world.get_cell_from_game_position(x.round() as i32, y.round() as i32) {
+ if let Some(cell) = sim
+ .cell_manager
+ .get_cell_from_game_position(x.round() as i32, y.round() as i32)
+ {
let material = cell.material.def();
let cell_label = ui.label(
egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),