2
\$\begingroup\$

I'm writing a simple physics based game in C++ using SFML. I want to trigger a scene change when my playerCharacter collides with a door. Since C++ does not have any native Event Sender/Listener system, I'm not sure how I should organize my architecture such that entities can trigger events within the world, or within other entities they are not colliding with directly. These are the only ways I can think of;

  1. Entities all have a reference back to the scene/world. This is what I'm doing currently but I keep hearing it's horrible design.

  2. Have the scene/world call methods on the entities to check if they are making changes. This seems like a terrible solution, I would have to check for any possible change.

  3. I integrate a premade C++ Event system. I'm happy to do this, I just want to first make sure there isn't a more simple approach I'm missing.

  4. Interfaces between classes. I keep hearing this a solution, but I don't know how ti really solves anything. If my Entity and Scene objects both have references to the interface, and have to base functionality around that- isn't that just as bad?

  5. Messaging system. This actually seems like a good approach, but I'm not sure if it's intended to be a comprehensive solution. Here it is in detail: How to implement the interaction between engine parts?

Please let me know if you have any solutions for this specific issue, or perhaps some sort of class diagram that circumvents this issue completely. I've been looking a while and haven't found a solution for this issue. How do the major engines do it?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ How do the major engines do it? is not super relevant to your situation. What is your current architecture? How are your entities organized and how do you trigger those events at the moment? \$\endgroup\$
    – Vaillancourt
    Commented Jun 26, 2020 at 22:05
  • \$\begingroup\$ I haven't filled all the trigger in yet, so there isn't a current implementation. My entities are just in a long linkedlist per level. They all get drawn in 2d each loop. The player has a reference to the scene object so it just calls the load directly when it collides with a door. I want the entities to be able to trigger something in other entities, though. I'm not sure how to go about it other than just letting everything reference each other, or having some sort of place where they can look each other up. \$\endgroup\$ Commented Jun 26, 2020 at 23:08
  • 1
    \$\begingroup\$ It's hard to give you super precise help given that you don't give us details of how you're currently doing things. Generally speaking, if a certain architecture works for you and your game and you don't foresee any issue with it, go with it, it's not worth it to fix issues that do not exist. \$\endgroup\$
    – Vaillancourt
    Commented Jun 27, 2020 at 0:56
  • 1
    \$\begingroup\$ That makes sense. I've had a growing realization lately that I spend too much time refactoring, trying to code things how they "should be" and not enough time just making things work and moving on. Thank for your time, I appreciate the response. \$\endgroup\$ Commented Jun 27, 2020 at 20:51

0

You must log in to answer this question.

Browse other questions tagged .