Ignore:
Timestamp:
Apr 10, 2008, 11:08:14 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Removed 4300 lines of unused code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.