Skip to content

Commit

Permalink
Cleaning up some bits and pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Apr 5, 2024
1 parent 2445449 commit cf0bd71
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 100 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,3 @@ scripting = { package = "surreal-scripting", path = "./modules/scripting", optio
[[example]]
name = "hello-world"
required-features = ["sdl", "graphics", "input"]

[[example]]
name = "falling-sand"
required-features = ["sdl", "graphics", "input"]
3 changes: 1 addition & 2 deletions backends/sdl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
use std::ffi::CString;

use common::FastHashSet;
pub use sdl2_sys as sys;
use sys::{SDL_KeyCode, SDL_Keycode};

use common::FastHashSet;

/// Represents an error that can occur when creating a window.
#[derive(Debug)]
pub enum WindowError {
Expand Down
6 changes: 2 additions & 4 deletions common/src/abstractions/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ pub struct AssetBundle {}
pub trait AssetBundleCodec {}

mod exporters {
use crate::OutputStream;

use super::*;
use crate::OutputStream;

/// An error that can occur when exporting an asset.
#[derive(Debug)]
Expand Down Expand Up @@ -272,9 +271,8 @@ mod exporters {
}

mod importers {
use crate::InputStream;

use super::*;
use crate::InputStream;

/// An error that can occur when exporting an asset.
#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions common/src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::{
hash::BuildHasherDefault,
};

pub use smallvec::{smallvec, SmallVec};

pub use anymap::*;
pub use arena::*;
pub use graphs::*;
Expand All @@ -15,6 +13,7 @@ pub use multimap::*;
pub use priorityqueue::*;
pub use quadtree::*;
pub use ringbuffer::*;
pub use smallvec::{smallvec, SmallVec};
pub use spatialhash::*;

mod anymap;
Expand Down
2 changes: 1 addition & 1 deletion common/src/diagnostics/profiling.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use macros::profiling as profiling;
pub use macros::profiling;

/// A sink for profiling output.
pub trait Profiler {}
Expand Down
2 changes: 1 addition & 1 deletion common/src/io/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::{BufRead, Seek, Write};
pub enum StreamError {
UnexpectedEof,
UnexpectedEncoding,
FailedToDeserialize
FailedToDeserialize,
}

impl From<std::io::Error> for StreamError {
Expand Down
3 changes: 1 addition & 2 deletions common/src/io/virtualfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::sync::RwLock;
pub use local::*;
pub use memory::*;

use crate::{Singleton, StringName, ToStringName};

use super::{InputStream, OutputStream};
use crate::{Singleton, StringName, ToStringName};

mod local;
mod memory;
Expand Down
2 changes: 1 addition & 1 deletion common/src/maths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub use paths::*;
pub use random::*;
pub use ranges::*;
pub use rectangles::*;
pub use size::*;
pub use shapes::*;
pub use size::*;
pub use splines::*;
pub use time::*;

Expand Down
3 changes: 1 addition & 2 deletions common/src/maths/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

pub use glam::*;

pub use aabb::*;
pub use bsp::*;
pub use frustum::*;
pub use glam::*;
pub use planes::*;
pub use rays::*;
pub use scalars::*;
Expand Down
3 changes: 1 addition & 2 deletions common/src/maths/linear/frustum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::reinterpret_cast;

use super::*;
use crate::reinterpret_cast;

/// A frustum in 3-space.
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion common/tests/asset-database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use surreal_common::{AssetDatabase, AssetImporter, AssetImportError, InputStream};
use surreal_common::{AssetDatabase, AssetImportError, AssetImporter, InputStream};

#[test]
pub fn it_should_load_an_aseprite_file_and_export_it() {
Expand Down
69 changes: 0 additions & 69 deletions examples/falling-sand.rs

This file was deleted.

3 changes: 1 addition & 2 deletions macros/src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use proc_macro::TokenStream;

use quote::quote;
use syn::{DeriveInput, parse_macro_input};
use syn::{parse_macro_input, DeriveInput};

pub fn impl_binary(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
Expand Down
1 change: 0 additions & 1 deletion macros/src/profiling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proc_macro::TokenStream;

use quote::quote;
use syn::{parse_macro_input, parse_quote};

Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/src/meshes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{cell::RefCell, rc::Rc};

use common::{Size, vec2, Vec2, Vec3};
use common::{vec2, Size, Vec2, Vec3};
pub use macros::Vertex;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/src/rendering/pipelines.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Render pipeline abstractions.
use common::{Camera, profile_frame_end, profile_frame_start};
use common::{profile_frame_end, profile_frame_start, Camera};
use macros::profiling;

use super::*;
Expand Down
1 change: 0 additions & 1 deletion modules/graphics/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use core::str;
use std::{cell::RefCell, rc::Rc};

use bitflags::bitflags;

use common::*;
pub use lang::*;
pub use templates::*;
Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/src/shaders/lang/shady.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod compiler {
//!
//! This compiler will transpile Shady code into GLSL code that can be used
//! with the graphics engine.
use super::{*, parser::*};
use super::{parser::*, *};

/// Compiles the given Shady module into a list of [`ShaderKernel`]s.
pub fn compile(module: Module) -> Result<Vec<ShaderKernel>, ShaderError> {
Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/src/skinning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub struct SkinVertex {

#[cfg(test)]
mod tests {
use common::{ToStringName, vec3};
use common::{vec3, ToStringName};

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion 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::{Rectangle, uvec2, UVec2};
use common::{uvec2, Rectangle, UVec2};

use super::*;

Expand Down
56 changes: 56 additions & 0 deletions modules/physics/src/colliders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use super::*;

pub struct Collider2D<'w> {
collider_id: ColliderId,
world: &'w dyn PhysicsWorld2D,
}

impl<'w> Collider2D<'w> {
pub fn new_rectangle(world: &'w dyn PhysicsWorld2D) -> Self {
Collider2D {
world,
collider_id: world
.collider_create_rectangle(ColliderKind::Solid, Vec2::ZERO, Vec2::ONE)
.unwrap(),
}
}

pub fn new_circle(world: &'w dyn PhysicsWorld2D) -> Self {
Collider2D {
world,
collider_id: world
.collider_create_circle(ColliderKind::Solid, Vec2::ZERO, 1.0)
.unwrap(),
}
}

pub fn position(&self) -> Vec2 {
self.world.collider_get_position(self.collider_id).unwrap()
}

pub fn set_position(&self, position: Vec2) {
self.world.collider_set_position(self.collider_id, position).unwrap();
}

pub fn rotation(&self) -> f32 {
self.world.collider_get_rotation(self.collider_id).unwrap()
}

pub fn set_rotation(&self, rotation: f32) {
self.world.collider_set_rotation(self.collider_id, rotation).unwrap();
}

pub fn scale(&self) -> Vec2 {
self.world.collider_get_scale(self.collider_id).unwrap()
}

pub fn set_scale(&self, scale: Vec2) {
self.world.collider_set_scale(self.collider_id, scale).unwrap();
}
}

impl<'w> Drop for Collider2D<'w> {
fn drop(&mut self) {
self.world.collider_delete(self.collider_id).unwrap();
}
}
3 changes: 3 additions & 0 deletions modules/physics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use common::Vec2;

mod colliders;
mod homebaked;

pub use colliders::*;

common::impl_arena_index!(ColliderId, "Identifies a collider.");
common::impl_arena_index!(BodyId, "Identifies a physics body.");
common::impl_arena_index!(EffectorId, "Identifies an effector.");
Expand Down

0 comments on commit cf0bd71

Please sign in to comment.