• 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
metsfan

Engine object creation strategy.

4 posts in this topic

Hello all,


I am currently looking to refactor some of the code in my engine to remove some singletons I made out of laziness.  However, I am facing a problem, and I am curious how others would solve this problem.  As it stands, object creation within the engine is done through constructors, and internal engine dependencies are accessed through singletons.  This is the main design I am trying to move away from.  However, there is one distinct advantage to this approach, which I would very much like to maintain:  a user needs to know very little about the internal dependencies to construct a new object, and can easily inherit from certain objects in the engine.  

 

For example, I have in my GUI system a LabelControl class.   Each LabelControl object must have access to the FontManager, which is a subsystem that allows loading, retrieving  and caching of fonts (as it stands, built as a singleton).   I want users of my engine to be able to construct a new LabelControl, and also inherit from LabelControl, without needing to know that the FontManager even exists.  The only way I can see to solve this problem, while still keeping singletons out of my engine is to do the following:

 

-Take all my "singleton" subsystems and throw them into my Game base class in my engine.

- Require the user to pass their "Game" instance into every single constructor.

 

I'm not sure if this is the right way to do things, or if there is some other way that makes more sense.  Either way, I'd love some input and opinions on the matter.

 

Thanks,

-Adam

 

 

0

Share this post


Link to post
Share on other sites
Sounds like LabelControl has a bit too much responsibility. Perhaps it only needs a pointer/handle/ID of a font, which the GUI manager can provide when needed?

It is unfortunately quite hard to get rid of singletons. Sometimes you have to redesign quite heavily. This is one reason why they are a bad thing.
1

Share this post


Link to post
Share on other sites

I would avoid hiding things. If you think FontManager is too complex to assign to your control, maybe control does not need to get full access to it.

 

For example, I have similar system, and I require to pass Font when creating my Control, and Font needs my FontManager to create :). And it looks nice:

 

Font * smallFont = new Font("FreeMonoBold.ttf", 10, fontManager);
TextLine t(smallFont);

 

 

Of course I am lying, it does not look like this, it is crappier and I wrap my heap objects in shared_ptr.

But maybe it will give you some ideas :)

2

Share this post


Link to post
Share on other sites

Thank you for the responses.  I think you may be right that some of my objects may have too much responsibility.  However, as I think about it, this one example is just one of many problems.  For instance, my GameSound objects rely on my AudioManager class, which maintains a pointer to my FMOD system (another detail users of my engine should not have to deal with).  I think what I'm going to have to do is prefer factory methods for creating certain types of objects, and encourage users of my engine to prefer composition to inheritance for these types, and for types which can be inherited to also be made clear, but also encourage composition all the same.  Thanks guys.

 

I am of course open to more suggestions from the community, though.

Edited by metsfan
0

Share this post


Link to post
Share on other sites

Use the Observer pattern. In principle, you generate events at one place of the source code, and then catch these events elsewhere, as needed.

 

An example:

  • The melee function decides that the condition for an attack on the player from a monster is to be executed. It updates some physical values, and then generates a "MonsterHitPlayerEvent" with some information.
  • The Sound system catch this event, and generates an appropriate sound.
  • The graphical system catch the event, and splash some blood on the scene.
  • The log window catch the event, and prints a message "You are hit %d units by the %s monster".
  • The multiplayer module catch the event, and sends a network message to other players, to let them know.

This way, the melee function (usually part of the Model in the Model-View-Controller) does not need to know anything about sound, graphics, etc. Eventually, you no longer need to create a global variable for the sound manager, as it isn't used anywhere. And you don't need to create a global variable for the log window manager, etc.

 

The generator of the event is the one that declares the event type and what it will contain. The subscribers to this event need to include the header file that declares the event.

-1

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