Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 7:27 am

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11 ... 28  Next
Author Message
 Post subject:
PostPosted: Thu May 19, 2011 2:59 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
Hi appel, it's me again!!

I was wondering if there is an easy way to disable a component on an entity so this entity is not being processed in the corresponding system. For example, disable vulnerability (or HealthComponent) for a while to make an entity invulnerable. Removing the component and adding again would mean I have to hold the component in some place while it is "removed".

Possible solutions in mind:

* Having an extra component named InvulnerableComponent and, when processing the DamageSystem see if the entity has the InvulnerableComponent (and/or if it is enabled too).

* Modify my HealthComponent to hold a boolean vulnerable (enabled) and do not process it when processing the DamageSystem if it is false.

* Extract that logic to another class named Health or Whatever and hide there the fact that the object is invulnerable in some way (maybe an internal field or maybe different implementations) and when the DamageSystem says health.doDamage(50120401204120) the health class says "hahahah, in your dreams baby!! I am invulnerable!! damn.. that is supposed to be a secret". (I think I like this one)

* Remove the component and hold it on some place (wakale!) and then adding it again.

If there is no easy way to enable/disable a component, which of the previous solutions do you think it should be the most appropriate?

Thanks in advance.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2011 4:31 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
arielsan wrote:
Hi appel, it's me again!!

I was wondering if there is an easy way to disable a component on an entity so this entity is not being processed in the corresponding system. For example, disable vulnerability (or HealthComponent) for a while to make an entity invulnerable. Removing the component and adding again would mean I have to hold the component in some place while it is "removed".

Possible solutions in mind:

* Having an extra component named InvulnerableComponent and, when processing the DamageSystem see if the entity has the InvulnerableComponent (and/or if it is enabled too).

* Modify my HealthComponent to hold a boolean vulnerable (enabled) and do not process it when processing the DamageSystem if it is false.

* Extract that logic to another class named Health or Whatever and hide there the fact that the object is invulnerable in some way (maybe an internal field or maybe different implementations) and when the DamageSystem says health.doDamage(50120401204120) the health class says "hahahah, in your dreams baby!! I am invulnerable!! damn.. that is supposed to be a secret". (I think I like this one)

* Remove the component and hold it on some place (wakale!) and then adding it again.

If there is no easy way to enable/disable a component, which of the previous solutions do you think it should be the most appropriate?

Thanks in advance.


I would not remove HealthComponent, because you might be rendering health status somewhere, like of a temporary invulnerable unit in a RTS game.

I would favor the InvulnerableComponent, which could also contain a timeout for the invulnerability feature.

Problem with having it as a InvulnerableComponent is that the HealthSystem/DamageSystem would need to check for it, and thus have knowledge of this feature.

But I'd start with that and see how it works and feels.



Also, components are only supposed to have getters/setters for data, they are not meant to have logic, like responding with some message.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 1:16 am 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
An alternative to Appel's suggestion would be to have a boolean check HealthComponent.isInvulnerable() in your HealthSystem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 1:40 am 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
Yeah, I end adding a resistance field to the HealthComponent and adding an InvulnerableComponent, so when the InvulnerableSystem detects the invulnerable component it sets HealthComponent resistance to the maximum.

@appel, when I said about health.doSomething I wasn't talking about the component itself but another class external to the HealthComponent. An example:

HealthComponent
- Health

And having different implementations of the Health class (or even interface).

@both

Thanks for the answers

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 6:10 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
The InvulnerableComponent approach can get bad if you have a lot of player status on the game and add a Component for everyone because of the 64 bit limit, doesn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 7:01 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
thelinuxlich wrote:
The InvulnerableComponent approach can get bad if you have a lot of player status on the game and add a Component for everyone because of the 64 bit limit, doesn't it?


True.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 7:05 pm 
Offline

Joined: Wed Mar 09, 2011 10:40 pm
Posts: 49
Could'nt the 64 system limit be fixed by using something like a BigInteger? You dont need a very large game before it becomes a problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 8:04 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Uberrated wrote:
Could'nt the 64 system limit be fixed by using something like a BigInteger? You dont need a very large game before it becomes a problem.


It's easy to solve, I already had BitSet, but used long instead due to performance reasons.

Running the EntitySystem.change() check takes:
- Using BitSet takes 14227423 nanoseconds. (14 ms)
- Using long takes 564766 nanoseconds. (0.56 ms)

BitSet is 25 times slower.

I assume BigInteger would be similarly slow as BitSet.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2011 8:56 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Better go with StatusComponent, with a type attribute with a lot of enums then :D


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 1:29 am 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
I'm trying to run EntitySystems in separate threads but I can't get it to work. I believe the problem is with world.loopStart().

This would be a very nice enhancement to your EntitySystem framework.

What I am doing is spawning threads that each contain their own EntitySystem and process it.

I'm not getting very far.. I have world.loopStart() and world.setDelta() in their own thread.

Maybe a way to check if loopStart has been called or if the loopStart method has already performed its function would help with making the library asynchronous.

Edit: I made my own World obj extending World and did this manually. Will post a follow up of my results later.

Edit2: IntervalEntitySystems are giving me problems... they don't execute right. Must be the way they are handled internally?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 3:41 am 
Offline

Joined: Sun May 29, 2011 5:31 am
Posts: 6
Location: Texas
Squizzle wrote:
What I am doing is spawning threads that each contain their own EntitySystem and process it.


That sounds like you are going to have a bunch of threads competing for resources.

_________________
My Github - https://github.com/warmwaffles


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 4:40 am 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
You are right it uses too much CPU on my dual core (almost 100% which is both cores lol). So the ability to skip a entitysystem that is still being processed would be more ideal. And I can do that myself without needing any changes to Artemis.

Amazing what a temporary break from coding can do to refresh your perspective.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 9:03 am 
Offline

Joined: Mon May 30, 2011 8:48 am
Posts: 3
Very nice framework!

I'm working on porting it to C++ right now. :D


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 9:22 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Squizzle wrote:
I'm trying to run EntitySystems in separate threads but I can't get it to work. I believe the problem is with world.loopStart().

This would be a very nice enhancement to your EntitySystem framework.

What I am doing is spawning threads that each contain their own EntitySystem and process it.

I'm not getting very far.. I have world.loopStart() and world.setDelta() in their own thread.

Maybe a way to check if loopStart has been called or if the loopStart method has already performed its function would help with making the library asynchronous.

Edit: I made my own World obj extending World and did this manually. Will post a follow up of my results later.

Edit2: IntervalEntitySystems are giving me problems... they don't execute right. Must be the way they are handled internally?


You should go for lockstep mode.

In lockstep you process the systems in parallel, but setting delta and loopStart should be done before the parallel processing starts.

You can achieve this by using cyclic barriers (CyclicBarrier in Java).

So, main thread:
1. Sets delta and loopStart.
2. Initiates cyclicBarrier that executes all threads to process the systems.
3. Waits for cyclicBarrier to complete.
4. Done, and restart loop.


I could also instead of having each system as it's own thread, have a pool of workers that equals to the number of cores on your machine, and have it consume jobs from a system pool. So, just good old Producer-Consumer pattern here, where processing a entity system is a job.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 1:17 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Sceptrix wrote:
Very nice framework!

I'm working on porting it to C++ right now. :D


Let me know how that goes, and I'll add it to the "ports" list.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11 ... 28  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group