Jump to content

  • Log In with Google      Sign In   
  • Create Account

Game's MenuState and Game's Loop


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 KhoaVN   Members   -  Reputation: 315

Like
0Likes
Like

Posted 24 September 2013 - 12:05 PM

In normal application or non-animation application, we use event-driven. It means that just when there is at least one event inside event queue, the program will processes. If not, it will wait until at least one. During of that waiting time, the program does nothing.

 

For game, we use game loop (I saw others called it: loop-driven) because there are many things happening and need to be updated even if user did not input anything.

 

My question is:

 

With menu state (the menu for us to choose "Start new game" | "Load game" | "Continue Game" | "..." - not in-game menu/GUI), it is like normal app. It waits for user input. It does not need a real-time loop. So how we can implement it and attach it to our game?

 

Here is an overview of my code:

 

// class Game has a "StateManager" field and a loop like this

 

while(running)

{

-get Event

-process Event

-update

-draw

}

 

// inside update/draw, i simply call update/draw of "current_state" of StateManager

 

if the state is GamePlay, It is ok. If it is MenuState, it is my problem.



Sponsor:

#2 mark ds   Members   -  Reputation: 1254

Like
1Likes
Like

Posted 24 September 2013 - 12:18 PM

while( running )
{
while( running && in_menu_mode )
{
GetMessage(...)
}
while( running && in_game_mode )
{
PeekMessage(...)
}
}


#3 mark ds   Members   -  Reputation: 1254

Like
0Likes
Like

Posted 24 September 2013 - 12:20 PM

Sorry - no idea how to format the code!

 

But essentially, just use whichever message loop is appropriate for what you're doing at the time.



#4 ActiveUnique   Members   -  Reputation: 835

Like
0Likes
Like

Posted 24 September 2013 - 12:39 PM

have event checking and event processing in seperate loops, with event checking running low priority


I've read about the idea guy. It's a serious misnomer. You really want to avoid the lazy team.


#5 KhoaVN   Members   -  Reputation: 315

Like
0Likes
Like

Posted 24 September 2013 - 12:48 PM

@mark ds: wow it is really simple. Thank you so much.

@ActiveUnique: I still not figure out what you mean. Please explain! I really like to look for more ways.


Edited by KhoaVN, 24 September 2013 - 12:48 PM.


#6 ActiveUnique   Members   -  Reputation: 835

Like
1Likes
Like

Posted 24 September 2013 - 04:43 PM

Ok so you stated there's two application types in our minds here:

 Always on -  one big loop

 and wait for events - technically it is still a big loop with a minimum of one sentinel value between two other loops.

 

Maybe that can be confusing. But I was really just iterating the concept of what mark ds already gave you. It's nice to be able to say it to yourself and understand why it is going to work so try understanding it.


I've read about the idea guy. It's a serious misnomer. You really want to avoid the lazy team.


#7 Malabyte   Members   -  Reputation: 589

Like
1Likes
Like

Posted 25 September 2013 - 01:26 PM

Well, at the end of the day it's all about refresh, memory and the process per refresh. So personally, I don't see why you can't just use a big event-driven wrapper loop for all programs, regardless of them being games or not. It's just for human logic anyways, the computer doesn't care (afaik). Just adjust the currently running processes accordingly, thread or synchronize when needed and stop the loop children that aren't supposed to run at that time (and be sure to store relevant information for later, if needed).

 

A main menu is just another application that runs when the child gameLoop or any other loops (!running) and the parent mainLoop (running) or am I missing something here?

 

 

In pseudo-code:

mainLoop {

menuLoop ();

gameLoop ();

whateverOtherLoop ();

}

 

Throw an else if or more applicable statement (e.g. synchronized methods?) in there, so that only 1 loop is running at a time.


Edited by Malabyte, 25 September 2013 - 01:45 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#8 KhoaVN   Members   -  Reputation: 315

Like
0Likes
Like

Posted 26 September 2013 - 10:22 AM

@ActiveUnique: It is clear(more than the old). Thank you so much. :)

@Malabyte: Thanks for your advice. Maybe I just look one way. Your solution can be a good one. I am thinking about it. Thanks a lot :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS