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

[WIP] Sectors/pools: v2.0.0 branch #3009

Merged
merged 11 commits into from
Jul 21, 2017
Merged

Conversation

Vizaxo
Copy link
Contributor

@Vizaxo Vizaxo commented Jul 16, 2017

This PR contains the work done so far on sectors/entity pools. There's nothing new in here that isn't in the following PRs:

#2975
Vizaxo#2
Vizaxo#3
Vizaxo#4

This PR just consolidates the work done so far, rebases it on top of the v2.0.0 branch (which is on par with develop, at the time of writing), and squashes the commits from 54 down to 8.

Also, any references to caches have been removed, so pool is used all the way through.

Summary of sectors/pools

This adds entity pools, which split up the storage of entities into multiple pools, rather than storing them all together. It implements sectors on top of that, which are a new scope for entities to allow better simulation when no players are close to the entity.

More details about the motivation behind sectors:
http://forum.terasology.org/threads/new-conceptual-layer-sector-plus-musings-on-multi-world-node.1420/

Discussion of sectors architecture:
#2976

Vizaxo added 8 commits July 16, 2017 18:08
This allows entities to be split up into mulitple pools, rather than
all being kept in one pool. It is the ground-work for sector-level
entity stores, and in future could lead to multi-threaded systems.
This adds the SectorManager (and its implementation,
PojoSectorManager), which implements sectors by having separate pools
for sector-level entities.
Refactor various methods in PojoEntityPool to have nicer, more
maintainable code, and refactor EntityManager to extend EntityPool to
reduce API duplication.
Allow information about what scope an entity is in (either
sector-scope or global) to be serialized and saved when the world is
saved. No information about which sector the entity is in is stored;
that is worked out by the SectorManager when the entity is loaded.
Consolidate multiple entity retrieval methods into getEntity(), and
clean up many methods in PojoEntityManager.
Add the moveToPool() method, and add a tests for it. Also modify
BaseEntityRef's setScope() to move the entity into the proper pool
when the scope is changed.
Some small fixes to fix listComponents(), and make create(prefab,
position) add a LocationComponent if the prefab doesn't have
one (instead of silently discarding the location).

Also moves some methods around in the EntityManager interfaces, to
hide methods that aren't meant to be used in modules.
Update tests for moveToPool() and setScope() to be more comprehensive,
and add some tests for PojoEntityPool.

Make fixes in PojoEntityManager and PojoEntityPool to esure all tests
pass, by properly assigning the entity to the new pool when
moveToPool() is called.
@emanuele3d emanuele3d added the Topic: Architecture Requests, Issues and Changes related to software architecture, programming patterns, etc. label Jul 16, 2017
@skaldarnar skaldarnar requested review from Cervator and vampcat July 19, 2017 13:09
Copy link
Member

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

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

Overall this looks good, just a few comments (and a tiny bug).
Maybe somebody else wants to give it a quick review, otherwise it's good to go.


private static Context context;
private PojoEntityManager entityManager;
//private Prefab prefab;
Copy link
Member

Choose a reason for hiding this comment

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

Remove the commented line if not needed.

* @param prefab the prefab to add
* @return whether the prefab was successfully added
*/
public void addPrefab(Prefab prefab) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this method also have return type boolean like the one above? At least the Javadoc suggests so and it would be consistent with the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I just copied the Javadoc without properly checking it.

It currently doesn't have anywhere it can fail, though I guess passing a null prefab might cause it to return false. The addPrefab(String) one only fails because a non-null string can fail to return a prefab (though, looking at it again, it will fail and not add an EntityInfoComponent on a nulll string, so changing one of them would make them consistent).

Currently adding a null prefab is fine, and is used to create an entity when you want to add a location, but not a prefab.

EntityRef create(Prefab prefab, Vector3f position);

/**
* @param prefab
Copy link
Member

Choose a reason for hiding this comment

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

Don't add empty Javadoc, it serves no purpose (applies to the other code locations as well).

/**
* @param prefab
* @param position
* @return A new entity, based on the given prefab, at the desired position
Copy link
Member

Choose a reason for hiding this comment

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

If you think that documenting the return value is enough you can leave out the @param lines. @emanuele3d what is your usual approach on this?

import java.util.Optional;

/**
*/
Copy link
Member

Choose a reason for hiding this comment

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

Why are you adding empty Javadoc all the time? Does the IDE or some tool (falsely) count this as "documented" then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, IDEA adds it automatically whenever I create a new class, I just never got around to actually writing the content. Now that the API is fairly well-defined I'll go through and add the necessary documentation.

Vizaxo added 2 commits July 21, 2017 00:03
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.
This is easier to use without importing from the protobuf nested
classes, and allows for more flexibility in the future for adding
properties to different scopes.
@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

Copy link
Member

@Cervator Cervator left a comment

Choose a reason for hiding this comment

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

Gave this a read plus some more testing. Very good work and high quality code :-)

I left a couple questions on Slack for later and found one potential bug which I'll document here in a separate comment + I made a card for it on the project board

@Cervator
Copy link
Member

Encountered the following - could reliably reproduce:

  • Was flying forward with hspeed while railgunning trees
  • When i hit the spot where the sector entity unloaded shortly after something went wrong?
  • No more was heard from the sector entity - until i went back into range, then both log statements came back
  • After turning around and going out of range once more the entity kept sector simulating

May be a consequence from an unrelated bug that none the less is able to affect the sector events / schedules.

21:00:05.445 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 loaded. Value is 97.084
21:00:06.434 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 simulating. Value is 99.084
21:00:06.434 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 loaded. Value is 99.084
21:00:06.840 [main] INFO  o.t.sectorTesting.TestSystem - Chunk unload: entity 47
21:00:07.437 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 simulating. Value is 101.088
21:00:08.460 [main] ERROR o.t.logic.delay.DelayedActionSystem - ERROR: This entity is missing a DelayedActionComponent. So skipping delayed actions for this entity
21:00:16.021 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Creating game snapshot
21:00:16.031 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Snapshot created: Writing phase starts
21:00:17.653 [Saving-0] INFO  o.t.p.internal.SaveTransaction - Save game finished
21:00:19.349 [Timer-0] WARN  o.t.r.logic.NearestSortingList - Something went wrong during sorting process. Sorting is skipped this round.
21:00:19.399 [Timer-0] WARN  o.t.r.logic.NearestSortingList - The commands list was not emptied properly!
21:00:22.299 [Timer-0] WARN  o.t.r.logic.NearestSortingList - Something went wrong during sorting process. Sorting is skipped this round.
21:01:16.082 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Creating game snapshot
21:01:16.087 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Snapshot created: Writing phase starts
21:01:17.047 [Saving-0] INFO  o.t.p.internal.SaveTransaction - Save game finished
21:02:16.087 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Creating game snapshot
21:02:16.088 [main] INFO  o.t.p.i.ReadWriteStorageManager - Saving - Snapshot created: Writing phase starts
21:02:17.001 [Saving-0] INFO  o.t.p.internal.SaveTransaction - Save game finished
21:02:18.923 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 simulating. Value is 364.07202
21:02:19.517 [main] INFO  o.t.sectorTesting.TestSystem - Chunk load: entity 47
21:02:19.517 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 simulating. Value is 365.234
21:02:19.517 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 loaded. Value is 365.234
21:02:19.941 [main] INFO  o.t.sectorTesting.TestSystem - Entity 47 simulating. Value is 366.108

@Cervator Cervator merged commit 063fb2f into MovingBlocks:v2.0.0 Jul 21, 2017
@Cervator Cervator added this to the v2.0.0 milestone Jul 21, 2017
@Cervator Cervator mentioned this pull request Jul 21, 2017
@Vizaxo
Copy link
Contributor Author

Vizaxo commented Jul 21, 2017

Yeah, that's because I made sector entities not be alwaysRelevant all the time (or DynamicCities would create hundreds of thousands of entities that don't unload, and cause some lag), and haven't updated the tutorial module yet. I'll have a look into it with DC; perhaps those region entities can be chunk-scope.

Again, this goes back to whether to abandon alwaysRelevant altogether in favour of just setting the scope (Global, Sector, or Chunk). I think just setting the scope is a nicer way of doing it, as long as the sector entities can always be alwaysRelevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic: Architecture Requests, Issues and Changes related to software architecture, programming patterns, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants