Question

A conceptual question

Asked by: priyendra

Hi all!

Well, I think I understand the basic game loop. In an infinite loop, you update the position of your objects, you render, you update, you render ...

However, what I do not understand is that how does this tie in with all the other things that are there in a game. Most games have some sort of an intro, have a menu interface and the game itself. So is the game loop running even when the user is interacting with the menus? Or does the execution model change when the user is in the menu part?

I am asking this because I am myself working on a game. The work is at a stage where as soon as I run the executable, the application enters the game loop and the game starts. I want the user to first see a menu and the game should start only when the user instructs it to. Also I want to provide a host of other options in the menu. What is the standard way to do this??

Also, most commercial games have very stylish menus. They have custom GUIs (drop downs, text boxes etc). Are these elements hand coded or are they somehow derived from the base Windows GUI elements? And if they are hand coded, are there any free libraries that will help newbie game developers to put decent looking menus in their games?

Thanks in advance
-- Priyendra

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-07-02 at 11:30:05ID20666692
Topics

Game Programming

,

3D Graphics Software

Participating Experts
2
Points
200
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Tie::Appendhash
    Where do I get this Tie library to add to our existing PERL installation?
  2. HOW CAN I MAKE AN INTRO FOR MY WEBSITE
    IM AM A 14 year old who is trying to make a website and i want an intro for my website how do i get an introduction that is like a pop up and says text disapearing and stuff. Also How can i put a password to lock my website. One more thing im using www.freewebs.com please ...
  3. Installing Tie::File module
    I am trying to add the Tie::File module. I run the the basic setup like this: Go to the folder that has the perl mod type the command perl Makefile.PL make make test make install When I get to make test I get an error that says: t/40_abs_ca...
  4. Flash Intro
    How can one make an intro to be centerer on the screen? I have an intro that comes up centered on my 17" monitor, but once I tested it on another monitor, the intro was closer to the top left corner of the screen. Is there a way to resolve this?
  5. Flash Intros
    Hi, 1. Looking for resources for pre-made FLASH INTROS (not full websites, just the intros...) Particularly looking for ones themed for a travel agency right now, but will take any resources you know about for future reference. Here's the kicker - I already know about temp...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: MoonoverPosted on 2003-07-02 at 13:52:39ID: 8843992

Normally, the GUI is not hand-coded, but is part of a graphic engine... one of the simple 3D engine I have experimented with is WildTangent (www.wildtangent.com) ... it is not the best, but there is a good documentation, and I find it easy to use (i learned it during my gameprogramming course at my university) ...

Most of the time, the interfaces are designed in Photoshop, and imported in the game with the graphic engine functions ...

A game loop I use goes something like this:

loop until Quit
{
   if startup
   {
        load menu
        startup = false
   }

    if( playgame == true )
    {
             do the standard stuff ( update position of object, check AI, physics, display refresh, blablabla )
    }

    if( gameOver == true  )
    {
        - do something like freezing the display or play an end animation -- deallocate memory and stuff -
        playgame = false
        gameOver = false
        startup = true
    }
}


Hope it helps!

David

 

by: PeonicPosted on 2003-07-02 at 16:13:13ID: 8844853

OK, your half way there anyway, instead of your game loop consisting of a set Render() and Update() though how about allowing it to use one of the followiung structures:

If we have your generic game loop, with blank updates in:

class CGame
{
     virtual void Update();
     virtual void Render();
}

From this we can derive the kind of state you were using:

class CMainGame
{
     virtual void Update();
     virtual void Render();

     // whatever else you were using
}

In the main loop this would just appear as:

CGame *m_currentState;

WinMain()
{
    m_currentState = new CMainGame;

    for(;;)
   {
         m_currentState->Update();
         m_currentState->Render();
   }
}

This should just be similar to what your doing right now, the beauty of this system is you can create your own CGame states now and stick em on m_currentState, be they an intro, a menu, a pause screen, a bonus stage etc, you can lay them out in a stack, just have 1 at a time, however you want really.  An intro will work exactly the same, its update will be small and might just check for a keypress, once its found one or ended it'll close its self and move on to the next state, which will have its own update and render functions. All the while the main game loop remains small, tidy, easy to add to, heavily object oriented and can mainly be kept and improved from game to game.  The menus you mention could be part of the base state (CGame), if the main update spots a certain key is pressed it'll Render() a menu at the top, this would allow the menus to work in ANY state, frontend, main game etc.

If this doesn't make any sense in any way just ask or if your not bothered about OO coding (or using c++ or similar) go for the method above.

 

by: PeonicPosted on 2003-07-02 at 16:19:39ID: 8844886

that was meant to be:

class CMainGame : public CGame
{
    virtual void Update();
    virtual void Render();

    // whatever else you were using
}

hence all the inheritence jargon, sorry :)

 

by: priyendraPosted on 2003-07-02 at 22:39:30ID: 8846450

Thanks for your comments Moonover and Peonic.

Penoic your suggestion does seem impressive. I am myself a big fan of OOism and would like to better understand what you are suggesting. So far from what I gather, you are suggesting that I should create subclasses for all the different states that my game can be in. Okay, I create these subclasses for the main game, the intro, the pause screen etc. As my game starts, I initialize the m_currentState var to a CGameIntro object. Now the user presses a key and the update() function of CGameIntro understands that the intro must end now and therefore cleans up. However what do I do next? (My aim was to display a menu at  this point). Also, I do not understand the stuff about menus you put towards the end of your comment. Kindly spell that out in a bit more detail.

Thanks!

 

by: PeonicPosted on 2003-07-03 at 04:37:16ID: 8848213

I use a stack on my projects, I dont know how much you've used linked lists and things but basically when the state gets to the end it will push a new state on top of it, this allows you to drop back down states later.. For example, the game starts and a menu is on the stack, this will now be getting updated and rendered, when the user selects to continue to the game, the game state is pushed to the top of the stack, once again if a minigame/shop/score screen is needed this is pushed ontp of the game state, when its done its popped again and we drop back to the game, once the game is done its popped and we drop back to the menu. ALL the variables will already be set up, textures loaded.

Sorry what I mentioned about menus was assuming you wanted a menu which could be seen in all states, a kind of debug menu at the top or something, I didn't mean it in the context of a fronend menu. This system however will allow you to use things like that, you could put an error logging system in CGame's Update for example, as long as your states call CGame::Update(); they should be usable by all classes.

The most simple method of where to move from now would be to just:

delete m_currentState;  // <-- the destuctors all need to free EVERYTHING they used please remember
m_currentState = new CGameIntro(); // then allow it to continue


If you do decide to try for a stack here's what my main loop resembles:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
      //create a 800x600 window, 100x100 offset
      g_windowHandler.CreateNewWindow(hInstance, 100, 100, 640, 480);

      PLN_GameStateStack *m_gameStateStack = new PLN_GameStateStack(new PLN_ActionState());

      do
      {
            //Updates
            m_gameStateStack->m_currentState->Update();
      
            //Draws
            m_gameStateStack->m_currentState->PreDraw();
            m_gameStateStack->m_currentState->Draw();
            m_gameStateStack->m_currentState->PostDraw();

            g_windowHandler.SwapBuffer();
      }
      while(g_windowHandler.Update());            //if a quit is requested.. get out!

      return g_windowHandler.m_msg.wParam;      //last handled message
}

Im quite into my object stuff as you can see :).

In this PLN_ActionState is derived from PLN_GameState:

class PLN_ActionState : public PLN_GameState

The Stack works as follows:

// header --

class PLN_GameStateStack
{
public:
      PLN_GameState *m_currentState;
      PLN_GameStateStack(PLN_GameState *startState);
      ~PLN_GameStateStack();

      void PushState(PLN_GameState *newState);
      void PopState();      //the top state on the list will be ditched and free'd
};

// cpp --

PLN_GameStateStack::PLN_GameStateStack(PLN_GameState *startState)
{
      m_currentState = startState;
      m_currentState->Activate();
      m_currentState->m_prevState = NULL; //no prev state from here!

}

PLN_GameStateStack::~PLN_GameStateStack()
{
      PLN_GameState *tempState;

      //if there is more than one state active
      while(m_currentState->m_prevState != NULL)
      {
            tempState = m_currentState;
            m_currentState = m_currentState->m_prevState;

      }

      //thats the last of em free'd
      delete m_currentState;
}

void PLN_GameStateStack::PushState(PLN_GameState *newState)
{
      PLN_GameState *prevState;

      prevState = m_currentState;      //set prevstate to current one
      m_currentState = newState;      //move to new one
      m_currentState->Activate();
      m_currentState->m_prevState = prevState;      //set up the previous state and we're AWAY!
}

void PLN_GameStateStack::PopState()
{
      if(m_currentState->m_prevState == NULL) return; //we're already on the top state, return

      PLN_GameState *popped;            //set up the almost destroyed one
      popped = m_currentState;      
      m_currentState = m_currentState->m_prevState;      //send the current one back
      m_currentState->Activate();

      delete popped; //*pop*
}


From actionstate, once I've decided we're done and we want to continue I could then call:

PushState(PLN_SomethingElse); which would INSTANTLY call Activate() on the new state, then use its Draw(); and Updates();.

This system does have limitations, in my case I dont have a Disable() at the moment so textures and things sit in memory even while its not the top state, obvisouly resources delete themselves when its destroyed though, on small projects this isnt an issue, infact the 0 loading times suits me down to the ground. It also allows for some kick ass debugging, you can check whats on the stack, how much memory each state is using, all my resources are in a linked list from a resource base class as well so I can spot how many textures are loaded, the memory they consume etc. then all this can be displayed on screen using CGame::Predraw() if a m_debugOn flag is set.

This is a pretty big concept I know and I could keep waffling all day, I hope you see where I'm coming from. In your case with an Intro you'd need to add a function to remove something from the stack, this should be easy enough to do though.

 

by: PeonicPosted on 2003-07-03 at 04:54:58ID: 8848341

Oh and another thing, my basic Gamestate looks like this, all you'd need to add for the stack thing to work is a pointer to a previous state:

class PLN_GameState
{
public:

      PLN_ResourceHandler      *m_resourceList;      //list of sounds/textures/models/scripts and any other resources
      PLN_GameState            *m_prevState;
      char                    m_stateName[32];

      PLN_GameState(char *name);
      ~PLN_GameState();

      virtual int Update();
      
      virtual int PreDraw();
      virtual int Draw();
      virtual int PostDraw();

      virtual int Activate();
};

m_prevState is set up when the stack is sorted out.  As I mentioned before I use resources in a list, thats the handler which EVERY state will be created with, EVERYTHING i use is a resource it keeps the code nice and tidy.  The resources are the same in that they have an update and draw which is handled by the ResourceList from CGameStates update and draw.  This allows the actual states to stay VERY small and readable but keeps the complex code together..

PLN_ActionState::PLN_ActionState() : PLN_GameState("Action State")
{
   m_resourceList->AddResource(m_player = new PLN_ResourcePlayer("models\\players\\sonic", "sonic", "railgun",MD3_MODELCOLOUR_BLUE));
   m_resourceList->AddResource(m_camera = new PLN_ResourceTrackCamera(&m_player->m_worldInfo));
}

The player resource is derived from model resource, which is once again derived from the base resource, its only difference is it checks input and moves the player accordingly playing the correct animation, that's a quake 3 model it loads, it also contains collision checks.  A camera is then set up which tracks the player, to do things like set his position all I'd need to do is set m_player->m_worldInfo.m_position[X] - [Y] or [Z], basically the more stuff you can keep out of your game loop the better, if its tangled up you wont be able to reuse it, as its set out I could add 10 players to a map and allow 9 of them to be controlled over the network or something, once this player class is sorted I can throw it in as many projects as I want.

My Actionstate update:

int PLN_ActionState::Update()
{
     PLN_GameState::Update();

     // tumble weed and church bells

     return TRUE;
}

;) obviously this will have stuff in later, at the mo its just a character running around a map though, nothing specific to this state.

 

by: priyendraPosted on 2003-07-04 at 06:43:49ID: 8856518

Hi Peonic!

Thanks for your wonderfully detailed answers. I guess now I have a general direction to proceed along. Since you gave such a good detailed answer, I feel compelled to increase the points for this question and award them to you!!

 

by: MoonoverPosted on 2003-07-04 at 06:47:52ID: 8856545

I will keep that thread in my favorites .... that was a good one Peonic!

 

by: PeonicPosted on 2003-07-04 at 10:16:58ID: 8857649

:D

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...