How to avoid game rendering component circular references?
- by CodexArcanum
I'm working on a simple game design, and I wanted to break up my game objects into more reusable components. But I'm getting stuck on how exactly to implement the design I have in mind. Here's an example:
I have a Logger object, whose job is simply to store a list of messages and render them to screen. You know, logging. Originally the Logger just held the list, and the game loop rendered it's contents. Then I moved the rendering logic into the Logger.Draw() method, and now I want to move it further into a LoggerRenderer object.
In effect, I want to have the game loop call RenderAll, which will then call Logger.Render, which will in turn call the LoggerRenderer.Render and finally output the text. So the Logger needs to contain a Renderer object, but the Renderer needs access to the Logger's state (the message queue) in order to render.
How do I resolve that? Should I be passing in the message queue and other state information explicitly to the Render method? Or should the game loop be calling the Renderer directly and it links back to the logger, but the RenderAll method never actually sees the logger object itself?
This feels kind of like Command pattern, but I'm botching it up terribly.