Skip to content

Commit

Permalink
Reorganize according to amethyst#191, minor reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ebkalderon committed May 8, 2017
1 parent 1c479e8 commit f850855
Show file tree
Hide file tree
Showing 48 changed files with 47 additions and 65 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ before_script:

# Format the codebase, generate documentation, compile the engine, run tests.
script: |
# cargo fmt -- --write-mode=diff &&
cargo local-pkgs doc --no-deps -v &&
cargo local-pkgs build -v &&
# Build and test without profiler
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ travis-ci = { repository = "amethyst/amethyst" }
profiler = ["thread_profiler/thread_profiler"]

[dependencies]
amethyst_config = { path = "src/config/", version = "0.2" }
amethyst_renderer = { path = "src/renderer", version = "0.5" }
amethyst_config = { path = "amethyst_config/", version = "0.2" }
amethyst_renderer = { path = "amethyst_renderer/", version = "0.5" }
cgmath = "0.13"
dds-rs = "0.4"
derivative = "1.0"
Expand Down Expand Up @@ -62,4 +62,4 @@ name = "assets"
path = "examples/05_assets/main.rs"

[workspace]
members = ["src/config", "src/renderer"]
members = ["amethyst_config", "amethyst_renderer"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 4 additions & 8 deletions src/renderer/Cargo.toml → amethyst_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,17 @@ vulkan = ["gfx_device_vulkan", "gfx_window_vulkan"]
[dependencies]
cgmath = { version = "0.14", features = ["eders", "use_simd"] }
fnv = "1.0"
#gfx = { version = "0.15", features = ["cgmath-types", "serialize"], git = "https://github.com/gfx-rs/gfx" }
gfx = { version = "0.15", features = ["cgmath-types", "serialize"], path = "/home/ekalderon/gfx/src/render/" }
#gfx_core = { version = "0.7", features = ["cgmath-types", "serialize"], git = "https://github.com/gfx-rs/gfx" }
gfx_core = { version = "0.7", features = ["cgmath-types", "serialize"], path = "/home/ekalderon/gfx/src/core/" }
gfx = { version = "0.15", features = ["cgmath-types", "serialize"], git = "https://github.com/gfx-rs/gfx" }
gfx_core = { version = "0.7", features = ["cgmath-types", "serialize"], git = "https://github.com/gfx-rs/gfx" }
gfx_macros = "0.2"
num_cpus = "1.0"
rayon = "0.7"
serde = "1.0"
serde_derive = "1.0"
winit = "0.6"

#gfx_device_gl = { version = "0.14", optional = true, git = "https://github.com/gfx-rs/gfx" }
gfx_device_gl = { version = "0.14", optional = true, path = "/home/ekalderon/gfx/src/backend/gl/" }
#gfx_window_glutin = { version = "0.16", optional = true, git = "https://github.com/gfx-rs/gfx" }
gfx_window_glutin = { version = "0.16", optional = true, path = "/home/ekalderon/gfx/src/window/glutin/" }
gfx_device_gl = { version = "0.14", optional = true, git = "https://github.com/gfx-rs/gfx" }
gfx_window_glutin = { version = "0.16", optional = true, git = "https://github.com/gfx-rs/gfx" }
glutin = { version = "0.8", optional = true }

[target.'cfg(not(macos))'.dependencies]
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.
3 changes: 1 addition & 2 deletions examples/00_hello_world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl State for Example {
}

fn main() {
let cfg = Config::default();
let mut game = Application::build(Example, cfg).finish().expect("Fatal error");
let mut game = Application::new(Example).expect("Fatal error");
game.run();
}
45 changes: 18 additions & 27 deletions src/engine/app.rs → src/app.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//! The core engine framework.

#[cfg(feature = "profiler")]
use thread_profiler::{register_thread_with_profiler, write_profile};

// use asset_manager::AssetManager;
use config::Config;
use ecs::{Component, Gate, Planner, Priority, World};
use ecs::{Gate, Planner, Priority, World};
use ecs::systems::SystemExt;
use engine::event::Event;
use engine::state::{State, StateMachine};
use engine::timing::{Stopwatch, Time};
use error::{Error, Result};
use state::{State, StateMachine};
use timing::{Stopwatch, Time};
use std::time::Duration;

/// User-facing engine handle.
Expand All @@ -24,28 +20,27 @@ pub struct Engine<'e> {
}

/// User-friendly facade for building games. Manages main loop.
pub struct Application {
pub struct Application<'a> {
config: Config,
// assets: AssetManager,
planner: Planner<()>,
states: StateMachine,
states: StateMachine<'a>,
time: Time,
timer: Stopwatch,
}

impl Application {
impl<'a> Application<'a> {
/// Creates a new Application with the given initial game state.
pub fn new<S: State + 'static>(initial_state: S) -> Result<Application> {
use ecs::systems::{RenderingSystem, TransformSystem};
pub fn new<S: State + 'a>(initial_state: S) -> Result<Application<'a>> {
use ecs::systems::TransformSystem;
ApplicationBuilder::new(initial_state, Config::default())
.with_system::<TransformSystem>("trans", 0)
.with_system::<RenderingSystem>("render", 0)
.finish()
}

/// Builds a new application using builder pattern.
pub fn build<S>(initial_state: S, cfg: Config) -> ApplicationBuilder<S>
where S: State + 'static
where S: State + 'a
{
ApplicationBuilder::new(initial_state, cfg)
}
Expand Down Expand Up @@ -82,6 +77,8 @@ impl Application {
/// Advances the game world by one tick.
fn advance_frame(&mut self) {
{
use event::Event;

let mut world = self.planner.mut_world();
let mut time = world.write_resource::<Time>().pass();
time.delta_time = self.time.delta_time;
Expand Down Expand Up @@ -129,11 +126,11 @@ impl Application {
fn write_profile(&self) {
// TODO: Specify filename in config.
let path = format!("{}/thread_profile.json", env!("CARGO_MANIFEST_DIR"));
write_profile(path.as_str());
thread_profiler::write_profile(path.as_str());
}
}

impl Drop for Application {
impl<'a> Drop for Application<'a> {
fn drop(&mut self) {
#[cfg(feature = "profiler")]
self.write_profile();
Expand All @@ -143,7 +140,7 @@ impl Drop for Application {
/// Helper builder for Applications.
#[derive(Derivative)]
#[derivative(Debug)]
pub struct ApplicationBuilder<T: State + 'static>{
pub struct ApplicationBuilder<T: State>{
config: Config,
errors: Vec<Error>,
#[derivative(Debug = "ignore")]
Expand All @@ -152,10 +149,10 @@ pub struct ApplicationBuilder<T: State + 'static>{
planner: Planner<()>,
}

impl<T: State + 'static> ApplicationBuilder<T> {
impl<'a, T: State + 'a> ApplicationBuilder<T> {
/// Creates a new ApplicationBuilder with the given initial game state and
/// display configuration.
pub fn new(initial_state: T, cfg: Config) -> ApplicationBuilder<T> {
pub fn new(initial_state: T, cfg: Config) -> Self {
use num_cpus;

ApplicationBuilder {
Expand All @@ -166,12 +163,6 @@ impl<T: State + 'static> ApplicationBuilder<T> {
}
}

/// Registers a given component type.
pub fn register<C: Component>(mut self) -> Self {
self.planner.mut_world().register::<C>();
self
}

/// Adds a given system `sys`, assigns it the string identifier `name`,
/// and marks it with the runtime priority `pri`.
pub fn with_system<S>(mut self, name: &str, pri: Priority) -> Self
Expand All @@ -187,9 +178,9 @@ impl<T: State + 'static> ApplicationBuilder<T> {
}

/// Builds the Application and returns the result.
pub fn finish(self) -> Result<Application> {
pub fn finish(self) -> Result<Application<'a>> {
#[cfg(feature = "profiler")]
register_thread_with_profiler("Main".into());
thread_profile::register_thread_with_profiler("Main".into());
#[cfg(feature = "profiler")]
profile_scope!("new");

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ecs/systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use self::transform::TransformSystem;
use config::Config;
use error::Result;
use ecs::{System, World};
use engine::EventsIter;
use event::EventsIter;

mod rendering;
mod transform;
Expand Down
2 changes: 1 addition & 1 deletion src/ecs/systems/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use config::Config;
use ecs::{RunArg, System, World};
use engine::EventsIter;
use event::EventsIter;
use error::Result;
use renderer::prelude::*;
use super::SystemExt;
Expand Down
11 changes: 0 additions & 11 deletions src/engine/mod.rs

This file was deleted.

File renamed without changes.
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ extern crate ticketed_lock;
extern crate wavefront_obj;
extern crate winit;

pub use self::app::{Application, ApplicationBuilder, Engine};
pub use self::error::{Error, Result};
pub use self::state::{State, StateMachine, Trans};
pub use self::timing::Stopwatch;

// pub mod asset_manager;
pub mod ecs;
pub mod prelude;

pub use engine::*;
pub use error::*;

mod engine;
mod app;
mod event;
mod state;
mod timing;
mod error;
5 changes: 4 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! Contains common types that can be glob-imported (`*`) for convenience.

pub use app::{Application, ApplicationBuilder, Engine};
pub use config::{Config, DisplayConfig, Element};
pub use engine::*;
pub use error::{Error, Result};
pub use event::*;
pub use state::{State, Trans};
12 changes: 6 additions & 6 deletions src/engine/state.rs → src/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utilities for game state management.

// use asset_manager::AssetManager;
use engine::{Engine, Event};
use app::Engine;
use event::Event;

/// Types of state transitions.
pub enum Trans {
Expand Down Expand Up @@ -52,15 +52,15 @@ pub trait State {
/// A simple stack-based state machine (pushdown automaton).
#[derive(Derivative)]
#[derivative(Debug)]
pub struct StateMachine {
pub struct StateMachine<'a> {
running: bool,
#[derivative(Debug = "ignore")]
state_stack: Vec<Box<State>>,
state_stack: Vec<Box<State + 'a>>,
}

impl StateMachine {
impl<'a> StateMachine<'a> {
/// Creates a new state machine with the given initial state.
pub fn new<S: State + 'static>(initial_state: S) -> StateMachine {
pub fn new<S: State + 'a>(initial_state: S) -> StateMachine<'a> {
StateMachine {
running: false,
state_stack: vec![Box::new(initial_state)],
Expand Down
File renamed without changes.

0 comments on commit f850855

Please sign in to comment.