Skip to content

Commit

Permalink
Small sector/pool updates (primarily documentation)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vizaxo committed Jul 20, 2017
1 parent f2efc0e commit 063fb2f
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@
import static org.terasology.entitySystem.entity.internal.EntityScope.GLOBAL;
import static org.terasology.entitySystem.entity.internal.EntityScope.SECTOR;

/**
*/
public class BaseEntityRefTest {

private static Context context;
private PojoEntityManager entityManager;
//private Prefab prefab;
private EntityRef ref;

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
import org.terasology.entitySystem.event.internal.EventSystem;
import org.terasology.entitySystem.metadata.ComponentLibrary;
import org.terasology.entitySystem.prefab.PrefabManager;
import org.terasology.entitySystem.sectors.SectorSimulationComponent;

import java.util.Map;

/**
*/
public interface EntityManager extends EntityPool {

/**
* Creates a new EntityRef in sector-scope
*
* @param maxDelta the maximum delta for the sector entity's simulations
* @see SectorSimulationComponent#maxDelta
* @return the newly created EntityRef
*/
default EntityRef createSectorEntity(long maxDelta) {
return null;
}

/**
* @param other
* @return A new entity with a copy of each of the other entity's components
* @deprecated Use EntityRef.copy() instead.
*/
Expand All @@ -48,7 +48,6 @@ default EntityRef createSectorEntity(long maxDelta) {
/**
* Creates a copy of the components of an entity.
*
* @param original
* @return A map of components types to components copied from the target entity.
*/
// TODO: Remove? A little dangerous due to ownership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.terasology.math.geom.Quat4f;
import org.terasology.math.geom.Vector3f;

/**
*/
public interface EntityPool {

/**
Expand Down Expand Up @@ -82,32 +80,24 @@ public interface EntityPool {
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
* @return A new entity, based on the given prefab, at the desired position, and with the desired rotation
*/
EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation);

Expand All @@ -116,7 +106,6 @@ public interface EntityPool {
* <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);
Expand All @@ -126,7 +115,6 @@ public interface EntityPool {
* <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);
Expand All @@ -137,30 +125,28 @@ public interface EntityPool {
* 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);

/**
* Retrieve the entity ref with the given id.
*
* @param id
* @return the {@link EntityRef}, if it exists; {@link EntityRef#NULL} otherwise
*/
EntityRef getEntity(long id);

/**
* @return an iterable over all of the entities in this pool
*/
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class EntityRef implements MutableComponentContainer {
/**
* Sets the scope of the entity
*
* @param scope
* @param scope the new scope for the entity
*/
public void setScope(EntityScope scope) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.terasology.entitySystem.entity.internal.EngineEntityPool;
import org.terasology.entitySystem.entity.internal.EngineSectorManager;

/**
*/
public interface LowLevelEntityManager extends EntityManager {

boolean isExistingEntity(long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
*/
package org.terasology.entitySystem.entity;

/**
*/
public interface SectorManager extends EntityPool {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import java.util.Optional;

/**
*/
public interface EngineEntityManager extends LowLevelEntityManager, EngineEntityPool {

void setEntityRefStrategy(RefStrategy strategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import java.util.Optional;

/**
*/
public interface EngineEntityPool extends EntityPool {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@

import org.terasology.entitySystem.entity.SectorManager;

/**
*/
public interface EngineSectorManager extends SectorManager, EngineEntityPool {
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

import static org.terasology.entitySystem.entity.internal.EntityScope.SECTOR;

/**
*/
public class PojoEntityManager implements EngineEntityManager {
public static final long NULL_ID = 0;

Expand Down Expand Up @@ -136,7 +134,6 @@ public EntityRef createSectorEntity(long maxDelta) {
entity.addOrSaveComponent(new SectorSimulationComponent(maxDelta));

//TODO: look into keeping all sector entities loaded, or converting alwaysRelevant into another scope
entity.setAlwaysRelevant(true);
return entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

import static org.terasology.entitySystem.entity.internal.PojoEntityManager.NULL_ID;

/**
*/
public class PojoEntityPool implements EngineEntityPool {

private PojoEntityManager entityManager;
Expand Down Expand Up @@ -94,7 +92,8 @@ public EntityRef create(Iterable<Component> components, boolean sendLifecycleEve
}
}

for (Component component: components) {
//Retrieve the components again in case they were modified by the previous events
for (Component component : entityManager.iterateComponents(entity.getId())) {
entityManager.notifyComponentAdded(entity, component.getClass());
}

Expand Down Expand Up @@ -126,7 +125,6 @@ public EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation) {
return create(prefab, position, rotation, true);
}

//@Override
private EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation, boolean sendLifecycleEvents) {
EntityBuilder builder = newBuilder(prefab);
builder.setSendLifecycleEvents(sendLifecycleEvents);
Expand All @@ -147,8 +145,7 @@ private EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation, bool
return builder.build();
}

//@Override
public EntityRef create(String prefabName, Vector3f position, Quat4f rotation) {
private EntityRef create(String prefabName, Vector3f position, Quat4f rotation) {
return create(prefabName, position, rotation, true);
}

Expand All @@ -170,7 +167,7 @@ private EntityRef create(String prefabName, Vector3f position, Quat4f rotation,
/**
* Destroys this entity, sending event
*
* @param entityId
* @param entityId the id of the entity to destroy
*/
@Override
public void destroy(long entityId) {
Expand Down Expand Up @@ -288,6 +285,7 @@ public EntityRef createEntityWithId(long id, Iterable<Component> components) {
return entity;
}

@Override
public EntityBuilder newBuilder() {
return new EntityBuilder(entityManager, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.List;
import java.util.Optional;

/**
*/
public class PojoSectorManager implements EngineSectorManager {

private List<EngineEntityPool> pools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected SectorSimulationEvent(float delta) {
* 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.
* Using the delta will give a reliable measure of how much simulation to perform.
*
* @return the time, in seconds, since the last time this event was sent to the given entity
*/
Expand Down

0 comments on commit 063fb2f

Please sign in to comment.