OSDN Git Service

6b2071af152e62e5fd3c54d534efd948e6f7f626
[dtxmania/dtxmania.git] / DTXManiaプロジェクト / コード / ステージ / 07.演奏 / CAct演奏AVI.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Drawing;\r
5 using SlimDX;\r
6 using SlimDX.Direct3D9;\r
7 using FDK;\r
8 using System.Diagnostics;\r
9 \r
10 namespace DTXMania\r
11 {\r
12         internal class CAct演奏AVI : CActivity\r
13         {\r
14                 // コンストラクタ\r
15 \r
16                 public CAct演奏AVI()\r
17                 {\r
18                         base.b活性化してない = true;\r
19                 }\r
20                 /// <summary>\r
21                 /// プレビュームービーかどうか\r
22                 /// </summary>\r
23                 /// <remarks>\r
24                 /// On活性化()の前にフラグ操作すること。(活性化中に、本フラグを見て動作を変える部分があるため)\r
25                 /// </remarks>\r
26                 public bool bIsPreviewMovie\r
27                 {\r
28                         get;\r
29                         set;\r
30                 }\r
31                 public bool bHasBGA\r
32                 {\r
33                         get;\r
34                         set;\r
35                 }\r
36                 public bool bFullScreenMovie\r
37                 {\r
38                         get;\r
39                         set;\r
40                 }\r
41 \r
42                 public void PrepareProperSizeTexture(int width, int height)\r
43                 {\r
44                         try\r
45                         {\r
46                                 if (this.tx描画用 != null && (this.tx描画用.szテクスチャサイズ.Width != width || this.tx描画用.szテクスチャサイズ.Height != height))\r
47                                 {\r
48                                         this.tx描画用.Dispose();\r
49                                         this.tx描画用 = null;\r
50                                 }\r
51                                 if (this.tx描画用 == null)\r
52                                 {\r
53 #if TEST_Direct3D9Ex\r
54                                         if ( width % 32 != 0 )\r
55                                         {\r
56                                                 width /= 32;\r
57                                                 width++;\r
58                                                 width *= 32;\r
59                                         }\r
60                                         this.tx描画用 = new CTexture(\r
61                                                 CDTXMania.Instance.Device, width, height,\r
62                                                 CDTXMania.Instance.GraphicsDeviceManager.CurrentSettings.BackBufferFormat,\r
63                                                 Pool.Default, Usage.Dynamic );\r
64 #else\r
65                                         this.tx描画用 = new CTexture(\r
66                                                 CDTXMania.Instance.Device, width, height,\r
67                                                 CDTXMania.Instance.GraphicsDeviceManager.CurrentSettings.BackBufferFormat,\r
68                                                 Pool.Managed);\r
69 #endif\r
70                                 }\r
71                         }\r
72                         catch (CTextureCreateFailedException e)\r
73                         {\r
74                                 Trace.TraceError("CActAVI: OnManagedリソースの作成(): " + e.Message);\r
75                                 this.tx描画用 = null;\r
76                         }\r
77                 }\r
78 \r
79                 // メソッド\r
80                 public void Start(Ech定義 nチャンネル番号, CDTX.CAVI rAVI, int n開始サイズW, int n開始サイズH, int n終了サイズW, int n終了サイズH, int n画像側開始位置X, int n画像側開始位置Y, int n画像側終了位置X, int n画像側終了位置Y, int n表示側開始位置X, int n表示側開始位置Y, int n表示側終了位置X, int n表示側終了位置Y, int n総移動時間ms, int n移動開始時刻ms)\r
81                 {\r
82                         if (nチャンネル番号 == Ech定義.Movie || nチャンネル番号 == Ech定義.MovieFull)\r
83                         {\r
84                                 this.rAVI = rAVI;\r
85                                 this.n開始サイズW = n開始サイズW;\r
86                                 this.n開始サイズH = n開始サイズH;\r
87                                 this.n終了サイズW = n終了サイズW;\r
88                                 this.n終了サイズH = n終了サイズH;\r
89                                 this.n画像側開始位置X = n画像側開始位置X;\r
90                                 this.n画像側開始位置Y = n画像側開始位置Y;\r
91                                 this.n画像側終了位置X = n画像側終了位置X;\r
92                                 this.n画像側終了位置Y = n画像側終了位置Y;\r
93                                 this.n表示側開始位置X = n表示側開始位置X * 2;\r
94                                 this.n表示側開始位置Y = n表示側開始位置Y * 2;\r
95                                 this.n表示側終了位置X = n表示側終了位置X * 2;\r
96                                 this.n表示側終了位置Y = n表示側終了位置Y * 2;\r
97                                 this.n総移動時間ms = n総移動時間ms;\r
98                                 this.PrepareProperSizeTexture((int)this.rAVI.avi.nフレーム幅, (int)this.rAVI.avi.nフレーム高さ);\r
99                                 this.n移動開始時刻ms = (n移動開始時刻ms != -1) ? n移動開始時刻ms : CSound管理.rc演奏用タイマ.n現在時刻;\r
100                                 this.rAVI.avi.Run();\r
101                         }\r
102                 }\r
103                 public void SkipStart(int n移動開始時刻ms)\r
104                 {\r
105                         foreach (CChip chip in CDTXMania.Instance.DTX.listChip)\r
106                         {\r
107                                 if (chip.n発声時刻ms > n移動開始時刻ms)\r
108                                 {\r
109                                         break;\r
110                                 }\r
111                                 switch (chip.eAVI種別)\r
112                                 {\r
113                                         case EAVI種別.AVI:\r
114                                                 {\r
115                                                         if (chip.rAVI != null)\r
116                                                         {\r
117                                                                 if (this.rAVI == null)\r
118                                                                 {\r
119                                                                         this.rAVI = chip.rAVI;          // DTXVモードで、最初に途中再生で起動したときに、ここに来る\r
120                                                                 }\r
121                                                                 this.bFullScreenMovie = (chip.eチャンネル番号 == Ech定義.MovieFull || CDTXMania.Instance.ConfigIni.bForceAVIFullscreen);               // DTXVモードで、最初に途中再生で起動したときのために必要\r
122                                                                 this.rAVI.avi.Seek(n移動開始時刻ms - chip.n発声時刻ms);\r
123                                                                 this.Start(chip.eチャンネル番号, chip.rAVI, SampleFramework.GameWindowSize.Width, SampleFramework.GameWindowSize.Height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, chip.n発声時刻ms);\r
124                                                         }\r
125                                                         continue;\r
126                                                 }\r
127                                         case EAVI種別.AVIPAN:\r
128                                                 {\r
129                                                         if (chip.rAVIPan != null)\r
130                                                         {\r
131                                                                 if (this.rAVI == null)\r
132                                                                 {\r
133                                                                         this.rAVI = chip.rAVI;          // DTXVモードで、最初に途中再生で起動したときに、ここに来る\r
134                                                                 }\r
135                                                                 this.bFullScreenMovie = (chip.eチャンネル番号 == Ech定義.MovieFull || CDTXMania.Instance.ConfigIni.bForceAVIFullscreen);               // DTXVモードで、最初に途中再生で起動したときのために必要\r
136                                                                 this.rAVI.avi.Seek(n移動開始時刻ms - chip.n発声時刻ms);\r
137                                                                 this.Start(chip.eチャンネル番号, chip.rAVI, chip.rAVIPan.sz開始サイズ.Width, chip.rAVIPan.sz開始サイズ.Height, chip.rAVIPan.sz終了サイズ.Width, chip.rAVIPan.sz終了サイズ.Height, chip.rAVIPan.pt動画側開始位置.X, chip.rAVIPan.pt動画側開始位置.Y, chip.rAVIPan.pt動画側終了位置.X, chip.rAVIPan.pt動画側終了位置.Y, chip.rAVIPan.pt表示側開始位置.X, chip.rAVIPan.pt表示側開始位置.Y, chip.rAVIPan.pt表示側終了位置.X, chip.rAVIPan.pt表示側終了位置.Y, chip.n総移動時間, chip.n発声時刻ms);\r
138                                                         }\r
139                                                         continue;\r
140                                                 }\r
141                                 }\r
142                         }\r
143                 }\r
144                 public void Stop()\r
145                 {\r
146                         if ((this.rAVI != null) && (this.rAVI.avi != null))\r
147                         {\r
148                                 this.n移動開始時刻ms = -1;\r
149                         }\r
150                 }\r
151                 public void Cont(int n再開時刻ms)\r
152                 {\r
153                         if ((this.rAVI != null) && (this.rAVI.avi != null))\r
154                         {\r
155                                 this.n移動開始時刻ms = n再開時刻ms;\r
156                         }\r
157                 }\r
158                 public unsafe int t進行描画(int x, int y, int areaDrawingWidth, int areaDrawingHeight)\r
159                 {\r
160                         if (!base.b活性化してない)\r
161                         {\r
162                                 // Rectangle rectangle;\r
163                                 // Rectangle rectangle2;\r
164 \r
165                                 if (((this.n移動開始時刻ms == -1) || (this.rAVI == null)) || (this.rAVI.avi == null))\r
166                                 {\r
167                                         return 0;\r
168                                 }\r
169                                 if (this.tx描画用 == null)\r
170                                 {\r
171                                         return 0;\r
172                                 }\r
173                                 int time = (int)((CSound管理.rc演奏用タイマ.n現在時刻 - this.n移動開始時刻ms) * (((double)CDTXMania.Instance.ConfigIni.n演奏速度) / 20.0));\r
174                                 if ((this.n総移動時間ms != 0) && (this.n総移動時間ms < time))\r
175                                 {\r
176                                         this.n総移動時間ms = 0;\r
177                                         this.n移動開始時刻ms = -1;\r
178                                         return 0;\r
179                                 }\r
180                                 if ((this.n総移動時間ms == 0) && time >= this.rAVI.avi.GetDuration())\r
181                                 {\r
182                                         if (!bIsPreviewMovie)\r
183                                         {\r
184                                                 this.n移動開始時刻ms = -1;\r
185                                                 return 0;\r
186                                         }\r
187                                         // PREVIEW時はループ再生する。移動開始時刻msを現時刻にして(=AVIを最初に巻き戻して)、ここまでに行った計算をやり直す。\r
188                                         this.n移動開始時刻ms = CSound管理.rc演奏用タイマ.n現在時刻;\r
189                                         time = (int)((CSound管理.rc演奏用タイマ.n現在時刻 - this.n移動開始時刻ms) * (((double)CDTXMania.Instance.ConfigIni.n演奏速度) / 20.0));\r
190                                         this.rAVI.avi.Seek(0);\r
191                                 }\r
192                                 /*\r
193                                 if( ( this.n前回表示したフレーム番号 != frameNoFromTime ) && !this.bフレームを作成した )\r
194                                 {\r
195                                         // this.pBmp = this.rAVI.avi.GetFramePtr( frameNoFromTime );\r
196                                         this.n前回表示したフレーム番号 = frameNoFromTime;\r
197                                         this.bフレームを作成した = true;\r
198                                 }\r
199                                 Size size = new Size( (int) this.rAVI.avi.nフレーム幅, (int) this.rAVI.avi.nフレーム高さ );\r
200                                 // Size size2 = new Size( 278, 355);\r
201                                 Size size2 = new Size( SampleFramework.GameWindowSize.Width, SampleFramework.GameWindowSize.Height);\r
202                                 Size 開始サイズ = new Size( this.n開始サイズW, this.n開始サイズH );\r
203                                 Size 終了サイズ = new Size( this.n終了サイズW, this.n終了サイズH );\r
204                                 Point 画像側開始位置 = new Point( this.n画像側開始位置X, this.n画像側終了位置Y );\r
205                                 Point 画像側終了位置 = new Point( this.n画像側終了位置X, this.n画像側終了位置Y );\r
206                                 Point 表示側開始位置 = new Point( this.n表示側開始位置X, this.n表示側開始位置Y );\r
207                                 Point 表示側終了位置 = new Point( this.n表示側終了位置X, this.n表示側終了位置Y );\r
208                                 long num3 = this.n総移動時間ms;\r
209                                 long num4 = this.n移動開始時刻ms;\r
210                                 if( CSound管理.rc演奏用タイマ.n現在時刻 < num4 )\r
211                                 {\r
212                                         num4 = CSound管理.rc演奏用タイマ.n現在時刻;\r
213                                 }\r
214                                 time = (int) ( ( CSound管理.rc演奏用タイマ.n現在時刻 - num4 ) * ( ( (double) CDTXMania.Instance.ConfigIni.n演奏速度 ) / 20.0 ) );\r
215                                 if( num3 == 0 )\r
216                                 {\r
217                                         rectangle = new Rectangle( 画像側開始位置, 開始サイズ );\r
218                                         rectangle2 = new Rectangle( 表示側開始位置, 開始サイズ );\r
219                                 }\r
220                                 else\r
221                                 {\r
222                                         double num5 = ( (double) time ) / ( (double) num3 );\r
223                                         Size size5 = new Size( 開始サイズ.Width + ( (int) ( ( 終了サイズ.Width - 開始サイズ.Width ) * num5 ) ), 開始サイズ.Height + ( (int) ( ( 終了サイズ.Height - 開始サイズ.Height ) * num5 ) ) );\r
224                                         rectangle = new Rectangle( (int) ( ( 画像側終了位置.X - 画像側開始位置.X ) * num5 ), (int) ( ( 画像側終了位置.Y - 画像側開始位置.Y ) * num5 ), ( (int) ( ( 画像側終了位置.X - 画像側開始位置.X ) * num5 ) ) + size5.Width, ( (int) ( ( 画像側終了位置.Y - 画像側開始位置.Y ) * num5 ) ) + size5.Height );\r
225                                         rectangle2 = new Rectangle( (int) ( ( 表示側終了位置.X - 表示側開始位置.X ) * num5 ), (int) ( ( 表示側終了位置.Y - 表示側開始位置.Y ) * num5 ), ( (int) ( ( 表示側終了位置.X - 表示側開始位置.X ) * num5 ) ) + size5.Width, ( (int) ( ( 表示側終了位置.Y - 表示側開始位置.Y ) * num5 ) ) + size5.Height );\r
226                                         if( ( ( rectangle.Right <= 0 ) || ( rectangle.Bottom <= 0 ) ) || ( ( rectangle.Left >= size.Width ) || ( rectangle.Top >= size.Height ) ) )\r
227                                         {\r
228                                                 return 0;\r
229                                         }\r
230                                         if( ( ( rectangle2.Right <= 0 ) || ( rectangle2.Bottom <= 0 ) ) || ( ( rectangle2.Left >= size2.Width ) || ( rectangle2.Top >= size2.Height ) ) )\r
231                                         {\r
232                                                 return 0;\r
233                                         }\r
234                                         if( rectangle.X < 0 )\r
235                                         {\r
236                                                 int num6 = -rectangle.X;\r
237                                                 rectangle2.X += num6;\r
238                                                 rectangle2.Width -= num6;\r
239                                                 rectangle.X = 0;\r
240                                                 rectangle.Width -= num6;\r
241                                         }\r
242                                         if( rectangle.Y < 0 )\r
243                                         {\r
244                                                 int num7 = -rectangle.Y;\r
245                                                 rectangle2.Y += num7;\r
246                                                 rectangle2.Height -= num7;\r
247                                                 rectangle.Y = 0;\r
248                                                 rectangle.Height -= num7;\r
249                                         }\r
250                                         if( rectangle.Right > size.Width )\r
251                                         {\r
252                                                 int num8 = rectangle.Right - size.Width;\r
253                                                 rectangle2.Width -= num8;\r
254                                                 rectangle.Width -= num8;\r
255                                         }\r
256                                         if( rectangle.Bottom > size.Height )\r
257                                         {\r
258                                                 int num9 = rectangle.Bottom - size.Height;\r
259                                                 rectangle2.Height -= num9;\r
260                                                 rectangle.Height -= num9;\r
261                                         }\r
262                                         if( rectangle2.X < 0 )\r
263                                         {\r
264                                                 int num10 = -rectangle2.X;\r
265                                                 rectangle.X += num10;\r
266                                                 rectangle.Width -= num10;\r
267                                                 rectangle2.X = 0;\r
268                                                 rectangle2.Width -= num10;\r
269                                         }\r
270                                         if( rectangle2.Y < 0 )\r
271                                         {\r
272                                                 int num11 = -rectangle2.Y;\r
273                                                 rectangle.Y += num11;\r
274                                                 rectangle.Height -= num11;\r
275                                                 rectangle2.Y = 0;\r
276                                                 rectangle2.Height -= num11;\r
277                                         }\r
278                                         if( rectangle2.Right > size2.Width )\r
279                                         {\r
280                                                 int num12 = rectangle2.Right - size2.Width;\r
281                                                 rectangle.Width -= num12;\r
282                                                 rectangle2.Width -= num12;\r
283                                         }\r
284                                         if( rectangle2.Bottom > size2.Height )\r
285                                         {\r
286                                                 int num13 = rectangle2.Bottom - size2.Height;\r
287                                                 rectangle.Height -= num13;\r
288                                                 rectangle2.Height -= num13;\r
289                                         }\r
290                                         if( ( rectangle.X >= rectangle.Right ) || ( rectangle.Y >= rectangle.Bottom ) )\r
291                                         {\r
292                                                 return 0;\r
293                                         }\r
294                                         if( ( rectangle2.X >= rectangle2.Right ) || ( rectangle2.Y >= rectangle2.Bottom ) )\r
295                                         {\r
296                                                 return 0;\r
297                                         }\r
298                                         if( ( ( rectangle.Right < 0 ) || ( rectangle.Bottom < 0 ) ) || ( ( rectangle.X > size.Width ) || ( rectangle.Y > size.Height ) ) )\r
299                                         {\r
300                                                 return 0;\r
301                                         }\r
302                                         if( ( ( rectangle2.Right < 0 ) || ( rectangle2.Bottom < 0 ) ) || ( ( rectangle2.X > size2.Width ) || ( rectangle2.Y > size2.Height ) ) )\r
303                                         {\r
304                                                 return 0;\r
305                                         }\r
306                                 }\r
307                                 */\r
308                                 if ((this.tx描画用 != null) && (this.n総移動時間ms != -1))\r
309                                 {\r
310                                         this.rAVI.avi.tGetBitmap(CDTXMania.Instance.Device, this.tx描画用, time);\r
311                                         // 旧動画 (278x355以下)の場合と、それ以上の場合とで、拡大/表示位置補正ロジックを変えること。\r
312                                         // 旧動画の場合は、「278x355の領域に表示される」ことを踏まえて扱う必要あり。\r
313                                         // 例: 上半分だけ動画表示するような場合は・・・「上半分だけ」という表示意図を維持すべきか?それとも無視して全画面拡大すべきか??\r
314                                         // chnmr0 : プレビューの場合表示領域いっぱいにアス比保持で拡縮します。\r
315                                         //          プレビューでない場合単純に縦横2倍、位置変更なしで表示します。\r
316                                         // yyagi: BGAの有無を見ないで、単純にFullScreenMovieならアス比保持で拡縮、そうでないなら縦横2倍+位置変更なし。\r
317                                         // chnmr0 : 従来の大きさ以上のプレビュー動画で不都合が起きますのでここは常にアス比保持でフィッティングします。\r
318 \r
319                                         float magX = 2, magY = 2;\r
320                                         int xx = x, yy = y;\r
321 \r
322                                         if (CDTXMania.Instance.DTX != null && CDTXMania.Instance.DTX.bUse556x710BGAAVI)\r
323                                         {\r
324                                                 magX = magY = 1;\r
325                                         }\r
326 \r
327                                         if (bFullScreenMovie || bIsPreviewMovie)\r
328                                         {\r
329                                                 #region [ アスペクト比を維持した拡大縮小 ]\r
330                                                 if (bFullScreenMovie)\r
331                                                 {\r
332                                                         xx = 0;\r
333                                                         yy = 0;\r
334                                                         areaDrawingWidth = SampleFramework.GameWindowSize.Width;\r
335                                                         areaDrawingHeight = SampleFramework.GameWindowSize.Height;\r
336                                                 }\r
337 \r
338                                                 magX = (float)areaDrawingWidth / this.rAVI.avi.nフレーム幅;\r
339                                                 magY = (float)areaDrawingHeight / this.rAVI.avi.nフレーム高さ;\r
340                                                 if (magX > magY)\r
341                                                 {\r
342                                                         magX = magY;\r
343                                                         xx += (int)((areaDrawingWidth - (this.rAVI.avi.nフレーム幅 * magY)) / 2);\r
344                                                 }\r
345                                                 else\r
346                                                 {\r
347                                                         magY = magX;\r
348                                                         yy += (int)((areaDrawingHeight - (this.rAVI.avi.nフレーム高さ * magX)) / 2);\r
349                                                 }\r
350                                                 #endregion\r
351                                         }\r
352 \r
353                                         this.tx描画用.vc拡大縮小倍率.X = magX;\r
354                                         this.tx描画用.vc拡大縮小倍率.Y = magY;\r
355                                         this.tx描画用.vc拡大縮小倍率.Z = 1.0f;\r
356                                         this.tx描画用.bFlipY = true;\r
357                                         this.tx描画用.t2D描画(CDTXMania.Instance.Device, xx, yy);\r
358                                 }\r
359                         }\r
360                         return 0;\r
361                 }\r
362 \r
363 \r
364                 // CActivity 実装\r
365 \r
366                 public override void On活性化()\r
367                 {\r
368                         this.rAVI = null;\r
369                         this.n移動開始時刻ms = -1;\r
370                         this.bHasBGA = false;\r
371                         this.bFullScreenMovie = false;\r
372                         base.On活性化();\r
373                 }\r
374                 public override void OnManagedリソースの作成()\r
375                 {\r
376                         if (!base.b活性化してない)\r
377                         {\r
378 #if TEST_Direct3D9Ex\r
379                                 this.PrepareProperSizeTexture(\r
380                                                 ( bIsPreviewMovie ) ? 204 : SampleFramework.GameWindowSize.Width,\r
381                                                 ( bIsPreviewMovie ) ? 269 : SampleFramework.GameWindowSize.Height\r
382                                                 );\r
383 #else\r
384                                 this.PrepareProperSizeTexture(\r
385                                                 (bIsPreviewMovie) ? 204 : SampleFramework.GameWindowSize.Width,\r
386                                                 (bIsPreviewMovie) ? 269 : SampleFramework.GameWindowSize.Height\r
387                                                 );\r
388 #endif\r
389                                 this.tx描画用.vc拡大縮小倍率 = new Vector3(Scale.X, Scale.Y, 1f);\r
390                                 base.OnManagedリソースの作成();\r
391                         }\r
392                 }\r
393                 public override void OnManagedリソースの解放()\r
394                 {\r
395                         if (!base.b活性化してない)\r
396                         {\r
397                                 if (this.tx描画用 != null)\r
398                                 {\r
399                                         this.tx描画用.Dispose();\r
400                                         this.tx描画用 = null;\r
401                                 }\r
402                                 base.OnManagedリソースの解放();\r
403                         }\r
404                 }\r
405                 public override int On進行描画()\r
406                 {\r
407                         throw new InvalidOperationException("t進行描画(int,int)のほうを使用してください。");\r
408                 }\r
409 \r
410                 private long n移動開始時刻ms;\r
411                 private int n画像側開始位置X;\r
412                 private int n画像側開始位置Y;\r
413                 private int n画像側終了位置X;\r
414                 private int n画像側終了位置Y;\r
415                 private int n開始サイズH;\r
416                 private int n開始サイズW;\r
417                 private int n終了サイズH;\r
418                 private int n終了サイズW;\r
419                 private int n総移動時間ms;\r
420                 private int n表示側開始位置X;\r
421                 private int n表示側開始位置Y;\r
422                 private int n表示側終了位置X;\r
423                 private int n表示側終了位置Y;\r
424                 private CDTX.CAVI rAVI;\r
425                 private CTexture tx描画用;\r
426         }\r
427 }\r