Advertisement

HEY MOE-problem with timer code

Started by August 15, 2000 09:29 AM
-1 comments, last by Tracy 24 years, 4 months ago
Hey Moe, did you get the code from ch4 to work? I''ve had problems with the timer stuff. Everything builds but I get linker warnings and the .exe gives me error messages. In case you or anyone else is wondering what I''m talking about, here''s the code: /* WinMain (application loop) */ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { //locals MSG msg; BOOL notDone=TRUE; //and stuff for the timer LONGLONG cur_Time; DWORD time_Count=16; LONGLONG perf_Cnt; BOOL perf_Flag=FALSE; LONGLONG next_Time=0; LONGLONG last_Time=0; double time_Elapsed; double time_Scale; //initialize app, exit on failure if(!initApp(hInstance,nCmdShow)) /**/ { Cleanup(); /**/ return FALSE; } //is there a performance counter available? if(QueryPerformanceFrequency((LARGE_INTEGER *) &perf_Cnt)) { perf_Flag=TRUE; //next line gets linker error //warning C4244: ''='' : conversion from ''__int64'' to //''unsigned long'', possible loss of data time_Count=perf_Cnt/60; QueryPerformanceCounter((LARGE_INTEGER *) &next_Time); time_Scale=1.0/perf_Cnt; } else { //no performance counter, read in using timeGetTime() next_Time=timeGetTime(); time_Scale=0.001; time_Count=33; } //save time of the last frame last_Time=next_Time; //the loop while(notDone) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message==WM_QUIT) notDone=FALSE; TranslateMessage(&msg); DispatchMessage(&msg); } else { //use appropriate method to get time and //calculate elapsed time since last frame if(perf_Flag) QueryPerformanceCounter((LARGE_INTEGER *) &cur_Time); else cur_Time=timeGetTime(); //time to render frame? if(cur_Time>next_Time) { time_Elapsed=(cur_Time-last_Time)*time_Scale; last_Time=cur_Time; //move the screen position xpos+=move_Rate*time_Elapsed; if(xposMAX_POS) { xpos=MAX_POS; move_Rate=0; } //render the frame renderFrame(); /**/ //set time for next frame next_Time=cur_Time+time_Count; } } } //exit returning final message return(msg.wParam); } /* WinMain */ The problem is with this line: time_Count=perf_Cnt/60; Thanks in advance for any help. "A man can't just sit around." 'Lawn Chair' Larry Walters (1982)
"A man can't just sit around." 'Lawn Chair' Larry Walters (1982)

This topic is closed to new replies.

Advertisement