⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 support.cpp

📁 游戏编程精华02-含有几十个游戏编程例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	case DDERR_REGIONTOOSMALL:
		return "Region passed to Clipper::GetClipList is too small.\0";
	case DDERR_SURFACEALREADYATTACHED:
		return "This surface is already attached to the surface it is being attached to.\0";
	case DDERR_SURFACEALREADYDEPENDENT:
		return "This surface is already a dependency of the surface it is being made a dependency of.\0";
	case DDERR_SURFACEBUSY:
		return "Access to this surface is being refused because the surface is already locked by another thread.\0";
	case DDERR_SURFACEISOBSCURED:
		return "Access to surface refused because the surface is obscured.\0";
	case DDERR_SURFACELOST:
		return "Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have Restore called on it.\0";
	case DDERR_SURFACENOTATTACHED:
		return "The requested surface is not attached.\0";
	case DDERR_TOOBIGHEIGHT:
		return "Height requested by DirectDraw is too large.\0";
	case DDERR_TOOBIGSIZE:
		return "Size requested by DirectDraw is too large, but the individual height and width are OK.\0";
	case DDERR_TOOBIGWIDTH:
		return "Width requested by DirectDraw is too large.\0";
	case DDERR_UNSUPPORTED:
		return "Action not supported.\0";
	case DDERR_UNSUPPORTEDFORMAT:
		return "FOURCC format requested is unsupported by DirectDraw.\0";
	case DDERR_UNSUPPORTEDMASK:
		return "Bitmask in the pixel format requested is unsupported by DirectDraw.\0";
	case DDERR_VERTICALBLANKINPROGRESS:
		return "Vertical blank is in progress.\0";
	case DDERR_VIDEONOTACTIVE :
		return "The video port is not active. \0";
	case DDERR_WASSTILLDRAWING:
		return "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete.\0";
	case DDERR_WRONGMODE:
		return "This surface can not be restored because it was created in a different mode.\0";
	case DDERR_XALIGN:
		return "Rectangle provided was not horizontally aligned on required boundary.\0";
	default:
		return "Unrecognized error value.\0";
	}
}

// Small utility function to find the LowBit and Number of Bits in a supplied Mask
void
ProcessBits( DWORD Mask, WORD* LowBit, WORD* NumBits )
{
   DWORD TestMask = 1;
   for( *LowBit = 0; *LowBit < 32; ( *LowBit )++ )
   {
      if( Mask & TestMask )
         break;
      TestMask <<= 1;
   }

   TestMask <<= 1;
   for( *NumBits = 1; *NumBits < 32; ( *NumBits )++ )
   {
      if( !( Mask & TestMask ))
         break;
      TestMask <<= 1;
   }
}

// Guarda en las globales correspondientes, el Pixel Format
BOOL
StorePixelFormat()
{
   // Define a PixelFormat variable, clear it and set the dwSize variable, as usual.
   DDPIXELFORMAT DDPixelFormat;
   ZeroMemory( &DDPixelFormat, sizeof( DDPixelFormat ));
   DDPixelFormat.dwSize = sizeof( DDPixelFormat );

   // Fill the PixelFormat from the information for the Primary Surface
   if( FAILED( lpDDSPrimary->GetPixelFormat( &DDPixelFormat)))
   {
      // Fatal error. The program should exit nicely
      return FALSE;
   }

   // Salvo los masks
   RBitMask=DDPixelFormat.dwRBitMask;
   GBitMask=DDPixelFormat.dwGBitMask;
   BBitMask=DDPixelFormat.dwBBitMask;

   // Save the Low Bit and Number of Bits
   ProcessBits( DDPixelFormat.dwRBitMask, &LowRedBit, &NumberRedBits);
   ProcessBits( DDPixelFormat.dwGBitMask, &LowGreenBit, &NumberGreenBits);
   ProcessBits( DDPixelFormat.dwBBitMask, &LowBlueBit, &NumberBlueBits);

   fplog( "\nPixel Format:\nRed:\t%d %d\nGreen:\t%d %d\nBlue:\t%d %d\n\n",
	   LowRedBit, NumberRedBits, LowGreenBit, NumberGreenBits, LowBlueBit, NumberBlueBits);
  
   return TRUE;
}

/* Flips la main surface with the backbuffer */

void
FlipSurfaces(void)
{
    HRESULT ddrval;

	// Si la ejecucion esta suspendida, espero hasta que se reactive
	WaitForSingleObject(task_wakeup_event, INFINITE);

	// dibujo la pantalla
	ddrval = lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );

	if( ddrval == DDERR_SURFACELOST )
		fplog("Primary Surface Lost!\n" );
}

/* ----------------------- Publicas ---------------------- */

/* Initialize video system */
int
initVideoSystem(int width, int height, int bpp)
{
    DDSURFACEDESC2		ddsd;
    DDSCAPS2			ddscaps;
    HRESULT             ddrval;
	DDCAPS				ddCaps;

	/*
     * create the main DirectDraw object
     */
    ddrval = DirectDrawCreateEx( NULL, (void **) &lpDD, IID_IDirectDraw7, NULL );
    if( ddrval != DD_OK )
    {
		// "No se pudo crear DirectDraw. Abortando."
		return initFail(hwnd, mlang_message( MLANG_ABORTING_DD ) );
    }

	// Get DirectDraw HAL capabilities
	ddCaps.dwSize=sizeof(ddCaps);
	lpDD->GetCaps( &ddCaps, NULL );

	// Soporte de aceleracion 3d
	if( ddCaps.dwCaps & DDCAPS_3D )
		fplog( "HAL: Soporta aceleracion 3d\n" );
	else
		fplog( "HAL: No soporta aceleracion 3d\n" );

	// Soporte de alpha-only textures
	if( ddCaps.dwCaps & DDCAPS_ALPHA )
		fplog( "HAL: Soporta alpha-only textures\n" );
	else
		fplog( "HAL: No soporta alpha-only textures\n" );

    // Get exclusive mode
    ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_MULTITHREADED );
    if( ddrval != DD_OK )
    {
		// "No se pudo setear modo exclusivo. Abortando."
		return initFail(hwnd, mlang_message( MLANG_ABORTING_EXCLUSIVE ) );
    }

    // Set the video mode
	ddrval = lpDD->SetDisplayMode( width, height, bpp*8, 0, 0 );
    if( ddrval != DD_OK )
    {
		// "Modo gr醘ico no soportado. Abortando."
		return initFail(hwnd, mlang_message( MLANG_ABORTING_VIDEO_MODE ) ); 
    }

    // Create the primary surface with 1 back buffer
	ZeroMemory( &ddsd, sizeof( ddsd ) );
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
			  DDSCAPS_FLIP |
			  DDSCAPS_COMPLEX |
			  DDSCAPS_3DDEVICE;
    ddsd.dwBackBufferCount = 1;
    ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
    if( ddrval != DD_OK )
    {
		// "No se pudo crear la superficie primaria. Abortando."
		return initFail(hwnd, mlang_message( MLANG_ABORTING_PRIMARY_SURFACE ) );
    }

	// Create the backbuffer
	ZeroMemory( &ddscaps, sizeof( ddscaps ) );
    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &vscreen);
    if( ddrval != DD_OK )
    {
		// "No se pudo asociar el backbuffer. Abortando."
		return initFail(hwnd, mlang_message( MLANG_ABORTING_BACKBUFFER ) );
    }

	// Set pixel format globals
	if( FAILED(StorePixelFormat() ) )
	{
		// "No se pudo identificar el formato de pixel. Abortando." 
		return initFail(hwnd, mlang_message( MLANG_ABORTING_PIXEL_FORMAT) );
	}

	// Check primary display capabilities

	// Veo cuanta vidmem tengo
	unsigned long dwTotal, dwFree;

	ZeroMemory( &ddscaps, sizeof( ddscaps ) );
	ddscaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY |
					DDSCAPS_LOCALVIDMEM;

	lpDD->GetAvailableVidMem( &ddscaps, &dwTotal, &dwFree );

	fplog( "Vidmem Total: %ld, Free: %ld\n", dwTotal, dwFree );
	
	// Clear v_vscreen
	FillScreen( Make16(0,0,0));
	display_vscreen();

	return 0;
}

/* Uninit the video system */

void
unInitVideoSystem(void)
{
    HRESULT ddrval;

	fplog( "INI unInitVideoSystem\n" );
	
	// Close DirectDraw
	if( lpDD != NULL )
    {
		// Set non-exclusive mode for display 
		ddrval=lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
		fplog( "SetCooperativeLevel %s\n", ddReturn( ddrval ) );

		// Set previous display mode
		ddrval=lpDD->RestoreDisplayMode();
		fplog( "RestoreDisplayMode %s\n", ddReturn( ddrval ) );

		// Make our exit elegant
		lpDD->FlipToGDISurface(); 

		if( lpDDSPrimary != NULL )
		{
			lpDDSPrimary->Release();
			lpDDSPrimary = NULL;
		}

		lpDD->Release();
		lpDD = NULL;
    }

	fplog( "END unInitVideoSystem\n" );
}

/*
 * restoreAll
 *
 * restore all vidmem lost objects
 */
int
restoreAll( void )
{
	int iRet;
	int i;
	int n;
	CallbackT Cback;

	iRet = (int) lpDD->RestoreAllSurfaces();

	// Reload all graphics that must be reload
	fplog( "Recargo graficos\n" );

	n = gReloadSurfacesStack.StackDepth();
	for( i=n-1; i>=0; i-- )
	{
		gReloadSurfacesStack.GetStackElement( i, &Cback );

		(* (void (*)(void *))Cback.func)( Cback.data );
	}

	fplog( "fin Recargo graficos\n" );

	return iRet;
}

/* WaitRetrace (not used) */

void
WaitRetrace()
{
	lpDD->WaitForVerticalBlank( DDWAITVB_BLOCKBEGIN, NULL );
}

/* This copies a window of the vscreen to the screen. */

int
display_vscreen( int frame_duration )
{
	// Wait to fill in time
	FillTime( frame_duration );

	// Flip the backbuffer
    FlipSurfaces();

	return 0;
}

/* Copies into vscreen the primary surface contents */

void
restore_vscreen(void)
{
	vscreen->BltFast( 0, 0, lpDDSPrimary, NULL, DDBLTFAST_WAIT );
}

/* -------------- Etc Functions --------------- */

// Not enough memory function - only fatal errors
void
chau( void )
{
	fplog( "Error, not enough memory.\n" );
	exit(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -