diff --git a/content/pong/ball/bouncing/motion_engine.md b/content/pong/ball/bouncing/motion_engine.md index 5b115f6..aa35f92 100644 --- a/content/pong/ball/bouncing/motion_engine.md +++ b/content/pong/ball/bouncing/motion_engine.md @@ -72,7 +72,9 @@ namespace PongFE.Engines } ``` -Next, let's consolidate our MotionMessages per Entity. +First, at the very beginning of the processing, we insert all of our entities with a Position and Collision into the SpatialHash. + +Next, in a separate block, let's consolidate our MotionMessages per Entity. ```cs ... @@ -81,6 +83,11 @@ Next, let's consolidate our MotionMessages per Entity. ... + foreach (var entity in TrackedEntities) + { + ... + } + foreach (ref readonly var entity in ReadEntities()) { ref readonly var positionComponent = ref GetComponent(entity); @@ -95,7 +102,7 @@ Next, let's consolidate our MotionMessages per Entity. ... ``` -This is where our *IHasEntity* optimization comes in. It allows us to use the **ReadMessagesWithEntity** method. +This is where our *IHasEntity* optimization comes in. It allows us to use the **ReadMessagesWithEntity** method. This method efficiently queries messages that refer to the given entity. Finally, let's implement our sweep test. @@ -219,11 +226,16 @@ namespace PongFE.Engines } ``` -Now we can send these messages in **MotionEngine**. +Now, in the final block of our **MotionEngine**, we can perform our collision tests and send out our messages. ```cs ... + foreach (ref readonly var entity in ReadEntities()) + { + ... + } + foreach (var entity in TrackedEntities) { Vector2 moveAmount = _moveAmounts[entity]; @@ -252,8 +264,6 @@ Now we can send these messages in **MotionEngine**. SendMessage(new UpdatePositionMessage(entity, projectedPosition)); } - - ... ``` Here, we go over everything with a Position and Collision component, sweep test for collisions, and send appropriate Collision and UpdatePosition messages accordingly.