Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  The base of an entity system  (Read 23200 times)
0 Members and 1 Guest are viewing this topic.
Offline lhkbob

JGO Knight

Medals: 32

« Reply #30 - Posted 2012-04-23 20:27:38 »

I've seen millisecond gains, even with just 1000s of entities, when converting to a framework that does mapped objects. When you're limited to 16ms for a single frame, a millisecond here and there is pretty important.  You don't have to wait until you're processing millions of entities for the performance to become worth it.

I agree that Java doesn't make it the easiest to apply entity-component systems, but I think the decoupling data from methods can lead to more flexible design. Sure this isn't the only way to do it, but it is a way.  But if you're new to development and don't care about that sort of thing, then it's not very important to get it either.

As an example of why I decided to use components for my games is in material description: I have components for describing the different sources of diffuse coloring, they can optionally add emissive textures, or normal maps to turn on bump-mapping.  They can use a different lighting model than Blinn-Phong but that still requires diffuse/specular colors.  This can be conveniently described with a proper set of components.

Offline Roquen

JGO Kernel

Medals: 518

« Reply #31 - Posted 2012-04-24 05:04:55 »

I've seen millisecond gains, even with just 1000s of entities
Yes. Minimizing memory motion (and related issues like cache invalidation) are always a win.  My 1 mill number stems from when you get to very high loads it gets to be super fiddly if you really want to maximize throughput.  And in this situation using a well built component based systems "might" make sense.

Personally if I were to walk this path I'd punt and write a DSL.  Also since Java doesn't current support structures and arrays of structures I'd build on top of C or C++.

WRT: Material system.  I'm not getting your point.  What does that have to do with a component based model?
Offline lhkbob

JGO Knight

Medals: 32

« Reply #32 - Posted 2012-04-24 05:59:52 »

WRT: Material system.  I'm not getting your point.  What does that have to do with a component based model?

I found it to be a useful reason in my case to use a component based system, even if I don't need the performance. It was mainly to point out that it is possible to find circumstances where the entity-component model isn't useful purely for serious performance reasons. I could, and previously did, put all of my material logic into various OO types but they always progressed into a component model, so for me the performance gained from a mapped-object entity system is just extra win.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »

Medals: 1064
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #33 - Posted 2012-04-24 07:38:40 »

Hmm... you sure you're not really just talking about composition rather than the whole "entity system" concept?

Cas Smiley

Offline lhkbob

JGO Knight

Medals: 32

« Reply #34 - Posted 2012-04-24 15:45:03 »

Sure, any other way of composing material descriptors could and would work.  But when you have a problem that can actually be solved by composition, why not use an entity-component framework?  It's one possible solution and if it jives with the way you think, why not use it?

Offline OttoMeier

Senior Devvie

Medals: 4
Projects: 1

« Reply #35 - Posted 2012-04-24 19:05:14 »

I dont use an entity sytem cause:
-only a few hundred entities
-dont need to change the game at runtime cause i am the only one involved and i have the debugger anyway
-dont need scipting support cause nobody willl write mods for the game and java compile time is irrelevant
-dont want to learn or create another engine wich is maybe fun but also stop me from coding the game

So instead i do composition over inheritance and avoid deep inheritance hierarchy wich is imho best practise.

i think the points are valid for most projects in this forum.
Offline Roquen

JGO Kernel

Medals: 518

« Reply #36 - Posted 2012-04-24 19:24:31 »

To make a brief nod to the OP.  There are two problems in attempting to answer your question.  The first is that there will major lack of agreement regardless (as you're seeing).  And the second is that it's an impossible to answer question without know what your background is and what it is that you want to do.
Offline SkyAphid
« Reply #37 - Posted 2012-05-11 12:21:07 »

I usually make an ArrayList of a class called Entity that all of the other entities extend. Then, I use a comparator to order the list according their y positions so that they're drawn in a fashion where the lower objects are drawn over the higher ones.

it just werks
Offline DruLeeParsec
« Reply #38 - Posted 2012-05-11 14:32:49 »

My Entity class has x & y locations, an image, an enum of EntityType which tells me if it's a player object, opponent object, player projectile, opponent projectile etc.  My entity class also has hit points so I know how much damage it can take.  Entity does not move.  About the only time I use this base class by itself is if I want to place an object on the background.  That object doesn't move and usually has no collision properties.  Entity has getImage() doUpdate(container, game, delta) and doRender(Graphics g) which all other entities inherent.  It also has some booleans such as isCollidable and isVisible so I can turn collisions on and off and make them visible or not.

The Entity class also has my collision rectangles. Normally it's just the rectangle of the image but I also have a list of rectangles which I use for oddly shaped sprites.  Rectangle collision detection is fast and easy.  Java's Rectangle2D.Float extends RectangularShape which has the method public boolean intersects(Rectangle2D r) which is fast and precise enough for my needs.

Then I have a MovableEntity object which extends Entity.  That has dx/dy speed,  acceleration rate , deceleration rate and max speed.

I have a Startable entity which extends MoveableEntity.  This is a class where I can set my dx/dy but not have the entity move until I give it the start command.  This way I can set up objects offscreen and start them moving into the screen when I want to.

I also have ControllableEntity which extends MoveableEntity.  This entity can be bound to keyboard or game controller events and can change the dx/dy, speed, and acceleration of the entity.

I recently added AnimatedEntity which will go between Entity and MoveableEntity.  This way I can animate any of my entities as I do other things as well.

I created a Projectile class which extends MovableEntity.  The Projectile knows if it has moved offscreen and if so places itself back into the bullet pool.  Things which extend Projectile overload the image in the base class Entity with a static image so all the projectiles of a single type are using the same image in memory.

I place different entities in different Arraylist.  My GameLevel class has these list:

   private ArrayList<Entity> backgroundEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> midLevelEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> opponentEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> postOpponentEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> playerEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> postPlayerEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> hudEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> messageEntityList = new ArrayList<Entity>();

   private ArrayList<Entity> playerProjectileEntityList = new ArrayList<Entity>();
   private ArrayList<Entity> opponentProjectileEntityList = new ArrayList<Entity>();

These list allow me , for example, to draw all the background images, player images, opponent images, etc all in correct Z order.  The 2 projectile list in particular make it easier to pool bullets.  The postPlayer and postOpponent list allow opponent images to come out of caves which the player can fly over, or for the player to fly under a bridge.

The HUD list always paints next to last so the HUD (Heads Up Display) is on top of everything.

The Message list paints last.  I use this for menu items and messages which need to paint on top of everything.

In my game loop I walk through every list in order and call the doUpdate of every entity.  Then I do the same thing with doRender and it all works by itself.

Pages: 1 [2]
  ignore  |  Print  

hadezbladez (1095 views)
2018-11-16 13:46:03

hadezbladez (498 views)
2018-11-16 13:41:33

hadezbladez (1087 views)
2018-11-16 13:35:35

hadezbladez (251 views)
2018-11-16 13:32:03

EgonOlsen (2540 views)
2018-06-10 19:43:48

EgonOlsen (2740 views)
2018-06-10 19:43:44

EgonOlsen (1544 views)
2018-06-10 19:43:20

DesertCoockie (2248 views)
2018-05-13 18:23:11

nelsongames (2082 views)
2018-04-24 18:15:36

nelsongames (2777 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!