Skip to content

Commit f05aa60

Browse files
committedFeb 27, 2024
[Chore] dotnet format
1 parent 800f350 commit f05aa60

File tree

32 files changed

+170
-158
lines changed

32 files changed

+170
-158
lines changed
 

‎GREngine.Algorithms/Sort.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public static class Sort
1515
/// <returns>A sorted list with all elements combined</returns>
1616
public static IList<T> MergeSortedLists<T>(IList<T> a, IList<T> b) where T : IComparable<T>
1717
{
18-
if(a.Count >b.Count)
19-
return MergeSortedLists_Large_Small<T>(a,b);
18+
if (a.Count > b.Count)
19+
return MergeSortedLists_Large_Small<T>(a, b);
2020
else
21-
return MergeSortedLists_Large_Small<T>(b,a);
21+
return MergeSortedLists_Large_Small<T>(b, a);
2222
}
2323
private static IList<T> MergeSortedLists_Large_Small<T>(IList<T> a, IList<T> b) where T : IComparable<T>
2424
{

‎GREngine.Core/GREngine.Core.PebbleRenderer/Lighting/Light.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public class Light : Behaviour
2020
private float rotation = 0;
2121
public bool isShadowCasting;
2222

23-
public Light(Vector2 offset, Vector3 color,bool isShadowCasting = false ,float rotation = 0,float arc = 1) { //anything else?
23+
public Light(Vector2 offset, Vector3 color, bool isShadowCasting = false, float rotation = 0, float arc = 1)
24+
{ //anything else?
2425
this.position = new Vector2(0);
2526
this.offset = offset;
2627
this.color = color;

‎GREngine.Core/GREngine.Core.PebbleRenderer/Materials/Material.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace GREngine.Core.PebbleRenderer;
88

99
public class Material
1010
{
11-
public Shader[] shaders;
12-
public Material(Shader diffuse, Shader normal, Shader roughness) {
11+
public Shader[] shaders;
12+
public Material(Shader diffuse, Shader normal, Shader roughness)
13+
{
1314
this.shaders = new Shader[] { diffuse, normal, roughness };
1415
}
1516
}

‎GREngine.Core/GREngine.Core.PebbleRenderer/Materials/shader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace GREngine.Core.PebbleRenderer;
1010

1111
public class Shader
1212
{
13-
public Dictionary<string,float> attributes;
13+
public Dictionary<string, float> attributes;
1414
public Effect shader;
1515

1616
public Shader(Effect shader)

‎GREngine.Core/GREngine.Core.PebbleRenderer/PebbleRenderer.cs

+35-31
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public struct DebugDrawable
5656

5757
public Vector2 position2;
5858

59-
public DebugDrawable(Vector2 position, float radius,Color color)
59+
public DebugDrawable(Vector2 position, float radius, Color color)
6060
{ //circle
6161
this.position = position;
6262
this.color = color;
63-
this.position2 = new Vector2(radius,0);
63+
this.position2 = new Vector2(radius, 0);
6464
this.shape = DebugShape.CIRCLE;
6565
}
6666

@@ -83,7 +83,7 @@ public struct UIDrawable
8383
public SpriteFont font;
8484

8585

86-
public UIDrawable(Vector2 position, float scale, Color color,SpriteFont font, String message)
86+
public UIDrawable(Vector2 position, float scale, Color color, SpriteFont font, String message)
8787
{
8888
this.position = position;
8989
this.color = color;
@@ -113,7 +113,7 @@ public class PebbleRenderer : GameComponent, IPebbleRendererService
113113

114114
private List<Sprite>[,] lmsTensor;
115115

116-
private Dictionary<Light,Tuple<RenderTarget2D,RenderTarget2D>> lights;
116+
private Dictionary<Light, Tuple<RenderTarget2D, RenderTarget2D>> lights;
117117

118118
private Material[] materials;
119119
private int materialCount = 1; //the default material/shaders
@@ -165,12 +165,12 @@ public class PebbleRenderer : GameComponent, IPebbleRendererService
165165
private Queue<DebugDrawable> debugShapes;
166166
private Queue<UIDrawable> UIShapes;
167167

168-
public PebbleRenderer(Game game, GraphicsDeviceManager graphics, int outputWidth, int outputHeight,float renderScale = 1,float shadowRenderScale = 0.2f) : base(game)
168+
public PebbleRenderer(Game game, GraphicsDeviceManager graphics, int outputWidth, int outputHeight, float renderScale = 1, float shadowRenderScale = 0.2f) : base(game)
169169
{
170170
this.graphics = graphics;
171171
this.outputWidth = outputWidth;
172172
this.outputHeight = outputHeight;
173-
this.renderWidth = (int)MathF.Floor(outputWidth*renderScale);
173+
this.renderWidth = (int)MathF.Floor(outputWidth * renderScale);
174174
this.renderHeight = (int)MathF.Floor(outputHeight * renderScale);
175175
this.renderScale = renderScale;
176176
this.shadowRenderScale = shadowRenderScale;
@@ -183,12 +183,12 @@ public PebbleRenderer(Game game, GraphicsDeviceManager graphics, int outputWidth
183183

184184

185185

186-
lmsTensor = new List<Sprite>[MAX_lAYERS,MAX_MATERIALS]; //2d array of sprite lists, one list for each material-layer combination.
186+
lmsTensor = new List<Sprite>[MAX_lAYERS, MAX_MATERIALS]; //2d array of sprite lists, one list for each material-layer combination.
187187
for (int i = 0; i < MAX_lAYERS; i++)
188188
{
189189
for (int j = 0; j < MAX_MATERIALS; j++)
190190
{
191-
lmsTensor[i,j] = new List<Sprite>();
191+
lmsTensor[i, j] = new List<Sprite>();
192192
}
193193
}
194194
materials = new Material[MAX_MATERIALS];
@@ -209,10 +209,10 @@ public override void Initialize() //override?
209209
normalTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight);
210210
roughnessTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight);
211211

212-
shadowCasterTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth*2, renderHeight*2,false,SurfaceFormat.Alpha8,DepthFormat.None); //*2?
212+
shadowCasterTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth * 2, renderHeight * 2, false, SurfaceFormat.Alpha8, DepthFormat.None); //*2?
213213
shadowUpscaleTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight, false, SurfaceFormat.Alpha8, DepthFormat.None);
214214

215-
litTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight, false,SurfaceFormat.HdrBlendable,DepthFormat.None);
215+
litTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight, false, SurfaceFormat.HdrBlendable, DepthFormat.None);
216216

217217
noiseTarget = new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight, false, SurfaceFormat.Alpha8, DepthFormat.None);
218218

@@ -256,7 +256,7 @@ public void setCameraPosition(Vector2 cameraPosition)
256256

257257
public void lookAt(Vector2 position)
258258
{
259-
this.cameraPosition = position - new Vector2(REFERENCE_WIDTH/2,REFERENCE_HEIGHT/2);
259+
this.cameraPosition = position - new Vector2(REFERENCE_WIDTH / 2, REFERENCE_HEIGHT / 2);
260260
}
261261
public Vector2 getCameraPosition()
262262
{
@@ -267,7 +267,7 @@ public void addSprite(Sprite sprite)
267267
{
268268
if (sprite.material >= materialCount)
269269
{
270-
throw new ArgumentException("shader uses material Index: " + sprite.material+" but this shader is not registered.");
270+
throw new ArgumentException("shader uses material Index: " + sprite.material + " but this shader is not registered.");
271271
}
272272
lmsTensor[sprite.layer, sprite.material].Add(sprite);
273273

@@ -280,9 +280,9 @@ public void removeSprite(Sprite sprite)
280280

281281
public void addLight(Light light)
282282
{
283-
if(light.isShadowCasting)
283+
if (light.isShadowCasting)
284284
{
285-
lights.Add(light, new Tuple<RenderTarget2D,RenderTarget2D>(
285+
lights.Add(light, new Tuple<RenderTarget2D, RenderTarget2D>(
286286
new RenderTarget2D(Game.GraphicsDevice, (int)MathF.Floor(renderWidth * shadowRenderScale), (int)MathF.Floor(renderHeight * shadowRenderScale), false, SurfaceFormat.Alpha8, DepthFormat.None),
287287
new RenderTarget2D(Game.GraphicsDevice, renderWidth, renderHeight, false, SurfaceFormat.Alpha8, DepthFormat.None)));
288288
}
@@ -292,7 +292,7 @@ public void addLight(Light light)
292292
Game.GraphicsDevice.SetRenderTarget(whiteTarget);
293293
Game.GraphicsDevice.Clear(Color.White);
294294
Game.GraphicsDevice.SetRenderTarget(null);
295-
lights.Add(light, new Tuple<RenderTarget2D,RenderTarget2D>(whiteTarget, whiteTarget));
295+
lights.Add(light, new Tuple<RenderTarget2D, RenderTarget2D>(whiteTarget, whiteTarget));
296296
}
297297
}
298298

@@ -330,7 +330,8 @@ public void addMaterial(Material material)
330330
}
331331

332332

333-
public void Draw(GameTime time) {
333+
public void Draw(GameTime time)
334+
{
334335
this.time = time.TotalGameTime.TotalSeconds;
335336
this.random = randomGen.NextDouble();
336337
RenderNoise();
@@ -344,7 +345,7 @@ public void Draw(GameTime time) {
344345

345346

346347
//maybe make drawing occlusion map conditional on having shadow casting lights?
347-
renderShadowCasters(shadowCasterTarget, view * Matrix.CreateScale(shadowRenderScale) * Matrix.CreateTranslation(new Vector3(renderWidth / 2, renderHeight / 2,0)));
348+
renderShadowCasters(shadowCasterTarget, view * Matrix.CreateScale(shadowRenderScale) * Matrix.CreateTranslation(new Vector3(renderWidth / 2, renderHeight / 2, 0)));
348349

349350

350351

@@ -384,7 +385,7 @@ public void Draw(GameTime time) {
384385
setEngineShaderParams(pointLightShader.shader);
385386
Game.GraphicsDevice.SetRenderTarget(litTarget);
386387

387-
foreach (KeyValuePair<Light,Tuple<RenderTarget2D, RenderTarget2D>> light in lights)
388+
foreach (KeyValuePair<Light, Tuple<RenderTarget2D, RenderTarget2D>> light in lights)
388389
{
389390
//the approach I have in mind might be too cpu/ draw call intensive, so I will try raymarching first, but maybe come back to the 1d occlusion map approach with some optimization later.
390391
spriteBatch.Begin(effect: pointLightShader.shader, blendState: BlendState.Additive);
@@ -402,7 +403,7 @@ public void Draw(GameTime time) {
402403

403404
//HERE
404405
Game.GraphicsDevice.SetRenderTarget(postProcessTarget1); //I can maybe optimise this to overwrite diffuse buffer or lighting buffers, depends if I still want them
405-
spriteBatch.Begin(transformMatrix: Matrix.CreateScale(1 / renderScale),samplerState: samplerState); // maybe dont create the matrix every frame
406+
spriteBatch.Begin(transformMatrix: Matrix.CreateScale(1 / renderScale), samplerState: samplerState); // maybe dont create the matrix every frame
406407
spriteBatch.Draw(diffuseTarget, new Vector2(0f), Color.White);
407408
spriteBatch.End();
408409

@@ -411,8 +412,9 @@ public void Draw(GameTime time) {
411412
Game.GraphicsDevice.SetRenderTarget(null);
412413
postProcessPingPong = true;
413414

414-
foreach (PostProcess postProcess in postProcesses){
415-
if(postProcess.shader != null)
415+
foreach (PostProcess postProcess in postProcesses)
416+
{
417+
if (postProcess.shader != null)
416418
{
417419
setEngineShaderParams(postProcess.shader);
418420
}
@@ -449,7 +451,8 @@ private void setEngineShaderParams(Effect effect)
449451
effect.Parameters["noiseMap"]?.SetValue(noiseTarget);
450452
}
451453

452-
private void renderOutput(RenderTarget2D target, Matrix viewProjection){ //refactor this maybe, having a function for rendering to target isnt as nice as I hoped.
454+
private void renderOutput(RenderTarget2D target, Matrix viewProjection)
455+
{ //refactor this maybe, having a function for rendering to target isnt as nice as I hoped.
453456
Game.GraphicsDevice.SetRenderTarget(target);
454457
Game.GraphicsDevice.Clear(Color.Black);
455458

@@ -461,7 +464,7 @@ private void setEngineShaderParams(Effect effect)
461464
materials[j].shaders[0].shader.Parameters["ambientColor"]?.SetValue(ambientLightColor.ToVector3());
462465
setEngineShaderParams(materials[j].shaders[0].shader);
463466

464-
if(lmsTensor[i, j].Count == 0)
467+
if (lmsTensor[i, j].Count == 0)
465468
{
466469
continue;
467470
}
@@ -477,7 +480,7 @@ private void setEngineShaderParams(Effect effect)
477480
Game.GraphicsDevice.SetRenderTarget(null);// is this necessary?
478481
}
479482

480-
private void renderToTarget(RenderTarget2D target, Matrix viewProjection,Color clearColor, int shaderIndex)
483+
private void renderToTarget(RenderTarget2D target, Matrix viewProjection, Color clearColor, int shaderIndex)
481484
{
482485
Game.GraphicsDevice.SetRenderTarget(target);
483486
Game.GraphicsDevice.Clear(clearColor);
@@ -518,12 +521,13 @@ private void RenderNoise()
518521
Game.GraphicsDevice.SetRenderTarget(noiseTarget);
519522
setEngineShaderParams(gradientNoiseShader.shader);
520523
spriteBatch.Begin(effect: gradientNoiseShader.shader);
521-
spriteBatch.Draw(nullTexture, new Vector2(0),null, Color.White,0,Vector2.Zero,new Vector2(renderWidth,renderHeight),SpriteEffects.None,0);
524+
spriteBatch.Draw(nullTexture, new Vector2(0), null, Color.White, 0, Vector2.Zero, new Vector2(renderWidth, renderHeight), SpriteEffects.None, 0);
522525
spriteBatch.End();
523526
Game.GraphicsDevice.SetRenderTarget(null);//? needed?
524527
}
525528

526-
private void renderShadowCasters(RenderTarget2D target, Matrix viewProjection) {
529+
private void renderShadowCasters(RenderTarget2D target, Matrix viewProjection)
530+
{
527531
Game.GraphicsDevice.SetRenderTarget(target);
528532
Game.GraphicsDevice.Clear(Color.White);
529533

@@ -562,21 +566,21 @@ private void renderDebugShapes(RenderTarget2D target, Matrix viewProjection)
562566
{
563567
Game.GraphicsDevice.SetRenderTarget(target);
564568
spriteBatch.Begin(transformMatrix: viewProjection);
565-
while(debugShapes.Count > 0)
569+
while (debugShapes.Count > 0)
566570
{
567571
DebugDrawable drawable = debugShapes.Dequeue();
568572

569573
switch (drawable.shape)
570574
{
571575
case DebugShape.LINE:
572-
spriteBatch.DrawLine(drawable.position,drawable.position2, drawable.color,4);
576+
spriteBatch.DrawLine(drawable.position, drawable.position2, drawable.color, 4);
573577
break;
574578

575579
case DebugShape.RECTANGLE:
576-
spriteBatch.DrawRectangle(new Rectangle((int)drawable.position.X, (int)drawable.position.Y, (int)(drawable.position2.X - drawable.position.X), (int)(drawable.position2.Y - drawable.position.Y)),drawable.color,4 );
580+
spriteBatch.DrawRectangle(new Rectangle((int)drawable.position.X, (int)drawable.position.Y, (int)(drawable.position2.X - drawable.position.X), (int)(drawable.position2.Y - drawable.position.Y)), drawable.color, 4);
577581
break;
578582
case DebugShape.CIRCLE:
579-
spriteBatch.DrawCircle(drawable.position,drawable.position2.X,32,drawable.color,4);
583+
spriteBatch.DrawCircle(drawable.position, drawable.position2.X, 32, drawable.color, 4);
580584
break;
581585
}
582586
}
@@ -590,7 +594,7 @@ private void renderUI(RenderTarget2D target)
590594
while (UIShapes.Count > 0)
591595
{
592596
UIDrawable drawable = UIShapes.Dequeue();
593-
spriteBatch.DrawString(drawable.font,drawable.text,drawable.position,drawable.color, 0, Vector2.Zero,drawable.scale,SpriteEffects.None,0);
597+
spriteBatch.DrawString(drawable.font, drawable.text, drawable.position, drawable.color, 0, Vector2.Zero, drawable.scale, SpriteEffects.None, 0);
594598

595599
}
596600
spriteBatch.End();

‎GREngine.Core/GREngine.Core.PebbleRenderer/PostProcess/BloomPostProcess.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace GREngine.Core.PebbleRenderer;
1212

1313

1414
public class BloomPostProcess : PostProcess // A very fast blur effect that leverages fixed function gpu texture sampling to blur with a large kernel efficiently
15-
// input gets downsampled to size/2^passes and upsampled again.
15+
// input gets downsampled to size/2^passes and upsampled again.
1616
{
1717
RenderTarget2D[] BlurTargets;
1818
int nearestPOTx;
@@ -25,7 +25,7 @@ namespace GREngine.Core.PebbleRenderer;
2525
float scale;
2626

2727
Effect isolate;
28-
public BloomPostProcess(Game game,Effect isolate, int width, int height, int passes, float scale) : base(game, null)
28+
public BloomPostProcess(Game game, Effect isolate, int width, int height, int passes, float scale) : base(game, null)
2929
{
3030
this.width = width;
3131
this.height = height;

‎GREngine.Core/GREngine.Core.PebbleRenderer/PostProcess/BlurPostProcess.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace GREngine.Core.PebbleRenderer;
1212

1313

1414
public class BlurPostProcess : PostProcess // A very fast blur effect that leverages fixed function gpu texture sampling to blur with a large kernel efficiently
15-
// input gets downsampled to size/2^passes and upsampled again.
15+
// input gets downsampled to size/2^passes and upsampled again.
1616
{
1717
RenderTarget2D[] BlurTargets;
1818
int nearestPOTx;
@@ -23,7 +23,7 @@ namespace GREngine.Core.PebbleRenderer;
2323
float finalScaleX;
2424
float finalScaleY;
2525
float scale;
26-
public BlurPostProcess(Game game,int width,int height, int passes, float scale) : base(game, null)
26+
public BlurPostProcess(Game game, int width, int height, int passes, float scale) : base(game, null)
2727
{
2828
this.width = width;
2929
this.height = height;
@@ -37,7 +37,7 @@ public BlurPostProcess(Game game,int width,int height, int passes, float scale)
3737

3838
for (int i = 0; i < passes; i++)
3939
{
40-
BlurTargets[i] = new RenderTarget2D(game.GraphicsDevice, nearestPOTx / (int)Math.Pow(1/scale,i), nearestPOTy / (int)Math.Pow(1 / scale, i));
40+
BlurTargets[i] = new RenderTarget2D(game.GraphicsDevice, nearestPOTx / (int)Math.Pow(1 / scale, i), nearestPOTy / (int)Math.Pow(1 / scale, i));
4141
}
4242

4343
}
@@ -48,30 +48,30 @@ public override void applyPostProcess(RenderTarget2D bufferIn, RenderTarget2D bu
4848

4949
game.GraphicsDevice.SetRenderTarget(BlurTargets[0]);
5050
spriteBatch.Begin();
51-
spriteBatch.Draw(bufferIn, new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(1/finalScaleX, 1/finalScaleY), SpriteEffects.None, 0);
51+
spriteBatch.Draw(bufferIn, new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(1 / finalScaleX, 1 / finalScaleY), SpriteEffects.None, 0);
5252
spriteBatch.End();
5353

54-
for (int i = 0; i < passes-1 ; i++)
54+
for (int i = 0; i < passes - 1; i++)
5555
{
56-
game.GraphicsDevice.SetRenderTarget(BlurTargets[i+1]);
56+
game.GraphicsDevice.SetRenderTarget(BlurTargets[i + 1]);
5757
spriteBatch.Begin();
5858
spriteBatch.Draw(BlurTargets[i], new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(scale, scale), SpriteEffects.None, 0);
5959
spriteBatch.End();
6060

6161
}
62-
for (int i = passes - 1; i >0; i--)
62+
for (int i = passes - 1; i > 0; i--)
6363
{
64-
game.GraphicsDevice.SetRenderTarget(BlurTargets[i-1]);
64+
game.GraphicsDevice.SetRenderTarget(BlurTargets[i - 1]);
6565
spriteBatch.Begin();
66-
spriteBatch.Draw(BlurTargets[i], new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(1/scale, 1/ scale), SpriteEffects.None, 0);
66+
spriteBatch.Draw(BlurTargets[i], new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(1 / scale, 1 / scale), SpriteEffects.None, 0);
6767
spriteBatch.End();
6868

6969
}
7070

7171

7272
game.GraphicsDevice.SetRenderTarget(bufferOut);
7373
spriteBatch.Begin();
74-
spriteBatch.Draw(BlurTargets[0], new Vector2(0f),null, Color.White,0,new Vector2(0),new Vector2(finalScaleX,finalScaleY),SpriteEffects.None,0);
74+
spriteBatch.Draw(BlurTargets[0], new Vector2(0f), null, Color.White, 0, new Vector2(0), new Vector2(finalScaleX, finalScaleY), SpriteEffects.None, 0);
7575
spriteBatch.End();
7676

7777

‎GREngine.Core/GREngine.Core.PebbleRenderer/PostProcess/DitherPostProcess.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public DitherPostProcess(Game game, Effect shader, Texture2D ditherPattern) : ba
1818
this.game = game;
1919
attributes = new Dictionary<string, float>();
2020
this.shader = shader;
21-
this.ditherPattern = ditherPattern;
21+
this.ditherPattern = ditherPattern;
2222
}
2323

2424
public override void applyPostProcess(RenderTarget2D bufferIn, RenderTarget2D bufferOut, SpriteBatch spriteBatch)

0 commit comments

Comments
 (0)
Please sign in to comment.