perf: removed obsolete method calls and switched to for in draw calls

This commit is contained in:
Syntriax 2025-05-29 22:49:51 +03:00
parent 59059fa09d
commit 3c38cb4159
7 changed files with 18 additions and 18 deletions

2
Engine

@ -1 +1 @@
Subproject commit feb2a05aa3e0683b62f7a306ab73df0def060dda Subproject commit 67d7f401b832156e40e9bda11a4546cccd232707

View File

@ -72,8 +72,8 @@ public class KeyboardInputsBehaviour : Behaviour, IButtonInputs<Keys>
if (WasPressed(currentlyPressedKey)) if (WasPressed(currentlyPressedKey))
continue; continue;
action.InvokeSafe(this, currentlyPressedKey); action.Invoke(this, currentlyPressedKey);
OnAnyButtonPressed?.InvokeSafe(this, currentlyPressedKey); OnAnyButtonPressed?.Invoke(this, currentlyPressedKey);
} }
for (int i = 0; i < cachePressedPreviouslyCount; i++) for (int i = 0; i < cachePressedPreviouslyCount; i++)
@ -86,8 +86,8 @@ public class KeyboardInputsBehaviour : Behaviour, IButtonInputs<Keys>
if (IsPressed(previouslyPressedKey)) if (IsPressed(previouslyPressedKey))
continue; continue;
action.InvokeSafe(this, previouslyPressedKey); action.Invoke(this, previouslyPressedKey);
OnAnyButtonReleased?.InvokeSafe(this, previouslyPressedKey); OnAnyButtonReleased?.Invoke(this, previouslyPressedKey);
} }
Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount); Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount);

View File

@ -27,7 +27,7 @@ public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : Behavio
return; return;
_matrixTransform = value; _matrixTransform = value;
OnMatrixTransformChanged?.InvokeSafe(this); OnMatrixTransformChanged?.Invoke(this);
} }
} }
@ -46,7 +46,7 @@ public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : Behavio
return; return;
_viewport = value; _viewport = value;
OnViewportChanged?.InvokeSafe(this); OnViewportChanged?.Invoke(this);
} }
} }
@ -61,7 +61,7 @@ public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : Behavio
return; return;
_zoom = newValue; _zoom = newValue;
OnZoomChanged?.InvokeSafe(this); OnZoomChanged?.Invoke(this);
} }
} }

View File

@ -43,7 +43,7 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity,
public void ScoreToLeft() public void ScoreToLeft()
{ {
ScoreLeft++; ScoreLeft++;
OnScored?.InvokeSafe(this); OnScored?.Invoke(this);
CheckFinish(); CheckFinish();
} }
@ -51,7 +51,7 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity,
public void ScoreToRight() public void ScoreToRight()
{ {
ScoreRight++; ScoreRight++;
OnScored?.InvokeSafe(this); OnScored?.Invoke(this);
CheckFinish(); CheckFinish();
} }
@ -63,7 +63,7 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity,
ball.ResetBall(); ball.ResetBall();
ball.LaunchBall(GetBallLaunchDirection()); ball.LaunchBall(GetBallLaunchDirection());
OnReset?.InvokeSafe(this); OnReset?.Invoke(this);
} }
private void CheckFinish() private void CheckFinish()
@ -73,7 +73,7 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity,
if (ScoreLeft > halfwayScore || ScoreRight > halfwayScore) if (ScoreLeft > halfwayScore || ScoreRight > halfwayScore)
{ {
OnFinished?.InvokeSafe(this); OnFinished?.Invoke(this);
return; return;
} }

View File

@ -14,6 +14,6 @@ public class WallScoreBehaviour(Action OnCollision) : Behaviour2D
if (!BehaviourController.TryGetBehaviour(out ICollider2D? collider2D)) if (!BehaviourController.TryGetBehaviour(out ICollider2D? collider2D))
return; return;
collider2D.OnCollisionDetected += (_, _1) => OnCollision?.InvokeSafe(); collider2D.OnCollisionDetected += (_, _1) => OnCollision?.Invoke();
} }
} }

View File

@ -179,13 +179,13 @@ public class GamePong : Game
universe.Draw(); universe.Draw();
spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: cameraBehaviour.MatrixTransform); spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: cameraBehaviour.MatrixTransform);
foreach (var displayable in displayableCollector) for (int i = displayableCollector.Behaviours.Count - 1; i >= 0; i--)
displayable.Draw(spriteBatch); displayableCollector.Behaviours[i].Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
shapeBatch.Begin(cameraBehaviour.MatrixTransform); shapeBatch.Begin(cameraBehaviour.MatrixTransform);
foreach (var displayableShape in displayableShapeCollector) for (int i = displayableShapeCollector.Behaviours.Count - 1; i >= 0; i--)
displayableShape.Draw(shapeBatch); displayableShapeCollector.Behaviours[i].Draw(shapeBatch);
shapeBatch.End(); shapeBatch.End();
base.Draw(gameTime); base.Draw(gameTime);

View File

@ -37,7 +37,7 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
return; return;
foreach (Delegate @delegate in delegates) foreach (Delegate @delegate in delegates)
@delegate.InvokeSafe(packet, peer.Id.ToString()); @delegate.DynamicInvoke(packet, peer.Id.ToString());
} }
private void NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, byte channel, DeliveryMethod deliveryMethod) private void NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, byte channel, DeliveryMethod deliveryMethod)