@Override public boolean step() { NetworkSystemImpl networkSystem = (NetworkSystemImpl) CoreRegistry.get(NetworkSystem.class); EntityRef client = networkSystem.getServer().getClientEntity(); if (client.exists()) { CoreRegistry.get(LocalPlayer.class).setClientEntity(client); return true; } return false; }
@Override public boolean step() { EngineEntityManager entityManager = (EngineEntityManager) CoreRegistry.get(EntityManager.class); EntitySystemLibrary entitySystemLibrary = CoreRegistry.get(EntitySystemLibrary.class); BlockEntityRegistry blockEntityRegistry = CoreRegistry.get(BlockEntityRegistry.class); CoreRegistry.get(NetworkSystem.class) .connectToEntitySystem(entityManager, entitySystemLibrary, blockEntityRegistry); CoreRegistry.get(ComponentSystemManager.class).initialise(); return true; }
/** @author Immortius <*****@*****.**> */ public class BlockFamilyTypeHandler implements TypeHandler<BlockFamily> { private BlockManager blockManager = CoreRegistry.get(BlockManager.class); @Override public EntityData.Value serialize(BlockFamily value) { return EntityData.Value.newBuilder().addString(value.getURI().toString()).build(); } @Override public BlockFamily deserialize(EntityData.Value value) { if (value.getStringCount() > 0) { return blockManager.getBlockFamily(value.getString(0)); } return null; } @Override public EntityData.Value serializeCollection(Iterable<BlockFamily> value) { EntityData.Value.Builder result = EntityData.Value.newBuilder(); for (BlockFamily item : value) { result.addString(item.getURI().toString()); } return result.build(); } @Override public List<BlockFamily> deserializeCollection(EntityData.Value value) { List<BlockFamily> result = Lists.newArrayListWithCapacity(value.getStringCount()); for (String item : value.getStringList()) { result.add(blockManager.getBlockFamily(item)); } return result; } }
@Override public void initialise() { final BlockManager blockManager = CoreRegistry.get(BlockManager.class); lampTurnedOff = blockManager.getBlock("signalling:SignalLampOff"); lampTurnedOn = blockManager.getBlock("signalling:SignalLampOn"); signalTransformer = blockManager.getBlock("signalling:SignalTransformer"); signalPressurePlate = blockManager.getBlock("signalling:SignalPressurePlate"); signalSwitch = blockManager.getBlock("signalling:SignalSwitch"); signalLimitedSwitch = blockManager.getBlock("signalling:SignalLimitedSwitch"); signalButton = blockManager.getBlock("signalling:SignalButton"); signalOrGate = blockManager.getBlockFamily("signalling:SignalOrGate"); signalAndGate = blockManager.getBlockFamily("signalling:SignalAndGate"); signalXorGate = blockManager.getBlockFamily("signalling:SignalXorGate"); signalNandGate = blockManager.getBlockFamily("signalling:SignalNandGate"); signalOnDelayGate = blockManager.getBlockFamily("signalling:SignalOnDelayGate"); signalOffDelayGate = blockManager.getBlockFamily("signalling:SignalOffDelayGate"); signalSetResetGate = blockManager.getBlockFamily("signalling:SignalSetResetGate"); }
/** * Camera base class. * * @author Benjamin Glatzel <*****@*****.**> */ public abstract class Camera { /* CAMERA PARAMETERS */ protected final Vector3f position = new Vector3f(0, 0, 0); protected final Vector3f up = new Vector3f(0, 1, 0); protected final Vector3f viewingDirection = new Vector3f(1, 0, 0); protected float zNear = 0.1f; // TODO: This is too large, but many properties have to be adjusted if it changes protected float zFar = 5000.0f; protected float targetFov = CoreRegistry.get(Config.class).getRendering().getFieldOfView(); protected float activeFov = targetFov / 4f; /* VIEW FRUSTUM */ protected final ViewFrustum viewFrustum = new ViewFrustum(); protected final ViewFrustum viewFrustumReflected = new ViewFrustum(); /* MATRICES */ protected Matrix4f projectionMatrix = new Matrix4f(); protected Matrix4f inverseProjectionMatrix = new Matrix4f(); protected Matrix4f normViewMatrix = new Matrix4f(); protected Matrix4f viewMatrix = new Matrix4f(); protected Matrix4f viewProjectionMatrix = new Matrix4f(); protected Matrix4f inverseViewProjectionMatrix = new Matrix4f(); protected Matrix4f prevViewProjectionMatrix = new Matrix4f(); protected Matrix4f reflectionMatrix = new Matrix4f(); protected Matrix4f viewMatrixReflected = new Matrix4f(); protected Matrix4f normViewMatrixReflected = new Matrix4f(); /* USED FOR DIRTY CHECKS */ protected Vector3f cachedPosition = new Vector3f(); protected Vector3f cachedViewigDirection = new Vector3f(); protected float cachedFov; protected float cachedZNear; protected float cachedZFar; /* ETC */ private boolean reflected; /** Applies the projection and modelview matrix. */ public void lookThrough() { loadProjectionMatrix(); loadModelViewMatrix(); } /** * Applies the projection and the normalized modelview matrix (positioned at the origin without * any offset like bobbing) . */ public void lookThroughNormalized() { loadProjectionMatrix(); loadNormalizedModelViewMatrix(); } public void updateFrustum() { if (getViewMatrix() == null || getProjectionMatrix() == null) { return; } viewFrustum.updateFrustum( MatrixUtils.matrixToFloatBuffer(viewMatrix), MatrixUtils.matrixToFloatBuffer(projectionMatrix)); viewFrustumReflected.updateFrustum( MatrixUtils.matrixToFloatBuffer(viewMatrixReflected), MatrixUtils.matrixToFloatBuffer(projectionMatrix)); } public abstract boolean isBobbingAllowed(); public abstract void loadProjectionMatrix(); public abstract void loadModelViewMatrix(); public abstract void loadNormalizedModelViewMatrix(); public abstract void updateMatrices(); public abstract void updateMatrices(float fov); public void update(float delta) { double diff = Math.abs(activeFov - targetFov); if (diff < 1.0) { activeFov = targetFov; return; } if (activeFov < targetFov) { activeFov += 50.0 * delta; if (activeFov >= targetFov) { activeFov = targetFov; } } else if (activeFov > targetFov) { activeFov -= 50.0 * delta; if (activeFov <= targetFov) { activeFov = targetFov; } } } public void extendFov(float fov) { targetFov = CoreRegistry.get(Config.class).getRendering().getFieldOfView() + fov; } public void resetFov() { targetFov = CoreRegistry.get(Config.class).getRendering().getFieldOfView(); } public void setReflected(boolean reflected) { this.reflected = reflected; } public void updatePrevViewProjectionMatrix() { prevViewProjectionMatrix.set(viewProjectionMatrix); } public float getClipHeight() { return 31.5f; } public Matrix4f getViewMatrix() { if (!reflected) { return viewMatrix; } return viewMatrixReflected; } public Matrix4f getNormViewMatrix() { if (!reflected) { return normViewMatrix; } return normViewMatrixReflected; } public Matrix4f getProjectionMatrix() { return projectionMatrix; } public Matrix4f getViewProjectionMatrix() { return viewProjectionMatrix; } public Matrix4f getInverseProjectionMatrix() { return inverseProjectionMatrix; } public Matrix4f getInverseViewProjectionMatrix() { return inverseViewProjectionMatrix; } public Matrix4f getPrevViewProjectionMatrix() { return prevViewProjectionMatrix; } public Vector3f getPosition() { return position; } public Vector3f getViewingDirection() { return viewingDirection; } public Vector3f getUp() { return up; } public ViewFrustum getViewFrustum() { return viewFrustum; } public ViewFrustum getViewFrustumReflected() { return viewFrustumReflected; } public float getzNear() { return zNear; } public void setzNear(float zNear) { this.zNear = zNear; } public float getzFar() { return zFar; } public void setzFar(float zFar) { this.zFar = zFar; } public boolean isReflected() { return reflected; } }
public void resetFov() { targetFov = CoreRegistry.get(Config.class).getRendering().getFieldOfView(); }
public void extendFov(float fov) { targetFov = CoreRegistry.get(Config.class).getRendering().getFieldOfView() + fov; }
/** * Sets the location in the physics engine. * * @param entity The entity to set the location of. * @param newPos The new position of the entity. */ private static void setPhysicsLocation(EntityRef entity, Vector3f newPos) { PhysicsEngine physics = CoreRegistry.get(PhysicsEngine.class); CharacterCollider collider = physics.getCharacterCollider(entity); collider.setLocation(newPos); }