use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class HierarchicalAISystem method update.
// TODO add way to recognize if attacked
@Override
public void update(float delta) {
for (EntityRef entity : entityManager.getEntitiesWith(HierarchicalAIComponent.class, CharacterMovementComponent.class, LocationComponent.class)) {
LocationComponent location = entity.getComponent(LocationComponent.class);
Vector3f worldPos = location.getWorldPosition();
// Skip this AI if not in a loaded chunk
if (!worldProvider.isBlockRelevant(worldPos)) {
continue;
}
// goto Hierarchical system
loop(entity, location, worldPos);
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class EntityCreateBenchmark 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);
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class IterateSingleComponentBenchmark 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 CharacterMovementSystemUtility method setToInterpolateState.
public void setToInterpolateState(EntityRef entity, CharacterStateEvent a, CharacterStateEvent b, long time) {
float t = (float) (time - a.getTime()) / (b.getTime() - a.getTime());
Vector3f newPos = BaseVector3f.lerp(a.getPosition(), b.getPosition(), t);
Quat4f newRot = BaseQuat4f.interpolate(a.getRotation(), b.getRotation(), t);
LocationComponent location = entity.getComponent(LocationComponent.class);
location.setWorldPosition(newPos);
location.setWorldRotation(newRot);
entity.saveComponent(location);
CharacterMovementComponent movementComponent = entity.getComponent(CharacterMovementComponent.class);
movementComponent.mode = a.getMode();
movementComponent.setVelocity(a.getVelocity());
movementComponent.grounded = a.isGrounded();
if (b.getFootstepDelta() < a.getFootstepDelta()) {
movementComponent.footstepDelta = t * (1 + b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
if (movementComponent.footstepDelta > 1) {
movementComponent.footstepDelta -= 1;
}
} else {
movementComponent.footstepDelta = t * (b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
}
entity.saveComponent(movementComponent);
setPhysicsLocation(entity, newPos);
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CharacterSystem method isPredictionOfEventCorrect.
private boolean isPredictionOfEventCorrect(EntityRef character, ActivationRequest event) {
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
EntityRef camera = GazeAuthoritySystem.getGazeEntityForCharacter(character);
LocationComponent location = camera.getComponent(LocationComponent.class);
Vector3f direction = location.getWorldDirection();
if (!(vectorsAreAboutEqual(event.getDirection(), direction))) {
logger.error("Direction at client {} was different than direction at server {}", event.getDirection(), direction);
}
// Assume the exact same value in case there are rounding mistakes:
direction = event.getDirection();
Vector3f originPos = location.getWorldPosition();
if (!(vectorsAreAboutEqual(event.getOrigin(), originPos))) {
String msg = "Player {} seems to have cheated: It stated that it performed an action from {} but the predicted position is {}";
logger.info(msg, getPlayerNameFromCharacter(character), event.getOrigin(), originPos);
return false;
}
if (event.isOwnedEntityUsage()) {
if (!event.getUsedOwnedEntity().exists()) {
String msg = "Denied activation attempt by {} since the used entity does not exist on the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
if (!networkSystem.getOwnerEntity(event.getUsedOwnedEntity()).equals(networkSystem.getOwnerEntity(character))) {
String msg = "Denied activation attempt by {} since it does not own the entity at the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
} else {
// check for cheats so that data can later be trusted:
if (event.getUsedOwnedEntity().exists()) {
String msg = "Denied activation attempt by {} since it is not properly marked as owned entity usage";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
}
if (event.isEventWithTarget()) {
if (!event.getTarget().exists()) {
String msg = "Denied activation attempt by {} since the target does not exist on the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
// can happen if target existed on client
return false;
}
HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
if (!result.isHit()) {
String msg = "Denied activation attempt by {} since at the authority there was nothing to activate at that place";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
EntityRef hitEntity = result.getEntity();
if (!hitEntity.equals(event.getTarget())) {
/**
* Tip for debugging this issue: Obtain the network id of hit entity and search it in both client and
* server entity dump. When certain fields don't get replicated, then wrong entity might get hin in the
* hit test.
*/
String msg = "Denied activation attempt by {} since at the authority another entity would have been activated";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
if (!(vectorsAreAboutEqual(event.getHitPosition(), result.getHitPoint()))) {
String msg = "Denied activation attempt by {} since at the authority the object got hit at a differnt position";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
} else {
// In order to trust the data later we need to verify it even if it should be correct if no one cheats:
if (event.getTarget().exists()) {
String msg = "Denied activation attempt by {} since the event was not properly labeled as having a target";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
if (!(vectorsAreAboutEqual(event.getHitPosition(), originPos))) {
String msg = "Denied activation attempt by {} since the event was not properly labeled as having a hit postion";
logger.info(msg, getPlayerNameFromCharacter(character));
return false;
}
}
return true;
}
Aggregations