jwfwessels / AFK

Automated Battle Ground.
MIT License
1 stars 1 forks source link

Decouple Game and Graphics Engines entirely. #9

Open danini-the-panini opened 11 years ago

danini-the-panini commented 11 years ago

In light of what Dr. Solms mentioned at the demo, as well as the exchange of emails between us, I have come to the conclusion regarding the interactions between Tokyo and the Graphics Engine. I believe that the two are too intertwined, despite the fact that Tokyo speaks to Athens purely through an [interface/abstract class].

My idea is that, through some kind of observer design pattern we can leave the representation entirely up to a third party (such as the frontend) or a fourth party (such as a component specially designed to transform Game States into drawables). The communication is described in figure 1.

    +-------------+                     +--------------+
    |    Game     |                     |   Graphics   |
    |   Engine    |                     |    Engine    |
    +---------+---+                     +--------------+
        ^     |                                 ^
        |     | 1. Notify observer to draw      |
        |     |                                 |
        |     |                                 |
        |     |                                 |
        |     |       +---------------+         |
        |     +------>|               |         |
        |             |   Observer    +---------+
        +-------------+               |  3. Tell Graphics Engine
 2. Read game state   +---------------+     to draw

Figure 1. Communication flow in the Observer Pattern.

Pros:

I believe the Pros outweigh the Cons in this case. It requires a bit of effort on behalf of the team, and we should sit down and design the communication flows between the components. However it provides a large amount of flexibility and based on the tests Fritz and I have done will probably not amount to much performance decrease. We can do profiling after the change to see where any bottlenecks form but I am pretty sure that we will not find any, and if so they will probably be due to a silly mistake somewhere.