00001 #ifdef _LIB
00002 
00003 #include "ImageLoaders.cpp"
00004 #include "ImageLoaderTGA.cpp"
00005 #include "ScreenDebugOverlay.cpp"
00006 #include "ScreenCopper.cpp"
00007 #include "CopperWindow.cpp"
00008 #include "CopperPrimitives.cpp"
00009 #endif
00010 #include "global.h"
00011 #include "Mercury.h"
00012 #include "MercuryDisplay.h"
00013 #include "MercuryTextureManager.h"
00014 #include "Crash/archCrash.h"
00015 #include "MercuryTimer.h"
00016 #include "MercuryInput.h"
00017 #include "MercuryMessages.h"
00018 #include "MercuryScreenManager.h"
00019 #include "MercuryTheme.h"
00020 #include "MercuryLog.h"
00021 #include "MercuryObjectFactory.h"
00022 #include "MercurySoundDriver.h"
00023 
00024 #if defined (_EE)
00025 #include "MercuryDisplayEE.h"
00026 #endif
00027 MercuryDisplay* DISPLAY = NULL;
00028 MercuryTextureManager* TEXTMAN = NULL;
00029 MercuryScreenManager* SCREENMAN = NULL;
00030 MercuryINI* PREFSMAN = NULL;
00031 MercuryTimer gameTimer;
00032 
00033 
00034 volatile float DTIME;
00035 
00036 KeyMappingWithCode( button_Pause, "0-19" );
00037 
00038 
00039 
00040 REGISTER_STATEMENT_TO_MESSAGE( Pause,mappedinput,
00041                               InputMessageStruct c(args);
00042                             if (c.code == button_Pause && c.type == IET_DOWN )
00043                                 gameTimer.Pause();
00044 )
00045 
00046 int HGEXPORT StartMercury()
00047 {
00048     char ** C;
00049     C = new (char*);
00050     (*C) = "nothing";
00051     int ret = InitializeMercury( 1, C );
00052     delete C;
00053     return ret;
00054 }
00055 
00056 int HGEXPORT InitializeMercury( int argc, char**argv )
00057 {
00058     StartCrashHandler( argv, argc );
00059     LOG.Info("Initializing Mercury()");
00060     CheckPREFSMANSetup();
00061     if ( !MESSAGEMAN )
00062         MESSAGEMAN = new MercuryMessageManager;
00063     INPUTMAN = new MercuryInputManager;
00064     DTIME = 0;
00065     DISPLAY = MakeDisplayDriver();
00066 
00067 
00068 
00069 
00070     if ( !DISPLAY->Init(
00071         PREFSMAN->GetValueS( "Window", "Name", InitialWindowProperties::ProductName, true ).c_str(),
00072         PREFSMAN->GetValueI( "Window", "Width", InitialWindowProperties::WindowWidth, true ),
00073         PREFSMAN->GetValueI( "Window", "Height", InitialWindowProperties::WindowHeight, true ),
00074         PREFSMAN->GetValueI( "Window", "BPP", InitialWindowProperties::WindowBPP, true ),
00075         PREFSMAN->GetValueB( "Window", "Fullscreen", InitialWindowProperties::WindowFullscreen, true )
00076         ) )
00077     {
00078         LOG.Warn("Failed to initalize display.");
00079         return -1;
00080     }
00081 
00082 
00083     SCREENMAN = new MercuryScreenManager;
00084     TEXTMAN = new MercuryTextureManager;
00085 
00086     MercuryObjectFactory::GetInstance().FinalizeCallbacks();
00087 
00088 #ifdef _DEBUG_MEMORY
00089     ResetAllLeakInfo();
00090     SetPrintOnEnd(true);
00091 #endif
00092 
00093     
00094 
00095 
00096 
00097     TEXTMAN->CreateThread();
00098     SCREENMAN->SetPrimaryScreen( THEME.GetMetricS( "Common", "InitialScreen" ) );
00099     
00100     
00101     MString sOverlay = THEME.GetMetricS( "Common", "OverlayScreen" );
00102     while ( sOverlay.size() > 0 )
00103     {
00104         int i = BytesUntil( sOverlay.c_str(), ",", 0, sOverlay.length(), 1 );   
00105         if ( i == (int)sOverlay.size() )
00106         {
00107             SCREENMAN->AddScreen( sOverlay );   
00108             break;
00109         }
00110         SCREENMAN->AddScreen( sOverlay.substr( 0, i ) );    
00111         sOverlay = sOverlay.substr( i+1 );                  
00112     }
00113     gameTimer.Touch();
00114     return 0;
00115 }
00116 
00117 int HGEXPORT UpdateMercury( float &dTime )
00118 {
00119 
00120     if ( dTime <= 0 )
00121     {
00122 #ifndef _EE
00123         DTIME = dTime = float(gameTimer.Age());
00124 #else
00125         dTime = .033333f;
00126 #endif
00127     }
00128 
00129     gameTimer.Touch();
00130     if (SCREENMAN)
00131     {
00132         DISPLAY->EndFrame(); 
00133         DISPLAY->BeginFrame();
00134         SCREENMAN->Update(dTime);
00135         TEXTMAN->Update(dTime);
00136 
00137     }
00138     MESSAGEMAN->Update(dTime);
00139     INPUTMAN->Update();
00140     return DISPLAY->Update(dTime);
00141 }
00142 
00143 void HGEXPORT CloseMercury()
00144 {
00145     
00146     SAFE_DELETE(SCREENMAN);
00147 
00148     FONTHASH.Destroy();
00149     SAFE_DELETE(TEXTMAN);
00150     SAFE_DELETE(DISPLAY);
00151     SAFE_DELETE(INPUTMAN);
00152     SAFE_DELETE(PREFSMAN);
00153     SAFE_DELETE(MESSAGEMAN);
00154     LOG.Info( "CloseMercury done." );
00155     OBJECTREGISTER.ShutDown();
00156     BENCHMARK.Print();
00157 }
00158 
00159 #if !defined( MAKE_DLL )
00160 int main(int argc, char* argv[]) {
00161     if ( InitializeMercury( argc, argv ) != 0 )
00162     {
00163         printf( "Mercury Initialization failed.\n" );
00164         return -1;
00165     }
00166 
00167     float dTime = -1;
00168     do {
00169         
00170         dTime = -1; 
00171     } while ( UpdateMercury( dTime ) );
00172 
00173     CloseMercury();
00174     return 0;
00175 }
00176 #else
00177 bool HGEXPORT DllMain( HANDLE hModule, 
00178                        DWORD  ul_reason_for_call, 
00179                        LPVOID lpReserved
00180                      )
00181 {
00182     switch (ul_reason_for_call)
00183     {
00184     case DLL_PROCESS_ATTACH:
00185     case DLL_THREAD_ATTACH:
00186     case DLL_THREAD_DETACH:
00187     case DLL_PROCESS_DETACH:
00188         break;
00189     }
00190     return TRUE;
00191 }
00192 
00193 #endif
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221