ScreenDebugOverlay.cpp

Go to the documentation of this file.
00001 #include "global.h"
00002 #include "ScreenDebugOverlay.h"
00003 #include "MercuryScreenManager.h"
00004 #include "MercuryInput.h"
00005 #include "MercuryLog.h"
00006 #include "MercuryTheme.h"
00007 #include "MercuryDisplay.h"
00008 
00009 KeyMappingWithCode( button_F1, "0-282" );
00010 
00011 #include "MercuryObjectFactory.h"
00012 REGISTER_SCREEN_CLASS( ScreenDebugOverlay )
00013 
00014 #define     MC_INPUTMAPPED      1       //convention: MESSAGE CODE
00015 #define     MC_INPUTUNMAPPED    2   
00016 #define     MC_RENDERSTATS      3
00017 #define     MC_TEXTURESTATS     4
00018 
00019 ScreenDebugOverlay::~ScreenDebugOverlay()
00020 {
00021 }
00022 
00023 void ScreenDebugOverlay::Init()
00024 {
00025     MercuryScreen::Init();
00026 
00027 //  SetProjectionType(ORTHOGRAPHIC);
00028 
00029     int fontsize = THEME.GetMetricI( GetName(), "FontSize" );
00030     MString font = THEME.GetMetricS( GetName(), "Font" );
00031 
00032     m_FPS.SetName("FPSDisplay");
00033     m_FPS.Init();
00034     m_FPS.SetFont(font);
00035     m_FPS.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_FPS.GetName() + "OnCommand" ));
00036     m_FPS.SetSize(fontsize);
00037     AddOrthoObject(&m_FPS);
00038 
00039     m_VPF.SetName("VPFDisplay");
00040     m_VPF.Init();
00041     m_VPF.SetFont(font);
00042     m_VPF.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_VPF.GetName() + "OnCommand" ));
00043     m_VPF.SetSize(fontsize);
00044     AddOrthoObject(&m_VPF);
00045 
00046     m_VPS.SetName("VPSDisplay");
00047     m_VPS.Init();
00048     m_VPS.SetFont(font);
00049     m_VPS.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_VPS.GetName() + "OnCommand" ));
00050     m_VPS.SetSize(fontsize);
00051     AddOrthoObject(&m_VPS);
00052 
00053     m_textureCount.SetName("TextureCountDisplay");
00054     m_textureCount.Init();
00055     m_textureCount.SetFont(font);
00056     m_textureCount.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_textureCount.GetName() + "OnCommand" ));
00057     m_textureCount.SetSize(fontsize);
00058     AddOrthoObject(&m_textureCount);
00059 
00060     m_UtextureCount.SetName("UniqueTextureCountDisplay");
00061     m_UtextureCount.Init();
00062     m_UtextureCount.SetFont(font);
00063     m_UtextureCount.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_UtextureCount.GetName() + "OnCommand" ));
00064     m_UtextureCount.SetSize(fontsize);
00065     AddOrthoObject(&m_UtextureCount);
00066 
00067     m_cacheCount.SetName("CacheCountDisplay");
00068     m_cacheCount.Init();
00069     m_cacheCount.SetFont(font);
00070     m_cacheCount.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_cacheCount.GetName() + "OnCommand" ));
00071     m_cacheCount.SetSize(fontsize);
00072     AddOrthoObject(&m_cacheCount);
00073 
00074     m_UcacheCount.SetName("UniqueCacheCountDisplay");
00075     m_UcacheCount.Init();
00076     m_UcacheCount.SetFont(font);
00077     m_UcacheCount.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_UcacheCount.GetName() + "OnCommand" ));
00078     m_UcacheCount.SetSize(fontsize);
00079     AddOrthoObject(&m_UcacheCount);
00080 
00081     m_MercuryLogo.SetName( "MercuryLogoTopScreenText" );
00082     m_MercuryLogo.Init();
00083     m_MercuryLogo.SetFont( font );
00084     m_MercuryLogo.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_MercuryLogo.GetName()+ "OnCommand" ));
00085     m_MercuryLogo.SetSize( fontsize );
00086     m_MercuryLogo.SetText( THEME.GetMetricS( GetName(), m_MercuryLogo.GetName()+ "Text" ) );
00087     AddOrthoObject(&m_MercuryLogo);
00088 
00089     this->RegisterMessage( MC_RENDERSTATS, "RenderStats" );
00090     this->RegisterMessage( MC_TEXTURESTATS, "TextureStats" );
00091     this->RegisterMessage( MC_INPUTMAPPED, "mappedinput" );
00092 }
00093 
00094 void ScreenDebugOverlay::Message( int Message, PStack & data, const MString & name )
00095 {
00096     switch ( Message ) 
00097     {
00098     case MC_RENDERSTATS:
00099         {
00100             if ( IsHidden() )
00101                 break;
00102             m_FPS.SetText(ssprintf("FPS: %f", data.PeekItem(2).GetValueF()));
00103             m_VPF.SetText(ssprintf("VPF: %f", data.PeekItem(1).GetValueF()));
00104             m_VPS.SetText(ssprintf("VPS: %f", data.PeekItem(0).GetValueF()));
00105         }
00106         break;
00107     case MC_TEXTURESTATS:
00108         {
00109             if ( IsHidden() )
00110                 break;
00111             m_textureCount.SetText(ssprintf("TC: %d", data.PeekItem(1).GetValueI()));
00112             m_UtextureCount.SetText(ssprintf("UTC: %d", data.PeekItem(0).GetValueI()));
00113         }
00114         break;
00115     case MC_INPUTMAPPED:
00116         {
00117             InputMessageStruct c(data);
00118             if ( c.code == button_F1 )
00119             {
00120                 if ( c.type == IET_RELEASE )
00121                 {
00122                     SetHide(!GetHide());
00123                 }
00124             }
00125         }
00126         break;
00127     };
00128 }
00129 
00130 /* 
00131  * Copyright (c) 2005-2006 Joshua Allen
00132  * All rights reserved.
00133  *
00134  * Redistribution and use in source and binary forms, with or
00135  * without modification, are permitted provided that the following
00136  * conditions are met:
00137  *  -   Redistributions of source code must retain the above
00138  *      copyright notice, this list of conditions and the following disclaimer.
00139  *  -   Redistributions in binary form must reproduce the above copyright
00140  *      notice, this list of conditions and the following disclaimer in
00141  *      the documentation and/or other materials provided with the distribution.
00142  *  -   Neither the name of the Mercury Engine nor the names of its
00143  *      contributors may be used to endorse or promote products derived from
00144  *      this software without specific prior written permission.
00145  *
00146  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00147  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00148  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00149  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00150  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00151  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00152  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00153  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00154  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00155  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00156  */

Hosted by SourceForge.net Logo