From c2afdfe9c0301df7ef32e5184976a4dbe7082144 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 1 Feb 2008 07:18:53 +0000 Subject: [PATCH] 2008-02-01 08:17 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbw32ddr/w32_ddrw.cpp ! Fixed compile error under MSVC. ! Fixed MSVC warning (strdup() -> hb_strdup()) Now compiles without warnings under MSVC. ! Reindented, some formatting. --- harbour/ChangeLog | 7 + harbour/contrib/hbw32ddr/w32_ddrw.cpp | 1016 ++++++++++++------------- 2 files changed, 507 insertions(+), 516 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 879374086d..674a250730 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,13 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2008-02-01 08:17 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbw32ddr/w32_ddrw.cpp + ! Fixed compile error under MSVC. + ! Fixed MSVC warning (strdup() -> hb_strdup()) + Now compiles without warnings under MSVC. + ! Reindented, some formatting. + 2008-02-01 02:35 UTC+0100 Ryszard Glab * config/lib.cf * added vpath to search target libraries in lib// diff --git a/harbour/contrib/hbw32ddr/w32_ddrw.cpp b/harbour/contrib/hbw32ddr/w32_ddrw.cpp index f1f129438f..cf1bd2fa46 100644 --- a/harbour/contrib/hbw32ddr/w32_ddrw.cpp +++ b/harbour/contrib/hbw32ddr/w32_ddrw.cpp @@ -61,76 +61,75 @@ long hb_dd_g_DDSFaceCount=0; struct st_Sprites { - short int Type; // Type of Data - long Surface; // Surface index for loaded Image(s) - char * cName; // Sprite friendly Name - // 2D Engine data - long Width; // width of one frame - long Height; // height of one frame - long Images; // Number of frames in Surface - BOOL Visible; // Render it and do Hit detect? - long Frame; // Actual Frame to Render - long zOrder; // For painting - long x; // x in Virtual Screen - long y; // y in Virtual Screen - long VisibleX; // "real" y in Visible Screen - long VisibleY; // "real" x in Visible Screen - long FrameSpeed; // Render frame time ratio - long DrawInverted; // Draw Inverted - long Direction; // Clock wise code 1-2-3-4-5-6-7-8-9 - long xIncrement; // x Increment Increment; - long yIncrement; // y Increment - long Solid; // is Solid object ( collision on ) - long Masked; // is Masked? - short int lCollision; // Collision Detect On/Off + short int Type; // Type of Data + long Surface; // Surface index for loaded Image(s) + char * cName; // Sprite friendly Name + // 2D Engine data + long Width; // width of one frame + long Height; // height of one frame + long Images; // Number of frames in Surface + BOOL Visible; // Render it and do Hit detect? + long Frame; // Actual Frame to Render + long zOrder; // For painting + long x; // x in Virtual Screen + long y; // y in Virtual Screen + long VisibleX; // "real" y in Visible Screen + long VisibleY; // "real" x in Visible Screen + long FrameSpeed; // Render frame time ratio + long DrawInverted; // Draw Inverted + long Direction; // Clock wise code 1-2-3-4-5-6-7-8-9 + long xIncrement; // x Increment Increment; + long yIncrement; // y Increment + long Solid; // is Solid object ( collision on ) + long Masked; // is Masked? + short int lCollision; // Collision Detect On/Off - // Sprite Event Handlers... + // Sprite Event Handlers... - char * OnRender; // Render event Handler - char * OnCollision; // Collision Event Handler - char * OnFirstFrame; // First Frame handler - char * OnOutScreen; // Out of Bounds... + char * OnRender; // Render event Handler + char * OnCollision; // Collision Event Handler + char * OnFirstFrame; // First Frame handler + char * OnOutScreen; // Out of Bounds... -}hb_dd_Sprites[MAX_SPRITES]; +} hb_dd_Sprites[MAX_SPRITES]; long hb_dd_g_SpritesCount=0; //------------------------------------------------------------------// -// Multi-Key control array. +// Multi-Key control array. -short int hb_dd_g_KeyDown[256]; +short int hb_dd_g_KeyDown[ 256 ]; HB_FUNC( DD_ISKEYPRESSED ) { - if ( hb_dd_g_KeyDown[ hb_parnl( 1 ) ] ) - hb_retl( 1 ); - else - hb_retl( 0 ); + if( hb_dd_g_KeyDown[ hb_parnl( 1 ) ] ) + hb_retl( 1 ); + else + hb_retl( 0 ); } //------------------------------------------------------------------// HB_FUNC( DD_SPGETXY ) { + // This function is Broken ( hb_stornl fail ); - // This function is Broken ( hb_stornl fail ); + long n = hb_parnl( 1 ); - long n =hb_parnl( 1 ); + hb_reta( 2 ); - hb_reta( 2 ); - - hb_stornl( hb_dd_Sprites[ n ].x, -1, 0 ); - hb_stornl( hb_dd_Sprites[ n ].y, -1, 1 ); + hb_stornl( hb_dd_Sprites[ n ].x, -1, 0 ); + hb_stornl( hb_dd_Sprites[ n ].y, -1, 1 ); } HB_FUNC( DD_SPGETX ) { - hb_retnl( hb_dd_Sprites[ hb_parnl( 1 ) ].x ); + hb_retnl( hb_dd_Sprites[ hb_parnl( 1 ) ].x ); } HB_FUNC( DD_SPGETY ) { - hb_retnl( hb_dd_Sprites[ hb_parnl( 1 ) ].y ); + hb_retnl( hb_dd_Sprites[ hb_parnl( 1 ) ].y ); } //------------------------------------------------------------------// @@ -144,133 +143,133 @@ HB_FUNC( DD_SPGETVISIBLE ) HB_FUNC( DD_SPSETVISIBLE ) { - hb_dd_Sprites[ hb_parnl( 1 ) ].Visible = ( int ) hb_parl( 2 ); + hb_dd_Sprites[ hb_parnl( 1 ) ].Visible = ( int ) hb_parl( 2 ); } //------------------------------------------------------------------// HB_FUNC( DD_SPONRENDER ) { - hb_dd_Sprites[ hb_parnl( 1 ) ].OnRender = strdup( hb_parc(1) ); + hb_dd_Sprites[ hb_parnl( 1 ) ].OnRender = hb_strdup( hb_parc(1) ); } //------------------------------------------------------------------// HB_FUNC( DD_SPCLEARDIRECTION ) { - long n = hb_parnl( 1 ); - hb_dd_Sprites[ n ].xIncrement = 0; - hb_dd_Sprites[ n ].yIncrement = 0; - hb_dd_Sprites[ n ].Direction = -1; + long n = hb_parnl( 1 ); + hb_dd_Sprites[ n ].xIncrement = 0; + hb_dd_Sprites[ n ].yIncrement = 0; + hb_dd_Sprites[ n ].Direction = -1; } //------------------------------------------------------------------// HB_FUNC( DD_SPSETSOLID ) { - hb_dd_Sprites[hb_parnl( 1 ) ].Solid = hb_parl( 2 ); + hb_dd_Sprites[hb_parnl( 1 ) ].Solid = hb_parl( 2 ); } //------------------------------------------------------------------// HB_FUNC( DD_SPSETMASKED ) { - hb_dd_Sprites[hb_parnl( 1 ) ].Masked = hb_parl( 2 ); + hb_dd_Sprites[hb_parnl( 1 ) ].Masked = hb_parl( 2 ); } //------------------------------------------------------------------// HB_FUNC( DD_SPSETDIRECTION ) { - long n =hb_parnl( 1 ); + long n = hb_parnl( 1 ); - hb_dd_Sprites[ n ].Direction =hb_parnl( 2 ); - hb_dd_Sprites[ n ].xIncrement +=hb_parnl( 3 ); - hb_dd_Sprites[ n ].yIncrement +=hb_parnl( 4 ); + hb_dd_Sprites[ n ].Direction = hb_parnl( 2 ); + hb_dd_Sprites[ n ].xIncrement += hb_parnl( 3 ); + hb_dd_Sprites[ n ].yIncrement += hb_parnl( 4 ); } //------------------------------------------------------------------// HB_FUNC( DD_SPONFIRSTFRAME ) { - long n =hb_parnl( 1 ); - hb_dd_Sprites[ n ].OnFirstFrame = strdup( hb_parc(2) ); + long n = hb_parnl( 1 ); + hb_dd_Sprites[ n ].OnFirstFrame = hb_strdup( hb_parc(2) ); } //------------------------------------------------------------------// HB_FUNC( DD_SPONOUTSCREEN ) { - long n =hb_parnl( 1 ); - hb_dd_Sprites[ n ].OnOutScreen = strdup( hb_parc(2) ); + long n = hb_parnl( 1 ); + hb_dd_Sprites[ n ].OnOutScreen = hb_strdup( hb_parc(2) ); } //------------------------------------------------------------------// HB_FUNC( DD_SPONCOLLISION ) { - long n =hb_parnl( 1 ); - hb_dd_Sprites[ n ].OnCollision = strdup( hb_parc(2) ); - hb_dd_Sprites[ n ].lCollision = 1; + long n = hb_parnl( 1 ); + hb_dd_Sprites[ n ].OnCollision = hb_strdup( hb_parc(2) ); + hb_dd_Sprites[ n ].lCollision = 1; } //------------------------------------------------------------------// HB_FUNC( DD_CREATESPRITE ) { - long n = hb_dd_g_SpritesCount; + long n = hb_dd_g_SpritesCount; - ZeroMemory( &hb_dd_Sprites[ n ], sizeof( struct st_Sprites ) ); + ZeroMemory( &hb_dd_Sprites[ n ], sizeof( struct st_Sprites ) ); - hb_dd_Sprites[ n ].Surface = hb_parnl(1); - hb_dd_Sprites[ n ].cName = strdup( hb_parc(2) ); - hb_dd_Sprites[ n ].Width = hb_parnl(3); - hb_dd_Sprites[ n ].Height = hb_parnl(4); - hb_dd_Sprites[ n ].Images = hb_parnl(5); - hb_dd_Sprites[ n ].zOrder = hb_parnl(6); - hb_dd_Sprites[ n ].Visible = hb_parl(7); - hb_dd_Sprites[ n ].FrameSpeed =hb_parnl(8); + hb_dd_Sprites[ n ].Surface = hb_parnl( 1 ); + hb_dd_Sprites[ n ].cName = hb_strdup( hb_parc( 2 ) ); + hb_dd_Sprites[ n ].Width = hb_parnl( 3 ); + hb_dd_Sprites[ n ].Height = hb_parnl( 4 ); + hb_dd_Sprites[ n ].Images = hb_parnl( 5 ); + hb_dd_Sprites[ n ].zOrder = hb_parnl( 6 ); + hb_dd_Sprites[ n ].Visible = hb_parl( 7 ); + hb_dd_Sprites[ n ].FrameSpeed = hb_parnl( 8 ); - hb_dd_g_SpritesCount++; + hb_dd_g_SpritesCount++; - hb_retnl( n ); + hb_retnl( n ); } //------------------------------------------------------------------// HB_FUNC( DD_SPSETXY ) { - long n =hb_parnl( 1 ); - long x =hb_parnl( 2 ); - long y =hb_parnl( 3 ); - hb_dd_Sprites[ n ].x = x; - hb_dd_Sprites[ n ].y = y; + long n = hb_parnl( 1 ); + long x = hb_parnl( 2 ); + long y = hb_parnl( 3 ); + hb_dd_Sprites[ n ].x = x; + hb_dd_Sprites[ n ].y = y; } //------------------------------------------------------------------// HB_FUNC( DD_SPSETINVERTED ) { - LPDIRECTDRAWSURFACE4 pdds; - long n =hb_parnl(1); - RECT rt; - DDBLTFX todo; + LPDIRECTDRAWSURFACE4 pdds; + long n = hb_parnl( 1 ); + RECT rt; + DDBLTFX todo; - long dir =hb_parnl( 2 ); - if ( dir != hb_dd_Sprites[ n ].DrawInverted ) - { - rt.top = 0; - rt.left = 0; - rt.bottom= hb_dd_Sprites[ n ].Height; - rt.right = hb_dd_Sprites[ n ].Width * hb_dd_Sprites[ n ].Images; - ZeroMemory( &todo, sizeof( DDBLTFX ) ); + long dir = hb_parnl( 2 ); + if( dir != hb_dd_Sprites[ n ].DrawInverted ) + { + rt.top = 0; + rt.left = 0; + rt.bottom= hb_dd_Sprites[ n ].Height; + rt.right = hb_dd_Sprites[ n ].Width * hb_dd_Sprites[ n ].Images; + ZeroMemory( &todo, sizeof( DDBLTFX ) ); - hb_dd_Sprites[ n ].DrawInverted = dir; - todo.dwSize = sizeof( DDBLTFX ); - todo.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT; - pdds = hb_dd_g_DDSFaces[ hb_dd_Sprites[ n ].Surface ]; - pdds->Blt(&rt, pdds, &rt, DDBLT_DDFX ,&todo ); - } + hb_dd_Sprites[ n ].DrawInverted = dir; + todo.dwSize = sizeof( DDBLTFX ); + todo.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT; + pdds = hb_dd_g_DDSFaces[ hb_dd_Sprites[ n ].Surface ]; + pdds->Blt(&rt, pdds, &rt, DDBLT_DDFX ,&todo ); + } } @@ -278,311 +277,305 @@ HB_FUNC( DD_SPSETINVERTED ) HB_FUNC( DD_MSGBOX ) { - char *m1; - char *m2; - char deftitle [100] = ""; - char defmsg [2] = ""; + char *m1; + char *m2; + char deftitle [100] = ""; + char defmsg [2] = ""; - if ( hb_pcount() > 0 ) - m1 = hb_parc( 1 ); - else - m1 = defmsg; + if( hb_pcount() > 0 ) + m1 = hb_parc( 1 ); + else + m1 = defmsg; - if ( hb_pcount() > 1 ) - m2 = hb_parc( 2 ); - else - m2 = deftitle; + if( hb_pcount() > 1 ) + m2 = hb_parc( 2 ); + else + m2 = deftitle; - MessageBox( hb_dd_g_DDHwnd, m1, m2, NULL); + MessageBox( hb_dd_g_DDHwnd, m1, m2, NULL); } //------------------------------------------------------------------// void hb_dd_WinError( void ) { - LPVOID lpMsgBuf;FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf. - // ...// Display the string. - MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); - // Free the buffer. - LocalFree( lpMsgBuf ); - + LPVOID lpMsgBuf;FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf. + // ...// Display the string. + MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); + // Free the buffer. + LocalFree( lpMsgBuf ); } //------------------------------------------------------------------// DWORD hb_dd_DDColorMatch(IDirectDrawSurface4 * pdds, COLORREF rgb) { - COLORREF rgbT; - HDC hdc; - DWORD dw = CLR_INVALID; - DDSURFACEDESC2 ddsd; - HRESULT hres; + COLORREF rgbT; + HDC hdc; + DWORD dw = CLR_INVALID; + DDSURFACEDESC2 ddsd; + HRESULT hres; - // - // Use GDI SetPixel to color match for us - // - if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK) - { - rgbT = GetPixel(hdc, 0, 0); // Save current pixel value - SetPixel(hdc, 0, 0, rgb); // Set our value - pdds->ReleaseDC(hdc); - } - // - // Now lock the surface so we can read back the converted color - // - ddsd.dwSize = sizeof(ddsd); + // + // Use GDI SetPixel to color match for us + // + if( rgb != CLR_INVALID && pdds->GetDC( &hdc ) == DD_OK ) + { + rgbT = GetPixel( hdc, 0, 0 ); // Save current pixel value + SetPixel( hdc, 0, 0, rgb ); // Set our value + pdds->ReleaseDC( hdc ); + } + // + // Now lock the surface so we can read back the converted color + // + ddsd.dwSize = sizeof( ddsd ); - while ((hres = pdds->Lock(NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING); + while( ( hres = pdds->Lock( NULL, &ddsd, 0, NULL ) ) == DDERR_WASSTILLDRAWING ); - if (hres == DD_OK) - { - dw = *(DWORD *) ddsd.lpSurface; // Get DWORD - if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32) - dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; // Mask it to bpp - pdds->Unlock(NULL); - } - // - // Now put the color that was there back. - // - if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK) - { - SetPixel(hdc, 0, 0, rgbT); - pdds->ReleaseDC(hdc); - } + if( hres == DD_OK ) + { + dw = *( DWORD * ) ddsd.lpSurface; // Get DWORD + if( ddsd.ddpfPixelFormat.dwRGBBitCount < 32 ) + dw &= ( 1 << ddsd.ddpfPixelFormat.dwRGBBitCount ) - 1; // Mask it to bpp + pdds->Unlock(NULL); + } + // + // Now put the color that was there back. + // + if( rgb != CLR_INVALID && pdds->GetDC( &hdc ) == DD_OK ) + { + SetPixel( hdc, 0, 0, rgbT ); + pdds->ReleaseDC( hdc ); + } - return dw; + return dw; } //------------------------------------------------------------------// void hb_dd_RenderSprites( long control ) { + HRESULT hRet; + long cont,cont2; + RECT rcRect; + LPDIRECTDRAWSURFACE4 pdds; + PHB_DYNS pDynSym; - HRESULT hRet; - long cont,cont2; - RECT rcRect; - LPDIRECTDRAWSURFACE4 pdds; - PHB_DYNS pDynSym; + pDynSym = hb_dynsymFindName( "DDONRENDER" ); - pDynSym = hb_dynsymFindName( "DDONRENDER" ); + if( pDynSym ) + { + hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); + hb_vmPushNil(); + hb_vmDo( 0 ); + } - if( pDynSym ) - { - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - hb_vmPushNil(); - hb_vmDo(0); - } + for( cont=0; cont hb_dd_Sprites[ cont ].Images ) + if( hb_dd_Sprites[ cont ].Frame > hb_dd_Sprites[ cont ].Images ) + { + if( hb_dd_Sprites[ cont ].OnFirstFrame != NULL ) { - - if ( hb_dd_Sprites[ cont ].OnFirstFrame != NULL ) - { - pDynSym = hb_dynsymFindName( hb_dd_Sprites[ cont ].OnFirstFrame ); - - if( pDynSym ) - { - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - hb_vmPushNil(); - hb_vmDo(0); - } - } - hb_dd_Sprites[ cont ].Frame = 1; + pDynSym = hb_dynsymFindName( hb_dd_Sprites[ cont ].OnFirstFrame ); + + if( pDynSym ) + { + hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); + hb_vmPushNil(); + hb_vmDo(0); + } } + hb_dd_Sprites[ cont ].Frame = 1; + } + rcRect.left = ( hb_dd_Sprites[ cont ].Frame - 1 ) * hb_dd_Sprites[ cont ].Width; + rcRect.top = 0; + rcRect.right = ( hb_dd_Sprites[ cont ].Frame - 1 ) * hb_dd_Sprites[ cont ].Width + hb_dd_Sprites[ cont ].Width; + rcRect.bottom = hb_dd_Sprites[ cont ].Height; - rcRect.left = ( hb_dd_Sprites[ cont ].Frame - 1 ) * hb_dd_Sprites[ cont ].Width; - rcRect.top = 0; - rcRect.right = ( hb_dd_Sprites[ cont ].Frame - 1 ) * hb_dd_Sprites[ cont ].Width + hb_dd_Sprites[ cont ].Width; - rcRect.bottom = hb_dd_Sprites[ cont ].Height; + if( control == 1 ) + hb_dd_Sprites[ cont ].Frame++; - if ( control == 1 ) - hb_dd_Sprites[ cont ].Frame++; + pdds = hb_dd_g_DDSFaces[ hb_dd_Sprites[ cont ].Surface ]; - pdds = hb_dd_g_DDSFaces[ hb_dd_Sprites[ cont ].Surface ]; - - while (TRUE) + while( TRUE ) + { + if( ! hb_dd_Sprites[ cont ].Masked ) + hRet = hb_dd_g_DDSFaces[1]->BltFast(hb_dd_Sprites[ cont ].x, hb_dd_Sprites[ cont ].y, pdds, &rcRect, FALSE ); + else { - if ( ! hb_dd_Sprites[ cont ].Masked ) - hRet = hb_dd_g_DDSFaces[1]->BltFast(hb_dd_Sprites[ cont ].x, hb_dd_Sprites[ cont ].y, pdds, &rcRect, FALSE ); - else - { - DDCOLORKEY ddck; + DDCOLORKEY ddck; - ddck.dwColorSpaceLowValue = hb_dd_DDColorMatch( pdds, CLR_INVALID ); - ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue; + ddck.dwColorSpaceLowValue = hb_dd_DDColorMatch( pdds, CLR_INVALID ); + ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue; - pdds->SetColorKey( DDCKEY_SRCBLT ,&ddck ); + pdds->SetColorKey( DDCKEY_SRCBLT ,&ddck ); - hb_dd_g_DDSFaces[1]->SetColorKey( DDCKEY_DESTBLT ,&ddck ); + hb_dd_g_DDSFaces[1]->SetColorKey( DDCKEY_DESTBLT ,&ddck ); - hRet = hb_dd_g_DDSFaces[1]->BltFast(hb_dd_Sprites[ cont ].x, hb_dd_Sprites[ cont ].y, pdds, &rcRect, DDBLTFAST_SRCCOLORKEY ); - } - hb_dd_checkError( hRet ); - if (hRet == DD_OK) - break; - if (hRet == DDERR_SURFACELOST) - { - hRet = hb_dd_g_DDSFaces[1]->Restore(); - if (hRet != DD_OK) - break; - } - if (hRet != DDERR_WASSTILLDRAWING) - break; + hRet = hb_dd_g_DDSFaces[1]->BltFast(hb_dd_Sprites[ cont ].x, hb_dd_Sprites[ cont ].y, pdds, &rcRect, DDBLTFAST_SRCCOLORKEY ); } - - if ( hb_dd_Sprites[ cont ].OnOutScreen != NULL ) + hb_dd_checkError( hRet ); + if( hRet == DD_OK ) + break; + if( hRet == DDERR_SURFACELOST ) { - if ( hb_dd_Sprites[ cont ].x < 0 || hb_dd_Sprites[ cont ].y < 0 || hb_dd_Sprites[ cont ].x > 640 || hb_dd_Sprites[ cont ].y > 480 ) - { - if ( hb_dd_Sprites[ cont ].OnOutScreen != NULL ) - { - pDynSym = hb_dynsymFindName( hb_dd_Sprites[ cont ].OnOutScreen ); - - if( pDynSym ) - { - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - hb_vmPushNil(); - hb_vmPushLong( cont ); - hb_vmDo( 1 ); - } - } - - //SetParam( ( void * ) &cont , TSI_DWORD ); - //VMCall( hb_dd_Sprites[ cont ].OnOutScreen ); - } + hRet = hb_dd_g_DDSFaces[1]->Restore(); + if (hRet != DD_OK) + break; } - } - } + if( hRet != DDERR_WASSTILLDRAWING ) + break; + } + + if( hb_dd_Sprites[ cont ].OnOutScreen != NULL ) + { + if( hb_dd_Sprites[ cont ].x < 0 || hb_dd_Sprites[ cont ].y < 0 || hb_dd_Sprites[ cont ].x > 640 || hb_dd_Sprites[ cont ].y > 480 ) + { + if( hb_dd_Sprites[ cont ].OnOutScreen != NULL ) + { + pDynSym = hb_dynsymFindName( hb_dd_Sprites[ cont ].OnOutScreen ); + + if( pDynSym ) + { + hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); + hb_vmPushNil(); + hb_vmPushLong( cont ); + hb_vmDo( 1 ); + } + } + + //SetParam( ( void * ) &cont , TSI_DWORD ); + //VMCall( hb_dd_Sprites[ cont ].OnOutScreen ); + } + } + } + } } //------------------------------------------------------------------// - - long _stdcall hb_dd_DDWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - HRESULT hRet; - int nVirtKey; + HRESULT hRet; + int nVirtKey; - switch( uMsg ) - { - case WM_DESTROY: - hb_dd_ReleaseAllObjects(); - break; - case WM_KEYUP: - { - nVirtKey= (int) wParam; // virtual-key code - hb_dd_g_KeyDown[ nVirtKey ] = 0; - break; - } - case WM_KEYDOWN: - { - nVirtKey = (int) wParam; // virtual-key code - hb_dd_g_KeyDown[ nVirtKey ] = 1; + switch( uMsg ) + { + case WM_DESTROY: + { + hb_dd_ReleaseAllObjects(); + break; + } + case WM_KEYUP: + { + nVirtKey= (int) wParam; // virtual-key code + hb_dd_g_KeyDown[ nVirtKey ] = 0; + break; + } + case WM_KEYDOWN: + { + nVirtKey = (int) wParam; // virtual-key code + hb_dd_g_KeyDown[ nVirtKey ] = 1; - if ( ( int ) wParam == 27 ) - { - PostMessage( hWnd, WM_CLOSE,0,0); - PostMessage( hWnd, WM_DESTROY,0,0); - } - break; - } - case WM_TIMER: - { - if ( HB_DD_TIMER_ID == wParam) + if( ( int ) wParam == 27 ) + { + PostMessage( hWnd, WM_CLOSE,0,0); + PostMessage( hWnd, WM_DESTROY,0,0); + } + break; + } + case WM_TIMER: + { + if( HB_DD_TIMER_ID == wParam ) + { + if( ! hb_dd_g_handling_events ) { - if ( ! hb_dd_g_handling_events ) - { - hb_dd_g_handling_events = TRUE; - hb_dd_RenderSprites(1); - while (TRUE) - { - hRet = hb_dd_g_DDSFaces[0]->Flip(NULL, 0); - if (hRet == DD_OK) + hb_dd_g_handling_events = TRUE; + hb_dd_RenderSprites( 1 ); + while( TRUE ) + { + hRet = hb_dd_g_DDSFaces[0]->Flip(NULL, 0); + if( hRet == DD_OK ) + break; + if( hRet == DDERR_SURFACELOST ) + { + hRet = hb_dd_g_DDSFaces[0]->Restore(); + if( hRet != DD_OK ) break; - if (hRet == DDERR_SURFACELOST) - { - hRet = hb_dd_g_DDSFaces[0]->Restore(); - if (hRet != DD_OK) - break; - } - if (hRet != DDERR_WASSTILLDRAWING) - break; - } - hb_dd_g_handling_events = FALSE; - } + } + if( hRet != DDERR_WASSTILLDRAWING ) + break; + } + hb_dd_g_handling_events = FALSE; } - break; - } - } + } + break; + } + } - return DefWindowProc( hWnd, uMsg, wParam , lParam ); + return DefWindowProc( hWnd, uMsg, wParam , lParam ); } //------------------------------------------------------------------// - HB_FUNC( DD_CREATEWINDOW ) { - HWND m_hWnd; HINSTANCE m_hInstance = GetModuleHandle(NULL); long x,y; @@ -607,7 +600,7 @@ HB_FUNC( DD_CREATEWINDOW ) WS_POPUP, 0, 0, x,y, NULL, NULL, m_hInstance, 0L ); - if ( !m_hWnd ) + if( !m_hWnd ) hb_dd_WinError(); ShowWindow( m_hWnd,SW_SHOWMAXIMIZED ); @@ -618,126 +611,120 @@ HB_FUNC( DD_CREATEWINDOW ) //------------------------------------------------------------------// -hb_dd_InitFail(HWND hWnd, HRESULT hRet, LPCTSTR szError,...) +int hb_dd_InitFail( HWND hWnd, HRESULT hRet, LPCTSTR szError, ... ) { - char szBuff[128]; - va_list vl; - va_start(vl, szError); - vsprintf(szBuff, szError, vl); - MessageBox(hWnd, szBuff, "4dNow extend sys.", MB_OK); - DestroyWindow(hWnd); - va_end(vl); - exit(1); - return hRet; + char szBuff[ 128 ]; + va_list vl; + va_start( vl, szError ); + vsprintf( szBuff, szError, vl ); + MessageBox( hWnd, szBuff, "4dNow extend sys.", MB_OK ); + DestroyWindow( hWnd ); + va_end( vl ); + exit( 1 ); + return hRet; } - //------------------------------------------------------------------// HB_FUNC( DD_LOADBMPINTOSURFACE ) { - long nSurface = hb_parnl( 1 ); - char * cBitmap = hb_parc ( 2 ); - long x = hb_parnl( 3 ); - long y = hb_parnl( 4 ); - long dx = hb_parnl( 5 ); - long dy = hb_parnl( 6 ); + long nSurface = hb_parnl( 1 ); + char * cBitmap = hb_parc ( 2 ); + long x = hb_parnl( 3 ); + long y = hb_parnl( 4 ); + long dx = hb_parnl( 5 ); + long dy = hb_parnl( 6 ); - HBITMAP hbm; + HBITMAP hbm; - // Load our bitmap resource. + // Load our bitmap resource. + hbm = (HBITMAP) LoadImage(GetModuleHandle(NULL), cBitmap, IMAGE_BITMAP, 0, + 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); - hbm = (HBITMAP) LoadImage(GetModuleHandle(NULL), cBitmap, IMAGE_BITMAP, 0, - 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); + if( hbm == NULL ) + hb_dd_g_Error( "Can't load Bitmap.",100,cBitmap ); - if (hbm == NULL) - hb_dd_g_Error( "Can't load Bitmap.",100,cBitmap ); + if( hb_dd_g_DDSFaces[ nSurface ] == NULL ) + hb_dd_g_Error( "Invalid Surface",nSurface,"LoadBmpIntoSurface"); - if ( hb_dd_g_DDSFaces[ nSurface ] == NULL ) - hb_dd_g_Error( "Invalid Surface",nSurface,"LoadBmpIntoSurface"); - - if ( DD_OK != hb_dd_DDCopyBitmap( hb_dd_g_DDSFaces[ nSurface ], hbm, x,y, dx, dy ) ) - hb_dd_g_Error( "DDCopyBitmap",nSurface,"LoadBmpIntoSurface"); - - - DeleteObject(hbm); + if( DD_OK != hb_dd_DDCopyBitmap( hb_dd_g_DDSFaces[ nSurface ], hbm, x,y, dx, dy ) ) + hb_dd_g_Error( "DDCopyBitmap",nSurface,"LoadBmpIntoSurface"); + DeleteObject(hbm); } //------------------------------------------------------------------// HB_FUNC( DD_CREATEOFFSCREENBITMAP ) { - DDSURFACEDESC2 ddsd; - HRESULT hRet; + DDSURFACEDESC2 ddsd; + HRESULT hRet; - if ( ! hb_dd_g_pDD ) - hb_dd_g_Error("No DDraw Initialized",1000,""); + if( ! hb_dd_g_pDD ) + hb_dd_g_Error("No DDraw Initialized",1000,""); - if ( hb_dd_g_DDSFaceCount >= MAX_DDSURFACES ) - hb_dd_g_Error( "No more DDSurfaces -> Limit reached -> CreateDDSurface()",1000,"DDraw extend sys"); - else - { - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH ; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - ddsd.dwHeight = hb_dd_g_yWindow; - ddsd.dwWidth = hb_dd_g_xWindow; - hRet = hb_dd_g_pDD->CreateSurface(&ddsd, &hb_dd_g_DDSFaces[ hb_dd_g_DDSFaceCount ], NULL); - if (hRet != DD_OK) - hb_dd_InitFail(hb_dd_g_DDHwnd, hRet, "CreateSurface FAILED"); - } - - hb_retnl( hb_dd_g_DDSFaceCount ); - hb_dd_g_DDSFaceCount++; + if( hb_dd_g_DDSFaceCount >= MAX_DDSURFACES ) + hb_dd_g_Error( "No more DDSurfaces -> Limit reached -> CreateDDSurface()",1000,"DDraw extend sys"); + else + { + ZeroMemory(&ddsd, sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH ; + ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + ddsd.dwHeight = hb_dd_g_yWindow; + ddsd.dwWidth = hb_dd_g_xWindow; + hRet = hb_dd_g_pDD->CreateSurface(&ddsd, &hb_dd_g_DDSFaces[ hb_dd_g_DDSFaceCount ], NULL); + if( hRet != DD_OK ) + hb_dd_InitFail( hb_dd_g_DDHwnd, hRet, "CreateSurface FAILED" ); + } + hb_retnl( hb_dd_g_DDSFaceCount ); + hb_dd_g_DDSFaceCount++; } - //------------------------------------------------------------------// void hb_RestoreAll(void) { - HRESULT hRet; - long t; + HRESULT hRet; + long t; - hRet = hb_dd_g_DDSFaces[0]->Restore(); - if (hRet == DD_OK) - { - for( t=2;tRestore(); - } - } + hRet = hb_dd_g_DDSFaces[0]->Restore(); + if( hRet == DD_OK ) + { + for( t = 2; t < MAX_DDSURFACES; t++ ) + { + if( hb_dd_g_DDSFaces[ t ] != NULL ) + hb_dd_g_DDSFaces[ t ]->Restore(); + } + } } //------------------------------------------------------------------// void hb_dd_ReleaseAllObjects(void) { - long t; - if (hb_dd_g_pDD != NULL) - { - if (hb_dd_g_DDSFaces[0] != NULL) - { - hb_dd_g_DDSFaces[0]->Release(); - hb_dd_g_DDSFaces[0] = NULL; - } - - for( t=2;tRelease(); - hb_dd_g_DDSFaces[t] = NULL; - } - } - hb_dd_g_pDD->Release(); - hb_dd_g_pDD = NULL; - } + long t; + if( hb_dd_g_pDD != NULL ) + { + if( hb_dd_g_DDSFaces[ 0 ] != NULL ) + { + hb_dd_g_DDSFaces[ 0 ]->Release(); + hb_dd_g_DDSFaces[ 0 ] = NULL; + } + + for( t = 2; t < MAX_DDSURFACES; t++ ) + { + if( hb_dd_g_DDSFaces[ t ] != NULL ) + { + hb_dd_g_DDSFaces[ t ]->Release(); + hb_dd_g_DDSFaces[ t ] = NULL; + } + } + hb_dd_g_pDD->Release(); + hb_dd_g_pDD = NULL; + } } @@ -745,146 +732,143 @@ void hb_dd_ReleaseAllObjects(void) void hb_dd_DDrawStartup( HWND hWnd ) { - DDSURFACEDESC2 ddsd; - DDSCAPS2 ddscaps; - HRESULT hRet; - LPDIRECTDRAW pDD; - long t; + DDSURFACEDESC2 ddsd; + DDSCAPS2 ddscaps; + HRESULT hRet; + LPDIRECTDRAW pDD; + long t; - hb_dd_g_DDHwnd = hWnd; + hb_dd_g_DDHwnd = hWnd; + hRet = DirectDrawCreate(NULL, &pDD, NULL); + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "DirectDrawCreate FAILED" ); - hRet = DirectDrawCreate(NULL, &pDD, NULL); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "DirectDrawCreate FAILED"); + hRet = pDD->QueryInterface(IID_IDirectDraw4, (LPVOID *) &hb_dd_g_pDD ); + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "QueryInterface FAILED" ); - hRet = pDD->QueryInterface(IID_IDirectDraw4, (LPVOID *) &hb_dd_g_pDD ); + hRet = pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_ALLOWMODEX ); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "QueryInterface FAILED"); + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "SetCooperativeLevel FAILED" ); - hRet = pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_ALLOWMODEX ); + hRet = hb_dd_g_pDD->SetDisplayMode(hb_dd_g_xWindow , hb_dd_g_yWindow , 16, 0, 0); + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "SetDisplayMode FAILED" ); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "SetCooperativeLevel FAILED"); + for( t=0;t<= MAX_DDSURFACES;t++ ) + hb_dd_g_DDSFaces[t] = NULL; + for( t=0;t< MAX_SPRITES;t++) + hb_dd_Sprites[t].Surface = -1; + for( t=0;t<256;t++) + hb_dd_g_KeyDown[t] = 0; + ZeroMemory(&ddsd, sizeof(ddsd)); - hRet = hb_dd_g_pDD->SetDisplayMode(hb_dd_g_xWindow , hb_dd_g_yWindow , 16, 0, 0); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "SetDisplayMode FAILED"); + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT | DDSD_CKSRCBLT; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | + DDSCAPS_FLIP | + DDSCAPS_COMPLEX ; + ddsd.dwBackBufferCount = 1; + hRet = hb_dd_g_pDD->CreateSurface(&ddsd, &hb_dd_g_DDSFaces[0] , NULL); + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "CreateSurface FAILED" ); - for( t=0;t<= MAX_DDSURFACES;t++ ) - hb_dd_g_DDSFaces[t] = NULL; - for( t=0;t< MAX_SPRITES;t++) - hb_dd_Sprites[t].Surface = -1; - for( t=0;t<256;t++) - hb_dd_g_KeyDown[t] = 0; - ZeroMemory(&ddsd, sizeof(ddsd)); + ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT | DDSD_CKSRCBLT; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | - DDSCAPS_FLIP | - DDSCAPS_COMPLEX ; - ddsd.dwBackBufferCount = 1; - hRet = hb_dd_g_pDD->CreateSurface(&ddsd, &hb_dd_g_DDSFaces[0] , NULL); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "CreateSurface FAILED"); + hRet = hb_dd_g_DDSFaces[0]->GetAttachedSurface(&ddscaps,&hb_dd_g_DDSFaces[1] ); - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; + if( hRet != DD_OK ) + hb_dd_InitFail( hWnd, hRet, "GetAttachedSurface FAILED" ); - hRet = hb_dd_g_DDSFaces[0]->GetAttachedSurface(&ddscaps,&hb_dd_g_DDSFaces[1] ); + if( HB_DD_TIMER_ID != SetTimer( hWnd, HB_DD_TIMER_ID, HB_DD_TIMER_RATE, NULL ) ) + hb_dd_InitFail( hWnd, hRet, "SetTimer FAILED" ); - if (hRet != DD_OK) - hb_dd_InitFail(hWnd, hRet, "GetAttachedSurface FAILED"); - - if (HB_DD_TIMER_ID != SetTimer(hWnd, HB_DD_TIMER_ID, HB_DD_TIMER_RATE, NULL)) - hb_dd_InitFail( hWnd, hRet, "SetTimer FAILED" ); - - hb_dd_g_DDSFaceCount = 2; + hb_dd_g_DDSFaceCount = 2; } //------------------------------------------------------------------// HB_FUNC( DD_STARTWINDOW ) { - MSG msg; - BOOL loop = TRUE; + MSG msg; + BOOL loop = TRUE; - while( loop ) - { - if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - if ( WM_CLOSE == msg.message ) - loop = FALSE; - - } + while( loop ) + { + if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) + { + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + if( WM_CLOSE == msg.message ) + loop = FALSE; + } } //------------------------------------------------------------------// HRESULT hb_dd_DDCopyBitmap(IDirectDrawSurface4 * pdds, HBITMAP hbm, int x, int y, int dx, int dy) { - HDC hdcImage; - HDC hdc; - BITMAP bm; - DDSURFACEDESC2 ddsd; - HRESULT hr; + HDC hdcImage; + HDC hdc; + BITMAP bm; + DDSURFACEDESC2 ddsd; + HRESULT hr; - if (hbm == NULL || pdds == NULL) - return E_FAIL; + if( hbm == NULL || pdds == NULL ) + return E_FAIL; - pdds->Restore(); + pdds->Restore(); - hdcImage = CreateCompatibleDC(NULL); - if (!hdcImage) - OutputDebugString("createcompatible dc failed\n"); - SelectObject(hdcImage, hbm); + hdcImage = CreateCompatibleDC(NULL); + if( !hdcImage ) + OutputDebugString("createcompatible dc failed\n"); + SelectObject(hdcImage, hbm); - GetObject(hbm, sizeof(bm), &bm); - dx = dx == 0 ? bm.bmWidth : dx; // Use the passed size, unless zero - dy = dy == 0 ? bm.bmHeight : dy; + GetObject(hbm, sizeof(bm), &bm); + dx = dx == 0 ? bm.bmWidth : dx; // Use the passed size, unless zero + dy = dy == 0 ? bm.bmHeight : dy; - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; - pdds->GetSurfaceDesc(&ddsd); + pdds->GetSurfaceDesc(&ddsd); - if ((hr = pdds->GetDC(&hdc)) == DD_OK) - { - StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, x, y, - dx, dy, SRCCOPY); - pdds->ReleaseDC(hdc); - } - DeleteDC(hdcImage); - return hr; + if( ( hr = pdds->GetDC( &hdc ) ) == DD_OK ) + { + StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, x, y, + dx, dy, SRCCOPY); + pdds->ReleaseDC(hdc); + } + DeleteDC(hdcImage); + return hr; } long hb_dd_checkError( HRESULT hr ) { - long p = 0; + long p = 0; - switch( hr ) - { - case DDERR_EXCEPTION : p++;break; - case DDERR_GENERIC : p++;break; - case DDERR_INVALIDOBJECT : p++;break; - case DDERR_INVALIDPARAMS : p++;break; - case DDERR_INVALIDRECT : p++;break; - case DDERR_NOBLTHW : p++;break; - case DDERR_SURFACEBUSY : p++;break; - case DDERR_SURFACELOST : p++;break; - case DDERR_UNSUPPORTED : p++;break; - case DDERR_WASSTILLDRAWING : p++;break; - case DDERR_NOOVERLAYHW : p++;break; - case DDERR_NOTAOVERLAYSURFACE : p++;break; - case DDERR_INVALIDSURFACETYPE : p++;break; - } + switch( hr ) + { + case DDERR_EXCEPTION : p++;break; + case DDERR_GENERIC : p++;break; + case DDERR_INVALIDOBJECT : p++;break; + case DDERR_INVALIDPARAMS : p++;break; + case DDERR_INVALIDRECT : p++;break; + case DDERR_NOBLTHW : p++;break; + case DDERR_SURFACEBUSY : p++;break; + case DDERR_SURFACELOST : p++;break; + case DDERR_UNSUPPORTED : p++;break; + case DDERR_WASSTILLDRAWING : p++;break; + case DDERR_NOOVERLAYHW : p++;break; + case DDERR_NOTAOVERLAYSURFACE : p++;break; + case DDERR_INVALIDSURFACETYPE : p++;break; + } - return p; + return p; } void hb_dd_g_Error( char *, long , char *)