00001 #include "global.h" 00002 #include "MercuryScreenManager.h" 00003 #include "MercuryDisplay.h" 00004 #include "MercuryTheme.h" 00005 #include "MercuryLog.h" 00006 00007 REGISTER_STATEMENT_TO_MESSAGE( SetPrimaryScreen, SetPrimaryScreen, SCREENMAN->SetPrimaryScreen( args.PopItem().GetValueS() );) 00008 00009 MercuryScreenManager::MercuryScreenManager() 00010 { 00011 m_primary = NULL; 00012 m_current = NULL; 00013 } 00014 00015 MercuryScreenManager::~MercuryScreenManager() 00016 { 00017 //OK, the STL does some very weird stuff on this one in VS .net 2k5. 00018 //Apparently when the fix for that is put in place, VC6, and .net 2k3 00019 //start leaking here, so... To be safe, we're walking in reverse through 00020 //the vector and deleting it. 00021 00022 for( MDequeIterator<MercuryScreen*> i = m_screens.begin(); i != m_screens.end(); ++i ) 00023 SAFE_DELETE( *i ); 00024 00025 SAFE_DELETE(m_primary); 00026 } 00027 00028 void MercuryScreenManager::Update(const float dTime) 00029 { 00030 if (m_primary != NULL) 00031 { 00032 m_current = m_primary; 00033 m_current->Update(dTime); 00034 m_current->Render(); 00035 } 00036 00037 for( MDequeIterator<MercuryScreen*> i = m_screens.begin(); i != m_screens.end(); ) 00038 { 00039 m_current = (*i); 00040 m_current->Update(dTime); 00041 m_current->Render(); 00042 00043 //Only clear the ZBuffer if we have other screens to draw (expensive) 00044 if ( ++i != m_screens.end() ) 00045 DISPLAY->ClearZBuffer(); 00046 } 00047 m_current = NULL; 00048 } 00049 00050 void MercuryScreenManager::SetPrimaryScreen( MString name ) 00051 { 00052 SAFE_DELETE( m_primary ); 00053 00054 MString ScreenName; 00055 ScreenName = THEME.GetMetricS( name, "Class", "" ); 00056 00057 if ( ScreenName.length() == 0 ) 00058 { 00059 LOG.Warn( "Cannot find a screen class for " + name ); 00060 return; 00061 } 00062 00063 if ( (*ToMakeScreens).find(ScreenName) == (*ToMakeScreens).end() ) 00064 { 00065 LOG.Warn( "The Screen Class " + ScreenName + " does not exist!" ); 00066 return; 00067 } 00068 00069 DISPLAY->ResetFrustumClippingPlanes(); 00070 00071 m_primary = (*ToMakeScreens)[ScreenName]( name ); 00072 } 00073 00074 00075 void MercuryScreenManager::AddScreen(MercuryScreen* screen) 00076 { 00077 m_screens.push_back(screen); 00078 } 00079 00080 void MercuryScreenManager::AddScreen(MString name) 00081 { 00082 MString ScreenName; 00083 ScreenName = THEME.GetMetricS( name, "Class", "" ); 00084 00085 if ( ScreenName.length() == 0 ) 00086 { 00087 LOG.Warn( "Cannot find a screen class for " + name ); 00088 return; 00089 } 00090 00091 if ( (*ToMakeScreens).find(ScreenName) == (*ToMakeScreens).end() ) 00092 { 00093 LOG.Warn( "The Screen Class " + ScreenName + " does not exist!" ); 00094 return; 00095 } 00096 00097 //Screen's INIT must be called here but WTF 00098 AddScreen( (*ToMakeScreens)[ScreenName]( name ) ); 00099 } 00100 00101 void MercuryScreenManager::RemoveScreen(MercuryScreen* screen, bool delScreen) 00102 { 00103 for( MDequeIterator<MercuryScreen*> i = m_screens.begin(); i != m_screens.end(); ++i ) 00104 { 00105 if ((*i) == screen) 00106 { 00107 LOG.Log( "Screen " + (*i)->GetName() + " removed" ); 00108 if (delScreen) 00109 SAFE_DELETE(*i); 00110 m_screens.erase(i); 00111 return; 00112 } 00113 } 00114 } 00115 00116 void MercuryScreenManager::RemoveScreen(MString name, bool delScreen) 00117 { 00118 for( MDequeIterator<MercuryScreen*> i = m_screens.begin(); i != m_screens.end(); ++i ) 00119 { 00120 if ((*i)->GetName() == name) 00121 { 00122 LOG.Log( "Screen " + (*i)->GetName() + " removed" ); 00123 if (delScreen) 00124 SAFE_DELETE(*i); 00125 m_screens.erase(i); 00126 return; 00127 } 00128 } 00129 } 00130 00131 /* 00132 * Copyright (c) 2005-2006, Joshua Allen 00133 * All rights reserved. 00134 * 00135 * Redistribution and use in source and binary forms, with or 00136 * without modification, are permitted provided that the following 00137 * conditions are met: 00138 * - Redistributions of source code must retain the above 00139 * copyright notice, this list of conditions and the following disclaimer. 00140 * - Redistributions in binary form must reproduce the above copyright 00141 * notice, this list of conditions and the following disclaimer in 00142 * the documentation and/or other materials provided with the distribution. 00143 * - Neither the name of the Mercury Engine nor the names of its 00144 * contributors may be used to endorse or promote products derived from 00145 * this software without specific prior written permission. 00146 * 00147 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00148 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00149 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00150 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00151 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00152 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00153 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00154 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00155 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00156 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00157 */