OSDN Git Service

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