Skip to content

Commit

Permalink
Renames, docs & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Jan 14, 2022
1 parent f1c3974 commit 148c32e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions corrode/src/renderer/render_pass/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Pipelines {
}

/// System that contains the necessary facilities for rendering a single frame.
/// This is a stripped down version of https://github.com/vulkano-rs/vulkano/blob/master/examples/src/bin/deferred/main.rs
pub struct RenderPassDeferred {
gfx_queue: Arc<Queue>,
render_pass: Arc<RenderPass>,
Expand Down
1 change: 1 addition & 0 deletions corrode/src/renderer/render_pass/place_over_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vulkano::{

use crate::renderer::{pipelines::FullFrameImagePipeline, DeviceImageView, FinalImageView};

/// A simple render pass that places an image filling the whole frame
pub struct RenderPassPlaceOverFrame {
gfx_queue: Arc<Queue>,
render_pass: Arc<RenderPass>,
Expand Down
8 changes: 0 additions & 8 deletions corrode/src/renderer/vertices.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use cgmath::Vector2;

/// A B C D
pub const VERTICES_PER_QUAD: usize = 4;
/// 0, 2, 1, 0, 3, 2
pub const INDICES_PER_QUAD: usize = 6;

/// 0, 1, 1, 2, 2, 3, 3, 4 (Line list)
pub const VERTICES_PER_LINE: usize = 2;

/// Vertex for textured quads
#[repr(C)]
#[derive(Default, Debug, Clone, Copy)]
Expand Down
29 changes: 23 additions & 6 deletions sandbox/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ pub enum InputAction {
ToggleFullScreen,
}

pub struct App {
pub struct SandboxApp {
// Main structs
simulation: Option<Simulation>,
editor: Editor,
gui_state: GuiState,
settings: AppSettings,
// Bools
is_running_simulation: bool,
is_step: bool,
is_debug: bool,
time_since_last_step: f64,
time_since_last_perf: f64,
// Performance metrics
simulation_timer: PerformanceTimer,
render_timer: PerformanceTimer,
frame_timer: PerformanceTimer,
}

impl App {
pub fn new() -> Result<App> {
Ok(App {
impl SandboxApp {
pub fn new() -> Result<SandboxApp> {
Ok(SandboxApp {
simulation: None,
editor: Editor::new()?,
gui_state: GuiState::new(),
Expand Down Expand Up @@ -84,6 +87,7 @@ impl App {
log_world_performance(self.simulation.as_ref().unwrap());
}

/// Step the simulation
pub fn step(&mut self, api: &mut EngineApi<InputAction>) -> Result<()> {
self.simulation_timer.start();
let canvas_mouse_state = CanvasMouseState::new(&api.main_camera, &api.inputs[0]);
Expand All @@ -97,39 +101,47 @@ impl App {
}
}

impl Engine<InputAction> for App {
impl Engine<InputAction> for SandboxApp {
fn start<E>(
&mut self,
_event_loop: &EventLoop<E>,
api: &mut EngineApi<InputAction>,
) -> Result<()> {
// Zoom to desired level
api.main_camera.zoom_to_fit_canvas(WORLD_UNIT_SIZE);
// Read matter definitions
let matter_definitions = if let Some(defs) = read_matter_definitions_file() {
defs
} else {
default_matter_definitions()
};
validate_matter_definitions(&matter_definitions);
// Create simulator
self.simulation = Some(Simulation::new(
api.renderer.compute_queue(),
matter_definitions,
api.renderer.image_format(),
)?);
// Register gui images (for editor windows in gui)
self.editor
.register_gui_images(api, self.simulation.as_ref().unwrap());
// Update settings based on read information from renderer
self.settings
.update_based_on_device_info_and_env(&api.renderer);
// Toggle fullscreen
api.renderer.toggle_fullscreen();
Ok(())
}

fn update(&mut self, api: &mut EngineApi<InputAction>) -> Result<()> {
// Update editor & handle inputs there
self.editor.update(
api,
self.simulation.as_mut().unwrap(),
&mut self.is_running_simulation,
&mut self.is_step,
)?;
// Step if desired
if self.should_step() {
if self.is_running_simulation {
self.step(api)?;
Expand Down Expand Up @@ -174,7 +186,9 @@ impl Engine<InputAction> for App {
while let Some(pass) = frame.next_pass()? {
after_future = match pass {
Pass::Deferred(mut dp) => {
// Render canvas first
draw_canvas(simulation, &mut dp)?;
// Debug renders
if self.is_debug {
draw_contours(ecs_world, physics_world, simulation, &mut dp)?;
draw_grid(simulation, &mut dp, [0.5; 4])?;
Expand All @@ -185,6 +199,7 @@ impl Engine<InputAction> for App {
])?;
}
}
// Render line from dragged object
if let Some((obj_id, _)) = self.editor.dragger.dragged_object {
ecs_world
.query_one::<(&Position, &Angle)>(obj_id)
Expand All @@ -200,6 +215,7 @@ impl Engine<InputAction> for App {
});
}

// Render circle when painting
if self.editor.mode == EditorMode::Paint
|| self.editor.mode == EditorMode::ObjectPaint
{
Expand All @@ -220,6 +236,7 @@ impl Engine<InputAction> for App {
dp.draw_circle(pos, radius, color_f32)?;
}

// Draw painted object image
if self.editor.mode == EditorMode::ObjectPaint
&& self.editor.draw_state.started()
{
Expand All @@ -237,7 +254,7 @@ impl Engine<InputAction> for App {
}

fn gui_content(&mut self, api: &mut EngineApi<InputAction>) -> Result<()> {
let App {
let SandboxApp {
simulation: simulator,
gui_state,
is_running_simulation,
Expand Down
4 changes: 2 additions & 2 deletions sandbox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use corrode::{
use simplelog::LevelFilter;
use winit::event::VirtualKeyCode;

use crate::app::{App, InputAction};
use crate::app::{InputAction, SandboxApp};

/// This is an example for using doc comment attributes
/// Canvas plane scale (1.0 means our world is between -1.0 and 1.0)
Expand Down Expand Up @@ -90,7 +90,7 @@ fn main() -> Result<()> {
initialize_logger(LevelFilter::Info)?;

Corrode::run(
App::new()?,
SandboxApp::new()?,
EngineOptions {
render_options: RenderOptions {
v_sync: false,
Expand Down
1 change: 1 addition & 0 deletions sandbox/src/object/deformation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn depth_first_label_mark(
}

/// Go through inputted bitmap & extract new bitmaps of connected pixels (components)
/// See: https://en.wikipedia.org/wiki/Connected-component_labeling
pub fn extract_connected_components_from_bitmap(
bitmap: &[f64],
width: u32,
Expand Down
12 changes: 6 additions & 6 deletions sandbox/src/sim/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ impl Simulation {
Ok(())
}

/*
1. Write objects to CA grid
2. Step CA (multiple steps if needed). Updates solid etc. bitmaps
3. Form contours & physics utils from CA Grid
4. Step physics simulation
*/
/// 1. Write objects to CA grid
/// 2. Step CA (multiple steps if needed). Updates solid etc. bitmaps
/// 3. Remove object pixels from grid
/// 4. Form contours for new deformed physics objects
/// 5. Step physics simulation
pub fn step(
&mut self,
api: &mut EngineApi<InputAction>,
Expand Down Expand Up @@ -147,6 +146,7 @@ impl Simulation {
Ok(())
}

/// Update object ecs data after physics calculation
fn update_dynamic_physics_objects(&mut self, api: &mut EngineApi<InputAction>) -> Result<()> {
let EngineApi {
ecs_world,
Expand Down
3 changes: 3 additions & 0 deletions sandbox/src/sim/simulation_chunk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ impl GpuChunk {
}
}

/// The purpose of this manager is to organize map chunk loading and unloading when camera is moved
/// This is required for a potential endless 2d world. In this simulator it's not that useful though.
/// More like a tech demo part.
pub struct SimulationChunkManager {
pub queue: Arc<Queue>,
canvas_pos: Vector2<i32>,
Expand Down

0 comments on commit 148c32e

Please sign in to comment.