Complete removal of directdraw and replaced with OpenGL. Has some bugs, movies disabled.

This commit is contained in:
Justin Marshall
2020-06-11 17:59:36 -07:00
parent a7fdd19b5a
commit ed18ca9a37
24 changed files with 58441 additions and 9754 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+62 -337
View File
@@ -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
View File
@@ -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
View File
@@ -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);
}
+2 -2
View File
@@ -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
View File
@@ -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;