Code review: Small C++ game engine

Applied patterns, Portability, Maintainability, Expandability

Page 1 of 1

5 Replies - 2805 Views - Last Post: 21 June 2010 - 07:25 PM

#1 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

Code review: Small C++ game engine

Posted 19 June 2010 - 09:44 AM

I am writing a small C++ game engine. It is still unfinished, but I got the overall structure down, and I want to see what should be improved before I move on to the details. So I'm asking people to take a look at it, even a short one, and tell me if you think I did something wrong. I don't expect anyone to actually spend their time (for free) to do a thorough review, but even smaller input will be useful. :)

This is a re-writing of a text-based game I did last year. Back then I also requested a code review and was lucky Oler1s and baavgai ran into my thread, as they were of great help. Not much has changed in terms of actual content (I only added support for images and sound), but the code has changed almost entirely. The reason I'm doing the same thing again is because my focus is on learning good programming practices and correctly applying different programming patterns, and not on doing an actual game. At least for now.

Download source (105kB)
Includes VC10 and PN project files.


PROGRAM STRUCTURE

The main loop is located in main(), main.cpp:
GameManager game;
while (game.isRunning()) {
    game.update();
    game.render();
}


GameManager holds an std::vector of GameState objects; the last GameState in the vector is the currently active state. When GameManager::update()/render() get called from the main loop, GameManager calls the update()/render() functions of the currently active GameState.

It also holds the only instances of the GraphicsRenderer, SoundRenderer, and UserController classes in the application. It passes these instances around to the GameState objects, when it is required to.

The GameManager class also has change/push/popState() functions. When it update()-s the active state, the GameManager gives the state a pointer of itself so that the state would be able to change the currently active GameState.

void GameManager::update()
{
    if (!stateStack_.empty())
        stateStack_.back()->update(this, userController_);
}

void GameManager::render()
{
    if (!stateStack_.empty())
        stateStack_.back()->render(graphicsRenderer_);
}

This post has been edited by diego_pmc: 19 June 2010 - 11:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Code review: Small C++ game engine

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code review: Small C++ game engine

Posted 19 June 2010 - 10:52 AM

:) you really need to get this into source control -- I still have your last version on my hd...

What version/flavor of make do you use? I could not make your project from PN due to syntax errors -- but that is probably just the old version of make I have.

I would also recommend looking into doxigen to create documentation. You have the comment there, but they are not doing a whole lot of good in their current form. Doxigen can be used to turn your comments into a nice HTML or PDF documentation.

Actually -- doesn't VS do some neat documentation? I have never really seen it in C++ but I know C# does and I would imagine they make it kind of universal... I think I would still prefer doxigen -- but the point is to take your comments and create an end user documentation so it does not really matter which one you use.
Was This Post Helpful? 1
  • +
  • -

#3 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

Re: Code review: Small C++ game engine

Posted 19 June 2010 - 11:14 AM

View PostNickDMax, on 19 June 2010 - 09:52 AM, said:

:) you really need to get this into source control -- I still have your last version on my hd...


Yeah, I probably should. Google Code should be useful for something like this, right?

View PostNickDMax, on 19 June 2010 - 09:52 AM, said:

What version/flavor of make do you use? I could not make your project from PN due to syntax errors -- but that is probably just the old version of make I have.


I don't know. :( I took the makefile that comes with the devkitPro template example and modified it as required. What kind of syntax errors do you get? For me it compiles under both VC10 and PN.

View PostNickDMax, on 19 June 2010 - 09:52 AM, said:

I would also recommend looking into doxigen to create documentation. You have the comment there, but they are not doing a whole lot of good in their current form. Doxigen can be used to turn your comments into a nice HTML or PDF documentation.

Actually -- doesn't VS do some neat documentation? I have never really seen it in C++ but I know C# does and I would imagine they make it kind of universal... I think I would still prefer doxigen -- but the point is to take your comments and create an end user documentation so it does not really matter which one you use.

I've seen other projects that had documentation created with Doxygen, so I'm not entirely clueless. But shouldn't I leave this part towards the end of the project?

This post has been edited by diego_pmc: 19 June 2010 - 11:42 AM

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code review: Small C++ game engine

Posted 19 June 2010 - 01:28 PM

Quote

But shouldn't I leave this part towards the end of the project?
-- I suppose, I like to kind of develop my comments with my code.

I find that if I wait until the end I don't have the energy and drive to just add the documentation.
Was This Post Helpful? 0
  • +
  • -

#5 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

Re: Code review: Small C++ game engine

Posted 21 June 2010 - 08:21 AM

I added my project to Google Code and made it available for reviewing by anyone:
http://code.google.com/p/tbgengine/

I have a few questions though. If I go under the Source tab and then go to Browse I can see my source. I can also see it if I go to the https URL. However, if I go to the http URL (http://tbgengine.googlecode.com/svn/trunk) nothing appears (it still shows me the initial rev1 revision which is just the empty directory tree). Do I just have to wait for the servers to purge the page?

Also, you will notice I only added the source files themselves, plus the resources in this repository. Should I also add the project files, or should I keep those out of the repository and add them in an archive which I should post in under the Downloads tab?

EDIT: I used TortoiseSVN to upload my code. For some reason TSVN added question mark symbols over most of my Desktop icons. Also, if I create a new file/folder in Desktop, it will also get a question mark. I don't know what I did to cause this. How can I fix it?

Attached image(s)

  • Attached Image

This post has been edited by diego_pmc: 21 June 2010 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code review: Small C++ game engine

Posted 21 June 2010 - 07:25 PM

Apparently you added your desktop to source control....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1