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