示例#1
0
int main(int argc, char* argv[])
#endif
{
    setlocale(LC_NUMERIC, "C");

    std::stringstream dummy;
    PATHMANAGER::Init(dummy, dummy);

    ///  open Log file
    //----------------------------------------------------------------
    std::string logfilename = PATHMANAGER::GetLogDir() + "/log.txt";
    std::ofstream logfile(logfilename.c_str());
    if (!logfile)
    {
        std::cerr << "Couldn't open log file: " << logfilename << std::endl;
        return EXIT_FAILURE;
    }

    //  set up logging arrangement
    logging::splitterstreambuf infosplitter(std::cout, logfile);
    std::ostream infosplitterstream(&infosplitter);
    logging::splitterstreambuf errorsplitter(std::cerr, logfile);
    std::ostream errorsplitterstream(&errorsplitter);
    logging::logstreambuf infolog("INFO: ", infosplitterstream);	//logstreambuf infolog("INFO: ", logfile);
    logging::logstreambuf errorlog("ERROR: ", errorsplitterstream);

    //  primary logging ostreams
    std::ostream info_output(&infolog);
    std::ostream error_output(&errorlog);/**/


    ///  Load Settings
    //----------------------------------------------------------------
    SETTINGS* settings = new SETTINGS();
    std::string setFile = PATHMANAGER::GetSettingsFile();

    if (!PATHMANAGER::FileExists(setFile))
    {
        info_output << "Settings not found - loading defaults." << std::endl;
        LoadDefaultSet(settings,setFile);
    }
    settings->Load(setFile);  // LOAD
    if (settings->version != SET_VER)  // loaded older, use default
    {
        info_output << "Settings found, but older version - loading defaults." << std::endl;
        LoadDefaultSet(settings,setFile);
        settings->Load(setFile);  // LOAD
    }

    // HACK: we initialize paths a second time now that we have the output streams
    PATHMANAGER::Init(info_output, error_output);


    ///  Game start
    //----------------------------------------------------------------
    GAME* pGame = new GAME(info_output, error_output, settings);
    std::list <std::string> args;//(argv, argv + argc);
    pGame->Start(args);  //game.End();

    App* pApp = new App();
    pApp->pSet = settings;
    pApp->pGame = pGame;
    pGame->pOgreGame = pApp;

    try
    {
        if (settings->multi_thr > 0)
            boost::thread t(VprThread, pApp);

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        pApp->Run( settings->ogre_dialog || lpCmdLine[0]!=0 );  //Release change-
#else
        pApp->Run( settings->ogre_dialog);
#endif
    }
    catch (Ogre::Exception& e)
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
#endif
    }

    info_output << "Exiting" << std::endl;
    delete pApp;
    delete pGame;
    delete settings;
    return 0;
}
示例#2
0
	int main(int argc, char* argv[])
#endif
{
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
	//XInitThreads();
#endif
	
	setlocale(LC_NUMERIC, "C");

	PATHMANAGER::Init(std::cout, std::cerr);


	std::streambuf* oldCout = std::cout.rdbuf();
	std::streambuf* oldCerr = std::cerr.rdbuf();

	#if 0
    std::string po = PATHMANAGER::UserConfigDir() + "/ogre_ed.out";
    std::ofstream out(po.c_str());
    std::cout.rdbuf(out.rdbuf());  // redirect std::cout to out.txt
    #endif

	#if 1
    std::string pa = PATHMANAGER::UserConfigDir() + "/ogre_ed.err";
    std::ofstream oute(pa.c_str());
    std::cerr.rdbuf(oute.rdbuf());  // redirect std::cerr to oute.txt
    #endif
	

	///  Load Settings
	//----------------------------------------------------------------
	SETTINGS* settings = new SETTINGS();
	std::string setFile = PATHMANAGER::EditorSetFile();

	if (!PATHMANAGER::FileExists(setFile))
	{
		std::cout << "Settings not found - loading defaults." << std::endl;
		LoadDefaultSet(settings,setFile);
	}
	settings->Load(setFile);  // LOAD
	if (settings->version != SET_VER)  // loaded older, use default
	{
		std::cout << "Settings found, but older version - loading defaults." << std::endl;
		boost::filesystem::rename(setFile, PATHMANAGER::UserConfigDir() + "/editor_old.cfg");
		LoadDefaultSet(settings,setFile);
		settings->Load(setFile);  // LOAD
	}


	//  Start
	//----------------------------------------------------------------
	App* pApp = new App(settings);

	try
	{
		#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
			pApp->Run( settings->ogre_dialog || lpCmdLine[0]!=0 );
		#else
			pApp->Run( settings->ogre_dialog );
		#endif
	}
	catch (Ogre::Exception& e)
	{
		#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
			MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
		#else
			std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
		#endif
	}

	pApp->SaveCam();
	delete pApp;
	
	settings->Save(setFile);
	delete settings;

	std::cout.rdbuf(oldCout);
	std::cerr.rdbuf(oldCerr);

	return 0;
}