- Joined
- Mar 15, 2006
- Messages
- 451
- Reaction score
- 285
without big explanations.
Here is a part of the code in main.exe
Imagine that we have a simple scene and frame is drawn in 10ms.
After frame is drawn we get here
for 30 ms we will use cpu just to check if 40ms have passed since frame started to draw.
why we just don't go to sleep for a little and then check for the passed time? Let the system do useful things
So the point is - don't waste cpu time if we have a simple frame that is drawn faster then 40 ms.
How to add this thing in main using ollydbg:
1. Search for SwapBuffers or glFlush (search for name/lable CTRL+N)
and you will find this part of the code
in 97d it will look like this:
1.03.27 jpn:
2. Modify the code by adding sleep function call:
97d:
1.03.27 jpn:
Note: if main spends >= 40 ms for frame drawing, this thing won't save you from high cpu usage cpu will be busy in drawing frame
this thing needs testings, i made some tests + thx to Dios he made little tests, so test and maybe it will be useful
Here is a part of the code in main.exe
PHP:
startDraw = GetTickCount();
drawFrame();
frameTime = GetTickCount() - startDraw;
while(frameTime < 40)
{
frameTime = GetTickCount() - startDraw;
}
Imagine that we have a simple scene and frame is drawn in 10ms.
After frame is drawn we get here
PHP:
while(frameTime < 40)
{
frameTime = GetTickCount() - startDraw;
}
for 30 ms we will use cpu just to check if 40ms have passed since frame started to draw.
why we just don't go to sleep for a little and then check for the passed time? Let the system do useful things
PHP:
while(frameTime < 40)
{
Sleep(1); // will sleep for 10-15 ms, depending on time accuracy
frameTime = GetTickCount() - startDraw;
}
So the point is - don't waste cpu time if we have a simple frame that is drawn faster then 40 ms.
How to add this thing in main using ollydbg:
1. Search for SwapBuffers or glFlush (search for name/lable CTRL+N)
and you will find this part of the code
PHP:
frameTime = GetTickCount() - startDraw;
while(frameTime < 40)
{
frameTime = GetTickCount() - startDraw;
}
in 97d it will look like this:
1.03.27 jpn:
2. Modify the code by adding sleep function call:
97d:
1.03.27 jpn:
Note: if main spends >= 40 ms for frame drawing, this thing won't save you from high cpu usage cpu will be busy in drawing frame
this thing needs testings, i made some tests + thx to Dios he made little tests, so test and maybe it will be useful