From 1c7ee8ddcb657300d9e5d643127f7bbf61f6e803 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 13 Oct 2014 15:30:36 +0300 Subject: [PATCH] client/app: F8: Toggle drawing of debug geometry (only for physics at the moment) --- src/client/app.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/app.cpp b/src/client/app.cpp index 68369f7..a2e3b6c 100644 --- a/src/client/app.cpp +++ b/src/client/app.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #pragma GCC diagnostic pop extern "C" { #include @@ -97,6 +98,7 @@ struct CApp: public App, public magic::Application int64_t m_last_script_tick_us; bool m_reboot_requested = false; Options m_options; + bool m_draw_debug_geometry = false; magic::SharedPtr m_scene; magic::SharedPtr m_camera_node; @@ -169,6 +171,8 @@ struct CApp: public App, public magic::Application // Set up event handlers SubscribeToEvent(magic::E_UPDATE, HANDLER(CApp, on_update)); + SubscribeToEvent(magic::E_POSTRENDERUPDATE, + HANDLER(CApp, on_post_render_update)); SubscribeToEvent(magic::E_KEYDOWN, HANDLER(CApp, on_keydown)); SubscribeToEvent(magic::E_SCREENMODE, HANDLER(CApp, on_screenmode)); SubscribeToEvent(magic::E_LOGMESSAGE, HANDLER(CApp, on_logmessage)); @@ -420,6 +424,7 @@ struct CApp: public App, public magic::Application m_scene = new magic::Scene(context_); m_scene->CreateComponent(magic::LOCAL); m_scene->CreateComponent(magic::LOCAL); + m_scene->CreateComponent(magic::LOCAL); // Create a camera and a viewport for the scene. The scene can then be // accessed in Lua by magic.renderer:GetViewport(0):GetScene(). @@ -493,6 +498,13 @@ struct CApp: public App, public magic::Application script_tick(); } + void on_post_render_update( + magic::StringHash event_type, magic::VariantMap &event_data) + { + if(m_draw_debug_geometry) + m_scene->GetComponent()->DrawDebugGeometry(true); + } + void on_keydown(magic::StringHash event_type, magic::VariantMap &event_data) { int key = event_data["Key"].GetInt(); @@ -529,6 +541,9 @@ struct CApp: public App, public magic::Application magic::DebugHud *dhud = GetSubsystem()->CreateDebugHud(); dhud->ToggleAll(); } + if(key == Urho3D::KEY_F8){ + m_draw_debug_geometry = !m_draw_debug_geometry; + } } void on_screenmode(magic::StringHash event_type, magic::VariantMap &event_data)