OSDN Git Service

#38362 FulAVIの仕様を全面変更。FullAVI改めForceScalingAVIがOnの時に、ScaledAVIX,Y,W,Hで指定した領域に旧AVIをアスペ...
[dtxmania/dtxmania.git] / DTXMania / コード / ステージ / 07.演奏 / CAct演奏BGA.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Runtime.InteropServices;
5 using System.Drawing;
6 using System.Diagnostics;
7 using SharpDX.Direct3D9;
8 using SharpDX;
9 using FDK;
10
11 using Point = System.Drawing.Point;
12 using Rectangle = System.Drawing.Rectangle;
13
14 namespace DTXMania
15 {
16         internal class CAct演奏BGA : CActivity
17         {
18                 [StructLayout(LayoutKind.Sequential)]
19                 private struct STLAYER
20                 {
21                         public CDTX.CBMP rBMP;
22                         public CDTX.CBMPTEX rBMPTEX;
23                         public Size sz開始サイズ;
24                         public Size sz終了サイズ;
25                         public Point pt画像側開始位置;
26                         public Point pt画像側終了位置;
27                         public Point pt表示側開始位置;
28                         public Point pt表示側終了位置;
29                         public long n総移動時間ms;
30                         public long n移動開始時刻ms;
31                 }
32
33                 private CTexture txBGA;
34                 private STLAYER[] stLayer = new STLAYER[8];
35                 private Size size基準;
36
37                 public CAct演奏BGA()
38                 {
39                         base.b活性化してない = true;
40                 }
41
42                 public void ChangeScope(CChip chip)
43                 {
44                         this.stLayer[chip.nBGALayerSwapIndex].rBMP = chip.rBMP;
45                         this.stLayer[chip.nBGALayerSwapIndex].rBMPTEX = chip.rBMPTEX;
46                 }
47
48                 public void Start(CChip chip, CDTX.CBMP bmp, CDTX.CBMPTEX bmptex, 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 = -1)
49                 {
50                         int i = chip.nBGALayerIndex;
51                         this.stLayer[i].rBMP = bmp;
52                         this.stLayer[i].rBMPTEX = bmptex;
53                         this.stLayer[i].sz開始サイズ.Width = n開始サイズW;
54                         this.stLayer[i].sz開始サイズ.Height = n開始サイズH;
55                         this.stLayer[i].sz終了サイズ.Width = n終了サイズW;
56                         this.stLayer[i].sz終了サイズ.Height = n終了サイズH;
57                         this.stLayer[i].pt画像側開始位置.X = n画像側開始位置X;
58                         this.stLayer[i].pt画像側開始位置.Y = n画像側開始位置Y;
59                         this.stLayer[i].pt画像側終了位置.X = n画像側終了位置X;
60                         this.stLayer[i].pt画像側終了位置.Y = n画像側終了位置Y;
61                         this.stLayer[i].pt表示側開始位置.X = n表示側開始位置X;
62                         this.stLayer[i].pt表示側開始位置.Y = n表示側開始位置Y;
63                         this.stLayer[i].pt表示側終了位置.X = n表示側終了位置X;
64                         this.stLayer[i].pt表示側終了位置.Y = n表示側終了位置Y;
65                         this.stLayer[i].n総移動時間ms = n総移動時間ms;
66                         this.stLayer[i].n移動開始時刻ms = (n移動開始時刻ms != -1) ? n移動開始時刻ms : CDTXMania.Instance.Timer.n現在時刻;
67                 }
68
69                 public void SkipStart(int n移動開始時刻ms)
70                 {
71                         for (int i = 0; i < CDTXMania.Instance.DTX.listChip.Count; i++)
72                         {
73                                 CChip chip = CDTXMania.Instance.DTX.listChip[i];
74                                 if (chip.n発声時刻ms > n移動開始時刻ms)
75                                 {
76                                         return;
77                                 }
78                                 switch (chip.eBGA種別)
79                                 {
80                                         case EBGAType.BMP:
81                                                 if ((chip.rBMP != null) && (chip.rBMP.tx画像 != null))
82                                                 {
83                                                         this.Start(chip, chip.rBMP, null, chip.rBMP.n幅, chip.rBMP.n高さ, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, chip.n発声時刻ms);
84                                                 }
85                                                 break;
86
87                                         case EBGAType.BMPTEX:
88                                                 if ((chip.rBMPTEX != null) && (chip.rBMPTEX.tx画像 != null))
89                                                 {
90                                                         this.Start(chip, null, chip.rBMPTEX, chip.rBMPTEX.tx画像.sz画像サイズ.Width, chip.rBMPTEX.tx画像.sz画像サイズ.Height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, chip.n発声時刻ms);
91                                                 }
92                                                 break;
93
94                                         case EBGAType.BGA:
95                                                 if (chip.rBGA != null)
96                                                 {
97                                                         this.Start(chip, chip.rBMP, chip.rBMPTEX, chip.rBGA.pt画像側右下座標.X - chip.rBGA.pt画像側左上座標.X, chip.rBGA.pt画像側右下座標.Y - chip.rBGA.pt画像側左上座標.Y, 0, 0, chip.rBGA.pt画像側左上座標.X, chip.rBGA.pt画像側左上座標.Y, 0, 0, chip.rBGA.pt表示座標.X, chip.rBGA.pt表示座標.Y, 0, 0, 0, chip.n発声時刻ms);
98                                                 }
99                                                 break;
100
101                                         case EBGAType.BGAPAN:
102                                                 if (chip.rBGAPan != null)
103                                                 {
104                                                         this.Start(chip, chip.rBMP, chip.rBMPTEX, chip.rBGAPan.sz開始サイズ.Width, chip.rBGAPan.sz開始サイズ.Height, chip.rBGAPan.sz終了サイズ.Width, chip.rBGAPan.sz終了サイズ.Height, chip.rBGAPan.pt画像側開始位置.X, chip.rBGAPan.pt画像側開始位置.Y, chip.rBGAPan.pt画像側終了位置.X, chip.rBGAPan.pt画像側終了位置.Y, chip.rBGAPan.pt表示側開始位置.X, chip.rBGAPan.pt表示側開始位置.Y, chip.rBGAPan.pt表示側終了位置.X, chip.rBGAPan.pt表示側終了位置.Y, chip.n総移動時間, chip.n発声時刻ms);
105                                                 }
106                                                 break;
107                                 }
108                         }
109                 }
110
111                 public void Stop()
112                 {
113                         for (int i = 0; i < 8; i++)
114                         {
115                                 this.stLayer[i].n移動開始時刻ms = -1;
116                         }
117                 }
118
119                 public override void On活性化()
120                 {
121                         for (int i = 0; i < 8; i++)
122                         {
123                                 STLAYER stlayer2 = new STLAYER();
124                                 STLAYER stlayer = stlayer2;
125                                 stlayer.rBMP = null;
126                                 stlayer.rBMPTEX = null;
127                                 stlayer.n移動開始時刻ms = -1;
128                                 this.stLayer[i] = stlayer;
129                         }
130                         base.On活性化();
131                 }
132
133                 public override void OnUnmanagedリソースの作成()
134                 {
135                         if( base.b活性化してる )
136                         {
137                                 using( Surface surface = CDTXMania.Instance.Device.GetBackBuffer( 0, 0 ) )
138                                 {
139                                         try
140                                         {
141                                                 var format = Format.A8R8G8B8;
142                                                 switch( surface.Description.Format )    // バックバッファ用フォーマットで X を持つのはこれだけ。
143                                                 {
144                                                         case Format.X4R4G4B4: format = Format.A4R4G4B4; break;
145                                                         case Format.X8B8G8R8: format = Format.A8R8G8B8; break;
146                                                         case Format.X8R8G8B8: format = Format.A8R8G8B8; break;
147                                                 }
148                                                 size基準 = (CDTXMania.Instance.DTX.bUse556x710BGAAVI)?
149                                                         new Size(278 * 2, 355 * 2) : new Size( 278, 355 );
150
151                                                 this.txBGA = new CTexture( CDTXMania.Instance.Device,
152                                                         size基準.Width,
153                                                         size基準.Height,
154                                                         format,
155                                                         Pool.Default,
156                                                         Usage.RenderTarget,
157                                                         true );
158
159                                                 txBGA.vc拡大縮小倍率 = new Vector3(
160                                                         (float) CDTXMania.Instance.Coordinates.Movie.W / size基準.Width,
161                                                         (float) CDTXMania.Instance.Coordinates.Movie.H / size基準.Height,
162                                                         1f );
163                                         }
164                                         catch( Exception e )
165                                         {
166                                                 Trace.TraceError( "CAct演奏BGA: Error: ( " + e.Message + " )" );
167                                         }
168                                 }
169                                 base.OnUnmanagedリソースの作成();
170                         }
171                 }
172
173                 public override void OnUnmanagedリソースの解放()
174                 {
175                         if( base.b活性化してる )
176                         {
177                                 if( this.txBGA != null )
178                                 {
179                                         this.txBGA.Dispose();
180                                         this.txBGA = null;
181                                 }
182                                 base.OnUnmanagedリソースの解放();
183                         }
184                 }
185
186                 public override int On進行描画()
187                 {
188                         if (b活性化してる && CDTXMania.Instance.ConfigIni.bBGA && !CDTXMania.Instance.ConfigIni.bStoicMode)
189                         {
190                                 // (1) txBGA をレンダーターゲットにして、BGA を描画する。
191
192                                 using( Surface sfBackBuffer = CDTXMania.Instance.Device.GetRenderTarget( 0 ) )
193                                 {
194                                         using( Surface sfBGA = txBGA.texture.GetSurfaceLevel( 0 ) )
195                                         {
196                                                 CDTXMania.Instance.Device.SetRenderTarget( 0, sfBGA );
197                                                 CDTXMania.Instance.Device.Clear( ClearFlags.Target, new ColorBGRA( (int) 0 ), 0f, 0 );
198
199                                                 for( int i = 0; i < 8; i++ )
200                                                 {
201                                                         #region [ レイヤー i の描画 ]
202                                                         if( ( ( ( this.stLayer[ i ].n移動開始時刻ms != -1 ) && ( ( this.stLayer[ i ].rBMP != null ) || ( this.stLayer[ i ].rBMPTEX != null ) ) ) ) &&
203                                                                 ( ( ( this.stLayer[ i ].rBMP == null ) || ( this.stLayer[ i ].rBMP.bUse && ( this.stLayer[ i ].rBMP.tx画像 != null ) ) ) &&
204                                                                 ( ( ( this.stLayer[ i ].rBMPTEX == null ) || ( this.stLayer[ i ].rBMPTEX.bUse && ( this.stLayer[ i ].rBMPTEX.tx画像 != null ) ) ) ) ) )
205                                                         {
206                                                                 Size sizeStart = this.stLayer[ i ].sz開始サイズ;
207                                                                 Size sizeEnd = this.stLayer[ i ].sz終了サイズ;
208                                                                 Point ptImgStart = this.stLayer[ i ].pt画像側開始位置;
209                                                                 Point ptImgEnd = this.stLayer[ i ].pt画像側終了位置;
210                                                                 Point ptDispStart = this.stLayer[ i ].pt表示側開始位置;
211                                                                 Point ptDispEnd = this.stLayer[ i ].pt表示側終了位置;
212                                                                 long timeTotal = this.stLayer[ i ].n総移動時間ms;
213                                                                 long timeMoveStart = this.stLayer[ i ].n移動開始時刻ms;
214
215                                                                 if( CDTXMania.Instance.Timer.n現在時刻 < timeMoveStart )
216                                                                 {
217                                                                         timeMoveStart = CDTXMania.Instance.Timer.n現在時刻;
218                                                                 }
219
220                                                                 Size sizeBMP = new Size(
221                                                                         ( this.stLayer[ i ].rBMP != null ) ? this.stLayer[ i ].rBMP.n幅 : this.stLayer[ i ].rBMPTEX.tx画像.sz画像サイズ.Width,
222                                                                         ( this.stLayer[ i ].rBMP != null ) ? this.stLayer[ i ].rBMP.n高さ : this.stLayer[ i ].rBMPTEX.tx画像.sz画像サイズ.Height );
223
224                                                                 int n再生位置 = (int) ( ( CDTXMania.Instance.Timer.n現在時刻 - timeMoveStart ) * ( ( (double) CDTXMania.Instance.ConfigIni.nPlaySpeed ) / 20.0 ) );
225
226                                                                 if( ( timeTotal != 0 ) && ( timeTotal < n再生位置 ) )
227                                                                 {
228                                                                         this.stLayer[ i ].pt画像側開始位置 = ptImgStart = ptImgEnd;
229                                                                         this.stLayer[ i ].pt表示側開始位置 = ptDispStart = ptDispEnd;
230                                                                         this.stLayer[ i ].sz開始サイズ = sizeStart = sizeEnd;
231                                                                         this.stLayer[ i ].n総移動時間ms = timeTotal = 0;
232                                                                 }
233
234                                                                 Rectangle rect画像側 = new Rectangle();
235                                                                 Rectangle rect表示側 = new Rectangle();
236
237                                                                 if( timeTotal == 0 )
238                                                                 {
239                                                                         rect画像側.X = ptImgStart.X;
240                                                                         rect画像側.Y = ptImgStart.Y;
241                                                                         rect画像側.Width = sizeStart.Width;
242                                                                         rect画像側.Height = sizeStart.Height;
243                                                                         rect表示側.X = ptDispStart.X;
244                                                                         rect表示側.Y = ptDispStart.Y;
245                                                                         rect表示側.Width = sizeStart.Width;
246                                                                         rect表示側.Height = sizeStart.Height;
247                                                                 }
248                                                                 else
249                                                                 {
250                                                                         double coefSizeWhileMoving = ( (double) n再生位置 ) / ( (double) timeTotal );
251                                                                         Size sizeWhileMoving = new Size( 
252                                                                                 sizeStart.Width + ( (int) ( ( sizeEnd.Width - sizeStart.Width ) * coefSizeWhileMoving ) ),
253                                                                                 sizeStart.Height + ( (int) ( ( sizeEnd.Height - sizeStart.Height ) * coefSizeWhileMoving ) ) );
254                                                                         rect画像側.X = ptImgStart.X + ( (int) ( ( ptImgEnd.X - ptImgStart.X ) * coefSizeWhileMoving ) );
255                                                                         rect画像側.Y = ptImgStart.Y + ( (int) ( ( ptImgEnd.Y - ptImgStart.Y ) * coefSizeWhileMoving ) );
256                                                                         rect画像側.Width = sizeWhileMoving.Width;
257                                                                         rect画像側.Height = sizeWhileMoving.Height;
258                                                                         rect表示側.X = ptDispStart.X + ( (int) ( ( ptDispEnd.X - ptDispStart.X ) * coefSizeWhileMoving ) );
259                                                                         rect表示側.Y = ptDispStart.Y + ( (int) ( ( ptDispEnd.Y - ptDispStart.Y ) * coefSizeWhileMoving ) );
260                                                                         rect表示側.Width = sizeWhileMoving.Width;
261                                                                         rect表示側.Height = sizeWhileMoving.Height;
262                                                                 }
263
264                                                                 if(
265                                                                         ( rect画像側.Right > 0 ) &&
266                                                                         ( rect画像側.Bottom > 0 ) &&
267                                                                         ( rect画像側.Left < sizeBMP.Width ) &&
268                                                                         ( rect画像側.Top < sizeBMP.Height ) &&
269                                                                         ( rect表示側.Right > 0 ) &&
270                                                                         ( rect表示側.Bottom > 0 ) &&
271                                                                         ( rect表示側.Left < size基準.Width ) &&
272                                                                         ( rect表示側.Top < size基準.Height )
273                                                                         )
274                                                                 {
275                                                                         #region " 画像側の表示指定が画像の境界をまたいでいる場合補正 "
276                                                                         //----------------
277                                                                         if( rect画像側.X < 0 )
278                                                                         {
279                                                                                 rect表示側.Width -= -rect画像側.X;
280                                                                                 rect表示側.X += -rect画像側.X;
281                                                                                 rect画像側.Width -= -rect画像側.X;
282                                                                                 rect画像側.X = 0;
283                                                                         }
284                                                                         if( rect画像側.Y < 0 )
285                                                                         {
286                                                                                 rect表示側.Height -= -rect画像側.Y;
287                                                                                 rect表示側.Y += -rect画像側.Y;
288                                                                                 rect画像側.Height -= -rect画像側.Y;
289                                                                                 rect画像側.Y = 0;
290                                                                         }
291                                                                         if( rect画像側.Right > sizeBMP.Width )
292                                                                         {
293                                                                                 rect表示側.Width -= rect画像側.Right - sizeBMP.Width;
294                                                                                 rect画像側.Width -= rect画像側.Right - sizeBMP.Width;
295                                                                         }
296                                                                         if( rect画像側.Bottom > sizeBMP.Height )
297                                                                         {
298                                                                                 rect表示側.Height -= rect画像側.Bottom - sizeBMP.Height;
299                                                                                 rect画像側.Height -= rect画像側.Bottom - sizeBMP.Height;
300                                                                         }
301                                                                         //----------------
302                                                                         #endregion
303
304                                                                         #region " 表示側の表示指定が表示域の境界をまたいでいる場合補正 "
305                                                                         //----------------
306                                                                         if( rect表示側.X < 0 )
307                                                                         {
308                                                                                 rect画像側.Width -= -rect表示側.X;
309                                                                                 rect画像側.X += -rect表示側.X;
310                                                                                 rect表示側.Width -= rect表示側.X;
311                                                                                 rect表示側.X = 0;
312                                                                         }
313                                                                         if( rect表示側.Y < 0 )
314                                                                         {
315                                                                                 rect画像側.Height -= -rect表示側.Y;
316                                                                                 rect画像側.Y += -rect表示側.Y;
317                                                                                 rect表示側.Height -= -rect表示側.Y;
318                                                                                 rect表示側.Y = 0;
319                                                                         }
320                                                                         if( rect表示側.Right > size基準.Width )
321                                                                         {
322                                                                                 rect画像側.Width -= rect表示側.Right - size基準.Width;
323                                                                                 rect表示側.Width -= rect表示側.Right - size基準.Width;
324                                                                         }
325                                                                         if( rect表示側.Bottom > size基準.Height )
326                                                                         {
327                                                                                 rect画像側.Height -= rect表示側.Bottom - size基準.Height;
328                                                                                 rect表示側.Height -= rect表示側.Bottom - size基準.Height;
329                                                                         }
330                                                                         //----------------
331                                                                         #endregion
332
333                                                                         if(
334                                                                                 ( rect画像側.Width > 0 ) &&
335                                                                                 ( rect画像側.Height > 0 ) &&
336                                                                                 ( rect表示側.Width > 0 ) &&
337                                                                                 ( rect表示側.Height > 0 ) &&
338
339                                                                                 ( rect画像側.Right >= 0 ) &&
340                                                                                 ( rect画像側.Bottom >= 0 ) &&
341                                                                                 ( rect画像側.Left <= sizeBMP.Width ) &&
342                                                                                 ( rect画像側.Top <= sizeBMP.Height ) &&
343                                                                                 ( rect表示側.Right >= 0 ) &&
344                                                                                 ( rect表示側.Bottom >= 0 ) &&
345                                                                                 ( rect表示側.Left <= size基準.Width ) &&
346                                                                                 ( rect表示側.Top <= size基準.Height )
347                                                                                 )
348                                                                         {
349                                                                                 CTexture tex = null;
350                                                                                 if( this.stLayer[ i ].rBMP != null )
351                                                                                 {
352                                                                                         tex = this.stLayer[ i ].rBMP.tx画像;
353                                                                                 }
354                                                                                 else if( this.stLayer[ i ].rBMPTEX != null )
355                                                                                 {
356                                                                                         tex = this.stLayer[ i ].rBMPTEX.tx画像;
357                                                                                 }
358                                                                                 if( tex != null )
359                                                                                 {
360                                                                                         //if( CDTXMania.Instance.DTX != null && !CDTXMania.Instance.DTX.bUse556x710BGAAVI )
361                                                                                         //{
362                                                                                         //      tex.vc拡大縮小倍率.X = 2.0f;
363                                                                                         //      tex.vc拡大縮小倍率.Y = 2.0f;
364                                                                                         //      tex.vc拡大縮小倍率.Z = 1.0f;
365                                                                                         //}
366
367                                                                                         tex.t2D描画( CDTXMania.Instance.Device, rect表示側.X, rect表示側.Y, rect画像側 );
368                                                                                 }
369                                                                         }
370                                                                 }
371                                                         }
372                                                         #endregion
373                                                 }
374
375                                                 // レンダーターゲットをバックバッファに戻す。
376                                                 CDTXMania.Instance.Device.SetRenderTarget( 0, sfBackBuffer );
377                                         }
378                                 }
379
380                                 // (2) バックバッファに txBGA を描画する。
381
382                                 int x = CDTXMania.Instance.ConfigIni.cdAVIX[ CDTXMania.Instance.ConfigIni.eActiveInst ];
383                                 int y = CDTXMania.Instance.ConfigIni.cdAVIY[ CDTXMania.Instance.ConfigIni.eActiveInst ];
384
385                                 txBGA.t2D描画( CDTXMania.Instance.Device, x, y );
386                         }
387                         return 0;
388                 }
389
390
391         }
392 }