mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
Use a semaphore object to synchronize rendering thread with the game
This commit is contained in:
parent
5192ebc44f
commit
a40282013b
3
main.c
3
main.c
@ -154,6 +154,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
|||||||
|
|
||||||
EnterCriticalSection(&This->cs);
|
EnterCriticalSection(&This->cs);
|
||||||
This->render.run = FALSE;
|
This->render.run = FALSE;
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
LeaveCriticalSection(&This->cs);
|
LeaveCriticalSection(&This->cs);
|
||||||
|
|
||||||
WaitForSingleObject(This->render.thread, INFINITE);
|
WaitForSingleObject(This->render.thread, INFINITE);
|
||||||
@ -446,6 +447,7 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
|||||||
EnterCriticalSection(&This->cs);
|
EnterCriticalSection(&This->cs);
|
||||||
|
|
||||||
This->render.run = FALSE;
|
This->render.run = FALSE;
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
WaitForSingleObject(This->render.thread, INFINITE);
|
WaitForSingleObject(This->render.thread, INFINITE);
|
||||||
This->render.thread = NULL;
|
This->render.thread = NULL;
|
||||||
|
|
||||||
@ -561,6 +563,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
|
|
||||||
InitializeCriticalSection(&This->cs);
|
InitializeCriticalSection(&This->cs);
|
||||||
This->render.ev = CreateEvent(NULL, TRUE, FALSE, NULL);
|
This->render.ev = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
|
This->render.sem = CreateSemaphore(NULL, 0, 1, NULL);
|
||||||
|
|
||||||
/* load configuration options from ddraw.ini */
|
/* load configuration options from ddraw.ini */
|
||||||
char cwd[MAX_PATH];
|
char cwd[MAX_PATH];
|
||||||
|
1
main.h
1
main.h
@ -62,6 +62,7 @@ typedef struct IDirectDrawImpl
|
|||||||
HANDLE thread;
|
HANDLE thread;
|
||||||
BOOL run;
|
BOOL run;
|
||||||
HANDLE ev;
|
HANDLE ev;
|
||||||
|
HANDLE sem;
|
||||||
DEVMODE mode;
|
DEVMODE mode;
|
||||||
|
|
||||||
} render;
|
} render;
|
||||||
|
@ -44,6 +44,8 @@ HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
render.c
2
render.c
@ -87,7 +87,7 @@ DWORD WINAPI render_main(void)
|
|||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
while(ddraw->render.run)
|
while(ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
scale_w = (float)ddraw->width/tex_width;
|
scale_w = (float)ddraw->width/tex_width;
|
||||||
scale_h = (float)ddraw->height/tex_height;
|
scale_h = (float)ddraw->height/tex_height;
|
||||||
|
@ -50,7 +50,7 @@ DWORD WINAPI render_soft_main(void)
|
|||||||
frame_len = 1000.0f / ddraw->render.maxfps;
|
frame_len = 1000.0f / ddraw->render.maxfps;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ddraw->render.run)
|
while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
if(ddraw->render.maxfps > 0)
|
if(ddraw->render.maxfps > 0)
|
||||||
{
|
{
|
||||||
|
18
surface.c
18
surface.c
@ -93,12 +93,6 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run)
|
|
||||||
{
|
|
||||||
WaitForSingleObject(ddraw->render.ev, INFINITE);
|
|
||||||
ResetEvent(ddraw->render.ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Source)
|
if(Source)
|
||||||
{
|
{
|
||||||
int dx=0,dy=0;
|
int dx=0,dy=0;
|
||||||
@ -126,6 +120,13 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run)
|
||||||
|
{
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
|
WaitForSingleObject(ddraw->render.ev, INFINITE);
|
||||||
|
ResetEvent(ddraw->render.ev);
|
||||||
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +335,11 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe
|
|||||||
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
|
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run)
|
||||||
|
{
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user