2013-12-08 19:09:35 -05:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2013 Lionel Fuentes
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "debug.hpp"
|
2013-12-08 21:03:16 -05:00
|
|
|
#include "config/user_config.hpp"
|
|
|
|
#include "karts/controller/controller.hpp"
|
2013-12-08 20:51:03 -05:00
|
|
|
#include "karts/abstract_kart.hpp"
|
2013-12-08 19:09:35 -05:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2013-12-08 20:51:03 -05:00
|
|
|
#include "items/powerup_manager.hpp"
|
|
|
|
#include "modes/world.hpp"
|
|
|
|
#include "physics/irr_debug_drawer.hpp"
|
|
|
|
#include "physics/physics.hpp"
|
|
|
|
#include "race/history.hpp"
|
2014-01-24 18:38:47 -05:00
|
|
|
#include "main_loop.hpp"
|
2013-12-08 20:51:03 -05:00
|
|
|
#include "replay/replay_recorder.hpp"
|
2013-12-08 19:09:35 -05:00
|
|
|
#include "utils/log.hpp"
|
|
|
|
#include <IGUIEnvironment.h>
|
|
|
|
#include <IGUIContextMenu.h>
|
|
|
|
using namespace irr;
|
|
|
|
using namespace gui;
|
|
|
|
|
|
|
|
namespace Debug {
|
|
|
|
|
|
|
|
/** This is to let mouse input events go through when the debug menu is visible, otherwise
|
|
|
|
GUI events would be blocked while in a race... */
|
|
|
|
static bool g_debug_menu_visible = false;
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Commands for the debug menu
|
|
|
|
enum DebugMenuCommand
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
//! graphics commands
|
|
|
|
DEBUG_GRAPHICS_RELOAD_SHADERS,
|
2013-12-08 20:51:03 -05:00
|
|
|
DEBUG_GRAPHICS_RESET,
|
|
|
|
DEBUG_GRAPHICS_WIREFRAME,
|
|
|
|
DEBUG_GRAPHICS_MIPMAP_VIZ,
|
|
|
|
DEBUG_GRAPHICS_NORMALS_VIZ,
|
|
|
|
DEBUG_GRAPHICS_SSAO_VIZ,
|
|
|
|
DEBUG_GRAPHICS_SHADOW_VIZ,
|
|
|
|
DEBUG_GRAPHICS_LIGHT_VIZ,
|
|
|
|
DEBUG_GRAPHICS_DISTORT_VIZ,
|
|
|
|
DEBUG_GRAPHICS_BULLET_1,
|
|
|
|
DEBUG_GRAPHICS_BULLET_2,
|
|
|
|
DEBUG_PROFILER,
|
|
|
|
DEBUG_FPS,
|
|
|
|
DEBUG_SAVE_REPLAY,
|
|
|
|
DEBUG_SAVE_HISTORY,
|
|
|
|
DEBUG_POWERUP_BOWLING,
|
|
|
|
DEBUG_POWERUP_BUBBLEGUM,
|
|
|
|
DEBUG_POWERUP_CAKE,
|
2013-12-13 04:06:54 -05:00
|
|
|
DEBUG_POWERUP_PARACHUTE,
|
2013-12-08 20:51:03 -05:00
|
|
|
DEBUG_POWERUP_PLUNGER,
|
|
|
|
DEBUG_POWERUP_RUBBERBALL,
|
|
|
|
DEBUG_POWERUP_SWATTER,
|
|
|
|
DEBUG_POWERUP_SWITCH,
|
|
|
|
DEBUG_POWERUP_ZIPPER,
|
2013-12-08 21:03:16 -05:00
|
|
|
DEBUG_POWERUP_NITRO,
|
2014-01-24 18:38:47 -05:00
|
|
|
DEBUG_TOGGLE_GUI,
|
|
|
|
DEBUG_THROTTLE_FPS
|
2013-12-08 19:09:35 -05:00
|
|
|
};
|
|
|
|
|
2013-12-13 05:34:58 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Add powerup selected from debug menu for all player karts
|
|
|
|
void addPowerup(PowerupManager::PowerupType powerup)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world == NULL) return;
|
|
|
|
for(unsigned int i = 0; i < race_manager->getNumLocalPlayers(); i++)
|
|
|
|
{
|
|
|
|
AbstractKart* kart = world->getLocalPlayerKart(i);
|
|
|
|
kart->setPowerup(powerup, 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 19:09:35 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Debug menu handling
|
|
|
|
bool onEvent(const SEvent &event)
|
|
|
|
{
|
|
|
|
// Only activated in artist debug mode
|
|
|
|
if(!UserConfigParams::m_artist_debug_mode)
|
|
|
|
return true; // keep handling the events
|
|
|
|
|
|
|
|
if(event.EventType == EET_MOUSE_INPUT_EVENT)
|
|
|
|
{
|
|
|
|
// Create the menu (only one menu at a time)
|
|
|
|
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN && !g_debug_menu_visible)
|
|
|
|
{
|
|
|
|
// root menu
|
2013-12-08 20:51:03 -05:00
|
|
|
gui::IGUIEnvironment* guienv = irr_driver->getGUI();
|
2013-12-08 19:09:35 -05:00
|
|
|
IGUIContextMenu* mnu = guienv->addContextMenu(
|
|
|
|
core::rect<s32>(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Y+100, event.MouseInput.Y+100),NULL);
|
2013-12-08 20:51:03 -05:00
|
|
|
int graphicsMenuIndex = mnu->addItem(L"Graphics >",-1,true,true);
|
2013-12-08 19:09:35 -05:00
|
|
|
|
|
|
|
// graphics menu
|
2013-12-08 20:51:03 -05:00
|
|
|
IGUIContextMenu* sub = mnu->getSubMenu(graphicsMenuIndex);
|
2013-12-08 19:09:35 -05:00
|
|
|
|
|
|
|
sub->addItem(L"Reload shaders", DEBUG_GRAPHICS_RELOAD_SHADERS );
|
2013-12-08 20:51:03 -05:00
|
|
|
sub->addItem(L"Reset debug views", DEBUG_GRAPHICS_RESET );
|
|
|
|
sub->addItem(L"Wireframe", DEBUG_GRAPHICS_WIREFRAME );
|
|
|
|
sub->addItem(L"Mipmap viz", DEBUG_GRAPHICS_MIPMAP_VIZ );
|
|
|
|
sub->addItem(L"Normals viz", DEBUG_GRAPHICS_NORMALS_VIZ );
|
|
|
|
sub->addItem(L"SSAO viz", DEBUG_GRAPHICS_SSAO_VIZ );
|
|
|
|
sub->addItem(L"Shadow viz", DEBUG_GRAPHICS_SHADOW_VIZ );
|
|
|
|
sub->addItem(L"Light viz", DEBUG_GRAPHICS_LIGHT_VIZ );
|
|
|
|
sub->addItem(L"Distort viz", DEBUG_GRAPHICS_DISTORT_VIZ );
|
|
|
|
sub->addItem(L"Physics debug", DEBUG_GRAPHICS_BULLET_1);
|
|
|
|
sub->addItem(L"Physics debug (no kart)", DEBUG_GRAPHICS_BULLET_2);
|
|
|
|
|
2014-01-06 19:09:19 -05:00
|
|
|
mnu->addItem(L"Items >",-1,true,true);
|
2013-12-08 20:51:03 -05:00
|
|
|
sub = mnu->getSubMenu(1);
|
|
|
|
sub->addItem(L"Basketball", DEBUG_POWERUP_RUBBERBALL );
|
|
|
|
sub->addItem(L"Bowling", DEBUG_POWERUP_BOWLING );
|
|
|
|
sub->addItem(L"Bubblegum", DEBUG_POWERUP_BUBBLEGUM );
|
|
|
|
sub->addItem(L"Cake", DEBUG_POWERUP_CAKE );
|
2013-12-13 04:06:54 -05:00
|
|
|
sub->addItem(L"Parachute", DEBUG_POWERUP_PARACHUTE );
|
2013-12-08 20:51:03 -05:00
|
|
|
sub->addItem(L"Plunger", DEBUG_POWERUP_PLUNGER );
|
|
|
|
sub->addItem(L"Swatter", DEBUG_POWERUP_SWATTER );
|
|
|
|
sub->addItem(L"Switch", DEBUG_POWERUP_SWITCH );
|
|
|
|
sub->addItem(L"Zipper", DEBUG_POWERUP_ZIPPER );
|
|
|
|
sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO );
|
|
|
|
|
|
|
|
mnu->addItem(L"Profiler",DEBUG_PROFILER);
|
2014-01-24 18:38:47 -05:00
|
|
|
mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS);
|
2013-12-08 20:51:03 -05:00
|
|
|
mnu->addItem(L"FPS",DEBUG_FPS);
|
|
|
|
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
|
|
|
|
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
|
2013-12-08 21:03:16 -05:00
|
|
|
mnu->addItem(L"Toggle GUI", DEBUG_TOGGLE_GUI);
|
2013-12-08 20:51:03 -05:00
|
|
|
|
|
|
|
|
2013-12-08 19:09:35 -05:00
|
|
|
g_debug_menu_visible = true;
|
|
|
|
irr_driver->showPointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let Irrlicht handle the event while the menu is visible - otherwise in a race the GUI events won't be generated
|
|
|
|
if(g_debug_menu_visible)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.EventType == EET_GUI_EVENT)
|
|
|
|
{
|
2013-12-08 20:51:03 -05:00
|
|
|
if (event.GUIEvent.Caller != NULL && event.GUIEvent.Caller->getType() == EGUIET_CONTEXT_MENU )
|
2013-12-08 19:09:35 -05:00
|
|
|
{
|
2013-12-08 20:51:03 -05:00
|
|
|
IGUIContextMenu *menu = (IGUIContextMenu*)event.GUIEvent.Caller;
|
|
|
|
s32 cmdID = menu->getItemCommandId(menu->getSelectedItem());
|
2013-12-08 19:09:35 -05:00
|
|
|
|
2013-12-08 20:51:03 -05:00
|
|
|
if(event.GUIEvent.EventType == EGET_ELEMENT_CLOSED)
|
|
|
|
{
|
|
|
|
g_debug_menu_visible = false;
|
|
|
|
}
|
2013-12-08 19:09:35 -05:00
|
|
|
|
2013-12-08 20:51:03 -05:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED)
|
|
|
|
{
|
2013-12-08 19:09:35 -05:00
|
|
|
if(cmdID == DEBUG_GRAPHICS_RELOAD_SHADERS)
|
|
|
|
{
|
|
|
|
Log::info("Debug", "Reloading shaders...\n");
|
|
|
|
irr_driver->updateShaders();
|
|
|
|
}
|
2013-12-08 20:51:03 -05:00
|
|
|
else if (cmdID == DEBUG_GRAPHICS_RESET)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_WIREFRAME)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleWireframe();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_MIPMAP_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleMipVisualization();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_NORMALS_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleNormals();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_SSAO_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleSSAOViz();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_SHADOW_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleShadowViz();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_LIGHT_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleLightViz();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_DISTORT_VIZ)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);
|
|
|
|
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
irr_driver->toggleDistortViz();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_BULLET_1)
|
|
|
|
{
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world == NULL) return false;
|
|
|
|
world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_KARTS_PHYSICS);
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_GRAPHICS_BULLET_2)
|
|
|
|
{
|
|
|
|
irr_driver->resetDebugModes();
|
|
|
|
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world == NULL) return false;
|
|
|
|
world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_PROFILER)
|
|
|
|
{
|
|
|
|
UserConfigParams::m_profiler_enabled =
|
|
|
|
!UserConfigParams::m_profiler_enabled;
|
|
|
|
}
|
2014-01-24 18:38:47 -05:00
|
|
|
else if (cmdID == DEBUG_THROTTLE_FPS)
|
|
|
|
{
|
|
|
|
main_loop->setThrottleFPS(false);
|
|
|
|
}
|
2013-12-08 20:51:03 -05:00
|
|
|
else if (cmdID == DEBUG_FPS)
|
|
|
|
{
|
|
|
|
UserConfigParams::m_display_fps =
|
|
|
|
!UserConfigParams::m_display_fps;
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_SAVE_REPLAY)
|
|
|
|
{
|
|
|
|
ReplayRecorder::get()->Save();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_SAVE_HISTORY)
|
|
|
|
{
|
|
|
|
history->Save();
|
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_BOWLING)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_BOWLING);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_BUBBLEGUM)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_BUBBLEGUM);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_CAKE)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_CAKE);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
2013-12-13 04:06:54 -05:00
|
|
|
else if (cmdID == DEBUG_POWERUP_PARACHUTE)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_PARACHUTE);
|
2013-12-13 04:06:54 -05:00
|
|
|
}
|
2013-12-08 20:51:03 -05:00
|
|
|
else if (cmdID == DEBUG_POWERUP_PLUNGER)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_PLUNGER);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_RUBBERBALL)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_RUBBERBALL);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_SWATTER)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_SWATTER);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_SWITCH)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_SWITCH);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_ZIPPER)
|
|
|
|
{
|
2013-12-13 05:34:58 -05:00
|
|
|
addPowerup(PowerupManager::POWERUP_ZIPPER);
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
|
|
|
else if (cmdID == DEBUG_POWERUP_NITRO)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world == NULL) return false;
|
2013-12-12 12:51:14 -05:00
|
|
|
for(unsigned int i = 0; i < race_manager->getNumLocalPlayers(); i++)
|
|
|
|
{
|
|
|
|
AbstractKart* kart = world->getLocalPlayerKart(i);
|
|
|
|
kart->setEnergy(100.0f);
|
|
|
|
}
|
2013-12-08 20:51:03 -05:00
|
|
|
}
|
2013-12-08 21:03:16 -05:00
|
|
|
else if (cmdID == DEBUG_TOGGLE_GUI)
|
|
|
|
{
|
|
|
|
World* world = World::getWorld();
|
|
|
|
if (world == NULL) return false;
|
|
|
|
RaceGUIBase* gui = world->getRaceGUI();
|
|
|
|
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
|
|
|
|
|
|
|
|
const int count = World::getWorld()->getNumKarts();
|
|
|
|
for (int n=0; n<count; n++)
|
|
|
|
{
|
|
|
|
AbstractKart* kart = world->getKart(n);
|
|
|
|
if (kart->getController()->isPlayerController())
|
|
|
|
kart->getNode()->setVisible(gui->m_enabled);
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 19:09:35 -05:00
|
|
|
}
|
2013-12-08 20:51:03 -05:00
|
|
|
|
|
|
|
return false; // event has been handled
|
2013-12-08 19:09:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; // continue event handling
|
|
|
|
}
|
|
|
|
|
2013-12-08 21:15:54 -05:00
|
|
|
bool isOpen()
|
|
|
|
{
|
|
|
|
return g_debug_menu_visible;
|
|
|
|
}
|
2013-12-08 19:09:35 -05:00
|
|
|
}
|