mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-12 08:00:55 +02:00
Complete removal of directdraw and replaced with OpenGL. Has some bugs, movies disabled.
This commit is contained in:
+8
-15
@@ -15,8 +15,6 @@ set(src_win32lib
|
||||
./RedAlert/WIN32LIB/BUFFER.CPP
|
||||
./RedAlert/WIN32LIB/BUFFER.H
|
||||
./RedAlert/WIN32LIB/BUFFGLBL.CPP
|
||||
./RedAlert/WIN32LIB/DDRAW.CPP
|
||||
./RedAlert/WIN32LIB/DDRAW.H
|
||||
./RedAlert/WIN32LIB/DEFINES.H
|
||||
./RedAlert/WIN32LIB/DELAY.CPP
|
||||
./RedAlert/WIN32LIB/DESCMGMT.H
|
||||
@@ -621,14 +619,9 @@ set(src_redalert
|
||||
)
|
||||
|
||||
set(src_external
|
||||
#Direct Draw Wrapper
|
||||
./ddraw/ddrawwrapper/ddraw2.cpp
|
||||
./ddraw/ddrawwrapper/DirectDrawClipperWrapper.cpp
|
||||
./ddraw/ddrawwrapper/DirectDrawPaletteWrapper.cpp
|
||||
./ddraw/ddrawwrapper/DirectDrawSurfaceWrapper.cpp
|
||||
./ddraw/ddrawwrapper/DirectDrawWrapper.cpp
|
||||
./ddraw/ddrawwrapper/DirectDrawWrapper.h
|
||||
|
||||
#glew
|
||||
./external/gl/glew.c
|
||||
|
||||
#libsmacker
|
||||
./external/libsmacker/smacker.c
|
||||
./external/libsmacker/smacker.h
|
||||
@@ -644,8 +637,8 @@ set(src_external
|
||||
./external/imgui/imgui.h
|
||||
./external/imgui/imgui_draw.cpp
|
||||
./external/imgui/imgui_widgets.cpp
|
||||
./external/imgui/examples/imgui_impl_dx9.cpp
|
||||
./external/imgui/examples/imgui_impl_dx9.h
|
||||
./external/imgui/examples/imgui_impl_opengl3.cpp
|
||||
./external/imgui/examples/imgui_impl_opengl3.h
|
||||
./external/imgui/examples/imgui_impl_sdl.cpp
|
||||
./external/imgui/examples/imgui_impl_sdl.h
|
||||
|
||||
@@ -712,12 +705,12 @@ set(src_external
|
||||
|
||||
)
|
||||
|
||||
add_definitions(-DCHEAT_KEYS -DSCENARIO_EDITOR -DWINDOWS_IGNORE_PACKING_MISMATCH -DTRUE_FALSE_DEFINED -DWIN32 -DWINDOWS -DENGLISH -D_USRDLL -DREDALERT_EXPORTS)
|
||||
add_definitions(-DCHEAT_KEYS -DIMGUI_IMPL_OPENGL_LOADER_GLEW -DSCENARIO_EDITOR -DWINDOWS_IGNORE_PACKING_MISMATCH -DTRUE_FALSE_DEFINED -DWIN32 -DWINDOWS -DENGLISH -D_USRDLL -DREDALERT_EXPORTS)
|
||||
add_compile_options(/permissive+ /Zc:forScope- /Zp1)
|
||||
add_executable(RedAlert ${src_win32lib} ${src_redalert} ${src_external})
|
||||
|
||||
|
||||
|
||||
set_target_properties(RedAlert PROPERTIES OUTPUT_NAME "RedAlert" LINK_FLAGS "/PDB:\"RedAlert.pdb\" /SUBSYSTEM:WINDOWS")
|
||||
target_include_directories(RedAlert PRIVATE ./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include)
|
||||
target_link_libraries(RedAlert "d3d9.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/dxsdk/Lib/x86/d3dx9.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib")
|
||||
target_include_directories(RedAlert PRIVATE ./external/;./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include)
|
||||
target_link_libraries(RedAlert "opengl32.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/dxsdk/Lib/x86/d3dx9.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib")
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <windows.h>
|
||||
#include <ddraw.h>
|
||||
//#include <ddraw.h>
|
||||
|
||||
#ifdef MPGEXPORT
|
||||
#define DLLCALL __declspec(dllexport)
|
||||
|
||||
+31
-34
@@ -38,10 +38,7 @@
|
||||
// jmarshall - imgui
|
||||
#include "imgui.h"
|
||||
#include "examples/imgui_impl_sdl.h"
|
||||
#include "examples/imgui_impl_dx9.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
extern LPDIRECT3DDEVICE9 globald3d9Device;
|
||||
#include "examples/imgui_impl_opengl3.h"
|
||||
extern SDL_Window* game_window;
|
||||
// jmarshall end
|
||||
|
||||
@@ -577,7 +574,7 @@ int PASCAL WinMain ( HINSTANCE instance , HINSTANCE , char * command_line , int
|
||||
|
||||
// Setup Platform/Renderer bindings
|
||||
ImGui_ImplSDL2_InitForD3D(game_window);
|
||||
ImGui_ImplDX9_Init(globald3d9Device);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
io.Fonts->AddFontFromFileTTF("code/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
// jmarshall end
|
||||
@@ -599,18 +596,18 @@ int PASCAL WinMain ( HINSTANCE instance , HINSTANCE , char * command_line , int
|
||||
/*
|
||||
** Check that we really got a video memory page. Failure is fatal.
|
||||
*/
|
||||
DDSCAPS surface_capabilities;
|
||||
memset (&surface_capabilities, 0, sizeof(surface_capabilities));
|
||||
VisiblePage.Get_DD_Surface()->GetCaps(&surface_capabilities);
|
||||
if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
|
||||
/*
|
||||
** Aaaarrgghh!
|
||||
*/
|
||||
WWDebugString(TEXT_DDRAW_ERROR);WWDebugString("\n");
|
||||
MessageBox(MainWindow, TEXT_DDRAW_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
|
||||
if (WindowsTimer) delete WindowsTimer;
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
//DDSCAPS surface_capabilities;
|
||||
//memset (&surface_capabilities, 0, sizeof(surface_capabilities));
|
||||
//VisiblePage.Get_DD_Surface()->GetCaps(&surface_capabilities);
|
||||
//if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
|
||||
// /*
|
||||
// ** Aaaarrgghh!
|
||||
// */
|
||||
// WWDebugString(TEXT_DDRAW_ERROR);WWDebugString("\n");
|
||||
// MessageBox(MainWindow, TEXT_DDRAW_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
|
||||
// if (WindowsTimer) delete WindowsTimer;
|
||||
// return (EXIT_FAILURE);
|
||||
//}
|
||||
|
||||
/*
|
||||
** If we have enough left then put the hidpage in video memory unless...
|
||||
@@ -628,27 +625,27 @@ int PASCAL WinMain ( HINSTANCE instance , HINSTANCE , char * command_line , int
|
||||
!VideoBackBufferAllowed) {
|
||||
HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
|
||||
} else {
|
||||
//HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
|
||||
HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)GBC_VIDEOMEM);
|
||||
HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
|
||||
//HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)GBC_VIDEOMEM);
|
||||
|
||||
/*
|
||||
** Make sure we really got a video memory hid page. If we didnt then things
|
||||
** will run very slowly.
|
||||
*/
|
||||
memset (&surface_capabilities, 0, sizeof(surface_capabilities));
|
||||
HiddenPage.Get_DD_Surface()->GetCaps(&surface_capabilities);
|
||||
if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
|
||||
|
||||
/*
|
||||
** Oh dear, big trub. This must be an IBM Aptiva or something similarly cruddy.
|
||||
** We must redo the Hidden Page as system memory.
|
||||
*/
|
||||
AllSurfaces.Remove_DD_Surface(HiddenPage.Get_DD_Surface()); // Remove the old surface from the AllSurfaces list
|
||||
HiddenPage.Get_DD_Surface()->Release();
|
||||
HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
|
||||
} else {
|
||||
VisiblePage.Attach_DD_Surface(&HiddenPage);
|
||||
}
|
||||
//memset (&surface_capabilities, 0, sizeof(surface_capabilities));
|
||||
//HiddenPage.Get_DD_Surface()->GetCaps(&surface_capabilities);
|
||||
//if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
|
||||
//
|
||||
// /*
|
||||
// ** Oh dear, big trub. This must be an IBM Aptiva or something similarly cruddy.
|
||||
// ** We must redo the Hidden Page as system memory.
|
||||
// */
|
||||
// AllSurfaces.Remove_DD_Surface(HiddenPage.Get_DD_Surface()); // Remove the old surface from the AllSurfaces list
|
||||
// HiddenPage.Get_DD_Surface()->Release();
|
||||
// HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
|
||||
//} else {
|
||||
// VisiblePage.Attach_DD_Surface(&HiddenPage);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,7 +835,7 @@ bool InitDDraw(void)
|
||||
|
||||
VisiblePage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)(GBC_VISIBLE | GBC_VIDEOMEM));
|
||||
HiddenPage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)GBC_VIDEOMEM);
|
||||
VisiblePage.Attach_DD_Surface(&HiddenPage);
|
||||
// VisiblePage.Attach_DD_Surface(&HiddenPage);
|
||||
SeenBuff.Attach(&VisiblePage, 0, 0, 3072, 3072);
|
||||
HidPage.Attach(&HiddenPage, 0, 0, 3072, 3072);
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ long VQA_Play(_VQAHandle* vqaHandle) {
|
||||
int currentFrame = 0;
|
||||
bool shouldSampleAudio = true;
|
||||
|
||||
return 0;
|
||||
|
||||
smk_first(vqaHandle->smacker_video);
|
||||
|
||||
while (currentFrame < vqaHandle->frame_count) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+62
-337
@@ -31,6 +31,7 @@
|
||||
**
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gbuffer.h"
|
||||
#include "MISC.H"
|
||||
#include "WSA.H"
|
||||
@@ -40,7 +41,7 @@ IconCacheClass::IconCacheClass (void)
|
||||
IsCached =FALSE;
|
||||
SurfaceLost =FALSE;
|
||||
DrawFrequency =0;
|
||||
CacheSurface =NULL;
|
||||
//CacheSurface =NULL;
|
||||
IconSource =NULL;
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ extern "C" int __cdecl Get_Free_Index (void) {return 0;};
|
||||
extern "C" BOOL __cdecl Cache_New_Icon (int icon_index, void *icon_ptr) {return -1;};
|
||||
extern "C" int __cdecl Get_Free_Cache_Slot(void) {return -1;}
|
||||
|
||||
void IconCacheClass::Draw_It (LPDIRECTDRAWSURFACE dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height) {}
|
||||
void IconCacheClass::Draw_It (void *dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height) {}
|
||||
|
||||
|
||||
|
||||
@@ -1302,76 +1303,11 @@ void __cdecl Buffer_Fill_Rect(void *thisptr, int sx, int sy, int dx, int dy, uns
|
||||
*/
|
||||
void __cdecl Buffer_Clear(void *this_object, unsigned char color)
|
||||
{
|
||||
unsigned int local_color = color;
|
||||
GraphicViewPortClass* cls = (GraphicViewPortClass*)this_object;
|
||||
if (cls->Get_Graphic_Buffer()->GetMemoryBuffer() == NULL)
|
||||
return;
|
||||
|
||||
__asm {
|
||||
|
||||
cld ; always go forward
|
||||
|
||||
mov ebx,[this_object] ; get a pointer to viewport
|
||||
mov edi,[ebx]GraphicViewPortClass.Offset ; get the correct offset
|
||||
mov edx,[ebx]GraphicViewPortClass.Height ; get height from viewport
|
||||
mov esi,[ebx]GraphicViewPortClass.Width ; get width from viewport
|
||||
//push [dword (GraphicViewPort ebx).GVPPitch] ; extra pitch of direct draw surface
|
||||
push [ebx]GraphicViewPortClass.Pitch
|
||||
|
||||
mov ebx,[ebx]GraphicViewPortClass.XAdd ; esi = add for each line
|
||||
add ebx,[esp] ; Yes, I know its nasty but
|
||||
add esp,4 ; it works!
|
||||
|
||||
;*===================================================================
|
||||
; Convert the color byte to a DWORD for fast storing
|
||||
;*===================================================================
|
||||
mov al,[color] ; get color to clear to
|
||||
mov ah,al ; extend across WORD
|
||||
mov ecx,eax ; extend across DWORD in
|
||||
shl eax,16 ; several steps
|
||||
mov ax,cx
|
||||
|
||||
;*===================================================================
|
||||
; Find out if we should bother to align the row.
|
||||
;*===================================================================
|
||||
|
||||
cmp esi , OPTIMAL_BYTE_COPY ; is it worth aligning them?
|
||||
jl byte_by_byte ; if not then skip
|
||||
|
||||
;*===================================================================
|
||||
; Figure out the alignment offset if there is any
|
||||
;*===================================================================
|
||||
push ebx
|
||||
|
||||
dword_aligned_loop:
|
||||
mov ecx , edi
|
||||
mov ebx , esi
|
||||
neg ecx
|
||||
and ecx , 3
|
||||
sub ebx , ecx
|
||||
rep stosb
|
||||
mov ecx , ebx
|
||||
shr ecx , 2
|
||||
rep stosd
|
||||
mov ecx , ebx
|
||||
and ecx , 3
|
||||
rep stosb
|
||||
add edi , [ esp ]
|
||||
dec edx ; decrement the height
|
||||
jnz dword_aligned_loop ; if more to do than do it
|
||||
pop eax
|
||||
jmp done
|
||||
//ret
|
||||
|
||||
;*===================================================================
|
||||
; If not enough bytes to bother aligning copy each line across a byte
|
||||
; at a time.
|
||||
;*===================================================================
|
||||
byte_by_byte:
|
||||
mov ecx,esi ; get total width in bytes
|
||||
rep stosb ; store the width
|
||||
add edi,ebx ; handle the xadd
|
||||
dec edx ; decrement the height
|
||||
jnz byte_by_byte ; if any left then next line
|
||||
done:
|
||||
}
|
||||
memset(cls->Get_Graphic_Buffer()->GetMemoryBuffer(), color, cls->Get_Width() * cls->Get_Height());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1392,33 +1328,12 @@ void __cdecl Buffer_Clear(void *this_object, unsigned char color)
|
||||
*/
|
||||
|
||||
// jmarshall - ported to c
|
||||
void Nearest_CopyImage(byte* source, int sourceX, int sourceY, int sourceWidth, int sourceHeight, byte* dest, int destX, int destY, int destWidth, int width, int height, bool trans)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int _x = x;
|
||||
int _y = y;
|
||||
int destPos = (destWidth * (_y + (destY))) + (_x + (destX));
|
||||
int sourcePos = (sourceWidth * (_y + (sourceY))) + (_x + (sourceX));
|
||||
|
||||
if (sourcePos > sourceWidth * sourceHeight)
|
||||
return;
|
||||
|
||||
if(source[sourcePos] != 0 || trans == false)
|
||||
dest[destPos] = source[sourcePos];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
byte* Draw_Dropsample(const byte* in, int inwidth, int inheight, int outwidth, int outheight) {
|
||||
unsigned char* Draw_Dropsample(const unsigned char* in, int inwidth, int inheight, int outwidth, int outheight) {
|
||||
int i, j, k;
|
||||
const byte* inrow;
|
||||
const byte* pix1;
|
||||
byte* out, * out_p;
|
||||
static byte ViewportPixelBuffer[4096 * 4096];
|
||||
const unsigned char* inrow;
|
||||
const unsigned char* pix1;
|
||||
unsigned char* out, * out_p;
|
||||
static unsigned char ViewportPixelBuffer[4096 * 4096];
|
||||
|
||||
out = &ViewportPixelBuffer[0];
|
||||
out_p = out;
|
||||
@@ -1442,13 +1357,13 @@ BOOL __cdecl Linear_Scale_To_Linear(void *this_object, void *dest, int src_x, in
|
||||
GraphicViewPortClass* viewportClass = (GraphicViewPortClass*)this_object;
|
||||
GraphicViewPortClass* destViewportClass = (GraphicViewPortClass*)dest;
|
||||
|
||||
byte* viewportBuffer = ((byte*)viewportClass->Get_Offset());
|
||||
unsigned char* viewportBuffer = ((unsigned char*)viewportClass->Get_Offset());
|
||||
|
||||
// Scale the GraphicViewPortClass to dest_x, dest_y
|
||||
byte* scaled_buffer = Draw_Dropsample((byte *)viewportBuffer, viewportClass->Get_Width(), viewportClass->Get_Height(), dst_width, dst_height);
|
||||
unsigned char* scaled_buffer = Draw_Dropsample((unsigned char*)viewportBuffer, viewportClass->Get_Width(), viewportClass->Get_Height(), dst_width, dst_height);
|
||||
|
||||
// Blit the scaled_buffer to dest.
|
||||
Nearest_CopyImage(scaled_buffer, src_x, src_y, dst_width, dst_height, (byte *)destViewportClass->Get_Offset(), dst_x, dst_y, destViewportClass->Get_Width(), dst_width, dst_height, trans);
|
||||
Nearest_CopyImage(scaled_buffer, src_x, src_y, dst_width, dst_height, (unsigned char*)destViewportClass->Get_Offset(), dst_x, dst_y, destViewportClass->Get_Width(), dst_width, dst_height, trans);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1460,11 +1375,11 @@ BOOL __cdecl Linear_Blit_To_Linear(void* this_object, void* dest, int x_pixel, i
|
||||
bool needsUnlock = false;
|
||||
bool sourceNeedsUnlock = false;
|
||||
|
||||
byte* viewportBuffer = NULL;
|
||||
viewportBuffer = ((byte*)viewportClass->Get_Offset());
|
||||
unsigned char* viewportBuffer = NULL;
|
||||
viewportBuffer = ((unsigned char*)viewportClass->Get_Offset());
|
||||
|
||||
byte* destBuffer = NULL;
|
||||
destBuffer = ((byte*)destViewportClass->Get_Offset());
|
||||
unsigned char* destBuffer = NULL;
|
||||
destBuffer = ((unsigned char*)destViewportClass->Get_Offset());
|
||||
|
||||
//if (destViewportClass->Get_Graphic_Buffer()->Get_Buffer() != NULL) {
|
||||
// destBuffer = (byte*)destViewportClass->Get_Graphic_Buffer()->Get_Buffer();
|
||||
@@ -1482,7 +1397,7 @@ BOOL __cdecl Linear_Blit_To_Linear(void* this_object, void* dest, int x_pixel, i
|
||||
//}
|
||||
|
||||
// Blit the buffer to dest.
|
||||
Nearest_CopyImage(viewportBuffer, x_pixel, y_pixel, viewportClass->Get_Width(), viewportClass->Get_Height(), (byte*)destBuffer, dest_x0, dest_y0, destViewportClass->Get_Width(), pixel_width, pixel_height, trans);
|
||||
Nearest_CopyImage(viewportBuffer, x_pixel, y_pixel, viewportClass->Get_Width(), viewportClass->Get_Height(), (unsigned char*)destBuffer, dest_x0, dest_y0, destViewportClass->Get_Width(), pixel_width, pixel_height, trans);
|
||||
|
||||
//if (needsUnlock) {
|
||||
// destViewportClass->Get_Graphic_Buffer()->Unlock();
|
||||
@@ -4064,242 +3979,52 @@ CODESEG
|
||||
;*=========================================================================*
|
||||
*/
|
||||
|
||||
extern "C" long __cdecl Buffer_To_Page(int x_pixel, int y_pixel, int pixel_width, int pixel_height, void *src, void *dest)
|
||||
extern "C" long __cdecl Buffer_To_Page(int x, int y, int w, int h, void *buffer, void *dest)
|
||||
{
|
||||
GraphicViewPortClass& vp = *(GraphicViewPortClass*)dest;
|
||||
// from chronoshift
|
||||
int xstart = x;
|
||||
int ystart = y;
|
||||
int xend = x + w - 1;
|
||||
int yend = y + h - 1;
|
||||
|
||||
/*
|
||||
PROC Buffer_To_Page C near
|
||||
USES eax,ebx,ecx,edx,esi,edi
|
||||
int xoffset = 0;
|
||||
int yoffset = 0;
|
||||
|
||||
;*===================================================================
|
||||
;* define the arguements that our function takes.
|
||||
;*===================================================================
|
||||
ARG x_pixel :DWORD ; x pixel position in source
|
||||
ARG y_pixel :DWORD ; y pixel position in source
|
||||
ARG pixel_width :DWORD ; width of rectangle to blit
|
||||
ARG pixel_height:DWORD ; height of rectangle to blit
|
||||
ARG src :DWORD ; this is a member function
|
||||
ARG dest :DWORD ; what are we blitting to
|
||||
|
||||
; ARG trans :DWORD ; do we deal with transparents?
|
||||
|
||||
;*===================================================================
|
||||
; Define some locals so that we can handle things quickly
|
||||
;*===================================================================
|
||||
LOCAL x1_pixel :dword
|
||||
LOCAL y1_pixel :dword
|
||||
local scr_x : dword
|
||||
local scr_y : dword
|
||||
LOCAL dest_ajust_width:DWORD
|
||||
LOCAL scr_ajust_width:DWORD
|
||||
LOCAL dest_area : dword
|
||||
*/
|
||||
|
||||
unsigned long x1_pixel;
|
||||
unsigned long y1_pixel;
|
||||
unsigned long scr_x;
|
||||
unsigned long scr_y;
|
||||
unsigned long dest_ajust_width;
|
||||
unsigned long scr_ajust_width;
|
||||
//unsigned long dest_area;
|
||||
|
||||
__asm {
|
||||
|
||||
cmp [ src ] , 0
|
||||
jz real_out
|
||||
|
||||
|
||||
; Clip dest Rectangle against source Window boundaries.
|
||||
|
||||
mov [ scr_x ] , 0
|
||||
mov [ scr_y ] , 0
|
||||
mov esi , [ dest ] ; get ptr to dest
|
||||
xor ecx , ecx
|
||||
xor edx , edx
|
||||
mov edi , [esi]GraphicViewPortClass.Width ; get width into register
|
||||
mov ebx , [ x_pixel ]
|
||||
mov eax , [ x_pixel ]
|
||||
add ebx , [ pixel_width ]
|
||||
shld ecx , eax , 1
|
||||
mov [ x1_pixel ] , ebx
|
||||
inc edi
|
||||
shld edx , ebx , 1
|
||||
sub eax , edi
|
||||
sub ebx , edi
|
||||
shld ecx , eax , 1
|
||||
shld edx , ebx , 1
|
||||
|
||||
mov edi, [esi]GraphicViewPortClass.Height ; get height into register
|
||||
mov ebx , [ y_pixel ]
|
||||
mov eax , [ y_pixel ]
|
||||
add ebx , [ pixel_height ]
|
||||
shld ecx , eax , 1
|
||||
mov [ y1_pixel ] , ebx
|
||||
inc edi
|
||||
shld edx , ebx , 1
|
||||
sub eax , edi
|
||||
sub ebx , edi
|
||||
shld ecx , eax , 1
|
||||
shld edx , ebx , 1
|
||||
|
||||
xor cl , 5
|
||||
xor dl , 5
|
||||
mov al , cl
|
||||
test dl , cl
|
||||
jnz real_out
|
||||
or al , dl
|
||||
jz do_blit
|
||||
|
||||
test cl , 1000b
|
||||
jz dest_left_ok
|
||||
mov eax , [ x_pixel ]
|
||||
neg eax
|
||||
mov [ x_pixel ] , 0
|
||||
mov [ scr_x ] , eax
|
||||
|
||||
dest_left_ok:
|
||||
test cl , 0010b
|
||||
jz dest_bottom_ok
|
||||
mov eax , [ y_pixel ]
|
||||
neg eax
|
||||
mov [ y_pixel ] , 0
|
||||
mov [ scr_y ] , eax
|
||||
|
||||
dest_bottom_ok:
|
||||
test dl , 0100b
|
||||
jz dest_right_ok
|
||||
mov eax , [esi]GraphicViewPortClass.Width ; get width into register
|
||||
mov [ x1_pixel ] , eax
|
||||
dest_right_ok:
|
||||
test dl , 0001b
|
||||
jz do_blit
|
||||
mov eax , [esi]GraphicViewPortClass.Height ; get width into register
|
||||
mov [ y1_pixel ] , eax
|
||||
|
||||
do_blit:
|
||||
|
||||
cld
|
||||
|
||||
mov eax , [esi]GraphicViewPortClass.XAdd
|
||||
add eax , [esi]GraphicViewPortClass.Width
|
||||
add eax , [esi]GraphicViewPortClass.Pitch
|
||||
mov edi , [esi]GraphicViewPortClass.Offset
|
||||
|
||||
mov ecx , eax
|
||||
mul [ y_pixel ]
|
||||
add edi , [ x_pixel ]
|
||||
add edi , eax
|
||||
|
||||
add ecx , [ x_pixel ]
|
||||
sub ecx , [ x1_pixel ]
|
||||
mov [ dest_ajust_width ] , ecx
|
||||
|
||||
|
||||
mov esi , [ src ]
|
||||
mov eax , [ pixel_width ]
|
||||
sub eax , [ x1_pixel ]
|
||||
add eax , [ x_pixel ]
|
||||
mov [ scr_ajust_width ] , eax
|
||||
|
||||
mov eax , [ scr_y ]
|
||||
mul [ pixel_width ]
|
||||
add eax , [ scr_x ]
|
||||
add esi , eax
|
||||
|
||||
mov edx , [ y1_pixel ]
|
||||
mov eax , [ x1_pixel ]
|
||||
|
||||
sub edx , [ y_pixel ]
|
||||
jle real_out
|
||||
sub eax , [ x_pixel ]
|
||||
jle real_out
|
||||
|
||||
|
||||
; ********************************************************************
|
||||
; Forward bitblit only
|
||||
|
||||
//IF TRANSP
|
||||
// test [ trans ] , 1
|
||||
// jnz forward_Blit_trans
|
||||
//ENDIF
|
||||
|
||||
|
||||
; the inner loop is so efficient that
|
||||
; the optimal consept no longer apply because
|
||||
; the optimal byte have to by a number greather than 9 bytes
|
||||
cmp eax , 10
|
||||
jl forward_loop_bytes
|
||||
|
||||
forward_loop_dword:
|
||||
mov ecx , edi
|
||||
mov ebx , eax
|
||||
neg ecx
|
||||
and ecx , 3
|
||||
sub ebx , ecx
|
||||
rep movsb
|
||||
mov ecx , ebx
|
||||
shr ecx , 2
|
||||
rep movsd
|
||||
mov ecx , ebx
|
||||
and ecx , 3
|
||||
rep movsb
|
||||
add esi , [ scr_ajust_width ]
|
||||
add edi , [ dest_ajust_width ]
|
||||
dec edx
|
||||
jnz forward_loop_dword
|
||||
jmp real_out //ret
|
||||
|
||||
forward_loop_bytes:
|
||||
mov ecx , eax
|
||||
rep movsb
|
||||
add esi , [ scr_ajust_width ]
|
||||
add edi , [ dest_ajust_width ]
|
||||
dec edx ; decrement the height
|
||||
jnz forward_loop_bytes
|
||||
// ret
|
||||
|
||||
//IF TRANSP
|
||||
//
|
||||
//
|
||||
//forward_Blit_trans:
|
||||
//
|
||||
//
|
||||
// mov ecx , eax
|
||||
// and ecx , 01fh
|
||||
// lea ecx , [ ecx + ecx * 4 ]
|
||||
// neg ecx
|
||||
// shr eax , 5
|
||||
// lea ecx , [ transp_reference + ecx * 2 ]
|
||||
// mov [ y1_pixel ] , ecx
|
||||
//
|
||||
//
|
||||
//forward_loop_trans:
|
||||
// mov ecx , eax
|
||||
// jmp [ y1_pixel ]
|
||||
//forward_trans_line:
|
||||
// REPT 32
|
||||
// local transp_pixel
|
||||
// mov bl , [ esi ]
|
||||
// inc esi
|
||||
// test bl , bl
|
||||
// jz transp_pixel
|
||||
// mov [ edi ] , bl
|
||||
// transp_pixel:
|
||||
// inc edi
|
||||
// ENDM
|
||||
// transp_reference:
|
||||
// dec ecx
|
||||
// jge forward_trans_line
|
||||
// add esi , [ scr_ajust_width ]
|
||||
// add edi , [ dest_ajust_width ]
|
||||
// dec edx
|
||||
// jnz forward_loop_trans
|
||||
// ret
|
||||
//ENDIF
|
||||
|
||||
real_out:
|
||||
//ret
|
||||
// If we aren't drawing within the viewport, return
|
||||
if (!buffer || xstart >= vp.Get_Width() || ystart >= vp.Get_Height() || xend < 0 || yend < 0) {
|
||||
}
|
||||
|
||||
// Clipping
|
||||
if (xstart < 0) {
|
||||
xoffset = -xstart;
|
||||
xstart = 0;
|
||||
}
|
||||
|
||||
if (ystart < 0) {
|
||||
yoffset += h * (-ystart);
|
||||
ystart = 0;
|
||||
}
|
||||
|
||||
xend = min(xend, vp.Get_Width() - 1);
|
||||
yend = min(yend, vp.Get_Height() - 1);
|
||||
|
||||
int pitch = vp.Get_Pitch() + vp.Get_Width() + vp.Get_XAdd();
|
||||
uint8_t* dst = y * pitch + x + (uint8_t*)(vp.Get_Offset());
|
||||
uint8_t* src = xoffset + w * yoffset + static_cast<uint8_t*>(buffer);
|
||||
// int dst_pitch = x_pos + pitch - xend;
|
||||
// int src_pitch = x_pos + width - xend;
|
||||
int lines = yend - ystart + 1;
|
||||
int blit_width = xend - xstart + 1;
|
||||
|
||||
// blit
|
||||
while (lines--) {
|
||||
memcpy(dst, src, blit_width);
|
||||
src += w;
|
||||
dst += pitch;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//ENDP Buffer_To_Page
|
||||
|
||||
+22
-134
@@ -237,39 +237,7 @@ BOOL GraphicViewPortClass::Change(int x, int y, int w, int h)
|
||||
*=========================================================================*/
|
||||
void GraphicBufferClass::DD_Init(GBC_Enum flags)
|
||||
{
|
||||
//
|
||||
// Create the direct draw surface description
|
||||
//
|
||||
memset (&VideoSurfaceDescription , 0 , sizeof ( VideoSurfaceDescription ));
|
||||
|
||||
VideoSurfaceDescription.dwSize = sizeof( VideoSurfaceDescription );
|
||||
VideoSurfaceDescription.dwFlags = DDSD_CAPS;
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
||||
|
||||
|
||||
if (!(flags & GBC_VISIBLE)) {
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
||||
VideoSurfaceDescription.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
|
||||
VideoSurfaceDescription.dwHeight = Height;
|
||||
VideoSurfaceDescription.dwWidth = Width;
|
||||
}
|
||||
|
||||
//
|
||||
// Need to set the DDSCAPS_MODEX flag if we want a 320 wide mode
|
||||
//
|
||||
if ( Width == 320 ) {
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps |= DDSCAPS_MODEX;
|
||||
}
|
||||
|
||||
//
|
||||
// Call CreateSurface
|
||||
//
|
||||
DirectDrawObject->CreateSurface( &VideoSurfaceDescription , &VideoSurfacePtr , NULL);
|
||||
AllSurfaces.Add_DD_Surface (VideoSurfacePtr);
|
||||
|
||||
if ( GBC_VISIBLE & flags ){
|
||||
PaletteSurface=VideoSurfacePtr;
|
||||
}
|
||||
rawCpuBuffer = new unsigned char[Width * Height];
|
||||
|
||||
Allocated = FALSE; // even if system alloced, dont flag it cuz
|
||||
// we dont want it freed.
|
||||
@@ -278,13 +246,6 @@ void GraphicBufferClass::DD_Init(GBC_Enum flags)
|
||||
LockCount = 0; // surface is not locked
|
||||
}
|
||||
|
||||
|
||||
void GraphicBufferClass::Attach_DD_Surface (GraphicBufferClass * attach_buffer)
|
||||
{
|
||||
VideoSurfacePtr->AddAttachedSurface (attach_buffer->Get_DD_Surface());
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* GBC::INIT -- Core function responsible for initing a GBC *
|
||||
* *
|
||||
@@ -306,7 +267,7 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
Size = size; // find size of physical buffer
|
||||
Width = w; // Record width of Buffer
|
||||
Height = h; // Record height of Buffer
|
||||
|
||||
rawCpuBuffer = nullptr;
|
||||
//
|
||||
// If the surface we are creating is a direct draw object then
|
||||
// we need to do a direct draw init. Otherwise we will do
|
||||
@@ -316,7 +277,7 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
DD_Init(flags);
|
||||
} else {
|
||||
if (buffer) { // if buffer is specified
|
||||
Buffer = (BYTE *)buffer; // point to it and mark
|
||||
Buffer= (BYTE *)buffer; // point to it and mark
|
||||
Allocated = FALSE; // it as user allocated
|
||||
} else {
|
||||
if (!Size) Size = w*h;
|
||||
@@ -353,23 +314,8 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
void GraphicBufferClass::Un_Init (void)
|
||||
{
|
||||
if ( IsDirectDraw ){
|
||||
|
||||
if ( VideoSurfacePtr ){
|
||||
|
||||
while ( LockCount ){
|
||||
|
||||
if (VideoSurfacePtr->Unlock ( NULL ) == DDERR_SURFACELOST){
|
||||
if (Gbuffer_Focus_Loss_Function){
|
||||
Gbuffer_Focus_Loss_Function();
|
||||
}
|
||||
AllSurfaces.Restore_Surfaces();
|
||||
}
|
||||
}
|
||||
|
||||
AllSurfaces.Remove_DD_Surface (VideoSurfacePtr);
|
||||
VideoSurfacePtr->Release();
|
||||
VideoSurfacePtr = NULL;
|
||||
}
|
||||
delete rawCpuBuffer;
|
||||
rawCpuBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,8 +333,7 @@ void GraphicBufferClass::Un_Init (void)
|
||||
GraphicBufferClass::GraphicBufferClass(void)
|
||||
{
|
||||
GraphicBuff = this; // Get a pointer to our self
|
||||
VideoSurfacePtr = NULL;
|
||||
memset(&VideoSurfaceDescription, 0, sizeof(DDSURFACEDESC));
|
||||
rawCpuBuffer = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -538,7 +483,7 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
/*
|
||||
** If the video surface pointer is null then return
|
||||
*/
|
||||
if (!VideoSurfacePtr) return (FALSE);
|
||||
if (!rawCpuBuffer) return (FALSE);
|
||||
|
||||
/*
|
||||
** If we dont have focus then return failure
|
||||
@@ -548,7 +493,6 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
|
||||
Block_Mouse(this);
|
||||
|
||||
|
||||
//
|
||||
// If surface is already locked then inc the lock count and return true
|
||||
//
|
||||
@@ -558,46 +502,15 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
//
|
||||
// If it isn't locked at all then we will have to request that Direct
|
||||
// Draw actually lock the surface.
|
||||
//
|
||||
Offset = (unsigned long)rawCpuBuffer; // 32bit to 64bit issue here.
|
||||
//Pitch = Width;
|
||||
|
||||
if (VideoSurfacePtr){
|
||||
while (!LockCount && restore_attempts<2) {
|
||||
result = VideoSurfacePtr->Lock ( NULL
|
||||
, &(VideoSurfaceDescription)
|
||||
, DDLOCK_WAIT
|
||||
, NULL);
|
||||
|
||||
switch (result){
|
||||
case DD_OK :
|
||||
Offset = (unsigned long)VideoSurfaceDescription.lpSurface;
|
||||
Pitch = VideoSurfaceDescription.lPitch;
|
||||
Pitch -= Width;
|
||||
LockCount++; // increment count so we can track if
|
||||
TotalLocks++; // Total number of times we have locked (for debugging)
|
||||
//Colour_Debug (1);
|
||||
Unblock_Mouse(this);
|
||||
return (TRUE); // we locked it multiple times.
|
||||
|
||||
case DDERR_SURFACELOST :
|
||||
if (Gbuffer_Focus_Loss_Function){
|
||||
Gbuffer_Focus_Loss_Function();
|
||||
}
|
||||
AllSurfaces.Restore_Surfaces();
|
||||
restore_attempts++;
|
||||
break;
|
||||
|
||||
default :
|
||||
Unblock_Mouse(this);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
LockCount++; // increment count so we can track if
|
||||
TotalLocks++; // Total number of times we have locked (for debugging)
|
||||
|
||||
//Colour_Debug(1);
|
||||
Unblock_Mouse(this);
|
||||
return (FALSE); //Return false because we couldnt lock or restore the surface
|
||||
return (TRUE); //Return false because we couldnt lock or restore the surface
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
@@ -615,6 +528,8 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
|
||||
BOOL GraphicBufferClass::Unlock(void)
|
||||
{
|
||||
Video_Set_Data((unsigned char *)Get_Graphic_Buffer()->GetMemoryBuffer(), Width, Height);
|
||||
|
||||
//
|
||||
// If there is no lock count or this is not a direct draw surface
|
||||
// then just return true as there is no harm done.
|
||||
@@ -627,17 +542,12 @@ BOOL GraphicBufferClass::Unlock(void)
|
||||
// If lock count is directly equal to one then we actually need to
|
||||
// unlock so just give it a shot.
|
||||
//
|
||||
if (LockCount == 1 && VideoSurfacePtr) {
|
||||
if (LockCount == 1) {
|
||||
Block_Mouse(this);
|
||||
if ( VideoSurfacePtr->Unlock ( NULL ) != DD_OK ){
|
||||
Unblock_Mouse(this);
|
||||
return(FALSE);
|
||||
} else {
|
||||
Offset=NOT_LOCKED;
|
||||
LockCount--;
|
||||
Unblock_Mouse(this);
|
||||
return(TRUE);
|
||||
}
|
||||
Offset = NOT_LOCKED;
|
||||
LockCount--;
|
||||
Unblock_Mouse(this);
|
||||
return(TRUE);
|
||||
}
|
||||
//Colour_Debug (0);
|
||||
LockCount--;
|
||||
@@ -677,30 +587,8 @@ HRESULT GraphicViewPortClass::DD_Linear_Blit_To_Linear (
|
||||
, BOOL mask )
|
||||
|
||||
{
|
||||
RECT source_rectangle;
|
||||
RECT dest_rectangle;
|
||||
int key_source=0;
|
||||
|
||||
if ( mask ){
|
||||
key_source=DDBLT_KEYSRC;
|
||||
}
|
||||
|
||||
|
||||
source_rectangle.left = source_x;
|
||||
source_rectangle.top = source_y;
|
||||
source_rectangle.right = source_x+width;
|
||||
source_rectangle.bottom = source_y+height;
|
||||
|
||||
dest_rectangle.left = dest_x;
|
||||
dest_rectangle.top = dest_y;
|
||||
dest_rectangle.right = dest_x+width;
|
||||
dest_rectangle.bottom = dest_y+height;
|
||||
|
||||
return ( dest.GraphicBuff->Get_DD_Surface()->Blt ( &dest_rectangle,
|
||||
GraphicBuff->Get_DD_Surface(),
|
||||
&source_rectangle,
|
||||
key_source | DDBLT_WAIT | DDBLT_ASYNC,
|
||||
NULL ) );
|
||||
Nearest_CopyImage((unsigned char*)GraphicBuff->GetMemoryBuffer(), source_x, source_y, GraphicBuff->Get_Width(), GraphicBuff->Get_Height(), (unsigned char *)dest.Get_Graphic_Buffer()->GetMemoryBuffer(), dest_x, dest_y, dest.Get_Graphic_Buffer()->Get_Width(), GraphicBuff->Get_Width(), GraphicBuff->Get_Height(), true);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+85
-78
@@ -107,7 +107,7 @@
|
||||
#endif // _WIN32
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <ddraw.h>
|
||||
//#include <ddraw.h>
|
||||
|
||||
|
||||
#ifndef GBUFFER_H
|
||||
@@ -134,13 +134,49 @@
|
||||
#include "ww_win.h"
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include "iconcach.h"
|
||||
|
||||
|
||||
|
||||
#ifndef FUNCTION_H
|
||||
|
||||
__forceinline void Nearest_Fill(unsigned char source, unsigned char* dest, int destX, int destY, int destWidth, int width, int height, bool trans)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int _x = x;
|
||||
int _y = y;
|
||||
int destPos = (destWidth * (_y + (destY))) + (_x + (destX));
|
||||
|
||||
dest[destPos] = source;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__forceinline void Nearest_CopyImage(unsigned char* source, int sourceX, int sourceY, int sourceWidth, int sourceHeight, unsigned char* dest, int destX, int destY, int destWidth, int width, int height, bool trans)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int _x = x;
|
||||
int _y = y;
|
||||
int destPos = (destWidth * (_y + (destY))) + (_x + (destX));
|
||||
int sourcePos = (sourceWidth * (_y + (sourceY))) + (_x + (sourceX));
|
||||
|
||||
if (sourcePos > sourceWidth * sourceHeight)
|
||||
return;
|
||||
|
||||
if (destPos < 0)
|
||||
return;
|
||||
|
||||
if (source[sourcePos] != 0 || trans == false)
|
||||
dest[destPos] = source[sourcePos];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#pragma off (unreferenced)
|
||||
|
||||
#ifndef BITMAPCLASS
|
||||
@@ -176,7 +212,6 @@ class TPoint2D
|
||||
// Defines for direct draw
|
||||
//
|
||||
//
|
||||
extern LPDIRECTDRAW DirectDrawObject; //pointer to direct draw object
|
||||
extern HWND MainWindow; //handle to programs main window
|
||||
|
||||
/*
|
||||
@@ -368,23 +403,29 @@ class GraphicBufferClass : public GraphicViewPortClass, public BufferClass {
|
||||
void DD_Init(GBC_Enum flags);
|
||||
void Init(int w, int h, void *buffer, long size, GBC_Enum flags);
|
||||
void Un_Init(void);
|
||||
void Attach_DD_Surface (GraphicBufferClass * attach_buffer);
|
||||
//void Attach_DD_Surface (GraphicBufferClass * attach_buffer);
|
||||
BOOL Lock(void);
|
||||
BOOL Unlock(void);
|
||||
|
||||
void Scale_Rotate(BitmapClass &bmp,TPoint2D const &pt,long scale,unsigned char angle);
|
||||
|
||||
// Member to get a pointer to a direct draw surface
|
||||
LPDIRECTDRAWSURFACE Get_DD_Surface ( void );
|
||||
unsigned char* Get_DD_Surface(void) {
|
||||
if (!rawCpuBuffer)
|
||||
return (unsigned char* )Buffer;
|
||||
|
||||
return rawCpuBuffer;
|
||||
}
|
||||
// jmarshall
|
||||
void* GetMemoryBuffer(void) {
|
||||
return VideoSurfaceDescription.lpSurface;
|
||||
}
|
||||
if (!rawCpuBuffer)
|
||||
return Buffer;
|
||||
return rawCpuBuffer;
|
||||
}
|
||||
// jmarshall end
|
||||
protected:
|
||||
LPDIRECTDRAWSURFACE VideoSurfacePtr; //Pointer to the related direct draw surface
|
||||
DDSURFACEDESC VideoSurfaceDescription;//Description of the said surface
|
||||
|
||||
protected:
|
||||
unsigned char* rawCpuBuffer;
|
||||
};
|
||||
|
||||
|
||||
@@ -417,28 +458,6 @@ inline BOOL GraphicViewPortClass::Get_IsDirectDraw(void)
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* GBC::Get_DD_Surface -- returns a pointer to the buffer direct draw surface *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* INPUT: Nothing *
|
||||
* *
|
||||
* OUTPUT: ptr to direct draw surface *
|
||||
* *
|
||||
* WARNINGS: None *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 9/29/95 9:43AM ST : Created *
|
||||
*=============================================================================================*/
|
||||
inline LPDIRECTDRAWSURFACE GraphicBufferClass::Get_DD_Surface ( void )
|
||||
{
|
||||
return ( VideoSurfacePtr );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* GVPC::Lock -- lock the graphics buffer for reading or writing *
|
||||
* *
|
||||
@@ -503,6 +522,10 @@ inline BOOL GraphicViewPortClass::Unlock(void)
|
||||
*=========================================================================*/
|
||||
inline long GraphicViewPortClass::Get_Offset(void)
|
||||
{
|
||||
if(Offset == 0) {
|
||||
return (long)Get_Graphic_Buffer()->GetMemoryBuffer();
|
||||
}
|
||||
|
||||
return(Offset);
|
||||
}
|
||||
|
||||
@@ -1169,53 +1192,37 @@ inline VOID GraphicViewPortClass::Draw_Line(int sx, int sy, int dx, int dy, unsi
|
||||
*=========================================================================*/
|
||||
inline VOID GraphicViewPortClass::Fill_Rect(int sx, int sy, int dx, int dy, unsigned char color)
|
||||
{
|
||||
if ( AllowHardwareBlitFills
|
||||
&& IsDirectDraw
|
||||
&& ( (dx-sx) * (dy-sy) >= (32*32) )
|
||||
&& GraphicBuff->Get_DD_Surface()->GetBltStatus(DDGBS_CANBLT) == DD_OK){
|
||||
DDBLTFX blit_effects;
|
||||
RECT dest_rectangle;
|
||||
void Nearest_Fill(unsigned char source, unsigned char* dest, int destX, int destY, int destWidth, int width, int height, bool trans);
|
||||
RECT dest_rectangle;
|
||||
|
||||
dest_rectangle.left =sx+XPos;
|
||||
dest_rectangle.top =sy+YPos;
|
||||
dest_rectangle.right =dx+XPos;
|
||||
dest_rectangle.bottom=dy+YPos;
|
||||
dest_rectangle.left = sx + XPos;
|
||||
dest_rectangle.top = sy + YPos;
|
||||
dest_rectangle.right = dx + XPos;
|
||||
dest_rectangle.bottom = dy + YPos;
|
||||
|
||||
if (dest_rectangle.left<XPos){
|
||||
dest_rectangle.left=XPos;
|
||||
}
|
||||
|
||||
if (dest_rectangle.right >= Width + XPos){
|
||||
dest_rectangle.right = Width +XPos -1;
|
||||
}
|
||||
|
||||
if (dest_rectangle.top<YPos){
|
||||
dest_rectangle.top=YPos;
|
||||
}
|
||||
|
||||
if (dest_rectangle.bottom >= Height + YPos){
|
||||
dest_rectangle.bottom = Height + YPos -1;
|
||||
}
|
||||
|
||||
if (dest_rectangle.left >= dest_rectangle.right) return;
|
||||
if (dest_rectangle.top >= dest_rectangle.bottom) return;
|
||||
|
||||
dest_rectangle.right++;
|
||||
dest_rectangle.bottom++;
|
||||
|
||||
blit_effects.dwSize=sizeof(blit_effects);
|
||||
blit_effects.dwFillColor = color;
|
||||
GraphicBuff->Get_DD_Surface()->Blt(&dest_rectangle,
|
||||
NULL,
|
||||
NULL,
|
||||
DDBLT_WAIT | DDBLT_ASYNC | DDBLT_COLORFILL,
|
||||
&blit_effects);
|
||||
} else {
|
||||
if (Lock()){
|
||||
Buffer_Fill_Rect(this, sx, sy, dx, dy, color);
|
||||
Unlock();
|
||||
}
|
||||
if (dest_rectangle.left < XPos) {
|
||||
dest_rectangle.left = XPos;
|
||||
}
|
||||
|
||||
if (dest_rectangle.right >= Width + XPos) {
|
||||
dest_rectangle.right = Width + XPos - 1;
|
||||
}
|
||||
|
||||
if (dest_rectangle.top < YPos) {
|
||||
dest_rectangle.top = YPos;
|
||||
}
|
||||
|
||||
if (dest_rectangle.bottom >= Height + YPos) {
|
||||
dest_rectangle.bottom = Height + YPos - 1;
|
||||
}
|
||||
|
||||
if (dest_rectangle.left >= dest_rectangle.right) return;
|
||||
if (dest_rectangle.top >= dest_rectangle.bottom) return;
|
||||
|
||||
dest_rectangle.right++;
|
||||
dest_rectangle.bottom++;
|
||||
|
||||
Nearest_Fill(color, (unsigned char *)Get_Graphic_Buffer()->GetMemoryBuffer(), dest_rectangle.left, dest_rectangle.top, Width, dest_rectangle.right - dest_rectangle.left, dest_rectangle.bottom - dest_rectangle.top, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class IconCacheClass {
|
||||
void Restore(void); // restore the surface
|
||||
BOOL Cache_It (void * icon_ptr); // Cache the icon to video memory
|
||||
void Uncache_It (void); // Restore the video memory and flag the icon as uncached
|
||||
void Draw_It (LPDIRECTDRAWSURFACE dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height);
|
||||
void Draw_It (void *dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height);
|
||||
inline BOOL Get_Is_Cached(void); // Return the IsCached member
|
||||
|
||||
int TimesDrawn; // counter of times cached icon has been drawn
|
||||
@@ -80,7 +80,7 @@ class IconCacheClass {
|
||||
|
||||
private:
|
||||
|
||||
LPDIRECTDRAWSURFACE CacheSurface; // Ptr to direct draw surface where icon resides
|
||||
// LPDIRECTDRAWSURFACE CacheSurface; // Ptr to direct draw surface where icon resides
|
||||
BOOL IsCached; // Flag to say whether an icon is cached
|
||||
BOOL SurfaceLost; // Flag to indicate that our icons surface has been lost
|
||||
int DrawFrequency; // Number of times icon has been drawn
|
||||
|
||||
+10
-13
@@ -40,9 +40,7 @@
|
||||
#endif // _WIN32
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <ddraw.h>
|
||||
|
||||
extern LPDIRECTDRAWSURFACE PaletteSurface;
|
||||
//#include <ddraw.h>
|
||||
|
||||
/*========================= C++ Routines ==================================*/
|
||||
|
||||
@@ -52,6 +50,7 @@ extern LPDIRECTDRAWSURFACE PaletteSurface;
|
||||
/*=========================================================================*/
|
||||
void Process_DD_Result(HRESULT result, int display_ok_msg);
|
||||
BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel);
|
||||
void Video_Set_Data(unsigned char* buffer, int width, int height);
|
||||
void Reset_Video_Mode(void);
|
||||
unsigned Get_Free_Video_Memory(void);
|
||||
void Wait_Blit(void);
|
||||
@@ -106,20 +105,20 @@ class SurfaceMonitorClass {
|
||||
|
||||
public:
|
||||
|
||||
SurfaceMonitorClass();
|
||||
SurfaceMonitorClass() { }
|
||||
|
||||
void Add_DD_Surface (LPDIRECTDRAWSURFACE);
|
||||
void Remove_DD_Surface (LPDIRECTDRAWSURFACE);
|
||||
BOOL Got_Surface_Already (LPDIRECTDRAWSURFACE);
|
||||
void Restore_Surfaces (void);
|
||||
void Set_Surface_Focus ( BOOL in_focus );
|
||||
void Release(void);
|
||||
void Add_DD_Surface (void *) { }
|
||||
void Remove_DD_Surface (void*) { }
|
||||
BOOL Got_Surface_Already (void*) { }
|
||||
void Restore_Surfaces (void) { }
|
||||
void Set_Surface_Focus ( BOOL in_focus ) { }
|
||||
void Release(void) { }
|
||||
|
||||
BOOL SurfacesRestored;
|
||||
|
||||
private:
|
||||
|
||||
LPDIRECTDRAWSURFACE Surface[MAX_SURFACES];
|
||||
void *Surface[MAX_SURFACES];
|
||||
BOOL InFocus;
|
||||
|
||||
};
|
||||
@@ -130,8 +129,6 @@ extern SurfaceMonitorClass AllSurfaces; //List of all direct draw surfaces
|
||||
/*=========================================================================*/
|
||||
/* The following variables are declared in: DDRAW.CPP */
|
||||
/*=========================================================================*/
|
||||
extern LPDIRECTDRAW DirectDrawObject;
|
||||
extern LPDIRECTDRAW2 DirectDraw2Interface;
|
||||
extern HWND MainWindow;
|
||||
extern BOOL SystemToVideoBlits;
|
||||
extern BOOL VideoToSystemBlits;
|
||||
|
||||
+107
-3
@@ -55,12 +55,103 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
#include <gl/glew.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <examples/imgui_impl_opengl3.h>
|
||||
|
||||
GLuint backbuffer_texture = -1;
|
||||
byte* backbuffer_data;
|
||||
byte* backbuffer_data_raw;
|
||||
byte backbuffer_palette[768];
|
||||
HWND MainWindow;
|
||||
SurfaceMonitorClass AllSurfaces;
|
||||
SDL_Window* game_window;
|
||||
SDL_GLContext game_context;
|
||||
int OverlappedVideoBlits = 0;
|
||||
|
||||
void Video_Set_Data(unsigned char* buffer, int width, int height) {
|
||||
memcpy(backbuffer_data_raw, buffer, width * height);
|
||||
}
|
||||
|
||||
void (*Misc_Focus_Loss_Function)(void) = nullptr;
|
||||
void (*Misc_Focus_Restore_Function)(void) = nullptr;
|
||||
|
||||
void (*Imgui_Dialog_Function)(void) = nullptr;
|
||||
|
||||
BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel) {
|
||||
// Todo implement resoluton scaling.
|
||||
return true; // Always return true;
|
||||
}
|
||||
|
||||
unsigned int Get_Free_Video_Memory(void) {
|
||||
return 64 * 1024 * 1024;
|
||||
}
|
||||
|
||||
unsigned int Get_Video_Hardware_Capabilities() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Reset_Video_Mode(void) {
|
||||
|
||||
}
|
||||
|
||||
void Set_DD_Palette(void* palette)
|
||||
{
|
||||
char* palette_get = (char*)palette; //CCPalette.Get_Data();
|
||||
for (int j = 0; j < 768; j++) {
|
||||
backbuffer_palette[j] = palette_get[j] << 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Device_Present(void) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
io.DisplaySize = ImVec2(ScreenWidth, ScreenHeight);
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui_ImplSDL2_NewFrame(game_window);
|
||||
|
||||
// Rasterize the palette.
|
||||
for (int i = 0; i < ScreenWidth * ScreenHeight; i++) {
|
||||
backbuffer_data[(i * 4) + 0] = backbuffer_palette[(backbuffer_data_raw[i] * 3) + 0];
|
||||
backbuffer_data[(i * 4) + 1] = backbuffer_palette[(backbuffer_data_raw[i] * 3) + 1];
|
||||
backbuffer_data[(i * 4) + 2] = backbuffer_palette[(backbuffer_data_raw[i] * 3) + 2];
|
||||
backbuffer_data[(i * 4) + 3] = 255;
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, backbuffer_texture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ScreenWidth, ScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, backbuffer_data);
|
||||
|
||||
// Use imgui to render the screenbuffer.
|
||||
{
|
||||
bool ScreenActive;
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.FramePadding = ImVec2(0, 0);
|
||||
ImGui::SetNextWindowSize(ImVec2(ScreenWidth, ScreenHeight));
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::Begin("RenderWindow", &ScreenActive, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar);
|
||||
ImVec2 desktopSize(ScreenWidth, ScreenHeight);
|
||||
ImGui::Image((ImTextureID)backbuffer_texture, desktopSize);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (Imgui_Dialog_Function) {
|
||||
Imgui_Dialog_Function();
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
SDL_GL_SwapWindow(game_window);
|
||||
}
|
||||
|
||||
|
||||
void output(short,short)
|
||||
{}
|
||||
|
||||
SDL_Window* game_window;
|
||||
|
||||
unsigned long CCFocusMessage = WM_USER+50; //Private message for receiving application focus
|
||||
extern void VQA_PauseAudio(void);
|
||||
extern void VQA_ResumeAudio(void);
|
||||
@@ -480,7 +571,8 @@ void Create_Main_Window ( HANDLE instance , int command_show , int width , int h
|
||||
// (HINSTANCE)instance,
|
||||
// NULL );
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
game_window = SDL_CreateWindow(WINDOW_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
|
||||
game_window = SDL_CreateWindow(WINDOW_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
|
||||
game_context = SDL_GL_CreateContext(game_window);
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
SDL_GetWindowWMInfo(game_window, &wmInfo);
|
||||
@@ -501,6 +593,18 @@ void Create_Main_Window ( HANDLE instance , int command_show , int width , int h
|
||||
Misc_Focus_Restore_Function = &Focus_Restore;
|
||||
Gbuffer_Focus_Loss_Function = &Focus_Loss;
|
||||
|
||||
glGenTextures(1, &backbuffer_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, backbuffer_texture);
|
||||
// Give the image to OpenGL
|
||||
backbuffer_data = new byte[width * height * 4];
|
||||
memset(backbuffer_data, 0, width * height * 4);
|
||||
backbuffer_data_raw = new byte[width * height];
|
||||
memset(backbuffer_data_raw, 0, width * height);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, backbuffer_data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
glewInit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -948,7 +948,8 @@ GraphicBufferClass HiddenPage;
|
||||
GraphicViewPortClass SeenBuff(&VisiblePage, 0,0,1536,1536);
|
||||
GraphicBufferClass ModeXBuff;
|
||||
GraphicViewPortClass HidPage(&HiddenPage, 0,0, 1536,1536);
|
||||
GraphicBufferClass SysMemPage(DEFAULT_SCREEN_WIDTH, 200, (void*)NULL);
|
||||
byte SysMemPageBuffer[DEFAULT_SCREEN_WIDTH * 200];
|
||||
GraphicBufferClass SysMemPage(DEFAULT_SCREEN_WIDTH, 200, (void*)&SysMemPageBuffer[0]);
|
||||
int SoundOn;
|
||||
CountDownTimerClass FrameTimer(BT_SYSTEM, 0L);
|
||||
CountDownTimerClass DebugTimer(BT_SYSTEM, 0L);
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
#include "DirectDrawWrapper.h"
|
||||
|
||||
/*******************
|
||||
**IUnknown methods**
|
||||
********************/
|
||||
|
||||
// Retrieves pointers to the supported interfaces on an object.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::QueryInterface(REFIID riid, LPVOID FAR * ppvObj)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::QueryInterface", "Partially Implemented");
|
||||
|
||||
// Provide the directdraw interface for all versions up to 7
|
||||
if(riid == IID_IDirectDrawClipper)
|
||||
{
|
||||
// Set pointer to this interface
|
||||
ppvObj = (LPVOID *)this;
|
||||
// Increment reference count
|
||||
AddRef();
|
||||
// Return success
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Interface not supported
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
// Increments the reference count for an interface on an object.
|
||||
ULONG __stdcall IDirectDrawClipperWrapper::AddRef()
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::AddRef", "Partially Implemented");
|
||||
|
||||
// Increment reference count
|
||||
ReferenceCount++;
|
||||
// Return current reference count
|
||||
return ReferenceCount;
|
||||
}
|
||||
|
||||
// Decrements the reference count for an interface on an object.
|
||||
ULONG __stdcall IDirectDrawClipperWrapper::Release()
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::Release", "Partially Implemented");
|
||||
|
||||
// Decrement reference count
|
||||
ReferenceCount--;
|
||||
// If reference count reaches 0 then free object
|
||||
if(ReferenceCount == 0)
|
||||
{
|
||||
// Free objects here, skip for now
|
||||
}
|
||||
// Return new reference count
|
||||
return ReferenceCount;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
**IDirectDrawClipper methods**
|
||||
******************************/
|
||||
|
||||
// Retrieves a copy of the clip list that is associated with a DirectDrawClipper
|
||||
// object. To select a subset of the clip list, you can pass a rectangle that clips
|
||||
// the clip list.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::GetClipList(LPRECT lpRect, LPRGNDATA lpClipList, LPDWORD lpdwSize)
|
||||
{
|
||||
// ***Unimplemented***
|
||||
debugMessage(0, "IDirectDrawClipperWrapper::GetClipList", "Not Implemented");
|
||||
|
||||
if(lpClipList == NULL)
|
||||
{
|
||||
if(lpRect == NULL) {
|
||||
// lpdwSize = memory required to hold entire clip list
|
||||
}
|
||||
else
|
||||
{
|
||||
// lpdwSize = memory required to clip list in region lpRect
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(lpRect == NULL) {
|
||||
// lpClipList = RGNDATA structure that receives the resulting copy of the entire clip list.
|
||||
}
|
||||
else
|
||||
{
|
||||
// lpClipList = RGNDATA structure that receives the resulting copy of the clip list in region lpRect
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return DDERR_GENERIC;
|
||||
|
||||
/*
|
||||
DDERR_GENERIC
|
||||
DDERR_INVALIDCLIPLIST
|
||||
DDERR_INVALIDOBJECT
|
||||
DDERR_INVALIDPARAMS
|
||||
DDERR_NOCLIPLIST
|
||||
DDERR_REGIONTOOSMALL
|
||||
*/
|
||||
}
|
||||
|
||||
// Retrieves the window handle that was previously associated with this
|
||||
// DirectDrawClipper object by the IDirectDrawClipper::SetHWnd method.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::GetHWnd(HWND FAR *lphWnd)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::GetHWnd", "Partially Implemented");
|
||||
|
||||
// lphWnd cannot be null
|
||||
if(lphWnd == NULL) return DDERR_INVALIDPARAMS;
|
||||
|
||||
// Set lphWnd to associated window handle
|
||||
*lphWnd = hWnd;
|
||||
|
||||
// Success
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
// Initializes a DirectDrawClipper object that was created by using the
|
||||
// CoCreateInstance COM function.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::Initialize(LPDIRECTDRAW lpDD, DWORD dwFlags)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::Initialize", "Partially Implemented");
|
||||
if(lpDD == NULL)
|
||||
{
|
||||
// An independent DirectDrawClipper object is initialized; a call of this
|
||||
// type is equivalent to using the DirectDrawCreateClipper function.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call constructor
|
||||
}
|
||||
|
||||
// Overload to already init
|
||||
return DDERR_ALREADYINITIALIZED;
|
||||
|
||||
/*
|
||||
DDERR_ALREADYINITIALIZED
|
||||
DDERR_INVALIDPARAMS
|
||||
*/
|
||||
}
|
||||
|
||||
// Retrieves the status of the clip list if a window handle is associated
|
||||
// with a DirectDrawClipper object.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::IsClipListChanged(BOOL FAR *lpbChanged)
|
||||
{
|
||||
// ***Unimplemented***
|
||||
debugMessage(0, "IDirectDrawClipperWrapper::Initialize", "Not Implemented");
|
||||
|
||||
// lpbChanged cannot be null
|
||||
if(lpbChanged == NULL) return DDERR_INVALIDPARAMS;
|
||||
|
||||
// lpbChanged is TRUE if the clip list has changed, and FALSE otherwise.
|
||||
|
||||
return DDERR_GENERIC;
|
||||
|
||||
/*
|
||||
DDERR_INVALIDOBJECT
|
||||
DDERR_INVALIDPARAMS
|
||||
*/
|
||||
}
|
||||
|
||||
// Sets or deletes the clip list that is used by the IDirectDrawSurface7::Blt,
|
||||
// IDirectDrawSurface7::BltBatch, and IDirectDrawSurface7::UpdateOverlay methods
|
||||
// on surfaces to which the parent DirectDrawClipper object is attached.
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::SetClipList(LPRGNDATA lpClipList, DWORD dwFlags)
|
||||
{
|
||||
// ***Unimplemented***
|
||||
debugMessage(0, "IDirectDrawClipperWrapper::SetClipList", "Not Implemented");
|
||||
|
||||
//You cannot set the clip list if a window handle is already associated
|
||||
// with the DirectDrawClipper objet.
|
||||
if(hasHwnd)
|
||||
{
|
||||
return DDERR_CLIPPERISUSINGHWND;
|
||||
}
|
||||
|
||||
// ******NOTE: If you call IDirectDrawSurface7::BltFast on a surface with an attached
|
||||
// clipper, it returns DDERR_UNSUPPORTED.
|
||||
if(lpClipList == NULL)
|
||||
{
|
||||
// Delete associated clip list if it exists
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set clip list to lpClipList
|
||||
}
|
||||
|
||||
return DDERR_GENERIC;
|
||||
|
||||
/*
|
||||
DDERR_INVALIDCLIPLIST
|
||||
DDERR_INVALIDOBJECT
|
||||
DDERR_INVALIDPARAMS
|
||||
DDERR_OUTOFMEMORY
|
||||
*/
|
||||
}
|
||||
|
||||
// Sets the window handle that the clipper object uses to obtain clipping information
|
||||
HRESULT __stdcall IDirectDrawClipperWrapper::SetHWnd(DWORD dwFlags, HWND in_hWnd)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawClipperWrapper::SetHWnd", "Partially Implemented");
|
||||
|
||||
hasHwnd = true;
|
||||
hWnd = in_hWnd;
|
||||
|
||||
// Load clip list from window
|
||||
|
||||
return DD_OK;
|
||||
|
||||
/*
|
||||
DDERR_INVALIDCLIPLIST
|
||||
DDERR_INVALIDOBJECT
|
||||
DDERR_INVALIDPARAMS
|
||||
DDERR_OUTOFMEMORY
|
||||
*/
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
IDirectDrawClipperWrapper::IDirectDrawClipperWrapper()
|
||||
{
|
||||
// Init variables
|
||||
hasHwnd = false;
|
||||
hWnd = NULL;
|
||||
|
||||
ReferenceCount = 0;
|
||||
|
||||
// Add reference
|
||||
AddRef();
|
||||
|
||||
debugMessage(2, "IDirectDrawClipperWrapper::IDirectDrawClipperWrapper", "Created");
|
||||
}
|
||||
|
||||
// Default destructor
|
||||
IDirectDrawClipperWrapper::~IDirectDrawClipperWrapper()
|
||||
{
|
||||
// Release reference
|
||||
Release();
|
||||
|
||||
debugMessage(2, "IDirectDrawClipperWrapper::~IDirectDrawClipperWrapper", "Destroyed");
|
||||
}
|
||||
|
||||
// Initialize wrapper function
|
||||
HRESULT IDirectDrawClipperWrapper::WrapperInitialize(DWORD dwFlags)
|
||||
{
|
||||
debugMessage(2, "IDirectDrawClipperWrapper::WrapperInitialize", "Initialized");
|
||||
return DD_OK;
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
#include "DirectDrawWrapper.h"
|
||||
|
||||
/*******************
|
||||
**IUnknown methods**
|
||||
********************/
|
||||
|
||||
// Retrieves pointers to the supported interfaces on an object.
|
||||
HRESULT __stdcall IDirectDrawPaletteWrapper::QueryInterface(REFIID riid, LPVOID FAR * ppvObj)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawPaletteWrapper::QueryInterface", "Partially Implemented");
|
||||
|
||||
// Provide the directdraw interface for all versions up to 7
|
||||
if(riid == IID_IDirectDrawPalette)
|
||||
{
|
||||
// Set pointer to this interface
|
||||
ppvObj = (LPVOID *)this;
|
||||
// Increment reference count
|
||||
AddRef();
|
||||
// Return success
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Interface not supported
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
// Increments the reference count for an interface on an object.
|
||||
ULONG __stdcall IDirectDrawPaletteWrapper::AddRef()
|
||||
{
|
||||
debugMessage(1, "IDirectDrawPaletteWrapper::AddRef", "Partially Implemented");
|
||||
|
||||
// Increment reference count
|
||||
ReferenceCount++;
|
||||
// Return current reference count
|
||||
return ReferenceCount;
|
||||
}
|
||||
|
||||
// Decrements the reference count for an interface on an object.
|
||||
ULONG __stdcall IDirectDrawPaletteWrapper::Release()
|
||||
{
|
||||
debugMessage(1, "IDirectDrawPaletteWrapper::Release", "Partially Implemented");
|
||||
|
||||
// Decrement reference count
|
||||
ReferenceCount--;
|
||||
// If reference count reaches 0 then free object
|
||||
if(ReferenceCount == 0)
|
||||
{
|
||||
// Free objects
|
||||
if(rawPalette != NULL) delete rawPalette;
|
||||
if(rgbPalette != NULL) delete rgbPalette;
|
||||
}
|
||||
// Return new reference count
|
||||
return ReferenceCount;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
**IDirectDrawPalette methods**
|
||||
******************************/
|
||||
|
||||
// Retrieves the capabilities of the palette object.
|
||||
HRESULT __stdcall IDirectDrawPaletteWrapper::GetCaps(LPDWORD lpdwCaps)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawPaletteWrapper::GetCaps", "Partially Implemented");
|
||||
|
||||
// lpdwCaps cannot be null
|
||||
if(lpdwCaps == NULL) return DDERR_INVALIDPARAMS;
|
||||
|
||||
// set return data to current palette caps
|
||||
*lpdwCaps = paletteCaps;
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
// Retrieves palette values from a DirectDrawPalette object.
|
||||
HRESULT __stdcall IDirectDrawPaletteWrapper::GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
||||
{
|
||||
// lpEntries cannot be null and dwFlags must be 0
|
||||
if(lpEntries == NULL) return DDERR_INVALIDPARAMS;
|
||||
|
||||
// Copy raw palette entries to lpEntries(size dwNumEntries) starting at dwBase
|
||||
memcpy(lpEntries, &(rawPalette[dwBase]), sizeof(PALETTEENTRY) * min(dwNumEntries, entryCount - dwBase));
|
||||
|
||||
/*
|
||||
// NOTE: Debugging disabled for performance
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::GetEntries", "Retrieved Palette Entries");
|
||||
|
||||
char message[2048] = "\0";
|
||||
sprintf_s(message, 2048, "dwBase: %d, dwNumEntries: %d", dwBase, dwNumEntries);
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::GetEntries", message);
|
||||
*/
|
||||
|
||||
// dwNumEntries is the number of palette entries that can fit in the array that lpEntries
|
||||
// specifies. The colors of the palette entries are returned in sequence, from the value
|
||||
// of the dwStartingEntry parameter through the value of the dwCount parameter minus 1.
|
||||
// (These parameters are set by IDirectDrawPalette::SetEntries.)
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
// Initializes the DirectDrawPalette object.
|
||||
HRESULT __stdcall IDirectDrawPaletteWrapper::Initialize(LPDIRECTDRAW lpDDW, DWORD dwFlags, LPPALETTEENTRY lpDDColorTable)
|
||||
{
|
||||
debugMessage(1, "IDirectDrawPaletteWrapper::Initialize", "Partially Implemented");
|
||||
|
||||
// This method always returns already initialized
|
||||
return DDERR_ALREADYINITIALIZED;
|
||||
}
|
||||
|
||||
// Changes entries in a DirectDrawPalette object immediately.
|
||||
HRESULT __stdcall IDirectDrawPaletteWrapper::SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
||||
{
|
||||
// lpEntries cannot be null and dwFlags must be 0
|
||||
if(lpEntries == NULL) return DDERR_INVALIDPARAMS;
|
||||
|
||||
// Copy raw palette entries from dwStartingEntry and of count dwCount
|
||||
memcpy(&(rawPalette[dwStartingEntry]), lpEntries, sizeof(PALETTEENTRY) * min(dwCount, entryCount - dwStartingEntry));
|
||||
|
||||
// Translate new raw pallete entries to RGB(make sure not to go off the end of the memory)
|
||||
for(int i = dwStartingEntry; i < min(dwStartingEntry + dwCount, entryCount - dwStartingEntry); i++)
|
||||
{
|
||||
// Translate the raw palette to ARGB
|
||||
if(hasAlpha)
|
||||
{
|
||||
// Include peFlags as 8bit alpha
|
||||
rgbPalette[i] = rawPalette[i].peFlags << 24;
|
||||
rgbPalette[i] |= rawPalette[i].peRed << 16;
|
||||
rgbPalette[i] |= rawPalette[i].peGreen << 8;
|
||||
rgbPalette[i] |= rawPalette[i].peBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Alpha is always 255
|
||||
rgbPalette[i] = 0xFF000000;
|
||||
rgbPalette[i] |= rawPalette[i].peRed << 16;
|
||||
rgbPalette[i] |= rawPalette[i].peGreen << 8;
|
||||
rgbPalette[i] |= rawPalette[i].peBlue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// NOTE: Debugging disabled for performance
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::SetEntries", "Set Palette Entries");
|
||||
|
||||
char message[2048] = "\0";
|
||||
sprintf_s(message, 2048, "dwStartingEntry: %d, dwCount: %d", dwStartingEntry, dwCount);
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::SetEntries", message); */
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
IDirectDrawPaletteWrapper::IDirectDrawPaletteWrapper()
|
||||
{
|
||||
// Init vars
|
||||
rgbPalette = NULL;
|
||||
rawPalette = NULL;
|
||||
|
||||
ReferenceCount = 0;
|
||||
paletteCaps = 0;
|
||||
|
||||
entryCount = 0;
|
||||
hasAlpha = false;
|
||||
|
||||
// Create with flags
|
||||
AddRef();
|
||||
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::IDirectDrawPaletteWrapper", "Created");
|
||||
}
|
||||
|
||||
// Default destructor
|
||||
IDirectDrawPaletteWrapper::~IDirectDrawPaletteWrapper()
|
||||
{
|
||||
// Free used memory
|
||||
if(rgbPalette != NULL)
|
||||
{
|
||||
delete rgbPalette;
|
||||
rgbPalette = NULL;
|
||||
}
|
||||
if(rawPalette != NULL)
|
||||
{
|
||||
delete rawPalette;
|
||||
rawPalette = NULL;
|
||||
}
|
||||
|
||||
// Clean up
|
||||
Release();
|
||||
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::~IDirectDrawPaletteWrapper", "Destroyed");
|
||||
}
|
||||
|
||||
// Initialize wrapper function
|
||||
HRESULT IDirectDrawPaletteWrapper::WrapperInitialize(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette)
|
||||
{
|
||||
// Save palette caps
|
||||
paletteCaps = dwFlags;
|
||||
|
||||
// Default to 256 entries
|
||||
entryCount = 256;
|
||||
|
||||
// Create palette of requested bit size
|
||||
if(dwFlags & DDPCAPS_1BIT)
|
||||
{
|
||||
entryCount = 2;
|
||||
}
|
||||
else if(dwFlags & DDPCAPS_2BIT)
|
||||
{
|
||||
entryCount = 4;
|
||||
}
|
||||
else if(dwFlags & DDPCAPS_4BIT)
|
||||
{
|
||||
entryCount = 16;
|
||||
}
|
||||
else if(dwFlags & DDPCAPS_8BIT || dwFlags & DDPCAPS_ALLOW256)
|
||||
{
|
||||
entryCount = 256;
|
||||
}
|
||||
|
||||
// Allocate raw ddraw palette
|
||||
rawPalette = new PALETTEENTRY[entryCount];
|
||||
// Memory failed to allocate, return out of memory
|
||||
if(rawPalette == NULL)
|
||||
{
|
||||
debugMessage(0, "IDirectDrawPaletteWrapper::WrapperInitialize", "Failed to allocate raw palette memory");
|
||||
return DDERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
// Copy inital palette into raw palette
|
||||
memcpy(rawPalette, lpDDColorArray, sizeof(PALETTEENTRY) * entryCount);
|
||||
|
||||
// Check flags for alpha
|
||||
if(dwFlags & DDPCAPS_ALPHA)
|
||||
{
|
||||
hasAlpha = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasAlpha = false;
|
||||
}
|
||||
|
||||
// Allocate rgb palette
|
||||
rgbPalette = new UINT32[entryCount];
|
||||
// Memory failed to allocate, return out of memory
|
||||
if(rgbPalette == NULL)
|
||||
{
|
||||
debugMessage(0, "IDirectDrawPaletteWrapper::WrapperInitialize", "Failed to allocate RGB palette memory");
|
||||
return DDERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
// For all entries
|
||||
for(int i = 0; i < entryCount; i++)
|
||||
{
|
||||
// Translate the raw palette to ARGB
|
||||
if(hasAlpha)
|
||||
{
|
||||
// Include peFlags as 8bit alpha
|
||||
rgbPalette[i] = rawPalette[i].peFlags << 24;
|
||||
rgbPalette[i] |= rawPalette[i].peRed << 16;
|
||||
rgbPalette[i] |= rawPalette[i].peGreen << 8;
|
||||
rgbPalette[i] |= rawPalette[i].peBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Alpha is always 255
|
||||
rgbPalette[i] = 0xFF000000;
|
||||
rgbPalette[i] |= rawPalette[i].peRed << 16;
|
||||
rgbPalette[i] |= rawPalette[i].peGreen << 8;
|
||||
rgbPalette[i] |= rawPalette[i].peBlue;
|
||||
}
|
||||
}
|
||||
|
||||
char message[2048] = "\0";
|
||||
sprintf_s(message, 2048, "Initialized");
|
||||
if(dwFlags & DDPCAPS_1BIT) strcat_s(message, 2048, ", DDPCAPS_1BIT");
|
||||
if(dwFlags & DDPCAPS_2BIT) strcat_s(message, 2048, ", DDPCAPS_2BIT");
|
||||
if(dwFlags & DDPCAPS_4BIT) strcat_s(message, 2048, ", DDPCAPS_4BIT");
|
||||
if(dwFlags & DDPCAPS_8BIT) strcat_s(message, 2048, ", DDPCAPS_8BIT");
|
||||
if(dwFlags & DDPCAPS_8BITENTRIES) strcat_s(message, 2048, ", DDPCAPS_8BITENTRIES");
|
||||
if(dwFlags & DDPCAPS_ALPHA) strcat_s(message, 2048, ", DDPCAPS_ALPHA");
|
||||
if(dwFlags & DDPCAPS_ALLOW256) strcat_s(message, 2048, ", DDPCAPS_ALLOW256");
|
||||
if(dwFlags & DDPCAPS_INITIALIZE) strcat_s(message, 2048, ", DDPCAPS_INITIALIZE");
|
||||
if(dwFlags & DDPCAPS_PRIMARYSURFACE) strcat_s(message, 2048, ", DDPCAPS_PRIMARYSURFACE");
|
||||
if(dwFlags & DDPCAPS_PRIMARYSURFACELEFT) strcat_s(message, 2048, ", DDPCAPS_PRIMARYSURFACELEFT");
|
||||
if(dwFlags & DDPCAPS_VSYNC) strcat_s(message, 2048, ", DDPCAPS_VSYNC");
|
||||
debugMessage(2, "IDirectDrawPaletteWrapper::WrapperInitialize", message);
|
||||
|
||||
// Success
|
||||
return DD_OK;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,385 +0,0 @@
|
||||
#define VC_EXTRALEAN
|
||||
#include <Windows.h>
|
||||
#include <initguid.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
#include <stdio.h>
|
||||
#include <ddraw2.h>
|
||||
|
||||
#ifndef H_DDW
|
||||
#define H_DDW
|
||||
|
||||
// Global function def
|
||||
void debugMessage(int, char*, char*);
|
||||
|
||||
// Forward class declarations
|
||||
class FAR IDirectDrawWrapper;
|
||||
class FAR IDirectDrawPaletteWrapper;
|
||||
class FAR IDirectDrawClipperWrapper;
|
||||
class FAR IDirectDrawSurfaceWrapper;
|
||||
class FAR IDirectDrawColorControlWrapper;
|
||||
class FAR IDirectDrawGammaControlWrapper;
|
||||
|
||||
// Custom vertex format
|
||||
const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZRHW | D3DFVF_TEX1;
|
||||
|
||||
// Custom vertex
|
||||
struct TLVERTEX
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float rhw;
|
||||
float u;
|
||||
float v;
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawWrapper Class
|
||||
*/
|
||||
class FAR IDirectDrawWrapper : public IDirectDraw
|
||||
{
|
||||
// Implemented interfaces
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDraw methods ***/
|
||||
HRESULT __stdcall Compact();
|
||||
HRESULT __stdcall CreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter);
|
||||
HRESULT __stdcall CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter);
|
||||
HRESULT __stdcall CreateSurface(LPDDSURFACEDESC lpDDSurfaceDes, LPDIRECTDRAWSURFACE FAR *lplpDDSurface, IUnknown FAR *pUnkOuter);
|
||||
HRESULT __stdcall DuplicateSurface(LPDIRECTDRAWSURFACE lpDDSurface, LPDIRECTDRAWSURFACE FAR *lplpDupDDSurface);
|
||||
HRESULT __stdcall EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback);
|
||||
HRESULT __stdcall EnumSurfaces(DWORD dwFlags, LPDDSURFACEDESC lpDDSD, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback);
|
||||
HRESULT __stdcall FlipToGDISurface();
|
||||
HRESULT __stdcall GetCaps(LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps);
|
||||
HRESULT __stdcall GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc);
|
||||
HRESULT __stdcall GetFourCCCodes(LPDWORD lpNumCodes, LPDWORD lpCodes);
|
||||
HRESULT __stdcall GetGDISurface(LPDIRECTDRAWSURFACE FAR *lplpGDIDDSSurface);
|
||||
HRESULT __stdcall GetMonitorFrequency(LPDWORD lpdwFrequency);
|
||||
HRESULT __stdcall GetScanLine(LPDWORD lpdwScanLine);
|
||||
HRESULT __stdcall GetVerticalBlankStatus(LPBOOL lpbIsInVB);
|
||||
HRESULT __stdcall Initialize(GUID FAR *lpGUID);
|
||||
HRESULT __stdcall RestoreDisplayMode();
|
||||
HRESULT __stdcall SetCooperativeLevel(HWND hWnd, DWORD dwFlags);
|
||||
HRESULT __stdcall SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP);
|
||||
// HRESULT __stdcall SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags);
|
||||
HRESULT __stdcall WaitForVerticalBlank(DWORD dwFlags,HANDLE hEvent);
|
||||
/*** Added in the v2 interface ***/
|
||||
HRESULT __stdcall GetAvailableVideoMem(LPDDSCAPS2 lpDDSCaps2, LPDWORD lpdwTotal, LPDWORD lpdwFree);
|
||||
/*** Added in the V4 Interface ***/
|
||||
HRESULT __stdcall EvaluateMode(DWORD dwFlags, DWORD *pSecondsUntilTimeout);
|
||||
HRESULT __stdcall GetDeviceIdentifier(LPDDDEVICEIDENTIFIER2 lpdddi, DWORD dwFlags);
|
||||
HRESULT __stdcall GetSurfaceFromDC(HDC hdc, LPDIRECTDRAWSURFACE7 *lpDDS);
|
||||
HRESULT __stdcall RestoreAllSurfaces();
|
||||
HRESULT __stdcall StartModeTest(LPSIZE lpModesToTest, DWORD dwNumEntries, DWORD dwFlags);
|
||||
HRESULT __stdcall TestCooperativeLevel();
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawWrapper();
|
||||
~IDirectDrawWrapper();
|
||||
|
||||
// Helper functions
|
||||
HRESULT WrapperInitialize(WNDPROC wp, HMODULE hMod);
|
||||
HRESULT Present();
|
||||
BOOL MenuKey(WPARAM vKey);
|
||||
void DoSnapshot();
|
||||
void ToggleFullscreen();
|
||||
|
||||
// Display window handle
|
||||
HWND hWnd;
|
||||
WNDPROC lpPrevWndFunc;
|
||||
WNDPROC WndProc;
|
||||
HMODULE hModule;
|
||||
|
||||
// Current display mode
|
||||
bool isWindowed;
|
||||
|
||||
// Application display mode
|
||||
DWORD displayModeWidth;
|
||||
DWORD displayModeHeight;
|
||||
|
||||
// Display resolution
|
||||
UINT displayWidth;
|
||||
UINT displayHeight;
|
||||
|
||||
// Saved display resolutions for fullscreen and windowed
|
||||
UINT displayWidthWindowed;
|
||||
UINT displayHeightWindowed;
|
||||
UINT displayWidthFullscreen;
|
||||
UINT displayHeightFullscreen;
|
||||
|
||||
// Custom functions and variables
|
||||
private:
|
||||
// Helper function to set window mode to match display mode
|
||||
void AdjustWindow();
|
||||
bool CreateD3DDevice();
|
||||
bool CreateSurfaceTexture();
|
||||
bool ReinitDevice();
|
||||
bool CheckD3DFailure(HRESULT hr, char *location, char *message);
|
||||
|
||||
IDirectDrawSurfaceWrapper *lpAttachedSurface;
|
||||
|
||||
// Reference count
|
||||
ULONG ReferenceCount;
|
||||
|
||||
// Direct3D9 Objects
|
||||
LPDIRECT3D9 d3d9Object;
|
||||
LPDIRECT3DDEVICE9 d3d9Device;
|
||||
D3DPRESENT_PARAMETERS presParams;
|
||||
LPDIRECT3DTEXTURE9 surfaceTexture;
|
||||
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
|
||||
|
||||
LPD3DXSPRITE d3dSprite;
|
||||
LPDIRECT3DTEXTURE9 menuTexture;
|
||||
int curMenuFrame;
|
||||
int menuLocations[5];
|
||||
RECT menuSprites[18];
|
||||
|
||||
// Flags and settings
|
||||
BOOL inMenu;
|
||||
int curMenu;
|
||||
int menuWindowedResolution;
|
||||
int windowedResolutionCount;
|
||||
POINT* windowedResolutions;
|
||||
int menuFullscreenResolution;
|
||||
int fullscreenResolutionCount;
|
||||
POINT* fullscreenResolutions;
|
||||
UINT* fullscreenRefreshes;
|
||||
|
||||
bool menuWindowed;
|
||||
bool menuvSync;
|
||||
|
||||
// Last window position
|
||||
POINT lastPosition;
|
||||
// Vsync enabled
|
||||
bool vSync;
|
||||
// Refresh rate for fullscreen
|
||||
UINT refreshRate;
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawPalette Wrapper
|
||||
*/
|
||||
class FAR IDirectDrawPaletteWrapper : public IDirectDrawPalette
|
||||
{
|
||||
// Implemented interfaces
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDrawPalette methods ***/
|
||||
HRESULT __stdcall GetCaps(LPDWORD lpdwCaps);
|
||||
HRESULT __stdcall GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries);
|
||||
HRESULT __stdcall Initialize(LPDIRECTDRAW lpDDW, DWORD dwFlags, LPPALETTEENTRY lpDDColorTable);
|
||||
HRESULT __stdcall SetEntries(DWORD dwFlags,DWORD dwStartingEntry,DWORD dwCount, LPPALETTEENTRY lpEntries);
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawPaletteWrapper();
|
||||
~IDirectDrawPaletteWrapper();
|
||||
// Helper functions
|
||||
HRESULT WrapperInitialize(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette);
|
||||
|
||||
// Rgb translated palette
|
||||
UINT32 *rgbPalette;
|
||||
// Raw palette data
|
||||
LPPALETTEENTRY rawPalette;
|
||||
|
||||
// Custom functions and variables
|
||||
private:
|
||||
// Reference count
|
||||
ULONG ReferenceCount;
|
||||
|
||||
// Palette flags
|
||||
DWORD paletteCaps;
|
||||
|
||||
// Number of palette entries
|
||||
int entryCount;
|
||||
// Raw palette has alpha data
|
||||
bool hasAlpha;
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawClipper Wrapper
|
||||
*/
|
||||
class FAR IDirectDrawClipperWrapper : public IDirectDrawClipper
|
||||
{
|
||||
// Implemented interfaces
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDrawClipper methods ***/
|
||||
HRESULT __stdcall GetClipList(LPRECT lpRect, LPRGNDATA lpClipList, LPDWORD lpdwSize);
|
||||
HRESULT __stdcall GetHWnd(HWND FAR *lphWnd);
|
||||
HRESULT __stdcall Initialize(LPDIRECTDRAW lpDD, DWORD dwFlags);
|
||||
HRESULT __stdcall IsClipListChanged(BOOL FAR *lpbChanged);
|
||||
HRESULT __stdcall SetClipList(LPRGNDATA lpClipList, DWORD dwFlags);
|
||||
HRESULT __stdcall SetHWnd(DWORD dwFlags, HWND hWnd);
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawClipperWrapper();
|
||||
~IDirectDrawClipperWrapper();
|
||||
// Helper functions
|
||||
HRESULT WrapperInitialize(DWORD dwFlags);
|
||||
|
||||
// Custom functions and variables
|
||||
private:
|
||||
// Reference count
|
||||
ULONG ReferenceCount;
|
||||
// Associated hwnd
|
||||
bool hasHwnd;
|
||||
HWND hWnd;
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawSurface Wrapper
|
||||
*/
|
||||
class FAR IDirectDrawSurfaceWrapper : public IDirectDrawSurface
|
||||
{
|
||||
friend void Device_Present(void);
|
||||
// Implemented interfaces
|
||||
public:
|
||||
IDirectDrawSurfaceWrapper() { attachedPalette = NULL; }
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDrawSurface methods ***/
|
||||
HRESULT __stdcall AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSurface);
|
||||
HRESULT __stdcall AddOverlayDirtyRect(LPRECT lpRect);
|
||||
HRESULT __stdcall Blt(LPRECT lpDestRect,LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
||||
HRESULT __stdcall BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags);
|
||||
HRESULT __stdcall BltFast(DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags);
|
||||
HRESULT __stdcall DeleteAttachedSurface(DWORD dwFlags,LPDIRECTDRAWSURFACE lpDDSAttachedSurface);
|
||||
HRESULT __stdcall EnumAttachedSurfaces(LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback);
|
||||
HRESULT __stdcall EnumOverlayZOrders(DWORD dwFlags, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpfnCallback);
|
||||
HRESULT __stdcall Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags);
|
||||
HRESULT __stdcall GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE FAR *lplpDDAttachedSurface);
|
||||
HRESULT __stdcall GetBltStatus(DWORD dwFlags);
|
||||
HRESULT __stdcall GetCaps(LPDDSCAPS lpDDSCaps);
|
||||
HRESULT __stdcall GetClipper(LPDIRECTDRAWCLIPPER FAR *lplpDDClipper);
|
||||
HRESULT __stdcall GetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey);
|
||||
HRESULT __stdcall GetDC(HDC FAR *lphDC);
|
||||
HRESULT __stdcall GetFlipStatus(DWORD dwFlags);
|
||||
HRESULT __stdcall GetOverlayPosition(LPLONG lplX, LPLONG lplY);
|
||||
HRESULT __stdcall GetPalette(LPDIRECTDRAWPALETTE FAR *lplpDDPalette);
|
||||
HRESULT __stdcall GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat);
|
||||
HRESULT __stdcall GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc);
|
||||
HRESULT __stdcall Initialize(LPDIRECTDRAW lpDD, LPDDSURFACEDESC lpDDSurfaceDesc);
|
||||
HRESULT __stdcall IsLost();
|
||||
HRESULT __stdcall Lock(LPRECT lpDestRect, LPDDSURFACEDESC lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent);
|
||||
HRESULT __stdcall ReleaseDC(HDC hDC);
|
||||
HRESULT __stdcall Restore();
|
||||
HRESULT __stdcall SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper);
|
||||
HRESULT __stdcall SetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey);
|
||||
HRESULT __stdcall SetOverlayPosition(LONG lX, LONG lY);
|
||||
HRESULT __stdcall SetPalette(LPDIRECTDRAWPALETTE lpDDPalette);
|
||||
HRESULT __stdcall Unlock(LPVOID lpRect);
|
||||
HRESULT __stdcall Unlock(LPRECT lpRect);
|
||||
HRESULT __stdcall UpdateOverlay(LPRECT lpSrcRect, LPDIRECTDRAWSURFACE lpDDDestSurface, LPRECT lpDestRect, DWORD dwFlags, LPDDOVERLAYFX lpDDOverlayFx);
|
||||
HRESULT __stdcall UpdateOverlayDisplay(DWORD dwFlags);
|
||||
HRESULT __stdcall UpdateOverlayZOrder(DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSReference);
|
||||
/*** Added in the v2 interface ***/
|
||||
HRESULT __stdcall GetDDInterface(LPVOID FAR *lplpDD);
|
||||
HRESULT __stdcall PageLock(DWORD dwFlags);
|
||||
HRESULT __stdcall PageUnlock(DWORD dwFlags);
|
||||
/*** Added in the v3 interface ***/
|
||||
HRESULT __stdcall SetSurfaceDesc(LPDDSURFACEDESC2 lpDDsd2, DWORD dwFlags);
|
||||
/*** Added in the v4 interface ***/
|
||||
HRESULT __stdcall ChangeUniquenessValue();
|
||||
HRESULT __stdcall FreePrivateData(REFGUID guidTag);
|
||||
HRESULT __stdcall GetPrivateData(REFGUID guidTag, LPVOID lpBuffer, LPDWORD lpcbBufferSize);
|
||||
HRESULT __stdcall GetUniquenessValue(LPDWORD lpValue);
|
||||
HRESULT __stdcall SetPrivateData(REFGUID guidTag, LPVOID lpData, DWORD cbSize, DWORD dwFlags);
|
||||
/*** Texture7 methods ***/
|
||||
HRESULT __stdcall SetPriority(DWORD dwPriority);
|
||||
HRESULT __stdcall GetPriority(LPDWORD lpdwPriority);
|
||||
HRESULT __stdcall SetLOD(LPDWORD lpdwMaxLOD);
|
||||
HRESULT __stdcall GetLOD(DWORD dwMaxLOD);
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawSurfaceWrapper(IDirectDrawWrapper* parent);
|
||||
~IDirectDrawSurfaceWrapper();
|
||||
|
||||
// Helper functions
|
||||
HRESULT WrapperInitialize(LPDDSURFACEDESC lpDDSurfaceDesc, DWORD displayModeWidth, DWORD displayModeHeight, DWORD displayWidth, DWORD displayHeight);
|
||||
BOOL ReInitialize(DWORD displayWidth, DWORD displayHeight);
|
||||
|
||||
// RGB video memory
|
||||
UINT32 *rgbVideoMem;
|
||||
|
||||
//Custom functions and variables
|
||||
private:
|
||||
// Reference count
|
||||
ULONG ReferenceCount;
|
||||
// Directdraw object that created this surface
|
||||
IDirectDrawWrapper *ddrawParent;
|
||||
// Associated palette
|
||||
IDirectDrawPaletteWrapper *attachedPalette;
|
||||
|
||||
// Surface description
|
||||
DDSURFACEDESC surfaceDesc;
|
||||
LONG surfaceWidth;
|
||||
LONG surfaceHeight;
|
||||
|
||||
// Color keys(DDCKEY_DESTBLT, DDCKEY_DESTOVERLAY, DDCKEY_SRCBLT, DDCKEY_SRCOVERLAY)
|
||||
DDCOLORKEY colorKeys[4];
|
||||
LONG overlayX, overlayY;
|
||||
|
||||
// Virtual video memory
|
||||
BYTE *rawVideoMem;
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawColorControl
|
||||
*/
|
||||
class FAR IDirectDrawColorControlWrapper : public IDirectDrawColorControl
|
||||
{
|
||||
//implemented interfaces
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDrawColorControl methods ***/
|
||||
HRESULT __stdcall GetColorControls(LPDDCOLORCONTROL lpColorControl);
|
||||
HRESULT __stdcall SetColorControls(LPDDCOLORCONTROL lpColorControl);
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawColorControlWrapper();
|
||||
~IDirectDrawColorControlWrapper();
|
||||
|
||||
// Custom functions and variables
|
||||
private:
|
||||
};
|
||||
|
||||
/*
|
||||
* IDirectDrawGammaControl
|
||||
*/
|
||||
class FAR IDirectDrawGammaControlWrapper : public IDirectDrawGammaControl
|
||||
{
|
||||
// Implemented interfaces
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
|
||||
ULONG __stdcall AddRef();
|
||||
ULONG __stdcall Release();
|
||||
/*** IDirectDrawGammaControl methods ***/
|
||||
HRESULT __stdcall GetGammaRamp(DWORD dwFlags, LPDDGAMMARAMP lpRampData);
|
||||
HRESULT __stdcall SetGammaRamp(DWORD dwFlags, LPDDGAMMARAMP lpRampData);
|
||||
|
||||
// Constructor/destructor
|
||||
IDirectDrawGammaControlWrapper();
|
||||
~IDirectDrawGammaControlWrapper();
|
||||
|
||||
// Custom functions and variables
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,195 +0,0 @@
|
||||
#pragma comment(linker, "/EXPORT:DirectDrawCreate=_DirectDrawCreate@12")
|
||||
|
||||
#include "DirectDrawWrapper.h"
|
||||
//#include "resource.h"
|
||||
//#include "detours.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
// Main thread ddrawwrapper object
|
||||
IDirectDrawWrapper *lpDD = NULL;
|
||||
// Original setcursorpos function pointer
|
||||
static BOOL (WINAPI *TrueSetCursorPos)(int,int) = SetCursorPos;
|
||||
static HMODULE (WINAPI *TrueLoadLibraryA)(LPCSTR) = GetModuleHandleA;
|
||||
|
||||
// Are we in the settings menu
|
||||
BOOL inMenu;
|
||||
// Dll start time
|
||||
DWORD start_time;
|
||||
// The level of debug to display
|
||||
int debugLevel;
|
||||
//debug display mode (-1 = none, 0 = console, 1 = file)
|
||||
int debugDisplay;
|
||||
//the debug file handle
|
||||
FILE *debugFile;
|
||||
|
||||
// Dll hmodule
|
||||
HMODULE hMod;
|
||||
|
||||
/* Helper function for throwing debug/error messages
|
||||
*
|
||||
* int level - Debug level
|
||||
* char *location - Message location
|
||||
* char *message - Message
|
||||
*/
|
||||
void debugMessage(int level, char *location, char *message)
|
||||
{
|
||||
// If above the current level then skip totally
|
||||
if(level > debugLevel) return;
|
||||
|
||||
// Calculate HMS
|
||||
DWORD cur_time = GetTickCount() - start_time;
|
||||
long hours = (long)floor((double)cur_time / (double)3600000.0);
|
||||
cur_time -= (hours * 3600000);
|
||||
int minutes = (int)floor((double)cur_time / (double)60000.0);
|
||||
cur_time -= (minutes * 60000);
|
||||
double seconds = (double)cur_time / (double)1000.0;
|
||||
|
||||
// Build error message
|
||||
char text[4096] = "\0";
|
||||
if(level == 0)
|
||||
{
|
||||
sprintf_s(text, 4096, "%d:%d:%#.1f ERR %s %s\n", hours, minutes, seconds, location, message);
|
||||
}
|
||||
else if(level == 1)
|
||||
{
|
||||
sprintf_s(text, 4096, "%d:%d:%#.1f WRN %s %s\n", hours, minutes, seconds, location, message);
|
||||
}
|
||||
else if(level == 2)
|
||||
{
|
||||
sprintf_s(text, 4096, "%d:%d:%#.1f INF %s %s\n", hours, minutes, seconds, location, message);
|
||||
}
|
||||
// Output and flush
|
||||
printf_s(text);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// Override function for cursor position
|
||||
BOOL WINAPI OverrideSetCursorPos(int X, int Y)
|
||||
{
|
||||
// If ddraw object exists and windowed mode
|
||||
if(lpDD != NULL && lpDD->isWindowed)
|
||||
{
|
||||
// X,Y are relative to client area within the code
|
||||
// Get client area location
|
||||
POINT cpos;
|
||||
cpos.x = 0;
|
||||
cpos.y = 0;
|
||||
ClientToScreen(lpDD->hWnd, &cpos);
|
||||
|
||||
// Calculate correct cursor offset and move
|
||||
BOOL res = TrueSetCursorPos(cpos.x + X, cpos.y + Y);
|
||||
return res;
|
||||
}
|
||||
return TrueSetCursorPos(X, Y);
|
||||
}
|
||||
|
||||
// Override function for load library
|
||||
/*HMODULE WINAPI OverrideLoadLibraryA(LPCSTR lpModuleName)
|
||||
{
|
||||
printf_s("%s\n", lpModuleName);
|
||||
return TrueLoadLibraryA(lpModuleName);
|
||||
}*/
|
||||
|
||||
// Pretty standard winproc
|
||||
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
// On syskey down
|
||||
case WM_SYSKEYDOWN:
|
||||
// ALT+ENTER trap keydown
|
||||
if (wParam == VK_RETURN)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// On syskey up
|
||||
case WM_SYSKEYUP:
|
||||
// ALT+ENTER trap keyup
|
||||
if (wParam == VK_RETURN)
|
||||
{
|
||||
// If DDW exists
|
||||
if(lpDD != NULL)
|
||||
{
|
||||
lpDD->ToggleFullscreen();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// On keydown
|
||||
case WM_KEYDOWN:
|
||||
// Overload printscreen(save a snapshot of the current screen
|
||||
if(wParam == VK_SNAPSHOT)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Always pass ~ to menu
|
||||
if(wParam == VK_OEM_3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Everything gets passed if we are in the menu
|
||||
if(inMenu)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// On keyup
|
||||
case WM_KEYUP:
|
||||
// Overload printscreen(save a snapshot of the current screen)
|
||||
if(!inMenu && wParam == VK_SNAPSHOT)
|
||||
{
|
||||
lpDD->DoSnapshot();
|
||||
return 0;
|
||||
}
|
||||
// Always pass ~ to menu
|
||||
if(wParam == VK_OEM_3)
|
||||
{
|
||||
// Pass to menu and set inMenu to result
|
||||
inMenu = lpDD->MenuKey(VK_OEM_3);
|
||||
return 0;
|
||||
}
|
||||
// Everything gets passed if we are in the menu
|
||||
if(inMenu)
|
||||
{
|
||||
// Pass to menu and set inMenu to result
|
||||
inMenu = lpDD->MenuKey(wParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// On destroy window
|
||||
case WM_DESTROY:
|
||||
// Restore the orignal window proc if we have it
|
||||
if(lpDD->lpPrevWndFunc != NULL)
|
||||
{
|
||||
SetWindowLong(hwnd, GWL_WNDPROC, (LONG)lpDD->lpPrevWndFunc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Call original windiow proc by default
|
||||
return CallWindowProc(lpDD->lpPrevWndFunc, hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
// Emulated direct draw create
|
||||
HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter)
|
||||
{
|
||||
// Create directdraw object
|
||||
lpDD = new IDirectDrawWrapper();
|
||||
if(lpDD == NULL)
|
||||
{
|
||||
debugMessage(0, "DirectDrawCreate", "Failed to create IDirectDrawWrapper.");
|
||||
return DDERR_OUTOFMEMORY; // Simulate OOM error
|
||||
}
|
||||
|
||||
// Initialize the ddraw object with new wndproc
|
||||
HRESULT hr = lpDD->WrapperInitialize(&WndProc, hMod);
|
||||
// If error then return error(message will have been taken care of already)
|
||||
if(hr != DD_OK) return hr;
|
||||
|
||||
// Set return pointer to the newly created DirectDrawWrapper interface
|
||||
*lplpDD = (LPDIRECTDRAW)lpDD;
|
||||
|
||||
// Return success
|
||||
return DD_OK;
|
||||
}
|
||||
Vendored
+2618
File diff suppressed because it is too large
Load Diff
Vendored
+28581
File diff suppressed because it is too large
Load Diff
Vendored
+23688
File diff suppressed because it is too large
Load Diff
Vendored
+1775
File diff suppressed because it is too large
Load Diff
Vendored
+1447
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user