//========= Copyright © 2007, addiktiveGAMING - TEAMLegend, All rights reserved. =========// // // Purpose: Legend Application // File: LegendApp.cpp //========================================================================================// #include "cbase.h" #include "LegendApp.h" #include "iniparser/IniFile.h" #include "GameTime.h" VSmartPtr CLegendApp::m_spInstance = NULL; VIMPORT void VisionEnginePlugin_InitEnginePlugin(); VIMPORT void VisionEnginePlugin_DeInitEnginePlugin(); CLegendApp::CLegendApp() { m_pState = NULL; } CLegendApp::~CLegendApp() { LuaManager::DeleteSingleton(); } void CLegendApp::InitPlugins() { VisionEnginePlugin_InitEnginePlugin(); if ( !Vision::Plugins.LoadEnginePlugin( "Legend" ) ) Vision::Error.FatalError( "Could not load Legend.vPlugin" ); } void CLegendApp::InitDirectories() { //FIXME: Read ini file for location of data if ( _chdir( LEGEND_DATA_PATH ) != 0 ) Vision::Error.FatalError( "Data files must exist in: %s", LEGEND_DATA_PATH ); Vision::File.AddDataDirectory( "./" ); } void CLegendApp::InitConfig(int& Xre, int& Yre, bool& Full) { dictionary_t *d = Dictionary_CreateDictionary (0); // initialize a new dictionary INIFile_LoadINIFile (LEGEND_INI_NAME, d); // load an INI file into that dictionary Xre = INIFile_ReadEntryAsLong(d, "Display","iXres",1024); //Xre = 1024; Yre = INIFile_ReadEntryAsLong(d, "Display","iYres",768); //Yre = 768; Full = INIFile_ReadEntryAsBool(d, "Display","bFullScreen",true); //Full = false; INIFile_SaveINIFile (LEGEND_INI_NAME, d); // save the INI data back to a file Dictionary_DestroyDictionary (d); // don't forget to destroy the dictionary } bool CLegendApp::InitLegend() { int Xres, Yres; bool FullScreen; InitConfig(Xres, Yres, FullScreen); Vision::SetApplication( this ); InitDirectories(); InitPlugins(); InitDisplay(Xres, Yres, FullScreen); InitControls(); m_luaManager = LuaManager::GetSingleton(); m_luaManager->Init(); // Initialize the engine if ( !InitEngine() ) { Vision::Error.FatalError( "Failed to initialize the engine" ); return false; } //initiate game timer LegendTime LegendTime; LegendTime.InitGameTimer(); Vision::Renderer.SetDefaultTextureFilterMode( FILTER_MIN_MAG_MIP_LINEAR ); EnterState( new MainMenuState() ); return true; } void CLegendApp::InitControls() { //TODO: Use ini file for setting these Vision::Key.SetSingleHit( VGLK_ESC ); Vision::Key.SetSingleHit( VGLK_F1 ); Vision::Key.SetSingleHit( VGLK_F2 ); Vision::Key.SetSingleHit( VGLK_L ); } void CLegendApp::InitDisplay(const SLONG xres, const SLONG yres, const bool fullscr) { m_sWindowTitle = "Legend"; m_appConfig.m_videoConfig.m_eMultiSample = VVIDEO_MULTISAMPLE_2TIMES; m_appConfig.m_videoConfig.m_bFullScreen = fullscr; m_appConfig.m_videoConfig.m_iXRes = xres; m_appConfig.m_videoConfig.m_iYRes = yres; } void CLegendApp::DeInitLegend() { EndCurrentState(); DeInitEngine(); Vision::Plugins.UnloadEnginePlugin( "Legend" ); VisionEnginePlugin_DeInitEnginePlugin(); } bool CLegendApp::Run() { LegendTime LegendTime; //LegendTime.UpdateGameTimer(); if ( Vision::Key.IsPressed(VGLK_F1) ) EnterState( new InGameState() ); if ( Vision::Key.IsPressed(VGLK_ESC) ) EnterState( new MainMenuState() ); if ( Vision::Key.IsPressed(VGLK_L) ) m_luaManager->Execute(); //ugly test for the timer if ( Vision::Key.IsPressed(VGLK_T)) { std::string msg1 = boost::lexical_cast(LegendTime.GetGameHour()) + ":"; std::string msg2 = boost::lexical_cast(LegendTime.GetGameMin()) + " of the "; std::string msg3 = boost::lexical_cast(LegendTime.GetGameDay()) + "th day of the "; std::string msg4 = boost::lexical_cast(LegendTime.GetGameMonth()) + "th month of the year "; std::string msg5 = boost::lexical_cast(LegendTime.GetGameYear()) + "!"; std::string msg = msg1 + msg2 + msg3 + msg4 + msg5; const char* msg76 = msg.c_str(); Vision::Message.Add(1, msg76); } if ( !m_pState->Run() ) return false; return VisionApp_cl::Run(); }