Use out var syntax

This commit is contained in:
teinarss
2020-08-16 10:49:33 +02:00
committed by Paul Chote
parent d52e4793fe
commit 27f1a7ab27
193 changed files with 395 additions and 826 deletions

View File

@@ -242,8 +242,7 @@ namespace OpenRA.Platforms.Default
atten = 0.66f * ((PoolSize - activeCount * 0.5f) / PoolSize);
}
uint source;
if (!TryGetSourceFromPool(out source))
if (!TryGetSourceFromPool(out var source))
return null;
var slot = sourcePool[source];
@@ -259,8 +258,7 @@ namespace OpenRA.Platforms.Default
{
var currFrame = Game.LocalTick;
uint source;
if (!TryGetSourceFromPool(out source))
if (!TryGetSourceFromPool(out var source))
return null;
var slot = sourcePool[source];
@@ -295,8 +293,7 @@ namespace OpenRA.Platforms.Default
void PauseSound(uint source, bool paused)
{
int state;
AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE, out var state);
if (paused)
{
if (state == AL10.AL_PLAYING)
@@ -317,8 +314,7 @@ namespace OpenRA.Platforms.Default
{
var sounds = sourcePool.Keys.Where(key =>
{
int state;
AL10.alGetSourcei(key, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(key, AL10.AL_SOURCE_STATE, out var state);
return (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED) &&
(music == null || key != ((OpenAlSound)music).Source) &&
(video == null || key != ((OpenAlSound)video).Source);
@@ -449,7 +445,7 @@ namespace OpenRA.Platforms.Default
public float Volume
{
get { float volume; AL10.alGetSourcef(Source, AL10.AL_GAIN, out volume); return volume; }
get { AL10.alGetSourcef(Source, AL10.AL_GAIN, out var volume); return volume; }
set { AL10.alSourcef(Source, AL10.AL_GAIN, value); }
}
@@ -457,8 +453,7 @@ namespace OpenRA.Platforms.Default
{
get
{
int sampleOffset;
AL10.alGetSourcei(Source, AL11.AL_SAMPLE_OFFSET, out sampleOffset);
AL10.alGetSourcei(Source, AL11.AL_SAMPLE_OFFSET, out var sampleOffset);
return sampleOffset / SampleRate;
}
}
@@ -467,8 +462,7 @@ namespace OpenRA.Platforms.Default
{
get
{
int state;
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
return state == AL10.AL_STOPPED;
}
}
@@ -480,8 +474,7 @@ namespace OpenRA.Platforms.Default
protected void StopSource()
{
int state;
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED)
AL10.alSourceStop(Source);
}
@@ -554,8 +547,7 @@ namespace OpenRA.Platforms.Default
// TODO: A race condition can happen between the state check and playing/rewinding if a
// user pauses/resumes at the right moment. The window of opportunity is small and the
// consequences are minor, so for now we'll ignore it.
int state;
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state != AL10.AL_STOPPED)
AL10.alSourcePlay(source);
else
@@ -575,8 +567,7 @@ namespace OpenRA.Platforms.Default
// has stopped.
var currentSeek = SeekPosition;
int state;
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state == AL10.AL_STOPPED)
break;

View File

@@ -719,8 +719,7 @@ namespace OpenRA.Platforms.Default
if (Profile != GLProfile.Legacy)
{
int extensionCount;
glGetIntegerv(GL_NUM_EXTENSIONS, out extensionCount);
glGetIntegerv(GL_NUM_EXTENSIONS, out var extensionCount);
for (var i = 0; i < extensionCount; i++)
Log.Write("graphics", glGetStringi(GL_EXTENSIONS, (uint)i));
}

View File

@@ -40,8 +40,7 @@ namespace OpenRA.Platforms.Default
if (OpenGL.Profile != GLProfile.Legacy)
{
uint vao;
OpenGL.glGenVertexArrays(1, out vao);
OpenGL.glGenVertexArrays(1, out var vao);
OpenGL.CheckGLError();
OpenGL.glBindVertexArray(vao);
OpenGL.CheckGLError();

View File

@@ -67,8 +67,7 @@ namespace OpenRA.Platforms.Default
inputHandler.ModifierKeys(mods);
MouseInput? pendingMotion = null;
SDL.SDL_Event e;
while (SDL.SDL_PollEvent(out e) != 0)
while (SDL.SDL_PollEvent(out var e) != 0)
{
switch (e.type)
{
@@ -160,8 +159,7 @@ namespace OpenRA.Platforms.Default
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
{
int x, y;
SDL.SDL_GetMouseState(out x, out y);
SDL.SDL_GetMouseState(out var x, out var y);
var pos = EventPosition(device, x, y);
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, pos, new int2(0, e.wheel.y), mods, 0));

View File

@@ -167,16 +167,14 @@ namespace OpenRA.Platforms.Default
if (videoDisplay < 0 || videoDisplay >= DisplayCount)
videoDisplay = 0;
SDL.SDL_DisplayMode display;
SDL.SDL_GetCurrentDisplayMode(videoDisplay, out display);
SDL.SDL_GetCurrentDisplayMode(videoDisplay, out var display);
// Windows and Linux define window sizes in native pixel units.
// Query the display/dpi scale so we can convert our requested effective size to pixels.
// This is not necessary on macOS, which defines window sizes in effective units ("points").
if (Platform.CurrentPlatform == PlatformType.Windows)
{
float ddpi, hdpi, vdpi;
if (SDL.SDL_GetDisplayDPI(videoDisplay, out ddpi, out hdpi, out vdpi) == 0)
if (SDL.SDL_GetDisplayDPI(videoDisplay, out var ddpi, out var hdpi, out var vdpi) == 0)
windowScale = ddpi / 96;
}
else if (Platform.CurrentPlatform != PlatformType.OSX)
@@ -195,9 +193,8 @@ namespace OpenRA.Platforms.Default
var p = Process.Start(psi);
var lines = p.StandardOutput.ReadToEnd().Split('\n');
int dpi;
foreach (var line in lines)
if (line.StartsWith("Xft.dpi") && int.TryParse(line.Substring(8), out dpi))
if (line.StartsWith("Xft.dpi") && int.TryParse(line.Substring(8), out var dpi))
windowScale = dpi / 96f;
}
catch { }
@@ -228,8 +225,7 @@ namespace OpenRA.Platforms.Default
// (if dark mode is enabled) unless we drain the event queue before initializing GL
if (Platform.CurrentPlatform == PlatformType.OSX)
{
SDL.SDL_Event e;
while (SDL.SDL_PollEvent(out e) != 0)
while (SDL.SDL_PollEvent(out var e) != 0)
{
// We can safely ignore all mouse/keyboard events and window size changes
// (these will be caught in the window setup below), but do need to process focus
@@ -254,9 +250,7 @@ namespace OpenRA.Platforms.Default
{
// OSX defines the window size in "points", with a device-dependent number of pixels per point.
// The window scale is simply the ratio of GL pixels / window points.
int width, height;
SDL.SDL_GL_GetDrawableSize(Window, out width, out height);
SDL.SDL_GL_GetDrawableSize(Window, out var width, out var height);
surfaceSize = new Size(width, height);
windowScale = width * 1f / windowSize.Width;
}
@@ -282,8 +276,7 @@ namespace OpenRA.Platforms.Default
// This is usually not what the player wants, but is the best we can consistently do.
if (Platform.CurrentPlatform == PlatformType.OSX)
{
int width, height;
SDL.SDL_GetWindowSize(Window, out width, out height);
SDL.SDL_GetWindowSize(Window, out var width, out var height);
windowSize = surfaceSize = new Size(width, height);
windowScale = 1;
}
@@ -380,8 +373,7 @@ namespace OpenRA.Platforms.Default
{
if (mode)
{
int x, y;
SDL.SDL_GetMouseState(out x, out y);
SDL.SDL_GetMouseState(out var x, out var y);
lockedMousePosition = new int2(x, y);
}
else
@@ -399,8 +391,7 @@ namespace OpenRA.Platforms.Default
// We need to recalculate our scale to account for the potential change in the actual rendered area
if (Platform.CurrentPlatform == PlatformType.OSX)
{
int width, height;
SDL.SDL_GL_GetDrawableSize(Window, out width, out height);
SDL.SDL_GL_GetDrawableSize(Window, out var width, out var height);
if (width != SurfaceSize.Width || height != SurfaceSize.Height)
{

View File

@@ -51,16 +51,13 @@ namespace OpenRA.Platforms.Default
OpenGL.CheckGLError();
OpenGL.glCompileShader(shader);
OpenGL.CheckGLError();
int success;
OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out success);
OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out var success);
OpenGL.CheckGLError();
if (success == OpenGL.GL_FALSE)
{
int len;
OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out len);
OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out var len);
var log = new StringBuilder(len);
int length;
OpenGL.glGetShaderInfoLog(shader, len, out length, log);
OpenGL.glGetShaderInfoLog(shader, len, out var length, log);
Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
@@ -100,17 +97,14 @@ namespace OpenRA.Platforms.Default
OpenGL.glLinkProgram(program);
OpenGL.CheckGLError();
int success;
OpenGL.glGetProgramiv(program, OpenGL.GL_LINK_STATUS, out success);
OpenGL.glGetProgramiv(program, OpenGL.GL_LINK_STATUS, out var success);
OpenGL.CheckGLError();
if (success == OpenGL.GL_FALSE)
{
int len;
OpenGL.glGetProgramiv(program, OpenGL.GL_INFO_LOG_LENGTH, out len);
OpenGL.glGetProgramiv(program, OpenGL.GL_INFO_LOG_LENGTH, out var len);
var log = new StringBuilder(len);
int length;
OpenGL.glGetProgramInfoLog(program, len, out length, log);
OpenGL.glGetProgramInfoLog(program, len, out var length, log);
Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
throw new InvalidProgramException("Link error in shader program '{0}'".F(name));
}
@@ -118,18 +112,15 @@ namespace OpenRA.Platforms.Default
OpenGL.glUseProgram(program);
OpenGL.CheckGLError();
int numUniforms;
OpenGL.glGetProgramiv(program, OpenGL.GL_ACTIVE_UNIFORMS, out numUniforms);
OpenGL.glGetProgramiv(program, OpenGL.GL_ACTIVE_UNIFORMS, out var numUniforms);
OpenGL.CheckGLError();
var nextTexUnit = 0;
for (var i = 0; i < numUniforms; i++)
{
int length, size;
int type;
var sb = new StringBuilder(128);
OpenGL.glGetActiveUniform(program, i, 128, out length, out size, out type, sb);
OpenGL.glGetActiveUniform(program, i, 128, out var length, out var size, out var type, sb);
var sampler = sb.ToString();
OpenGL.CheckGLError();
@@ -172,8 +163,7 @@ namespace OpenRA.Platforms.Default
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, texture.ID);
// Work around missing textureSize GLSL function by explicitly tracking sizes in a uniform
int param;
if (OpenGL.Profile == GLProfile.Legacy && legacySizeUniforms.TryGetValue(kv.Key, out param))
if (OpenGL.Profile == GLProfile.Legacy && legacySizeUniforms.TryGetValue(kv.Key, out var param))
{
OpenGL.glUniform2f(param, texture.Size.Width, texture.Size.Height);
OpenGL.CheckGLError();
@@ -195,8 +185,7 @@ namespace OpenRA.Platforms.Default
if (t == null)
return;
int texUnit;
if (samplers.TryGetValue(name, out texUnit))
if (samplers.TryGetValue(name, out var texUnit))
textures[texUnit] = t;
}

View File

@@ -122,11 +122,9 @@ namespace OpenRA.Platforms.Default
if (OpenGL.Profile == GLProfile.Embedded)
{
// Query the active framebuffer so we can restore it afterwards
int lastFramebuffer;
OpenGL.glGetIntegerv(OpenGL.GL_FRAMEBUFFER_BINDING, out lastFramebuffer);
OpenGL.glGetIntegerv(OpenGL.GL_FRAMEBUFFER_BINDING, out var lastFramebuffer);
uint framebuffer;
OpenGL.glGenFramebuffers(1, out framebuffer);
OpenGL.glGenFramebuffers(1, out var framebuffer);
OpenGL.glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebuffer);
OpenGL.CheckGLError();