librelist archives

« back to archive

Multiple Instances of one System class.

Multiple Instances of one System class.

From:
Asmodehn Shade
Date:
2014-07-10 @ 03:33
Hello,

Given the interface :
  system_manager->add<Systems::Mysystem>();
and :
  system_manager->update<Systems::Mysystem>(dt);

I was wondering if it was possible to use multiple instances of the same system.
If so, how am I supposed to use them ?

I am using each system instance to wrap a "one thread only" behavior.
That thread is triggered (or not) during the update.

Having multiple instance of the same system will allow me to have
multiple threads running the same operation in parallel.
Each system can decide to skip his update if it already has a thread running...

Is this possible ?
Is my design of Systems/vs/Thread not the best way ?

Thanks for any insights...

--
AlexV

Re: [entityx] Multiple Instances of one System class.

From:
Alec Thomas
Date:
2014-07-10 @ 03:53

On Thursday, 10 July 2014 at 1:33 pm, Asmodehn Shade wrote:

> Hello,
> 
> Given the interface :
> system_manager->add<Systems::Mysystem>();
> and :
> system_manager->update<Systems::Mysystem>(dt);
> 
> I was wondering if it was possible to use multiple instances of the same system.
> If so, how am I supposed to use them ?
> 
> 

Within one SystemManager? No, that is not possible. I would run multiple 
threads inside one System. 
> 
> I am using each system instance to wrap a "one thread only" behavior.
> That thread is triggered (or not) during the update.
> 
> Having multiple instance of the same system will allow me to have
> multiple threads running the same operation in parallel.
> Each system can decide to skip his update if it already has a thread running...
> 
> Is this possible ?
> Is my design of Systems/vs/Thread not the best way ?
> 
> Thanks for any insights...
> 
> --
> AlexV
> 
> 

Re: [entityx] Multiple Instances of one System class.

From:
Asmodehn Shade
Date:
2014-07-12 @ 03:01
Hello,

Well having multiple thread in one system would have made my code a
bit too complex.
So in the end, I encapsulated one thread in one component.

I know a component is supposed to stay as simple as possible, with
little to no functionality in it... but I see now how components can
be used to integrate old C interface, based on state machine design (
constructor of component inits, destructor cleanup ), and entity
system can provide another layer of complexity with potentially more
advance behavior...
Code available there :

https://github.com/asmodehn/WkCocos/blob/develop/Include/WkCocos/Loading/Comp/CurlDL.h

This seems to work fine for me so far... but while doing this, I was
wondering how thread safe is entityx...
Entity systems are supposed to be a help if we want to multithread
things, because the complex code is already divided between multiple
system. so in theory it would be quite simple to run one system in one
thread. but in my case I kept multithread at the component level...

Any information about this topic ? How can we use threads with entityx
and still be safe ?

Thanks a lot.
--
AlexV


2014-07-10 12:53 GMT+09:00 Alec Thomas <alec@swapoff.org>:
>
> On Thursday, 10 July 2014 at 1:33 pm, Asmodehn Shade wrote:
>
> Hello,
>
> Given the interface :
> system_manager->add<Systems::Mysystem>();
> and :
> system_manager->update<Systems::Mysystem>(dt);
>
> I was wondering if it was possible to use multiple instances of the same
> system.
> If so, how am I supposed to use them ?
>
> Within one SystemManager? No, that is not possible. I would run multiple
> threads inside one System.
>
>
> I am using each system instance to wrap a "one thread only" behavior.
> That thread is triggered (or not) during the update.
>
> Having multiple instance of the same system will allow me to have
> multiple threads running the same operation in parallel.
> Eac h system can decide to skip his update if it already has a thread
> running...
>
> Is this possible ?
> Is my design of Systems/vs/Thread not the best way ?
>
> Thanks for any insights...
>
> --
> AlexV
>
>

Re: [entityx] Multiple Instances of one System class.

From:
Alec Thomas
Date:
2014-07-13 @ 22:41

On Saturday, 12 July 2014 at 1:01 pm, Asmodehn Shade wrote:

> Hello,
> 
> Well having multiple thread in one system would have made my code a
> bit too complex.
> So in the end, I encapsulated one thread in one component.
> 
> I know a component is supposed to stay as simple as possible, with
> little to no functionality in it... but I see now how components can
> be used to integrate old C interface, based on state machine design (
> constructor of component inits, destructor cleanup ), and entity
> system can provide another layer of complexity with potentially more
> advance behavior...
> Code available there :
> 
https://github.com/asmodehn/WkCocos/blob/develop/Include/WkCocos/Loading/Comp/CurlDL.h
> 
> This seems to work fine for me so far... but while doing this, I was
> wondering how thread safe is entityx...
> Entity systems are supposed to be a help if we want to multithread
> things, because the complex code is already divided between multiple
> system. so in theory it would be quite simple to run one system in one
> thread. but in my case I kept multithread at the component level...
> 
> Any information about this topic ? How can we use threads with entityx
> and still be safe ?
> 
> 


I think the easiest way would be to take a copy of the component data you 
need to act on. That would require only one lock per update cycle, vs. 
potentially many locks if 
 EntityX were managing per-entity or per-component locks. The copy 
overhead is not ideal, but at least it gives absolute control over lock 
contention to the end developer.
> 
> Thanks a lot.
> --
> AlexV
> 
> 
> 2014-07-10 12:53 GMT+09:00 Alec Thomas <alec@swapoff.org 
(mailto:alec@swapoff.org)>:
> > 
> > On Thursday, 10 July 2014 at 1:33 pm, Asmodehn Shade wrote:
> > 
> > Hello,
> > 
> > Given the interface :
> > system_manager->add<Systems::Mysystem>();
> > and :
> > system_manager->update<Systems::Mysystem>(dt);
> > 
> > I was wondering if it was possible to use multiple instances of the same
> > system.
> > If so, how am I supposed to use them ?
> > 
> > Within one SystemManager? No, that is not possible. I would run multiple
> > threads inside one System.
> > 
> > 
> > I am using each system instance to wrap a "one thread only" behavior.
> > That thread is triggered (or not) during the update.
> > 
> > Having multiple instance of the same system will allow me to have
> > multiple threads running the same operation in parallel.
> > Eac h system can decide to skip his update if it already has a thread
> > running...
> > 
> > Is this possible ?
> > Is my design of Systems/vs/Thread not the best way ?
> > 
> > Thanks for any insights...
> > 
> > --
> > AlexV
> > 
> 
> 
>