コード例 #1
0
ファイル: vqa.cpp プロジェクト: jjermann/freecnc_redalert
/** Play the vqamovie */
void VQAMovie::play()
{
    SDL_Surface *frame, *cframe;
    SDL_Rect dest;
    SDL_Event esc_event;
    Uint8 *sndbuf;
    Uint16 sndlen;
    int i;
    static ImageProc scaler;

    if( vqafile == NULL )
        return;

    dest.w = header.Width<<1;
    dest.h = header.Height<<1;
    dest.x = (pc::gfxeng->getWidth()-(header.Width<<1))>>1;
    dest.y = (pc::gfxeng->getHeight()-(header.Height<<1))>>1;

    /* clear the screen */
    pc::gfxeng->clearScreen();

    /* Seek to first frame/snd information of vqa */
    vqafile->seekSet(offsets[0]);

    /* init the sound - if there is no sound, DecodeSNDChunk returns 0 for sndlen and we continue*/
    /* Is it safe to continue with sndlen set to zero? */
    sndindex = 0;
    sndsample = 0;
    sndbuf = new Uint8[MAX_UNCOMPRESSED_SIZE];
    memset(sndbuf, 0, MAX_UNCOMPRESSED_SIZE);
    sndlen = DecodeSNDChunk(sndbuf);
    pc::sfxeng->initVQAsound(sndbuf, sndlen);

    /* create the frame to store the image in. */
    frame = SDL_CreateRGBSurface(SDL_SWSURFACE, header.Width, header.Height, 8, 0, 0, 0, 0);
    /* Initialise the scaler */
    if( scaleVideo )
        scaler.initVideoScale(frame, videoScaleQuality);
    for( i = 0; i < header.NumFrames; i++ ) {
        /* decode SND Chunk first */
        sndlen = DecodeSNDChunk(sndbuf);

        if(DecodeVQFRChunk(frame) == 1) {
            /* Error decoding frame! We cannot continue, we must bail out */
            break;
        }

        /* add the sound, when this function returns it's time to add the picture */
        pc::sfxeng->addVQAsound(sndbuf, sndlen);

        /* draw the frame */
        if( scaleVideo ) {
            cframe = scaler.scaleVideo(frame);
            pc::gfxeng->drawVQAFrame(cframe);
        } else {
            pc::gfxeng->drawVQAFrame(frame);
        }
        //SDL_FreeSurface(cframe);

        while ( SDL_PollEvent(&esc_event) ) {
            if (esc_event.type == SDL_KEYDOWN) {
                if (esc_event.key.state != SDL_PRESSED)
                    break;
                if (esc_event.key.keysym.sym == SDLK_ESCAPE) {
                    i = header.NumFrames; /* set i high  to break for loop*/
                    break;
                }
            }
        } /* while */
    } /* for */


    pc::sfxeng->closeVQAsound();
    SDL_FreeSurface(frame);
    if( scaleVideo ) {
        scaler.closeVideoScale();
    }

    delete[] sndbuf;
}