void MFCallstackInternal_DrawMeterLabel(const MFVector &listPos, const MFVector &colour, const char *pString, const char *pStats) { MFPrimitive_DrawUntexturedQuad(listPos.x, listPos.y + 1.0f, listPos.x + 14.0f, listPos.y + 15.0f, MFVector::one); MFPrimitive_DrawUntexturedQuad(listPos.x + 2, listPos.y + 3.0f, listPos.x + 12.0f, listPos.y + 13.0f, colour); MFFont_DrawTextf(MFFont_GetDebugFont(), listPos + MakeVector(16.0f, 0.0f, 0.0f), 16.0f, MFVector::one, pString); if(pStats) { float width = (float)MFDisplay_GetDisplaySettings()->width; MFFont_DrawTextf(MFFont_GetDebugFont(), listPos + MakeVector((width - listPos.x) - 250.0f, 0.0f, 0.0f), 16.0f, MFVector::one, pStats); } }
int MFWindowPC_HandleWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if(!gpEngineInstance->bIsInitialised) return 1; MFWindow_PC *pWindow = (MFWindow_PC*)GetWindowLongPtr(hWnd, GWLP_USERDATA); switch(message) { case WM_ACTIVATE: { int activate = LOWORD(wParam); MFInputPC_Acquire(activate != WA_INACTIVE); if(activate != WA_INACTIVE) { if(pWindow->params.bFullscreen) MFDisplay_Reset(pWindow->pDisplay); // scan key states... // using GetKeyState() for windows keystates // or read the state from directinput pWindow->bHasFocus = true; MFDisplay_GainedFocus(pWindow->pDisplay); MFSystemCallbackFunction pCallback = MFSystem_GetSystemCallback(MFCB_GainedFocus); if(pCallback) pCallback(); } else { pWindow->bHasFocus = false; MFDisplay_LostFocus(pWindow->pDisplay); MFSystemCallbackFunction pCallback = MFSystem_GetSystemCallback(MFCB_LostFocus); if(pCallback) pCallback(); } break; } case WM_SYSCOMMAND: { switch (wParam) { case SC_KEYMENU: if(pWindow && lParam == VK_RETURN) { MFDisplaySettings display = *MFDisplay_GetDisplaySettings(pWindow->pDisplay); display.bFullscreen = !display.bFullscreen; if(display.bFullscreen) { display.width = pWindow->pDisplay->fullscreenWidth; display.height = pWindow->pDisplay->fullscreenHeight; } else { display.width = pWindow->pDisplay->windowWidth; display.height = pWindow->pDisplay->windowHeight; } MFDisplay_Reset(pWindow->pDisplay, &display); } case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_SETCURSOR: /*if(CurrentDisplay.FullScreen) { SetCursor(NULL); return TRUE; }*/ break; case WM_MOVE: if(pWindow && !pWindow->params.bFullscreen) { pWindow->params.x = LOWORD(lParam); pWindow->params.y = HIWORD(lParam); } break; case WM_SIZE: if(pWindow && !pWindow->params.bFullscreen) { switch(wParam) { case SIZE_MINIMIZED: pWindow->state = MFWinState_Minimised; pWindow->pDisplay->bIsVisible = false; break; case SIZE_MAXIMIZED: pWindow->state = MFWinState_Maximised; pWindow->pDisplay->bIsVisible = true; break; case SIZE_MAXHIDE: pWindow->pDisplay->bIsVisible = false; break; case SIZE_MAXSHOW: pWindow->pDisplay->bIsVisible = true; break; case SIZE_RESTORED: pWindow->state = MFWinState_Normal; break; } if(wParam != SIZE_MINIMIZED) { RECT r, cr; GetWindowRect(hWnd, &r); GetClientRect(hWnd, &cr); pWindow->params.x = r.left; pWindow->params.y = r.top; pWindow->params.width = cr.right - cr.left; pWindow->params.height = cr.bottom - cr.top; MFDisplaySettings display = *MFDisplay_GetDisplaySettings(pWindow->pDisplay); display.width = pWindow->params.width; display.height = pWindow->params.height; MFDisplay_Reset(pWindow->pDisplay, &display); } } break; case WM_CLOSE: PostQuitMessage(0); return 0; case WM_DEVICECHANGE: { if(wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { void DeviceChange(DEV_BROADCAST_DEVICEINTERFACE *pDevInf, bool connect); PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam; switch(pHdr->dbch_devicetype) { case DBT_DEVTYP_DEVICEINTERFACE: { PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr; DeviceChange(pDevInf, wParam == DBT_DEVICEARRIVAL ? true : false); } } } } break; #if defined(ALLOW_RAW_INPUT) case WM_INPUT: if(gDefaults.input.allowMultipleMice) HandleRawMouseMessage((HRAWINPUT)lParam); break; #endif case WM_KEYDOWN: gWindowsKeys[wParam] = 1; break; case WM_KEYUP: gWindowsKeys[wParam] = 0; break; } return 1; }
void MFCallstack_Draw() { MFCALLSTACK; if(drawCallstack) { const MFDisplaySettings *pDisplaySettings = MFDisplay_GetDisplaySettings(); float width = (float)pDisplaySettings->width; float height = (float)pDisplaySettings->height; float xoffset = width / 10.0f; float yoffset = height / 6.0f; MFView_Push(); MFRect rect = { 0.f, 0.f, width, height }; MFView_SetOrtho(&rect); float rtcFreq = 1000000.f / (float)MFSystem_GetRTCFrequency(); MFVector callstackPos = MakeVector(xoffset, yoffset, 0.f, 0.f); // sort the calls qsort(gpProfiles, gNumProfileFunctions, sizeof(gpProfiles[0]), MFCallstack_SortPred); // if(!drawCallstackMeter) { // just draw the callstack profiling information.. MFPrimitive_DrawUntexturedQuad(callstackPos.x - 10.f, callstackPos.y - 10.f, (width - callstackPos.x) + 10, callstackPos.y + (float)gNumProfileFunctions*16.0f + 10, MakeVector(0, 0, 0, 0.8f)); for(int a=0; a<gNumProfileFunctions; a++) { uint32 microseconds = uint32((float)gpProfiles[a]->totalTime * rtcFreq); uint32 percent = uint32((float)microseconds / 166.66666f); // MFVector colour = gProfileColours[gpProfiles[a]->functionColour]; MFVector colour = MFVector::one; MFFont_DrawTextf(MFFont_GetDebugFont(), callstackPos, 16.0f, colour, "%s", gpProfiles[a]->pFunctionName); MFFont_DrawTextf(MFFont_GetDebugFont(), callstackPos + MakeVector((width - xoffset) - 250.0f, 0, 0), 16.0f, colour, "- %dus (%d%%) %d calls", microseconds, percent, gpProfiles[a]->numCalls); callstackPos.y += 16.0f; } } /* else { // draw a meter up the top of the screen representing the frame.. MFPrimitive_DrawUntexturedQuad(callstackPos.x - 10.f, callstackPos.y - 10.f, width - callstackPos.x + 10, callstackPos.y + (float)(gNumProfileTotals+1)*16.0f + 18, MakeVector(0, 0, 0, 0.8f)); MFVector meterPos = MakeVector(xoffset - 8.f, yoffset*0.5f - 15.0f, 0.0f); MFVector meterDimensions = MakeVector(width - (xoffset-8.0f)*2.0f, 20.0f, 0.0f); // draw the meter container MFPrimitive_DrawUntexturedQuad(meterPos.x - 2.0f, meterPos.y - 2.0f, meterPos.x + meterDimensions.x + 2.0f, meterPos.y + meterDimensions.y + 2.0f, MakeVector(1.0f, 1.0f, 1.0f, 0.8f)); MFPrimitive_DrawUntexturedQuad(meterPos.x, meterPos.y, meterPos.x + meterDimensions.x, meterPos.y + meterDimensions.y, MakeVector(0.0f, 0.0f, 0.0f, 1.0f)); // draw the overhead counter uint32 frameDuration = uint32(gBeginTime - gLastBeginTime); float frameTime = (float)frameDuration * rtcFreq; MFCallstackInternal_DrawMeterBlock(meterPos, meterDimensions, (float)(gEndTime - gLastBeginTime) / (float)frameTime, 1.0f, MakeVector(0.0f, 1.0f, 1.0f, 1.0f)); MFCallstackInternal_DrawMeterLabel(callstackPos, MakeVector(0.0f, 1.0f, 1.0f, 1.0f), "Frame Overhead/VSync", NULL); callstackPos.y += 24.0f; // draw all the totals for(int a=0; a<gNumProfileTotals; a++) { uint32 microseconds = uint32((float)gpProfiles[a]->totalTime * rtcFreq); uint32 percent = uint32((float)microseconds / 166.66666f); MFCallstackInternal_DrawMeterLabel(callstackPos, gProfileColours[a % gProfileColourCount], gProfileTotals[a].pFunctionName, MFStr("- %dus (%d%%) %d calls", microseconds, percent, gProfileTotals[a].numCalls)); callstackPos.y += 16.0f; } // draw all the function profiles float totalTime = (float)(gBeginTime - gLastBeginTime); for(int a=0; a<gNumProfileResults; a++) { int colour = MFCallstackInternal_GetTotalIndex(a); MFCallstackInternal_DrawMeterBlock(meterPos, meterDimensions, (float)(gProfileResults[a].startTime - gLastBeginTime) / totalTime, (float)(gProfileResults[a].endTime - gLastBeginTime) / totalTime, gProfileColours[colour % gProfileColourCount]); } } */ MFView_Pop(); } }