void VDebugProfiling::RebuildMenu() { const char* szGroupName = "Debug Profiling"; DeRegisterCallbacks(); VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) return; pMainMenu->RemoveGroup(szGroupName); VProfilingNode* pRoot = Vision::Profiling.GetProfilingRootNode(); if (pRoot) { VAppMenuItems items; const unsigned int iCount = Vision::Profiling.GetNumOfGroups(); for (unsigned int i=0; i<iCount; ++i) { VProfilingNode* pNode = pRoot->Children().GetAt(i); if (pNode) items.Add(VAppMenuItem(pNode->GetName(), i, i, true)); } items.Add(VAppMenuItem("Reset Max Values", s_iResetMaxValuesAction, iCount, false)); m_callbacks = pMainMenu->RegisterGroup(szGroupName, items, NULL, VAPP_DEFAULT_SORTING_1, false); RegisterCallbacks(); } }
void VDebugOptions::SetWireframe(bool bWireframe) { Vision::Renderer.SetWireframeMode(bWireframe); VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu != NULL) { pMainMenu->SetItemCheckState("Wireframe", bWireframe); } }
void VDebugOptions::SetFrameRateVisible(bool bVisible) { m_bFpsVisible = bVisible; VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu != NULL) { pMainMenu->SetItemCheckState("Toggle FPS Display", m_bFpsVisible); } }
void VCameraHandling::ReleaseCameraList() { DeactivateAllCameras(); DeRegisterCallbacks(); VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu != NULL) pMainMenu->RemoveGroup(m_sMenuGroupName); m_callbacks.RemoveAll(); m_actionMap.RemoveAll(); m_iWASDActionIndex = -1; }
void VHelp::Init() { Vision::Callbacks.OnUpdateSceneFinished += this; VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) { SetEnabled(false); m_bToggleEnabled = true; return; } m_callbacks.Append(pMainMenu->RegisterItem(VAppMenuItem("Help", 0, VAPP_DEFAULT_SORTING_3, true))); RegisterCallbacks(); SetEnabled(false); }
void VDebugShadingModes::Init() { Vision::Callbacks.OnAfterSceneLoaded += this; Vision::Callbacks.OnBeforeSceneUnloaded += this; m_debugShadingEffects.Clear(); m_spDebugShadingShaderLib = NULL; m_spDebugShadingShaderLib = Vision::Shaders.LoadShaderLibrary("Shaders\\DebugShadingEffects.ShaderLib"); if ((m_spDebugShadingShaderLib == NULL) || (m_spDebugShadingShaderLib && !m_spDebugShadingShaderLib->IsLoaded())) return; VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) return; VAppMenuItems items; VisShaderFXLibManager_cl &manager(Vision::Shaders.GetShaderFXLibManager()); // Enumerate all available effects and add them to a collection for later usage for (int i=0;i<m_spDebugShadingShaderLib->m_Effects.Count();i++) { VCompiledEffect *pFX = m_spDebugShadingShaderLib->m_Effects.GetAt(i)->CompileEffect(NULL, manager.m_ShaderInstances); // Skip the "NotAvailable" shader, because it is only used for fallback reasons in vForge if ((pFX==NULL) || (pFX && VStringHelper::SafeCompare(pFX->GetSourceEffect()->GetName(), "NotAvailable") == 0)) continue; // Use the effect's same as a description pFX->SetUserData((void *)pFX->GetSourceEffect()->GetName()); int iIndex = m_debugShadingEffects.Add(pFX); items.Add(VAppMenuItem(pFX->GetSourceEffect()->GetName(), iIndex, 0, true)); } m_callbacks = pMainMenu->RegisterGroup("Debug Shading", items, NULL, VAPP_DEFAULT_SORTING_2, false); RegisterCallbacks(); }
void VCameraHandling::ActivateCameraByActionIndex(int iActionIndex) { EntityAccessor entity; if (!m_actionMap.Lookup(iActionIndex, entity)) { // Activate the free camera for the current position. DeactivateAllCameras(); PlaceFreeCameraAtCurrentPosition(); return; } if (!ActivateCamera(entity)) { // Remove item from menu since it doesn't exist anymore. VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu != NULL) pMainMenu->RemoveItem(entity.GetMenuName()); m_actionMap.RemoveKey(iActionIndex); Vision::Message.Add("Camera object has been removed from the scene.\n"); } }
void VDebugProfiling::OnActionTriggered(int iIndex) { VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); const VProfilingNodeCollection& pages = Vision::Profiling.GetProfilingRootNode()->Children(); // deselect old menu item if (m_iCurrentProfilingPage != -1) { if (pMainMenu!=NULL) pMainMenu->SetItemCheckState(pages.GetAt(m_iCurrentProfilingPage)->GetName(), false); } if (iIndex == s_iResetMaxValuesAction) { Vision::Profiling.ResetProfilingMaxValues(); } else { if (iIndex == -1 || Vision::Profiling.IsPageVisible(iIndex)) { Vision::Profiling.Hide(); m_iCurrentProfilingPage = -1; } else { Vision::Profiling.SetPage(iIndex); m_iCurrentProfilingPage = iIndex; } } // select new menu item if (m_iCurrentProfilingPage != -1) { if (pMainMenu!=NULL) pMainMenu->SetItemCheckState(pages.GetAt(m_iCurrentProfilingPage)->GetName(), true); } }
void VCameraHandling::BuildCameraList() { VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) return; int iActionIndex = 0; VAppMenuItems menuItems; menuItems.Add(VAppMenuItem("<Switch to Free Camera>", iActionIndex++, 0, false)); #if defined(WIN32) && !defined(_VISION_WINRT) // Add option to disable WASD controls. m_iWASDActionIndex = iActionIndex++; menuItems.Add(VAppMenuItem("<Toggle Free Camera WASD Controls>", m_iWASDActionIndex, 1, true, m_bWASDEnabled)); #endif // Find camera objects in the scene. // Only store element manager indices in order to be able to detect removed objects. unsigned int uiNumOrbitCameras = 0; unsigned int uiNumCameraPositions = 0; unsigned int uiNumPathCameras = 0; const unsigned int uiNumEntities = VisBaseEntity_cl::ElementManagerGetSize(); for (unsigned int uiElementIndex = 0; uiElementIndex < uiNumEntities; uiElementIndex++) { VisBaseEntity_cl* pEntity = VisBaseEntity_cl::ElementManagerGet(uiElementIndex); if (pEntity == NULL) continue; // Try to convert the entity to all of the supported camera types. VOrbitCamera* pOrbitCamera = pEntity->Components().GetComponentOfBaseType<VOrbitCamera>(); CameraPositionEntity* pCameraPosition = vdynamic_cast<CameraPositionEntity*>(pEntity); PathCameraEntity* pPathCamera = vdynamic_cast<PathCameraEntity*>(pEntity); // Menu name data const char* szKey = ""; const char* szCameraType = ""; unsigned int uiSortingKey = 0; unsigned int uiCameraIndex = 0; if (pOrbitCamera != NULL) { // If the owner entity's key is not set, use the model's file name. const char* szKey = pEntity->GetObjectKey(); if (VStringUtil::IsEmpty(szKey)) szKey = (pEntity->GetMesh() ? pEntity->GetMesh()->GetFilename() : ""); szCameraType = "OrbitCamera"; uiSortingKey = 2; uiCameraIndex = uiNumOrbitCameras++; } else if (pCameraPosition != NULL) { szKey = pEntity->GetObjectKey(); szCameraType = "CameraPosition"; uiSortingKey = 3; uiCameraIndex = uiNumCameraPositions++; } else if (pPathCamera != NULL) { szKey = pEntity->GetObjectKey(); szCameraType = "PathCamera"; uiSortingKey = 4; uiCameraIndex = uiNumPathCameras++; } else { // If we haven't found a free camera entity yet, try to store this one. if (m_spFreeCamera == NULL) m_spFreeCamera = vdynamic_cast<VFreeCamera*>(pEntity); // No camera found. continue; } // Generate menu name. VString sMenuName; if (VStringUtil::IsEmpty(szKey)) sMenuName.Format("%s%02d", szCameraType, uiCameraIndex + 1); else sMenuName.Format("%s%02d (%s)", szCameraType, uiCameraIndex + 1, szKey); menuItems.Add(VAppMenuItem(sMenuName, iActionIndex, uiSortingKey, false)); m_actionMap.SetAt(iActionIndex++, EntityAccessor(pEntity, sMenuName)); } m_callbacks.Append(pMainMenu->RegisterGroup(m_sMenuGroupName, menuItems, NULL, VAPP_DEFAULT_SORTING_2 + 1)); RegisterCallbacks(); }
void VDebugOptions::Init() { Vision::Callbacks.OnUpdateSceneBegin += this; Vision::Callbacks.OnBeforeSwapBuffers += this; Vision::Callbacks.OnRenderHook += this; // Setup graph for displaying un-/filtered time steps VGraphProps timeStepGraphProps; timeStepGraphProps.vPosition.set(-0.85f, -0.3f); timeStepGraphProps.fWidth = 0.25f; timeStepGraphProps.fHeight = 0.25f; timeStepGraphProps.iResolution = 64; timeStepGraphProps.bRangeAdaptation = true; m_pTimeStepGraph = new VGraphObject(timeStepGraphProps); m_pTimeStepGraph->AddCurve("Unfiltered Time Step", VColorRef(0, 255, 0), new VUnfilteredTimeDiffUpdater); m_pTimeStepGraph->AddCurve("Filtered Time Step", VColorRef(255, 0, 0), new VFilteredTimeDiffUpdater); m_pTimeStepGraph->Init(); m_pTimeStepGraph->SetVisible(false); #if defined(WIN32) GetParent()->GetInputMap()->MapTrigger(TOGGLE_FPS, VInputManager::GetKeyboard(), CT_KB_F2, VInputOptions::Once(ONCE_ON_RELEASE)); GetParent()->GetInputMap()->MapTrigger(TOGGLE_WIREFRAME, VInputManager::GetKeyboard(), CT_KB_F3, VInputOptions::Once(ONCE_ON_RELEASE)); #endif VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) return; // General Debug Options // Note: OPTION_FPS, OPTION_WIREFRAME, and OPTION_RELOAD_RESOURCES are added directly to the menu's root, the other options // are added to the menu's root as a group called 'Debug Options' m_callbacks.Append(pMainMenu->RegisterItem(VAppMenuItem("Toggle FPS Display", OPTION_FPS, VAPP_DEFAULT_SORTING_0, true))); // wireframe rendering is not supported on GLES2 #if !defined(_VR_GLES2) m_callbacks.Append(pMainMenu->RegisterItem(VAppMenuItem("Wireframe", OPTION_WIREFRAME, VAPP_DEFAULT_SORTING_0 + 1, true))); #endif m_callbacks.Append(pMainMenu->RegisterItem(VAppMenuItem("Reload Modified Resources", OPTION_RELOAD_RESOURCES, VAPP_DEFAULT_SORTING_0 + 2, false))); VAppMenuItems items; items.Add(VAppMenuItem("Show Time Step Graph", OPTION_TIME_STEP_GRAPH, 0, true)); items.Add(VAppMenuItem("Save Screenshot", OPTION_SAVE_SCREENSHOT, 0, false)); #if defined(SUPPORTS_MULTITOUCH) items.Add(VAppMenuItem("Touch Area Debug Rendering", OPTION_MULTITOUCH, 0, true)); #endif m_callbacks.Append(pMainMenu->RegisterGroup("Debug Options", items, NULL, VAPP_DEFAULT_SORTING_0 + 3, true)); RegisterCallbacks(); // Debug Render Flags items.RemoveAll(); items.Add(VAppMenuItem("Display Object Triangle Count", DEBUGRENDERFLAG_OBJECT_TRIANGLECOUNT, 0, true)); items.Add(VAppMenuItem("Display Object Visibility BoundingBox", DEBUGRENDERFLAG_OBJECT_VISBBOX, 0, true)); items.Add(VAppMenuItem("Display Object vis. Area Assignment", DEBUGRENDERFLAG_OBJECT_VISIBILITYZONES, 0, true)); items.Add(VAppMenuItem("Display Light Influence BoundingBox", DEBUGRENDERFLAG_LIGHT_INFLUENCEBOX, 0, true)); items.Add(VAppMenuItem("Display Trace Lines", DEBUGRENDERFLAG_TRACELINES, 0, true)); items.Add(VAppMenuItem("Display Visibility Objects", DEBUGRENDERFLAG_VISIBILITYOBJECTS, 0, true)); items.Add(VAppMenuItem("Display Portals", DEBUGRENDERFLAG_PORTALS, 0, true)); items.Add(VAppMenuItem("Display Visibility Zones", DEBUGRENDERFLAG_VISIBILITYZONES, 0, true)); items.Add(VAppMenuItem((Vision::GetScriptManager() != NULL) ? "Scripting Statistics" : "Scripting Statistics (no script man.)", DEBUGRENDERFLAG_SCRIPTSTATISTICS, 0, true)); items.Add(VAppMenuItem("Display Object Render Order", DEBUGRENDERFLAG_OBJECTRENDERORDER, 0, true)); items.Add(VAppMenuItem("Display Thread Workload", DEBUGRENDERFLAG_THREADWORKLOAD, 0, true)); items.Add(VAppMenuItem("Display Streaming Zones", DEBUGRENDERFLAG_ZONES, 0, true)); items.Add(VAppMenuItem("Display Resource Stats", DEBUGRENDERFLAG_RESOURCE_STATISTICS, 0, true)); items.Add(VAppMenuItem("Display Memory Stats", DEBUGRENDERFLAG_MEMORY_STATISTICS, 0, true)); m_debugInfos = pMainMenu->RegisterGroup("Debug Infos", items, "Debug Options"); RegisterCallbacks(m_debugInfos); }
void VDebugOptions::OnHandleCallback(IVisCallbackDataObject_cl* pData) { if (pData->m_pSender == &Vision::Callbacks.OnUpdateSceneBegin) { #if defined(WIN32) if (GetParent()->GetInputMap()->GetTrigger(TOGGLE_FPS)) { SetFrameRateVisible(!IsFrameRateVisible()); } else if (GetParent()->GetInputMap()->GetTrigger(TOGGLE_WIREFRAME)) { SetWireframe(!IsWireframe()); } #endif // FPS accumulation { m_iFrameCounter++; m_fTimeAccumulator += Vision::GetUITimer()->GetTimeDifference(); if (m_fTimeAccumulator >= 1.0f) { m_fCurrentFrameTime = m_fTimeAccumulator / m_iFrameCounter; m_fCurrentFps = m_iFrameCounter / m_fTimeAccumulator; m_fTimeAccumulator = 0.0f; m_iFrameCounter = 0; } } if (m_bFpsVisible) Vision::Message.Print(1, 10, Vision::Video.GetYRes() - 35, "FPS : %.1f\nFrame Time : %.2f", m_fCurrentFps, m_fCurrentFrameTime * 1000.0f); } else if (pData->m_pSender == &Vision::Callbacks.OnBeforeSwapBuffers) { if (m_bSaveScreenshot) { VScreenShotHelper helper; helper.Capture(); if (helper.PendingDataInBuffer()) { if (helper.SaveBufferToFile("", NULL, 1.0f, 1.0f)) Vision::Message.Add(0, "Screenshot saved to \"%s\".\n", helper.GetScreenShotPath()); else Vision::Message.Add(0, "Screenshot could not be saved.\n"); } // Re-enable the VAppMenu again VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu) pMainMenu->SetVisible(true); m_bSaveScreenshot = false; } } else if (pData->m_pSender == &Vision::Callbacks.OnRenderHook) { VisRenderHookDataObject_cl *pRenderHookData = (VisRenderHookDataObject_cl *)pData; if (pRenderHookData->m_iEntryConst == VRH_PRE_SCREENMASKS) { // Debug drawing of all visible touch areas. #if defined(SUPPORTS_MULTITOUCH) if (m_bTouchAreaDebug) { IVMultiTouchInput* pMultiTouchInput = NULL; pMultiTouchInput = static_cast<IVMultiTouchInput*>(&VInputManager::GetInputDevice(INPUT_DEVICE_TOUCHSCREEN)); VPListT<VTouchArea> touchAreas = pMultiTouchInput->GetTouchAreas(); const float fBorderWidth = 3.0f; VSimpleRenderState_t alphaState(VIS_TRANSP_ALPHA, RENDERSTATEFLAG_FRONTFACE|RENDERSTATEFLAG_NOWIREFRAME|RENDERSTATEFLAG_ALWAYSVISIBLE); IVRender2DInterface *pRI = Vision::RenderLoopHelper.BeginOverlayRendering(); { for (int i=0; i<touchAreas.GetLength(); ++i) { const VRectanglef& rect = touchAreas.Get(i)->GetArea(); const VColorRef color = touchAreas.Get(i)->GetTouchPointIndex() < 0 ? VColorRef(0, 255, 0, 64) : VColorRef(0, 255, 0, 96); pRI->DrawSolidQuad(rect.m_vMin, rect.m_vMax, color, alphaState); pRI->DrawSolidQuad(rect.m_vMin, hkvVec2(rect.m_vMax.x, rect.m_vMin.y + fBorderWidth), VColorRef(0, 255, 0, 255), alphaState); pRI->DrawSolidQuad(hkvVec2(rect.m_vMin.x, rect.m_vMax.y - fBorderWidth), rect.m_vMax, VColorRef(0, 255, 0, 255), alphaState); pRI->DrawSolidQuad(hkvVec2(rect.m_vMin.x, rect.m_vMin.y + fBorderWidth), hkvVec2(rect.m_vMin.x + fBorderWidth, rect.m_vMax.y - fBorderWidth), VColorRef(0, 255, 0, 255), alphaState); pRI->DrawSolidQuad(hkvVec2(rect.m_vMax.x - fBorderWidth, rect.m_vMin.y + fBorderWidth), hkvVec2(rect.m_vMax.x, rect.m_vMax.y - fBorderWidth), VColorRef(0, 255, 0, 255), alphaState); } } Vision::RenderLoopHelper.EndOverlayRendering(); } #endif } } int iIndex = GetCallbackIndex(pData); if (iIndex >= 0) { if (iIndex == OPTION_FPS) { m_bFpsVisible = !m_bFpsVisible; } else if (iIndex == OPTION_WIREFRAME) { if (Vision::Renderer.GetWireframeMode()) Vision::Renderer.SetWireframeMode(false); else Vision::Renderer.SetWireframeMode(true); } else if (iIndex == OPTION_RELOAD_RESOURCES) { int iCount = Vision::ResourceSystem.ReloadModifiedResourceFiles(NULL, VURO_HOT_RELOAD); // Clear effect caches so that material shaders will be re-created (not re-used). Vision::Shaders.GetShaderFXLibManager().ResetCompiledEffectCaches(); // Reassign all material shaders. Vision::Shaders.ReloadAllShaderAssignmentFiles(); Vision::Message.Add(1, "%i resources were outdated and have been reloaded.", iCount); } else if (iIndex == OPTION_TIME_STEP_GRAPH) { m_pTimeStepGraph->SetVisible(!m_pTimeStepGraph->IsVisible()); } #if defined(SUPPORTS_MULTITOUCH) else if (iIndex == OPTION_MULTITOUCH) { m_bTouchAreaDebug = !m_bTouchAreaDebug; } #endif else if (iIndex == OPTION_SAVE_SCREENSHOT) { m_bSaveScreenshot = true; // We don't want the menu to be visible in the screenshot VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu != NULL) pMainMenu->SetVisible(false); } } iIndex = GetCallbackIndex(m_debugInfos, pData); if (iIndex >= 0) Vision::Profiling.ToggleDebugRenderFlags((unsigned int)iIndex); }
void VExitHandler::OnHandleCallback(IVisCallbackDataObject_cl* pData) { if (pData->m_pSender == &Vision::Callbacks.OnFrameUpdatePreRender) { if (!m_bEnabled) return; VInputMap* pInputMap = GetParent()->GetInputMap(); if (pInputMap->GetTrigger(VAPP_EXIT)) { VAppMenu* pMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMenu && pMenu->IsVisible()) return; if (!m_bShowExitDialog) { VAppBase::Get()->Quit(); } else if (!m_spExitDlg->IsVisible()) { VAppMenu* pMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMenu != NULL && pMenu->IsVisible()) pMenu->ToggleMainMenu(); if (!VInputMap::AreInputMapsLocked()) { VInputMap::LockInputMaps(true); m_spExitDlg->SetUnlockInput(true); } else { m_spExitDlg->SetUnlockInput(false); } GetParent()->GetInputMap()->SetEnabled(true); m_spExitDlg->SetVisible(true); VAppMenuContextPtr spContext = GetParent()->GetContext(); spContext->ShowDialog(m_spExitDlg); } } else if (m_spExitDlg->IsVisible()) { VExitDialog* pDialog = static_cast<VExitDialog*>(m_spExitDlg.GetPtr()); if (pDialog->IsExitTriggered()) { VAppBase::Get()->Quit(); return; } if (pInputMap->GetTrigger(VAPP_MENU_CONFIRM)) VAppBase::Get()->Quit(); else if (pInputMap->GetTrigger(VAPP_MENU_BACK)) pDialog->CloseDialog(); } } else if (pData->m_pSender == &Vision::Callbacks.OnVideoChanged) { const hkvVec2& vSize = m_spExitDlg->GetSize(); m_spExitDlg->SetPosition((static_cast<float>(Vision::Video.GetXRes()) - vSize.x)*0.5f, (static_cast<float>(Vision::Video.GetYRes()) - vSize.y)*0.5f); } }