Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

graphicset.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           graphicset.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jan 28 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00014 /***************************************************************************
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #include <map>
00024 
00025 #include "basestrm.h"
00026 #include "misc.h"
00027 #include "graphicset.h"
00028 // #include "basegfx.h"
00029 #include "errors.h"
00030 #include "typen.h"
00031 #include "sgstream.h"
00032 
00033 #include "itemrepository.h"
00034 #include "iconrepository.h"
00035 
00036 
00037 GraphicSetManager_Base::GraphicSetManager_Base() : activeSet(NULL)
00038 {
00039 
00040 }
00041 
00042 
00043 bool GraphicSetManager_Base :: picAvail ( int num ) const
00044 {
00045    if ( activeSet )
00046       return activeSet->picAvail(num);
00047    else
00048       return false;
00049 }
00050 
00051 
00052 int GraphicSetManager_Base :: getMode ( int num ) const
00053 {
00054    if ( activeSet && activeSet->picmode.size() > num )
00055       return activeSet->picmode[num];
00056    else
00057       return 0;
00058 }
00059 
00060 
00061 
00062 Surface& GraphicSetManager_Base :: getPic ( int num )
00063 {
00064    if( num >= activeSet->image.size() )
00065       return IconRepository::getIcon("emptyfld.raw");
00066    else
00067       return activeSet->image[num];
00068 }
00069 
00070 void GraphicSetManager_Base :: setPic( int num, Surface pic )
00071 {
00072    activeSet->image[num] = pic;
00073 }
00074 
00075 
00076 
00077 int GraphicSetManager_Base :: setActive ( int id )
00078 {
00079    if ( activeSet && id == activeSet->id )
00080       return id;
00081 
00082    for ( GraphicSets::iterator i = graphicSets.begin(); i != graphicSets.end(); ++i )
00083       if ( (*i)->id == id ) {
00084          activeSet = *i;
00085          return id;
00086       }
00087 
00088    if ( graphicSets.size() < 1 )
00089       fatalError( "no graphic sets (*.gfx) found! Check that asc.gfx is in your search path" );
00090    activeSet = *graphicSets.begin();   
00091    return 0;
00092 }
00093 
00094 const OverviewMapImage* GraphicSetManager_Base::getQuickView( int id )
00095 {
00096    if ( picAvail ( id )) {
00097       map<int,OverviewMapImage>::iterator qv = activeSet->quickViewImages.find ( id );
00098       if ( qv == activeSet->quickViewImages.end()) {
00099          OverviewMapImage* fqv = new OverviewMapImage ( getPic( id ) );
00100          activeSet->quickViewImages[id] = *fqv;
00101          delete fqv;
00102          return &activeSet->quickViewImages[id];
00103       } else
00104          return &qv->second;
00105 
00106    } else {
00107       static OverviewMapImage* emptyFieldQuickView = NULL;
00108       if ( !emptyFieldQuickView )
00109          emptyFieldQuickView = new OverviewMapImage();
00110 
00111       return emptyFieldQuickView;
00112    }
00113 }
00114 
00115 
00116 
00117 int getGraphicSetIdFromFilename ( const ASCString& filename )
00118 {
00119     tnfilestream stream ( filename, tnstream::reading );
00120 
00121     int magic = stream.readInt();
00122     if ( magic == -1 ) {
00123        return stream.readInt();
00124     } else
00125        return 0;
00126 }
00127 
00128 
00129 
00130 void GraphicSetManager_Base::loadData()
00131 {
00132    if ( activeSet )
00133       return;
00134 
00135    #ifdef logging
00136    logtofile("loadbi3graphics");
00137    #endif
00138 
00139    loadpalette();
00140 
00141   
00142    
00143    /*
00144 
00145    #ifdef genimg
00146    void* mask;
00147    {
00148       int i ;
00149       tnfilestream s ( "largehex.raw", tnstream::reading );
00150       s.readrlepict ( &mask, false, & i );
00151    }
00152    #endif
00153 */
00154    IconRepository::getIcon("emptyfld.raw");
00155 
00156    ASCString location;
00157    tfindfile ff ( "*.gfx" );
00158    ASCString filename = ff.getnextname( NULL, NULL, &location);
00159    while ( !filename.empty() ) {
00160 
00161       tnfilestream s ( filename, tnstream::reading );
00162 
00163       displayLogMessage ( 5, "loading graphic set " + location + filename + "\n" );
00164 
00165       int magic = s.readInt();
00166       if ( magic == -1 ) {
00167 
00168          GraphicSet* gs = new GraphicSet;
00169 
00170          gs->id = s.readInt();
00171          int picnum = s.readInt();
00172          s.readInt(); // maxPicSize
00173 
00174          int* picmode = new int[picnum];
00175          for ( int i = 0; i < picnum; ++i )
00176             picmode[i] = s.readInt();
00177             
00178          gs->image.resize   ( picnum );
00179          gs->picmode.resize ( picnum );
00180          for ( int i = 0; i < picnum; i++ ) {
00181             if ( picmode[i] >= 1 ) {
00182                Surface& surf = gs->image[i];
00183                surf.read ( s );
00184                if ( surf.w() != fieldsizex || surf.h() != fieldsizey ) 
00185                   surf.strech ( fieldsizex, fieldsizey );
00186                gs->picmode[i] = picmode[i];
00187             } else {
00188                gs->picmode[i] = 256 + 2;
00189                gs->image[i] = IconRepository::getIcon("emptyfld.raw");
00190             }
00191            gs->image[i].assignDefaultPalette();
00192 
00193            dataLoaderTicker();
00194 
00195          }
00196 
00197          delete[] picmode;
00198 
00199          graphicSets.push_back ( gs );
00200       }
00201 
00202       filename = ff.getnextname();
00203    }
00204 
00205    setActive ( 0 );
00206 }
00207 
00208 
00209 GraphicSetManager_Base::~GraphicSetManager_Base()
00210 {
00211    for ( GraphicSets::iterator i = graphicSets.begin(); i != graphicSets.end(); ++i)
00212       delete *i;
00213 }
00214 

Generated on Tue Jun 24 01:27:43 2008 for Advanced Strategic Command by  doxygen 1.4.2