2 using System.Collections.Generic;
3 using System.Globalization;
5 using System.Windows.Forms;
7 using System.Diagnostics;
9 using System.Threading;
11 using SharpDX.Direct3D9;
13 using SampleFramework;
14 using System.Runtime.Serialization;
17 using Point = System.Drawing.Point;
18 using Color = System.Drawing.Color;
22 internal class CDTXMania : Game
25 #region [ properties ]
26 public static readonly string VERSION = "108+(170506)";
27 public static readonly string SLIMDXDLL = "c_net20x86_Jun2010";
28 public static readonly string D3DXDLL = "d3dx9_43.dll"; // June 2010
29 //public static readonly string D3DXDLL = "d3dx9_42.dll"; // February 2010
30 //public static readonly string D3DXDLL = "d3dx9_41.dll"; // March 2009
31 private static CDTXMania instance = new CDTXMania();
33 public static CDTXMania Instance
40 public C文字コンソール act文字コンソール { get; private set; }
41 public bool bコンパクトモード { get; private set; }
42 public CConfigXml ConfigIni;
43 public CResources Resources;
53 if ((dtx != null) && (Instance != null))
56 Instance.listトップレベルActivities.Remove(dtx);
59 if ((dtx != null) && (Instance != null))
61 Instance.listトップレベルActivities.Add(dtx);
65 public CFPS FPS { get; private set; }
66 public CInput管理 Input管理 { get; private set; }
68 public int nPerfect範囲ms
72 if (stage選曲.r確定された曲 != null)
74 C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
75 if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPerfect範囲ms >= 0))
77 return c曲リストノード.nPerfect範囲ms;
80 return ConfigIni.nHitRange.Perfect;
87 if (stage選曲.r確定された曲 != null)
89 C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
90 if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGreat範囲ms >= 0))
92 return c曲リストノード.nGreat範囲ms;
95 return ConfigIni.nHitRange.Great;
102 if (stage選曲.r確定された曲 != null)
104 C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
105 if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGood範囲ms >= 0))
107 return c曲リストノード.nGood範囲ms;
110 return ConfigIni.nHitRange.Good;
117 if (stage選曲.r確定された曲 != null)
119 C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
120 if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPoor範囲ms >= 0))
122 return c曲リストノード.nPoor範囲ms;
125 return ConfigIni.nHitRange.Poor;
129 public CPad Pad { get; private set; }
130 public Random Random { get; private set; }
131 public CSkin Skin { get; private set; }
132 public CSongs管理 Songs管理 { get; set; }// 2012.1.26 yyagi private解除 CStage起動でのdesirialize読み込みのため
133 public CEnumSongs EnumSongs { get; private set; }
134 public CActEnumSongs actEnumSongs { get; private set; }
135 public CActFlushGPU actFlushGPU { get; private set; }
137 public CSound管理 Sound管理 { get; private set; }
138 public CStage起動 stage起動 { get; private set; }
139 public CStageタイトル stageタイトル { get; private set; }
140 public CStageコンフィグ stageコンフィグ { get; private set; }
141 public CStage選曲 stage選曲 { get; private set; }
142 public CStage曲読み込み stage曲読み込み { get; private set; }
143 public CStage演奏画面共通 stage演奏画面 { get; private set; }
144 public CStage結果 stage結果 { get; private set; }
145 public CStageChangeSkin stageChangeSkin { get; private set; }
146 public CStage終了 stage終了 { get; private set; }
147 public CStage r現在のステージ = null;
148 public CStage r直前のステージ = null;
149 public string strEXEのあるフォルダ { get; private set; }
150 public string strコンパクトモードファイル { get; private set; }
151 public CTimer Timer { get; private set; }
152 public Format TextureFormat = Format.A8R8G8B8;
153 internal IPluginActivity act現在入力を占有中のプラグイン = null;
154 public bool bApplicationActive { get; private set; }
155 public bool b次のタイミングで垂直帰線同期切り替えを行う { get; set; }
156 public bool b次のタイミングで全画面_ウィンドウ切り替えを行う { get; set; }
157 public Coordinates.CCoordinates Coordinates;
162 return base.GraphicsDeviceManager.Direct3D9.Device;
165 public CPluginHost PluginHost { get; private set; }
166 public List<STPlugin> listプラグイン = new List<STPlugin>();
168 private Size currentClientSize { get; set; } // #23510 2010.10.27 add yyagi to keep current window size
169 // public static CTimer ct;
170 public IntPtr WindowHandle // 2012.10.24 yyagi; to add ASIO support
174 return base.Window.Handle;
177 public CDTXVmode DTXVmode { get; set; }// #28821 2014.1.23 yyagi
186 public void InitializeInstance()
188 #region [ strEXEのあるフォルダを決定する ]
189 // BEGIN #23629 2010.11.13 from: デバッグ時は Application.ExecutablePath が ($SolutionDir)/bin/x86/Debug/ などになり System/ の読み込みに失敗するので、カレントディレクトリを採用する。(プロジェクトのプロパティ→デバッグ→作業ディレクトリが有効になる)
191 strEXEのあるフォルダ = Environment.CurrentDirectory + @"\";
192 //strEXEのあるフォルダ = Path.GetDirectoryName( Environment.GetCommandLineArgs()[ 0 ] ) + @"\";
194 strEXEのあるフォルダ = Path.GetDirectoryName(Application.ExecutablePath) + @"\"; // #23629 2010.11.9 yyagi: set correct pathname where DTXManiaGR.exe is.
196 // END #23629 2010.11.13 from
199 #region [ 言語リソースの初期化 ]
200 Trace.TraceInformation( "言語リソースの初期化を行います。" );
204 Resources = new CResources();
205 Resources.LoadResources( "" );
206 Trace.TraceInformation( "言語リソースの初期化を完了しました。" );
214 #region [ Config.ini の読込み ]
215 ConfigIni = new CConfigXml();
216 CDTXMania.Instance.LoadConfig();
217 // #28200 2011.5.1 yyagi
218 this.Window.EnableSystemMenu = CDTXMania.Instance.ConfigIni.bIsEnabledSystemMenu;
219 // 2012.8.22 Config.iniが無いときに初期値が適用されるよう、この設定行をifブロック外に移動
224 Coordinates = new Coordinates.CCoordinates();
226 //Coordinates = (DTXMania.Coordinates.CCoordinates) CDTXMania.DeserializeXML( strEXEのあるフォルダ + "Coordinates.xml", typeof( DTXMania.Coordinates.CCoordinates ) );
227 //if ( Coordinates == null )
229 // if ( File.Exists( strEXEのあるフォルダ + "Coordinates.xml" ) )
231 // Trace.TraceInformation( "Coordinates.xmlファイルは存在します。" );
233 // Trace.TraceInformation( "Coordiantes.xmlファイルの読み込みができませんでした。無視して進めます。" );
234 // Coordinates = new Coordinates.CCoordinates();
239 Trace.AutoFlush = true;
244 Trace.Listeners.Add(new CTraceLogListener(new StreamWriter(System.IO.Path.Combine(strEXEのあるフォルダ, "DTXManiaLog.txt"), false, Encoding.GetEncoding("utf-16"))));
246 catch (System.UnauthorizedAccessException) // #24481 2011.2.20 yyagi
248 int c = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja") ? 0 : 1;
249 string[] mes_writeErr = {
250 "DTXManiaLog.txtへの書き込みができませんでした。書き込みできるようにしてから、再度起動してください。",
251 "Failed to write DTXManiaLog.txt. Please set it writable and try again."
253 MessageBox.Show(mes_writeErr[c], "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
258 Trace.WriteLine("DTXMania powered by YAMAHA Silent Session Drums");
259 Trace.WriteLine(string.Format("Release: {0}", VERSION));
261 Trace.TraceInformation("----------------------");
262 Trace.TraceInformation("■ アプリケーションの初期化");
263 Trace.TraceInformation("OS Version: " + Environment.OSVersion);
264 Trace.TraceInformation("ProcessorCount: " + Environment.ProcessorCount.ToString());
265 Trace.TraceInformation("CLR Version: " + Environment.Version.ToString());
269 Trace.TraceInformation( "言語情報の読み込みを開始します。" );
270 //Debug.WriteLine( "language=" + Resources.Language );
271 //Debug.WriteLine( "settings=" + instance.ConfigIni.strLanguage );
272 Resources.Language = instance.ConfigIni.strLanguage;
273 Trace.TraceInformation( "言語を{0}に設定しました。", Resources.Language );
278 #region [ DTXVmodeクラス の初期化 ]
279 //Trace.TraceInformation( "DTXVモードの初期化を行います。" );
283 DTXVmode = new CDTXVmode();
284 DTXVmode.Enabled = false;
285 //Trace.TraceInformation( "DTXVモードの初期化を完了しました。" );
292 #region [ コンパクトモードスイッチの有無、もしくは、DTXViewerとしての起動 ]
294 strコンパクトモードファイル = "";
295 string[] commandLineArgs = Environment.GetCommandLineArgs();
296 if ((commandLineArgs != null) && (commandLineArgs.Length > 1))
301 for (int i = 1; i < commandLineArgs.Length; i++)
305 arg += " " + "\"" + commandLineArgs[i] + "\"";
309 arg += commandLineArgs[i];
312 DTXVmode.ParseArguments(arg);
313 if (DTXVmode.Enabled)
315 DTXVmode.Refreshed = false; // 初回起動時は再読み込みに走らせない
316 strコンパクトモードファイル = DTXVmode.filename;
317 switch (DTXVmode.soundDeviceType) // サウンド再生方式の設定
319 case ESoundDeviceType.DirectSound:
320 ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.DSound;
322 case ESoundDeviceType.ExclusiveWASAPI:
323 ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
325 case ESoundDeviceType.SharedWASAPI:
326 ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Shared;
328 case ESoundDeviceType.ASIO:
329 ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.ASIO;
330 ConfigIni.strASIODevice.Index = DTXVmode.nASIOdevice;
334 CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
335 CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
338 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
342 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
345 CDTXMania.Instance.ConfigIni.bFullScreen.Value = false;
346 CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow; // #36612 2016.9.12 yyagi
347 CDTXMania.Instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
348 CDTXMania.Instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
349 CDTXMania.Instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
350 CDTXMania.Instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
354 strコンパクトモードファイル = commandLineArgs[1];
357 if (!File.Exists(strコンパクトモードファイル)) // #32985 2014.1.23 yyagi
359 Trace.TraceError("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。[{0}]", strコンパクトモードファイル);
361 Environment.Exit(-1);
363 if (strコンパクトモードファイル == "") // DTXMania未起動状態で、DTXCで再生停止ボタンを押した場合は、何もせず終了
365 Environment.Exit(-1);
369 throw new FileNotFoundException("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。", strコンパクトモードファイル);
373 if (DTXVmode.Enabled)
375 Trace.TraceInformation("DTXVモードで起動します。[{0}]", strコンパクトモードファイル);
379 Trace.TraceInformation("コンパクトモードで起動します。[{0}]", strコンパクトモードファイル);
384 Trace.TraceInformation( "通常モードで起動します。" );
388 #region [ Input管理 の初期化 ]
389 Trace.TraceInformation("DirectInput, MIDI入力の初期化を行います。");
393 bool bUseMIDIIn = !DTXVmode.Enabled;
394 Input管理 = new CInput管理(base.Window.Handle, bUseMIDIIn);
395 foreach (IInputDevice device in Input管理.list入力デバイス)
397 if ((device.e入力デバイス種別 == E入力デバイス種別.Joystick) && !ConfigIni.dicJoystick.Value.ContainsValue(device.GUID))
400 while (ConfigIni.dicJoystick.Value.ContainsKey(key))
404 ConfigIni.dicJoystick.Value.Add(key, device.GUID);
407 foreach (IInputDevice device2 in Input管理.list入力デバイス)
409 if (device2.e入力デバイス種別 == E入力デバイス種別.Joystick)
411 foreach (KeyValuePair<int, string> pair in ConfigIni.dicJoystick.Value)
413 if (device2.GUID.Equals(pair.Value))
415 ((CInputJoystick)device2).SetID(pair.Key);
422 Trace.TraceInformation("DirectInput の初期化を完了しました。");
424 catch (Exception exception2)
426 Trace.TraceError(exception2.Message);
427 Trace.TraceError("DirectInput, MIDI入力の初期化に失敗しました。");
429 int c = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja") ? 0 : 1;
430 string[] mes_writeErr = {
431 "DirectInputまたはMIDI入力の初期化に失敗しました。DTXManiaGRを終了します。",
432 "Failed to initialize DirectInput (or MIDI-IN)."
434 MessageBox.Show(mes_writeErr[c], "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
444 // #30675 2013.02.04 ikanick add
445 base.Window.StartPosition = FormStartPosition.Manual;
446 base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
447 // 事前にDTXVmodeの実体を作っておくこと
448 base.Window.Text = this.strWindowTitle;
449 //base.Window.StartPosition = FormStartPosition.Manual;
450 //base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
452 // #34510 yyagi 2010.10.31 to change window size got from Config.ini
453 base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
454 #if !WindowedFullscreen
455 if (!ConfigIni.bウィンドウモード) // #23510 2010.11.02 yyagi: add; to recover window size in case bootup with fullscreen mode
456 { // #30666 2013.02.02 yyagi: currentClientSize should be always made
458 currentClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
459 #if !WindowedFullscreen
462 // #23510 2010.11.04 yyagi: to support maximizing window
463 base.Window.MaximizeBox = true;
464 // #23510 2010.10.27 yyagi: changed from FixedDialog to Sizable, to support window resize
465 base.Window.FormBorderStyle = FormBorderStyle.Sizable;
466 // #30666 2013.02.02 yyagi: moved the code to t全画面・ウインドウモード切り替え()
467 base.Window.ShowIcon = true;
468 base.Window.Icon = Properties.Resources.dtx;
469 base.Window.KeyDown += new KeyEventHandler(this.Window_KeyDown);
470 base.Window.MouseUp += new MouseEventHandler(this.Window_MouseUp);
471 // #23510 2010.11.13 yyagi: to go fullscreen mode
472 base.Window.MouseDoubleClick += new MouseEventHandler(this.Window_MouseDoubleClick);
473 // #23510 2010.11.20 yyagi: to set resized window size in Config.ini
474 base.Window.ResizeEnd += new EventHandler(this.Window_ResizeEnd);
475 base.Window.ApplicationActivated += new EventHandler(this.Window_ApplicationActivated);
476 base.Window.ApplicationDeactivated += new EventHandler(this.Window_ApplicationDeactivated);
477 base.Window.MouseMove += new MouseEventHandler(this.Window_MouseMove);
480 #region [ Direct3D9Exを使うかどうか判定 ]
483 #region [ Direct3D9 デバイスの生成 ]
484 DeviceSettings settings = new DeviceSettings();
485 #if WindowedFullscreen
486 // #30666 2013.2.2 yyagi: Fullscreenmode is "Maximized window" mode
487 settings.Windowed = true;
489 settings.Windowed = ConfigIni.bウィンドウモード;
491 settings.BackBufferWidth = SampleFramework.GameWindowSize.Width;
492 settings.BackBufferHeight = SampleFramework.GameWindowSize.Height;
493 // settings.BackBufferCount = 3;
494 settings.EnableVSync = ConfigIni.bVSyncWait;
495 // settings.BackBufferFormat = Format.A8R8G8B8;
496 // settings.MultisampleType = MultisampleType.FourSamples;
497 // settings.MultisampleQuality = 4;
498 // settings.MultisampleType = MultisampleType.None;
499 // settings.MultisampleQuality = 0;
500 settings.Multithreaded = true;
504 base.GraphicsDeviceManager.ChangeDevice(settings);
506 catch (DeviceCreationException e)
508 Trace.TraceError(e.ToString());
509 MessageBox.Show(e.Message + e.ToString(), "DTXMania failed to boot: DirectX9 Initialize Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
510 Environment.Exit(-1);
512 Trace.TraceInformation("DeviceCaps = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps.ToString());
513 Trace.TraceInformation("DeviceCaps2 = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps2.ToString());
514 Trace.TraceInformation("MaxTextureWidth = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureWidth);
515 Trace.TraceInformation("MaxTextureHeight = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureHeight);
516 Trace.TraceInformation("TextureCaps = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.TextureCaps.ToString());
518 base.IsFixedTimeStep = false;
519 // base.TargetElapsedTime = TimeSpan.FromTicks( 10000000 / 75 );
520 // #23510 2010.10.31 yyagi: to recover window size. width and height are able to get from Config.ini.
521 base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
522 // #23568 2010.11.3 yyagi: to support valiable sleep value when !IsActive
523 base.InactiveSleepTime = TimeSpan.FromMilliseconds((float)(ConfigIni.nSleepUnfocusMs));
524 // #23568 2010.11.4 ikanick changed ( 1 -> ConfigIni )
525 #if WindowedFullscreen
526 // #30666 2013.2.2 yyagi: finalize settings for "Maximized window mode"
527 this.t全画面_ウィンドウモード切り替え();
529 actFlushGPU = new CActFlushGPU();
534 #region [ Skin の初期化 ]
535 Trace.TraceInformation("スキンの初期化を行います。");
540 CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath,
541 CDTXMania.Instance.ConfigIni.bUseBoxDefSkin);
542 // 旧指定のSkinフォルダが消滅していた場合に備える
543 CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value = CDTXMania.Instance.Skin.GetCurrentSkinSubfolderFullName(true);
544 Trace.TraceInformation("スキンの初期化を完了しました。");
548 Trace.TraceInformation("スキンの初期化に失敗しました。");
557 #region [ Timer の初期化 ]
558 Trace.TraceInformation("タイマの初期化を行います。");
562 Timer = new CTimer(CTimer.E種別.MultiMedia);
563 Trace.TraceInformation("タイマの初期化を完了しました。");
571 #region [ マウス消去用のクラスを初期化 ]
572 cMouseHideControl = new CMouseHideControl();
575 #region [ FPS カウンタの初期化 ]
576 Trace.TraceInformation("FPSカウンタの初期化を行います。");
581 Trace.TraceInformation("FPSカウンタを生成しました。");
589 #region [ act文字コンソールの初期化 ]
590 Trace.TraceInformation("文字コンソールの初期化を行います。");
594 act文字コンソール = new C文字コンソール();
595 Trace.TraceInformation("文字コンソールを生成しました。");
597 Trace.TraceInformation("文字コンソールを活性化しました。");
598 Trace.TraceInformation("文字コンソールの初期化を完了しました。");
600 catch (Exception exception)
602 Trace.TraceError(exception.Message);
603 Trace.TraceError("文字コンソールの初期化に失敗しました。");
612 Trace.TraceInformation("パッドの初期化を行います。");
617 Trace.TraceInformation("パッドの初期化を完了しました。");
619 catch (Exception exception3)
621 Trace.TraceError(exception3.Message);
622 Trace.TraceError("パッドの初期化に失敗しました。");
630 #region [ Sound管理 の初期化 ]
631 Trace.TraceInformation("サウンドデバイスの初期化を行います。");
635 ESoundDeviceType soundDeviceType;
636 switch (CDTXMania.Instance.ConfigIni.nSoundDeviceType.Value)
638 case ESoundDeviceTypeForConfig.DSound:
639 soundDeviceType = ESoundDeviceType.DirectSound;
641 case ESoundDeviceTypeForConfig.ASIO:
642 soundDeviceType = ESoundDeviceType.ASIO;
644 case ESoundDeviceTypeForConfig.WASAPI_Exclusive:
645 soundDeviceType = ESoundDeviceType.ExclusiveWASAPI;
647 case ESoundDeviceTypeForConfig.WASAPI_Shared:
648 soundDeviceType = ESoundDeviceType.SharedWASAPI;
651 soundDeviceType = ESoundDeviceType.Unknown;
654 Sound管理 = new CSound管理(base.Window.Handle,
656 CDTXMania.Instance.ConfigIni.nWASAPIBufferSizeMs,
657 CDTXMania.instance.ConfigIni.bEventDrivenWASAPI,
659 CDTXMania.Instance.ConfigIni.strASIODevice.Index,
660 CDTXMania.Instance.ConfigIni.bUseOSTimer
662 //Sound管理 = FDK.CSound管理.Instance;
663 //Sound管理.t初期化( soundDeviceType, 0, 0, CDTXMania.Instance.ConfigIni.nASIODevice, base.Window.Handle );
665 ShowWindowTitleWithSoundType();
666 FDK.CSound管理.bIsTimeStretch = CDTXMania.Instance.ConfigIni.bTimeStretch;
667 Sound管理.nMasterVolume = CDTXMania.Instance.ConfigIni.nMasterVolume;
668 //FDK.CSound管理.bIsMP3DecodeByWindowsCodec = CDTXMania.Instance.ConfigIni.bNoMP3Streaming;
669 Trace.TraceInformation("サウンドデバイスの初期化を完了しました。");
673 Trace.TraceError(e.Message);
682 #region [ Songs管理 の初期化 ]
683 //---------------------
684 Trace.TraceInformation("曲リストの初期化を行います。");
688 Songs管理 = new CSongs管理();
689 // Songs管理_裏読 = new CSongs管理();
690 EnumSongs = new CEnumSongs();
691 actEnumSongs = new CActEnumSongs();
692 Trace.TraceInformation("曲リストの初期化を完了しました。");
696 Trace.TraceError(e.Message);
697 Trace.TraceError("曲リストの初期化に失敗しました。");
703 //---------------------
706 #region [ CAvi の初期化 ]
710 #region [ Random の初期化 ]
711 Random = new Random((int)Timer.nシステム時刻);
717 stage起動 = new CStage起動();
718 stageタイトル = new CStageタイトル();
719 stageコンフィグ = new CStageコンフィグ();
720 stage選曲 = new CStage選曲();
721 stage曲読み込み = new CStage曲読み込み();
722 stage演奏画面 = new CStage演奏画面共通();
723 stage結果 = new CStage結果();
724 stageChangeSkin = new CStageChangeSkin();
725 stage終了 = new CStage終了();
727 this.listトップレベルActivities = new List<CActivity>();
728 this.listトップレベルActivities.Add(actEnumSongs);
729 this.listトップレベルActivities.Add(act文字コンソール);
730 this.listトップレベルActivities.Add(stage起動);
731 this.listトップレベルActivities.Add(stageタイトル);
732 this.listトップレベルActivities.Add(stageコンフィグ);
733 this.listトップレベルActivities.Add(stage選曲);
734 this.listトップレベルActivities.Add(stage曲読み込み);
735 this.listトップレベルActivities.Add(stage演奏画面);
736 this.listトップレベルActivities.Add(stage結果);
737 this.listトップレベルActivities.Add(stageChangeSkin);
738 this.listトップレベルActivities.Add(stage終了);
739 this.listトップレベルActivities.Add(actFlushGPU);
742 #region [ プラグインの検索と生成 ]
743 PluginHost = new CPluginHost();
745 Trace.TraceInformation("プラグインの検索と生成を行います。");
750 Trace.TraceInformation("プラグインの検索と生成を完了しました。");
758 #region [ プラグインの初期化 ]
759 if (this.listプラグイン != null && this.listプラグイン.Count > 0)
761 Trace.TraceInformation("プラグインの初期化を行います。");
765 foreach (STPlugin st in this.listプラグイン)
767 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
768 st.plugin.On初期化(this.PluginHost);
769 st.plugin.OnManagedリソースの作成();
770 st.plugin.OnUnmanagedリソースの作成();
771 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
773 Trace.TraceInformation("すべてのプラグインの初期化を完了しました。");
777 Trace.TraceError("プラグインのどれかの初期化に失敗しました。");
788 Trace.TraceInformation("アプリケーションの初期化を完了しました。");
790 #region [ 最初のステージの起動 ]
791 Trace.TraceInformation("----------------------");
792 Trace.TraceInformation("■ 起動");
794 if (CDTXMania.Instance.bコンパクトモード)
796 r現在のステージ = stage曲読み込み;
806 public void t全画面_ウィンドウモード切り替え()
808 #if WindowedFullscreen
809 if (ConfigIni != null)
811 DeviceSettings settings = base.GraphicsDeviceManager.CurrentSettings.Clone();
812 if ( ( ConfigIni != null ) && ( ConfigIni.bウィンドウモード != settings.Windowed ) )
815 #if !WindowedFullscreen
816 settings.Windowed = ConfigIni.bウィンドウモード;
818 if (ConfigIni.bウィンドウモード == false) // #23510 2010.10.27 yyagi: backup current window size before going fullscreen mode
820 currentClientSize = this.Window.ClientSize;
821 ConfigIni.rcWindow.W = this.Window.ClientSize.Width;
822 ConfigIni.rcWindow.H = this.Window.ClientSize.Height;
823 // FDK.CTaskBar.ShowTaskBar( false );
825 #if !WindowedFullscreen
826 base.GraphicsDeviceManager.ChangeDevice( settings );
828 if (ConfigIni.bウィンドウモード == true) // #23510 2010.10.27 yyagi: to resume window size from backuped value
830 #if WindowedFullscreen
831 // #30666 2013.2.2 yyagi Don't use Fullscreen mode becasue NVIDIA GeForce is
832 // tend to delay drawing on Fullscreen mode. So DTXMania uses Maximized window
833 // in spite of using fullscreen mode.
834 Instance.Window.WindowState = FormWindowState.Normal;
835 Instance.Window.FormBorderStyle = FormBorderStyle.Sizable;
836 Instance.Window.WindowState = FormWindowState.Normal;
838 base.Window.ClientSize =
839 new Size(currentClientSize.Width, currentClientSize.Height);
840 // FDK.CTaskBar.ShowTaskBar( true );
842 #if WindowedFullscreen
845 Instance.Window.WindowState = FormWindowState.Normal;
846 Instance.Window.FormBorderStyle = FormBorderStyle.None;
847 Instance.Window.WindowState = FormWindowState.Maximized;
849 if (cMouseHideControl != null)
851 if (ConfigIni.bウィンドウモード)
853 cMouseHideControl.Show();
857 cMouseHideControl.Hide();
864 #region [ #24609 リザルト画像をpngで保存する ] // #24609 2011.3.14 yyagi; to save result screen in case BestRank or HiSkill.
868 /// <param name="strFilename">保存するファイル名(フルパス)</param>
869 public bool SaveResultScreen(string strFullPath)
871 string strSavePath = Path.GetDirectoryName(strFullPath);
872 if (!Directory.Exists(strSavePath))
876 Directory.CreateDirectory(strSavePath);
884 // http://www.gamedev.net/topic/594369-dx9slimdxati-incorrect-saving-surface-to-file/
885 using (Surface pSurface = CDTXMania.Instance.Device.GetRenderTarget(0))
887 Surface.ToFile(pSurface, strFullPath, ImageFileFormat.Png);
895 protected override void Initialize()
899 //swlist1 = new List<int>( 8192 );
900 //swlist2 = new List<int>( 8192 );
901 //swlist3 = new List<int>( 8192 );
902 //swlist4 = new List<int>( 8192 );
903 //swlist5 = new List<int>( 8192 );
904 if (this.listトップレベルActivities != null)
906 foreach (CActivity activity in this.listトップレベルActivities)
907 activity.OnManagedリソースの作成();
910 foreach (STPlugin st in this.listプラグイン)
912 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
913 st.plugin.OnManagedリソースの作成();
914 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
917 #region [ 現在の電源プランをバックアップし、HighPerformanceに変更 ]
918 CPowerPlan.BackupCurrentPowerPlan();
919 if ( CDTXMania.Instance.ConfigIni.bForceHighPowerPlan )
921 CPowerPlan.ChangeHighPerformance();
926 #if GPUFlushAfterPresent
927 FrameEnd += dtxmania_FrameEnd;
930 #if GPUFlushAfterPresent
931 void dtxmania_FrameEnd( object sender, EventArgs e ) // GraphicsDeviceManager.game_FrameEnd()後に実行される
932 { // → Present()直後にGPUをFlushする
933 // → 画面のカクツキが頻発したため、ここでのFlushは行わない
934 actFlushGPU.On進行描画(); // Flush GPU
937 protected override void LoadContent()
939 if (cMouseHideControl != null)
941 if (ConfigIni.bウィンドウモード)
943 cMouseHideControl.Show();
947 cMouseHideControl.Hide();
950 this.Device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0f, 0f, (float)(-SampleFramework.GameWindowSize.Height / 2 * Math.Sqrt(3.0))), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)));
951 this.Device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH(C変換.DegreeToRadian((float)60f), ((float)this.Device.Viewport.Width) / ((float)this.Device.Viewport.Height), -100f, 100f));
952 this.Device.SetRenderState(RenderState.Lighting, false);
953 this.Device.SetRenderState(RenderState.ZEnable, false);
954 this.Device.SetRenderState(RenderState.AntialiasedLineEnable, false);
955 this.Device.SetRenderState(RenderState.AlphaTestEnable, true);
956 this.Device.SetRenderState(RenderState.AlphaRef, 10);
958 this.Device.SetRenderState(RenderState.MultisampleAntialias, true);
959 this.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
960 this.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
962 this.Device.SetRenderState<Compare>(RenderState.AlphaFunc, Compare.Greater);
963 this.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
964 this.Device.SetRenderState<Blend>(RenderState.SourceBlend, Blend.SourceAlpha);
965 this.Device.SetRenderState<Blend>(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
966 this.Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
967 this.Device.SetTextureStageState(0, TextureStage.AlphaArg1, 2);
968 this.Device.SetTextureStageState(0, TextureStage.AlphaArg2, 1);
970 if (this.listトップレベルActivities != null)
972 foreach (CActivity activity in this.listトップレベルActivities)
973 activity.OnUnmanagedリソースの作成();
976 foreach (STPlugin st in this.listプラグイン)
978 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
979 st.plugin.OnUnmanagedリソースの作成();
980 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
983 protected override void UnloadContent()
985 if (this.listトップレベルActivities != null)
987 foreach (CActivity activity in this.listトップレベルActivities)
988 activity.OnUnmanagedリソースの解放();
991 foreach (STPlugin st in this.listプラグイン)
993 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
994 st.plugin.OnUnmanagedリソースの解放();
995 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
998 protected override void OnExiting(EventArgs e)
1000 CPowerPlan.RestoreCurrentPowerPlan(); // 電源プランを元のものに戻す
1001 CPowerManagement.tEnableMonitorSuspend(); // スリープ抑止状態を解除
1005 protected override void Update(GameTime gameTime)
1008 protected override void Draw(GameTime gameTime)
1010 Sound管理.t再生中の処理をする();
1014 if (CSound管理.rc演奏用タイマ != null)
1015 CSound管理.rc演奏用タイマ.t更新();
1017 if (Input管理 != null)
1018 Input管理.tポーリング(this.bApplicationActive, CDTXMania.Instance.ConfigIni.bBufferedInput);
1023 //if( Pad != null ) ポーリング時にクリアしたらダメ!曲の開始時に1回だけクリアする。(2010.9.11)
1024 // Pad.st検知したデバイス.Clear();
1026 if (this.Device == null)
1029 if (this.bApplicationActive) // DTXMania本体起動中の本体/モニタの省電力モード移行を抑止
1030 CPowerManagement.tDisableMonitorSuspend();
1032 // #xxxxx 2013.4.8 yyagi; sleepの挿入位置を、EndScnene~Present間から、BeginScene前に移動。描画遅延を小さくするため。
1034 if (ConfigIni.nSleepPerFrameMs >= 0) // #xxxxx 2011.11.27 yyagi
1036 Thread.Sleep(ConfigIni.nSleepPerFrameMs);
1040 #region [ DTXCreatorからの指示 ]
1041 if (this.Window.IsReceivedMessage) // ウインドウメッセージで、
1043 string strMes = this.Window.strMessage;
1044 this.Window.IsReceivedMessage = false;
1048 DTXVmode.ParseArguments(strMes);
1050 if (DTXVmode.Enabled)
1053 strコンパクトモードファイル = DTXVmode.filename;
1054 if (DTXVmode.Command == CDTXVmode.ECommand.Preview)
1057 string strPreviewFilename = DTXVmode.previewFilename;
1058 //Trace.TraceInformation( "Preview Filename=" + DTXVmode.previewFilename );
1061 if (this.previewSound != null)
1063 this.previewSound.tサウンドを停止する();
1064 this.previewSound.Dispose();
1065 this.previewSound = null;
1067 this.previewSound = CDTXMania.Instance.Sound管理.tサウンドを生成する(strPreviewFilename);
1068 this.previewSound.n音量 = DTXVmode.previewVolume;
1069 this.previewSound.n位置 = DTXVmode.previewPan;
1070 this.previewSound.t再生を開始する();
1071 Trace.TraceInformation("DTXCからの指示で、サウンドを生成しました。({0})", strPreviewFilename);
1075 Trace.TraceError("DTXCからの指示での、サウンドの生成に失敗しました。({0})", strPreviewFilename);
1076 if (this.previewSound != null)
1078 this.previewSound.Dispose();
1080 this.previewSound = null;
1088 this.Device.BeginScene();
1089 this.Device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, SharpDX.Color.Black, 1f, 0);
1091 if (r現在のステージ != null)
1093 this.n進行描画の戻り値 = (r現在のステージ != null) ? r現在のステージ.On進行描画() : 0;
1095 #region [ プラグインの進行描画 ]
1096 //---------------------
1097 foreach (STPlugin sp in this.listプラグイン)
1099 Directory.SetCurrentDirectory(sp.strプラグインフォルダ);
1101 if (CDTXMania.Instance.act現在入力を占有中のプラグイン == null || CDTXMania.Instance.act現在入力を占有中のプラグイン == sp.plugin)
1102 sp.plugin.On進行描画(CDTXMania.Instance.Pad, CDTXMania.Instance.Input管理.Keyboard);
1104 sp.plugin.On進行描画(null, null);
1106 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1108 //---------------------
1112 CScoreIni scoreIni = null;
1114 if (Control.IsKeyLocked(Keys.CapsLock)) // #30925 2013.3.11 yyagi; capslock=ON時は、EnumSongsしないようにして、起動負荷とASIOの音切れの関係を確認する
1116 // → songs.db等の書き込み時だと音切れするっぽい
1117 actEnumSongs.On非活性化();
1118 EnumSongs.SongListEnumCompletelyDone();
1119 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1121 #region [ 曲検索スレッドの起動/終了 ここに"Enumerating Songs..."表示を集約 ]
1122 if (!CDTXMania.Instance.bコンパクトモード)
1124 actEnumSongs.On進行描画(); // "Enumerating Songs..."アイコンの描画
1126 switch (r現在のステージ.eステージID)
1128 case CStage.Eステージ.タイトル:
1129 case CStage.Eステージ.コンフィグ:
1130 case CStage.Eステージ.選曲:
1131 case CStage.Eステージ.曲読み込み:
1132 if (EnumSongs != null)
1134 #region [ (特定条件時) 曲検索スレッドの起動・開始 ]
1135 if (r現在のステージ.eステージID == CStage.Eステージ.タイトル &&
1136 r直前のステージ.eステージID == CStage.Eステージ.起動 &&
1137 this.n進行描画の戻り値 == (int)CStageタイトル.E戻り値.継続 &&
1138 !EnumSongs.IsSongListEnumStarted)
1140 actEnumSongs.On活性化();
1141 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = true;
1142 EnumSongs.Init(CDTXMania.Instance.Songs管理.listSongsDB, CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数); // songs.db情報と、取得した曲数を、新インスタンスにも与える
1143 EnumSongs.StartEnumFromDisk(); // 曲検索スレッドの起動・開始
1144 if (CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数 == 0) // もし初回起動なら、検索スレッドのプライオリティをLowestでなくNormalにする
1146 EnumSongs.ChangeEnumeratePriority(ThreadPriority.Normal);
1151 #region [ 曲検索の中断と再開 ]
1152 if (r現在のステージ.eステージID == CStage.Eステージ.選曲 && !EnumSongs.IsSongListEnumCompletelyDone)
1154 switch (this.n進行描画の戻り値)
1157 //if ( CDTXMania.Instance.stage選曲.bIsEnumeratingSongs )
1158 if (!CDTXMania.Instance.stage選曲.bIsPlayingPremovie)
1160 EnumSongs.Resume(); // #27060 2012.2.6 yyagi 中止していたバックグランド曲検索を再開
1161 EnumSongs.IsSlowdown = false;
1165 // EnumSongs.Suspend(); // #27060 2012.3.2 yyagi #PREMOVIE再生中は曲検索を低速化
1166 EnumSongs.IsSlowdown = true;
1168 actEnumSongs.On活性化();
1172 EnumSongs.Suspend(); // #27060 バックグラウンドの曲検索を一時停止
1173 actEnumSongs.On非活性化();
1179 #region [ 曲探索中断待ち待機 ]
1180 if (r現在のステージ.eステージID == CStage.Eステージ.曲読み込み && !EnumSongs.IsSongListEnumCompletelyDone &&
1181 EnumSongs.thDTXFileEnumerate != null) // #28700 2012.6.12 yyagi; at Compact mode, enumerating thread does not exist.
1183 EnumSongs.WaitUntilSuspended(); // 念のため、曲検索が一時中断されるまで待機
1187 #region [ 曲検索が完了したら、実際の曲リストに反映する ]
1188 // CStage選曲.On活性化() に回した方がいいかな?
1189 if (EnumSongs.IsSongListEnumerated)
1191 actEnumSongs.On非活性化();
1192 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1194 bool bRemakeSongTitleBar = (r現在のステージ.eステージID == CStage.Eステージ.選曲) ? true : false;
1195 CDTXMania.Instance.stage選曲.Refresh(EnumSongs.Songs管理, bRemakeSongTitleBar);
1196 EnumSongs.SongListEnumCompletelyDone();
1204 switch (r現在のステージ.eステージID)
1206 case CStage.Eステージ.何もしない:
1209 case CStage.Eステージ.起動:
1211 //-----------------------------
1212 if (this.n進行描画の戻り値 != 0)
1217 Trace.TraceInformation("----------------------");
1218 Trace.TraceInformation("■ タイトル");
1220 r直前のステージ = r現在のステージ;
1221 r現在のステージ = stageタイトル;
1226 Trace.TraceInformation("----------------------");
1227 Trace.TraceInformation("■ 曲読み込み");
1229 r直前のステージ = r現在のステージ;
1230 r現在のステージ = stage曲読み込み;
1233 foreach (STPlugin pg in this.listプラグイン)
1235 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1236 pg.plugin.Onステージ変更();
1237 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1240 this.tガベージコレクションを実行する();
1242 //-----------------------------
1246 case CStage.Eステージ.タイトル:
1248 //-----------------------------
1249 switch (this.n進行描画の戻り値)
1251 case (int)CStageタイトル.E戻り値.GAMESTART:
1253 //-----------------------------
1255 Trace.TraceInformation("----------------------");
1256 Trace.TraceInformation("■ 選曲");
1258 r直前のステージ = r現在のステージ;
1260 //-----------------------------
1264 #region [ OPTION: 廃止済 ]
1265 // case 2: // #24525 OPTIONとCONFIGの統合に伴い、OPTIONは廃止
1267 // //-----------------------------
1268 // r現在のステージ.On非活性化();
1269 // Trace.TraceInformation( "----------------------" );
1270 // Trace.TraceInformation( "■ オプション" );
1271 // stageオプション.On活性化();
1272 // r直前のステージ = r現在のステージ;
1273 // r現在のステージ = stageオプション;
1274 // //-----------------------------
1279 case (int)CStageタイトル.E戻り値.CONFIG:
1281 //-----------------------------
1283 Trace.TraceInformation("----------------------");
1284 Trace.TraceInformation("■ コンフィグ");
1286 r直前のステージ = r現在のステージ;
1287 r現在のステージ = stageコンフィグ;
1288 //-----------------------------
1292 case (int)CStageタイトル.E戻り値.EXIT:
1294 //-----------------------------
1296 Trace.TraceInformation("----------------------");
1297 Trace.TraceInformation("■ 終了");
1299 r直前のステージ = r現在のステージ;
1301 //-----------------------------
1306 foreach (STPlugin pg in this.listプラグイン)
1308 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1309 pg.plugin.Onステージ変更();
1310 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1313 //this.tガベージコレクションを実行する(); // #31980 2013.9.3 yyagi タイトル画面でだけ、毎フレームGCを実行して重くなっていた問題の修正
1314 //-----------------------------
1318 case CStage.Eステージ.コンフィグ:
1320 //-----------------------------
1321 if (this.n進行描画の戻り値 != 0)
1323 switch (r直前のステージ.eステージID)
1325 case CStage.Eステージ.タイトル:
1327 //-----------------------------
1329 Trace.TraceInformation("----------------------");
1330 Trace.TraceInformation("■ タイトル");
1332 r直前のステージ = r現在のステージ;
1333 r現在のステージ = stageタイトル;
1335 foreach (STPlugin pg in this.listプラグイン)
1337 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1338 pg.plugin.Onステージ変更();
1339 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1342 this.tガベージコレクションを実行する();
1344 //-----------------------------
1347 case CStage.Eステージ.選曲:
1349 //-----------------------------
1351 Trace.TraceInformation("----------------------");
1352 Trace.TraceInformation("■ 選曲");
1354 r直前のステージ = r現在のステージ;
1357 foreach (STPlugin pg in this.listプラグイン)
1359 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1360 pg.plugin.Onステージ変更();
1361 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1364 this.tガベージコレクションを実行する();
1366 //-----------------------------
1370 //-----------------------------
1374 case CStage.Eステージ.選曲:
1376 //-----------------------------
1377 switch (this.n進行描画の戻り値)
1379 case (int)CStage選曲.E戻り値.タイトルに戻る:
1381 //-----------------------------
1383 Trace.TraceInformation("----------------------");
1384 Trace.TraceInformation("■ タイトル");
1386 r直前のステージ = r現在のステージ;
1387 r現在のステージ = stageタイトル;
1389 foreach (STPlugin pg in this.listプラグイン)
1391 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1392 pg.plugin.Onステージ変更();
1393 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1396 this.tガベージコレクションを実行する();
1398 //-----------------------------
1401 case (int)CStage選曲.E戻り値.選曲した:
1403 //-----------------------------
1405 Trace.TraceInformation("----------------------");
1406 Trace.TraceInformation("■ 曲読み込み");
1408 r直前のステージ = r現在のステージ;
1409 r現在のステージ = stage曲読み込み;
1411 foreach (STPlugin pg in this.listプラグイン)
1413 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1414 pg.plugin.Onステージ変更();
1415 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1418 this.tガベージコレクションを実行する();
1420 //-----------------------------
1423 case (int)CStage選曲.E戻り値.コンフィグ呼び出し:
1425 //-----------------------------
1427 Trace.TraceInformation("----------------------");
1428 Trace.TraceInformation("■ コンフィグ");
1430 r直前のステージ = r現在のステージ;
1431 r現在のステージ = stageコンフィグ;
1433 foreach (STPlugin pg in this.listプラグイン)
1435 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1436 pg.plugin.Onステージ変更();
1437 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1440 this.tガベージコレクションを実行する();
1442 //-----------------------------
1445 case (int)CStage選曲.E戻り値.スキン変更:
1448 //-----------------------------
1450 Trace.TraceInformation("----------------------");
1451 Trace.TraceInformation("■ スキン切り替え");
1452 stageChangeSkin.On活性化();
1453 r直前のステージ = r現在のステージ;
1454 r現在のステージ = stageChangeSkin;
1456 //-----------------------------
1459 //-----------------------------
1463 case CStage.Eステージ.曲読み込み:
1465 //-----------------------------
1466 DTXVmode.Refreshed = false; // 曲のリロード中に発生した再リロードは、無視する。
1467 if (this.n進行描画の戻り値 != 0)
1469 CDTXMania.Instance.Pad.st検知したデバイス.Clear(); // 入力デバイスフラグクリア(2010.9.11)
1471 #region [ ESC押下時は、曲の読み込みを中止して選曲画面に戻る ]
1472 if (this.n進行描画の戻り値 == (int)E曲読込画面の戻り値.読込中止)
1476 Trace.TraceInformation("曲の読み込みを中止しました。");
1477 this.tガベージコレクションを実行する();
1478 Trace.TraceInformation("----------------------");
1479 Trace.TraceInformation("■ 選曲");
1481 r直前のステージ = r現在のステージ;
1483 foreach (STPlugin pg in this.listプラグイン)
1485 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1486 pg.plugin.Onステージ変更();
1487 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1493 Trace.TraceInformation("----------------------");
1494 Trace.TraceInformation("■ 演奏(ドラム画面)");
1495 r直前のステージ = r現在のステージ;
1496 r現在のステージ = stage演奏画面;
1498 foreach (STPlugin pg in this.listプラグイン)
1500 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1501 pg.plugin.Onステージ変更();
1502 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1505 this.tガベージコレクションを実行する();
1507 //-----------------------------
1511 case CStage.Eステージ.演奏:
1513 //-----------------------------
1514 //long n1 = FDK.CSound管理.rc演奏用タイマ.nシステム時刻ms;
1515 //long n2 = FDK.CSound管理.SoundDevice.n経過時間ms;
1516 //long n3 = FDK.CSound管理.SoundDevice.tmシステムタイマ.nシステム時刻ms;
1517 //long n4 = FDK.CSound管理.rc演奏用タイマ.n現在時刻;
1518 //long n5 = FDK.CSound管理.SoundDevice.n経過時間を更新したシステム時刻ms;
1520 //swlist1.Add( Convert.ToInt32(n1) );
1521 //swlist2.Add( Convert.ToInt32(n2) );
1522 //swlist3.Add( Convert.ToInt32( n3 ) );
1523 //swlist4.Add( Convert.ToInt32( n4 ) );
1524 //swlist5.Add( Convert.ToInt32( n5 ) );
1526 #region [ DTXVモード中にDTXCreatorから指示を受けた場合の処理 ]
1527 if (DTXVmode.Enabled && DTXVmode.Refreshed)
1529 DTXVmode.Refreshed = false;
1531 if (DTXVmode.Command == CDTXVmode.ECommand.Stop)
1533 CDTXMania.Instance.stage演奏画面.t停止();
1535 if (previewSound != null)
1537 this.previewSound.tサウンドを停止する();
1538 this.previewSound.Dispose();
1539 this.previewSound = null;
1544 // for ( int i = 0; i < swlist1.Count; i++ )
1546 // int d1 = swlist1[ i ];
1547 // int d2 = swlist2[ i ];
1548 // int d3 = swlist3[ i ];
1549 // int d4 = swlist4[ i ];
1550 // int d5 = swlist5[ i ];
1552 // int dif = d1 - lastd;
1554 // if ( 16 <= dif && dif <= 17 )
1561 // Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3} - {7:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4, d5 );
1573 else if (DTXVmode.Command == CDTXVmode.ECommand.Play)
1575 if (DTXVmode.NeedReload)
1577 CDTXMania.Instance.stage演奏画面.t再読込();
1578 if (DTXVmode.GRmode)
1580 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
1584 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
1586 CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
1587 CSound管理.bIsTimeStretch = DTXVmode.TimeStretch;
1588 if (CDTXMania.Instance.ConfigIni.bVSyncWait != DTXVmode.VSyncWait)
1590 CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
1591 CDTXMania.Instance.b次のタイミングで垂直帰線同期切り替えを行う = true;
1596 CDTXMania.Instance.stage演奏画面.t演奏位置の変更(CDTXMania.Instance.DTXVmode.nStartBar);
1602 switch (this.n進行描画の戻り値)
1604 case (int)E演奏画面の戻り値.再読込_再演奏:
1605 #region [ DTXファイルを再読み込みして、再演奏 ]
1610 r直前のステージ = r現在のステージ;
1611 r現在のステージ = stage曲読み込み;
1612 this.tガベージコレクションを実行する();
1616 //case (int) E演奏画面の戻り値.再演奏:
1617 #region [ 再読み込み無しで、再演奏 ]
1621 case (int)E演奏画面の戻り値.継続:
1624 case (int)E演奏画面の戻り値.演奏中断:
1626 //-----------------------------
1627 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Play canceled");
1628 if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass) // #35417 2015.8.18 yyagi Gt/Bsを入れ替えていたなら、演奏設定を元に戻す
1630 //CDTXMania.Instance.DTX.SwapGuitarBassInfos(); // 譜面情報も元に戻す (現在は再演奏機能なしのため、元に戻す必要はない)
1635 //for (int i = 0; i < swlist1.Count; i++)
1637 // int d1 = swlist1[ i ];
1638 // int d2 = swlist2[ i ];
1639 // int d3 = swlist3[ i ];
1640 // int d4 = swlist4[ i ];
1642 // int dif = d1 - lastd;
1644 // if ( 16 <= dif && dif <= 17 )
1651 // Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4 );
1660 #region [ プラグイン On演奏キャンセル() の呼び出し ]
1661 //---------------------
1662 foreach (STPlugin pg in this.listプラグイン)
1664 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1665 pg.plugin.On演奏キャンセル(scoreIni);
1666 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1668 //---------------------
1676 base.Window.Close();
1680 Trace.TraceInformation("----------------------");
1681 Trace.TraceInformation("■ 選曲");
1683 r直前のステージ = r現在のステージ;
1686 #region [ プラグイン Onステージ変更() の呼び出し ]
1687 //---------------------
1688 foreach (STPlugin pg in this.listプラグイン)
1690 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1691 pg.plugin.Onステージ変更();
1692 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1694 //---------------------
1697 this.tガベージコレクションを実行する();
1700 //-----------------------------
1703 case (int)E演奏画面の戻り値.ステージ失敗:
1704 #region [ 演奏失敗(StageFailed) ]
1705 //-----------------------------
1706 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Stage failed");
1708 #region [ プラグイン On演奏失敗() の呼び出し ]
1709 //---------------------
1710 foreach (STPlugin pg in this.listプラグイン)
1712 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1713 pg.plugin.On演奏失敗(scoreIni);
1714 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1716 //---------------------
1724 base.Window.Close();
1728 Trace.TraceInformation("----------------------");
1729 Trace.TraceInformation("■ 選曲");
1731 r直前のステージ = r現在のステージ;
1734 #region [ プラグイン Onステージ変更() の呼び出し ]
1735 //---------------------
1736 foreach (STPlugin pg in this.listプラグイン)
1738 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1739 pg.plugin.Onステージ変更();
1740 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1742 //---------------------
1745 this.tガベージコレクションを実行する();
1748 //-----------------------------
1751 case (int)E演奏画面の戻り値.ステージクリア:
1753 //-----------------------------
1754 STDGBSValue<CScoreIni.C演奏記録> record;
1755 record = stage演奏画面.Record;
1757 double playskill = 0.0;
1759 for (EPart inst = EPart.Drums; inst <= EPart.Bass; ++inst)
1761 if (!record[inst].b全AUTOである && record[inst].n全チップ数 > 0)
1763 playskill = record[inst].db演奏型スキル値;
1767 string str = "Cleared";
1768 switch (CScoreIni.t総合ランク値を計算して返す(record))
1770 case CScoreIni.ERANK.SS:
1771 str = string.Format("Cleared (SS: {0:F2})", playskill);
1774 case CScoreIni.ERANK.S:
1775 str = string.Format("Cleared (S: {0:F2})", playskill);
1778 case CScoreIni.ERANK.A:
1779 str = string.Format("Cleared (A: {0:F2})", playskill);
1782 case CScoreIni.ERANK.B:
1783 str = string.Format("Cleared (B: {0:F2})", playskill);
1786 case CScoreIni.ERANK.C:
1787 str = string.Format("Cleared (C: {0:F2})", playskill);
1790 case CScoreIni.ERANK.D:
1791 str = string.Format("Cleared (D: {0:F2})", playskill);
1794 case CScoreIni.ERANK.E:
1795 str = string.Format("Cleared (E: {0:F2})", playskill);
1798 case CScoreIni.ERANK.UNKNOWN: // #23534 2010.10.28 yyagi add: 演奏チップが0個のとき
1799 str = "Cleared (No chips)";
1803 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新(str);
1805 #region [ プラグイン On演奏クリア() の呼び出し ]
1806 //---------------------
1807 foreach (STPlugin pg in this.listプラグイン)
1809 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1810 pg.plugin.On演奏クリア(scoreIni);
1811 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1813 //---------------------
1817 Trace.TraceInformation("----------------------");
1818 Trace.TraceInformation("■ 結果");
1819 stage結果.st演奏記録 = record;
1820 stage結果.r空うちドラムチップ = stage演奏画面.GetNoChipDrums();
1822 r直前のステージ = r現在のステージ;
1825 #region [ プラグイン Onステージ変更() の呼び出し ]
1826 //---------------------
1827 foreach (STPlugin pg in this.listプラグイン)
1829 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1830 pg.plugin.Onステージ変更();
1831 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1833 //---------------------
1837 //-----------------------------
1840 //-----------------------------
1844 case CStage.Eステージ.結果:
1846 //-----------------------------
1847 if (this.n進行描画の戻り値 != 0)
1849 // #35417 2015.08.30 chnmr0 changed : ステージクリア処理で入れ替えるため元に戻した
1850 // #35417 2015.8.18 yyagi: AUTO系のフラグ入れ替えは削除可能!?。以後AUTOフラグに全くアクセスしておらず、意味がないため。
1851 if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass) // #24415 2011.2.27 yyagi Gt/Bsを入れ替えていたなら、Auto状態をリザルト画面終了後に元に戻す
1853 CDTXMania.Instance.ConfigIni.SwapGuitarBassInfos_AutoFlags(); // Auto入れ替え
1861 Trace.TraceInformation("----------------------");
1862 Trace.TraceInformation("■ 選曲");
1864 r直前のステージ = r現在のステージ;
1867 foreach (STPlugin pg in this.listプラグイン)
1869 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1870 pg.plugin.Onステージ変更();
1871 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1874 this.tガベージコレクションを実行する();
1878 base.Window.Close();
1881 //-----------------------------
1885 case CStage.Eステージ.ChangeSkin:
1887 //-----------------------------
1888 if (this.n進行描画の戻り値 != 0)
1891 Trace.TraceInformation("----------------------");
1892 Trace.TraceInformation("■ 選曲");
1894 r直前のステージ = r現在のステージ;
1896 this.tガベージコレクションを実行する();
1898 //-----------------------------
1902 case CStage.Eステージ.終了:
1904 //-----------------------------
1905 if (this.n進行描画の戻り値 != 0)
1909 //-----------------------------
1914 this.Device.EndScene();
1915 // Present()は game.csのOnFrameEnd()に登録された、GraphicsDeviceManager.game_FrameEnd() 内で実行されるので不要
1916 // (つまり、Present()は、Draw()完了後に実行される)
1917 #if !GPUFlushAfterPresent
1918 actFlushGPU.On進行描画(); // Flush GPU // EndScene()~Present()間 (つまりVSync前) でFlush実行
1920 if (Sound管理.GetCurrentSoundDeviceType() != "DirectSound")
1922 Sound管理.t再生中の処理をする(); // サウンドバッファの更新; 画面描画と同期させることで、スクロールをスムーズにする
1925 #region [ マウスカーソル消去制御 ]
1926 cMouseHideControl.tHideCursorIfNeed();
1928 #region [ 全画面・ウインドウ切り替え ]
1929 if (this.b次のタイミングで全画面_ウィンドウ切り替えを行う)
1931 // ConfigIni.bFullScreen.Value = !ConfigIni.bFullScreen;
1932 Instance.t全画面_ウィンドウモード切り替え();
1933 this.b次のタイミングで全画面_ウィンドウ切り替えを行う = false;
1936 #region [ 垂直基線同期切り替え ]
1937 if (this.b次のタイミングで垂直帰線同期切り替えを行う)
1939 bool bIsMaximized = this.Window.IsMaximized; // #23510 2010.11.3 yyagi: to backup current window mode before changing VSyncWait
1940 currentClientSize = this.Window.ClientSize; // #23510 2010.11.3 yyagi: to backup current window size before changing VSyncWait
1941 DeviceSettings currentSettings = Instance.GraphicsDeviceManager.CurrentSettings;
1942 currentSettings.EnableVSync = ConfigIni.bVSyncWait;
1943 Instance.GraphicsDeviceManager.ChangeDevice(currentSettings);
1944 this.b次のタイミングで垂直帰線同期切り替えを行う = false;
1945 base.Window.ClientSize = new Size(currentClientSize.Width, currentClientSize.Height); // #23510 2010.11.3 yyagi: to resume window size after changing VSyncWait
1948 this.Window.WindowState = FormWindowState.Maximized; // #23510 2010.11.3 yyagi: to resume window mode after changing VSyncWait
1953 //GC.Collect( 0, GCCollectionMode.Optimized, false ); // Rel105で処理が重くなっていることに対する、暫定処置。
1954 // 重くなっている原因に対する適切な処置をして、処理が104程度に軽くなったら、
1959 /// XML ファイルからオブジェクトを生成します。
1961 /// <param name="xmlfile">オブジェクトが記述される XML のパス。これは DataContract によってシリアライズされていなければなりません。</param>
1962 /// <returns>生成したオブジェクト。正しく生成できなかった場合 null 。</returns>
1963 public static object DeserializeXML(string xmlpath, Type t)
1968 if (File.Exists(xmlpath))
1970 using (XmlReader xr = XmlReader.Create(xmlpath))
1972 DataContractSerializer serializer = new DataContractSerializer(t);
1973 ret = serializer.ReadObject(xr);
1979 Trace.TraceWarning( e.Message );
1986 /// オブジェクトから XML ファイルを生成します。
1988 /// <param name="xmlfile">XML ファイルのパス。</param>
1989 /// <param name="obj">XML としてシリアライズするオブジェクト。DataContract 属性を持つクラスからインスタンス化されたオブジェクトです。</param>
1990 public static void SerializeXML(string xmlpath, object obj)
1992 XmlWriterSettings settings = new XmlWriterSettings();
1993 settings.IndentChars = " ";
1994 settings.Indent = true;
1995 settings.NewLineChars = Environment.NewLine;
1996 settings.Encoding = new System.Text.UTF8Encoding(false);
1997 using ( XmlWriter xw = XmlWriter.Create( new FileStreamSSD( xmlpath ), settings ) )
1999 DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
2000 serializer.WriteObject(xw, obj);
2004 public void SaveConfig()
2006 #region [ Skinパスの絶対パス→相対パス変換 ]
2007 string _strSystemSkinSubfolderPath = ConfigIni.strSystemSkinSubfolderPath.Value;
2008 Uri uriRoot = new Uri( System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar ) );
2009 if ( ConfigIni.strSystemSkinSubfolderPath.Value != null && ConfigIni.strSystemSkinSubfolderPath.Value.Length == 0 )
2011 // Config.iniが空の状態でDTXManiaをViewerとして起動・終了すると、strSystemSkinSubfolderFullName が空の状態でここに来る。
2012 // → 初期値として Default/ を設定する。
2013 ConfigIni.strSystemSkinSubfolderPath.Value = System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar + "Default" + System.IO.Path.DirectorySeparatorChar );
2016 // 起動直後は(Loadの前にSaveを通るため)Skinパスには初期値の相対パスが入っている場合がある。
2017 // そのため、以下の処理を通すために、いったん絶対パスに変換
2018 if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2020 ConfigIni.strSystemSkinSubfolderPath.Value =
2021 Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2024 Uri uriPath = new Uri( System.IO.Path.Combine( ConfigIni.strSystemSkinSubfolderPath.Value, "." + System.IO.Path.DirectorySeparatorChar ) );
2025 string relPath = uriRoot.MakeRelativeUri( uriPath ).ToString(); // 相対パスを取得
2026 relPath = System.Web.HttpUtility.UrlDecode( relPath ); // デコードする
2027 relPath = relPath.Replace( '/', System.IO.Path.DirectorySeparatorChar ); // 区切り文字が\ではなく/なので置換する
2028 ConfigIni.strSystemSkinSubfolderPath.Value = relPath;
2030 ConfigIni.strDTXManiaVersion.Value = CDTXMania.VERSION;
2032 CDTXMania.SerializeXML( strEXEのあるフォルダ + "Config.xml", ConfigIni );
2035 ConfigIni.strSystemSkinSubfolderPath.Value = _strSystemSkinSubfolderPath;
2038 public void LoadConfig()
2040 string path = strEXEのあるフォルダ + "Config.xml";
2042 if (!File.Exists(path))
2046 if (File.Exists(path))
2048 ConfigIni = (CConfigXml)CDTXMania.DeserializeXML(path, typeof(CConfigXml));
2049 if (ConfigIni == null)
2051 ConfigIni = new CConfigXml();
2054 // Skinパスの相対パスを、絶対パスに変換
2055 if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2057 ConfigIni.strSystemSkinSubfolderPath.Value =
2058 Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2063 /// 座標値を読み込む。Coordinates メンバ初期化後いつ呼び出しても構わない。
2065 public void UpdateCoordinates()
2067 string coordXml = strEXEのあるフォルダ + "Coordinates.xml";
2070 if (File.Exists(coordXml))
2072 using (XmlReader xr = XmlReader.Create(coordXml))
2074 DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2077 Coordinates = (Coordinates.CCoordinates) serializer.ReadObject( xr );
2079 catch (SerializationException e)
2081 Trace.TraceWarning( "Rel107以前の古いフォーマットのCoordinates.xmlが読み込まれました。無視します。\n" + e.Message );
2086 XmlWriterSettings settings = new XmlWriterSettings();
2087 settings.IndentChars = " ";
2088 settings.Indent = true;
2089 settings.NewLineChars = Environment.NewLine;
2090 settings.Encoding = new System.Text.UTF8Encoding( false );
2091 using ( XmlWriter xw = XmlTextWriter.Create( coordXml, settings ) )
2093 //XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
2094 //ns.Add( String.Empty, String.Empty );
2096 //StreamWriter sw = new StreamWriter( "test2.xml", false, Encoding.UTF8 );
2097 //serializer.Serialize( sw, item, ns );
2100 DataContractSerializer serializer = new DataContractSerializer( typeof( Coordinates.CCoordinates ) );
2101 serializer.WriteObject( xw, Coordinates );
2102 //serializer.WriteStartObject( xw, Coordinates );
2103 //xw.WriteAttributeString( "xmlns", "d1p1", "http://www.w3.org/2000/xmlns/",
2104 // "http://schemas.microsoft.com/2003/10/Serialization/" );
2105 //serializer.WriteObjectContent( xw, Coordinates );
2106 //serializer.WriteEndObject( xw );
2110 if (File.Exists(coordXml))
2112 using (XmlReader xr = XmlReader.Create(coordXml))
2114 DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2115 Coordinates = (Coordinates.CCoordinates)serializer.ReadObject(xr);
2122 /// 保存するxmlからnamespaceを削除するためのXmlTextWriter
2124 //public class MyXmlTextWriter : XmlTextWriter
2126 // private bool _ignoreAttr = false;
2128 // public MyXmlTextWriter( TextWriter w )
2131 // Debug.WriteLine( "create" );
2134 // public override string LookupPrefix( string ns )
2136 // Debug.WriteLine( "luprefix" );
2137 // return string.Empty;
2140 // public override void WriteStartAttribute( string prefix, string localName, string ns )
2142 // Debug.WriteLine( "writestartattribute" );
2143 // if ( String.Compare( prefix, "xmlns", true ) == 0 )
2145 // Debug.WriteLine( "[!]" );
2146 // this._ignoreAttr = true;
2151 // public override void WriteEndAttribute()
2153 // if ( this._ignoreAttr )
2155 // this._ignoreAttr = false;
2158 // base.WriteEndAttribute();
2161 // public override void WriteString( string text )
2163 // Debug.WriteLine( "ws" );
2164 // if ( String.Compare( text, "http://www.w3.org/2001/XMLSchema-instance", true ) == 0 )
2168 // base.WriteString( text );
2171 // public override void WriteStartElement( string prefix, string localName, string ns )
2173 // Debug.WriteLine( "wse" );
2174 // base.WriteStartElement( null, localName, null );
2178 public void ShowWindowTitleWithSoundType()
2181 if (Sound管理.GetCurrentSoundDeviceType() != "DirectSound")
2183 delay = "(" + Sound管理.GetSoundDelay() + "ms)";
2185 base.Window.Text = strWindowTitle + " (" + Sound管理.GetCurrentSoundDeviceType() + delay + ")";
2190 private bool b終了処理完了済み;
2191 private static CDTX dtx;
2192 private List<CActivity> listトップレベルActivities;
2193 private int n進行描画の戻り値;
2194 private MouseButtons mb = System.Windows.Forms.MouseButtons.Left;
2195 private string strWindowTitle
2199 if (DTXVmode.Enabled)
2201 return "DTXMViewer release " + VERSION;
2205 return "DTXMania .NET style release " + VERSION;
2209 private CSound previewSound;
2210 private CMouseHideControl cMouseHideControl = null;
2212 private void t終了処理()
2214 if (!this.b終了処理完了済み)
2216 Trace.TraceInformation("----------------------");
2217 Trace.TraceInformation("■ アプリケーションの終了");
2218 #region [ 曲検索の終了処理 ]
2219 //---------------------
2220 if (actEnumSongs != null)
2222 Trace.TraceInformation("曲検索actの終了処理を行います。");
2226 actEnumSongs.On非活性化();
2227 actEnumSongs = null;
2228 Trace.TraceInformation("曲検索actの終了処理を完了しました。");
2232 Trace.TraceError(e.Message);
2233 Trace.TraceError("曲検索actの終了処理に失敗しました。");
2240 //---------------------
2242 #region [ 現在のステージの終了処理 ]
2243 //---------------------
2244 if (CDTXMania.Instance.r現在のステージ != null && CDTXMania.Instance.r現在のステージ.b活性化してる) // #25398 2011.06.07 MODIFY FROM
2246 Trace.TraceInformation("現在のステージを終了します。");
2251 Trace.TraceInformation("現在のステージの終了処理を完了しました。");
2258 //---------------------
2261 #region [ 選曲ステージの終了処理 ]
2265 #region [ プラグインの終了処理 ]
2266 //---------------------
2267 if (this.listプラグイン != null && this.listプラグイン.Count > 0)
2269 Trace.TraceInformation("すべてのプラグインを終了します。");
2273 foreach (STPlugin st in this.listプラグイン)
2275 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
2276 st.plugin.OnUnmanagedリソースの解放();
2277 st.plugin.OnManagedリソースの解放();
2279 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2282 Trace.TraceInformation("すべてのプラグインの終了処理を完了しました。");
2289 //---------------------
2291 #region [ 曲リストの終了処理 ]
2292 //---------------------
2293 if (Songs管理 != null)
2295 Trace.TraceInformation("曲リストの終了処理を行います。");
2300 Trace.TraceInformation("曲リストの終了処理を完了しました。");
2302 catch (Exception exception)
2304 Trace.TraceError(exception.Message);
2305 Trace.TraceError("曲リストの終了処理に失敗しました。");
2313 //---------------------
2315 #region [ スキンの終了処理 ]
2316 //---------------------
2319 Trace.TraceInformation("スキンの終了処理を行います。");
2325 Trace.TraceInformation("スキンの終了処理を完了しました。");
2327 catch (Exception exception2)
2329 Trace.TraceError(exception2.Message);
2330 Trace.TraceError("スキンの終了処理に失敗しました。");
2337 //---------------------
2339 #region [ DirectSoundの終了処理 ]
2340 //---------------------
2341 if (Sound管理 != null)
2343 Trace.TraceInformation("DirectSound の終了処理を行います。");
2349 Trace.TraceInformation("DirectSound の終了処理を完了しました。");
2351 catch (Exception exception3)
2353 Trace.TraceError(exception3.Message);
2354 Trace.TraceError("DirectSound の終了処理に失敗しました。");
2361 //---------------------
2363 #region [ パッドの終了処理 ]
2364 //---------------------
2367 Trace.TraceInformation("パッドの終了処理を行います。");
2372 Trace.TraceInformation("パッドの終了処理を完了しました。");
2374 catch (Exception exception4)
2376 Trace.TraceError(exception4.Message);
2377 Trace.TraceError("パッドの終了処理に失敗しました。");
2384 //---------------------
2386 #region [ DirectInput, MIDI入力の終了処理 ]
2387 //---------------------
2388 if (Input管理 != null)
2390 Trace.TraceInformation("DirectInput, MIDI入力の終了処理を行います。");
2396 Trace.TraceInformation("DirectInput, MIDI入力の終了処理を完了しました。");
2398 catch (Exception exception5)
2400 Trace.TraceError(exception5.Message);
2401 Trace.TraceError("DirectInput, MIDI入力の終了処理に失敗しました。");
2408 //---------------------
2410 #region [ 文字コンソールの終了処理 ]
2411 //---------------------
2412 if (act文字コンソール != null)
2414 Trace.TraceInformation("文字コンソールの終了処理を行います。");
2418 act文字コンソール.On非活性化();
2420 Trace.TraceInformation("文字コンソールの終了処理を完了しました。");
2422 catch (Exception exception6)
2424 Trace.TraceError(exception6.Message);
2425 Trace.TraceError("文字コンソールの終了処理に失敗しました。");
2432 //---------------------
2434 #region [ FPSカウンタの終了処理 ]
2435 //---------------------
2436 Trace.TraceInformation("FPSカウンタの終了処理を行います。");
2444 Trace.TraceInformation("FPSカウンタの終了処理を完了しました。");
2450 //---------------------
2452 #region [ タイマの終了処理 ]
2453 //---------------------
2454 Trace.TraceInformation("タイマの終了処理を行います。");
2462 Trace.TraceInformation("タイマの終了処理を完了しました。");
2466 Trace.TraceInformation("タイマは使用されていません。");
2473 //---------------------
2475 #region [ Config.iniの出力 ]
2476 //---------------------
2477 Trace.TraceInformation("Config.xml を出力します。");
2478 // if ( ConfigIni.bIsSwappedGuitarBass ) // #24063 2011.1.16 yyagi ギターベースがスワップしているときは元に戻す
2479 if (ConfigIni.bIsSwappedGuitarBass_AutoFlagsAreSwapped) // #24415 2011.2.21 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、AUTOのフラグをswapして戻す
2481 ConfigIni.SwapGuitarBassInfos_AutoFlags();
2484 if (ConfigIni.bIsSwappedGuitarBass_PlaySettingsAreSwapped) // #35417 2015/8/18 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、演奏設定のフラグをswapして戻す
2486 ConfigIni.SwapGuitarBassInfos_PlaySettings();
2489 string str = strEXEのあるフォルダ + "Config.xml";
2493 if (DTXVmode.Enabled)
2495 DTXVmode.tUpdateConfigIni();
2496 Trace.TraceInformation("DTXVモードの設定情報を、Config.xmlに保存しました。");
2500 CDTXMania.Instance.SaveConfig();
2501 Trace.TraceInformation("保存しました。({0})", str);
2506 Trace.TraceError(e.Message);
2507 Trace.TraceError("Config.xml の出力に失敗しました。({0})", str);
2513 //---------------------
2515 #region [ DTXVmodeの終了処理 ]
2516 //---------------------
2517 //Trace.TraceInformation( "DTXVモードの終了処理を行います。" );
2521 if (DTXVmode != null)
2524 //Trace.TraceInformation( "DTXVモードの終了処理を完了しました。" );
2528 //Trace.TraceInformation( "DTXVモードは使用されていません。" );
2535 //---------------------
2537 #region [ DirectXの終了処理 ]
2538 //---------------------
2539 base.GraphicsDeviceManager.Dispose();
2540 //---------------------
2542 Trace.TraceInformation( "アプリケーションの終了処理を完了しました。" );
2545 this.b終了処理完了済み = true;
2548 private CScoreIni tScoreIniへBGMAdjustとHistoryとPlayCountを更新(string str新ヒストリ行)
2550 STDGBSValue<bool> isUpdated = new STDGBSValue<bool>();
2551 string strFilename = DTX.strファイル名の絶対パス + ".score.ini";
2552 CScoreIni ini = new CScoreIni(strFilename);
2553 if (!File.Exists(strFilename))
2555 ini.stファイル.Title = DTX.TITLE;
2556 ini.stファイル.Name = DTX.strファイル名;
2557 ini.stファイル.Hash = CScoreIni.tファイルのMD5を求めて返す(DTX.strファイル名の絶対パス);
2558 for (EPart i = EPart.Drums; i <= EPart.Bass; ++i)
2560 ini.stセクション.HiScore[i].nPerfectになる範囲ms = nPerfect範囲ms;
2561 ini.stセクション.HiScore[i].nGreatになる範囲ms = nGreat範囲ms;
2562 ini.stセクション.HiScore[i].nGoodになる範囲ms = nGood範囲ms;
2563 ini.stセクション.HiScore[i].nPoorになる範囲ms = nPoor範囲ms;
2565 ini.stセクション.HiSkill[i].nPerfectになる範囲ms = nPerfect範囲ms;
2566 ini.stセクション.HiSkill[i].nGreatになる範囲ms = nGreat範囲ms;
2567 ini.stセクション.HiSkill[i].nGoodになる範囲ms = nGood範囲ms;
2568 ini.stセクション.HiSkill[i].nPoorになる範囲ms = nPoor範囲ms;
2570 ini.stセクション.LastPlay[i].nPerfectになる範囲ms = nPerfect範囲ms;
2571 ini.stセクション.LastPlay[i].nGreatになる範囲ms = nGreat範囲ms;
2572 ini.stセクション.LastPlay[i].nGoodになる範囲ms = nGood範囲ms;
2573 ini.stセクション.LastPlay[i].nPoorになる範囲ms = nPoor範囲ms;
2576 ini.stファイル.BGMAdjust = DTX.nBGMAdjust;
2577 isUpdated = CScoreIni.t更新条件を取得する();
2578 if (isUpdated.Drums || isUpdated.Guitar || isUpdated.Bass)
2580 if (isUpdated.Drums)
2582 ini.stファイル.PlayCountDrums++;
2584 if (isUpdated.Guitar)
2586 ini.stファイル.PlayCountGuitar++;
2590 ini.stファイル.PlayCountBass++;
2592 ini.tヒストリを追加する(str新ヒストリ行);
2595 stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Drums = ini.stファイル.PlayCountDrums;
2596 stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Guitar = ini.stファイル.PlayCountGuitar;
2597 stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Bass = ini.stファイル.PlayCountBass;
2598 for (int j = 0; j < ini.stファイル.History.Length; j++)
2600 stage選曲.r現在選択中のスコア.譜面情報.演奏履歴[j] = ini.stファイル.History[j];
2604 if (ConfigIni.bScoreIni)
2606 ini.t書き出し(strFilename);
2611 private void tガベージコレクションを実行する()
2613 GC.Collect(0, GCCollectionMode.Optimized, true );
2614 GC.WaitForPendingFinalizers();
2615 GC.Collect(0, GCCollectionMode.Forced, true );
2616 GC.WaitForPendingFinalizers();
2618 private void tプラグイン検索と生成()
2620 this.listプラグイン = new List<STPlugin>();
2622 string strIPluginActivityの名前 = typeof(IPluginActivity).FullName;
2623 string strプラグインフォルダパス = strEXEのあるフォルダ + "Plugins\\";
2625 this.t指定フォルダ内でのプラグイン検索と生成(strプラグインフォルダパス, strIPluginActivityの名前);
2627 if (this.listプラグイン.Count > 0)
2628 Trace.TraceInformation(this.listプラグイン.Count + " 個のプラグインを読み込みました。");
2631 private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
2633 var domain = (AppDomain)sender;
2635 foreach (var assembly in domain.GetAssemblies())
2637 if (assembly.FullName == args.Name)
2642 private void t指定フォルダ内でのプラグイン検索と生成(string strプラグインフォルダパス, string strプラグイン型名)
2644 // 指定されたパスが存在しないとエラー
2645 if (!Directory.Exists(strプラグインフォルダパス))
2647 Trace.TraceWarning("プラグインフォルダが存在しません。(" + strプラグインフォルダパス + ")");
2651 AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
2654 // (1) すべての *.dll について…
2655 string[] strDLLs = System.IO.Directory.GetFiles(strプラグインフォルダパス, "*.dll");
2656 foreach (string dllName in strDLLs)
2658 if (Path.GetExtension(dllName).ToLower() != "dll")
2664 // (1-1) dll をアセンブリとして読み込む。
2665 System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom(dllName);
2667 // (1-2) アセンブリ内のすべての型について、プラグインとして有効か調べる
2668 foreach (Type t in asm.GetTypes())
2670 // (1-3) ↓クラスであり↓Publicであり↓抽象クラスでなく↓IPlugin型のインスタンスが作れる 型を持っていれば有効
2671 if (t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(strプラグイン型名) != null)
2673 // (1-4) クラス名からインスタンスを作成する
2674 var st = new STPlugin()
2676 plugin = (IPluginActivity)asm.CreateInstance(t.FullName),
2677 strプラグインフォルダ = Path.GetDirectoryName(dllName),
2678 strアセンブリ簡易名 = asm.GetName().Name,
2679 Version = asm.GetName().Version,
2682 // (1-5) プラグインリストへ登録
2683 this.listプラグイン.Add(st);
2684 Trace.TraceInformation("プラグイン {0} ({1}, {2}, {3}) を読み込みました。", t.FullName, Path.GetFileName(dllName), st.strアセンブリ簡易名, st.Version.ToString());
2688 catch (System.Reflection.ReflectionTypeLoadException e)
2690 Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
2691 Trace.TraceInformation(e.ToString());
2692 Trace.TraceInformation(e.Message);
2694 StringBuilder sb = new StringBuilder();
2695 foreach (Exception exSub in e.LoaderExceptions)
2697 sb.AppendLine(exSub.Message);
2698 FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
2699 if (exFileNotFound != null)
2701 if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
2703 sb.AppendLine("Fusion Log:");
2704 sb.AppendLine(exFileNotFound.FusionLog);
2709 string errorMessage = sb.ToString();
2710 //Display or log the error based on your application.
2711 Trace.TraceInformation(errorMessage);
2716 Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
2717 Trace.TraceInformation(e.ToString());
2718 Trace.TraceInformation(e.Message);
2722 // (2) サブフォルダがあれば再帰する
2723 string[] strDirs = Directory.GetDirectories(strプラグインフォルダパス, "*");
2724 foreach (string dir in strDirs)
2725 this.t指定フォルダ内でのプラグイン検索と生成(dir + "\\", strプラグイン型名);
2728 #region [ Windowイベント処理 ]
2729 private void Window_ApplicationActivated( object sender, EventArgs e )
2731 this.bApplicationActive = true;
2733 private void Window_ApplicationDeactivated(object sender, EventArgs e)
2735 this.bApplicationActive = false;
2736 cMouseHideControl.Show();
2738 private void Window_KeyDown(object sender, KeyEventArgs e)
2740 if (e.KeyCode == Keys.Menu)
2743 e.SuppressKeyPress = true;
2745 else if ((e.KeyCode == Keys.Return) && e.Alt)
2747 if (ConfigIni != null)
2749 ConfigIni.bウィンドウモード = !ConfigIni.bウィンドウモード;
2750 this.t全画面_ウィンドウモード切り替え();
2753 e.SuppressKeyPress = true;
2757 for (int i = 0; i < CConfigXml.AssignableCodes; i++)
2759 var captureCode = (SlimDX.DirectInput.Key) ConfigIni.KeyAssign[ EPad.Capture ][ i ].コード;
2761 if( (int) captureCode > 0 &&
2762 e.KeyCode == DeviceConstantConverter.KeyToKeys( captureCode ) )
2764 // Debug.WriteLine( "capture: " + string.Format( "{0:2x}", (int) e.KeyCode ) + " " + (int) e.KeyCode );
2765 string strFullPath =
2766 Path.Combine( CDTXMania.Instance.strEXEのあるフォルダ, "Capture_img" );
2767 strFullPath = Path.Combine( strFullPath, DateTime.Now.ToString( "yyyyMMddHHmmss" ) + ".png" );
2768 SaveResultScreen( strFullPath );
2773 private void Window_MouseUp(object sender, MouseEventArgs e)
2778 private void Window_MouseDoubleClick(object sender, MouseEventArgs e) // #23510 2010.11.13 yyagi: to go full screen mode
2780 if (mb.Equals(MouseButtons.Left) && ConfigIni.bIsAllowedDoubleClickFullscreen) // #26752 2011.11.27 yyagi
2782 ConfigIni.bウィンドウモード = false;
2783 this.t全画面_ウィンドウモード切り替え();
2786 private void Window_MouseMove(object sender, MouseEventArgs e)
2788 cMouseHideControl.tResetCursorState(ConfigIni.bウィンドウモード, this.bApplicationActive);
2791 private void Window_ResizeEnd(object sender, EventArgs e) // #23510 2010.11.20 yyagi: to get resized window size
2793 if (ConfigIni.bウィンドウモード)
2795 ConfigIni.rcWindow.X = base.Window.Location.X; // #30675 2013.02.04 ikanick add
2796 ConfigIni.rcWindow.Y = base.Window.Location.Y; //
2799 ConfigIni.rcWindow.W = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Width : currentClientSize.Width; // #23510 2010.10.31 yyagi add
2800 ConfigIni.rcWindow.H = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Height : currentClientSize.Height;
2804 //Stopwatch sw = new Stopwatch();
2805 //List<int> swlist1, swlist2, swlist3, swlist4, swlist5;
2809 private class CMouseHideControl
2811 private Point lastPosition;
2812 private CCounter ccMouseShow;
2813 private bool bマウスカーソル表示中;
2818 public CMouseHideControl()
2820 ccMouseShow = new CCounter();
2821 lastPosition = Cursor.Position;
2828 ccMouseShow.t開始(0, 20, 100, CDTXMania.instance.Timer);
2831 public void tHideCursorIfNeed()
2834 //Trace.TraceInformation("n現在の経過時間ms" + ccMouseShow.n現在の経過時間ms + ", n現在の値=" + ccMouseShow.n現在の値 + ", b終了値に達した=" + ccMouseShow.b終了値に達した);
2835 if (bマウスカーソル表示中 && ccMouseShow.b終了値に達した)
2837 Point client_point = CDTXMania.Instance.Window.PointToClient(Cursor.Position);
2838 if (client_point.Y >= 0) // タイトルバー上にマウスカーソルがある場合は、隠さない
2846 public void tResetCursorState(bool bWindowed, bool bApplicationActive)
2848 //Trace.TraceInformation("マウス移動: " + Cursor.Position.X + "," + Cursor.Position.Y);
2849 if ((bWindowed == true && bマウスカーソル表示中 == false) || bApplicationActive == false) // #36168 2016.3.19 yyagi: do not to show mouse cursor in full screen mode
2851 Point currentPosition = Cursor.Position;
2852 //Trace.TraceInformation("current=" + currentPosition.ToString() + ", last=" + lastPosition.ToString());
2853 if (lastPosition != currentPosition)
2855 //Trace.TraceInformation("移動発生");
2856 lastPosition = currentPosition;
2871 bマウスカーソル表示中 = false;