📄 maingame.cpp
字号:
// MainGame.cpp: implementation of the CMainGame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MainGame.h"
#include "MainTitle.h"
#include "ServerConnect.h"
#include "CharSelect.h"
#include "CharMake.h"
#include "GameLoading.h"
#include "GameIn.h"
#include "MapChange.h"
#include "MurimNet.h"
#include "MHTimeManager.h"
#include "mhnetwork.h"
#include "./Engine/Engine.h"
#include "./Interface/cResourceManager.h"
#include "./Interface/cWindowManager.h"
#include "../[CC]Header/GameResourceManager.h"
#include "AppearanceManager.h"
#include "ObjectManager.h"
#include "OptionManager.h"
#include "StringLoader.h"
#include "MovePoint.h"
#include "./Input/cIMEWnd.h"
#include "./Audio/MHAudioManager.h"
#include "mhMap.h"
#include "./Input/UserInput.h"
#include "CQuestManager.h"
#include "MacroManager.h"
#include "MixManager.h"
#include "NpcScriptManager.h"
#include "HelpDicManager.h"
#include "AbilityManager.h"
#include "CheatMsgparser.h"
#include "MouseCursor.h"
#include "ChatManager.h"
#include "ReinforceManager.h"
#ifdef _GMTOOL_
#include "GMToolManager.h"
#endif
#define MAX_PROFILE_NUM 6
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//DWORD _stdcall BeforeRenderFunc();
//DWORD _stdcall AfterRenderFunc();
GLOBALTON(CMainGame);
CMainGame* pTempMainGame = NULL;
HWND gHwnd = NULL;
CMainGame::CMainGame()
{
ASSERT(!pTempMainGame);
m_bChangeState = FALSE;
m_ChangeState = -1;
m_ppGameState = NULL;
m_pCurrentGameState = NULL;
m_pEngine = NULL;
m_bEndGame = FALSE;
m_pStateInitParam = NULL;
pTempMainGame = this;
m_nUserLevel = eUSERLEVEL_USER;
}
CMainGame::~CMainGame()
{
// Release(); //PJH 咯扁辑 角青窍搁 滴锅 Release窍霸 等促
}
void CMainGame::Init(HWND hMainWnd)
{
srand( GetTickCount() );
DIRECTORYMGR->Init();
DIRECTORYMGR->SetLoadMode(eLM_EffectScript);
LoadEffectFileTable("list_m.befl");
DIRECTORYMGR->SetLoadMode(eLM_Root);
m_pEngine = new CEngine;
m_pEngine->Init(hMainWnd,&GAMERESRCMNGR->m_GameDesc.dispInfo,
GAMERESRCMNGR->m_GameDesc.MaxShadowNum,GAMERESRCMNGR->m_GameDesc.MaxShadowTexDetail,0,
GAMERESRCMNGR->m_GameDesc.FramePerSec);
RESRCMGR->Init(FILE_IMAGE_PATH, FILE_IMAGE_MSG);
NETWORK->Init(hMainWnd);
//interface : window manager
WINDOWMGR->Init(); //迄飘, 皋技瘤冠胶 檬扁拳
gHwnd = hMainWnd;
STRINGLOADER->Init(".\\Resource\\string.mhs");
//KES 030828 霸烙牢俊辑 颗败咳
OPTIONMGR->Init(); //可记 皋聪廉, 盲泼皋聪廉绰 弥檬俊?//***
OPTIONMGR->ApplySettings(); //***
LOGFILE("MACROMGR->Init()");
MACROMGR->Init(); //贸澜霸烙 肺爹矫父
MIXMGR->LoadMixList();
REINFORCEMGR->LoadReinforceItemInfo();
// LBS Npc措荤客 Help郴侩 肺靛
LOGFILE("NPCSCRIPTMGR->Init()");
NPCSCRIPTMGR->Init();
LOGFILE("HELPDICMGR->Init()");
HELPDICMGR->Init();
//------------
AUDIOMGR->Initialize( hMainWnd );
// if( !AUDIOMGR->Initialize( hMainWnd ) )
// WINDOWMGR->MsgBox( MBI_VERCHKERROR, 1, "荤款靛 墨靛甫 犬牢窍技夸!!" );
MOVEPOINT->Init();
//DirectInput檬扁拳
g_UserInput.Init();
// EVENT
// CHEATMGR->LoadItem();
}
void CMainGame::Release()
{
MOVEPOINT->Release();
if(m_pCurrentGameState)
{
m_pCurrentGameState->Release(NULL);
m_pCurrentGameState = NULL;
}
EFFECTMGR->Release();
WINDOWMGR->Release();
RESRCMGR->Release();
NETWORK->Release();
// MAP->Release();
if(m_pEngine)
{
m_pEngine->Release();
delete m_pEngine;
m_pEngine = NULL;
}
SAFE_DELETE_ARRAY(m_pStateInitParam);
// SAFE_DELETE(gMp3);
AUDIOMGR->Terminate();
//DirectInputRelease
g_UserInput.Release();
CURSOR->Release();
}
void CMainGame::SetGameState(int StateNum,void* pStateInitParam,int ParamLen)
{
m_bChangeState = TRUE;
m_ChangeState = StateNum;
if(m_ChangeState == eGAMESTATE_END)
{
m_bEndGame = TRUE;
#ifdef _GMTOOL_
GMTOOLMGR->DestroyGMDialog();
#endif
}
//ASSERT(m_pStateInitParam == NULL);
if(pStateInitParam && ParamLen)
{
m_pStateInitParam = new char[ParamLen];
memcpy(m_pStateInitParam,pStateInitParam,ParamLen);
}
}
extern BOOL g_bActiveApp;
int CMainGame::Process()
{
if(g_bActiveApp == FALSE)
Sleep( 10 );
static int sleepcount = 1;
Sleep(sleepcount); //浇赋阑 救林聪 付快胶啊 肋 救框流捞匙.. 1捞扼档 林磊.
if(m_bEndGame)
{
Release();
return -1;
}
MHTIMEMGR->Process();
BeforeRenderFunc();
BOOL rt = m_pEngine->BeginProcess(NULL,AfterRenderFunc);
if(rt)
{
if(m_pCurrentGameState)
{
if(m_pCurrentGameState->IsBlock() == FALSE)
{
//Input Process
g_UserInput.Process();
//Window Process
WINDOWMGR->Process();
m_pCurrentGameState->Process();
}
AUDIOMGR->Process();
}
}
//YH2DO 烙矫 窍靛内爹
if(m_pCurrentGameState == GAMEIN && GAMEIN->IsGameInAcked() == FALSE)
{
g_pExecutive->GetRenderer()->BeginRender(0,0,0);
g_pExecutive->GetRenderer()->EndRender();
}
m_pEngine->EndProcess();
if(m_bChangeState)
{
if(m_pCurrentGameState)
{
m_pCurrentGameState->Release(GetGameState(m_ChangeState));
m_pCurrentGameState->SetBlock(FALSE);
}
m_pCurrentGameState = GetGameState(m_ChangeState);
if(!m_pCurrentGameState) // 辆丰
{
Release(); //KES 030827 眠啊
// GAMEIN->ReleaseForGame();
return -1;
}
m_nCurStateNum = m_ChangeState; //KES 030827 眠啊
CIMEWND->SetDockingEx( NULL, TRUE ); //KES 眠啊.
}
// 橇肺技胶 吝俊 GXObject甫 瘤快芭唱 窍搁 俊矾啊 唱扁锭巩俊 咯扁俊 抵具 窃
// 例措肺 鉴辑 官操瘤 富巴!!!
APPEARANCEMGR->ProcessAppearance();
OBJECTMGR->ProcessGarbage();
if(m_bChangeState)
{
m_pCurrentGameState->SetBlock(FALSE);
if( m_pCurrentGameState->Init(m_pStateInitParam) == FALSE )
{
// MessageBox(0,"Cannot initialize GameState ",0,0);// pjslocal [5/29/2003]
// m_pCurrentGameState = NULL;
// SAFE_DELETE_ARRAY(m_pStateInitParam);
// Release(); // MainGame俊 措茄 Release甫 秦拎具 茄促. LBS 03.11. 26
// return -1;
if( m_nCurStateNum == eGAMESTATE_TITLE ) //maintitle立加阂瓷(distribute绝阑矫)
{
m_pCurrentGameState->SetBlock( FALSE );
TITLE->OnLoginError( LOGIN_ERROR_NODISTRIBUTESERVER, 0 );
}
else
{
MessageBox( 0, CHATMGR->GetChatMsg(444), 0, 0 );
SAFE_DELETE_ARRAY(m_pStateInitParam);
Release(); // MainGame俊 措茄 Release甫 秦拎具 茄促. LBS 03.11. 26
// GAMEIN->ReleaseForGame();
//霸烙捞扼搁 relaseforgame();
return -1;
}
}
SAFE_DELETE_ARRAY(m_pStateInitParam);
m_bChangeState = FALSE;
}
return 0;
}
void CMainGame::BeforeRender()
{
if(m_pCurrentGameState)
m_pCurrentGameState->BeforeRender();
}
void CMainGame::AfterRender()
{
if(m_pCurrentGameState)
m_pCurrentGameState->AfterRender();
}
void CMainGame::PauseRender( BOOL bPause )
{
m_pEngine->PauseRender( bPause);
}
CGameState* CMainGame::GetGameState(int StateNum)
{
CGameState* pState=NULL;
switch(StateNum)
{
case eGAMESTATE_CONNECT:
pState = SERVERCONNECT;
break;
case eGAMESTATE_TITLE:
pState = TITLE;
break;
case eGAMESTATE_CHARSELECT:
pState = CHARSELECT;
break;
case eGAMESTATE_CHARMAKE:
pState = CHARMAKE;
break;
case eGAMESTATE_GAMELOADING:
pState = GAMELOADING;
break;
case eGAMESTATE_GAMEIN:
pState = GAMEIN;
break;
case eGAMESTATE_MAPCHANGE:
pState = MAPCHANGE;
break;
case eGAMESTATE_MURIMNET:
pState = MURIMNET;
break;
case eGAMESTATE_END:
pState = NULL;
break;
default:
break;
}
return pState;
}
DWORD _stdcall BeforeRenderFunc()
{
pTempMainGame->BeforeRender();
return 0;
}
DWORD _stdcall AfterRenderFunc()
{
pTempMainGame->AfterRender();
return 0;
}
DWORD _stdcall AfterRenderFunc__()
{
WINDOWMGR->Render();
return 0;
}
DWORD __stdcall MapLoadCallback(DWORD dwCurCount,DWORD dwTotalCount,void* pArg)
{
// dwCurCount 绰 泅犁 妮归墨款飘捞促.0何磐 矫累茄促.
// dwTotalCount绰 醚 妮归 墨款飘 俺荐捞促.
// ex)
// if (dwCurCount+1 >= dwTotalCount)
// Message(肺靛 肯丰);
// 霸烙 橇肺技胶甫 柳青.
//g_v2Scale.x += 0.01f;
g_pExecutive->Run(0xff000000,NULL,AfterRenderFunc__,0);
// WINDOWMGR->Process();
// 拳搁俊 谎府扁.
g_pExecutive->GetGeometry()->Present(NULL);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -