The first ECS-based objects are done

Posted by Isaac Lichter on July 20, 2020

When I wrote my last blog post, I had two pull requests that were ready for review. They were both approved, but the two branches had merge conflicts. After working out the conflicts, I put both PRs into a new one, which was then merged.

Once that was done, I turned my attention to my next big goal: making ECS-based asteroids. However, I needed to accomplish another project first. In order to create a fully functioning asteroid, I needed to create a DropsMoneyOnDeath component, so that when an asteroid is destroyed, Money objects will be created (the same way that it already would). The Money creation is handled by the MoneyDroppingSystem, which creates Money whenever an entity with a DropsMoneyOnDeath component receives a DestroyEvent. The amount of money is scaled based on the size of the entity. The PR is currently under review.

After that, I was able to start designing asteroids themselves. First, I made a system to create an asteroid Body and a system to handle impulse events to an entity with an asteroid component.

Next, I added code to SolContactListener (the class that handles contact) to send the Contact object in a Contact event. Asteroids don’t have any special contact handling, but the new code works for every entity.

Finally, I made a prefab for easy asteroid creation. However, the PR currently can’t be tested, because the gestalt library currently has issues handling empty components and components with public fields (as opposed to getters and setters). Once the next version is released, I’ll test and fine-tune my PR.

After that, I moved to refactoring the Transcendent class. In the current structure, when a ship enters a starport, it is changed into a Transcendent object. Once it gets to the other end, it is converted back into a SolShip. With my new PR, it’ll be much simpler to handle; all it takes is an InStarportTransit component and an EnteringStarportEvent.

When an entity enters a starport, the EnteringStarportEvent sends information about the source and destination of the entity to the system that handles the movement. That system moves the entity toward the destination every tick, when it receives an update event. Then, once the entity has reached the destination, a StarportTransitFinishedEvent is sent to tell the system to remove the InStarportTransit component. While it is traveling, the StarportTravelSystem prevents the entity from taking any damage or colliding with anything.

The Graphics code still has some slight issues, so I’m going to tackle that next. After that, it’s on to SolShip!