?? mainfrm.cpp
字號:
//if sound initialization has already failed in InitSfx(), then we want the ships'
//sound buffers to be NULL so that we don't try to release them later.
for (i=0; i<MAX_SOUNDS; i++)
{
lpDirectSoundBuffer [i] = NULL;
lpDirectSound3DBuffer[i] = NULL;
}
}
}
/*
* This function is called if the initialization function fails
*/
extern BOOL initFail(LPCTSTR msg )
{ finiGlob();
finiObjects();
MessageBox(hWindow, msg,"AntiWar", MB_OK );
DestroyWindow( hWindow );
return FALSE;
} /* initFail */
static void finiGlob(void)
{ if( lpDD != NULL )
{
if( lpDDSPrimary != NULL )
{
lpDDSPrimary->Release();
lpDDSPrimary = NULL;
}
if( lpDDSBack != NULL )
{
lpDDSBack->Release();
lpDDSBack = NULL;
}
if(lpGround!=NULL)
{lpGround->Release();
lpGround=NULL;
}
lpDD->Release();
lpDD = NULL;
}
}
static void finiObjects( void )
{int i;
{
for(i=0;i<FLOORNUM;i++)
{ if(Floor[i] != NULL )
{
Floor[i]->Release();
Floor[i] = NULL;
}
}
for(i=0;i<BUILDNUM;i++)
{ if(Build[i] != NULL )
{
Build[i]->Release();
Build[i] = NULL;
}
}
for(i=0;i<MYARMYNUM;i++)
{ if(Myarmy[i] != NULL )
{
Myarmy[i]->Release();
Myarmy[i] = NULL;
}
}
for(i=0;i<ARMYNUM;i++)
{ if(Army[i] != NULL )
{
Army[i]->Release();
Army[i] = NULL;
}
}
for(i=0;i<ENEMYNUM;i++)
{ if(Enemy[i] != NULL )
{
Enemy[i]->Release();
Enemy[i] = NULL;
}
}
for(i=0;i<EXPNUM;i++)
{ if(PicExp[i] != NULL )
{
PicExp[i]->Release();
PicExp[i] = NULL;
}
}
for(i=0;i<OTHERSNUM;i++)
{ if(Others[i] != NULL )
{
Others[i]->Release();
Others[i] = NULL;
}
}
for(i=0;i<BULLETNUM;i++)
{ if(PicBullet[i] != NULL )
{
PicBullet[i]->Release();
PicBullet[i] = NULL;
}
}
for(i=0;i<TREENUM;i++)
{ if(PicTree[i] != NULL )
{
PicTree[i]->Release();
PicTree[i] = NULL;
}
}
if(PicRect!=NULL)
{PicRect->Release();
PicRect=NULL;
}
/*if(PicShape!=NULL)
{PicShape->Release();
PicShape=NULL;
}*/
if(PicBlack!=NULL)
{PicBlack->Release();
PicBlack=NULL;
}
if(PicWhite!=NULL)
{PicWhite->Release();
PicWhite=NULL;
}
}
} /* finiObjects */
void EndPlay()
{/*myarmy *Ob;
Building *B;
Ob=firstsoldier;
do {
if(Ob->Next==NULL){if(Ob!=firstsoldier)Ob->Free();break;}
Ob=Ob->Next;
if(Ob->Prev!=firstsoldier)
Ob->Prev->Free();
}while(Ob);
B=firstbuild;
do {
if(B->Next==NULL){if(B!=firstbuild)B->Free();break;}
B=B->Next;
if(B->Prev!=firstbuild)
B->Prev->Free();
}while(B);
*/
CleanupSfx();
}
void Flip(void)
{ HRESULT ddrval;
// Flip the surfaces
while( 1 )
{
ddrval = lpDDSPrimary->Flip( NULL, 0 );
if( ddrval == DD_OK )
{
break;
}
if( ddrval == DDERR_SURFACELOST )
{
ddrval = restoreAll();
if( ddrval != DD_OK )
{
break;
}
}
if( ddrval != DDERR_WASSTILLDRAWING )
{
break;
}
}
}
void BltSplash(void)
{char File[32];
LPDIRECTDRAWSURFACE lpSplash;
sprintf(File,"bmp\\splash%d.bmp",0);
lpSplash=DDLoadBitmap(lpDD,File,0,0);
//DDSetColorKey(Floor[i],CLR_INVALID);
if(lpSplash==NULL)
initFail(NULL);
else {JFBlt(lpDDSBack, 0, 0, 640,480,lpSplash,0,0,
DDBLTFAST_NOCOLORKEY );
Flip();
if(lpSplash!=NULL)
{lpSplash->Release();
lpSplash=NULL;
}
}
}
int ProcessKeys(void)
{switch(gwKeys )
{case VK_F5:
if(ProgramState==GETSELECT)
return ALONE;
break;
case VK_F6:
if(ProgramState==GETSELECT)
return MUD;
break;
}
return ProgramState;
}
void InitAloneGame(void)
{InitGame();
}
/*
* ReceiveGameMessages
*
* Checks if there are any messages for us and receives them
*/
/*HRESULT ReceiveMessages( void )
{
DPID idFrom, idTo;
LPVOID lpvMsgBuffer;
DWORD dwMsgBufferSize;
HRESULT hr;
// read all messages in queue
dwMsgBufferSize = gdwReceiveBufferSize;
lpvMsgBuffer = glpvReceiveBuffer;
while (TRUE)
{
// see what's out there
idFrom = 0;
idTo = 0;
hr = DPlayReceive(&idFrom, &idTo, DPRECEIVE_ALL, lpvMsgBuffer, &dwMsgBufferSize);
if (hr == DPERR_BUFFERTOOSMALL)
{
if (lpvMsgBuffer == NULL)
{
lpvMsgBuffer = GlobalAllocPtr(GHND, dwMsgBufferSize);
if (lpvMsgBuffer == NULL)
return (DPERR_NOMEMORY);
glpvReceiveBuffer = lpvMsgBuffer;
gdwReceiveBufferSize = dwMsgBufferSize;
}
else if (dwMsgBufferSize > gdwReceiveBufferSize)
{
lpvMsgBuffer = GlobalReAllocPtr(lpvMsgBuffer, dwMsgBufferSize, 0);
if (lpvMsgBuffer == NULL)
return (DPERR_NOMEMORY);
glpvReceiveBuffer = lpvMsgBuffer;
gdwReceiveBufferSize = dwMsgBufferSize;
}
}
else if ((hr == DP_OK) &&
((dwMsgBufferSize >= sizeof(GENERICMSG)) ||
(dwMsgBufferSize >= sizeof(DPMSG_GENERIC))))
{
if (idFrom == DPID_SYSMSG)
{
//DoSystemMessage((LPDPMSG_GENERIC) lpvMsgBuffer, dwMsgBufferSize, idFrom, idTo);
}
else
{
//DoApplicationMessage((LPGENERICMSG) lpvMsgBuffer, dwMsgBufferSize, idFrom, idTo);
}
}
else
break;
};
return hr;
}
*/
/*
* DoSystemMessage
*
* Evaluates system messages and performs appropriate actions
*/
/*void DoSystemMessage( LPDPMSG_GENERIC lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo )
{
switch( lpMsg->dwType)
{
case DPSYS_CREATEPLAYERORGROUP:
{
LPDPMSG_CREATEPLAYERORGROUP lpAddMsg = (LPDPMSG_CREATEPLAYERORGROUP) lpMsg;
if( gbIsHost)
{
gHostMsg.GameType = gGameType;
SendGameMessage((LPGENERICMSG) &gHostMsg, lpAddMsg->dpId);
}
}
break;
case DPSYS_DESTROYPLAYERORGROUP:
{
// LPSHIP lpShip;
LPDPMSG_DESTROYPLAYERORGROUP lpDestroyMsg = (LPDPMSG_DESTROYPLAYERORGROUP) lpMsg;
//if ((sizeof(SHIP) != lpDestroyMsg->dwLocalDataSize) ||
// (NULL == lpDestroyMsg->lpLocalData))
// break;
//lpShip = lpDestroyMsg->lpLocalData;
// ReleasePlayerLocalSoundData(lpShip);
}
break;
case DPSYS_HOST:
{
gbIsHost = TRUE;
//UpdateTitle();//do info
}
break;
case DPSYS_SESSIONLOST:
// inform user that session was lost
initFail("IDS_DPLAY_ERROR_SL");
gbSessionLost = TRUE;
break;
}
}
*/
/*
* DoApplicationMessage
*
* Evaluates an application message and performs appropriate actions
*/
/*void DoApplicationMessage( LPGENERICMSG lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo )
{
// HRESULT hr;
switch( lpMsg->byType )
{
case MSG_HOST:
{
LPHOSTMSG lpHost;
if( !gbIsHost )
{
lpHost = (LPHOSTMSG) lpMsg;
// receive the field layout
gGameType = lpHost->GameType;
// have host initializtion at this point
gbHaveHostInit = TRUE;
// start updating screen
gbIsActive = TRUE;
}
}
break;
case MSG_BUILD:
break;
case MSG_FIRE:
break;
case MSG_MOVE:
break;
case MSG_CALLFIX:
break;
case MSG_TALK:
break;
default:
{
initFail("Unknown message type" );
}
break;
}
}
*/
/*
* SendGameMessage
*
* Sends a message to specified player(s)
*/
/*void SendGameMessage( LPGENERICMSG lpMsg, DPID idTo )
{
int nBytes;
DWORD dwFlags = 0;
if (gbSessionLost)
{
// no sends when we are not in the session
return;
}
switch( lpMsg->byType )
{
case MSG_HOST:
nBytes = sizeof( HOSTMSG );
dwFlags = DPSEND_GUARANTEED;
break;
case MSG_BUILD:
//nBytes = sizeof( BUILDMSG );
break;
case MSG_FIRE:
//nBytes = sizeof( FIREMSG );
break;
case MSG_MOVE:
//nBytes = sizeof( MOVEMSG );
break;
case MSG_CALLFIX:
// nBytes = sizeof( CALLFIXMSG );
break;
case MSG_TALK:
//nBytes = sizeof( TALKMSG );
break;
default:
return;
}
if (gbReliable)
{
dwFlags = DPSEND_GUARANTEED;
}
// Send the message to the relevant player(s)
DPlaySend(gOurID, idTo, dwFlags, (LPVOID)lpMsg, nBytes);
}
*/
/*
* LaunchedByLobby
*
* Determines if we were launched by a lobby. If so, gets the connection settings
* and creates our player using the information from the lobby
*/
BOOL LaunchedByLobby(void)
{
HRESULT hr;
HWND hwndStatus;
// create a lobby object
hr = DPLobbyCreate();
if (FAILED(hr))
{
initFail("IDS_DPLOBBY_ERROR_C");
return FALSE;
}
// get connection settings from the lobby (into glpdplConnection)
hr = DPLobbyGetConnectionSettings();
if (FAILED(hr))
{
if (DPERR_NOTLOBBIED == hr)
{
// we were not lobbied - start up game normally
hr = DPLobbyRelease();
if (FAILED(hr))
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -