In my ongoing efforts to keep a fairly large code-base manageable despite the fact that my current project is fairly ambitious for my knowledge (but I'm determined dammit!), I've run into a phenomena that keeps popping up and I'm unsure if its a bad thing, a necessary evil, or maybe its just fine and I'm worrying for nothing.
In a nutshell my program works like this.
- I have a Main_Controller class that owns and runs the main game loop.
- The Main_Controller contains these objects, that are relevent to this conversation:
- A Graphics object, an std::stack of Controller objects, and a Gui_Manager object.
- Each Controller object basically defines a given screen (World Map, Town Screen, Battle Screen, etc) and handles input for that screen. The Controller on the top of the stack is considered the "active" controller and thus handles all input while it is active.
- Each Controller also contains some number of data driven objects that make up that screen. So the Battle_Controller contains a Map, which in turn contains some Enemies, some Tiles, and so on.
There is obviously other stuff going on, but that's the basic idea. My question is related to the ever expanding collection of Data in my game and the fact that I have a kind of hierarchy (not an inheritence hierarchy, mind you) of data (like in the above, the Map has a bunch of data made up of enemies, which have their own data made up of..., etc.)
Now, lets say I want to display the stats of a given enemy in a window created by my Gui_Manager. Well, the Enemy class contains a Stat_Pack, and a getStats() method which returns the Stat_Pack in question. Then Map contains a getStats() method as well, and then so does the Battle_Controller. And finally, Gui_Manager has a displayStats(Stat_Pack stats) method which gets called by the Main_Controller.
Obviously, the data in question has to be retrieved somehow, but I just wonder if going through a chain of 5+ function calls just to get some small amount of data from one place to another in my code is really the best way to do it. Obviously I could give, in this case, Gui_Manager direct access to some of this data if I wanted to, but that seems like it would completely break the modular design I've worked pretty hard to maintain.
The other solution I thought up seems more like a band-aid than anything else, but I could perhaps create a "middle" type class that's meant specifically to transfer data from one "branch" of code to another. But then I think the problem is, what do I give that class access to? Everything? That doesn't seem like a good idea...
So, what do you folks think?