Last active
August 29, 2015 14:24
-
-
Save unpacklo/fe9a582cb7a79400b667 to your computer and use it in GitHub Desktop.
Debug panel tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PanelTabParams | |
{ | |
Game *game; | |
World *world; | |
b2World *physics; | |
HandleManager *handles; | |
PackFileGui *packGui; | |
ResourceEditGui *editGui; | |
Graphics *graphics; | |
const GameTime *time; | |
const char *buildString; | |
}; | |
struct PanelTab | |
{ | |
const char *tabName; | |
void *userdata; | |
void (*guiHandler)(void *userdata); | |
}; | |
... | |
INTERNAL void DoMainPanel(void *ptp) | |
{ | |
PanelTabParams *params = (PanelTabParams *)ptp; | |
Game &game = *params->game; | |
const char *buildString = params->buildString; | |
ImGui::Checkbox("devmode", &g_devMode); | |
ImGui::Checkbox("invisible", &g_invisible); | |
ImGui::Checkbox("deaf", &g_deaf); | |
ImGui::Checkbox("infiniteammo", &g_infiniteAmmo); | |
ImGui::Checkbox("godprops", &g_godProps); | |
ImGui::Spacing(); | |
ImGui::Text("God mode:"); | |
ImGui::RadioButton("Off", &g_godmode, 0); | |
ImGui::SameLine(); | |
ImGui::RadioButton("Player", &g_godmode, 1); | |
ImGui::SameLine(); | |
ImGui::RadioButton("Everyone", &g_godmode, 2); | |
ImGui::Spacing(); | |
ImGui::Text("Audio"); | |
if (ImGui::SliderFloat("Master", &g_volumeMaster, 0.0f, 1.0f)) | |
{ | |
FMOD_Studio_Bus_SetFaderLevel(g_audio->master, g_volumeMaster); | |
} | |
if (ImGui::SliderFloat("Music", &g_volumeMusic, 0.0f, 1.0f)) | |
{ | |
FMOD_Studio_Bus_SetFaderLevel(g_audio->music, g_volumeMusic); | |
} | |
if (ImGui::SliderFloat("Effects", &g_volumeEffects, 0.0f, 1.0f)) | |
{ | |
FMOD_Studio_Bus_SetFaderLevel(g_audio->effects, g_volumeEffects); | |
} | |
if (ImGui::SliderFloat("Voices", &g_volumeVoices, 0.0f, 1.0f)) | |
{ | |
FMOD_Studio_Bus_SetFaderLevel(g_audio->voices, g_volumeVoices); | |
} | |
ImGui::Spacing(); | |
if (ImGui::CollapsingHeader("Collision avoidance")) | |
{ | |
ImGui::Checkbox("Memory", &g_collisionAvoidMemory); | |
ImGui::Checkbox("Cones", &g_collisionAvoidCones); | |
ImGui::Checkbox("Dynamic", &g_collisionAvoidDynamic); | |
ImGui::Checkbox("Static", &g_collisionAvoidStatic); | |
ImGui::Checkbox("V", &g_collisionAvoidV); | |
ImGui::Checkbox("V pref", &g_collisionAvoidVPref); | |
ImGui::Checkbox("V new", &g_collisionAvoidVNew); | |
ImGui::Checkbox("V max", &g_collisionAvoidVMax); | |
ImGui::Checkbox("Debug prints", &g_collisionAvoidPrints); | |
ImGui::Checkbox("Fill invalid regions", &g_collisionAvoidFillInvalidRegions); | |
ImGui::ColorEdit4("Fill color", g_collisionAvoidFillColor); | |
ImGui::SliderFloat("Dynamic lookahead", &g_collisionAvoidDynamicLookaheadDist, 0.0f, 50.0f); | |
ImGui::SliderFloat("Static lookahead", &g_collisionAvoidStaticLookaheadDist, 0.0f, 50.0f); | |
ImGui::SliderFloat("Dynamic lookahead time", &g_collisionAvoidDynamicLookaheadTime, 0.0f, 10.0f); | |
ImGui::SliderFloat("Static lookahead time", &g_collisionAvoidStaticLookaheadTime, 0.0f, 10.0f); | |
} | |
ImGui::Spacing(); | |
if (ImGui::CollapsingHeader("Miscellaneous")) | |
{ | |
ImGui::PushID("misc"); | |
ImGui::AlignFirstTextHeightToWidgets(); | |
ImGui::Text("Draw map perimeter:"); | |
ImGui::SameLine(); ImGui::CheckboxFlags("Walkable", &g_rPerimeter, PERIMETER_WALKABLE); | |
ImGui::SameLine(); ImGui::CheckboxFlags("Blocked", &g_rPerimeter, PERIMETER_BLOCKED); | |
ImGui::PushID("r_paths"); | |
ImGui::AlignFirstTextHeightToWidgets(); | |
ImGui::Text("r_paths: "); ImGui::SameLine(); ImGui::RadioButton("Off", &g_rPaths, 0); ImGui::SameLine(); | |
ImGui::RadioButton("On", &g_rPaths, 1); ImGui::SameLine(); ImGui::RadioButton("On (with path radius)", &g_rPaths, 2); | |
ImGui::PopID(); | |
ImGui::PushID("r_drawnavmesh"); | |
ImGui::AlignFirstTextHeightToWidgets(); | |
ImGui::Text("r_drawnavmesh: "); ImGui::SameLine(); ImGui::RadioButton("Off", &g_rDrawNavMesh, 0); ImGui::SameLine(); | |
ImGui::RadioButton("On", &g_rDrawNavMesh, 1); ImGui::SameLine(); ImGui::RadioButton("On (detailed)", &g_rDrawNavMesh, 2); | |
ImGui::PopID(); | |
ImGui::PushID("r_cover"); | |
ImGui::AlignFirstTextHeightToWidgets(); | |
ImGui::Text("r_cover: "); ImGui::SameLine(); ImGui::RadioButton("Off", &g_rCover, 0); ImGui::SameLine(); | |
ImGui::RadioButton("On", &g_rCover, 1); ImGui::SameLine(); ImGui::RadioButton("On (well positioned)", &g_rCover, 2); | |
ImGui::SliderFloat("r_covermaxheight", &g_rCoverMaxHeight, 0.0f, 10.0f); | |
ImGui::PopID(); | |
ImGui::Checkbox("r_props", &g_rProps); | |
ImGui::Checkbox("r_prophitboxes", &g_rPropHitboxes); | |
ImGui::Checkbox("r_unithitboxes", &g_rUnitHitboxes); | |
ImGui::Checkbox("r_drawtraps", &g_rDrawTraps); | |
ImGui::Checkbox("r_drawscenery", &g_rDrawScenery); | |
ImGui::Checkbox("r_drawsceneryhitboxes", &g_rDrawSceneryHitboxes); | |
ImGui::Checkbox("r_drawbodies", &g_rDrawBodies); | |
ImGui::Checkbox("Draw flank map", &g_drawFlankMap); | |
ImGui::Spacing(); | |
ImGui::Text("AI sense:"); | |
ImGui::Checkbox("memory", &g_aiSenseMemory); | |
ImGui::Checkbox("visible", &g_aiSenseVisible); | |
ImGui::Text("Profile:"); | |
ImGui::Checkbox("profile_fmod", &g_profileFmod); | |
ImGui::Checkbox("profile_box2d", &g_profileBox2d); | |
ImGui::Text("Mech query:"); | |
ImGui::Checkbox("Show memory##mechquery", &g_memprofileCircleQuery); | |
ImGui::Checkbox("Show grid##mechquery", &g_circleQueryDrawGrid); | |
ImGui::Text("Prop query:"); | |
ImGui::Checkbox("Show memory##propquery", &g_memprofileTileQuery); | |
ImGui::Checkbox("Show grid##propquery", &g_tileQueryDrawGrid); | |
static bool showTest = false; | |
showTest ^= ImGui::Button("Test/help"); | |
if (showTest) | |
{ | |
ImGui::ShowTestWindow(&showTest); | |
} | |
ImGui::SameLine(); | |
if (ImGui::Button("Hide panels")) | |
{ | |
DebugPanel::ToggleShow(); | |
} | |
ImGui::PopID(); | |
} | |
ImGui::Spacing(); | |
ImGui::Separator(); | |
ImGui::Spacing(); | |
ImGui::Text("Build: %s", buildString); | |
ImGui::Text("FMOD header: %x.%.2x.%.2x", | |
g_audioVersion.header >> 16, | |
(g_audioVersion.header >> 8) & 0xFF, | |
g_audioVersion.header & 0xFF); | |
ImGui::Text("FMOD linked: %x.%.2x.%.2x", | |
g_audioVersion.linked >> 16, | |
(g_audioVersion.linked >> 8) & 0xFF, | |
g_audioVersion.linked & 0xFF); | |
SDL_version sdlVersion; | |
SDL_VERSION(&sdlVersion); | |
ImGui::Text("SDL header: %d.%d.%d", sdlVersion.major, sdlVersion.minor, sdlVersion.patch); | |
SDL_GetVersion(&sdlVersion); | |
ImGui::Text("SDL linked: %d.%d.%d", sdlVersion.major, sdlVersion.minor, sdlVersion.patch); | |
ImGui::Text("imgui header: %s", IMGUI_VERSION); | |
ImGui::Text("imgui linked: %s", ImGui::GetVersion()); | |
if (ImGui::Button("Copy build string")) | |
{ | |
SetClipboardText(buildString); | |
} | |
} | |
// TAB DEFS. | |
INTERNAL int selectedTab = -1; | |
INTERNAL PanelTab tabs[] = | |
{ | |
{"Main", &panelTabParams, DoMainPanel}, | |
{"Mech debug", &panelTabParams, DoMechDebug}, | |
{"Pack file", &packFileParams, DoPackFileGui}, | |
{"Data editor", &editGuiParams, DoResourceEditGui}, | |
{"Message debug", &panelTabParams, DoMessageDebug}, | |
{"Range finder", &panelTabParams, DoRangeFinder}, | |
{"Money debug", &panelTabParams, DoMoneyDebug}, | |
{"Rendering control", &panelTabParams, DoRenderingControl}, | |
{"Graphics info", &panelTabParams, DoGraphicsInfo}, | |
{"Profiler", &panelTabParams, DoProfiler}, | |
}; | |
bool DebugPanel::SetSelectedTab(const char *tabName) | |
{ | |
for (int i = 0; i < ARRAY_ELEMENTS(tabs); ++i) | |
{ | |
if (!strcmp(tabs[i].tabName, tabName)) | |
{ | |
selectedTab = i; | |
return true; | |
} | |
} | |
return false; | |
} | |
bool DebugPanel::IsSelectedTab(const char *tabName) | |
{ | |
return !strcmp(tabs[selectedTab].tabName, tabName); | |
} | |
void DebugPanel::StartFrame(Game &game) | |
{ | |
panelTabParams.game = &game; | |
panelTabParams.world = game.m_world; | |
panelTabParams.physics = game.m_world ? game.m_world->getPhysics() : NULL; | |
panelTabParams.handles = &game.m_handles; | |
panelTabParams.packGui = &packGui; | |
panelTabParams.editGui = &editGui; | |
panelTabParams.graphics = &game.m_graphics; | |
panelTabParams.time = &game.m_inputs.time; | |
panelTabParams.buildString = game.m_buildString; | |
spriteDraw.graphics = &game.m_graphics; | |
spriteDraw.strings = &game.m_strings; | |
ImGuiIO &io(ImGui::GetIO()); | |
io.DisplaySize.x = game.m_graphics.GetViewportWidth(); | |
io.DisplaySize.y = game.m_graphics.GetViewportHeight(); | |
io.DeltaTime = game.m_inputs.time.wallDeltaTimeFloat; | |
ImGui::NewFrame(); | |
if (!IsShowing()) | |
{ | |
return; | |
} | |
ImGui::Begin("Debug (F1 to toggle panels)"); | |
ImVec2 tabBarMin; | |
for (int i = 0; i < ARRAY_ELEMENTS(tabs); ++i) | |
{ | |
PanelTab *tab = tabs + i; | |
const char *tabName = tab->tabName; | |
if (ImGui::Selectable(tabName, selectedTab == i, 0, ImGui::CalcTextSize(tabName))) | |
{ | |
selectedTab = i; | |
} | |
if (!i) | |
{ | |
tabBarMin = ImGui::GetItemRectMin(); | |
} | |
if ((i + 1) < ARRAY_ELEMENTS(tabs)) | |
{ | |
ImGui::SameLine(); ImGui::Text("|"); ImGui::SameLine(); | |
} | |
} | |
ImVec2 tabBarLastTabTopRight = ImGui::GetItemRectMax(); | |
ImGui::Separator(); | |
ImVec2 tabBarLowerRight = ImGui::GetItemRectMax(); | |
ImVec2 tabBarMax(tabBarLowerRight.x, tabBarLastTabTopRight.y); | |
if (ImGui::IsMouseHoveringRect(tabBarMin, tabBarMax) && ImGui::IsMouseClicked(1)) | |
{ | |
ImGui::OpenPopup("tab menu"); | |
} | |
if (ImGui::BeginPopup("tab menu")) | |
{ | |
for (int i = 0; i < ARRAY_ELEMENTS(tabs); ++i) | |
{ | |
PanelTab *tab = tabs + i; | |
const char *tabName = tab->tabName; | |
if (ImGui::Selectable(tabName, selectedTab == i)) | |
{ | |
selectedTab = i; | |
} | |
} | |
ImGui::EndPopup(); | |
} | |
selectedTab = CLAMP(selectedTab, 0, (int)ARRAY_ELEMENTS(tabs) - 1); | |
PanelTab *selected = tabs + selectedTab; | |
ImGui::BeginChild(selected->tabName); | |
selected->guiHandler(selected->userdata); | |
ImGui::EndChild(); | |
ImGui::End(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment