1
\$\begingroup\$

I've read through this post Interactions between game objects but it doesn't really address my question.

Background assumptions:

  • Maximum number of possible objects and the game still runs
  • Maximum sized game world and the game still runs
  • Game world is partitioned into sectors
  • Having an object/process at the game loop level to decide what objects are aware of what would be a bottleneck

The goal is feed an arbitrary game object the data it needs to do its thing.
The question is how should i go about doing this without some global god object/process that sits at the game loop level?

What I thought of (simplified):

Method 1 involved a list of all the objects. This would be the god object. Each game loop, determine an objects perception range, and pull the objects that fit.

Method 2 involved an event stream for each sector. A god process would look at the range of the object and put it into the sector's streams that are in range of the event. At each game loop, the god process would feed the object the streams of the sectors that are in its perception range.

Why I don't want a god object: How to avoid the GameManager god object?

Unfortunately, I'm not sure if the solutions outlined in that question really helps, as the "problem" recognized in that post is poor programming habits/design. At its core, the post and all the answers take for granted that the god object must exist. What I am after is to see if there's a way for objects in the world to be aware of each other without the all seeing eye.

In the real physical world, things do not commune with god, or gods, or the akashic record, or some other esoteric entity in order to be aware of and interact with each other. Things will do their thing and each thing relies on whatever method of sensing they were born with to do their thing.

It might be because of my limited imagination/knowledge/experience that I don't know how to replicate how the world works digitally or it might be because this is not possible. I don't know, hence this post.

\$\endgroup\$
  • \$\begingroup\$ To confirm: you're looking to somehow maintain/query, for each of a set of entities, the collection of entities that are within that entity's awareness radius? (And entities can have different associated radii, so this relationship might not be mutual, correct?) Can you describe why you've included the "without a god object" constraint? It seems like some shared data/logic could help to reduce redundant/duplicated work in some situations like these. \$\endgroup\$ – DMGregory Dec 27 '17 at 2:08
  • \$\begingroup\$ @DMGregory Yes and Yes. I feel like the god object would be a problem down the line in terms of cost, performance, and maintainability of the program as a whole. This is from my experience as a developer in business systems rather than a game dev. These types of objects tend to be convenient in the beginning but put serious constrains on the flexibility and and agility of the dev team in the long run. As the reliance on the god object grows, inertia builds and it becomes very hard to even think about making changes to the object for fear of the entire system breaking. \$\endgroup\$ – ton.yeung Dec 27 '17 at 3:47
  • \$\begingroup\$ and to clarify, the entire purpose is to give a way for the game objects to be aware of their environment and this is how I'm planning on implementing it. I'm trying to avoid reinventing the wheel but I could not find any posts on the subject when googling so this is what I came up with after kicking the idea around with a few colleagues. \$\endgroup\$ – ton.yeung Dec 27 '17 at 3:52
  • \$\begingroup\$ Added some clarification to the question itself. \$\endgroup\$ – ton.yeung Dec 27 '17 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.