mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
Add a Frames per second counter
This commit is contained in:
parent
9fcbe27046
commit
4f26204355
@ -526,7 +526,7 @@ public class PacketHandler {
|
|||||||
}
|
}
|
||||||
connection.getPlayer().setSpawnConfirmed(true);
|
connection.getPlayer().setSpawnConfirmed(true);
|
||||||
connection.getRenderProperties().getController().getCameraMovement().setRotation(pkg.getRotation());
|
connection.getRenderProperties().getController().getCameraMovement().setRotation(pkg.getRotation());
|
||||||
connection.getRenderProperties().getController().setPlayerPos(new Vec3(pkg.getLocation()));
|
connection.getRenderProperties().getController().setPlayerPosition(new Vec3(pkg.getLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(PacketAttachEntity pkg) {
|
public void handle(PacketAttachEntity pkg) {
|
||||||
|
@ -74,7 +74,7 @@ public class OpenGLWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (MemoryStack stack = stackPush()) {
|
try (MemoryStack stack = stackPush()) {
|
||||||
IntBuffer pWidth = stack.mallocInt(1);
|
IntBuffer pWidth = stack.mallocInt(1);
|
||||||
IntBuffer pHeight = stack.mallocInt(1);
|
IntBuffer pHeight = stack.mallocInt(1);
|
||||||
|
|
||||||
glfwGetWindowSize(windowId, pWidth, pHeight);
|
glfwGetWindowSize(windowId, pWidth, pHeight);
|
||||||
@ -173,6 +173,8 @@ public class OpenGLWindow {
|
|||||||
lastFrame = currentFrame;
|
lastFrame = currentFrame;
|
||||||
|
|
||||||
setupPerspective();
|
setupPerspective();
|
||||||
|
|
||||||
|
glfwSetWindowTitle(windowId, String.format("Minosoft game window (%s FPS)", 1/deltaTime));
|
||||||
return deltaTime;
|
return deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping;
|
|||||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||||
import de.bixilon.minosoft.data.world.World;
|
import de.bixilon.minosoft.data.world.World;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
|
||||||
import de.bixilon.minosoft.render.utility.AdditionalMath;
|
import de.bixilon.minosoft.render.utility.AdditionalMath;
|
||||||
import de.bixilon.minosoft.render.utility.Vec3;
|
import de.bixilon.minosoft.render.utility.Vec3;
|
||||||
|
|
||||||
@ -33,42 +32,42 @@ public class CollisionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleCollisions() {
|
public void handleCollisions() {
|
||||||
if (isPositionValid(controller.playerPos)) {
|
if (isPositionValid(controller.playerPosition)) {
|
||||||
// the player currently isn't colliding with with anything so the player Position does not have to be adjusted
|
// the player currently isn't colliding with with anything so the player Position does not have to be adjusted
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xAxisCollision();
|
xAxisCollision();
|
||||||
yAxisCollision();
|
yAxisCollision();
|
||||||
zAxisCollision();
|
zAxisCollision();
|
||||||
if (!isPositionValid(controller.playerPos)) {
|
if (!isPositionValid(controller.playerPosition)) {
|
||||||
controller.playerPos.x = controller.oldPos.x;
|
controller.playerPosition.x = controller.oldPosition.x;
|
||||||
controller.playerPos.z = controller.oldPos.z;
|
controller.playerPosition.z = controller.oldPosition.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void xAxisCollision() {
|
private void xAxisCollision() {
|
||||||
double deltaX = controller.playerPos.x - controller.oldPos.x;
|
double deltaX = controller.playerPosition.x - controller.oldPosition.x;
|
||||||
if (deltaX == 0) {
|
if (deltaX == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vec3 testPos = controller.oldPos.copy().add(deltaX, 0, 0);
|
Vec3 testPos = controller.oldPosition.copy().add(deltaX, 0, 0);
|
||||||
if (isPositionValid(testPos)) {
|
if (isPositionValid(testPos)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.playerPos.x = controller.oldPos.x;
|
controller.playerPosition.x = controller.oldPosition.x;
|
||||||
controller.playerVelocity.x = 0;
|
controller.playerVelocity.x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void yAxisCollision() {
|
private void yAxisCollision() {
|
||||||
double deltaY = controller.playerPos.y - controller.oldPos.y;
|
double deltaY = controller.playerPosition.y - controller.oldPosition.y;
|
||||||
if (deltaY == 0) {
|
if (deltaY == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vec3 testPos = controller.oldPos.copy().add(0, deltaY, 0);
|
Vec3 testPos = controller.oldPosition.copy().add(0, deltaY, 0);
|
||||||
if (isPositionValid(testPos)) {
|
if (isPositionValid(testPos)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.playerPos.y = controller.oldPos.y;
|
controller.playerPosition.y = controller.oldPosition.y;
|
||||||
controller.playerVelocity.y = 0;
|
controller.playerVelocity.y = 0;
|
||||||
|
|
||||||
if (deltaY < 0) {
|
if (deltaY < 0) {
|
||||||
@ -77,15 +76,15 @@ public class CollisionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void zAxisCollision() {
|
private void zAxisCollision() {
|
||||||
double deltaZ = controller.playerPos.z - controller.oldPos.z;
|
double deltaZ = controller.playerPosition.z - controller.oldPosition.z;
|
||||||
if (deltaZ == 0) {
|
if (deltaZ == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vec3 testPos = controller.oldPos.copy().add(0, 0, deltaZ);
|
Vec3 testPos = controller.oldPosition.copy().add(0, 0, deltaZ);
|
||||||
if (isPositionValid(testPos)) {
|
if (isPositionValid(testPos)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.playerPos.z = controller.oldPos.z;
|
controller.playerPosition.z = controller.oldPosition.z;
|
||||||
controller.playerVelocity.z = 0;
|
controller.playerVelocity.z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ public class PlayerController {
|
|||||||
private static final float gravity = 13;
|
private static final float gravity = 13;
|
||||||
|
|
||||||
private final Connection connection;
|
private final Connection connection;
|
||||||
public Vec3 oldPos;
|
public Vec3 oldPosition;
|
||||||
CameraMovement cameraMovement;
|
CameraMovement cameraMovement;
|
||||||
PlayerMovement playerMovement;
|
PlayerMovement playerMovement;
|
||||||
Vec3 playerPos = new Vec3(); // the feet position of the player
|
Vec3 playerPosition = new Vec3(); // the feet position of the player
|
||||||
Vec3 playerVelocity = new Vec3();
|
Vec3 playerVelocity = new Vec3();
|
||||||
private boolean onGround;
|
private boolean onGround;
|
||||||
private boolean enableGravity;
|
private boolean enableGravity;
|
||||||
@ -51,10 +51,10 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
if (GameWindow.paused) {
|
if (GameWindow.paused) {
|
||||||
cameraMovement.loop();
|
cameraMovement.loop();
|
||||||
glTranslated(-playerPos.x, -(playerPos.y + playerHeight - 0.2f), -playerPos.z);
|
glTranslated(-playerPosition.x, -(playerPosition.y + playerHeight - 0.2f), -playerPosition.z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
oldPos = playerPos.copy();
|
oldPosition = playerPosition.copy();
|
||||||
|
|
||||||
GameModes gameMode = connection.getPlayer().getGameMode();
|
GameModes gameMode = connection.getPlayer().getGameMode();
|
||||||
enableGravity = gameMode != GameModes.CREATIVE && gameMode != GameModes.SPECTATOR;
|
enableGravity = gameMode != GameModes.CREATIVE && gameMode != GameModes.SPECTATOR;
|
||||||
@ -64,12 +64,12 @@ public class PlayerController {
|
|||||||
applyVelocity(deltaTime);
|
applyVelocity(deltaTime);
|
||||||
|
|
||||||
if (gameMode == GameModes.SPECTATOR) {
|
if (gameMode == GameModes.SPECTATOR) {
|
||||||
glTranslated(-playerPos.x, -(playerPos.y + playerHeight - 0.2f), -playerPos.z);
|
glTranslated(-playerPosition.x, -(playerPosition.y + playerHeight - 0.2f), -playerPosition.z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleCollisions(connection.getPlayer().getWorld());
|
handleCollisions(connection.getPlayer().getWorld());
|
||||||
|
|
||||||
glTranslated(-playerPos.x, -(playerPos.y + playerHeight - 0.2f), -playerPos.z);
|
glTranslated(-playerPosition.x, -(playerPosition.y + playerHeight - 0.2f), -playerPosition.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCollisions(World world) {
|
private void handleCollisions(World world) {
|
||||||
@ -85,16 +85,12 @@ public class PlayerController {
|
|||||||
return enableGravity;
|
return enableGravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 getPlayerPos() {
|
public Vec3 getPlayerPosition() {
|
||||||
return playerPos;
|
return playerPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerPos(Vec3 playerPos) {
|
public void setPlayerPosition(Vec3 playerPosition) {
|
||||||
this.playerPos = playerPos;
|
this.playerPosition = playerPosition;
|
||||||
}
|
|
||||||
|
|
||||||
private void applyVelocity(float deltaTime) {
|
|
||||||
playerPos.add(Vec3.mul(playerVelocity, deltaTime));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGravity(float deltaTime) {
|
private void handleGravity(float deltaTime) {
|
||||||
@ -129,4 +125,8 @@ public class PlayerController {
|
|||||||
public float getPlayerHeight() {
|
public float getPlayerHeight() {
|
||||||
return playerHeight;
|
return playerHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyVelocity(float deltaTime) {
|
||||||
|
playerPosition.add(Vec3.mul(playerVelocity, deltaTime));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class PlayerMovement {
|
|||||||
private final Connection connection;
|
private final Connection connection;
|
||||||
|
|
||||||
private Vec3 cameraFront;
|
private Vec3 cameraFront;
|
||||||
private Vec3 playerPos;
|
private Vec3 playerPosition;
|
||||||
|
|
||||||
public PlayerMovement(Connection connection) {
|
public PlayerMovement(Connection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
@ -35,26 +35,26 @@ public class PlayerMovement {
|
|||||||
float cameraSpeed = FLY_SPEED / deltaTime;
|
float cameraSpeed = FLY_SPEED / deltaTime;
|
||||||
|
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_W) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_W) == GLFW_PRESS) {
|
||||||
playerPos.add(Vec3.mul(cameraFront, -cameraSpeed * deltaTime));
|
playerPosition.add(Vec3.mul(cameraFront, -cameraSpeed * deltaTime));
|
||||||
}
|
}
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_S) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_S) == GLFW_PRESS) {
|
||||||
playerPos.add(Vec3.mul(cameraFront, cameraSpeed * deltaTime));
|
playerPosition.add(Vec3.mul(cameraFront, cameraSpeed * deltaTime));
|
||||||
}
|
}
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_A) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_A) == GLFW_PRESS) {
|
||||||
playerPos.add(Vec3.mul(Vec3.cross(CAMERA_UP, cameraFront), -cameraSpeed * deltaTime));
|
playerPosition.add(Vec3.mul(Vec3.cross(CAMERA_UP, cameraFront), -cameraSpeed * deltaTime));
|
||||||
}
|
}
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_D) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_D) == GLFW_PRESS) {
|
||||||
playerPos.add(Vec3.mul(Vec3.cross(CAMERA_UP, cameraFront), cameraSpeed * deltaTime));
|
playerPosition.add(Vec3.mul(Vec3.cross(CAMERA_UP, cameraFront), cameraSpeed * deltaTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
|
||||||
if (!connection.getRenderProperties().getController().isGravityEnabled()) {
|
if (!connection.getRenderProperties().getController().isGravityEnabled()) {
|
||||||
playerPos.add(0, -cameraSpeed * deltaTime, 0);
|
playerPosition.add(0, -cameraSpeed * deltaTime, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_SPACE) == GLFW_PRESS) {
|
if (glfwGetKey(GameWindow.getOpenGLWindow().getWindowId(), GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||||
if (!connection.getRenderProperties().getController().isGravityEnabled()) {
|
if (!connection.getRenderProperties().getController().isGravityEnabled()) {
|
||||||
playerPos.add(0, cameraSpeed * deltaTime, 0);
|
playerPosition.add(0, cameraSpeed * deltaTime, 0);
|
||||||
}
|
}
|
||||||
if (connection.getRenderProperties().getController().isOnGround()) {
|
if (connection.getRenderProperties().getController().isOnGround()) {
|
||||||
connection.getRenderProperties().getController().jump();
|
connection.getRenderProperties().getController().jump();
|
||||||
@ -64,7 +64,11 @@ public class PlayerMovement {
|
|||||||
|
|
||||||
public void loop(float deltaTime) {
|
public void loop(float deltaTime) {
|
||||||
cameraFront = connection.getRenderProperties().getController().getCameraMovement().getCameraFront();
|
cameraFront = connection.getRenderProperties().getController().getCameraMovement().getCameraFront();
|
||||||
playerPos = connection.getRenderProperties().getController().getPlayerPos();
|
playerPosition = connection.getRenderProperties().getController().getPlayerPosition();
|
||||||
processInput(deltaTime);
|
processInput(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPlayerPosition(Vec3 playerPosition) {
|
||||||
|
this.playerPosition = playerPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user