A Simple Discrete-Event Simulation: Part 6

Now that I’m sure the basics are working the way I’d like I want to see if I can streamline things some more.

The first thing to do is recognize that the next item being pulled off the future events queue can always be referred to the same way. If we make the item a global variable then we can always have code refer to it by a known name without having to pass the reference around all over the place. This cleans things up quite a bit.

We’ll start by creating a variable called feqCurrent, which is intended to hold a futureEventItem object.

Next, we’ll copy the insertExistingItem method in the futureEventsQueue object so it eliminates the need to pass in a reference to an feqItem, because it refers to the global variable instead.

We’ll follow that up by streamlining the advance function in the same way.

Then we’ll do the same to the activate function in the entity object.

Finally, we’ll do the same thing to the main event processing loop.

The output remains the same as before, so we assume we haven’t broken anything.

This entry was posted in Simulation and tagged , . Bookmark the permalink.

Leave a Reply