mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
Try to avoid race condition on startup, more work on limiting the scrolling speed
This commit is contained in:
parent
b6f989eeee
commit
5edb561b2b
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
all:
|
all:
|
||||||
i586-mingw32msvc-gcc -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c mouse.c palette.c surface.c clipper.c ddraw.def -lgdi32 -lopengl32
|
i586-mingw32msvc-gcc -D_DEBUG -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c mouse.c palette.c surface.c clipper.c ddraw.def -lgdi32 -lopengl32
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ddraw.dll
|
rm -f ddraw.dll
|
||||||
|
2
main.c
2
main.c
@ -316,6 +316,7 @@ HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HAN
|
|||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This);
|
printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This);
|
||||||
#endif
|
#endif
|
||||||
|
WaitForSingleObject(ddraw->ev, INFINITE);
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +408,6 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
printf(" This = %p\n", This);
|
printf(" This = %p\n", This);
|
||||||
*lplpDD = (LPDIRECTDRAW)This;
|
*lplpDD = (LPDIRECTDRAW)This;
|
||||||
ddraw = This;
|
ddraw = This;
|
||||||
InitializeCriticalSection(&This->cs);
|
|
||||||
|
|
||||||
This->windowed = TRUE;
|
This->windowed = TRUE;
|
||||||
|
|
||||||
|
1
main.h
1
main.h
@ -39,6 +39,7 @@ typedef struct IDirectDrawImpl
|
|||||||
DWORD freq;
|
DWORD freq;
|
||||||
BOOL windowed;
|
BOOL windowed;
|
||||||
CRITICAL_SECTION cs;
|
CRITICAL_SECTION cs;
|
||||||
|
HANDLE ev;
|
||||||
|
|
||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
58
surface.c
58
surface.c
@ -99,8 +99,7 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
|||||||
|
|
||||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&ddraw->cs);
|
WaitForSingleObject(ddraw->ev, INFINITE);
|
||||||
LeaveCriticalSection(&ddraw->cs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Source)
|
if(Source)
|
||||||
@ -130,12 +129,6 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&ddraw->cs);
|
|
||||||
LeaveCriticalSection(&ddraw->cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,12 +327,6 @@ 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)
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&ddraw->cs);
|
|
||||||
LeaveCriticalSection(&ddraw->cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,11 +414,6 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
|||||||
Surface->width = This->width;
|
Surface->width = This->width;
|
||||||
Surface->height = This->height;
|
Surface->height = This->height;
|
||||||
Surface->hWnd = This->hWnd;
|
Surface->hWnd = This->hWnd;
|
||||||
#if USE_OPENGL
|
|
||||||
Surface->dThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ogl_Thread, (void *)Surface, 0, NULL);
|
|
||||||
#else
|
|
||||||
Surface->dThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)dd_Thread, (void *)Surface, 0, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_ddscaps(lpDDSurfaceDesc->ddsCaps.dwCaps);
|
dump_ddscaps(lpDDSurfaceDesc->ddsCaps.dwCaps);
|
||||||
@ -458,6 +440,15 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
|||||||
Surface->Ref = 0;
|
Surface->Ref = 0;
|
||||||
ddraw_surface_AddRef(Surface);
|
ddraw_surface_AddRef(Surface);
|
||||||
|
|
||||||
|
if(Surface->caps & DDSCAPS_PRIMARYSURFACE)
|
||||||
|
{
|
||||||
|
#if USE_OPENGL
|
||||||
|
Surface->dThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ogl_Thread, (void *)Surface, 0, NULL);
|
||||||
|
#else
|
||||||
|
Surface->dThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)dd_Thread, (void *)Surface, 0, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,37 +554,50 @@ DWORD WINAPI dd_Thread(IDirectDrawSurfaceImpl *This)
|
|||||||
IDirectDrawClipper_SetHWnd(clipper, 0, This->hWnd);
|
IDirectDrawClipper_SetHWnd(clipper, 0, This->hWnd);
|
||||||
IDirectDrawSurface_SetClipper(primary, clipper);
|
IDirectDrawSurface_SetClipper(primary, clipper);
|
||||||
|
|
||||||
|
#ifdef FRAME_LIMIT
|
||||||
DWORD tick_start;
|
DWORD tick_start;
|
||||||
DWORD tick_end;
|
DWORD tick_end;
|
||||||
DWORD frame_len = 1000.0f / 60.0f /*This->parent->freq*/;
|
DWORD frame_len = 1000.0f / This->parent->freq;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
InitializeCriticalSection(&ddraw->cs);
|
||||||
|
ddraw->ev = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
|
|
||||||
while(This->dRun)
|
while(This->dRun)
|
||||||
{
|
{
|
||||||
tick_start = GetTickCount();
|
ResetEvent(ddraw->ev);
|
||||||
|
|
||||||
|
#ifdef FRAME_LIMIT
|
||||||
|
tick_start = GetTickCount();
|
||||||
|
#endif
|
||||||
IDirectDrawSurface_Lock(primary, NULL, &ddsd, DDLOCK_WRITEONLY|DDLOCK_WAIT, NULL);
|
IDirectDrawSurface_Lock(primary, NULL, &ddsd, DDLOCK_WRITEONLY|DDLOCK_WAIT, NULL);
|
||||||
|
|
||||||
/* convert ddraw surface to opengl texture */
|
if(This->palette)
|
||||||
for(i=0; i<This->height; i++)
|
|
||||||
{
|
{
|
||||||
for(j=0; j<This->width; j++)
|
for(i=0; i<This->height; i++)
|
||||||
{
|
{
|
||||||
((int *)ddsd.lpSurface)[(i+This->parent->winpos.y)*width+(j+This->parent->winpos.x)] = This->palette->data[((unsigned char *)This->surface)[i*This->lPitch + j*This->lXPitch]];
|
for(j=0; j<This->width; j++)
|
||||||
|
{
|
||||||
|
((int *)ddsd.lpSurface)[(i+This->parent->winpos.y)*width+(j+This->parent->winpos.x)] = This->palette->data[((unsigned char *)This->surface)[i*This->lPitch + j*This->lXPitch]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirectDrawSurface_Unlock(primary, NULL);
|
IDirectDrawSurface_Unlock(primary, NULL);
|
||||||
|
|
||||||
|
#ifdef FRAME_LIMIT
|
||||||
tick_end = GetTickCount();
|
tick_end = GetTickCount();
|
||||||
|
|
||||||
if(tick_end - tick_start < frame_len)
|
if(tick_end - tick_start < frame_len)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&ddraw->cs);
|
|
||||||
Sleep( frame_len - (tick_end - tick_start) );
|
Sleep( frame_len - (tick_end - tick_start) );
|
||||||
LeaveCriticalSection(&ddraw->cs);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
SetEvent(ddraw->ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseHandle(ddraw->ev);
|
||||||
|
|
||||||
IDirectDrawClipper_Release(clipper);
|
IDirectDrawClipper_Release(clipper);
|
||||||
IDirectDrawSurface_Release(primary);
|
IDirectDrawSurface_Release(primary);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user