Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

boltthrower

Two funcs at once

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

This program requires the user to input a few characters within two seconds to keep from failing the game. I know how to call a sleep function and set it for however many seconds. During these two seconds I put in a getc() function, but of course this crashes because the sleep() is only doing what it's told and can't with the getc() func inside waiting for its characters. But I do'nt know how to satisfy both requirements. I realize that I could call clock() before and after user input, subtract the two values, and find out AFTER how long it took, but this isn't consistent with the context of this part of the game. I'm using C and a 16-bit Borland Compiler. Edited by - boltthrower on 4/17/00 7:27:15 PM Edited by - boltthrower on 4/17/00 7:30:43 PM

Share this post


Link to post
Share on other sites
Advertisement
If you''re programming a Windows app, you can use the SetTimer function and set up a callback function that will get executed when the time is up. If you are developing for DOS and comfortable with interrupts, one way is to use interrupt 0x1A functions 06 (set alarm) and 07 (reset alarm), which will call interrupt handler you provide.

aig

Share this post


Link to post
Share on other sites
Why is using clock() not consistent. It is much better for a number of reasons (A) it is more accurate (B) it allows you to do other things while still gaining how long it toke.

If you were to do that I suggest you create two functions, one for the start of the game loop and one for the end of the game loop.

//----------------------------------------------------//
// Example.cpp ---------------------------------------//
// ---------------------------------------------------//

int StartingTime=0; // used to hold the starting time


DWORD Start_The_Clock(void)
{
return(StartingTime = GetTickCount());
}


DWORD Wait_The_Time(DWORD HowLong)
{
while((GetTickCount() - StartingTime) < HowLong);

return(GetTickCount());
}

int main()
{
Start_The_Clock();

// process all game code

Wait_The_Time(30); // this will make the game run at about 30 fps

return(0);

}

// end of program

//-------------------------------------------------------//

Hope that helped








~Spike

You can contact me at
luke_howard@dingoblue.net.au

Share this post


Link to post
Share on other sites
NO, I put at the bottom that I''m using a 16-bit compiler. That''s only text, isn''t it?

At least that''s what I was told. I''m new to this.

Anyways, it''s not a graphics game, but a text game. The user is supposed to put two characters into getc() before two seconds is up.

Share this post


Link to post
Share on other sites
unsigned int start = clock();

while (clock()-start < 2000)
if (kbhit())
ch = getc();

something of the sort...

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites

  • 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!