view music2/movie.cc @ 66:d112357a0ec1

Fix a bug with savegames introduced with changeset c7bcc0ec2267. Warning: savegames created since c7bcc0ec2267 are probably corrupted, you may have to start the game over. If you chose not to do so, you should replace all occurrences of 'TextWindow' by 'TextImplWindow', and 'Text Window' by 'TextImpl Window' in your save files.
author Thibaut Girka <thib@sitedethib.com>
date Sat, 11 Dec 2010 18:36:20 +0100
parents 4416cfac86ae
children
line wrap: on
line source

/*
 * Copyright (c) 2004-2006  Kazunori "jagarl" Ueno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * movie.cc  smpeg による動画再生
 *
*/

#include <stdio.h>
#include "music.h"
#include <SDL.h>
#include <SDL_mixer.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "system/file.h"
#include "window/system.h"

#if USE_SMPEG
#include <smpeg/smpeg.h>

static SMPEG* smpeg_handle = 0;
const char* FindMovieFile(const char* path);
void MuSys::PlayMovie(const char* path, int x1, int y1, int x2, int y2, int loop_count) {
	if (!pcm_enable) return;
	FinalizeMusic();
	SMPEG_Info info;
	const char* find_path = FindMovieFile(path);
	if (find_path == NULL) return;
	smpeg_handle = SMPEG_new(find_path, &info, true);
	//SMPEG_enableaudio(smpeg_handle,  true);
	//SMPEG_enablevideo(smpeg_handle,  true);
	SMPEG_enableaudio(smpeg_handle,  true);
	SMPEG_enablevideo(smpeg_handle,  true);
	SDL_Surface* surface = SDL_GetVideoSurface();
	System::Main::DisableVideo();
	SMPEG_setdisplay(smpeg_handle, surface, 0, 0);
	// if (loop_c > 1) SMPEG_loop(smpeg_handle, true);
	//if (x1 != 0 || x2 != 0) SMPEG_setdisplayregion(smpeg_handle,x1, y1, x2-x1, y1-y2);
	SMPEG_play(smpeg_handle);
#if 0
	while(SMPEG_status(smpeg_handle) != SMPEG_PLAYING) {
           	SDL_Delay( 10 );
	}
#endif
	return;
}

const char* FindMovieFile(const char* path) {
	FileSearcher* file_searcher = FileSearcher::GetInstance();
	ARCINFO* info = file_searcher->Find(FileSearcher::MOV, path, "avi");
	if (info == NULL)
		info = file_searcher->Find(FileSearcher::MOV,path,"mpg");
	if (info == NULL) return NULL;
	const char* file = info->Path();
	delete info;
	return file;
}

void MuSys::StopMovie(void) {
	if (smpeg_handle) {
		if (SMPEG_status(smpeg_handle) == SMPEG_PLAYING)
			SMPEG_stop(smpeg_handle);
		while(SMPEG_status(smpeg_handle) == SMPEG_PLAYING) {
            		SDL_Delay( 10 );
		}
		SMPEG_delete(smpeg_handle);
	}
	smpeg_handle = 0;
	System::Main::EnableVideo();
	InitMusic();
}
bool MuSys::IsStopMovie(void) {
	if (!smpeg_handle) return true;
	if (SMPEG_status(smpeg_handle) == SMPEG_PLAYING) return false;
	return true;
}

#else /* USE_SMPEG */
void MuSys::PlayMovie(const char* path, int x1, int y1, int x2, int y2, int loop_count) {
}
void MuSys::StopMovie(void) {
}
bool MuSys::IsStopMovie(void) {
	return true;
}
#endif