What exactly does clock() do?
Sep 11, 2014 at 3:35pm UTC
I guess i understand that it starts as so as the program starts but in this example it loops, not as fast when the !getasynckeystate is there but still what going on. I borrow this code from somebody else and they didn't respond and this is a piece
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
#include <string>
#include <Windows.h>
#include <ctime>
int isGameAvail = clock();
int main ()
{
while (!GetAsyncKeyState(VK_INSERT))
{
if (clock() - isGameAvail > 400)
{
isGameAvail = clock(); //-> Why is this called when it's defined?
std::cout << "Example " << std::endl;
}
system("PAUSE" );
}
Sep 11, 2014 at 4:13pm UTC
> Why is this called when it's defined?
¿what?
Sep 11, 2014 at 6:52pm UTC
It looks like a very shoddy hack to try and control the speed that
gets printed on the terminal.
That there loop causes heavy CPU load. You should use a proper sleep()/delay() function.
Here's a Windows/POSIX solution that should work well everywhere
(See the
IsKeyPressed() function)
http://www.cplusplus.com/forum/beginner/131352/#msg708089
Hope this helps.
Sep 13, 2014 at 12:22am UTC
Thanks!
Topic archived. No new replies allowed.