use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class IterateMultipleComponentBenchmark method run.
@Override
public void run() {
for (EntityRef entity : entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
loc.getLocalPosition();
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class IterateMultipleComponentBenchmark method setup.
@Override
public void setup() {
FastRandom rand = new FastRandom(0L);
rawEntityData = Lists.newArrayList();
for (int i = 0; i < 1000; ++i) {
List<Component> entityData = Lists.newArrayList();
if (rand.nextFloat() < 0.75f) {
entityData.add(new LocationComponent());
}
if (rand.nextFloat() < 0.5f) {
entityData.add(new MeshComponent());
}
if (rand.nextFloat() < 0.25f) {
entityData.add(new BlockComponent());
}
rawEntityData.add(entityData);
}
entityManager = new PojoEntityManager();
for (List<Component> rawEntity : rawEntityData) {
entityManager.create(rawEntity);
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class IterateSingleComponentBenchmark method run.
@Override
public void run() {
for (EntityRef entity : entityManager.getEntitiesWith(LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
loc.getLocalPosition();
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class SectorUtil method getWatchedChunks.
/**
* Watched chunks are defined as the union of:
* <ul>
* <li>The chunk in which the {@link LocationComponent#getWorldPosition()} resides, if any</li>
* <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
* </ul>
*
* @param entity the entity to query the watched chunks of
* @return the set of positions of this entity's watched chunks
*/
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
Set<Vector3i> chunks = new HashSet<>();
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
chunks.add(ChunkMath.calcChunkPos(loc.getWorldPosition()));
}
SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
if (regionComponent != null) {
chunks.addAll(regionComponent.chunks);
}
return chunks;
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class TargetSystem method updateTarget.
public boolean updateTarget(Vector3f pos, Vector3f dir, float maxDist) {
if (targetBlockPos != null && !target.exists()) {
target = blockRegistry.getEntityAt(targetBlockPos);
}
HitResult hitInfo = physics.rayTrace(pos, dir, maxDist, filter);
EntityRef newTarget = hitInfo.getEntity();
if (hitInfo.isWorldHit()) {
if (targetBlockPos != null) {
if (targetBlockPos.equals(hitInfo.getBlockPosition())) {
return false;
}
}
targetBlockPos = hitInfo.getBlockPosition();
} else {
if (target.equals(newTarget)) {
return false;
}
targetBlockPos = null;
}
prevTarget = target;
target = newTarget;
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null && targetBlockPos != null) {
location.setLocalPosition(targetBlockPos.toVector3f());
}
return true;
}
Aggregations