1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

Try to avoid race condition on startup, more work on limiting the scrolling speed

This commit is contained in:
Toni Spets 2010-11-05 17:45:32 +02:00
parent b6f989eeee
commit 5edb561b2b
4 changed files with 34 additions and 29 deletions

View File

@ -1,5 +1,5 @@
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:
rm -f ddraw.dll

2
main.c
View File

@ -316,6 +316,7 @@ HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HAN
#if _DEBUG
printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This);
#endif
WaitForSingleObject(ddraw->ev, INFINITE);
return DD_OK;
}
@ -407,7 +408,6 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
printf(" This = %p\n", This);
*lplpDD = (LPDIRECTDRAW)This;
ddraw = This;
InitializeCriticalSection(&This->cs);
This->windowed = TRUE;

1
main.h
View File

@ -39,6 +39,7 @@ typedef struct IDirectDrawImpl
DWORD freq;
BOOL windowed;
CRITICAL_SECTION cs;
HANDLE ev;
HWND hWnd;
LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM);

View File

@ -99,8 +99,7 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
if(This->caps & DDSCAPS_PRIMARYSURFACE)
{
EnterCriticalSection(&ddraw->cs);
LeaveCriticalSection(&ddraw->cs);
WaitForSingleObject(ddraw->ev, INFINITE);
}
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;
}
@ -334,12 +327,6 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
#endif
if(This->caps & DDSCAPS_PRIMARYSURFACE)
{
EnterCriticalSection(&ddraw->cs);
LeaveCriticalSection(&ddraw->cs);
}
return DD_OK;
}
@ -427,11 +414,6 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
Surface->width = This->width;
Surface->height = This->height;
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);
@ -458,6 +440,15 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
Surface->Ref = 0;
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;
}
@ -563,37 +554,50 @@ DWORD WINAPI dd_Thread(IDirectDrawSurfaceImpl *This)
IDirectDrawClipper_SetHWnd(clipper, 0, This->hWnd);
IDirectDrawSurface_SetClipper(primary, clipper);
#ifdef FRAME_LIMIT
DWORD tick_start;
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)
{
tick_start = GetTickCount();
ResetEvent(ddraw->ev);
#ifdef FRAME_LIMIT
tick_start = GetTickCount();
#endif
IDirectDrawSurface_Lock(primary, NULL, &ddsd, DDLOCK_WRITEONLY|DDLOCK_WAIT, NULL);
/* convert ddraw surface to opengl texture */
for(i=0; i<This->height; i++)
if(This->palette)
{
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);
#ifdef FRAME_LIMIT
tick_end = GetTickCount();
if(tick_end - tick_start < frame_len)
{
EnterCriticalSection(&ddraw->cs);
Sleep( frame_len - (tick_end - tick_start) );
LeaveCriticalSection(&ddraw->cs);
}
#endif
SetEvent(ddraw->ev);
}
CloseHandle(ddraw->ev);
IDirectDrawClipper_Release(clipper);
IDirectDrawSurface_Release(primary);