OSDN Git Service

#none 指定時刻に一番近いChipを探索する部分のリファクタ。読みやすさ向上と、ほんのちょっと高速化。
authoryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Thu, 30 Jun 2011 15:53:36 +0000 (15:53 +0000)
committeryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Thu, 30 Jun 2011 15:53:36 +0000 (15:53 +0000)
git-svn-id: http://svn.osdn.jp/svnroot/dtxmania/trunk@217 16f42ceb-6dc6-49c8-ba94-f2d53467949d

DTXManiaプロジェクト/コード/ステージ/07.演奏/CStage演奏画面共通.cs

index 7189704..3b496d8 100644 (file)
@@ -694,24 +694,29 @@ namespace DTXMania
                                return null;\r
                        }\r
                        int count = CDTXMania.DTX.listChip.Count;\r
-                       int nIndex_InitialPositionSearchingToFuture = nIndex_InitialPositionSearchingToPast = this.n現在のトップChip;\r
+                       int nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToPast = this.n現在のトップChip;\r
                        if ( this.n現在のトップChip >= count )                    // その時点で演奏すべきチップが既に全部無くなっていたら\r
                        {\r
-                               nIndex_InitialPositionSearchingToFuture = nIndex_InitialPositionSearchingToPast = count - 1;\r
+                               nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToPast = count - 1;\r
                        }\r
-                       int nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToFuture;\r
-                       while ( nIndex_NearestChip_Future < count )             // 未来方向への検索\r
+                       //int nIndex_NearestChip_Future;        // = nIndex_InitialPositionSearchingToFuture;\r
+                       //while ( nIndex_NearestChip_Future < count )           // 未来方向への検索\r
+                       for ( ; nIndex_NearestChip_Future < count; nIndex_NearestChip_Future++)\r
                        {\r
                                CDTX.CChip chip = CDTXMania.DTX.listChip[ nIndex_NearestChip_Future ];\r
-                               if ( ( ( nChannel >= 0x11 ) && ( nChannel <= 0x1a ) ) && ( ( chip.nチャンネル番号 == nChannel ) || ( chip.nチャンネル番号 == ( nChannel + 0x20 ) ) ) )\r
+                               if ( ( ( 0x11 <= nChannel ) && ( nChannel <= 0x1a ) ) )\r
                                {\r
-                                       if ( chip.n発声時刻ms > nTime )\r
+                                       if ( ( chip.nチャンネル番号 == nChannel ) || ( chip.nチャンネル番号 == ( nChannel + 0x20 ) ) )\r
                                        {\r
-                                               break;\r
+                                               if ( chip.n発声時刻ms > nTime )\r
+                                               {\r
+                                                       break;\r
+                                               }\r
+                                               nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
                                        }\r
-                                       nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
+                                       continue;       // ほんの僅かながら高速化\r
                                }\r
-                               else if ( ( ( nChannel == 0x2f ) && ( chip.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( nChannel >= 0x20 ) && ( nChannel <= 0x28 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
+                               else if ( ( ( nChannel == 0x2f ) && ( chip.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( 0x20 <= nChannel ) && ( nChannel <= 0x28 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
                                {\r
                                        if ( chip.n発声時刻ms > nTime )\r
                                        {\r
@@ -719,7 +724,7 @@ namespace DTXMania
                                        }\r
                                        nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
                                }\r
-                               else if ( ( ( nChannel == 0xaf ) && ( chip.e楽器パート == E楽器パート.BASS ) ) || ( ( ( nChannel >= 0xa0 ) && ( nChannel <= 0xa8 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
+                               else if ( ( ( nChannel == 0xaf ) && ( chip.e楽器パート == E楽器パート.BASS ) ) || ( ( ( 0xa0 <= nChannel ) && ( nChannel <= 0xa8 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
                                {\r
                                        if ( chip.n発声時刻ms > nTime )\r
                                        {\r
@@ -727,49 +732,56 @@ namespace DTXMania
                                        }\r
                                        nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
                                }\r
-                               nIndex_NearestChip_Future++;\r
+                               // nIndex_NearestChip_Future++;\r
                        }\r
                        int nIndex_NearestChip_Past = nIndex_InitialPositionSearchingToPast;\r
-                       while ( nIndex_NearestChip_Past >= 0 )                  // 過去方向への検索\r
+                       //while ( nIndex_NearestChip_Past >= 0 )                        // 過去方向への検索\r
+                       for ( ; nIndex_NearestChip_Past >= 0; nIndex_NearestChip_Past-- )\r
                        {\r
-                               CDTX.CChip chip2 = CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
-                               if ( ( nChannel >= 0x11 ) && ( nChannel <= 0x1a ) )\r
+                               CDTX.CChip chip = CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
+                               if ( ( 0x11 <= nChannel ) && ( nChannel <= 0x1a ) )\r
                                {\r
-                                       if ( ( chip2.nチャンネル番号 == nChannel ) || ( chip2.nチャンネル番号 == ( nChannel + 0x20 ) ) )\r
+                                       if ( ( chip.nチャンネル番号 == nChannel ) || ( chip.nチャンネル番号 == ( nChannel + 0x20 ) ) )\r
                                        {\r
                                                break;\r
                                        }\r
                                }\r
-                               else if ( ( ( nChannel == 0x2f ) && ( chip2.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( nChannel >= 0x20 ) && ( nChannel <= 0x28 ) ) && ( chip2.nチャンネル番号 == nChannel ) ) )\r
+                               else if ( ( ( nChannel == 0x2f ) && ( chip.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( 0x20 <= nChannel ) && ( nChannel <= 0x28 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
                                {\r
-                                       if ( ( chip2.nチャンネル番号 >= 0x20 ) && ( chip2.nチャンネル番号 <= 0x28 ) )\r
+                                       if ( ( 0x20 <= chip.nチャンネル番号 ) && ( chip.nチャンネル番号 <= 0x28 ) )\r
                                        {\r
                                                break;\r
                                        }\r
                                }\r
-                               else if ( ( ( ( nChannel == 0xaf ) && ( chip2.e楽器パート == E楽器パート.BASS ) ) || ( ( ( nChannel >= 0xa0 ) && ( nChannel <= 0xa8 ) ) && ( chip2.nチャンネル番号 == nChannel ) ) ) && ( ( chip2.nチャンネル番号 >= 0xa0 ) && ( chip2.nチャンネル番号 <= 0xa8 ) ) )\r
+                               else if ( ( ( ( nChannel == 0xaf ) && ( chip.e楽器パート == E楽器パート.BASS ) ) || ( ( ( 0xa0 <= nChannel ) && ( nChannel <= 0xa8 ) ) && ( chip.nチャンネル番号 == nChannel ) ) )\r
+                                       && ( ( 0xa0 <= chip.nチャンネル番号 ) && ( chip.nチャンネル番号 <= 0xa8 ) ) )\r
                                {\r
                                        break;\r
                                }\r
-                               nIndex_NearestChip_Past--;\r
-                       }\r
-                       if ( ( nIndex_NearestChip_Future == count ) && ( nIndex_NearestChip_Past < 0 ) )        // 検索対象が過去未来どちらにも見つからなかった場合\r
-                       {\r
-                               return null;\r
+                               // nIndex_NearestChip_Past--;\r
                        }\r
-                       if ( nIndex_NearestChip_Future == count )                                                                                       // 検索対象が未来方向には見つからなかった(しかし過去方向には見つかった)場合\r
+\r
+                       if ( nIndex_NearestChip_Future >= count )\r
                        {\r
-                               return CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
+                               if ( nIndex_NearestChip_Past < 0 )      // 検索対象が過去未来どちらにも見つからなかった場合\r
+                               {\r
+                                       return null;\r
+                               }\r
+                               else                                                            // 検索対象が未来方向には見つからなかった(しかし過去方向には見つかった)場合\r
+                               {\r
+                                       return CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
+                               }\r
                        }\r
-                       if ( nIndex_NearestChip_Past < 0 )                                                                                                      // 検索対象が過去方向には見つからなかった(しかし未来方向には見つかった)場合\r
+                       else if ( nIndex_NearestChip_Past < 0 ) // 検索対象が過去方向には見つからなかった(しかし未来方向には見つかった)場合\r
                        {\r
                                return CDTXMania.DTX.listChip[ nIndex_NearestChip_Future ];\r
                        }\r
+                                                                                                       // 検索対象が過去未来の双方に見つかったなら、より近い方を採用する\r
                        CDTX.CChip nearestChip_Future = CDTXMania.DTX.listChip[ nIndex_NearestChip_Future ];\r
                        CDTX.CChip nearestChip_Past   = CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
                        int nDiffTime_Future = Math.Abs( (int) ( nTime - nearestChip_Future.n発声時刻ms ) );\r
-                       int nDiffTIme_Past   = Math.Abs( (int) ( nTime - nearestChip_Past.n発声時刻ms ) );\r
-                       if ( nDiffTime_Future >= nDiffTIme_Past )\r
+                       int nDiffTime_Past   = Math.Abs( (int) ( nTime - nearestChip_Past.n発声時刻ms ) );\r
+                       if ( nDiffTime_Future >= nDiffTime_Past )\r
                        {\r
                                return nearestChip_Past;\r
                        }\r
@@ -1135,29 +1147,31 @@ namespace DTXMania
                                return null;\r
                        }\r
                        int count = CDTXMania.DTX.listChip.Count;\r
-                       int nIndex_InitialPositionSearchingToFuture = nIndex_InitialPositionSearchingToPast = this.n現在のトップChip;\r
+                       int nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToPast = this.n現在のトップChip;\r
                        if ( this.n現在のトップChip >= count )            // その時点で演奏すべきチップが既に全部無くなっていたら\r
                        {\r
-                               nIndex_InitialPositionSearchingToFuture = nIndex_InitialPositionSearchingToPast = count - 1;\r
+                               nIndex_NearestChip_Future  = nIndex_InitialPositionSearchingToPast = count - 1;\r
                        }\r
-                       int nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToFuture;\r
+                       // int nIndex_NearestChip_Future = nIndex_InitialPositionSearchingToFuture;\r
 //                     while ( nIndex_NearestChip_Future < count )     // 未来方向への検索\r
                        for ( ; nIndex_NearestChip_Future < count; nIndex_NearestChip_Future++ )\r
                        {\r
                                CDTX.CChip chip = CDTXMania.DTX.listChip[ nIndex_NearestChip_Future ];\r
                                if ( !chip.bHit )\r
                                {\r
-                                       if ( ( nChannel >= 0x11 ) && ( nChannel <= 0x1a ) &&\r
-                                               ( ( chip.nチャンネル番号 == nChannel ) || ( chip.nチャンネル番号 == ( nChannel + 0x20 ) ) )\r
-                                       )\r
+                                       if ( ( 0x11 <= nChannel ) && ( nChannel <= 0x1a ) )\r
                                        {\r
-                                               if ( chip.n発声時刻ms > nTime )\r
+                                               if ( ( chip.nチャンネル番号 == nChannel ) || ( chip.nチャンネル番号 == ( nChannel + 0x20 ) ) )\r
                                                {\r
-                                                       break;\r
+                                                       if ( chip.n発声時刻ms > nTime )\r
+                                                       {\r
+                                                               break;\r
+                                                       }\r
+                                                       nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
                                                }\r
-                                               nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
+                                               continue;\r
                                        }\r
-                                       else if ( ( ( ( nChannel == 0x2f ) && ( chip.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( nChannel >= 0x20 ) && ( nChannel <= 0x28 ) ) && ( chip.nチャンネル番号 == nChannel ) ) ) )\r
+                                       else if ( ( ( ( nChannel == 0x2f ) && ( chip.e楽器パート == E楽器パート.GUITAR ) ) || ( ( ( 0x20 <= nChannel ) && ( nChannel <= 0x28 ) ) && ( chip.nチャンネル番号 == nChannel ) ) ) )\r
                                        {\r
                                                if ( chip.n発声時刻ms > nTime )\r
                                                {\r
@@ -1165,7 +1179,7 @@ namespace DTXMania
                                                }\r
                                                nIndex_InitialPositionSearchingToPast = nIndex_NearestChip_Future;\r
                                        }\r
-                                       else if ( ( ( ( nChannel == 0xaf ) && ( chip.e楽器パート == E楽器パート.BASS ) ) || ( ( ( nChannel >= 0xA0 ) && ( nChannel <= 0xa8 ) ) && ( chip.nチャンネル番号 == nChannel ) ) ) )\r
+                                       else if ( ( ( ( nChannel == 0xaf ) && ( chip.e楽器パート == E楽器パート.BASS ) ) || ( ( ( 0xa0 <= nChannel ) && ( nChannel <= 0xa8 ) ) && ( chip.nチャンネル番号 == nChannel ) ) ) )\r
                                        {\r
                                                if ( chip.n発声時刻ms > nTime )\r
                                                {\r
@@ -1203,12 +1217,12 @@ namespace DTXMania
                                        }\r
 //                             nIndex_NearestChip_Past--;\r
                        }\r
-                       if ( ( nIndex_NearestChip_Future == count ) && ( nIndex_NearestChip_Past < 0 ) )        // 検索対象が過去未来どちらにも見つからなかった場合\r
+                       if ( ( nIndex_NearestChip_Future >= count ) && ( nIndex_NearestChip_Past < 0 ) )        // 検索対象が過去未来どちらにも見つからなかった場合\r
                        {\r
                                return null;\r
                        }\r
                        CDTX.CChip nearestChip; // = null;      // 以下のifブロックのいずれかで必ずnearestChipには非nullが代入されるので、null初期化を削除\r
-                       if ( nIndex_NearestChip_Future == count )                                                                                       // 検索対象が未来方向には見つからなかった(しかし過去方向には見つかった)場合\r
+                       if ( nIndex_NearestChip_Future >= count )                                                                                       // 検索対象が未来方向には見つからなかった(しかし過去方向には見つかった)場合\r
                        {\r
                                nearestChip = CDTXMania.DTX.listChip[ nIndex_NearestChip_Past ];\r
 //                             nTimeDiff = Math.Abs( (int) ( nTime - nearestChip.n発声時刻ms ) );\r