Jump to content
  • Advertisement
Sign in to follow this  
Kjansen92

When to Implement Game Loop

This topic is 1502 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

Hey all!

 

I've been coding this simple text-based business game for the past couple of days, and I'd like to hear your opinions on this, be they idealistic, or totally rudimentary.

 

As I've hear and am now coming to realize, coding a text-based game is relatively simple. Adding whatever functionality I may think of has been a breeze and a lot of fun so far.

 

I'm getting to the point where I may consider adding a game loop.

 

Is there anything to say about when to add a game loop, and how it impacts the production of a game, be it as simple as my project?

 

Thanks!

Kevin John Jansen

Share this post


Link to post
Share on other sites
Advertisement

If you need a game loop, it's time to add one.  If you're able to implement your game without one then it isn't necessary.  There really isn't much more to the decision! smile.png

 

Will the addition of a game loop improve your game, simplify your development, or allow you to add features that you can't currently add or which are currently prohibitively difficult to add?

Share this post


Link to post
Share on other sites

Hey J.B.,

 

I'm assuming not. I'm currently testing all of my functionality through a tutorial function in the main file. 

 

I just thought there would be possibly be something to it that I wasn't seeing, such as:

-How to make it more fun

-Studying things that I will need to know for building graphics, engines, AI, etc.

 

But you're right. As far as testing goes, a main loop isn't really going to add to anything.

 

I also thought I'd put a post up here just to be part of the community.

Share this post


Link to post
Share on other sites

I think the game loop is the first thing to add when starting any game.

That is because without it people get tempted to create their game as an endless intermingling of repeated input, output and game logic (cout, cin, if inside a textbased game), that is impossible to refactor into a gameloop. That results in having to start anew when realizing it.

Share this post


Link to post
Share on other sites

...an endless intermingling of repeated input, output and game logic...


Surprising fact: The original X-Com game for DOS was uses that kind of "intermingling" style, and the windows port didn't change it much, either (imagine seeing the windows message pump being called FROM the gameplay code when the game is ready for input). I was pretty shocked when I discovered this, but it got me thinking that there might be ways to exploit the general idea in modern games.

I'm not necessarily saying that you shouldn't use a game loop; just that sometimes you can think outside the box and it won't necessarily be catastrophic. Edited by Nypyren

Share this post


Link to post
Share on other sites

Working without a game loop is nothing different, no less catastrophic, assuming that you keep in mind that the functionality has to work together as one unit.

 

That's pretty common sense.

 

I was more looking for answers on the constructive side.

Share this post


Link to post
Share on other sites

A game loop can be thought of as the core of a game. Pro's why you would want to try using a game loop in your game:
For learning purposes. Thats really all the reason you need!

Generally a game loop handles 3 parts: initializing the game,updating and drawing.

Even though you don't really need this in your text game, it's a nice way to learn the basics I guess.
Basics as in, learning how to set the speed of the cycle, aka fps(frames per second) and ups (updates per second).

I'm not sure how your game is constructed but chances are that you will need to edit some stuff or the entire game to get it working.

But if you wanna learn how it works then go ahead and implement it!

Generally I would say that the first thing you should always do is implement a game loop.

Good luck!

psst, a little example about how your gameloop would probably look (in psuedo code):

 

gameLoop()
{
    init(); // Initialize
    while(gameIsRunning)
    {
        input();
        update();
        render();
    }
    clearMemory(); // clear/empty allocated memory.
}

As you see, it does not need to differ much from the game loop of a graphical game

Share this post


Link to post
Share on other sites

the "init();" and "clearMemory();" are not part of the game loop.and shouldn't be in a the "gameLoop()" !

In this case it is the game entry-point.

Share this post


Link to post
Share on other sites

Game loop generally used when you have a real time application that needs to update the game objects on the screen and draw them and then sleep the application inside one game loop.

 

Any real time application be it games or whatnot use loop to keep the application running.

 

Since you are designing a text based game which is not a real time application, you would still need a game loop but not the one that does any rendering and sleeping on the application. You just need a loop (both a main loop and a game loop combined for the text based program flow) You may still need to update or not update the game objects depending on the design.

Edited by warnexus

Share this post


Link to post
Share on other sites

How are you implementing you game without a loop? In pretty much every game there are things that need to be repeated (even in text games), so how are you doing that now? goto? I don't even understand how you could make a game without a loop of some kind. Even an event driven game has a loop (it may be hidden from you but it's there).

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!