From 4bf463a2fcd9c63d09114e3fcce1d105c4fc0314 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 28 Feb 2020 11:15:06 -0600 Subject: [PATCH] use object initializers in Client.EmuHawk --- BizHawk.Client.EmuHawk/ArgParser.cs | 6 ++- .../DisplayManager/Filters/Gui.cs | 9 ++-- .../GraphicsImplementations/IGL_GdiPlus.cs | 17 ++++--- .../GraphicsImplementations/IGL_SlimDX9.cs | 21 +++------ .../GraphicsImplementations/IGL_TK.cs | 14 +++--- .../SlimDXExtensions.cs | 39 ++++++++-------- .../tools/NES/NESMusicRipper.cs | 44 ++++++++++++------- .../controls/VirtualPadDiscManager.cs | 8 +--- 8 files changed, 78 insertions(+), 80 deletions(-) diff --git a/BizHawk.Client.EmuHawk/ArgParser.cs b/BizHawk.Client.EmuHawk/ArgParser.cs index 02dab02522..c0baa2d7ef 100644 --- a/BizHawk.Client.EmuHawk/ArgParser.cs +++ b/BizHawk.Client.EmuHawk/ArgParser.cs @@ -175,8 +175,10 @@ namespace BizHawk.Client.EmuHawk //initialize mapped memory files if (mmf_filename != null) { - GlobalWin.memoryMappedFiles = new Communication.MemoryMappedFiles(); - GlobalWin.memoryMappedFiles.Filename = mmf_filename; + GlobalWin.memoryMappedFiles = new Communication.MemoryMappedFiles + { + Filename = mmf_filename + }; } } diff --git a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs index e1f64768aa..02aca5c210 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs @@ -406,10 +406,11 @@ namespace BizHawk.Client.EmuHawk.Filters OutputSize.Height *= YIS; } - var outState = new SurfaceState(); - outState.SurfaceFormat = new SurfaceFormat(OutputSize); - outState.SurfaceDisposition = SurfaceDisposition.RenderTarget; - DeclareOutput(outState); + DeclareOutput(new SurfaceState + { + SurfaceFormat = new SurfaceFormat(OutputSize), + SurfaceDisposition = SurfaceDisposition.RenderTarget + }); } public override Size PresizeOutput(string channel, Size size) diff --git a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs index c84a9196a7..4ca67074c1 100644 --- a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs +++ b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs @@ -157,8 +157,7 @@ namespace BizHawk.Client.EmuHawk public Texture2d LoadTexture(sd.Bitmap bitmap) { var sdbmp = (sd.Bitmap)bitmap.Clone(); - GDIPTextureWrapper tw = new GDIPTextureWrapper(); - tw.SDBitmap = sdbmp; + GDIPTextureWrapper tw = new GDIPTextureWrapper { SDBitmap = sdbmp }; return new Texture2d(this, tw, bitmap.Width, bitmap.Height); } @@ -190,8 +189,7 @@ namespace BizHawk.Client.EmuHawk { //definitely needed (by TextureFrugalizer at least) var sdbmp = bmp.ToSysdrawingBitmap(); - var tw = new GDIPTextureWrapper(); - tw.SDBitmap = sdbmp; + var tw = new GDIPTextureWrapper { SDBitmap = sdbmp }; return new Texture2d(this, tw, bmp.Width, bmp.Height); } @@ -349,8 +347,7 @@ namespace BizHawk.Client.EmuHawk var ret = new GLControlWrapper_GdiPlus(this); //create a render target for this control - RenderTargetWrapper rtw = new RenderTargetWrapper(this); - rtw.Control = ret; + RenderTargetWrapper rtw = new RenderTargetWrapper(this) { Control = ret }; ret.RenderTargetWrapper = rtw; return ret; @@ -364,11 +361,13 @@ namespace BizHawk.Client.EmuHawk public unsafe RenderTarget CreateRenderTarget(int w, int h) { - GDIPTextureWrapper tw = new GDIPTextureWrapper(); - tw.SDBitmap = new Bitmap(w,h, sdi.PixelFormat.Format32bppArgb); + var tw = new GDIPTextureWrapper + { + SDBitmap = new Bitmap(w, h, sdi.PixelFormat.Format32bppArgb) + }; var tex = new Texture2d(this, tw, w, h); - RenderTargetWrapper rtw = new RenderTargetWrapper(this); + var rtw = new RenderTargetWrapper(this); var rt = new RenderTarget(this, rtw, tex); rtw.Target = rt; return rt; diff --git a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs index ec48778120..0265989e16 100644 --- a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs +++ b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs @@ -1,18 +1,11 @@ using System; -using System.Linq; -using System.Text; using System.IO; using System.Collections.Generic; using System.Drawing; -using System.Drawing.Imaging; -using System.Windows.Forms; - using BizHawk.Bizware.BizwareGL; using SlimDX.Direct3D9; using OpenTK; -using OpenTK.Graphics; - using d3d9 = SlimDX.Direct3D9; using gl = OpenTK.Graphics.OpenGL; using sd = System.Drawing; @@ -48,8 +41,7 @@ namespace BizHawk.Client.EmuHawk } //make an 'offscreen context' so we can at least do things without having to create a window - OffscreenNativeWindow = new OpenTK.NativeWindow(); - OffscreenNativeWindow.ClientSize = new sd.Size(8, 8); + OffscreenNativeWindow = new NativeWindow { ClientSize = new Size(8, 8) }; CreateDevice(); CreateRenderStates(); @@ -226,8 +218,7 @@ namespace BizHawk.Client.EmuHawk { if (required) throw; - var s = new Shader(this, null, false); - s.Errors = ex.ToString(); + var s = new Shader(this, null, false) { Errors = ex.ToString() }; return s; } } @@ -247,7 +238,7 @@ namespace BizHawk.Client.EmuHawk if (!results.Succeeded) { if (required) throw new InvalidOperationException(results.Errors); - else return new Shader(this, null, false); + return new Shader(this, null, false); } sw.MapCodeToNative = results.MapCodeToNative; @@ -282,8 +273,7 @@ namespace BizHawk.Client.EmuHawk { if (required) throw; - var s = new Shader(this, null, false); - s.Errors = ex.ToString(); + var s = new Shader(this, null, false) { Errors = ex.ToString() }; return s; } } @@ -384,8 +374,7 @@ namespace BizHawk.Client.EmuHawk string errors = $"Vertex Shader:\r\n {vertexShader.Errors} \r\n-------\r\nFragment Shader:\r\n{fragmentShader.Errors}"; if (required) throw new InvalidOperationException($"Couldn't build required GL pipeline:\r\n{errors}"); - var pipeline = new Pipeline(this, null, false, null, null, null); - pipeline.Errors = errors; + var pipeline = new Pipeline(this, null, false, null, null, null) { Errors = errors }; return pipeline; } diff --git a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs index 98c41d60cd..661ea836f3 100644 --- a/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs +++ b/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs @@ -71,13 +71,12 @@ namespace BizHawk.Client.EmuHawk public IGL_TK(int major_version, int minor_version, bool forward_compatible) { //make an 'offscreen context' so we can at least do things without having to create a window - OffscreenNativeWindow = new NativeWindow(); - OffscreenNativeWindow.ClientSize = new sd.Size(8, 8); - this.GraphicsContext = new GraphicsContext(GraphicsMode.Default, OffscreenNativeWindow.WindowInfo, major_version, minor_version, forward_compatible ? GraphicsContextFlags.ForwardCompatible : GraphicsContextFlags.Default); + OffscreenNativeWindow = new NativeWindow { ClientSize = new sd.Size(8, 8) }; + GraphicsContext = new GraphicsContext(GraphicsMode.Default, OffscreenNativeWindow.WindowInfo, major_version, minor_version, forward_compatible ? GraphicsContextFlags.ForwardCompatible : GraphicsContextFlags.Default); MakeDefaultCurrent(); //this is important for reasons unknown - this.GraphicsContext.LoadAll(); + GraphicsContext.LoadAll(); //misc initialization CreateRenderStates(); @@ -190,8 +189,7 @@ namespace BizHawk.Client.EmuHawk string errors = $"Vertex Shader:\r\n {vertexShader.Errors} \r\n-------\r\nFragment Shader:\r\n{fragmentShader.Errors}"; if (required) throw new InvalidOperationException($"Couldn't build required GL pipeline:\r\n{errors}"); - var pipeline = new Pipeline(this, null, false, null, null, null); - pipeline.Errors = errors; + var pipeline = new Pipeline(this, null, false, null, null, null) { Errors = errors }; return pipeline; } @@ -316,9 +314,7 @@ namespace BizHawk.Client.EmuHawk if (fsw.MapCodeToNative.ContainsKey(name)) name = fsw.MapCodeToNative[name]; } - var ui = new UniformInfo(); - ui.Name = name; - ui.Opaque = loc; + var ui = new UniformInfo { Name = name, Opaque = loc }; if (type == ActiveUniformType.Sampler2D) { diff --git a/BizHawk.Client.EmuHawk/GraphicsImplementations/SlimDXExtensions.cs b/BizHawk.Client.EmuHawk/GraphicsImplementations/SlimDXExtensions.cs index 8e4964c616..5cd8686b1b 100644 --- a/BizHawk.Client.EmuHawk/GraphicsImplementations/SlimDXExtensions.cs +++ b/BizHawk.Client.EmuHawk/GraphicsImplementations/SlimDXExtensions.cs @@ -4,27 +4,31 @@ { public static global::SlimDX.Matrix ToSlimDXMatrix(this OpenTK.Matrix4 m, bool transpose) { - global::SlimDX.Matrix ret = new global::SlimDX.Matrix(); - ret.M11 = m.M11; - ret.M12 = m.M12; - ret.M13 = m.M13; - ret.M14 = m.M14; - ret.M21 = m.M21; - ret.M22 = m.M22; - ret.M23 = m.M23; - ret.M24 = m.M24; - ret.M31 = m.M31; - ret.M32 = m.M32; - ret.M33 = m.M33; - ret.M34 = m.M34; - ret.M41 = m.M41; - ret.M42 = m.M42; - ret.M43 = m.M43; - ret.M44 = m.M44; + global::SlimDX.Matrix ret = new global::SlimDX.Matrix + { + M11 = m.M11, + M12 = m.M12, + M13 = m.M13, + M14 = m.M14, + M21 = m.M21, + M22 = m.M22, + M23 = m.M23, + M24 = m.M24, + M31 = m.M31, + M32 = m.M32, + M33 = m.M33, + M34 = m.M34, + M41 = m.M41, + M42 = m.M42, + M43 = m.M43, + M44 = m.M44 + }; //could be optimized later into the above copies if (transpose) + { ret = global::SlimDX.Matrix.Transpose(ret); + } return ret; } @@ -38,6 +42,5 @@ { return new global::SlimDX.Vector2(v.X, v.Y); } - } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs b/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs index dc7817200a..c37c8508d7 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs @@ -445,21 +445,35 @@ namespace BizHawk.Client.EmuHawk float noise_freq = 1789773.0f / (16.0f * (noise_period + 1)); int noise_note = FindNearestNote(noise_freq); - //create the record - ApuState rec = new ApuState(); - rec.pulse0.en = !apu.pulse[0].Debug_IsSilenced; - rec.pulse0.vol = (byte)apu.pulse[0].Debug_Volume; - rec.pulse0.note = pulse0_note; - rec.pulse0.type = (byte)apu.pulse[0].Debug_DutyType; - rec.pulse1.en = !apu.pulse[1].Debug_IsSilenced; - rec.pulse1.vol = (byte)apu.pulse[1].Debug_Volume; - rec.pulse1.note = pulse1_note; - rec.pulse1.type = (byte)apu.pulse[1].Debug_DutyType; - rec.triangle.en = !apu.triangle.Debug_IsSilenced; - rec.triangle.note = tri_note; - rec.noise.en = !apu.noise.Debug_IsSilenced; - rec.noise.vol = (byte)apu.noise.Debug_Volume; - rec.noise.note = noise_note; + // create the record + var rec = new ApuState + { + pulse0 = + { + en = !apu.pulse[0].Debug_IsSilenced, + vol = (byte) apu.pulse[0].Debug_Volume, + note = pulse0_note, + type = (byte) apu.pulse[0].Debug_DutyType + }, + pulse1 = + { + en = !apu.pulse[1].Debug_IsSilenced, + vol = (byte) apu.pulse[1].Debug_Volume, + note = pulse1_note, + type = (byte) apu.pulse[1].Debug_DutyType + }, + triangle = + { + en = !apu.triangle.Debug_IsSilenced, + note = tri_note + }, + noise = + { + en = !apu.noise.Debug_IsSilenced, + vol = (byte) apu.noise.Debug_Volume, + note = noise_note + } + }; Log.Add(rec); diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs index ae8423b0f2..9a527bc981 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs @@ -45,8 +45,7 @@ namespace BizHawk.Client.EmuHawk return; var psx = OwnerEmulator as Octoshock; - List buttons = new List(); - buttons.Add("- NONE -"); + var buttons = new List { "- NONE -" }; buttons.AddRange(psx.HackyDiscButtons); lvDiscs.Items.Clear(); @@ -167,10 +166,5 @@ namespace BizHawk.Client.EmuHawk UpdateValues(); } } - - - - - } }