edmain.cpp

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the 
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <algorithm>
00026 #include <memory>
00027 #include <SDL_image.h>
00028 #include <signal.h>
00029 
00030 #include "edmisc.h"
00031 #include "loadbi3.h"
00032 #include "edselfnt.h"
00033 #include "edglobal.h"
00034 #include "errors.h"
00035 #include "gameoptions.h"
00036 #include "mapdisplay.h"
00037 #include "itemrepository.h"
00038 #include "loadimage.h"
00039 #include "graphicset.h"
00040 #include "paradialog.h"
00041 #include "soundList.h"
00042 #include "maped-mainscreen.h"
00043 #include "cannedmessages.h"
00044 #include "stdio-errorhandler.h"
00045 #include "unitset.h"
00046 #include "widgets/textrenderer-addons.h"
00047 #include "spfst-legacy.h"
00048 #include "dataversioncheck.h"
00049 #include "tasks/taskhibernatingcontainer.h"
00050 
00051 #ifdef WIN32
00052 # include "win32/win32-errormsg.h"
00053 # include  "win32/msvc/mdump.h"
00054  MiniDumper miniDumper( "mapeditor" );
00055 #endif
00056 
00057 
00058 
00059 // #define MEMCHK
00060 #include "memorycheck.cpp"
00061 
00062 pfont load_font(const char* name)
00063 {
00064    tnfilestream stream ( name, tnstream::reading );
00065    return loadfont ( &stream );
00066 }
00067 
00068 
00069 void loadEditordata( void ) 
00070 {
00071    loadmessages();
00072 
00073    dataLoaderTicker();
00074 
00075    GraphicSetManager::Instance().loadData();
00076       
00077    registerDataLoader ( new PlayListLoader() );
00078    registerDataLoader ( new BI3TranslationTableLoader() );
00079 
00080    loadAllData();
00081 
00082    dataLoaderTicker();
00083 
00084    loadUnitSets();
00085 
00086    schriften.smallarial = load_font("smalaril.fnt");
00087    schriften.large = load_font("usablack.fnt");
00088    schriften.arial8 = load_font("arial8.fnt");
00089    schriften.smallsystem = load_font("msystem.fnt");
00090    schriften.monogui = load_font("monogui.fnt");
00091 
00092    uselessCallToTextRenderAddons();
00093 }
00094 
00095 void buildemptymap ( void )
00096 {
00097    TerrainType::Weather* w = terrainTypeRepository.getObject_byID(30)->weather[0];
00098    if ( !w )
00099       w = terrainTypeRepository.getObject_byPos(0)->weather[0];
00100 
00101    actmap = new GameMap;
00102    actmap->allocateFields( 10, 20, w );
00103 }
00104 
00105 
00106 int mapeditorMainThread ( void* _mapname )
00107 {
00108    const char* mapname = (const char*) _mapname;
00109    loadpalette();
00110 
00111    try {
00112       StartupScreen sus( "title_mapeditor.jpg", dataLoaderTicker );
00113       
00114       GraphicSetManager::Instance().loadData();
00115       loadEditordata();
00116 
00117       if ( mapname && mapname[0] ) {
00118          /*
00119          if( patimat ( savegameextension, mapname )) {
00120             if( validatesavfile( mapname ) == 0 )
00121                fatalError ( "The savegame %s is invalid. Aborting.", mapname );
00122 
00123             try {
00124                loadgame( mapname );
00125             } catch ( tfileerror ) {
00126                fatalError ( "%s is not a legal savegame. ", mapname );
00127             }
00128       } else*/
00129             if( patimat ( mapextension, mapname )) 
00130                actmap = mapLoadingExceptionChecker( mapname, MapLoadingFunction( tmaploaders::loadmap )); 
00131             else
00132                fatalError ( "%s is not an accepted file format", mapname );
00133       } else
00134          buildemptymap();
00135 
00136       mapSwitcher.toggle();
00137       if ( exist ( "palette.map" ))
00138          actmap = mapLoadingExceptionChecker( "palette.map", MapLoadingFunction( tmaploaders::loadmap )); 
00139       
00140       if (!actmap )
00141          buildemptymap();
00142 
00143       actmap->preferredFileNames.mapname[0] = "";
00144 
00145       mapSwitcher.toggle();
00146 
00147    } /* end try */
00148    catch ( ParsingError err ) {
00149       fatalError ( "Error parsing text file " + err.getMessage() );
00150    }
00151    catch ( tfileerror err ) {
00152       fatalError ( "Error loading file " + err.getFileName() );
00153    } /* end catch */
00154    catch ( ASCmsgException err ) {
00155       fatalError( "Error loading file " + err.getMessage() );
00156    }
00157 
00158    activefontsettings.font = schriften.arial8;
00159    activefontsettings.color =lightblue ;
00160    activefontsettings.background =3;
00161    activefontsettings.length =100;
00162    activefontsettings.justify =lefttext;
00163 
00164 
00165    setstartvariables();
00166 
00167    mainScreenWidget = new Maped_MainScreenWidget( getPGApplication());
00168    mainScreenWidget->Show();
00169    
00170    mousevisible(true);
00171 
00172    getPGApplication().Run();
00173 
00174    if (mapsaved == false )
00175       if (choice_dlg("You have unsaved changes! Save?","~y~es","~n~o") == 1)
00176          k_savemap(false);
00177   
00178    if ( actmap ) {
00179       delete actmap;
00180       actmap = NULL;
00181    }
00182    return 0;
00183 }
00184 
00185 // including the command line parser, which is generated by genparse
00186 #include "clparser/mapedit.cpp"
00187 
00188 void setSaveNotification()
00189 {
00190    mapsaved = false;
00191 }
00192 
00193 int main(int argc, char *argv[] )
00194 {
00195  
00196    StdIoErrorHandler stdIoErrorHandler(false);
00197    
00198    putenv(const_cast<char*>("SDL_VIDEO_CENTERED=1")) ;
00199 
00200    Cmdline* cl = NULL;
00201    try {
00202       cl = new Cmdline ( argc, argv );
00203    }
00204    catch ( string s ) {
00205       cerr << s;
00206       exit(1);
00207    }
00208    auto_ptr<Cmdline> apcl ( cl );
00209 
00210    if ( cl->next_param() < argc ) {
00211       cerr << "invalid command line parameter\n";
00212       exit(1);
00213    }
00214 
00215    if ( cl->v() ) {
00216       ASCString msg = kgetstartupmessage();
00217       printf( "%s", msg.c_str() );
00218       exit(0);
00219    }
00220 
00221    MessagingHub::Instance().setVerbosity( cl->r() );
00222    MessagingHub::Instance().exitHandler.connect( SigC::bind( SigC::slot( exit_asc ), -1 ));
00223 
00224    #ifdef logging
00225     logtofile ( kgetstartupmessage() );
00226     logtofile ( "\n new log started \n ");
00227    #endif
00228 
00229 #ifdef WIN32
00230    Win32IoErrorHandler* win32ErrorDialogGenerator = new Win32IoErrorHandler;
00231 #endif
00232 
00233    ConfigurationFileLocator::Instance().setExecutableLocation( argv[0] );
00234    initFileIO( cl->c() );
00235 
00236    signal ( SIGINT, SIG_IGN );
00237 
00238    bool fullscreen = !CGameOptions::Instance()->mapeditWindowedMode;
00239    if ( cl->f() )
00240       fullscreen = true;
00241    if (  cl->w() )
00242       fullscreen = false;
00243 
00244    checkDataVersion();
00245 
00246    // determining the graphics resolution
00247    int xr  = CGameOptions::Instance()->mapeditor_xresolution;
00248    if ( cl->x() != 800 )
00249       xr = cl->x();
00250 
00251    int yr  = CGameOptions::Instance()->mapeditor_yresolution;
00252    if ( cl->y() != 600 )
00253       yr = cl->y();
00254 
00255    PG_FileArchive archive( argv[0] );
00256 
00257    ASC_PG_App app ( "asc2_dlg" );
00258    
00259    int flags = SDL_SWSURFACE;
00260    if ( fullscreen )
00261       flags |= SDL_FULLSCREEN;
00262    
00263    app.setIcon( "mapeditor-icon.png" );
00264    if ( !app.InitScreen( xr, yr, 32, flags))
00265       fatalError( "Could not initialize video mode");
00266 #ifdef WIN32
00267    delete win32ErrorDialogGenerator;
00268 #endif
00269       
00270    #ifdef pbpeditor
00271    setWindowCaption ( "PBP Editor - Advanced Strategic Command");
00272    #else
00273    setWindowCaption ( "Map Editor - Advanced Strategic Command");
00274    #endif
00275 
00276    virtualscreenbuf.init();
00277 
00278    mapChanged.connect( SigC::hide<GameMap*>( repaintMap.slot() ) );
00279    mapChanged.connect( SigC::hide<GameMap*>( updateFieldInfo.slot() ) );
00280    mapChanged.connect( SigC::hide<GameMap*>( SigC::slot( setSaveNotification) ));
00281    
00282    TaskHibernatingContainer::registerHooks();
00283 
00284    
00285    char* buf = new char[cl->l().length()+10];
00286    strcpy ( buf, cl->l().c_str() );
00287    initializeEventHandling ( mapeditorMainThread, buf  );
00288    delete[] buf;
00289 
00290    writegameoptions ();
00291    
00292    mapSwitcher.deleteMaps();
00293 
00294    return 0;
00295 }
00296 

Generated on Mon May 21 01:26:32 2012 for Advanced Strategic Command by  doxygen 1.5.1