Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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 9436 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
« Reply #31 - Posted 2012-04-24 05:04:55 »

Quote
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
Online princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 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 Member


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
« 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.


“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline DruLeeParsec

Junior Member


Medals: 2
Projects: 1



« 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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!