Skip to content

Commit

Permalink
Tidy up crate layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Jul 10, 2024
1 parent 5115ec4 commit 693c93e
Show file tree
Hide file tree
Showing 117 changed files with 68 additions and 49 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
version = "0.1.0"

[workspace]
members = ["backends/*", "common", "editor", "macros", "modules/*"]
members = ["crates/*", "backends/*"]

[profile.dev.package."*"]
opt-level = 3
Expand All @@ -31,16 +31,16 @@ bitflags = "2.1.0"

[dependencies]
# core
common = { package = "surreal-common", path = "./common" }
common = { package = "surreal-common", path = "./crates/common" }
editor = { package = "surreal-editor", path = "./editor", optional = true }

# framework
sdl = { package = "surreal-backend-sdl", path = "./backends/sdl", optional = true }

# modules
audio = { package = "surreal-audio", path = "./modules/audio", optional = true }
graphics = { package = "surreal-graphics", path = "./modules/graphics", optional = true }
input = { package = "surreal-input", path = "./modules/input", optional = true }
# crates
audio = { package = "surreal-audio", path = "./crates/audio", optional = true }
graphics = { package = "surreal-graphics", path = "./crates/graphics", optional = true }
input = { package = "surreal-input", path = "./crates/input", optional = true }

[[example]]
name = "hello-world"
Expand Down
8 changes: 4 additions & 4 deletions backends/sdl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors.workspace = true
edition.workspace = true

[dependencies]
common = { package = "surreal-common", path = "../../common" }
audio = { package = "surreal-audio", path = "../../modules/audio" }
graphics = { package = "surreal-graphics", path = "../../modules/graphics" }
input = { package = "surreal-input", path = "../../modules/input" }
common = { package = "surreal-common", path = "../../crates/common" }
audio = { package = "surreal-audio", path = "../../crates/audio" }
graphics = { package = "surreal-graphics", path = "../../crates/graphics" }
input = { package = "surreal-input", path = "../../crates/input" }
sdl2-sys = { version = "0.36.0", features = ["bundled"] }
2 changes: 1 addition & 1 deletion modules/audio/Cargo.toml → crates/audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors.workspace = true
edition.workspace = true

[dependencies]
common = { package = "surreal-common", path = "../../common" }
common = { package = "surreal-common", path = "../common" }
openal-sys = "1.16.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum SpatialShape {

impl SpatialShape {
/// Determines if this shape intersects the given other shape
pub fn intersects(&self, other: &SpatialShape) -> bool {
pub fn intersects(&self, _other: &SpatialShape) -> bool {
todo!()
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {

#[test]
fn test_read_file_from_disk() {
let path = "local://../assets/fonts/bitboy8_v1.otf".to_virtual_path();
let path = "local://../../assets/fonts/bitboy8_v1.otf".to_virtual_path();
let bytes = path.read_all_bytes().unwrap();

assert!(!bytes.is_empty());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions modules/graphics/Cargo.toml → crates/graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors.workspace = true
edition.workspace = true

[dependencies]
common = { package = "surreal-common", path = "../../common" }
macros = { package = "surreal-macros", path = "../../macros" }
common = { package = "surreal-common", path = "../common" }
macros = { package = "surreal-macros", path = "../macros" }
serde = { workspace = true, optional = true }
bitflags = { workspace = true }
image = { version = "0.25.1", default-features = false, features = ["png"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ use common::{FastHashMap, Identity, Lerp, Quat, StringName, TimeSpan, Vec2, Vec3

use crate::{Color, Color32};

/// Represents a type that can be animated by an animation tree.
pub trait Animatable<V> {
/// Applies the given value to the animatable type.
fn apply(&mut self, track: AnimationTrack, time: f32);
}

impl Animatable<Vec2> for Vec2 {
fn apply(&mut self, track: AnimationTrack, time: f32) {
match track {
AnimationTrack::Vec2(data) => {
*self = evaluate_keyframes(time, &data);
}
_ => {}
}
}
}

impl Animatable<Vec3> for Vec3 {
fn apply(&mut self, track: AnimationTrack, time: f32) {
match track {
AnimationTrack::Vec3(data) => {
*self = evaluate_keyframes(time, &data);
}
_ => {}
}
}
}

/// An animation tree that can be used to drive animation state changes.
///
/// The animation tree is a directed acyclic graph (DAG) where each node is an
Expand Down Expand Up @@ -118,18 +146,6 @@ impl<T> AnimationTree<T> {
state.time_elapsed = TimeSpan::ZERO;
}

// evaluate all tracks and apply them to the state
for track in &state.clip.tracks {
match track {
AnimationTrack::Scalar(_) => {}
AnimationTrack::Vec2(_) => {}
AnimationTrack::Vec3(_) => {}
AnimationTrack::Quat(_) => {}
AnimationTrack::Color(_) => {}
AnimationTrack::Color32(_) => {}
}
}

// evaluate all transitions each tick
for transition in &state.transitions {
let AnimationTransition { condition, target } = transition;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,23 @@ impl RenderQueue {
/// Flushes all [`RenderCommand`]s in the queue to the given renderer.
pub fn flush(&mut self) -> Result<(), RenderQueueError> {
let mut commands = self.commands.lock().unwrap();
let graphics = graphics();

for command in commands.drain(..) {
common::profile_scope!("RenderCommand::{:?}", command.type_name());

match command {
RenderCommand::SetRenderTarget { target_id } => {
graphics().target_activate(target_id)?;
graphics.target_activate(target_id)?;
}
RenderCommand::SetRenderTargetToDisplay => {
graphics().target_set_default()?;
graphics.target_set_default()?;
}
RenderCommand::ClearColorBuffer { color } => {
graphics().clear_color_buffer(color);
graphics.clear_color_buffer(color);
}
RenderCommand::ClearDepthBuffer { depth } => {
graphics().clear_depth_buffer(depth);
graphics.clear_depth_buffer(depth);
}
RenderCommand::SetShader {
shader_id,
Expand All @@ -188,57 +189,57 @@ impl RenderQueue {
culling_mode,
scissor_mode,
} => {
graphics().set_blend_state(blend_state);
graphics().set_culling_mode(culling_mode);
graphics().set_scissor_mode(scissor_mode);
graphics.set_blend_state(blend_state);
graphics.set_culling_mode(culling_mode);
graphics.set_scissor_mode(scissor_mode);

for (key, uniform) in uniforms.iter() {
let location = graphics()
let location = graphics
.shader_uniform_location(shader_id, key)
.ok_or(ShaderError::InvalidUniform)?;

graphics().shader_set_uniform(shader_id, location, uniform)?;
graphics.shader_set_uniform(shader_id, location, uniform)?;
}

graphics().shader_activate(shader_id)?;
graphics.shader_activate(shader_id)?;
}
RenderCommand::SetUniformByKey {
shader_id,
key,
uniform,
} => {
let location = graphics()
let location = graphics
.shader_uniform_location(shader_id, &key)
.ok_or(ShaderError::InvalidUniform)?;

graphics().shader_set_uniform(shader_id, location, &uniform)?;
graphics.shader_set_uniform(shader_id, location, &uniform)?;
}
RenderCommand::SetUniformByLocation {
shader_id,
location,
uniform,
} => {
graphics().shader_set_uniform(shader_id, location, &uniform)?;
graphics.shader_set_uniform(shader_id, location, &uniform)?;
}
RenderCommand::DispatchCompute {
shader_id,
group_count: (x, y, z),
} => {
graphics().shader_dispatch_compute(shader_id, x, y, z)?;
graphics.shader_dispatch_compute(shader_id, x, y, z)?;
}
RenderCommand::MemoryBarrier { barrier } => {
graphics().shader_memory_barrier(barrier)?;
graphics.shader_memory_barrier(barrier)?;
}
RenderCommand::DrawMesh {
mesh_id,
topology,
vertex_count,
index_count,
} => {
graphics().mesh_draw(mesh_id, topology, vertex_count, index_count)?;
graphics.mesh_draw(mesh_id, topology, vertex_count, index_count)?;
}
RenderCommand::BlitRenderTargetToActive { target_id, filter } => {
graphics().target_blit_to_active(target_id, None, None, filter)?;
graphics.target_blit_to_active(target_id, None, None, filter)?;
}
}
}
Expand All @@ -261,9 +262,11 @@ mod tests {
#[test]
fn test_basic_commands() {
let mut queue = RenderQueue::default();
let mesh = Mesh::create_circle(1.0, 16);

queue.set_render_target_to_display();
queue.clear_color_buffer(Color::BLACK);
queue.draw_mesh(&mesh, PrimitiveTopology::Triangles);

queue.flush().unwrap();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/input/Cargo.toml → crates/input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors.workspace = true
edition.workspace = true

[dependencies]
common = { package = "surreal-common", path = "../../common" }
common = { package = "surreal-common", path = "../common" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ version.workspace = true

[dependencies]
# core dependencies
common = { package = "surreal-common", path = "../common" }
audio = { package = "surreal-audio", path = "../modules/audio" }
graphics = { package = "surreal-graphics", path = "../modules/graphics" }
input = { package = "surreal-input", path = "../modules/input" }
common = { package = "surreal-common", path = "../crates/common" }
audio = { package = "surreal-audio", path = "../crates/audio" }
graphics = { package = "surreal-graphics", path = "../crates/graphics" }
input = { package = "surreal-input", path = "../crates/input" }
sdl = { package = "surreal-backend-sdl", path = "../backends/sdl" }

# third-party dependencies
Expand Down

0 comments on commit 693c93e

Please sign in to comment.