• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Plethora

Are lots of "Pass-Through" methods bad/poor design?

4 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

I see two issues, not just one.

 

The first one I see is that it looks like you are failing to build abstract interfaces.

 

Are you implementing the Dependancy Inversion principle correctly?  That is, are you writing systems that depend on an abstract interface rather than writing systems that depend on specific concrete types.

 

 

 

The second one is inappropriate intimacy from your Gui_Manager.  

 

If you want to display the stats of one enemy, you should have that one enemy selected.  No other objects should be involved in the transaction.  Maybe it was from a mouse event or mouse hover, maybe it was from a click, but whatever triggered the event it should ultimately resolve to the Gui_Manager knowing about only one object.  

 

It makes sense for a mouse-picking code to traverse the world to see what is being pointed to.  But once it is selected nothing else should need to traverse the tree.

0

Share this post


Link to post
Share on other sites

On your first point, I have some reading to do and will be reimplementing some things, thank you for the help and the link!  I am absolutely writing systems that depend on concrete types and will need to be making some modifications to my program going forward.  As I said, this is a big project for me, and a big part of my goal is learning how to manage something a bit bigger than what I've done in the past.  I don't at all mind going back to refactor stuff like this, so I really do appreciate the lesson.  :)

 

I'd like to talk about the second point a little bit though.  I think I get what you're saying, but I just want to clarify a little bit.  So with the current example, when the mouse is clicked it happens as you said.  The coordinates are gotten and then used to determine what is clicked on just as you say.

 

Now, the part where I get a little confused is this.  In my current implementation, Gui_Manager knows absolutely nothing about anything really.  All it knows how to do is create a set of predefined windows when it is told to from outside.  It is given only the information it needs to do so.  In most cases, it doesn't even know about specific types of objects.  In the example we're discussing, Gui_Manager doesn't even know what an Enemy is.  All it knows is how to display a window which displays to the user a set of statistics given to it in the form of a Stat_Pack object (which is a simple struct containing a bunch of integers and one std::string). 

 

What I hear you saying is that once the program determines what has been clicked on, then I should have functionality built into Gui_Manager where it knows what should be displayed.  Like for example, maybe Gui_Manager contains a pointer to some object that will be changed by the event handling code.  Even as I am typing this, I see the logic in that and am working out how I will implement it.  But, to make sure, is that essentially what you mean?

0

Share this post


Link to post
Share on other sites
Yes.

Keeping the two together, any object that can be displayed by the gui's stats system should implement a common interface. Perhaps call it IHasStatsPack.

On many of our studio's projects we have established the pattern of interfaces named IHasFoo or IFooable.

The interface would just be something simple:

class IHasStatsPack {
Stats_Pack* getStats() = 0;
}

Then your gui class can accept an object of type IHasStatsPack.

That's really all the gui cares about. The gui doesn't care if the object is an enemy or a player or some other game object. All it cares about is that the object has the getStats() function that returns a valid stats structure for display.

Now anyone who creates game objects can use your gui to display any object they want. It may happen that the game will only ever display stats for enemy units. But maybe not. If someday a future programmer needs to build some helper class somewhere and wants to pass that to your gui, they just need to implement the IHasStatsPack interface.

Everybody wins with this kind of design.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0