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

📄 support.cpp

📁 游戏编程精华02-含有几十个游戏编程例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
 * Support.cpp - Support Functions V.2.15.001
 *
 * (c) Copyright 1996-2000 Sabarasa Entertainment
 * For internal use only.
 *********************************************************************/               

/*
	("Abandon all hope, ye who enter here")

						-- Dante. Inferno
*/

#include <dos.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <stdarg.h>

#include "mainptah7.h"

#include "support.hpp"
#include "input.hpp"
#include "blitbuf.hpp"
#include "prim.hpp"
#include "stack.h"

/* ----------------- Globals --------------------- */

LPDIRECTDRAWSURFACE7	vscreen=NULL;			// Back buffer
LPDIRECTDRAWSURFACE7	lpDDSPrimary=NULL;		// DirectDraw primary surface

int PhysicalWidth=PHYSICAL_WIDTH;
int PhysicalHeight=PHYSICAL_HEIGHT;
int PhysicalBPP=PHYSICAL_BPP;

// These variables are set in StorePixelFormat and should be defined
// elsewhere(global, member variable, etc...)
WORD NumberRedBits, NumberGreenBits, NumberBlueBits;
WORD LowRedBit, LowGreenBit, LowBlueBit;
DWORD RBitMask, GBitMask, BBitMask;

/* ---------------- Globales privadas ------------- */

// Last time we called FillTime()
static unsigned long last_fill_time=0;

// DirectDraw Globals
LPDIRECTDRAW7 lpDD=NULL;           // DirectDraw object

/* -------------- Timing Functions --------------- */

void
delay( int time )
{
	Sleep( time );
}

void
FillTime( int interval )
{
	unsigned long a;

	a=GetTickCount();

	if( a<(interval+last_fill_time) )
		Sleep( interval-a+last_fill_time );

	last_fill_time = a;
}

/*------------------------- Interface Functions ----------------------------*/

/* ------------------------ Private ---------------------- */

#define MLANG_ABORTING_DD				1000
#define MLANG_ABORTING_EXCLUSIVE		1001
#define MLANG_ABORTING_VIDEO_MODE		1002
#define MLANG_ABORTING_PRIMARY_SURFACE	1003
#define MLANG_ABORTING_BACKBUFFER		1004
#define MLANG_ABORTING_PIXEL_FORMAT		1005

// Returns a string with the respective language version
char *
mlang_message( int codigo )
{
	// Initialization messages

	if( idioma==0 )	// Castellano
	{
		switch( codigo )
		{
		case MLANG_ABORTING_DD:
			return "No se pudo crear DirectDraw. Abortando.\0";
		case MLANG_ABORTING_EXCLUSIVE:
			return "No se pudo setear modo exclusivo en DirectDraw. Abortando.";
		case MLANG_ABORTING_VIDEO_MODE:
			return "Modo gr醘ico no soportado. Abortando.";
		case MLANG_ABORTING_PRIMARY_SURFACE:
			return "No se pudo crear la superficie primaria. Abortando.";			
		case MLANG_ABORTING_BACKBUFFER:
			return "No se pudo asociar el backbuffer. Abortando.";
		case MLANG_ABORTING_PIXEL_FORMAT:
			return "No se pudo identificar el formato de pixel. Abortando.";
		default:
			return "Codigo de mensaje desconocido.";
		}
	}
	else	// Ingles, Portugues, Chino
	{
		switch( codigo )
		{
		case MLANG_ABORTING_DD:
			return "Couldn't create DirectDraw. Aborting.";
		case MLANG_ABORTING_EXCLUSIVE:
			return "Couldn't set DirectDraw's exclusive mode. Aborting.";
		case MLANG_ABORTING_VIDEO_MODE:
			return "Unsupported graphical mode. Aborting.";
		case MLANG_ABORTING_PRIMARY_SURFACE:
			return "Couldn't create the primary surface. Aborting.";
		case MLANG_ABORTING_BACKBUFFER:
			return "Couldn't create the backbuffer. Aborting.";
		case MLANG_ABORTING_PIXEL_FORMAT:
			return "Couldn't identify the pixel format. Aborting.";
		default:
			return "Unknown message code.";
		}
	}
}

// Returns a DirectDraw error string
char*
ddReturn(HRESULT error)
{
	switch(error)
	{
	case DD_OK:
		return "No error.\0";
	case DDERR_ALREADYINITIALIZED:
		return "This object is already initialized.\0";
	case DDERR_BLTFASTCANTCLIP:
		return "Return if a clipper object is attached to the source surface passed into a BltFast call.\0";
	case DDERR_CANNOTATTACHSURFACE:
		return "This surface can not be attached to the requested surface.\0";
	case DDERR_CANNOTDETACHSURFACE:
		return "This surface can not be detached from the requested surface.\0";
	case DDERR_CANTCREATEDC:
		return "Windows can not create any more DCs.\0";
	case DDERR_CANTDUPLICATE:
		return "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created.\0";
	case DDERR_CANTLOCKSURFACE :
		return "Access to this surface is refused because an attempt was made to lock the primary surface without DCI support. \0";
	case DDERR_CANTPAGELOCK :
		return "An attempt to page-lock a surface failed. Page lock does not work on a display-memory surface or an emulated primary surface. \0";
	case DDERR_CANTPAGEUNLOCK :
		return "An attempt to page-unlock a surface failed. Page unlock does not work on a display-memory surface or an emulated primary surface. \0";
	case DDERR_CLIPPERISUSINGHWND:
		return "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd.\0";
	case DDERR_COLORKEYNOTSET:
		return "No src color key specified for this operation.\0";
	case DDERR_CURRENTLYNOTAVAIL:
		return "Support is currently not available.\0";
	case DDERR_DEVICEDOESNTOWNSURFACE :
		return "Surfaces created by one DirectDraw device cannot be used directly by another DirectDraw device.\0";
	case DDERR_DIRECTDRAWALREADYCREATED :
		return "A DirectDraw object representing this driver has already been created for this process.\0";
	case DDERR_EXCEPTION:
		return "An exception was encountered while performing the requested operation.\0";
	case DDERR_EXCLUSIVEMODEALREADYSET:
		return "An attempt was made to set the cooperative level when it was already set to exclusive.\0";
	case DDERR_EXPIRED :
		return "The data has expired and is therefore no longer valid.\0";
	case DDERR_GENERIC:
		return "Generic failure.\0";
	case DDERR_HEIGHTALIGN:
		return "Height of rectangle provided is not a multiple of reqd alignment.\0";
	case DDERR_HWNDALREADYSET:
		return "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created.\0";
	case DDERR_HWNDSUBCLASSED:
		return "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state.\0";
	case DDERR_IMPLICITLYCREATED:
		return "This surface can not be restored because it is an implicitly created surface.\0";
	case DDERR_INCOMPATIBLEPRIMARY:
		return "Unable to match primary surface creation request with existing primary surface.\0";
	case DDERR_INVALIDCAPS:
		return "One or more of the caps bits passed to the callback are incorrect.\0";
	case DDERR_INVALIDCLIPLIST:
		return "DirectDraw does not support the provided cliplist.\0";
	case DDERR_INVALIDDIRECTDRAWGUID:
		return "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.\0";
	case DDERR_INVALIDMODE:
		return "DirectDraw does not support the requested mode.\0";
	case DDERR_INVALIDOBJECT:
		return "DirectDraw received a pointer that was an invalid DIRECTDRAW object.\0";
	case DDERR_INVALIDPARAMS:
		return "One or more of the parameters passed to the function are incorrect.\0";
	case DDERR_INVALIDPIXELFORMAT:
		return "The pixel format was invalid as specified.\0";
	case DDERR_INVALIDPOSITION:
		return "Returned when the position of the overlay on the destination is no longer legal for that destination.\0";
	case DDERR_INVALIDRECT:
		return "Rectangle provided was invalid.\0";
	case DDERR_INVALIDSTREAM :
		return "The specified stream contains invalid data. \0";
	case DDERR_INVALIDSURFACETYPE :
		return "The requested operation could not be performed because the surface was of the wrong type.\0";
	case DDERR_LOCKEDSURFACES:
		return "Operation could not be carried out because one or more surfaces are locked.\0";
	case DDERR_MOREDATA :
		return "There is more data available than the specified buffer size can hold.\0";
	case DDERR_NO3D:
		return "There is no 3D present.\0";
	case DDERR_NOALPHAHW:
		return "Operation could not be carried out because there is no alpha accleration hardware present or available.\0";
	case DDERR_NOBLTHW:
		return "No blitter hardware present.\0";
	case DDERR_NOCLIPLIST:
		return "No cliplist available.\0";
	case DDERR_NOCLIPPERATTACHED:
		return "No clipper object attached to surface object.\0";
	case DDERR_NOCOLORCONVHW:
		return "Operation could not be carried out because there is no color conversion hardware present or available.\0";
	case DDERR_NOCOLORKEY:
		return "Surface doesn't currently have a color key\0";
	case DDERR_NOCOLORKEYHW:
		return "Operation could not be carried out because there is no hardware support of the destination color key.\0";
	case DDERR_NOCOOPERATIVELEVELSET:
		return "Create function called without DirectDraw object method SetCooperativeLevel being called.\0";
	case DDERR_NODC:
		return "No DC was ever created for this surface.\0";
	case DDERR_NODDROPSHW:
		return "No DirectDraw ROP hardware.\0";
	case DDERR_NODIRECTDRAWHW:
		return "A hardware-only DirectDraw object creation was attempted but the driver did not support any hardware.\0";
	case DDERR_NOEMULATION:
		return "Software emulation not available.\0";
	case DDERR_NOEXCLUSIVEMODE:
		return "Operation requires the application to have exclusive mode but the application does not have exclusive mode.\0";
	case DDERR_NOFLIPHW:
		return "Flipping visible surfaces is not supported.\0";
	case DDERR_NOFOCUSWINDOW :
		return "An attempt was made to create or set a device window without first setting the focus window.\0";
	case DDERR_NOGDI:
		return "There is no GDI present.\0";
	case DDERR_NOHWND:
		return "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND.\0";
	case DDERR_NOMIPMAPHW :
		return "No mipmap-capable texture mapping hardware is present or available. \0";
	case DDERR_NOMIRRORHW:
		return "Operation could not be carried out because there is no hardware present or available.\0";
	case DDERR_NONONLOCALVIDMEM :
		return "An attempt was made to allocate nonlocal video memory from a device that does not support nonlocal video memory. \0";
	case DDERR_NOOPTIMIZEHW :
		return "The device does not support optimized surfaces. \0";
	case DDERR_NOOVERLAYDEST:
		return "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on to establish a destination.\0";
	case DDERR_NOOVERLAYHW:
		return "Operation could not be carried out because there is no overlay hardware present or available.\0";
	case DDERR_NOPALETTEATTACHED:
		return "No palette object attached to this surface.\0";
	case DDERR_NOPALETTEHW:
		return "No hardware support for 16 or 256 color palettes.\0";
	case DDERR_NORASTEROPHW:
		return "Operation could not be carried out because there is no appropriate raster op hardware present or available.\0";
	case DDERR_NOROTATIONHW:
		return "Operation could not be carried out because there is no rotation hardware present or available.\0";
	case DDERR_NOSTEREOHARDWARE :
		return "No stereo hardware is present or available.\0";
	case DDERR_NOSTRETCHHW:
		return "Operation could not be carried out because there is no hardware support for stretching.\0";
	case DDERR_NOSURFACELEFT :
		return "No hardware is present that supports stereo surfaces. \0";
	case DDERR_NOT4BITCOLOR:
		return "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette.\0";
	case DDERR_NOT4BITCOLORINDEX:
		return "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette.\0";
	case DDERR_NOT8BITCOLOR:
		return "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color.\0";
	case DDERR_NOTAOVERLAYSURFACE:
		return "Returned when an overlay member is called for a non-overlay surface.\0";
	case DDERR_NOTEXTUREHW:
		return "Operation could not be carried out because there is no texture mapping hardware present or available.\0";
	case DDERR_NOTFLIPPABLE:
		return "An attempt has been made to flip a surface that is not flippable.\0";
	case DDERR_NOTFOUND:
		return "Requested item was not found.\0";
	case DDERR_NOTLOCKED:
		return "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this process, has been attempted.\0";
	case DDERR_NOTPAGELOCKED :
		return "An attempt was made to page-unlock a surface with no outstanding page locks. \0";
	case DDERR_NOTPALETTIZED:
		return "The surface being used is not a palette-based surface.\0";
	case DDERR_NOVSYNCHW:
		return "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations.\0";
	case DDERR_NOZBUFFERHW:
		return "Operation could not be carried out because there is no hardware support for zbuffer blitting.\0";
	case DDERR_NOZOVERLAYHW:
		return "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays.\0";
	case DDERR_OUTOFCAPS:
		return "The hardware needed for the requested operation has already been allocated.\0";
	case DDERR_OUTOFMEMORY:
		return "DirectDraw does not have enough memory to perform the operation.\0";
	case DDERR_OUTOFVIDEOMEMORY:
		return "DirectDraw does not have enough memory to perform the operation.\0";
	case DDERR_OVERLAPPINGRECTS :
		return "The source and destination rectangles are on the same surface and overlap each other. \0";
	case DDERR_OVERLAYCANTCLIP:
		return "The hardware does not support clipped overlays.\0";
	case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
		return "Can only have ony color key active at one time for overlays.\0";
	case DDERR_OVERLAYNOTVISIBLE:
		return "Returned when GetOverlayPosition is called on a hidden overlay.\0";
	case DDERR_PALETTEBUSY:
		return "Access to this palette is being refused because the palette is already locked by another thread.\0";
	case DDERR_PRIMARYSURFACEALREADYEXISTS:
		return "This process already has created a primary surface.\0";

⌨️ 快捷键说明

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