oh ... i need to mention ...
my gues is ...
to apply real world math ... is to sync the render proces to refreshrate of the grafixcard.
recently i read about the Hobbit using a high frame rate of 48 frames a second.
there is so much the read on ... and so limited time ...
but basicly ... rendering ... on 70mhz (normal monitor refresh rate)....
1000 miliseconds / 70 mhz(frames) = 14,28571428571429 miliseconds.
so you have about 14 milisecond to render 1 frame and present it.
(that a topic ... i still need answer on)
oh .... besides ....
remember this ...
http://msdn.microsoft.com/en-us/library ... s.85).aspx
(i showed you in you acces class question thread, but apperently the link is broken and fixed)
Code: Select all
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
.
..
...
}
the threaded function returns a DWORD ... it probably can retun any other type ...
just past this function in your code and change DWORD to anything you want .... strip out the exces / add the missing essential stuff ... the stuff visual studio complains about and do some experiments ...
you can also put a copy of the putpixel(....) inside the threaded function. using a dualcore optimal : ) or 2 x
14 ms
async .... sofar i encountered no problems with sync problems ... (acces/mod the same varaibles by 2 different "objects") and i have a intel q9450.
Code: Select all
Game.h
.
..
...
void Game::StartMyThread(int x, int y, int r, int g, int b),
D3DCOLOR WINAPI Game::MyThreadFunction( LPVOID lpParam );
private:
PMYDATA pData;
DWORD dwThreadId;
HANDLE hThread;
typedef struct MyData {
int r, g, b, x, y;
} MYDATA, *PMYDATA;
Game.ccp
void Game::StartMyThread(int x, int y, int r, int g, int b)
{
pData = (PMYDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
if( pData == NULL )
{
// If the array allocation fails, the system is out of memory
// so there is no point in trying to print an error message.
// Just terminate execution.
return; // error
}
// Generate unique data for each thread to work with.
pData->r = r;
pData->g = g;
pData->b = b;
pData->x = x;
pData->y = y;
// Create the thread to begin execution on its own.
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function name
pData, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
// If CreateThread fails, terminate execution.
// This will automatically clean up threads and memory.
if (hThread == NULL)
{
// error
return; // error
}
// # this stuff till has to be adapted to your need and another location i.e: destructor
// Wait until all threads have terminated.
// WaitForMultipleObjects(MAX_THREADS, hThread, TRUE, INFINITE);
//
// Close all thread handle and free memory allocations.
// CloseHandle(hThread);
// if(pData != NULL)
// {
// HeapFree(GetProcessHeap(), 0, pData);
// pData = NULL; // Ensure address is not reused.
// }
}
D3DCOLOR WINAPI Game::MyThreadFunction( LPVOID lpParam )
[
PMYDATA pData; // local version
...
..
.
// Cast the parameter to the correct data type.
// The pointer is known to be valid because
// it was checked for NULL before the thread was created.
pData = (PMYDATA)lpParam;
...
..
.
D3DCOLOR c = new D3DCOLOR(
pData->r,
pData->g,
pData->b);
return c;
// or ...
// pSysBuffer[ pData->x + SCREENWIDTH * pData->y ] = c;
}
just add this to your project ...
it's loosely typed ... but i think ... it should compile or be easy to fix
if you should use this stuff and encounter sync problems in the future .. you need to put a mutex/lock on the variables you want to change and prevent other threads from modding it while you are working on it.