-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #2975
Closed
Closed
[WIP] Sectors #2975
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
83cf26a
Implement sector-level entity stores
Vizaxo c4e6658
Rename EnittyStore to EntityCache (EntityStore already existed)
Vizaxo 4bf43c8
Refactor EntityManager into EntityManager and EntityCache
Vizaxo ea66429
Implement clearing of EntityCache
Vizaxo 25e5cd1
Add fixes and notes regarding EntityManager methods on sectors
Vizaxo aae66e2
Reorder methods in PojoEntityManager to be in their original order
Vizaxo b1ae5d1
Make createEntityRef check all caches
Vizaxo 15ca85c
Allow any EntityRef to have invalidate() called on it
Vizaxo 4bf88fa
Make getEntityStore return an unmodifiable map
Vizaxo 47511ee
Make the EntityManager store entity components in the correct cache
Vizaxo 0a537c6
Make small code style improvements
Vizaxo ae7a6d1
Add checks to handle null prefabs
Vizaxo 1ee645b
Add checks to treat null component lists as empty lists
Vizaxo 28eb9dd
Add the getAllEntities method to the EntityCache
Vizaxo 5261096
Implement getEntitiesWith method for EntityCache
Vizaxo 93542c9
Simplify creation of EntityBuilders with prefabs
Vizaxo fe0aa62
Add getExistingEntity method
Vizaxo 5263091
Add hasComponent method to EntityCache
Vizaxo 3cb07c2
Add the SectorManager and update PojoEntityManager to use it
Vizaxo bd8225e
Refactor entity creation methods to use EntityBuilder
Vizaxo 19b710b
Refactor createEntityWithoutLifecycleEvents to use EntityBuilder
Vizaxo 6d92ec0
Refactor EntityManager to extend EntityCache & add EngineEntityCache
Vizaxo d73c2f5
Refactor PojoSectorManager to implement EngineEntityCache
Vizaxo 74411b3
Update getAllEntities method to iterate over all caches
Vizaxo dc5ea5f
Update getEntitiesWith method to iterate over all caches
Vizaxo 487ae2d
Allow serialization of sector-scope entities
Vizaxo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
engine/src/main/java/org/terasology/entitySystem/entity/EntityCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* Copyright 2017 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.entitySystem.entity; | ||
|
||
import org.terasology.entitySystem.Component; | ||
import org.terasology.entitySystem.prefab.Prefab; | ||
import org.terasology.math.geom.Quat4f; | ||
import org.terasology.math.geom.Vector3f; | ||
|
||
/** | ||
*/ | ||
public interface EntityCache { | ||
|
||
/** | ||
* Removes all entities from the cache. | ||
*/ | ||
void clear(); | ||
|
||
/** | ||
* Creates an EntityBuilder. | ||
* | ||
* @return A new entity builder | ||
*/ | ||
EntityBuilder newBuilder(); | ||
|
||
/** | ||
* Creates an EntityBuilder, from a prefab | ||
* | ||
* @return A new entity builder | ||
*/ | ||
EntityBuilder newBuilder(String prefabName); | ||
|
||
/** | ||
* Creates an EntityBuilder, from a prefab | ||
* | ||
* @return A new entity builder | ||
*/ | ||
EntityBuilder newBuilder(Prefab prefab); | ||
|
||
/** | ||
* @return A references to a new, unused entity | ||
*/ | ||
EntityRef create(); | ||
|
||
/** | ||
* @return A references to a new, unused entity with the desired components | ||
*/ | ||
EntityRef create(Component... components); | ||
|
||
/** | ||
* @return A references to a new, unused entity with the desired components | ||
*/ | ||
EntityRef create(Iterable<Component> components); | ||
|
||
|
||
/** | ||
* Creates a new entity from the given components. | ||
* | ||
* @param components the components to create this entity from | ||
* @param sendLifecycleEvents will only send lifecycle events if this is true | ||
* @return | ||
*/ | ||
EntityRef create(Iterable<Component> components, boolean sendLifecycleEvents); | ||
|
||
/** | ||
* @param prefabName The name of the prefab to create. | ||
* @return A new entity, based on the the prefab of the given name. If the prefab doesn't exist, just a new entity. | ||
*/ | ||
EntityRef create(String prefabName); | ||
|
||
/** | ||
* @param prefab | ||
* @return A new entity, based on the given prefab | ||
*/ | ||
EntityRef create(Prefab prefab); | ||
|
||
// TODO: Review. Probably better to move these into a static helper | ||
|
||
/** | ||
* @param prefab | ||
* @param position | ||
* @return A new entity, based on the given prefab, at the desired position | ||
*/ | ||
EntityRef create(String prefab, Vector3f position); | ||
|
||
/** | ||
* @param prefab | ||
* @param position | ||
* @return A new entity, based on the given prefab, at the desired position | ||
*/ | ||
EntityRef create(Prefab prefab, Vector3f position); | ||
|
||
/** | ||
* @param prefab | ||
* @param position | ||
* @param rotation | ||
* @return | ||
*/ | ||
EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation); | ||
|
||
/** | ||
* Creates an entity but doesn't send any lifecycle events. | ||
* <br><br> | ||
* This is used by the block entity system to give an illusion of permanence to temporary block entities. | ||
* | ||
* @param components | ||
* @return The newly created entity ref. | ||
*/ | ||
EntityRef createEntityWithoutLifecycleEvents(Iterable<Component> components); | ||
|
||
/** | ||
* Creates an entity but doesn't send any lifecycle events. | ||
* <br><br> | ||
* This is used by the block entity system to give an illusion of permanence to temporary block entities. | ||
* | ||
* @param prefab | ||
* @return The newly created entity ref. | ||
*/ | ||
EntityRef createEntityWithoutLifecycleEvents(String prefab); | ||
|
||
EntityRef createEntityWithoutLifecycleEvents(Prefab prefab); | ||
|
||
/** | ||
* Allows the creation of an entity with a given id - this is used | ||
* when loading persisted entities | ||
* | ||
* @param id | ||
* @param components | ||
* @return The entityRef for the newly created entity | ||
*/ | ||
EntityRef createEntityWithId(long id, Iterable<Component> components); | ||
|
||
/** | ||
* Creates an entity ref with the given id. This is used when loading components with references. | ||
* | ||
* @param id | ||
* @return The entityRef for the given id | ||
*/ | ||
EntityRef createEntityRefWithId(long id); | ||
|
||
Iterable<EntityRef> getAllEntities(); | ||
|
||
/** | ||
* @param componentClasses | ||
* @return An iterable over all entities with the provided component types. | ||
*/ | ||
Iterable<EntityRef> getEntitiesWith(Class<? extends Component>... componentClasses); | ||
|
||
/** | ||
* @param componentClasses | ||
* @return A count of entities with the provided component types | ||
*/ | ||
int getCountOfEntitiesWith(Class<? extends Component>... componentClasses); | ||
|
||
/** | ||
* @return A count of currently active entities | ||
*/ | ||
int getActiveEntityCount(); | ||
|
||
/** | ||
* Gets an entity, if it already exists. | ||
* | ||
* @param id the id of the desired entity | ||
* @return the {@link EntityRef}, if it exists; {@link EntityRef#NULL} otherwise | ||
*/ | ||
EntityRef getExistingEntity(long id); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do a final iteration over the Javadoc in the end. Most of it is pretty self-documenting. However, try to avoid "empty" Javadoc where just the parameter names and such are auto-generated. A general summary of what the
EntityCache
actually is might be helpful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I will. I didn't want to go documenting lots of stuff now when it's still rapidly changing.