// ============================================================== // This file is part of Glest (www.glest.org) // // Copyright (C) 2001-2005 Martiņo Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published // by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version // ============================================================== #include "main.h" #include #include #include "game.h" #include "main_menu.h" #include "program.h" #include "config.h" #include "metrics.h" #include "game_util.h" #include "platform_main.h" #include "platform_util.h" #include "leak_dumper.h" using namespace std; using namespace Shared::Platform; using namespace Shared::Util; namespace Glest{ namespace Game{ // ===================================================== // class ExceptionHandler // ===================================================== class ExceptionHandler: public PlatformExceptionHandler{ public: virtual void handle(string description, void *address){ FILE *f= fopen("crash.txt", "at"); if(f!=NULL){ time_t t= time(NULL); char *timeString= asctime(localtime(&t)); fprintf(f, "Crash\n"); fprintf(f, "Version: %s\n", glestVersionString.c_str()); fprintf(f, "Time: %s", timeString); fprintf(f, "Description: %s\n", description.c_str()); fprintf(f, "Address: %p\n\n", address); fclose(f); } message("An error ocurred and Glest will close.\nCrash info has been saved in the crash.txt file\nPlease report this bug to " + mailString); } }; // ===================================================== // class MainWindow // ===================================================== MainWindow::MainWindow(Program *program){ this->program= program; } MainWindow::~MainWindow(){ delete program; } void MainWindow::eventMouseDown(int x, int y, MouseButton mouseButton){ switch(mouseButton){ case mbLeft: program->mouseDownLeft(x, getH() - y); break; case mbRight: program->mouseDownRight(x, getH() - y); break; default: break; } } void MainWindow::eventMouseUp(int x, int y, MouseButton mouseButton){ if(mouseButton==mbLeft){ program->mouseUpLeft(x, getH() - y); } } void MainWindow::eventMouseDoubleClick(int x, int y, MouseButton mouseButton){ if(mouseButton == mbLeft){ program->mouseDoubleClickLeft(x, getH() - y); } } void MainWindow::eventMouseMove(int x, int y, const MouseState *ms){ program->mouseMove(x, getH() - y, ms); } void MainWindow::eventKeyDown(char key){ program->keyDown(key); } void MainWindow::eventKeyUp(char key){ program->keyUp(key); } void MainWindow::eventActivate(bool active){ if(!active){ minimize(); } } void MainWindow::eventResize(SizeState sizeState){ program->resize(sizeState); } void MainWindow::eventClose(){ delete program; program= NULL; } // ===================================================== // Main // ===================================================== int glestMain(){ MainWindow *mainWindow= NULL; Program *program= NULL; ExceptionHandler exceptionHandler; exceptionHandler.install(); try{ Config &config = Config::getInstance(); showCursor(config.getBool("Windowed")); program= new Program(); mainWindow= new MainWindow(program); program->init(mainWindow); while(Window::handleEvent()){ program->loop(); } } catch(const exception &e){ restoreVideoMode(); exceptionMessage(e); } delete mainWindow; return 0; } }}//end namespace MAIN_FUNCTION(Glest::Game::glestMain)