Changeset 134 for abuse


Ignore:
Timestamp:
Apr 10, 2008, 11:08:14 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Removed 4300 lines of unused code.
Location:
abuse/trunk/src
Files:
35 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/control.cpp

    r124 r134  
    1313#include "control.hpp"
    1414#include "specs.hpp"
    15 #include "loader.hpp"
    1615#include "hpoint.hpp"
    1716#include "ability.hpp"
  • abuse/trunk/src/game.cpp

    r129 r134  
    2929#include "ability.hpp"
    3030#include "cache.hpp"
    31 #include "loader.hpp"
    3231#include "lisp.hpp"
    3332#include "jrand.hpp"
     
    12191218void do_title()
    12201219{
    1221     if(cdc_logo != -1)
    1222     {
    1223         if(sound_avail & MUSIC_INITIALIZED)
    1224         {
    1225             if(current_song)
     1220    if(cdc_logo == -1)
     1221        return;
     1222
     1223    if(sound_avail & MUSIC_INITIALIZED)
     1224    {
     1225        if(current_song)
     1226        {
     1227            current_song->stop();
     1228            delete current_song;
     1229        }
     1230        current_song = new song("music/intro.hmi");
     1231        current_song->play(music_volume);
     1232    }
     1233
     1234    void *logo_snd = symbol_value(make_find_symbol("LOGO_SND"));
     1235
     1236    if(DEFINEDP(logo_snd) && (sound_avail & SFX_INITIALIZED))
     1237        cache.sfx(lnumber_value(logo_snd))->play(sfx_volume);
     1238
     1239    // This must be a dynamic allocated image because if it
     1240    // is not and the window gets closed during do_title, then
     1241    // exit() will try to delete (through the desctructor of
     1242    // image_list in image.cpp) the image on the stack -> boom.
     1243    image *blank = new image(2, 2);
     1244    blank->clear();
     1245    wm->set_mouse_shape(blank->copy(), 0, 0); // hide mouse
     1246    delete blank;
     1247    fade_in(cache.img(cdc_logo), 32);
     1248
     1249    milli_wait(400);
     1250
     1251    void *space_snd = symbol_value(make_find_symbol("SPACE_SND"));
     1252
     1253    fade_out(32);
     1254    milli_wait(100);
     1255
     1256    int i;
     1257    char *str = lstring_value(eval(make_find_symbol("plot_start")));
     1258
     1259    bFILE *fp = open_file("art/smoke.spe", "rb");
     1260    if(!fp->open_failure())
     1261    {
     1262        spec_directory sd(fp);
     1263        palette *old_pal = pal;
     1264        pal = new palette(sd.find(SPEC_PALETTE), fp);
     1265        pal->shift(1);
     1266
     1267        image *gray = new image(sd.find("gray_pict"), fp);
     1268        image *smoke[5];
     1269
     1270        char nm[20];
     1271        for(i = 0; i < 5; i++)
     1272        {
     1273            sprintf(nm, "smoke%04d.pcx", i + 1);
     1274            smoke[i] = new image(sd.find(nm), fp);
     1275        }
     1276
     1277        screen->clear();
     1278        pal->load();
     1279
     1280        int dx = (xres + 1) / 2 - gray->width() / 2, dy = (yres + 1) / 2 - gray->height() / 2;
     1281        gray->put_image(screen, dx, dy);
     1282        smoke[0]->put_image(screen, dx + 24, dy + 5);
     1283
     1284        fade_in(NULL, 16);
     1285        uint8_t cmap[32];
     1286        for(i = 0; i < 32; i++)
     1287        cmap[i] = pal->find_closest(i * 256 / 32, i * 256 / 32, i * 256 / 32);
     1288
     1289        event ev;
     1290        ev.type = EV_SPURIOUS;
     1291        time_marker start;
     1292
     1293        for(i = 0; i < 320 && (ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON); i++)
     1294        {
     1295            gray->put_image(screen, dx, dy);
     1296            smoke[i % 5]->put_image(screen, dx + 24, dy + 5);
     1297            text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, wm->font(), cmap, wm->bright_color());
     1298            wm->flush_screen();
     1299            time_marker now;
     1300
     1301            while(now.diff_time(&start) < 0.18)
    12261302            {
    1227                 current_song->stop();
    1228                 delete current_song;
     1303                milli_wait(20); // ECS - Added the wait, so CPU utilization stays low during the story
     1304                now.get_time();
    12291305            }
    1230             current_song = new song("music/intro.hmi");
    1231             current_song->play(music_volume);
    1232         }
    1233 
    1234         void *logo_snd = symbol_value(make_find_symbol("LOGO_SND"));
    1235 
    1236         if(DEFINEDP(logo_snd) && (sound_avail & SFX_INITIALIZED))
    1237             cache.sfx(lnumber_value(logo_snd))->play(sfx_volume);
    1238 
    1239         // This must be a dynamic allocated image because if it
    1240         // is not and the window gets closed during do_title, then
    1241         // exit() will try to delete (through the desctructor of
    1242         // image_list in image.cpp) the image on the stack -> boom.
    1243         image *blank = new image(2, 2);
    1244         blank->clear();
    1245         wm->set_mouse_shape(blank->copy(), 0, 0); // hide mouse
    1246         delete blank;
    1247         fade_in(cache.img(cdc_logo), 32);
    1248 
    1249         milli_wait(400);
    1250 
    1251         void *space_snd = symbol_value(make_find_symbol("SPACE_SND"));
    1252 
    1253         fade_out(32);
    1254         milli_wait(100);
    1255 
    1256         int i;
    1257         char *str = lstring_value(eval(make_find_symbol("plot_start")));
    1258 
    1259         bFILE *fp = open_file("art/smoke.spe", "rb");
    1260         if(!fp->open_failure())
    1261         {
    1262             spec_directory sd(fp);
    1263             palette *old_pal = pal;
    1264             pal = new palette(sd.find(SPEC_PALETTE), fp);
    1265             pal->shift(1);
    1266 
    1267             image *gray = new image(sd.find("gray_pict"), fp);
    1268             image *smoke[5];
    1269 
    1270             char nm[20];
    1271             for(i = 0; i < 5; i++)
     1306
     1307            start.get_time();
     1308
     1309            while(wm->event_waiting() && ev.type != EV_KEY)
    12721310            {
    1273                 sprintf(nm, "smoke%04d.pcx", i + 1);
    1274                 smoke[i] = new image(sd.find(nm), fp);
     1311                wm->get_event(ev);
    12751312            }
    1276 
    1277             screen->clear();
    1278             pal->load();
    1279 
    1280             int dx = (xres + 1) / 2 - gray->width() / 2, dy = (yres + 1) / 2 - gray->height() / 2;
    1281             gray->put_image(screen, dx, dy);
    1282             smoke[0]->put_image(screen, dx + 24, dy + 5);
    1283 
    1284             fade_in(NULL, 16);
    1285             uint8_t cmap[32];
    1286             for(i = 0; i < 32; i++)
    1287             cmap[i] = pal->find_closest(i * 256 / 32, i * 256 / 32, i * 256 / 32);
    1288 
    1289             event ev;
    1290             ev.type = EV_SPURIOUS;
    1291             time_marker start;
    1292 
    1293             for(i = 0; i < 320 && (ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON); i++)
     1313            if((i % 5) == 0 && DEFINEDP(space_snd) && (sound_avail & SFX_INITIALIZED))
    12941314            {
    1295                 gray->put_image(screen, dx, dy);
    1296                 smoke[i % 5]->put_image(screen, dx + 24, dy + 5);
    1297                 text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, wm->font(), cmap, wm->bright_color());
    1298                 wm->flush_screen();
    1299                 time_marker now;
    1300 
    1301                 while(now.diff_time(&start) < 0.18)
    1302                 {
    1303                     milli_wait(20); // ECS - Added the wait, so CPU utilization stays low during the story
    1304                     now.get_time();
    1305                 }
    1306 
    1307                 start.get_time();
    1308 
    1309                 while(wm->event_waiting() && ev.type != EV_KEY)
    1310                 {
    1311                     wm->get_event(ev);
    1312                 }
    1313                 if((i % 5) == 0 && DEFINEDP(space_snd) && (sound_avail & SFX_INITIALIZED))
    1314                 {
    1315                     cache.sfx(lnumber_value(space_snd))->play(sfx_volume * 90 / 127);
    1316                 }
     1315                cache.sfx(lnumber_value(space_snd))->play(sfx_volume * 90 / 127);
    13171316            }
    1318 
    1319             the_game->reset_keymap();
    1320 
    1321             fade_out(16);
    1322 
    1323             for(i = 0; i < 5; i++)
    1324                 delete smoke[i];
    1325             delete gray;
    1326             delete pal;
    1327             pal = old_pal;
    1328         }
    1329         delete fp;
    1330 
    1331         if(title_screen >= 0)
    1332             fade_in(cache.img(title_screen), 32);
    1333     }
     1317        }
     1318
     1319        the_game->reset_keymap();
     1320
     1321        fade_out(16);
     1322
     1323        for(i = 0; i < 5; i++)
     1324            delete smoke[i];
     1325        delete gray;
     1326        delete pal;
     1327        pal = old_pal;
     1328    }
     1329    delete fp;
     1330
     1331    if(title_screen >= 0)
     1332        fade_in(cache.img(title_screen), 32);
    13341333}
    13351334
  • abuse/trunk/src/game.hpp

    r127 r134  
    1616#include "image.hpp"
    1717#include "video.hpp"
    18 #include "mdlread.hpp"
    1918#include "event.hpp"
    2019#include "fonts.hpp"
    21 #include "loader.hpp"
    2220#include "items.hpp"
    2321#include "jwindow.hpp"
  • abuse/trunk/src/imlib/Makefile.am

    r130 r134  
    44libimlib_a_SOURCES = \
    55    filter.cpp filter.hpp \
    6     gifread.cpp gifread.hpp \
    76    globals.cpp \
    87    image.cpp image.hpp \
    98    linked.cpp linked.hpp \
    109    input.cpp input.hpp \
    11     mdlread.cpp mdlread.hpp \
    1210    palette.cpp palette.hpp \
    13     ppmread.cpp ppmread.hpp \
    1411    include.cpp include.hpp \
    15     xwdread.cpp xwdread.hpp \
    1612    fonts.cpp fonts.hpp \
    17     decoder.cpp \
    18     loader.cpp loader.hpp \
    19     glread.cpp glread.hpp \
    20     texture.cpp texture.hpp \
    2113    specs.cpp specs.hpp \
    2214    supmorph.cpp supmorph.hpp \
    23     image24.cpp image24.hpp \
    2415    pcxread.cpp pcxread.hpp \
    2516    timage.cpp timage.hpp \
    2617    jrand.cpp jrand.hpp \
    27     lbmread.cpp lbmread.hpp \
    28     targa.cpp targa.hpp \
    2918    keys.cpp keys.hpp \
    3019    dprint.cpp dprint.hpp \
    3120    status.cpp status.hpp \
    32     visobj.cpp visobj.hpp \
    33     packet.cpp packet.hpp \
    3421    readwav.cpp readwav.hpp \
    3522    pmenu.cpp pmenu.hpp \
     
    4027    sprite.cpp sprite.hpp \
    4128    jwindow.cpp jwindow.hpp \
    42     main.hpp macs.hpp video.hpp gifdecod.hpp event.hpp mouse.hpp timing.hpp \
    43     jdir.hpp emm.hpp system.h std.h dos.h dir.h errs.h \
     29    main.hpp macs.hpp video.hpp event.hpp mouse.hpp timing.hpp jdir.hpp \
     30    system.h \
    4431    $(NULL)
    4532
  • abuse/trunk/src/imlib/jdir.hpp

    r57 r134  
    1313void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs);
    1414
    15 
    1615#endif
  • abuse/trunk/src/imlib/palette.cpp

    r129 r134  
    1515#include "image.hpp"
    1616#include "macs.hpp"
    17 #include "dos.h"
    1817#include "video.hpp"
    1918#include "filter.hpp"
  • abuse/trunk/src/imlib/pcxread.cpp

    r124 r134  
    2323} PCX_header;
    2424
    25 int read_PCX_header(FILE *fp)
    26 {
    27   if (!fread(&PCX_header.manufactururer,1,1,fp)) return 0;
    28   if (!fread(&PCX_header.version,1,1,fp)) return 0;
    29   if (!fread(&PCX_header.encoding,1,1,fp)) return 0;
    30   if (!fread(&PCX_header.bits_per_pixel,1,1,fp)) return 0;
    31   PCX_header.xmin=read_uint16(fp);
    32   PCX_header.ymin=read_uint16(fp);
    33   PCX_header.xmax=read_uint16(fp);
    34   PCX_header.ymax=read_uint16(fp);
    35   PCX_header.hres=read_uint16(fp);
    36   PCX_header.vres=read_uint16(fp);
    37   if (!fread(PCX_header.palette,1,48,fp)) return 0;
    38   if (!fread(&PCX_header.reserved,1,1,fp)) return 0;
    39   if (!fread(&PCX_header.color_planes,1,1,fp)) return 0;
    40   PCX_header.bytes_per_line=read_uint16(fp);
    41   PCX_header.palette_type=read_uint16(fp);
    42   if (!fread(PCX_header.filter,1,58,fp)) return 0;
    43   return 1;
    44 }
    45 
    4625int write_PCX_header(FILE *fp)
    4726{
     
    6544}
    6645
    67 
    68 
    69 PCX_type PCX_file_type(char const *filename)
    70 {
    71   FILE *fp=fopen(filename,"rb");
    72   if (!fp)
    73   { set_error(imREAD_ERROR);
    74     return not_PCX;
    75   }
    76 
    77   if (!read_PCX_header(fp))
    78   {
    79     fclose(fp);
    80     set_error(imREAD_ERROR);
    81     return not_PCX;
    82   }
    83   fclose(fp);
    84   if (PCX_header.manufactururer!=10)
    85     return not_PCX;
    86   if (PCX_header.color_planes==3 && PCX_header.bits_per_pixel==8)
    87     return PCX_24;
    88   else if (PCX_header.color_planes==1 && PCX_header.bits_per_pixel==8)
    89     return PCX_8;
    90   else return not_PCX;
    91 }
    92 
    93 void read_PCX_line(FILE *fp, unsigned char *start, short skip, int width)
    94 {
    95   int c,n=0,i;
    96 
    97   do
    98   {
    99     c=fgetc(fp)&0xff;
    100     if ((c&0xc0)==0xc0)
    101     {
    102       i=c&0x3f;
    103       c=fgetc(fp);
    104       while (i--)
    105       {
    106     *start=c;
    107     start+=skip;
    108         n++;   
    109       }
    110     }
    111     else
    112     {
    113       *start=c;
    114       start+=skip;
    115       n++;
    116     }
    117   } while (n<width);
    118 }
    119 
    120 
    121 image24 *read_PCX24(char const *filename)
    122 {
    123   if (PCX_file_type(filename)!=PCX_24) return NULL;
    124   FILE *fp=fopen(filename,"rb");
    125   read_PCX_header(fp);
    126   image24 *im=new image24(PCX_header.xmax-PCX_header.xmin+1,
    127               PCX_header.ymax-PCX_header.ymin+1);
    128   int y;
    129   for (y=0;y<im->height();y++)
    130   {
    131     read_PCX_line(fp,im->scan_line(y),3,PCX_header.bytes_per_line);
    132     read_PCX_line(fp,im->scan_line(y)+1,3,PCX_header.bytes_per_line);
    133     read_PCX_line(fp,im->scan_line(y)+2,3,PCX_header.bytes_per_line);
    134   }
    135   fclose(fp);
    136   return im;
    137 }
    138 
    139 image *read_PCX(char const *filename, palette *&pal)
    140 {
    141   if (PCX_file_type(filename)!=PCX_8) return NULL;
    142   FILE *fp=fopen(filename,"rb");
    143   read_PCX_header(fp);
    144 
    145   image *im=new image(PCX_header.xmax-PCX_header.xmin+1,
    146               PCX_header.ymax-PCX_header.ymin+1);
    147   int y;
    148   for (y=0;y<im->height();y++)
    149     read_PCX_line(fp,im->scan_line(y),1,PCX_header.bytes_per_line);
    150   unsigned char palette_confirm;
    151   if (!fread(&palette_confirm,1,1,fp) || palette_confirm!=12)
    152   {
    153     pal=new palette;
    154     pal->defaults();
    155   }
    156   else
    157   {
    158     pal=new palette;
    159     fread(pal->addr(),1,256*3,fp);
    160   }
    161   fclose(fp);
    162   return im;
    163 }
    164 
    16546void write_PCX(image *im, palette *pal, char const *filename)
    16647{
     
    17152    return ;
    17253  }
    173 
    17454
    17555  PCX_header.manufactururer=10;
     
    18868  PCX_header.palette_type=0;
    18969  memset(PCX_header.filter,0,58);
    190 
    19170
    19271  if (!write_PCX_header(fp))
     
    226105}
    227106
    228 
    229 
  • abuse/trunk/src/imlib/pcxread.hpp

    r57 r134  
    1212
    1313#include "image.hpp"
    14 #include "image24.hpp"
    1514#include "palette.hpp"
    1615
    17 enum PCX_type { not_PCX, PCX_8, PCX_24 };
    18 
    19 PCX_type PCX_file_type(char const *filename);
    20 image24 *read_PCX24(char const *filename);
    21 image *read_PCX(char const *filename, palette *&pal);
    2216void write_PCX(image *im, palette *pal, char const *filename);
    2317
  • abuse/trunk/src/imlib/sprite.cpp

    r124 r134  
    1313
    1414#include "macs.hpp"
    15 #include "mdlread.hpp"
    1615#include "video.hpp"
    1716#include "image.hpp"
    1817#include "palette.hpp"
    1918#include "linked.hpp"
    20 #include "glread.hpp"
    21 #include "gifread.hpp"
    22 #include "ppmread.hpp"
    23 #include "emm.hpp"
    2419#include "sprite.hpp"
    2520
  • abuse/trunk/src/sdlport/mouse.cpp

    r124 r134  
    2626#include "image.hpp"
    2727#include "filter.hpp"
    28 #include "mdlread.hpp"
    2928#include "mouse.hpp"
    3029
  • abuse/trunk/src/sdlport/video.cpp

    r129 r134  
    2121
    2222#include <SDL.h>
    23 #ifdef HAVE_OPENGL
    24 #ifdef __APPLE__
    25 #include <OpenGL/gl.h>
    26 #include <OpenGL/glu.h>
    27 #else
    28 #include <GL/gl.h>
    29 #include <GL/glu.h>
    30 #endif    /* __APPLE__ */
     23
     24#ifdef HAVE_OPENGL
     25#   ifdef __APPLE__
     26#       include <OpenGL/gl.h>
     27#       include <OpenGL/glu.h>
     28#   else
     29#       include <GL/gl.h>
     30#       include <GL/glu.h>
     31#   endif    /* __APPLE__ */
    3132#endif    /* HAVE_OPENGL */
     33
    3234#include "filter.hpp"
    3335#include "system.h"
     
    6163{
    6264    int value;
    63     for( value = 1 ; value < input ; value <<= 1);
     65    for(value = 1 ; value < input ; value <<= 1);
    6466    return value;
    6567}
     
    6971// Set the video mode
    7072//
    71 void set_mode( int mode, int argc, char **argv )
     73void set_mode(int mode, int argc, char **argv)
    7274{
    7375    const SDL_VideoInfo *vidInfo;
     
    7678    // Check for video capabilities
    7779    vidInfo = SDL_GetVideoInfo();
    78     if( vidInfo->hw_available )
    79     {
     80    if(vidInfo->hw_available)
    8081        vidFlags |= SDL_HWSURFACE;
    81     }
    82     else
    83     {
     82    else
    8483        vidFlags |= SDL_SWSURFACE;
    85     }
    86     if( flags.fullscreen )
    87     {
     84
     85    if(flags.fullscreen)
    8886        vidFlags |= SDL_FULLSCREEN;
    89     }
    90     if( flags.doublebuf )
    91     {
     87
     88    if(flags.doublebuf)
    9289        vidFlags |= SDL_DOUBLEBUF;
    93     }
    9490
    9591    // Calculate the window scale
     
    9894
    9995    // Try using opengl hw accell
    100     if( flags.gl ) {
    101 #ifdef HAVE_OPENGL
    102         printf( "Video : OpenGL enabled\n" );
     96    if(flags.gl) {
     97#ifdef HAVE_OPENGL
     98        printf("Video : OpenGL enabled\n");
    10399        // allow doublebuffering in with gl too
    104         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, flags.doublebuf );
     100        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, flags.doublebuf);
    105101        // set video gl capability
    106102        vidFlags |= SDL_OPENGL;
     
    109105#else
    110106        // ignore the option if not available
    111         printf( "Video : OpenGL disabled (Support missing in executable)\n");
     107        printf("Video : OpenGL disabled (Support missing in executable)\n");
    112108        flags.gl = 0;
    113109#endif
     
    115111
    116112    // Set the icon for this window.  Looks nice on taskbars etc.
    117     SDL_WM_SetIcon( SDL_LoadBMP("abuse.bmp"), NULL );
     113    SDL_WM_SetIcon(SDL_LoadBMP("abuse.bmp"), NULL);
    118114
    119115    // Create the window with a preference for 8-bit (palette animations!), but accept any depth */
    120     window = SDL_SetVideoMode(flags.xres, flags.yres, 8, vidFlags | SDL_ANYFORMAT );
    121     if( window == NULL )
    122     {
    123         printf( "Video : Unable to set video mode : %s\n", SDL_GetError() );
    124         exit( 1 );
     116    window = SDL_SetVideoMode(flags.xres, flags.yres, 8, vidFlags | SDL_ANYFORMAT);
     117    if(window == NULL)
     118    {
     119        printf("Video : Unable to set video mode : %s\n", SDL_GetError());
     120        exit(1);
    125121    }
    126122
    127123    // Create the screen image
    128     screen = new image( xres, yres, NULL, 2 );
    129     if( screen == NULL )
     124    screen = new image(xres, yres, NULL, 2);
     125    if(screen == NULL)
    130126    {
    131127        // Our screen image is no good, we have to bail.
    132         printf( "Video : Unable to create screen image.\n" );
    133         exit( 1 );
     128        printf("Video : Unable to create screen image.\n");
     129        exit(1);
    134130    }
    135131    screen->clear();
     
    138134    {
    139135#ifdef HAVE_OPENGL
    140         int w,h;
     136        int w, h;
    141137
    142138        // texture width/height should be power of 2
     139        // FIXME: we can use GL_ARB_texture_non_power_of_two or
     140        // GL_ARB_texture_rectangle to avoid the extra memory allocation
    143141        w = power_of_two(xres);
    144142        h = power_of_two(yres);
    145143
    146144        // create texture surface
    147         texture = SDL_CreateRGBSurface( SDL_SWSURFACE, w ,h ,32,
     145        texture = SDL_CreateRGBSurface(SDL_SWSURFACE, w , h , 32,
    148146#if SDL_BYTEORDER == SDL_LIL_ENDIAN
    149                 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 );
     147                0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
    150148#else
    151                 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF );
     149                0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
    152150#endif
    153151
     
    164162        glLoadIdentity();
    165163
    166         glOrtho(0.0, (GLdouble)window->w, (GLdouble)window->h, 0.0, 0.0,1.0);
     164        glOrtho(0.0, (GLdouble)window->w, (GLdouble)window->h, 0.0, 0.0, 1.0);
    167165
    168166        glMatrixMode(GL_MODELVIEW);
     
    181179        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, flags.antialias);
    182180        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, flags.antialias);
    183         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels );
     181        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels);
    184182#endif
    185183    }
    186184
    187185    // Create our 8-bit surface
    188     surface = SDL_CreateRGBSurface( SDL_SWSURFACE, window->w, window->h, 8, 0xff, 0xff, 0xff, 0xff );
    189     if( surface == NULL )
     186    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, window->w, window->h, 8, 0xff, 0xff, 0xff, 0xff);
     187    if(surface == NULL)
    190188    {
    191189        // Our surface is no good, we have to bail.
    192         printf( "Video : Unable to create 8-bit surface.\n" );
    193         exit( 1 );
    194     }
    195 
    196     printf( "Video : %dx%d %dbpp\n", window->w, window->h, window->format->BitsPerPixel );
     190        printf("Video : Unable to create 8-bit surface.\n");
     191        exit(1);
     192    }
     193
     194    printf("Video : %dx%d %dbpp\n", window->w, window->h, window->format->BitsPerPixel);
    197195
    198196    // Set the window caption
    199     SDL_WM_SetCaption( "Abuse-SDL", "Abuse-SDL" );
     197    SDL_WM_SetCaption("Abuse", "Abuse");
    200198
    201199    // Grab and hide the mouse cursor
    202     SDL_ShowCursor( 0 );
    203     if( flags.grabmouse )
    204     {
    205         SDL_WM_GrabInput( SDL_GRAB_ON );
    206     }
    207 
    208     update_dirty( screen );
     200    SDL_ShowCursor(0);
     201    if(flags.grabmouse)
     202        SDL_WM_GrabInput(SDL_GRAB_ON);
     203
     204    update_dirty(screen);
    209205}
    210206
     
    215211void close_graphics()
    216212{
    217     if( lastl )
    218     {
     213    if(lastl)
    219214        delete lastl;
    220     }
    221215    lastl = NULL;
    222216    // Free our 8-bit surface
    223     if( surface )
    224     {
    225         SDL_FreeSurface( surface );
    226     }
    227 #ifdef HAVE_OPENGL
    228     if ( texture )
    229     {
    230         SDL_FreeSurface( texture );
    231     }
     217    if(surface)
     218        SDL_FreeSurface(surface);
     219
     220#ifdef HAVE_OPENGL
     221    if (texture)
     222        SDL_FreeSurface(texture);
    232223#endif
    233224    delete screen;
     
    237228// Draw only dirty parts of the image
    238229//
    239 void put_part_image( image *im, int x, int y, int x1, int y1, int x2, int y2 )
     230void put_part_image(image *im, int x, int y, int x1, int y1, int x2, int y2)
    240231{
    241232    int xe, ye;
     
    246237    Uint16 dinset;
    247238
    248     if( (unsigned)y > yres || (unsigned)x > xres )
    249     {
     239    if((unsigned)y > yres || (unsigned)x > xres)
    250240        return;
    251     }
    252     CHECK( x1 >= 0 && x2 >= x1 && y1 >= 0 && y2 >= y1 );
     241
     242    CHECK(x1 >= 0 && x2 >= x1 && y1 >= 0 && y2 >= y1);
    253243
    254244    // Adjust if we are trying to draw off the screen
    255     if( x < 0 )
     245    if(x < 0)
    256246    {
    257247        x1 += -x;
     
    259249    }
    260250    srcrect.x = x1;
    261     if( (unsigned)(x + ( x2 - x1 )) >= xres )
    262     {
     251    if((unsigned)(x + (x2 - x1)) >= xres)
    263252        xe = xres - x + x1 - 1;
    264     }
    265     else
    266     {
     253    else
    267254        xe = x2;
    268     }
    269     if( y < 0 )
     255
     256    if(y < 0)
    270257    {
    271258        y1 += -y;
     
    273260    }
    274261    srcrect.y = y1;
    275     if( (unsigned)(y + ( y2 - y1 )) >= yres )
    276     {
     262    if((unsigned)(y + (y2 - y1)) >= yres)
    277263        ye = yres - y + y1 - 1;
    278     }
    279     else
    280     {
     264    else
    281265        ye = y2;
    282     }
    283     if( srcrect.x >= xe || srcrect.y >= ye )
     266
     267    if(srcrect.x >= xe || srcrect.y >= ye)
    284268        return;
    285269
     
    299283
    300284    // Lock the surface if necessary
    301     if( SDL_MUSTLOCK( surface ) )
    302     {
    303         SDL_LockSurface( surface );
    304     }
     285    if(SDL_MUSTLOCK(surface))
     286        SDL_LockSurface(surface);
     287
    305288    dpixel = (Uint8 *)surface->pixels;
    306289    dpixel += (dstrect.x + ((dstrect.y) * surface->w)) * surface->format->BytesPerPixel;
     
    311294        srcy = srcrect.y;
    312295        dpixel = ((Uint8 *)surface->pixels) + y * surface->w + x ;
    313         for( ii=0 ; ii < srcrect.h; ii++ )
     296        for(ii=0 ; ii < srcrect.h; ii++)
    314297        {
    315             memcpy( dpixel, im->scan_line( srcy ) + srcrect.x , srcrect.w );
     298            memcpy(dpixel, im->scan_line(srcy) + srcrect.x , srcrect.w);
    316299            dpixel += surface->w;
    317300            srcy ++;
     
    328311        dpixel = (Uint8 *)surface->pixels + (dstrect.x + ((dstrect.y) * surface->w)) * surface->format->BytesPerPixel;
    329312
    330         for( ii = 0; ii < dstrect.h; ii++ )
     313        for(ii = 0; ii < dstrect.h; ii++)
    331314        {
    332315            srcx = (srcrect.x << 16);
    333             for( jj = 0; jj < dstrect.w; jj++ )
     316            for(jj = 0; jj < dstrect.w; jj++)
    334317            {
    335                 memcpy( dpixel, im->scan_line( (srcy >> 16) ) + ((srcx >> 16) * surface->format->BytesPerPixel), surface->format->BytesPerPixel );
     318                memcpy(dpixel, im->scan_line((srcy >> 16)) + ((srcx >> 16) * surface->format->BytesPerPixel), surface->format->BytesPerPixel);
    336319                dpixel += surface->format->BytesPerPixel;
    337320                srcx += xstep;
     
    345328
    346329    // Unlock the surface if we locked it.
    347     if( SDL_MUSTLOCK( surface ) )
    348     {
    349         SDL_UnlockSurface( surface );
    350     }
     330    if(SDL_MUSTLOCK(surface))
     331        SDL_UnlockSurface(surface);
    351332
    352333    // Now blit the surface
    353     update_window_part( &dstrect);
     334    update_window_part(&dstrect);
    354335}
    355336
     
    358339// Draw the entire image
    359340//
    360 void put_image( image * im, int x, int y )
    361 {
    362     put_part_image( im, x, y, 0, 0, im->width() - 1, im->height() - 1 );
     341void put_image(image * im, int x, int y)
     342{
     343    put_part_image(im, x, y, 0, 0, im->width() - 1, im->height() - 1);
    363344}
    364345
     
    367348// Update the dirty parts of the window
    368349//
    369 void update_dirty_window( image *im, int xoff, int yoff )
     350void update_dirty_window(image *im, int xoff, int yoff)
    370351{
    371352    int count;
    372353    dirty_rect *dr, *q;
    373     CHECK( im->special ); // make sure the image has the ability to contain dirty areas
    374     if( im->special->keep_dirt == 0 )
    375     {
    376         put_image( im, xoff, yoff );
     354    CHECK(im->special); // make sure the image has the ability to contain dirty areas
     355    if(im->special->keep_dirt == 0)
     356    {
     357        put_image(im, xoff, yoff);
    377358    }
    378359    else
    379360    {
    380361        count = im->special->dirties.number_nodes();
    381         if( !count )
     362        if(!count)
    382363            return;  // if nothing to update, return
    383         dr = (dirty_rect *)( im->special->dirties.first() );
    384         while( count > 0 )
     364        dr = (dirty_rect *)(im->special->dirties.first());
     365        while(count > 0)
    385366        {
    386             put_part_image( im, xoff + dr->dx1, yoff + dr->dy1, dr->dx1, dr->dy1, dr->dx2 + 1, dr->dy2 + 1 );
     367            put_part_image(im, xoff + dr->dx1, yoff + dr->dy1, dr->dx1, dr->dy1, dr->dx2 + 1, dr->dy2 + 1);
    387368            q = dr;
    388             dr = (dirty_rect *)( dr->next() );
    389             im->special->dirties.unlink( ( linked_node *)q );
     369            dr = (dirty_rect *)(dr->next());
     370            im->special->dirties.unlink((linked_node *)q);
    390371            delete q;
    391372            count--;
     
    398379// Update the dirty parts of the image
    399380//
    400 void update_dirty( image *im, int xoff, int yoff )
    401 {
    402     update_dirty_window( im, xoff, yoff );
     381void update_dirty(image *im, int xoff, int yoff)
     382{
     383    update_dirty_window(im, xoff, yoff);
    403384    update_window_done();
    404385}
     
    407388// make_page()
    408389//
    409 void image::make_page( short width, short height, unsigned char *page_buffer )
    410 {
    411     if( page_buffer )
     390void image::make_page(short width, short height, unsigned char *page_buffer)
     391{
     392    if(page_buffer)
    412393        data = page_buffer;
    413394    else
    414         data = (unsigned char *)malloc( width * height );
     395        data = (unsigned char *)malloc(width * height);
    415396}
    416397
     
    420401void image::delete_page()
    421402{
    422     if( !special || !special->static_mem )
    423         free( data );
     403    if(!special || !special->static_mem)
     404        free(data);
    424405}
    425406
     
    430411void palette::load()
    431412{
    432     if( lastl )
    433     {
     413    if(lastl)
    434414        delete lastl;
    435     }
    436415    lastl = copy();
    437416
    438417    // Force to only 256 colours.
    439418    // Shouldn't be needed, but best to be safe.
    440     if( ncolors > 256 )
    441     {
     419    if(ncolors > 256)
    442420        ncolors = 256;
    443     }
    444421
    445422    SDL_Color colors[ncolors];
    446     for( int ii = 0; ii < ncolors; ii++ )
     423    for(int ii = 0; ii < ncolors; ii++)
    447424    {
    448425        colors[ii].r = red(ii);
     
    450427        colors[ii].b = blue(ii);
    451428    }
    452     SDL_SetColors( surface, colors, 0, ncolors );
    453     if( window->format->BitsPerPixel == 8 )
    454     {
    455         SDL_SetColors( window, colors, 0, ncolors );
    456     }
     429    SDL_SetColors(surface, colors, 0, ncolors);
     430    if(window->format->BitsPerPixel == 8)
     431        SDL_SetColors(window, colors, 0, ncolors);
    457432
    458433    // Now redraw the surface
    459     update_window_part( NULL );
     434    update_window_part(NULL);
    460435    update_window_done();
    461436}
     
    473448void update_window_done()
    474449{
     450#ifdef HAVE_OPENGL
    475451    // opengl blit complete surface to window
    476     if (flags.gl)
    477     {
    478 #ifdef HAVE_OPENGL
     452    if(flags.gl)
     453    {
    479454        // convert color-indexed surface to RGB texture
    480         SDL_BlitSurface( surface, NULL, texture, NULL );
     455        SDL_BlitSurface(surface, NULL, texture, NULL);
    481456
    482457        // Texturemap complete texture to surface so we have free scaling
    483458        // and antialiasing
    484         glTexSubImage2D( GL_TEXTURE_2D,0,
    485              0,0,texture->w,texture->h,
    486              GL_RGBA,GL_UNSIGNED_BYTE,texture->pixels);
     459        glTexSubImage2D(GL_TEXTURE_2D, 0,
     460                        0, 0, texture->w, texture->h,
     461                        GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels);
    487462        glBegin(GL_TRIANGLE_STRIP);
    488463        glTexCoord2f(texcoord[0], texcoord[1]); glVertex3i(0, 0, 0);
     
    491466        glTexCoord2f(texcoord[2], texcoord[3]); glVertex3i(window->w, window->h, 0);
    492467        glEnd();
    493 #endif
    494     }
    495 
     468
     469        if(flags.doublebuf)
     470            SDL_GL_SwapBuffers();
     471    }
     472#else
    496473    // swap buffers in case of double buffering
    497     if (flags.doublebuf)
    498     {
    499         if (flags.gl)
    500         {
    501 #ifdef HAVE_OPENGL
    502             SDL_GL_SwapBuffers();
    503 #endif
    504         }
    505         else
    506         {
    507             SDL_Flip(window);
    508         }
    509     }
    510 
    511474    // do nothing in case of single buffering
    512 }
    513 
    514 void update_window_part( SDL_Rect *rect)
     475    if(flags.doublebuf)
     476        SDL_Flip(window);
     477#endif
     478}
     479
     480void update_window_part(SDL_Rect *rect)
    515481{
    516482    // no partial blit's in case of opengl
    517483    // complete blit + scaling just before flip
    518484    if (flags.gl)
    519     {
    520485        return;
    521     }
    522 
    523     SDL_BlitSurface( surface, rect, window, rect );
     486
     487    SDL_BlitSurface(surface, rect, window, rect);
    524488
    525489    // no window update needed until end of run
    526     if( flags.doublebuf)
    527     {
     490    if(flags.doublebuf)
    528491        return;
    529     }
    530492
    531493    // update window part for single buffer
    532     if( rect == NULL )
    533     {
    534         SDL_UpdateRect( window, 0, 0, 0, 0 );
    535     }
    536     else
    537     {
    538         SDL_UpdateRect( window, rect->x, rect->y, rect->w, rect->h );
    539     }
    540 }
     494    if(rect == NULL)
     495        SDL_UpdateRect(window, 0, 0, 0, 0);
     496    else
     497        SDL_UpdateRect(window, rect->x, rect->y, rect->w, rect->h);
     498}
Note: See TracChangeset for help on using the changeset viewer.