Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 7:02 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 ... 24, 25, 26, 27, 28
Author Message
PostPosted: Wed Aug 08, 2012 11:36 pm 
Offline

Joined: Tue Jul 17, 2012 12:46 pm
Posts: 12
In my case this is my code:

Code:
virtual void processEntities(artemis::ImmutableBag<artemis::Entity*>& bag)
{
   creatCollisionBuckets(bag); // Seperate objects into their own space coordinates.
      
   for(int i=0; i< collisionBuckets->getCapacity(); i++) // loop trough our complete grid
   {
      artemis::Bag<artemis::Entity*> * bucket = collisionBuckets->get(i);
                     
                // If our bucket is empty or has one continue.
      if(bucket->isEmpty() || bucket->getCount() == 1) continue;

      for(int j=0; j < bucket->getCount(); j++) // Check bucket against itself index j
      {
             artemis::Entity& ej = *bucket->get(j);

         for(int k=j+1; k < bucket->getCount(); k++) // index k
         {
            //Do collision action
            artemis::Entity& ek = *bucket->get(k);

             //Perform collision relevance            
              // if allowed do intersection check
            if(intersects(ej,ek)){
            // ej collides with ek.
                          ****
            }
         }
      }
   }
}


At line **** this is where I should perform the action. I could create a new object that does all the if and else check for components and what not. But since Artemis has this autonomous design I thought I should work in such fashion. So it really can't do harm asking whether the entity has component X or Y outside any System?


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 1:42 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Just doing a general collision check against all collidable objects is not really useful, you need to go further.

Bullets should not hit other bullets, only actors like ships, tanks or whatever you have in your game.
Furthermore, bullets should not hit all actors, only enemy actors.

This all depends on the realism you want for your game of course, but most collision implementations I've seen in games depends on groups of entities colliding with each other, e.g. bullets collide with actors. Then you can add further collision check like bullets only hit actors if they don't belong to the same team or player.

You're doing a grid based collision check, that's all fine and dandy. Where you have **** you need to execute a list of your more fine grained collision checkers that you've added to your system.

e.g.:

Code:
collisionSystem.addGroupToGroupCollisionHandler(Groups.Bullets, Groups.Actors, new CollisionHandler() {
  @Override
  public void check(Entity bullet, Entity actor) {
     if(teamManager.getTeam(bullet) != teamManager.getTeam(actor)) {
        // You decide what to do with bullet, most likely just: bullet.delete();
        // And you'll most likely just decrease health of actor here,
        // or add a new component to entity specifying some action to
        // be processed by another system.
     }
  }
});


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 2:51 am 
Offline

Joined: Tue Jul 17, 2012 12:46 pm
Posts: 12
appel wrote:

Bullets should not hit other bullets, only actors like ships, tanks or whatever you have in your game.
Furthermore, bullets should not hit all actors, only enemy actors.


I'm aware of that, I left some code out. I check validity between objects. And only if they are valid then only a collision is checked.
My collision components hold an id which is an enumerator type. So for a bullet the id is BULLET. so if both items are of BULLET, they are ignored and the loops continues.
I could use the grouping functions, but then I shouldn't be using a system in the first place since processEntities is always called. The bag parameter becomes pointless then.

That wasn't exactly my problem. It's how I should act upon the collision check. I'm looking for a clean way to check what my entity holds.
But it looks from the answers that the only way to process them is check with if/else on whether it holds a component or not


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 9:30 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Quote:
If so then perform action depending on their components.


Well... if a bullet entity has A and B components, but actor entity has A, B and C components, then adding X "action" component to both entities so a collision handling system can process it:

CollisionHandlingSystem1(A.class, B.class, C.class, X.class).process() // remove X component here so later systems don't re-process it.
CollisionHandlingSystem2(A.class, B.class, X.class).process()


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 12:29 pm 
Offline

Joined: Tue Jul 17, 2012 12:46 pm
Posts: 12
Quote:
// remove X component here so later systems don't re-process it.


I'm confused about this, if I remove component x there, it will never reach the other systems right?
Could you clarify your intent?


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 12:39 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Sidar wrote:
Quote:
// remove X component here so later systems don't re-process it.


I'm confused about this, if I remove component x there, it will never reach the other systems right?
Could you clarify your intent?

X component is simply used as an event here, fired into the system that processes it first (and then consumes the event/component by deleting it).


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 1:43 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
What I was suggesting was to process the collision detection in one system and then in other systems process your custom logic based on the collision state.

For example, suppose you have a CollisionComponent:

Code:
CollisionComponent {
   bounding box;
   entities in contact;
}


On the CollisionSystem you just update the state with the new contacts, but you do no game specific logic. Based on your example:

Code:
         
  // first thing is to clear all the contacts from the previous state

  .....

  if(intersects(e1,e2)){
                          e1.getComponent(CollisionComponent).addContact(e2);
                          e2.getComponent(CollisionComponent).addContact(e1);
  }


Then, you have a DamageSystem or whatever, and you handle HealthComponent and CollisionComponent, then for each entity you get the entities in contact from the CollisionComponent and check if they have the DamageComponent to apply the damage.

As we are using Box2d, we predefined some collision flags to define which kind of entities collides with which other types, so in our case projectiles only collide with enemies, and that improves a lot exploring the entities in contact.

_________________
Image


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 2:08 pm 
Offline

Joined: Tue Jul 17, 2012 12:46 pm
Posts: 12
Thanks both of you.

I still have to think this trough. Completely depleted at this moment.
In my case I really don't use physics though. I'm making a Shoot 'em up ( like R-type, Gradius) and just check simple AABB collisions ( I might add circle collision, but that is something for later). Nothing fancy.

But I guess the contact solution sounds plausible for my problem. ( I should probably go with different semantics )


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 2:28 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
Right, I just wanted to share the idea with the example, we don't even use those semantics.

_________________
Image


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 4:18 am 
Offline

Joined: Fri Aug 10, 2012 3:58 am
Posts: 1
Forgive my ignorance, but could someone please explain the concept of "spatials"?
Is it in any way related to the "scripting" concept defined here? Is this the way I would define entity specific logic, such as rendering and AI, or would I divide that up into cases within the appropriate systems?


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 5:08 pm 
Offline

Joined: Tue Jul 17, 2012 12:46 pm
Posts: 12
Isn't spatials concerned with space?
Like the x and y components of a position, or separating objects into different data structure and such for A.I and collision?


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 5:13 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
We consider Spatial as the location information of an entity, for example, in 2d you could consider x,y, and angle. And no, Spatial concept is not related with Scripting although you probably would access the Spatial of an entity from a Script.

_________________
Image


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 5:46 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Well, this is more of a definition issue.

Spatial is something that you can see, and exists in space, hence the name spatial.

A spatial without a position in the space, makes no sense. But you could still have non-spatial (invisible) entities that have position in space, such as triggers at a certain location.

So, spatial in my mind is the look of the entity, the form of it, perhaps a model or some sprite. Bundled with a position it's something that a rendering system can process.


Scripting is all about loading some external script file and run its logic.


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 5:55 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
I believe Spatial(Component) is related with location the game world, mainly that, if you want more information you could have more components, that is the nice part of an entity engine, you define what you need for your game. Your SpatialComponent could have all the info you want or you could define multiple components to be more modular, etc. For example, in our case, to render an Entity we need a SpatialComponent + a component with render information, by having only a SpatialComponent the entity is not renderable. If you are on a 2d world you could use a SpriteComponent with information of the image you want to render and other info. I believe Spatial/Location concept should be treated as part of one layer over Artemis/Apollo like all other game dependent concepts.

_________________
Image


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 6:16 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
arielsan wrote:
I believe Spatial(Component) is related with location the game world, mainly that, if you want more information you could have more components, that is the nice part of an entity engine, you define what you need for your game. Your SpatialComponent could have all the info you want or you could define multiple components to be more modular, etc. For example, in our case, to render an Entity we need a SpatialComponent + a component with render information, by having only a SpatialComponent the entity is not renderable. If you are on a 2d world you could use a SpriteComponent with information of the image you want to render and other info. I believe Spatial/Location concept should be treated as part of one layer over Artemis/Apollo like all other game dependent concepts.


True enough. Maybe keeping a simple design is better. Spatial contains both position and transformational information on a entity. If it's an invisible entity like a trigger, then well, it surely would have an invisible box for collision purposes!


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 ... 24, 25, 26, 27, 28

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