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

Why a "Game" class?

12 posts in this topic

Hi,

Everytime I see some game's source code (just a sneak peek), I see al class "Game" (or CGame).
Was just wondering, in my own main application I declare objects for input, io, audio, 3d scene etc. Global in the cpp file.

Would the game class be having all of these as a member, so you need only one "game" objects? (and also put your other stuff in there what otherwise would be global in your cpp main file)
0

Share this post


Link to post
Share on other sites

Using a game class has a number of other potential advantages. Firstly, it can allow you to benefit from inheritance and polymorphism. If you're utilising an underlying framework, that framework might provide a Game class which can be extended, thereby handling much of the lower-level stuff. Certainly this can be handled using a number of separate systems, but there's certainly scope for conveniently handling timing values and calls to update the input system through a base class.

 

In the same way, you can benefit from polymorphism. In the Heron Framework, which I've developed and used for a number of years, there are multiple extensions to the game class that provide more specific functionality and, more importantly, there are different versions for different platforms. Once again, there are other ways to approach these issues but this is one convenient one.

 

There's also the possibility to consider scope for multiple 'games.' In Heron, there's a 'GameMode' class which provides the functionality of a game loop but is managed by a game. This effectively allows multiple 'Game'-type classes to be created, loaded, unloaded and run. In this manner separate components can be loaded separately and unloaded when not required, though this is usually handled in other ways. More often, I use this class to create a single game class in a portable library.

 

A final way in which multiple 'Games' might be employed are in tools. While not games, a number of the tools I have created employ Game classes to manage components that utilise the graphic device and may also employ the input system or content pipeline. In such cases it is beneficial to separate the game from the remainder of the application, and also sometimes necessary to create multiple games and run them simultaneously.

 

These are some of the reasons I, personally, choose to use game classes. Like rip-off, I also have an aversion to globals. That said, there are many other valid approaches to the problem, such as utilising a graph of systems and components. 

1

Share this post


Link to post
Share on other sites

I love globals, so you only have to declare them once, also not passing in functions, just use external in the header file.

Next to game class i also have demomovie class, mainmenu, briefing, options, credits, etc etc.

greetings

-7

Share this post


Link to post
Share on other sites

Thanks for all replies.

I'm gonna make a game class for sure, but first I'll probably have to make a basic design on the 'whole game'. So my decisions on which classes should be part of the 'game class' are logical. For example my audio and input class will not change during runtime, so they wouldn't need to be reloaded (as part of a 'new game').

0

Share this post


Link to post
Share on other sites

Hello Frob,

I got voted down for these reasons about globals ?, i feel special now that i can handle it then.

Once the engine works like this, there is no more of these problems.

 

Anyways are using globals also slower ?

 

The point for me is that i have all data / pointers in 1 file ( ok 2 files ( cpp & h ) )

i like to make many games, so i dont have to hunt everything down when cleaning the engine.

Its realy comfortable, professors can discuss another decade about it, but it wont convince me.

 

greetings

Edited by the incredible smoker
-4

Share this post


Link to post
Share on other sites
Interesting reactions and input, thanks.
I'll go draw out my high over design and decide where to do what with the game class/ globals.
0

Share this post


Link to post
Share on other sites

Hello, I just looked in my engine, I forgot i have a DataLoader class now.

 

So i just do like this :

 

DataLoader load;

 

load.SetFolder( "foldername" );

load.Texture( true , "name" ); // true is for global or false = each level

 

The DataLoader remembers the name, so it wont load twice.

 

Now with this i only have one global , and that is DataLoader load;

I,m hoping to get voted up now for once!

 

@Ravyne : Saying that i am uneducated, but not giving a better solution ?

0

Share this post


Link to post
Share on other sites

Now with this i only have one global , and that is DataLoader load;

I,m hoping to get voted up now for once!

You don't typically get voted up for making your own problems better. Or even voted down for making yourself problems.

You get voted down for encouraging others to adopt your mistakes.

It should come as no surprise then, that helping others to avoid the mistakes you've made or that you know are mistakes is the way to get voted up.

@Ravyne : Saying that i am uneducated, but not giving a better solution ?

Better solutions are well known. Abuse of global is the first thing covered in any software engineering course or book. Even most introductory programming classes or books will get around to mentioning in their first half.

But somehow you missed this information, and instead glibly recommended against best practices and then boasted how good you must be to not have experienced any of its known problems.

I'm probably coming of harshly, but I'm just being frank. Everyone is welcome here but don't expect to be awarded points for mere participation. When you offer up advice, that advice will be judged. So before you offer it, consider whether it is good advice and whether you are actually qualified to judge whether it us or not. If you want to share something that there's no consensus on, present it as opinion rather than fact. And if you want to share something that is contrary to best practices, qualify when the problems can be ignored.

For example, if you had said something like "In small, throw-away projects under a couple thousand lines long, I like to just use global when I'm coding from the hip." is an entirely different answer than "I think globals are great!" and it probably wouldn't have gotten any down-votes at all.
2

Share this post


Link to post
Share on other sites

In my engine the Game class holds the state machine, hig perf timer, and the fixed step loop, feeded by the timer down the state machine.

When doing a game, I create a GameName class, derived from both Game and Window (Window is a wrapper for win32 windows).

In that class I put the other engine main systems, like sprite renderer, sound, networking. And overwrite the wndprocedure function from the Window class, for handling resizing /input etc. ( I initialize the systems on WM_CRATE).

 

My message loop is handled manually, I dont know how to make it part of the engine. I place the Game::FixedStepLoop() myself on the main, and just need to load the first state to start the game. Till now all states I create grab a pointer to the GameName class on initialization, to access the main systems.

Edited by Icebone1000
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