Skip to content

Commit 56e3792

Browse files
committed
Change: Inline a bunch of variables
1 parent 1bc9a04 commit 56e3792

13 files changed

+69
-138
lines changed

source/OpenBVE/Audio/Sounds.Update.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ protected override void UpdateInverseModel(double timeElapsed)
104104
* The sound is to be played or is already playing.
105105
* */
106106
if (Sources[i].State == SoundSourceState.Playing) {
107-
int state;
108-
AL.GetSource(Sources[i].OpenAlSourceName, ALGetSourcei.SourceState, out state);
107+
AL.GetSource(Sources[i].OpenAlSourceName, ALGetSourcei.SourceState, out int state);
109108
if (state != (int)ALSourceState.Initial & state != (int)ALSourceState.Playing) {
110109
/*
111110
* The sound is not playing any longer.

source/OpenBVE/Game/Menu/Menu.SingleMenu.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ public SingleMenu(MenuType menuType, int data = 0, double MaxWidth = 0)
220220
Icon icon = Icon.ExtractAssociatedIcon(potentialFiles[j]);
221221
if (icon != null)
222222
{
223-
Texture t;
224-
Program.CurrentHost.RegisterTexture(icon.ToBitmap(), new TextureParameters(null, null), out t);
223+
Program.CurrentHost.RegisterTexture(icon.ToBitmap(), new TextureParameters(null, null), out Texture t);
225224
iconCache.Add(ext, t);
226225
Items[totalEntries].Icon = t;
227226
}

source/OpenBVE/Parsers/Script/TrackFollowingObjectParser.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ private static void ParseTrainNode(string ObjectPath, string FileName, XElement
257257
break;
258258
default:
259259
{
260-
int n;
261-
262-
if (!NumberFormats.TryParseIntVb6(Value, out n))
260+
if (!NumberFormats.TryParseIntVb6(Value, out int n))
263261
{
264262
Interface.AddMessage(MessageType.Error, false, $"Value is invalid in {Key} in {Section} at line {LineNumber.ToString(culture)} in {FileName}");
265263
}

source/OpenBVE/System/GameWindow.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,7 @@ protected override void OnMouseMove(MouseMoveEventArgs e)
508508

509509
if (Program.Renderer.CurrentInterface == InterfaceType.Normal)
510510
{
511-
MouseCursor.Status Status;
512-
MouseCursor newCursor;
513-
if (Program.Renderer.Touch.MoveCheck(new Vector2(e.X, e.Y), out Status, out newCursor))
511+
if (Program.Renderer.Touch.MoveCheck(new Vector2(e.X, e.Y), out MouseCursor.Status Status, out MouseCursor newCursor))
514512
{
515513
if (newCursor != null)
516514
{

source/OpenBVE/System/Host.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ public override bool LoadObject(string path, System.Text.Encoding Encoding, out
343343
if (Program.CurrentHost.Plugins[i].Object.CanLoadObject(path)) {
344344
try
345345
{
346-
UnifiedObject obj;
347-
if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out obj)) {
346+
if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out UnifiedObject obj)) {
348347
if (obj == null)
349348
{
350349
continue;

source/OpenBVE/System/Input/Controls.cs

+22-45
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,11 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
140140
{
141141
Controls[Length].Command = Translations.CommandInfos[j].Command;
142142
Controls[Length].InheritedType = Translations.CommandInfos[j].Type;
143-
ControlMethod Method;
144-
Enum.TryParse(Terms[1], true, out Method);
143+
Enum.TryParse(Terms[1], true, out ControlMethod Method);
145144
bool Valid = false;
146145
if (Method == ControlMethod.Keyboard & Terms.Length >= 4)
147146
{
148-
Key CurrentKey;
149-
// ReSharper disable once NotAccessedVariable
150-
int SDLTest;
151-
if (int.TryParse(Terms[2], out SDLTest))
147+
if (int.TryParse(Terms[2], out _))
152148
{
153149
//We've discovered a SDL keybinding is present, so reset the loading process with the default keyconfig & show an appropriate error message
154150
if (ControlsReset == false)
@@ -185,19 +181,17 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
185181
return;
186182
}
187183

188-
if (Enum.TryParse(Terms[2], true, out CurrentKey))
184+
if (Enum.TryParse(Terms[2], true, out Key CurrentKey))
189185
{
190-
int Modifiers;
191-
if (int.TryParse(Terms[3], NumberStyles.Integer, Culture, out Modifiers))
186+
if (int.TryParse(Terms[3], NumberStyles.Integer, Culture, out int Modifiers))
192187
{
193188
Controls[Length].Method = Method;
194189
Controls[Length].Device = Guid.Empty;
195190
Controls[Length].Component = JoystickComponent.Invalid;
196191
Controls[Length].Key = (OpenBveApi.Input.Key)CurrentKey;
197192
Controls[Length].Direction = 0;
198193
Controls[Length].Modifier = (KeyboardModifier) Modifiers;
199-
int Option;
200-
if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out Option))
194+
if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out int Option))
201195
{
202196
Controls[Length].Option = Option;
203197
}
@@ -208,26 +202,22 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
208202
}
209203
else if (Method == ControlMethod.Joystick & Terms.Length >= 4)
210204
{
211-
int oldDevice;
212205
Guid Device = Guid.Empty;
213-
if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out oldDevice))
206+
if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out int oldDevice))
214207
{
215208
Device = Joystick.GetGuid(oldDevice);
216209
}
217210

218-
JoystickComponent Component;
219-
Enum.TryParse(Terms[3], true, out Component);
211+
Enum.TryParse(Terms[3], true, out JoystickComponent Component);
220212

221213
if (Device != Guid.Empty || Guid.TryParse(Terms[2], out Device))
222214
{
223215

224216
if (Component == JoystickComponent.Axis & Terms.Length >= 6)
225217
{
226-
int CurrentAxis;
227-
if (int.TryParse(Terms[4], out CurrentAxis))
218+
if (int.TryParse(Terms[4], out int CurrentAxis))
228219
{
229-
int Direction;
230-
if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out Direction))
220+
if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Direction))
231221
{
232222

233223
Controls[Length].Method = Method;
@@ -236,8 +226,7 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
236226
Controls[Length].Element = CurrentAxis;
237227
Controls[Length].Direction = Direction;
238228
Controls[Length].Modifier = KeyboardModifier.None;
239-
int Option;
240-
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out Option))
229+
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option))
241230
{
242231
Controls[Length].Option = Option;
243232
}
@@ -248,20 +237,17 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
248237
}
249238
else if (Component == JoystickComponent.Hat & Terms.Length >= 6)
250239
{
251-
int CurrentHat;
252-
if (int.TryParse(Terms[4], out CurrentHat))
240+
if (int.TryParse(Terms[4], out int CurrentHat))
253241
{
254-
int HatDirection;
255-
if (int.TryParse(Terms[5], out HatDirection))
242+
if (int.TryParse(Terms[5], out int HatDirection))
256243
{
257244
Controls[Length].Method = Method;
258245
Controls[Length].Device = Device;
259246
Controls[Length].Component = JoystickComponent.Hat;
260247
Controls[Length].Element = CurrentHat;
261248
Controls[Length].Direction = HatDirection;
262249
Controls[Length].Modifier = KeyboardModifier.None;
263-
int Option;
264-
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out Option))
250+
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option))
265251
{
266252
Controls[Length].Option = Option;
267253
}
@@ -273,17 +259,15 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
273259
}
274260
else if (Component == JoystickComponent.Button & Terms.Length >= 5)
275261
{
276-
int CurrentButton;
277-
if (int.TryParse(Terms[4], out CurrentButton))
262+
if (int.TryParse(Terms[4], out int CurrentButton))
278263
{
279264
Controls[Length].Method = Method;
280265
Controls[Length].Device = Device;
281266
Controls[Length].Component = JoystickComponent.Button;
282267
Controls[Length].Element = CurrentButton;
283268
Controls[Length].Direction = 0;
284269
Controls[Length].Modifier = KeyboardModifier.None;
285-
int Option;
286-
if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out Option))
270+
if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Option))
287271
{
288272
Controls[Length].Option = Option;
289273
}
@@ -296,24 +280,20 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
296280
}
297281
else if (Method == ControlMethod.RailDriver & Terms.Length >= 4)
298282
{
299-
int oldDevice;
300283
Guid Device = Guid.Empty;
301-
if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out oldDevice))
284+
if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out int oldDevice))
302285
{
303286
Device = Joystick.GetGuid(oldDevice);
304287
}
305288

306289
if (Device != Guid.Empty || Guid.TryParse(Terms[2], out Device))
307290
{
308-
JoystickComponent Component;
309-
Enum.TryParse(Terms[3], true, out Component);
291+
Enum.TryParse(Terms[3], true, out JoystickComponent Component);
310292
if (Component == JoystickComponent.Axis & Terms.Length >= 6)
311293
{
312-
int CurrentAxis;
313-
if (int.TryParse(Terms[4], out CurrentAxis))
294+
if (int.TryParse(Terms[4], out int CurrentAxis))
314295
{
315-
int Direction;
316-
if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out Direction))
296+
if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Direction))
317297
{
318298

319299
Controls[Length].Method = Method;
@@ -322,8 +302,7 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
322302
Controls[Length].Element = CurrentAxis;
323303
Controls[Length].Direction = Direction;
324304
Controls[Length].Modifier = KeyboardModifier.None;
325-
int Option;
326-
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out Option))
305+
if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option))
327306
{
328307
Controls[Length].Option = Option;
329308
}
@@ -334,17 +313,15 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
334313
}
335314
else if (Component == JoystickComponent.Button & Terms.Length >= 5)
336315
{
337-
int CurrentButton;
338-
if (int.TryParse(Terms[4], out CurrentButton))
316+
if (int.TryParse(Terms[4], out int CurrentButton))
339317
{
340318
Controls[Length].Method = ControlMethod.RailDriver;
341319
Controls[Length].Device = Device;
342320
Controls[Length].Component = JoystickComponent.Button;
343321
Controls[Length].Element = CurrentButton;
344322
Controls[Length].Direction = 0;
345323
Controls[Length].Modifier = KeyboardModifier.None;
346-
int Option;
347-
if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out Option))
324+
if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Option))
348325
{
349326
Controls[Length].Option = Option;
350327
}

source/OpenBVE/System/Interface.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ internal static bool TryParseTime(string Expression, out double Value)
2929
i = Expression.IndexOf(':');
3030
}
3131
if (i >= 1) {
32-
int h; if (int.TryParse(Expression.Substring(0, i), NumberStyles.Integer, Culture, out h)) {
32+
if (int.TryParse(Expression.Substring(0, i), NumberStyles.Integer, Culture, out int h)) {
3333
int n = Expression.Length - i - 1;
3434
if (n == 1 | n == 2) {
35-
uint m; if (uint.TryParse(Expression.Substring(i + 1, n), NumberStyles.None, Culture, out m)) {
35+
if (uint.TryParse(Expression.Substring(i + 1, n), NumberStyles.None, Culture, out uint m)) {
3636
Value = 3600.0 * h + 60.0 * m;
3737
return true;
3838
}
@@ -42,8 +42,7 @@ internal static bool TryParseTime(string Expression, out double Value)
4242
Program.CurrentHost.AddMessage(MessageType.Warning, false, "A maximum of 4 digits of precision are supported in TIME values");
4343
n = 4;
4444
}
45-
uint m; if (uint.TryParse(Expression.Substring(i + 1, 2), NumberStyles.None, Culture, out m)) {
46-
uint s;
45+
if (uint.TryParse(Expression.Substring(i + 1, 2), NumberStyles.None, Culture, out uint m)) {
4746
string ss = Expression.Substring(i + 3, n - 2);
4847
if (Interface.CurrentOptions.EnableBveTsHacks)
4948
{
@@ -56,15 +55,15 @@ internal static bool TryParseTime(string Expression, out double Value)
5655
ss = ss.Substring(1, ss.Length - 1);
5756
}
5857
}
59-
if (uint.TryParse(ss, NumberStyles.None, Culture, out s)) {
58+
if (uint.TryParse(ss, NumberStyles.None, Culture, out uint s)) {
6059
Value = 3600.0 * h + 60.0 * m + s;
6160
return true;
6261
}
6362
}
6463
}
6564
}
6665
} else if (i == -1) {
67-
int h; if (int.TryParse(Expression, NumberStyles.Integer, Culture, out h)) {
66+
if (int.TryParse(Expression, NumberStyles.Integer, Culture, out int h)) {
6867
Value = 3600.0 * h;
6968
return true;
7069
}

0 commit comments

Comments
 (0)