OSDN Git Service

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