Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (725)
Games in Android Showcase (216)
games submitted by our members
Games in WIP (791)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Recommended architecture to allow entities to access each other's data.  (Read 1000 times)
0 Members and 1 Guest are viewing this topic.
Offline unlight
« Posted 2016-12-26 04:14:28 »

Hi guys,

I'm looking for some advice or resources on game programming patterns / architectures that are most appropriate to handle interactions between entities in games. To give some background, I am currently designing a game mechanic where projectiles are launched in space and affected by the orbital gravity of planets (similar to Angry Birds in Space). In this case, the projectile entities need to be aware of the positions of the planet entities in order to calculate their velocities due to gravity. They also need to be aware of other projectile entities for collision detection.

After doing some research I have come up with the following potential solution:

  • Create an entity management class to store reference to all entities.
  • Pass entity manager to entities during construction.
  • During game loop update, the projectile objects can access the planet objects via the entity manager class to calculate velocity and collision detection.

However, it seems like the point of having an entity manager is so that the entity manager can perform the collision detection so that the entity classes do not need to know of one another. However, the entity manager would then also need to calculate the velocities for each projectile, per update, and this is where i get confused.

I get that I can simply pass a planet entity list to the projectile class update function, but what about in big games where many entities require information on each other to function correctly?

I would really appreciate if anyone can share any resources that could help me build a pretty architecture for this, or how they handle these types of interactions themselves.

Getting my head around programming architectures is the reason I enjoy game programming.
Offline 65K
« Reply #1 - Posted 2016-12-26 07:35:31 »

When you need to look at the whole picture or need all objects of a kind for a task, it is a good approach to create new separate classes that perform such tasks. But don't call any class "Manager". It the most abused and meaningless name you can think of. What you want is a physics simulation and collision detection. It might make sense to integrate both into one PhysicsSimluator or have two classes. Depends on your approach on physics simulation.

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
Offline unlight
« Reply #2 - Posted 2016-12-26 08:06:20 »

This does sound like a cleaner approach, do you happen to know of any resources or examples that I could have a look through? I'm having difficulty finding the right words to Google.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online tariqbroadnax

Junior Devvie


Medals: 1
Exp: 3 years



« Reply #3 - Posted 2016-12-26 09:01:25 »

I recommend:

  • Create a Scene class that stores and updates everything related to your game
  • Create a CollisionManager class that checks for collisions. The Scene class should store the CollisionManager and update it.
  • Create a data structure that group entities by their location for faster collision detection and faster access of entities in certain areas
  • Give a every entity a reference to the scene so that they can access any entity
  • Have every relevant entity store a list of vectors for each force/accel that they are feeling
  • Have every relevant entity update its position and vel based on these vectors
  • Create a Planet class that gives and updates force vector to every relevant entity
Offline 65K
« Reply #4 - Posted 2016-12-26 09:25:00 »

The basic architecture is (and should be) very simple, for example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
public class EntityModel {
   List<Entity> getEntities();
   List<Entity> getPlanets();
   List<Entity> getProjectiles();
}

public class PhysicsSimulator {
   public void update(long time) {
      // place to tear your hair by simulating gravity effects...
      for (Entity entity : entities) {
         ...
         entity.getMass()
         ...
         entity.setVelocity(...)
         ...
      }
   }
   
   private EntityModel entityModel;
}


Think of having controllers and models. Controllers do the action and know the model. Not vice versa.
This will massively help in keeping code dependencies and data flow under control.

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
Offline unlight
« Reply #5 - Posted 2016-12-26 12:44:29 »

Wow, thank you so much for the advice guys. I wouldn't have thought to maintain my projects in this way, there is still much to learn about effective software development!
Pages: [1]
  ignore  |  Print  
 
 

 
Archive (59 views)
2017-04-28 11:45:51

buddyBro (271 views)
2017-04-05 21:38:00

CopyableCougar4 (695 views)
2017-03-25 09:39:42

theagentd (696 views)
2017-03-25 09:32:08

Rule (738 views)
2017-03-20 06:43:22

Rule (713 views)
2017-03-20 06:42:17

Rule (717 views)
2017-03-20 06:36:21

theagentd (727 views)
2017-03-16 23:07:07

theagentd (660 views)
2017-03-16 16:37:06

theagentd (501 views)
2017-03-16 16:32:18
List of Learning Resources
by elect
2017-03-14 08:05:44

List of Learning Resources
by elect
2017-03-14 08:04:45

SF/X Libraries
by philfrei
2017-03-03 02:45:19

SF/X Libraries
by philfrei
2017-03-03 02:44:05

SF/X Libraries
by SkyAphid
2017-03-03 00:38:56

SF/X Libraries
by SkyAphid
2017-03-03 00:38:32

SF/X Libraries
by SkyAphid
2017-03-03 00:38:05

SF/X Libraries
by SkyAphid
2017-03-03 00:37:51
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!