annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 /*
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
29 * movie.cc smpeg による動画再生
0
223b71206888 Initial import
thib
parents:
diff changeset
30 *
223b71206888 Initial import
thib
parents:
diff changeset
31 */
223b71206888 Initial import
thib
parents:
diff changeset
32
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
33 #include <stdio.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
34 #include "music.h"
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
35 #include <SDL.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
36 #include <SDL_mixer.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
37 #include <string.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
38 #include <ctype.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
39 #include <stdlib.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
40 #include "system/file.h"
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
41 #include "window/system.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 #if USE_SMPEG
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
44 #include <smpeg/smpeg.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
45
223b71206888 Initial import
thib
parents:
diff changeset
46 static SMPEG* smpeg_handle = 0;
223b71206888 Initial import
thib
parents:
diff changeset
47 const char* FindMovieFile(const char* path);
223b71206888 Initial import
thib
parents:
diff changeset
48 void MuSys::PlayMovie(const char* path, int x1, int y1, int x2, int y2, int loop_count) {
223b71206888 Initial import
thib
parents:
diff changeset
49 if (!pcm_enable) return;
223b71206888 Initial import
thib
parents:
diff changeset
50 FinalizeMusic();
223b71206888 Initial import
thib
parents:
diff changeset
51 SMPEG_Info info;
223b71206888 Initial import
thib
parents:
diff changeset
52 const char* find_path = FindMovieFile(path);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
53 if (find_path == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
54 smpeg_handle = SMPEG_new(find_path, &info, true);
223b71206888 Initial import
thib
parents:
diff changeset
55 //SMPEG_enableaudio(smpeg_handle, true);
223b71206888 Initial import
thib
parents:
diff changeset
56 //SMPEG_enablevideo(smpeg_handle, true);
223b71206888 Initial import
thib
parents:
diff changeset
57 SMPEG_enableaudio(smpeg_handle, true);
223b71206888 Initial import
thib
parents:
diff changeset
58 SMPEG_enablevideo(smpeg_handle, true);
223b71206888 Initial import
thib
parents:
diff changeset
59 SDL_Surface* surface = SDL_GetVideoSurface();
223b71206888 Initial import
thib
parents:
diff changeset
60 System::Main::DisableVideo();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
61 SMPEG_setdisplay(smpeg_handle, surface, 0, 0);
0
223b71206888 Initial import
thib
parents:
diff changeset
62 // if (loop_c > 1) SMPEG_loop(smpeg_handle, true);
223b71206888 Initial import
thib
parents:
diff changeset
63 //if (x1 != 0 || x2 != 0) SMPEG_setdisplayregion(smpeg_handle,x1, y1, x2-x1, y1-y2);
223b71206888 Initial import
thib
parents:
diff changeset
64 SMPEG_play(smpeg_handle);
223b71206888 Initial import
thib
parents:
diff changeset
65 #if 0
223b71206888 Initial import
thib
parents:
diff changeset
66 while(SMPEG_status(smpeg_handle) != SMPEG_PLAYING) {
223b71206888 Initial import
thib
parents:
diff changeset
67 SDL_Delay( 10 );
223b71206888 Initial import
thib
parents:
diff changeset
68 }
223b71206888 Initial import
thib
parents:
diff changeset
69 #endif
223b71206888 Initial import
thib
parents:
diff changeset
70 return;
223b71206888 Initial import
thib
parents:
diff changeset
71 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
72
0
223b71206888 Initial import
thib
parents:
diff changeset
73 const char* FindMovieFile(const char* path) {
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
74 FileSearcher* file_searcher = FileSearcher::GetInstance();
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
75 ARCINFO* info = file_searcher->Find(FileSearcher::MOV, path, "avi");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
76 if (info == NULL)
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
77 info = file_searcher->Find(FileSearcher::MOV,path,"mpg");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
78 if (info == NULL) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
79 const char* file = info->Path();
223b71206888 Initial import
thib
parents:
diff changeset
80 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
81 return file;
223b71206888 Initial import
thib
parents:
diff changeset
82 }
223b71206888 Initial import
thib
parents:
diff changeset
83
223b71206888 Initial import
thib
parents:
diff changeset
84 void MuSys::StopMovie(void) {
223b71206888 Initial import
thib
parents:
diff changeset
85 if (smpeg_handle) {
223b71206888 Initial import
thib
parents:
diff changeset
86 if (SMPEG_status(smpeg_handle) == SMPEG_PLAYING)
223b71206888 Initial import
thib
parents:
diff changeset
87 SMPEG_stop(smpeg_handle);
223b71206888 Initial import
thib
parents:
diff changeset
88 while(SMPEG_status(smpeg_handle) == SMPEG_PLAYING) {
223b71206888 Initial import
thib
parents:
diff changeset
89 SDL_Delay( 10 );
223b71206888 Initial import
thib
parents:
diff changeset
90 }
223b71206888 Initial import
thib
parents:
diff changeset
91 SMPEG_delete(smpeg_handle);
223b71206888 Initial import
thib
parents:
diff changeset
92 }
223b71206888 Initial import
thib
parents:
diff changeset
93 smpeg_handle = 0;
223b71206888 Initial import
thib
parents:
diff changeset
94 System::Main::EnableVideo();
223b71206888 Initial import
thib
parents:
diff changeset
95 InitMusic();
223b71206888 Initial import
thib
parents:
diff changeset
96 }
223b71206888 Initial import
thib
parents:
diff changeset
97 bool MuSys::IsStopMovie(void) {
223b71206888 Initial import
thib
parents:
diff changeset
98 if (!smpeg_handle) return true;
223b71206888 Initial import
thib
parents:
diff changeset
99 if (SMPEG_status(smpeg_handle) == SMPEG_PLAYING) return false;
223b71206888 Initial import
thib
parents:
diff changeset
100 return true;
223b71206888 Initial import
thib
parents:
diff changeset
101 }
223b71206888 Initial import
thib
parents:
diff changeset
102
223b71206888 Initial import
thib
parents:
diff changeset
103 #else /* USE_SMPEG */
223b71206888 Initial import
thib
parents:
diff changeset
104 void MuSys::PlayMovie(const char* path, int x1, int y1, int x2, int y2, int loop_count) {
223b71206888 Initial import
thib
parents:
diff changeset
105 }
223b71206888 Initial import
thib
parents:
diff changeset
106 void MuSys::StopMovie(void) {
223b71206888 Initial import
thib
parents:
diff changeset
107 }
223b71206888 Initial import
thib
parents:
diff changeset
108 bool MuSys::IsStopMovie(void) {
223b71206888 Initial import
thib
parents:
diff changeset
109 return true;
223b71206888 Initial import
thib
parents:
diff changeset
110 }
223b71206888 Initial import
thib
parents:
diff changeset
111 #endif