Comments (1)
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)
- Add Generic instances for Component, Elem, Expl[Get|Set|Destroy|Members] HOT 10
- Argument order in Reacts.react HOT 2
- Passing keys between members/exists and get/set HOT 3
- apecs-physics 0.4.5 marked as broken on nix - 'readGenericPackageDescription' not in scope HOT 6
- How to handle multiple potential components HOT 7
- Template Haskell function requires me to import some symbols unqualified HOT 2
- apecs-stm: newEntity_ leads to a compilation error, not newEntity HOT 4
- Unable to load package `apecs-physics-0.4.5' HOT 20
- Community chat? HOT 4
- Build failure with GHC 9.2.1 HOT 1
- Why is there no getAll / members? HOT 12
- Please enhance Benchmark Comparison chart HOT 5
- error destroying component for entity seemingly guaranteed to have that component HOT 4
- lazy cfoldr and cfoldMap HOT 2
- Physics documentation is inaccurate HOT 6
- Judy-backed storage in IO HOT 5
- fails to build with ghc-9.4/Cabal-3.8 for Stackage Nightly
- New article for Apecs - maybe depreciate outdated one? HOT 1
- Apecs-Physics collision handlers still nonfunctional HOT 1
- Need help getting Enemy AI to follow player HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apecs.