Skip to content

Commit

Permalink
Tidying up various bits and pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Apr 4, 2024
1 parent cacd581 commit c0c7385
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 331 deletions.
305 changes: 9 additions & 296 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/src/abstractions/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
pub use exporters::*;
pub use importers::*;

use crate::{FastHashMap, FileSystemError, Guid, StreamError, StringName, ToVirtualPath, VirtualPath};
use crate::{FastHashMap, FileSystemError, Guid, impl_from_error, StreamError, StringName, ToVirtualPath, VirtualPath};

/// Represents a reference to an asset that can either be loaded or unloaded.
///
Expand Down
27 changes: 15 additions & 12 deletions common/src/diagnostics/profiling.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use macros::profile as profiling;
pub use macros::profiling as profiling;

/// A sink for profiling output.
pub trait Profiler {}
Expand All @@ -7,7 +7,15 @@ pub trait Profiler {}
#[macro_export]
macro_rules! profile_frame_start {
() => {
todo!();
// TODO: implement me
};
}

/// Notifies the profiler that a frame has ended.
#[macro_export]
macro_rules! profile_frame_end {
() => {
// TODO: implement me
};
}

Expand All @@ -18,22 +26,17 @@ macro_rules! profile_scope {
// TODO: implement me
};
($name:expr, $args:expr) => {
// TODO: implement me
$crate::profile_scope!(concat!($name, "(", stringify!($args), ")"));
};
}

/// Notifies the profiler that a function has started.
/// Notifies the profiler that a function is executing.
#[macro_export]
macro_rules! profile_function {
($name:expr) => {
// TODO: implement me
$crate::profile_scope!($name);
};
}

/// Notifies the profiler that a frame has ended.
#[macro_export]
macro_rules! profile_frame_end {
() => {
todo!();
($name:expr, $args:expr) => {
$crate::profile_scope!($name, $args);
};
}
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn derive_reflect(input: TokenStream) -> TokenStream {

/// Instruments a function with profiling code.
#[proc_macro_attribute]
pub fn profile(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn profiling(_attr: TokenStream, item: TokenStream) -> TokenStream {
profiling::impl_profiling(item)
}

Expand Down
5 changes: 1 addition & 4 deletions modules/graphics/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ impl GraphicsBackend for HeadlessGraphicsBackend {
Ok(())
}

fn texture_blit_to_display(&self, texture: TextureId) -> Result<(), TextureError> {
Ok(())
}

fn texture_delete(&self, texture: TextureId) -> Result<(), TextureError> {
Ok(())
}
Expand Down Expand Up @@ -234,6 +230,7 @@ impl GraphicsBackend for HeadlessGraphicsBackend {
) -> Result<(), TargetError> {
Ok(())
}

fn target_delete(&self, target: TargetId) -> Result<(), TargetError> {
Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion modules/graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub trait GraphicsBackend {
fn texture_read_data(&self, texture: TextureId, length: usize, pixel_format: TextureFormat, pixels: *mut u8, mip_level: usize) -> Result<(), TextureError>;
fn texture_write_data(&self, texture: TextureId, width: u32, height: u32, pixels: *const u8, internal_format: TextureFormat, pixel_format: TextureFormat, mip_level: usize) -> Result<(), TextureError>;
fn texture_write_sub_data(&self, texture: TextureId, region: &common::Rectangle, pixels: *const u8, pixel_format: TextureFormat, mip_level: usize) -> Result<(), TextureError>;
fn texture_blit_to_display(&self, texture: TextureId,) -> Result<(), TextureError>;
fn texture_delete(&self, texture: TextureId) -> Result<(), TextureError>;

// shaders
Expand Down
7 changes: 0 additions & 7 deletions modules/graphics/src/opengl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use super::*;
/// This type implemented by the host application and is used to provide the
/// graphics backend with access to the host's OpenGL functions.
pub trait OpenGLHost {
/// Gets the address of an OpenGL function.
fn get_proc_address(&self, name: &str) -> *const c_void;
}

Expand Down Expand Up @@ -402,11 +401,6 @@ impl GraphicsBackend for OpenGLGraphicsBackend {
}
}

#[profiling]
fn texture_blit_to_display(&self, _texture: TextureId) -> Result<(), TextureError> {
todo!()
}

#[profiling]
fn texture_delete(&self, texture: TextureId) -> Result<(), TextureError> {
unsafe {
Expand Down Expand Up @@ -838,7 +832,6 @@ impl GraphicsBackend for OpenGLGraphicsBackend {
}
}

#[profiling]
fn target_blit_to_active(
&self,
target: TargetId,
Expand Down
8 changes: 7 additions & 1 deletion modules/graphics/src/rendering/pipelines.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Render pipeline abstractions.
use common::Camera;
use common::{Camera, profile_frame_end, profile_frame_start};
use macros::profiling;

use super::*;

Expand Down Expand Up @@ -60,7 +61,10 @@ pub struct MultiPassPipeline {
}

impl RenderPipeline for MultiPassPipeline {
#[profiling]
fn render(&mut self, scene: &dyn RenderScene, delta_time: f32) {
profile_frame_start!();

let mut frame = RenderFrame {
delta_time,
queue: &mut self.queue,
Expand Down Expand Up @@ -91,6 +95,8 @@ impl RenderPipeline for MultiPassPipeline {
for pass in &self.passes {
pass.end_frame(scene, &mut frame);
}

profile_frame_end!();
}
}

Expand Down
9 changes: 2 additions & 7 deletions modules/graphics/src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{cell::RefCell, rc::Rc};

use common::{uvec2, Rectangle, UVec2};
use common::{Rectangle, uvec2, UVec2};

use super::*;

Expand Down Expand Up @@ -260,12 +260,7 @@ impl Texture {

/// Blits this texture to the display.
pub fn blit_to_display(&self) {
let state = self.state.borrow();

state
.graphics
.texture_blit_to_display(state.id)
.expect("Failed to blit texture to display");
todo!()
}
}

Expand Down
11 changes: 10 additions & 1 deletion modules/physics/src/simplex/world2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ enum ColliderShape {
}

/// A single collision event in the 2d world.
enum CollisionEvent {}
struct CollisionEvent {
source_body: BodyId,
source_collider: ColliderId,
target_body: BodyId,
target_collider: ColliderId,
position: Vec2,
normal: Vec2,
penetration: f32,
kind: ColliderKind,
}

/// An effector in the 2d physics world.
struct Effector {
Expand Down

0 comments on commit c0c7385

Please sign in to comment.