#include "pch.h"
HRESULT EngineApp::Initialize(const ZString& strCommandLine)
{
FreeImage_Initialise();
Pane::Initialize();
bool bSoftwareOnly;
bool bPrimaryOnly;
DWORD dwBPP = 0; ParseCommandLine(strCommandLine, bSoftwareOnly, bPrimaryOnly, dwBPP);
m_pengine = CreateEngine(!bSoftwareOnly, !bPrimaryOnly, dwBPP);
if (!m_pengine->IsValid()) {
return E_FAIL;
}
m_pmodeler = Modeler::Create(m_pengine);
m_ppopupContainer = CreatePopupContainer();
return S_OK;
}
void EngineApp::Terminate()
{
if (m_pmodeler)
m_pmodeler->Terminate();
if (m_pengine)
m_pengine->Terminate();
m_pmodeler = NULL;
m_pengine = NULL;
FreeImage_DeInitialise();
Win32App::Terminate();
}
void EngineApp::ParseCommandLine(
const ZString& strCommandLine,
bool& bSoftwareOnly,
bool& bPrimaryOnly,
DWORD& dwBPP
) {
bPrimaryOnly = false;
bSoftwareOnly = false;
PCC pcc = strCommandLine;
CommandLineToken token(pcc, strCommandLine.GetLength());
while (token.MoreTokens()) {
ZString str;
if (token.IsMinus(str)) {
if (str == "primary") {
bPrimaryOnly = true;
} else if (str == "software") {
bSoftwareOnly = true;
}
if (str == "32b") {
dwBPP = 32;
}
else if (str == "16b") {
dwBPP = 16;
}
} else {
token.IsString(str);
}
}
}
void EngineApp::SetMouse(MouseInputStream* pmouse)
{
m_pmouse = pmouse;
}
int EngineApp::OnException(DWORD code, ExceptionData* pdata)
{
if (m_pengine && m_pengine->IsFullscreen()) {
m_pengine->DebugSetWindowed();
if (m_pmouse) {
m_pmouse->SetEnabled(false);
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
#ifdef _DEBUG
bool EngineApp::OnAssert(const char* psz, const char* pszFile, int line, const char* pszModule)
{
OnException(0, NULL);
return Win32App::OnAssert(psz, pszFile, line, pszModule);
}
#endif