wait a bit

I am trying to create a very simple console app game. When I run the game the console screen goes all wacko because the game operates to fast. I tried using this function:[color=Blue][code]
[color=Green]#include [/color]

. . .
[color=Green]#define DELAY 0.1[/color][color=Orange]//I think 0.1 is about right[/color]

. . .
void pause(void)
{
time_t then;

time(&then);
while(difftime(time(NULL),then) < DELAY);
}[/code][/color]
but [color=Blue]pause()[/color] waited for 0.5 seconds in stead of 0.1 witch is to slow. Is there any way to wait less than 0.5 seconds

I am working in windows XP and using minGW-3.1.0-1 as a compiler.

Comments

  • : I am trying to create a very simple console app game. When I run the
    : game the console screen goes all wacko because the game operates to
    : fast. I tried using this function:[color=Blue]
    :
    : [color=Green]#include [/color]
    :
    : . . .
    : [color=Green]#define DELAY 0.1[/color][color=Orange]//I think 0.1 is about right[/color]
    :
    : . . .
    : void pause(void)
    : {
    : time_t then;
    :
    : time(&then);
    : while(difftime(time(NULL),then) < DELAY);
    : }[/code]: [/color]
    : but [color=Blue]pause()[/color] waited for 0.5 seconds in stead of
    : 0.1 witch is to slow. Is there any way to wait less than 0.5 seconds
    :
    : I am working in windows XP and using minGW-3.1.0-1 as a compiler.
    :
    The code looks fine. I would just modify DELAY until the speed is to your
    liking. (ie, mabey try 0.05?)

    You can also try another timing routine (sleep(), timeGettime(), etc..)
  • : : I am trying to create a very simple console app game. When I run the
    : : game the console screen goes all wacko because the game operates to
    : : fast. I tried using this function:[color=Blue]
    : :
    : : [color=Green]#include [/color]
    : :
    : : . . .
    : : [color=Green]#define DELAY 0.1[/color][color=Orange]//I think 0.1 is about right[/color]
    : :
    : : . . .
    : : void pause(void)
    : : {
    : : time_t then;
    : :
    : : time(&then);
    : : while(difftime(time(NULL),then) < DELAY);
    : : }[/code]: : [/color]
    : : but [color=Blue]pause()[/color] waited for 0.5 seconds in stead of
    : : 0.1 witch is to slow. Is there any way to wait less than 0.5 seconds
    : :
    : : I am working in windows XP and using minGW-3.1.0-1 as a compiler.
    : :
    : The code looks fine. I would just modify DELAY until the speed is to
    : your
    : liking. (ie, mabey try 0.05?)
    :
    : You can also try another timing routine (sleep(), timeGettime(),
    : etc..)
    :
    I can't find [color=Blue]sleep()[/color] or [color=blue] timeGettime() [/color] in minGW's include file and something in my code is rounding DELAY to the nearest half second. I need to find a way to count in smaller bits of seconds
  • : I can't find [color=Blue]sleep()[/color] or [color=blue]
    : timeGettime() [/color] in minGW's include file and something in my
    : code is rounding DELAY to the nearest half second. I need to find a
    : way to count in smaller bits of seconds
    :
    My mistake--Sleep() and timeGettime() are both in windows.h.

    Nontheless, this should work:

    [code]
    void pause (void) {

    clock_t start_time, cur_time;
    start_time = clock();
    while((clock() - start_time) < DELAY * CLOCKS_PER_SEC);
    }
    [/code]

    By changing DELAY you can achieve resolution greater then 1 second
    using this code.
  • : : I can't find [color=Blue]sleep()[/color] or [color=blue]
    : : timeGettime() [/color] in minGW's include file and something in my
    : : code is rounding DELAY to the nearest half second. I need to find a
    : : way to count in smaller bits of seconds
    : :
    : My mistake--Sleep() and timeGettime() are both in windows.h.
    :
    : Nontheless, this should work:
    :
    : [code]:
    : void pause (void) {
    :
    : clock_t start_time, cur_time;
    : start_time = clock();
    : while((clock() - start_time) < DELAY * CLOCKS_PER_SEC);
    : }
    : [/code]:
    :
    : By changing DELAY you can achieve resolution greater then 1 second
    : using this code.
    :
    tank you vary much, your version of pause() worked perfectly and my game is on the verge of being fun!(for a console app game)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion