From 20b291c48bf5bbfca45ba1495f2616ee1ccafa47 Mon Sep 17 00:00:00 2001
From: Sam Hocevar <sam@hocevar.net>
Date: Tue, 9 Oct 2012 12:26:48 +0000
Subject: [PATCH] neercs: don't show the FPS information unless the setup is
 open.

---
 neercs/neercs.cpp       |  1 -
 neercs/video/render.cpp | 18 +++++++++++++++++-
 neercs/video/render.h   |  2 ++
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/neercs/neercs.cpp b/neercs/neercs.cpp
index 2c367ab..18a34ea 100644
--- a/neercs/neercs.cpp
+++ b/neercs/neercs.cpp
@@ -80,7 +80,6 @@ int main(int argc, char **argv)
 #endif
 
     new Neercs(argc, argv);
-    new DebugFps(2, 2);
     app.ShowPointer(false);
 
     app.Run();
diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp
index d6a0f53..7ada5c5 100644
--- a/neercs/video/render.cpp
+++ b/neercs/video/render.cpp
@@ -601,6 +601,7 @@ int Render::CreateGLWindow()
 Render::Render(caca_canvas_t *caca)
   : m_cv_screen(caca),
     m_cv_setup(caca_create_canvas(1, 1)),
+    m_fps_debug(0),
     m_ready(false),
     m_pause(false),
     m_polygon(true),
@@ -735,6 +736,18 @@ void Render::TickDraw(float seconds)
         if (g_setup) setup_n = calc_item_length();
         sync_flag = true;
         sync_angle = main_angle;
+
+        if (m_fps_debug)
+        {
+            Ticker::Unref(m_fps_debug);
+            m_fps_debug = NULL;
+        }
+
+        if (g_setup)
+        {
+            m_fps_debug = new DebugFps(2, 2);
+            Ticker::Ref(m_fps_debug);
+        }
     }
     if (Input::WasPressed(Key::F2))
     {
@@ -1330,4 +1343,7 @@ void Render::Draw3D()
 
 Render::~Render()
 {
-}
\ No newline at end of file
+    if (m_fps_debug)
+        Ticker::Unref(m_fps_debug);
+}
+
diff --git a/neercs/video/render.h b/neercs/video/render.h
index f140add..4f5b0e9 100644
--- a/neercs/video/render.h
+++ b/neercs/video/render.h
@@ -33,6 +33,8 @@ private:
     caca_canvas_t *m_cv_screen, *m_cv_setup;
     class TextRender *m_txt_screen, *m_txt_setup;
 
+    Entity *m_fps_debug;
+
     bool m_ready;
     bool m_pause;
     bool m_polygon;