void *SurfaceLock (LPDIRECTDRAWSURFACE7 pSurface, DDSURFACEDESC2 *retpDesc) // SurfaceLock // // Locks the given surface and returns a pointer to it { HRESULT hr; DDSURFACEDESC2 desc; if (retpDesc == NULL) retpDesc = &desc; // Lock the surface int iMaxCount = 10; while (iMaxCount-- > 0) { retpDesc->dwSize = sizeof(desc); hr = pSurface->Lock(NULL, retpDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); // Return the pointer if successful if (hr == DD_OK) return (void *)retpDesc->lpSurface; // Restore the surface if necessary else if (hr == DDERR_SURFACELOST) { hr = pSurface->Restore(); ::Sleep(500); if (FAILED(hr)) kernelDebugLogMessage("Surface restore failed: %x", hr); } // Fail with an error otherwise else { kernelDebugLogMessage("Lock failed: %x", hr); return NULL; } } // If we've tried 10 times (5 seconds) and still nothing, then we give up kernelDebugLogMessage("Unable to lock surface"); return NULL; }
void CDesignCollection::FireOnGlobalPaneInit (void *pScreen, CDesignType *pRoot, const CString &sScreen, const CString &sPane) // FireOnGlobalPaneInit // // Give other design types a way to override screens { int i; CString sError; // Generate a screen UNID that contains both the screen UNID and a local screen CString sScreenUNID = CDockScreenType::GetStringUNID(pRoot, sScreen); DWORD dwRootUNID = (pRoot ? pRoot->GetUNID() : 0); // Fire all events for (i = 0; i < m_EventsCache[evtOnGlobalDockPaneInit]->GetCount(); i++) { SEventHandlerDesc Event; CDesignType *pType = m_EventsCache[evtOnGlobalDockPaneInit]->GetEntry(i, &Event); if (pType->FireOnGlobalDockPaneInit(Event, pScreen, dwRootUNID, sScreenUNID, sPane, &sError) != NOERROR) kernelDebugLogMessage("%s", sError.GetASCIIZPointer()); } }
void CHumanInterface::HardCrash (const CString &sProgramState) // HardCrash // // Report an error { CString sSessionMessage; try { if (m_pCurSession) m_pCurSession->HIReportHardCrash(&sSessionMessage); } catch (...) { sSessionMessage = CONSTLIT("Unable to obtain crash report from session."); } CString sMessage = strPatternSubst(CONSTLIT( "Unable to continue due to program error.\r\n\r\n" "program state: %s\r\n" "%s" "\r\n\r\nPlease contact [email protected] with a copy of Debug.log and your save file. " "We are sorry for the inconvenience.\r\n"), sProgramState, sSessionMessage ); kernelDebugLogMessage(sMessage.GetASCIIZPointer()); ShowHardCrashSession(CONSTLIT("Transcendence System Crash"), sMessage); }
void InitTrig (void) // InitTrig // // Initializes sine and cosine tables { if (!g_bTrigInit) { for (int i = 0; i < 360; i++) { Metric rRadian = 2 * g_Pi * i / 360; g_Sine[i] = sin(rRadian); g_Cosine[i] = cos(rRadian); } g_bTrigInit = true; } #if 0 for (int i = 0; i < 360; i++) { CVector vTest = PolarToVector(i, 100); kernelDebugLogMessage("Angle %d = (%d,%d) = %d", i, (int)vTest.GetX(), (int)vTest.GetY(), VectorToPolar(vTest, NULL)); } #endif }
ICCItem *CCPrimitive::Execute (CEvalContext *pCtx, ICCItem *pArgs) // Execute // // Executes the function and returns a result { bool bCustomArgEval = ((m_dwFlags & PPFLAG_CUSTOM_ARG_EVAL) ? true : false); // Evaluate args, if necessary ICCItem *pEvalArgs; if (!bCustomArgEval) { pEvalArgs = pCtx->pCC->EvaluateArgs(pCtx, pArgs, m_sArgPattern); if (pEvalArgs->IsError()) return pEvalArgs; } else pEvalArgs = pArgs; // Invoke the function ICCItem *pResult; bool bReportError = false; try { pResult = m_pfFunction(pCtx, pEvalArgs, m_dwData); } catch (...) { bReportError = true; } // Report error if (bReportError) { CString sArgs; try { sArgs = pEvalArgs->Print(pCtx->pCC); } catch (...) { sArgs = CONSTLIT("[invalid arg item]"); } CString sError = strPatternSubst(CONSTLIT("Exception in %s; arg = %s"), m_sName, sArgs); pResult = pCtx->pCC->CreateError(sError, pEvalArgs); kernelDebugLogMessage(sError.GetASCIIZPointer()); } // Done if (!bCustomArgEval) pEvalArgs->Discard(pCtx->pCC); return pResult; }
void CTranscendenceWnd::PaintFrameRate (void) // PaintFrameRate // // Paints the frame rate { int i; CG16bitImage &TheScreen = g_pHI->GetScreen(); if (m_iStartAnimation == 0) m_iStartAnimation = GetTickCount(); else { // Figure out how much time has elapsed since the last frame int iNow = GetTickCount(); m_iFrameTime[m_iFrameCount % FRAME_RATE_COUNT] = iNow - m_iStartAnimation; // Add up all the times int iTotalFrameTime = 0; int iTotalPaintTime = 0; int iTotalBltTime = 0; int iTotalUpdateTime = 0; for (i = 0; i < FRAME_RATE_COUNT; i++) { iTotalFrameTime += m_iFrameTime[i]; iTotalPaintTime += m_iPaintTime[i]; iTotalBltTime += m_iBltTime[i]; iTotalUpdateTime += m_iUpdateTime[i]; } // Compute the frame rate (in 10ths of frames) int rFrameRate = 0; if (iTotalFrameTime > 0) rFrameRate = 10000 * FRAME_RATE_COUNT / iTotalFrameTime; char szBuffer[256]; int iLen = wsprintf(szBuffer, "Frames: %d Paint: %d Blt: %d Update: %d", rFrameRate / 10, iTotalPaintTime / FRAME_RATE_COUNT, iTotalBltTime / FRAME_RATE_COUNT, iTotalUpdateTime / FRAME_RATE_COUNT); TheScreen.DrawText(300, 0, m_Fonts.Header, CG16bitImage::RGBValue(80,80,80), CString(szBuffer, iLen)); // Every once in a while, output to log file if (m_iFrameCount > FRAME_RATE_COUNT && ((m_iFrameCount % 300) == 0)) kernelDebugLogMessage(szBuffer); // Next m_iFrameCount++; m_iStartAnimation = iNow; } }
void CAscendedObjectList::WriteToStream (IWriteStream *pStream) // WriteToStream // // Write { int i; DWORD dwCount = m_List.GetCount(); pStream->Write((char *)&dwCount, sizeof(DWORD)); for (i = 0; i < (int)dwCount; i++) { try { m_List[i]->WriteToStream(pStream); } catch (...) { CString sError = CONSTLIT("Unable to save ascended object:\r\n"); ReportCrashObj(&sError, m_List[i]); kernelDebugLogMessage(sError); return; } } }
ALERROR CUniverse::LoadSound (SDesignLoadCtx &Ctx, CXMLElement *pElement) // LoadSound // // Load a sound element { ALERROR error; if (Ctx.bNoResources) return NOERROR; DWORD dwUNID = LoadUNID(Ctx, pElement->GetAttribute(UNID_ATTRIB)); CString sFilename = pElement->GetAttribute(FILENAME_ATTRIB); // Load the image int iChannel; if (error = Ctx.pResDb->LoadSound(*m_pSoundMgr, NULL_STR, sFilename, &iChannel)) { Ctx.sError = strPatternSubst(CONSTLIT("Unable to load sound: %s"), sFilename.GetASCIIZPointer()); return error; } if (error = m_Sounds.AddEntry((int)dwUNID, (CObject *)iChannel)) { Ctx.sError = CONSTLIT("Unable to add sound"); return error; } #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Loaded sound: %x", dwUNID); #endif return NOERROR; }
void CScreenMgr::DebugOutputStats (void) // DebugOutputStats // // Output debug stats { if (m_pDD) { // DirectX info kernelDebugLogMessage("DIRECT X"); if (m_bExclusiveMode) kernelDebugLogMessage("exclusive mode"); kernelDebugLogMessage("Screen: %d x %d (%d-bit color)", m_cxScreen, m_cyScreen, m_iColorDepth); if (m_PrimaryType == CG16bitImage::r5g5b5) kernelDebugLogMessage("Pixels: 5-5-5"); else kernelDebugLogMessage("Pixels: 5-6-5"); //kernelDebugLogMessage("Video Memory: %d", caps.dwVidMemTotal); // Primary surface #if 0 kernelDebugLogMessage("PRIMARY SURFACE"); if (!FAILED(hr)) DebugOutputSurfaceDesc(desc); else kernelDebugLogMessage("GetSurfaceDesc failed: %x", hr); // Back buffer if (m_pBack) { kernelDebugLogMessage("SECONDARY SURFACE"); DDSURFACEDESC2 desc; ZeroMemory(&desc, sizeof(desc)); desc.dwSize = sizeof(desc); hr = m_pBack->GetSurfaceDesc(&desc); if (!FAILED(hr)) DebugOutputSurfaceDesc(desc); else kernelDebugLogMessage("GetSurfaceDesc failed: %x", hr); } #endif } }
ALERROR CUniverse::LoadModules (SDesignLoadCtx &Ctx, CXMLElement *pModules) // LoadModules // // Load all sub-modules { ALERROR error; int i; for (i = 0; i < pModules->GetContentElementCount(); i++) { CXMLElement *pModule = pModules->GetContentElement(i); CString sFilename = pModule->GetAttribute(FILENAME_ATTRIB); #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Loading module %s...", sFilename.GetASCIIZPointer()); #endif // Load the module CXMLElement *pModuleXML; if (error = Ctx.pResDb->LoadModule(NULL_STR, sFilename, &pModuleXML, &Ctx.sError)) return error; #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("...loaded XML from database"); #endif if (error = LoadModule(Ctx, pModuleXML)) { Ctx.sError = strPatternSubst(CONSTLIT("Unable to load module (%s): %s"), sFilename.GetASCIIZPointer(), Ctx.sError.GetASCIIZPointer()); return error; } delete pModuleXML; #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Done loading module", sFilename.GetASCIIZPointer()); #endif } return NOERROR; }
void CObjectImageArray::GenerateGlowImage (int iRotation) const // GenerateGlowImage // // Generates a mask that looks like a glow. The mask is 0 for all image pixels // and for all pixels where there is no glow (thus we can optimize painting // of the glow by ignoring 0 values) { ASSERT(iRotation >= 0 && iRotation < m_iRotationCount); // Source if (m_pImage == NULL) return; CG16bitImage &Source(*m_pImage->GetImage()); // Allocate the array of images (if not already allocated) if (m_pGlowImages == NULL) m_pGlowImages = new CG16bitImage[m_iRotationCount]; // If the image for this rotation has already been initialized, then // we're done if (!m_pGlowImages[iRotation].IsEmpty()) return; // Otherwise we need to create the glow mask. The glow image is larger // than the object image (by GLOW_SIZE) int cxSrcWidth = RectWidth(m_rcImage); int cySrcHeight = RectHeight(m_rcImage); int cxGlowWidth = cxSrcWidth + 2 * GLOW_SIZE; int cyGlowHeight = cySrcHeight + 2 * GLOW_SIZE; if (m_pGlowImages[iRotation].Create(cxGlowWidth, cyGlowHeight, 8) != NOERROR) { m_pGlowImages[iRotation].DiscardSurface(); kernelDebugLogMessage("Unable to create image"); return; } RECT rcSrc; rcSrc.left = ComputeSourceX(0); rcSrc.top = m_rcImage.top + (iRotation * cySrcHeight); rcSrc.right = rcSrc.left + cxSrcWidth; rcSrc.bottom = rcSrc.top + cySrcHeight; m_pGlowImages[iRotation].DrawGlowImage(0, 0, Source, rcSrc.left, rcSrc.top, rcSrc.right, rcSrc.bottom, 4); }
ALERROR IEffectPainter::ValidateClass (SLoadCtx &Ctx, const CString &sOriginalClass) // ValidateClass // // Reads the class string. If the class does not match the current painter, // we read the old data and return ERR_FAIL. { if (Ctx.dwVersion >= 40) { CString sClass; sClass.ReadFromStream(Ctx.pStream); // If the original class doesn't match the current one, then it means // that the design changed. In that case, we load the painter using the // old class. if (!strEquals(sClass, sOriginalClass)) { // If sClass is blank, then it means that the original did not have // an effect painter (but the current design does) if (!sClass.IsBlank()) { // Get the original creator CEffectCreator *pOriginalCreator; if (CEffectCreator::CreateFromTag(sClass, &pOriginalCreator) != NOERROR) { kernelDebugLogMessage("Unable to find original effect creator: %s", sClass.GetASCIIZPointer()); return ERR_FAIL; } // Load the original painter IEffectPainter *pOriginalPainter = pOriginalCreator->CreatePainter(); pOriginalPainter->ReadFromStream(Ctx); // Discard pOriginalPainter->Delete(); delete pOriginalCreator; } // Done return ERR_FAIL; } } return NOERROR; }
void LogDDError (HRESULT hr) { SDDERRText *pEntry = g_DDERRTable; while (pEntry->hr != DD_OK) { if (pEntry->hr == hr) { kernelDebugLogMessage(pEntry->pszText); break; } pEntry++; } }
ALERROR CTopologyNode::AddStargate (const CString &sGateID, const CString &sDestNodeID, const CString &sDestGateID) // AddStargate // // Adds a new stargate to the topology { // Get the destination node CTopologyNode *pDestNode = g_pUniverse->FindTopologyNode(sDestNodeID); if (pDestNode == NULL) { kernelDebugLogMessage("Unable to find destination node: %s", sDestNodeID); return ERR_FAIL; } // Look for the destination stargate CString sReturnNodeID; CString sReturnEntryPoint; if (!pDestNode->FindStargate(sDestGateID, &sReturnNodeID, &sReturnEntryPoint)) { kernelDebugLogMessage("Unable to find destination stargate: %s", sDestGateID); return ERR_FAIL; } // Add the gate AddGateInt(sGateID, sDestNodeID, sDestGateID); // See if we need to fix up the return gate if (strEquals(sReturnNodeID, PREV_DEST)) pDestNode->SetStargateDest(sDestGateID, GetID(), sGateID); return NOERROR; }
void CScreenMgr::FlipInt (void) // FlipInt // // Flips DX surfaces in exclusive mode { ASSERT(m_pDD); ASSERT(m_bExclusiveMode); ASSERT(m_pPrimary); HRESULT hr = m_pPrimary->Flip(NULL, DDFLIP_WAIT); if (FAILED(hr)) kernelDebugLogMessage("Flip failed: %x", hr); }
void CDesignCollection::FireOnGlobalPlayerChangedShips (CSpaceObject *pOldShip) // FireOnGlobalPlayerChangedShips // // Fire event { int i; CString sError; for (i = 0; i < GetCount(); i++) { if (GetEntry(i)->FireOnGlobalPlayerChangedShips(pOldShip, &sError) != NOERROR) kernelDebugLogMessage("%s", sError.GetASCIIZPointer()); } }
void CDesignCollection::FireOnGlobalSystemCreated (SSystemCreateCtx &SysCreateCtx) // FireOnGlobalSystemCreate // // Notify all type that a system has been created { int i; CString sError; for (i = 0; i < GetCount(); i++) { if (GetEntry(i)->FireOnGlobalSystemCreated(SysCreateCtx, &sError) != NOERROR) kernelDebugLogMessage("%s", sError.GetASCIIZPointer()); } }
void CDesignCollection::FireOnGlobalPlayerLeftSystem (void) // FireOnGlobalPlayerLeftSystem // // Fire event { int i; CString sError; for (i = 0; i < GetCount(); i++) { if (GetEntry(i)->FireOnGlobalPlayerLeftSystem(&sError) != NOERROR) kernelDebugLogMessage("%s", sError.GetASCIIZPointer()); } }
void CDockingPorts::DockAtRandomPort (CSpaceObject *pOwner, CSpaceObject *pObj) // DockAtRandomPort // // Dock the ship at a random port. This is used during setup { int i; int iStart = mathRandom(0, m_iPortCount - 1); int iDockingPort = -1; for (i = 0; i < m_iPortCount; i++) { int iPort = (iStart + i) % m_iPortCount; if (m_pPort[iPort].iStatus == psEmpty) { iDockingPort = iPort; break; } } // Set ship at the docking port if (iDockingPort != -1) { m_pPort[iDockingPort].pObj = pObj; m_pPort[iDockingPort].iStatus = psInUse; pObj->Place(GetPortPos(pOwner, m_pPort[iDockingPort], pObj)); pObj->OnDocked(pOwner); // Set the ship's rotation. We do this because this is only called // during set up CShip *pShip = pObj->AsShip(); if (pShip) pShip->SetRotation(m_pPort[iDockingPort].iRotation); } else { kernelDebugLogMessage("Warning: Unable to find docking port at %s", pOwner->GetName()); } }
void CNPServer::Log (char *pszLine, ...) // Log // // Logs a message to the debug log { if (m_bLog) { char *pArgs; char szBuffer[1024]; pArgs = (char *)&pszLine + sizeof(pszLine); wvsprintf(szBuffer, pszLine, pArgs); kernelDebugLogMessage(szBuffer); #ifdef _DEBUG printf("%s\n", szBuffer); #endif } }
void CAdventureDesc::FireOnGameStart (void) // FireOnGameStart // // Fire OnGameStart event { SEventHandlerDesc Event; if (FindEventHandler(ON_GAME_START_EVENT, &Event)) { CCodeChainCtx Ctx; // Run code ICCItem *pResult = Ctx.Run(Event); if (pResult->IsError()) kernelDebugLogMessage("OnGameStart error: %s", pResult->GetStringValue()); Ctx.Discard(pResult); } }
bool CSpaceObjectAddressResolver::HasUnresolved (void) // HasUnresolved // // For all callback reference, we call them with NULL. If there are any address // references left, then we return TRUE. { int i, j; bool bUnresolved = false; for (i = 0; i < m_List.GetCount(); i++) { TArray<SEntry> *pList = &m_List[i]; for (j = 0; j < pList->GetCount(); j++) { SEntry *pEntry = &pList->GetAt(j); // If we have a callback function, invoke it now. // The function may throw if it does not want to leave an object // unresolved. if (pEntry->pfnResolveProc) (pEntry->pfnResolveProc)(pEntry->pCtx, m_List.GetKey(i), NULL); // Otherwise this is unresolved else { kernelDebugLogMessage("Unresolved object: %x", m_List.GetKey(i)); bUnresolved = true; } } } return bUnresolved; }
void CTransmuterController::OnModelInitDone (CInitModelTask *pTask) // OnModelInitDone // // Model is done initializing. { CString sError; // Check for error. if (pTask->GetResult(&sError)) { kernelDebugLogMessage(sError); m_HI.OpenPopupSession(new CMessageSession(m_HI, ERR_LOAD_ERROR, sError, CMD_UI_EXIT)); return; } // Tell the session that we're done loading. m_HI.GetSession()->HICommand(CMD_INTRO_SHOW_UI); }
void CAdventureDesc::FireOnGameEnd (const CGameRecord &Game, const SBasicGameStats &BasicStats) // FireOnGameEnd // // Fire OnGameEnd event { SEventHandlerDesc Event; if (FindEventHandler(ON_GAME_END_EVENT, &Event)) { CCodeChainCtx Ctx; // Initialize variables Ctx.DefineInteger(CONSTLIT("aScore"), Game.GetScore()); Ctx.DefineInteger(CONSTLIT("aResurrectCount"), Game.GetResurrectCount()); Ctx.DefineInteger(CONSTLIT("aSystemsVisited"), BasicStats.iSystemsVisited); Ctx.DefineInteger(CONSTLIT("aEnemiesDestroyed"), BasicStats.iEnemiesDestroyed); Ctx.DefineInteger(CONSTLIT("aBestEnemiesDestroyed"), BasicStats.iBestEnemyDestroyedCount); if (BasicStats.dwBestEnemyDestroyed) Ctx.DefineInteger(CONSTLIT("aBestEnemyClass"), BasicStats.dwBestEnemyDestroyed); else Ctx.DefineNil(CONSTLIT("aBestEnemyClass")); Ctx.DefineString(CONSTLIT("aEndGameReason"), Game.GetEndGameReason()); Ctx.DefineString(CONSTLIT("aEpitaph"), Game.GetEndGameEpitaph()); Ctx.DefineString(CONSTLIT("aEpitaphOriginal"), Game.GetEndGameEpitaph()); Ctx.DefineString(CONSTLIT("aTime"), Game.GetPlayTimeString()); // Invoke ICCItem *pResult = Ctx.Run(Event); if (pResult->IsError()) kernelDebugLogMessage("OnGameEnd error: %s", pResult->GetStringValue()); Ctx.Discard(pResult); } }
ALERROR CUniverse::LoadImage (SDesignLoadCtx &Ctx, CXMLElement *pElement) // LoadImage // // Load an image { ALERROR error; if (Ctx.bNoResources) return NOERROR; // Add the image to the library if (error = m_BitmapLibrary.AddImage(Ctx, pElement)) return error; #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Loaded image: %x", dwUNID); #endif return NOERROR; }
void CHumanInterface::HardCrash (const CString &sProgramState) // HardCrash // // Report an error { CString sSessionMessage; try { if (m_pCurSession) m_pCurSession->HIReportHardCrash(&sSessionMessage); } catch (...) { sSessionMessage = CONSTLIT("Unable to obtain crash report from session."); } CString sMessage = strPatternSubst(CONSTLIT( "Unable to continue due to program error.\r\n\r\n" "program state: %s\r\n" "%s" "\r\n\r\nPlease contact [email protected] with a copy of Debug.log and your save file. " "We are sorry for the inconvenience.\r\n"), sProgramState, sSessionMessage ); kernelDebugLogMessage(sMessage); ShowHardCrashSession(CONSTLIT("Transcendence System Crash"), sMessage); // Ask the controller to post a crash report CString *pCrashReport = new CString(::kernelGetSessionDebugLog()); if (HICommand(CONSTLIT("cmdPostCrashReport"), pCrashReport) == ERR_NOTFOUND) delete pCrashReport; }
ALERROR CUniverse::InitStarSystemTypes (SDesignLoadCtx &Ctx, CXMLElement *pElement) // InitStarSystemTypes // // Load <StarSystemTypes> tag { ALERROR error; int i; for (i = 0; i < pElement->GetContentElementCount(); i++) { CXMLElement *pItem = pElement->GetContentElement(i); if (strEquals(pItem->GetTag(), TABLES_TAG)) { if (m_pSystemTables) { Ctx.sError = CONSTLIT("Multiple global tables found in <StarSystemDescriptions>"); return ERR_FAIL; } m_pSystemTables = pItem->OrphanCopy(); } else { if (error = m_Design.LoadEntryFromXML(Ctx, pItem)) return error; #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Loaded system type: %x", dwUNID); #endif } } return NOERROR; }
void CAscendedObjectList::ReadFromStream (SLoadCtx &Ctx) // ReadFromStream // // Read // // DWORD Count // CSpaceObject { int i; CleanUp(); DWORD dwCount; Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD)); m_List.InsertEmpty(dwCount); for (i = 0; i < (int)dwCount; i++) { CSpaceObject *pObj; try { CSpaceObject::CreateFromStream(Ctx, &pObj); } catch (...) { CString sError = CSpaceObject::DebugLoadError(Ctx); kernelDebugLogMessage(sError); return; } // Add to list m_List[i] = pObj; } }
CG32bitImage *CDesignCollection::GetImage (DWORD dwUNID, DWORD dwFlags) // GetImage // // Returns an image { CDesignType *pType = m_AllTypes.FindByUNID(dwUNID); if (pType == NULL) return NULL; CObjectImage *pImage = CObjectImage::AsType(pType); if (pImage == NULL) return NULL; if (dwFlags & FLAG_IMAGE_COPY) return pImage->CreateCopy(); else { CString sError; CG32bitImage *pRawImage = pImage->GetImage(strFromInt(dwUNID), &sError); if (pRawImage == NULL) kernelDebugLogMessage(sError); // Lock, if requested. NOTE: Since we obtained the image above, // this call is guaranteed to succeed. if (dwFlags & FLAG_IMAGE_LOCK) pImage->Lock(SDesignLoadCtx()); // Done return pRawImage; } }
LONG CTranscendenceWnd::WMCreate (CString *retsError) // WMCreate // // Handle WM_CREATE { ALERROR error; int i; // Get the version information { SFileVersionInfo VerInfo; fileGetVersionInfo(NULL_STR, &VerInfo); m_sVersion = strPatternSubst(CONSTLIT("%s %s"), VerInfo.sProductName, VerInfo.sProductVersion); m_sCopyright = VerInfo.sCopyright; kernelDebugLogMessage(m_sVersion); } // Load preferences //LoadPreferences(); //g_pHI->GetSoundMgr().SetWaveVolume(m_Prefs.iSoundVolume); // Compute screen size ComputeScreenSize(); // Initialize frame rate information m_iStartAnimation = 0; m_iFrameCount = 0; for (i = 0; i < FRAME_RATE_COUNT; i++) { m_iFrameTime[i] = 0; m_iPaintTime[i] = 0; m_iUpdateTime[i] = 0; m_iBltTime[i] = 0; } // Initialize m_rcScreen.left = 0; m_rcScreen.top = 0; m_rcScreen.right = g_cxScreen; m_rcScreen.bottom = g_cyScreen; int cxMainScreen = Min(MAIN_SCREEN_WIDTH, g_cxScreen); int cyMainScreen = Min(MAIN_SCREEN_HEIGHT, g_cyScreen); m_rcMainScreen.left = (g_cxScreen - cxMainScreen) / 2; m_rcMainScreen.top = (g_cyScreen - cyMainScreen) / 2; m_rcMainScreen.right = m_rcMainScreen.left + cxMainScreen; m_rcMainScreen.bottom = m_rcMainScreen.top + cyMainScreen; // Initialize the font table m_Fonts.Small.Create(STR_SMALL_TYPEFACE, -10); m_Fonts.Medium.Create(STR_SMALL_TYPEFACE, -13); m_Fonts.MediumBold.Create(STR_SMALL_TYPEFACE, -13, true); m_Fonts.MediumHeavyBold.Create(STR_MEDIUM_TYPEFACE, -14, true); m_Fonts.Large.Create(STR_MEDIUM_TYPEFACE, -16); m_Fonts.LargeBold.Create(STR_MEDIUM_TYPEFACE, -16, true); m_Fonts.Header.CreateFromResource(g_hInst, "DXFN_HEADER"); m_Fonts.HeaderBold.CreateFromResource(g_hInst, "DXFN_HEADER_BOLD"); m_Fonts.SubTitle.CreateFromResource(g_hInst, "DXFN_SUBTITLE"); m_Fonts.SubTitleBold.CreateFromResource(g_hInst, "DXFN_SUBTITLE_BOLD"); m_Fonts.SubTitleHeavyBold.CreateFromResource(g_hInst, "DXFN_SUBTITLE_HEAVY_BOLD"); m_Fonts.Title.CreateFromResource(g_hInst, "DXFN_TITLE"); m_Fonts.LogoTitle.CreateFromResource(g_hInst, "DXFN_LOGO_TITLE"); m_Fonts.Console.Create(STR_FIXED_TYPEFACE, -14); // Output the typeface that we got if (m_pTC->GetOptionBoolean(CGameSettings::debugVideo)) { kernelDebugLogMessage("Small typeface: %s", m_Fonts.Small.GetTypeface()); kernelDebugLogMessage("Medium typeface: %s", m_Fonts.Large.GetTypeface()); kernelDebugLogMessage("Large typeface: %s", m_Fonts.Header.GetTypeface()); kernelDebugLogMessage("Console typeface: %s", m_Fonts.Console.GetTypeface()); } // Set colors m_Fonts.wTextColor = CG16bitImage::RGBValue(191,196,201); m_Fonts.wTitleColor = CG16bitImage::RGBValue(218,235,255); m_Fonts.wLightTitleColor = CG16bitImage::RGBValue(120,129,140); m_Fonts.wHelpColor = CG16bitImage::RGBValue(103,114,128); m_Fonts.wBackground = CG16bitImage::RGBValue(15,17,18); m_Fonts.wSectionBackground = CG16bitImage::RGBValue(86,82,73); m_Fonts.wSelectBackground = CG16bitImage::RGBValue(115,230,115); //m_Fonts.wSelectBackground = CG16bitImage::RGBValue(255,225,103); m_Fonts.wAltGreenColor = CG16bitImage::RGBValue(5,211,5); m_Fonts.wAltGreenBackground = CG16bitImage::RGBValue(23,77,23); m_Fonts.wAltYellowColor = CG16bitImage::RGBValue(255,225,103); m_Fonts.wAltYellowBackground = CG16bitImage::RGBValue(65,57,24); m_Fonts.wAltRedColor = CG16bitImage::RGBValue(4,179,4); m_Fonts.wAltRedBackground = CG16bitImage::RGBValue(76,0,0); m_Fonts.wAltBlueColor = CG16bitImage::RGBValue(87,111,205); m_Fonts.wAltBlueBackground = CG16bitImage::RGBValue(52,57,64); m_Fonts.wItemTitle = CG16bitImage::RGBValue(255,255,255); m_Fonts.wItemRef = CG16bitImage::RGBValue(255,255,255); m_Fonts.wItemDesc = CG16bitImage::RGBValue(128,128,128); m_Fonts.wItemDescSelected = CG16bitImage::RGBValue(200,200,200); // Initialize UI resources if (error = m_UIRes.Init(&m_Fonts)) { *retsError = CONSTLIT("Unable to initialize UI resources."); goto Fail; } // Play Intro Music if (!m_pTC->GetOptionBoolean(CGameSettings::noMusic)) g_pHI->GetSoundMgr().PlayMusic(CONSTLIT("TranscendenceMarch.mp3")); // Initialize debug console RECT rcRect; rcRect.left = m_rcScreen.right - (DEBUG_CONSOLE_WIDTH + 4); rcRect.top = (RectHeight(m_rcScreen) - DEBUG_CONSOLE_HEIGHT) / 2; rcRect.right = rcRect.left + DEBUG_CONSOLE_WIDTH; rcRect.bottom = rcRect.top + DEBUG_CONSOLE_HEIGHT; m_DebugConsole.SetFontTable(&m_Fonts); m_DebugConsole.Init(this, rcRect); m_DebugConsole.Output(CONSTLIT("Transcendence Debug Console")); m_DebugConsole.Output(m_sVersion); m_DebugConsole.Output(m_sCopyright); m_DebugConsole.Output(NULL_STR); return 0; Fail: return -1; }