Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sector Simulation #5

Closed
wants to merge 1 commit into from
Closed

Conversation

Vizaxo
Copy link
Owner

@Vizaxo Vizaxo commented Jul 17, 2017

This PR includes the mechanisms to allow sector-scope entities to perform simulation tasks. The bulk of the work is done by the SectorSimulationSystem, which sends events to allow sector-scope entities to work.

The SectorSimulationEvent is sent repeatedly, whether or not the chunk the entity is in is loaded. It will be sent at least once every maxDelta (defined in the SectorSimulationComponent, which holds information for calculating the simulation delta), but might be sent more often (e.g. it is always sent when the chunk is loaded). This should be used for any calculations and simulation the entity needs to do.

TODO: add another property so that the simulation rate can be adjusted when the entity is loaded

The LoadedSectorUpdateEvent is sent repeatedly, but only while the chunk the entity is in is loaded. This is where any effects on the world should take place, as the chunk is guaranteed to be loaded whenever this is sent. A SectorSimulationEvent is always sent immediately prior to this one, so no simulation needs to happen in reaction to this event.

The OnChunkLoaded and BeforeChunkLoaded also get forwarded to the appropriate sector entities when their chunks are affected, so certain things can be done on chunk load/unload (e.g. caching some data to use when the chunk is unloaded). A LoadedSectorUpdateEvent is automatically sent immediately after the OnChunkLoaded event, so this only needs to be used for things that don't normally get simulated (e.g. generating new villager entities).

See the SectorTesting module for an example of how it is implemented.

This is the system behind the simulation of sector-scope entities. It
allows sector-level entities to be used for simulation, even when the
chunk they are in is not loaded.
@@ -33,7 +33,7 @@
*
* @return the newly created EntityRef
*/
default EntityRef createSectorEntity() {
default EntityRef createSectorEntity(long maxDelta) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a @param maxDelta Javadoc description.

/**
* The component that allows the {@link SectorSimulationSystem} to send simulation events to a sector-scope entity.
*
* This should be automatically added by either {@link EntityManager#createSectorEntity(long)} or

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, might there be a use case for setting this component in a prefab? I can't think of any good example right now ... maybe a group of deer splitting up and a new DeerGroup entity is created (in sector-scope). Just want to hear you opinion on this...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that too. There should probably be a way to define this in the prefab, and to set the maxDelta there too.

I think it would be useful, as you can just create an entity from the prefab, and not worry about any scope or deltas or anything like that (which would also allow, say, a DeerGroup to simulate correctly if it is spawned with the spawnPrefab command).

}

/**
* This gives the time elapsed, in seconds, since the last time this event was sent to the given {@link EntityRef}.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether it is a smart decision to use seconds here. It obviously conveys the idea that sector simulation happens at larger intervals. However, usually the simulations would get a delta in milliseconds for their computation. This might yield confusion when you try to use the same simulation code for both scopes.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are milliseconds used? I know the DelayManager uses them to set the delay, but the UpdateSubscriberSystem uses seconds for its delta, and I've used seconds for all of the sector simulation stuff (I assumed seconds was the more common one). If ms is more common it would probably be best to use that to be consistent.

* big variations in the time between sending these events (notably, an event will be sent whenever the chunk an
* entity is in is loaded, even if one has just been sent.
*
* Using the delta will give a relaible measure of how much simulation to perform.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in "reliable"

@Vizaxo
Copy link
Owner Author

Vizaxo commented Jul 26, 2017

Merged in MovingBlocks#3009

@Vizaxo Vizaxo closed this Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants