mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
Synchronize Unlock and Blt with drawing loop, force loop to constant 60 FPS, fixes too fast scrolling (its still fast)
This commit is contained in:
parent
9606f1b54f
commit
b6f989eeee
2
Makefile
2
Makefile
@ -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
|
||||
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
|
||||
|
||||
clean:
|
||||
rm -f ddraw.dll
|
||||
|
11
main.c
11
main.c
@ -194,12 +194,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
ddraw->cursor.y = HIWORD(lParam);
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
if(ddraw_primary)
|
||||
{
|
||||
SetEvent(ddraw_primary->flipEvent);
|
||||
}
|
||||
break;
|
||||
case WM_MOVE:
|
||||
ddraw->winpos.x = LOWORD(lParam);
|
||||
ddraw->winpos.y = HIWORD(lParam);
|
||||
@ -211,11 +205,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
ddraw->winpos.y = 0;
|
||||
}
|
||||
|
||||
if(ddraw_primary)
|
||||
{
|
||||
SetEvent(ddraw_primary->flipEvent);
|
||||
}
|
||||
break;
|
||||
case WM_WINDOWPOSCHANGED:
|
||||
GetClientRect(ddraw->hWnd, &ddraw->cursorclip);
|
||||
|
1
main.h
1
main.h
@ -38,6 +38,7 @@ typedef struct IDirectDrawImpl
|
||||
DWORD bpp;
|
||||
DWORD freq;
|
||||
BOOL windowed;
|
||||
CRITICAL_SECTION cs;
|
||||
|
||||
HWND hWnd;
|
||||
LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM);
|
||||
|
6
mouse.c
6
mouse.c
@ -87,7 +87,6 @@ void mouse_lock()
|
||||
ddraw->locked = TRUE;
|
||||
ClipCursor(&ddraw->cursorclip);
|
||||
while(ShowCursor(FALSE) > 0);
|
||||
SetEvent(ddraw_primary->flipEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,11 +106,6 @@ void mouse_unlock()
|
||||
ClipCursor(NULL);
|
||||
ddraw->cursor.x = ddraw->width / 2;
|
||||
ddraw->cursor.y = ddraw->height / 2;
|
||||
|
||||
if(ddraw_primary)
|
||||
{
|
||||
SetEvent(ddraw_primary->flipEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void mouse_init(HWND hWnd)
|
||||
|
42
surface.c
42
surface.c
@ -51,7 +51,6 @@ ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
|
||||
if(This->dThread)
|
||||
{
|
||||
This->dRun = FALSE;
|
||||
SetEvent(This->flipEvent);
|
||||
WaitForSingleObject(This->dThread, INFINITE);
|
||||
This->dThread = NULL;
|
||||
}
|
||||
@ -98,6 +97,12 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
||||
}
|
||||
#endif
|
||||
|
||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
|
||||
if(Source)
|
||||
{
|
||||
int dx=0,dy=0;
|
||||
@ -125,7 +130,11 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
|
||||
}
|
||||
}
|
||||
|
||||
SetEvent(This->flipEvent);
|
||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
@ -327,7 +336,8 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe
|
||||
|
||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
SetEvent(This->flipEvent);
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
@ -474,12 +484,13 @@ DWORD WINAPI ogl_Thread(IDirectDrawSurfaceImpl *This)
|
||||
This->hRC = wglCreateContext( This->hDC );
|
||||
wglMakeCurrent( This->hDC, This->hRC );
|
||||
|
||||
This->flipEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DWORD tick_start;
|
||||
DWORD tick_end;
|
||||
DWORD frame_len = 1000.0f / 60.0f /*This->parent->freq*/;
|
||||
|
||||
while(This->dRun)
|
||||
{
|
||||
WaitForSingleObject(This->flipEvent, INFINITE);
|
||||
ResetEvent(This->flipEvent);
|
||||
tick_start = GetTickCount();
|
||||
|
||||
/* convert ddraw surface to opengl texture */
|
||||
for(i=0; i<This->height; i++)
|
||||
@ -505,6 +516,15 @@ DWORD WINAPI ogl_Thread(IDirectDrawSurfaceImpl *This)
|
||||
glEnd();
|
||||
|
||||
SwapBuffers(This->hDC);
|
||||
|
||||
tick_end = GetTickCount();
|
||||
|
||||
if(tick_end - tick_start < frame_len)
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
Sleep( frame_len - (tick_end - tick_start) );
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
}
|
||||
|
||||
free(glTex);
|
||||
@ -543,19 +563,15 @@ DWORD WINAPI dd_Thread(IDirectDrawSurfaceImpl *This)
|
||||
IDirectDrawClipper_SetHWnd(clipper, 0, This->hWnd);
|
||||
IDirectDrawSurface_SetClipper(primary, clipper);
|
||||
|
||||
This->flipEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
WaitForSingleObject(This->flipEvent, INFINITE);
|
||||
|
||||
DWORD tick_start;
|
||||
DWORD tick_end;
|
||||
DWORD frame_len = 1000.0f / This->parent->freq;
|
||||
DWORD frame_len = 1000.0f / 60.0f /*This->parent->freq*/;
|
||||
|
||||
while(This->dRun)
|
||||
{
|
||||
tick_start = GetTickCount();
|
||||
|
||||
if(IDirectDrawSurface_Lock(primary, NULL, &ddsd, DDLOCK_WRITEONLY|DDLOCK_WAIT, NULL) != DD_OK)
|
||||
continue;
|
||||
IDirectDrawSurface_Lock(primary, NULL, &ddsd, DDLOCK_WRITEONLY|DDLOCK_WAIT, NULL);
|
||||
|
||||
/* convert ddraw surface to opengl texture */
|
||||
for(i=0; i<This->height; i++)
|
||||
@ -572,7 +588,9 @@ DWORD WINAPI dd_Thread(IDirectDrawSurfaceImpl *This)
|
||||
|
||||
if(tick_end - tick_start < frame_len)
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
Sleep( frame_len - (tick_end - tick_start) );
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user