Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

Is my main.cpp good or did I over do it?

This topic is 4612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How's my main.cpp file? I think it's good, but maybe it's just too short?
#include "CGameManager.h"

int main(int argc, char *argv[])
{
    CGameManager gMainGame;

    if (!gMainGame.GetStatus())
        return gMainGame.GetStatus();

    while (gMainGame.Handle())
        gMainGame.Render();

    return gMainGame.GetStatus();
}

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Frankly I wouldn't allocate CGameManager on the stack like that. That's my personal taste.

Also depending on the return value of Handle() probably isn't the best way to determine if your game is still running. Probably would want something more specific like CGameManager::IsRunning().

What's the 'g' in gMainGame? Clearly, it's a local not a global which is what I would expect the 'g' to mean.

Obviously you have a lot of initialization in your constructor. I don't like that pattern; most other people don't either.

Share this post


Link to post
Share on other sites
What type of game are you making? Also, I think you are right. It does look a bit short for the main game file. Add more detail to it or tell me info on the game, then I can be of help.

Share this post


Link to post
Share on other sites
I notice that your main loop is just:
gMainGame.Render();

To me that is a bit misleading because to me Render is "Render Graphics". This does not mention anything about where:

Input is handled.
Sound is handled.
Game AI/logic is handled.
Networking ( if in use ) is handled.


I assume all this handled in the Render function but a better name might be Tick or Step.

Share this post


Link to post
Share on other sites
Quote:
Original post by Undeadlnsanity
Haha, brilliant! I'd hate to see what CGameManager.h looked like though.


CGameManager.h: 32 lines with #ifndef ... #define ... #endif.

This is supposed to be a ping pong game, but one just started. It's splitted into 11 files along with main.cpp, since it has an SDL wrapper. It's input, events, init', deint', and sprite. CGameManager just handles stuff because I don't like main(...). *cough* She and I had problems. *cough*

The engine is supposed to be somewhat 'reusable' next time, so I don't have to write sloppy stuff.

There isn't "ALOT" initialization in CGameManager::CGameManager. Just:

CGameManager::CGameManager(): m_SCREEN_W(640), m_SCREEN_H(480), m_SCREEN_BPP(32), m_Status(true)
{
if (!m_MainApp.Init(SDL_INIT_VIDEO))
{
m_Status = false;
return;
}

if (!m_MainApp.InitWindow(m_SCREEN_H, m_SCREEN_W, m_SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF))
{
m_Status = false;
return;
}

SDL_WM_SetCaption("Crazy Pong! ~Agi~", NULL);
}



So, any other ideas?

P.S. 'g' for 'game'. I didn't know other people recognized 'g' as 'global'.

Share this post


Link to post
Share on other sites
Quote:
Original post by acraig
I notice that your main loop is just:
gMainGame.Render();

To me that is a bit misleading because to me Render is "Render Graphics". This does not mention anything about where:

Input is handled.
Sound is handled.
Game AI/logic is handled.
Networking ( if in use ) is handled.


I assume all this handled in the Render function but a better name might be Tick or Step.


Noo... Not exactly. What's gMainGame.Handle() in there for? [smile]

EDIT: Handle(...), not Run(...) ;)!

EDIT: It's EDIT, not DIT ;)))!

Share this post


Link to post
Share on other sites
Why not move all that initialisation out of the constructor and into something like CGameManager::Initialise()? That way you could return true or false directly, and you wouldn't need the extra status variable.

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
Why not move all that initialisation out of the constructor and into something like CGameManager::Initialise()? That way you could return true or false directly, and you wouldn't need the extra status variable.


A fake init() function? That's what the constructor is for, initialization! And I need m_Status to return in main, so I don't return any ugly 0's. Plus I can use m_Status as a check, too.

Share this post


Link to post
Share on other sites
Quote:
Original post by agi_shi
Quote:
Original post by superpig
Why not move all that initialisation out of the constructor and into something like CGameManager::Initialise()? That way you could return true or false directly, and you wouldn't need the extra status variable.


A fake init() function? That's what the constructor is for, initialization! And I need m_Status to return in main, so I don't return any ugly 0's. Plus I can use m_Status as a check, too.


The constructor is more used to Init your attributes (not sure of the english word) to their starting values. e.g m_bGameRunning = true;

The SDL Initialisation should be in a function because this way it can return if the Init was succesfull or no.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!