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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
LONGLONG cur_time; // current time
DWORD time_count=40; // ms per frame, default if no performance counter
LONGLONG perf_cnt=0; // performance timer frequency
LONGLONG next_time=0; // time to render next frame
BOOL move_flag=TRUE; // flag noting if we have moved yet
QueryPerformanceFrequency((LARGE_INTEGER *) &perf_cnt);
time_count=static_cast<DWORD>(perf_cnt/25); // calculate time per frame based on frequency
QueryPerformanceCounter((LARGE_INTEGER *) &next_time);
// prime the message structure
PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE);
// run till completed
while (msg.message!=WM_QUIT) {
// is there a message to process?
if (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) {
// dispatch the message
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
// do we need to move?
if (move_flag) {
// yes, move and clear flag
D3DXMatrixRotationX(&Rotation, 0.0f);
D3DXMatrixTranslation(&Translation,0.0f,0.0f,0.0f);
D3DXMatrixMultiply(&Welt, &Rotation, &Translation);
move_flag=FALSE;
}
QueryPerformanceCounter((LARGE_INTEGER *) &cur_time);
// is it time to render the frame?
if (cur_time>next_time) {
// yes, render the frame
test->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
test->BeginScene();
test->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, &Dreieck, sizeof(SVertex));
test->EndScene();
test->Present(NULL,NULL,NULL,NULL);
// set time for next frame
next_time += time_count;
// If we get more than a frame ahead, allow us to drop one
// Otherwise, we will never catch up if we let the error
// accumulate, and message handling will suffer
if (next_time < cur_time)
next_time = cur_time + time_count;
// flag that we need to move objects again
move_flag=TRUE;
}
}
}
|