OSDN Git Service

DTXManiaソリューション、DTXManiaプロジェクト、DTXCreatorプロジェクト、FDKプロジェクトについて英語化。
[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 readonly Size size基準 = new Size( 278, 355 );
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
149                                                 this.txBGA = new CTexture( CDTXMania.Instance.Device,
150                                                         size基準.Width,
151                                                         size基準.Height,
152                                                         format,
153                                                         Pool.Default,
154                                                         Usage.RenderTarget,
155                                                         true );
156
157                                                 txBGA.vc拡大縮小倍率 = new Vector3(
158                                                         (float) CDTXMania.Instance.Coordinates.Movie.W / size基準.Width,
159                                                         (float) CDTXMania.Instance.Coordinates.Movie.H / size基準.Height,
160                                                         1f );
161                                         }
162                                         catch( Exception e )
163                                         {
164                                                 Trace.TraceError( "CAct演奏BGA: Error: ( " + e.Message + " )" );
165                                         }
166                                 }
167                                 base.OnUnmanagedリソースの作成();
168                         }
169                 }
170
171                 public override void OnUnmanagedリソースの解放()
172                 {
173                         if( base.b活性化してる )
174                         {
175                                 if( this.txBGA != null )
176                                 {
177                                         this.txBGA.Dispose();
178                                         this.txBGA = null;
179                                 }
180                                 base.OnUnmanagedリソースの解放();
181                         }
182                 }
183
184                 public override int On進行描画()
185                 {
186                         if (b活性化してる && CDTXMania.Instance.ConfigIni.bBGA && !CDTXMania.Instance.ConfigIni.bStoicMode)
187                         {
188                                 // (1) txBGA をレンダーターゲットにして、BGA を描画する。
189
190                                 using( Surface sfBackBuffer = CDTXMania.Instance.Device.GetRenderTarget( 0 ) )
191                                 {
192                                         using( Surface sfBGA = txBGA.texture.GetSurfaceLevel( 0 ) )
193                                         {
194                                                 CDTXMania.Instance.Device.SetRenderTarget( 0, sfBGA );
195                                                 CDTXMania.Instance.Device.Clear( ClearFlags.Target, new ColorBGRA( (int) 0 ), 0f, 0 );
196
197                                                 for( int i = 0; i < 8; i++ )
198                                                 {
199                                                         #region [ レイヤー i の描画 ]
200                                                         if( ( ( ( this.stLayer[ i ].n移動開始時刻ms != -1 ) && ( ( this.stLayer[ i ].rBMP != null ) || ( this.stLayer[ i ].rBMPTEX != null ) ) ) ) &&
201                                                                 ( ( ( this.stLayer[ i ].rBMP == null ) || ( this.stLayer[ i ].rBMP.bUse && ( this.stLayer[ i ].rBMP.tx画像 != null ) ) ) &&
202                                                                 ( ( ( this.stLayer[ i ].rBMPTEX == null ) || ( this.stLayer[ i ].rBMPTEX.bUse && ( this.stLayer[ i ].rBMPTEX.tx画像 != null ) ) ) ) ) )
203                                                         {
204                                                                 Size sizeStart = this.stLayer[ i ].sz開始サイズ;
205                                                                 Size sizeEnd = this.stLayer[ i ].sz終了サイズ;
206                                                                 Point ptImgStart = this.stLayer[ i ].pt画像側開始位置;
207                                                                 Point ptImgEnd = this.stLayer[ i ].pt画像側終了位置;
208                                                                 Point ptDispStart = this.stLayer[ i ].pt表示側開始位置;
209                                                                 Point ptDispEnd = this.stLayer[ i ].pt表示側終了位置;
210                                                                 long timeTotal = this.stLayer[ i ].n総移動時間ms;
211                                                                 long timeMoveStart = this.stLayer[ i ].n移動開始時刻ms;
212
213                                                                 if( CDTXMania.Instance.Timer.n現在時刻 < timeMoveStart )
214                                                                 {
215                                                                         timeMoveStart = CDTXMania.Instance.Timer.n現在時刻;
216                                                                 }
217
218                                                                 Size sizeBMP = new Size(
219                                                                         ( this.stLayer[ i ].rBMP != null ) ? this.stLayer[ i ].rBMP.n幅 : this.stLayer[ i ].rBMPTEX.tx画像.sz画像サイズ.Width,
220                                                                         ( this.stLayer[ i ].rBMP != null ) ? this.stLayer[ i ].rBMP.n高さ : this.stLayer[ i ].rBMPTEX.tx画像.sz画像サイズ.Height );
221
222                                                                 int n再生位置 = (int) ( ( CDTXMania.Instance.Timer.n現在時刻 - timeMoveStart ) * ( ( (double) CDTXMania.Instance.ConfigIni.nPlaySpeed ) / 20.0 ) );
223
224                                                                 if( ( timeTotal != 0 ) && ( timeTotal < n再生位置 ) )
225                                                                 {
226                                                                         this.stLayer[ i ].pt画像側開始位置 = ptImgStart = ptImgEnd;
227                                                                         this.stLayer[ i ].pt表示側開始位置 = ptDispStart = ptDispEnd;
228                                                                         this.stLayer[ i ].sz開始サイズ = sizeStart = sizeEnd;
229                                                                         this.stLayer[ i ].n総移動時間ms = timeTotal = 0;
230                                                                 }
231
232                                                                 Rectangle rect画像側 = new Rectangle();
233                                                                 Rectangle rect表示側 = new Rectangle();
234
235                                                                 if( timeTotal == 0 )
236                                                                 {
237                                                                         rect画像側.X = ptImgStart.X;
238                                                                         rect画像側.Y = ptImgStart.Y;
239                                                                         rect画像側.Width = sizeStart.Width;
240                                                                         rect画像側.Height = sizeStart.Height;
241                                                                         rect表示側.X = ptDispStart.X;
242                                                                         rect表示側.Y = ptDispStart.Y;
243                                                                         rect表示側.Width = sizeStart.Width;
244                                                                         rect表示側.Height = sizeStart.Height;
245                                                                 }
246                                                                 else
247                                                                 {
248                                                                         double coefSizeWhileMoving = ( (double) n再生位置 ) / ( (double) timeTotal );
249                                                                         Size sizeWhileMoving = new Size( 
250                                                                                 sizeStart.Width + ( (int) ( ( sizeEnd.Width - sizeStart.Width ) * coefSizeWhileMoving ) ),
251                                                                                 sizeStart.Height + ( (int) ( ( sizeEnd.Height - sizeStart.Height ) * coefSizeWhileMoving ) ) );
252                                                                         rect画像側.X = ptImgStart.X + ( (int) ( ( ptImgEnd.X - ptImgStart.X ) * coefSizeWhileMoving ) );
253                                                                         rect画像側.Y = ptImgStart.Y + ( (int) ( ( ptImgEnd.Y - ptImgStart.Y ) * coefSizeWhileMoving ) );
254                                                                         rect画像側.Width = sizeWhileMoving.Width;
255                                                                         rect画像側.Height = sizeWhileMoving.Height;
256                                                                         rect表示側.X = ptDispStart.X + ( (int) ( ( ptDispEnd.X - ptDispStart.X ) * coefSizeWhileMoving ) );
257                                                                         rect表示側.Y = ptDispStart.Y + ( (int) ( ( ptDispEnd.Y - ptDispStart.Y ) * coefSizeWhileMoving ) );
258                                                                         rect表示側.Width = sizeWhileMoving.Width;
259                                                                         rect表示側.Height = sizeWhileMoving.Height;
260                                                                 }
261
262                                                                 if(
263                                                                         ( rect画像側.Right > 0 ) &&
264                                                                         ( rect画像側.Bottom > 0 ) &&
265                                                                         ( rect画像側.Left < sizeBMP.Width ) &&
266                                                                         ( rect画像側.Top < sizeBMP.Height ) &&
267                                                                         ( rect表示側.Right > 0 ) &&
268                                                                         ( rect表示側.Bottom > 0 ) &&
269                                                                         ( rect表示側.Left < size基準.Width ) &&
270                                                                         ( rect表示側.Top < size基準.Height )
271                                                                         )
272                                                                 {
273                                                                         #region " 画像側の表示指定が画像の境界をまたいでいる場合補正 "
274                                                                         //----------------
275                                                                         if( rect画像側.X < 0 )
276                                                                         {
277                                                                                 rect表示側.Width -= -rect画像側.X;
278                                                                                 rect表示側.X += -rect画像側.X;
279                                                                                 rect画像側.Width -= -rect画像側.X;
280                                                                                 rect画像側.X = 0;
281                                                                         }
282                                                                         if( rect画像側.Y < 0 )
283                                                                         {
284                                                                                 rect表示側.Height -= -rect画像側.Y;
285                                                                                 rect表示側.Y += -rect画像側.Y;
286                                                                                 rect画像側.Height -= -rect画像側.Y;
287                                                                                 rect画像側.Y = 0;
288                                                                         }
289                                                                         if( rect画像側.Right > sizeBMP.Width )
290                                                                         {
291                                                                                 rect表示側.Width -= rect画像側.Right - sizeBMP.Width;
292                                                                                 rect画像側.Width -= rect画像側.Right - sizeBMP.Width;
293                                                                         }
294                                                                         if( rect画像側.Bottom > sizeBMP.Height )
295                                                                         {
296                                                                                 rect表示側.Height -= rect画像側.Bottom - sizeBMP.Height;
297                                                                                 rect画像側.Height -= rect画像側.Bottom - sizeBMP.Height;
298                                                                         }
299                                                                         //----------------
300                                                                         #endregion
301
302                                                                         #region " 表示側の表示指定が表示域の境界をまたいでいる場合補正 "
303                                                                         //----------------
304                                                                         if( rect表示側.X < 0 )
305                                                                         {
306                                                                                 rect画像側.Width -= -rect表示側.X;
307                                                                                 rect画像側.X += -rect表示側.X;
308                                                                                 rect表示側.Width -= rect表示側.X;
309                                                                                 rect表示側.X = 0;
310                                                                         }
311                                                                         if( rect表示側.Y < 0 )
312                                                                         {
313                                                                                 rect画像側.Height -= -rect表示側.Y;
314                                                                                 rect画像側.Y += -rect表示側.Y;
315                                                                                 rect表示側.Height -= -rect表示側.Y;
316                                                                                 rect表示側.Y = 0;
317                                                                         }
318                                                                         if( rect表示側.Right > size基準.Width )
319                                                                         {
320                                                                                 rect画像側.Width -= rect表示側.Right - size基準.Width;
321                                                                                 rect表示側.Width -= rect表示側.Right - size基準.Width;
322                                                                         }
323                                                                         if( rect表示側.Bottom > size基準.Height )
324                                                                         {
325                                                                                 rect画像側.Height -= rect表示側.Bottom - size基準.Height;
326                                                                                 rect表示側.Height -= rect表示側.Bottom - size基準.Height;
327                                                                         }
328                                                                         //----------------
329                                                                         #endregion
330
331                                                                         if(
332                                                                                 ( rect画像側.Width > 0 ) &&
333                                                                                 ( rect画像側.Height > 0 ) &&
334                                                                                 ( rect表示側.Width > 0 ) &&
335                                                                                 ( rect表示側.Height > 0 ) &&
336
337                                                                                 ( rect画像側.Right >= 0 ) &&
338                                                                                 ( rect画像側.Bottom >= 0 ) &&
339                                                                                 ( rect画像側.Left <= sizeBMP.Width ) &&
340                                                                                 ( rect画像側.Top <= sizeBMP.Height ) &&
341                                                                                 ( rect表示側.Right >= 0 ) &&
342                                                                                 ( rect表示側.Bottom >= 0 ) &&
343                                                                                 ( rect表示側.Left <= size基準.Width ) &&
344                                                                                 ( rect表示側.Top <= size基準.Height )
345                                                                                 )
346                                                                         {
347                                                                                 CTexture tex = null;
348                                                                                 if( this.stLayer[ i ].rBMP != null )
349                                                                                 {
350                                                                                         tex = this.stLayer[ i ].rBMP.tx画像;
351                                                                                 }
352                                                                                 else if( this.stLayer[ i ].rBMPTEX != null )
353                                                                                 {
354                                                                                         tex = this.stLayer[ i ].rBMPTEX.tx画像;
355                                                                                 }
356                                                                                 if( tex != null )
357                                                                                 {
358                                                                                         //if( CDTXMania.Instance.DTX != null && !CDTXMania.Instance.DTX.bUse556x710BGAAVI )
359                                                                                         //{
360                                                                                         //      tex.vc拡大縮小倍率.X = 2.0f;
361                                                                                         //      tex.vc拡大縮小倍率.Y = 2.0f;
362                                                                                         //      tex.vc拡大縮小倍率.Z = 1.0f;
363                                                                                         //}
364
365                                                                                         tex.t2D描画( CDTXMania.Instance.Device, rect表示側.X, rect表示側.Y, rect画像側 );
366                                                                                 }
367                                                                         }
368                                                                 }
369                                                         }
370                                                         #endregion
371                                                 }
372
373                                                 // レンダーターゲットをバックバッファに戻す。
374                                                 CDTXMania.Instance.Device.SetRenderTarget( 0, sfBackBuffer );
375                                         }
376                                 }
377
378                                 // (2) バックバッファに txBGA を描画する。
379
380                                 int x = CDTXMania.Instance.ConfigIni.cdMovieX[ CDTXMania.Instance.ConfigIni.eActiveInst ];
381                                 int y = CDTXMania.Instance.ConfigIni.cdMovieY[ CDTXMania.Instance.ConfigIni.eActiveInst ];
382
383                                 txBGA.t2D描画( CDTXMania.Instance.Device, x, y );
384                         }
385                         return 0;
386                 }
387
388
389         }
390 }