Giter Club home page Giter Club logo

Comments (1)

jonascarpay avatar jonascarpay commented on July 18, 2024

There are some similarities, defining components is pretty much identical to specs, for example:

#[derive(Debug)]
struct Position(f32);

impl Component for Position {
    type Storage = VecStorage<Self>;
}

fn main() {
  let mut world = World::new();
  world.register::<Position>();
  world.create_entity().with(Position(0.0)).build();
}

vs

newtype Position = Position Double deriving Show

instance Component Position where
  type Storage Position = Map Position

makeWorld "MyWorld" [''Position]

main = do
  newEntity (Position 0)
  ...

They have very different interpretations of the idea of a system, however. In specs, a system is something you build and explicitly dispatch, whereas in apecs, a system is just a statement. Consider:

struct HelloWorld;

impl<'a> System<'a> for HelloWorld {
    type SystemData = ReadStorage<'a, Position>;

    fn run(&mut self, position: Self::SystemData) {
        use specs::Join;

        for position in position.join() {
            println!("Hello, {:?}", &position);
        }
    }
}

fn main() {
  ...
  let mut dispatcher = DispatcherBuilder::new().with(SysA, "sys_a", &[]).build();
  dispatcher.setup(&mut world.res);
  dispatcher.dispatch(&mut world.res);
}

vs

main = do
  ...
  cmapM_ $ \(p :: Position) -> liftIO . putStrLn $ "Hello, " ++ show p

You don't get any automatic parallelism, but it's easy to do yourself. You use forkSys to run a system on a new thread, and atomically to eliminate race conditions by lifting it into the STM monad. How you combine these is up to you, but here's an example in which we spawn a thread that continuously executes a system, prints a message, sleeps for a period of time, and then repeats:

forkSys . forever $ do
  atomically . cmap $ \(Position p, Velocity v) -> Position (p+v)
  liftIO (putStrLn "Stepped positions")
  liftIO (threadDelay 1000)

does that answer your question?

from apecs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.