|
@@ -3,7 +3,7 @@
|
|
#include "client/gui/StartGUI.h"
|
|
#include "client/gui/StartGUI.h"
|
|
#include "client/rendering/Engine.h"
|
|
#include "client/rendering/Engine.h"
|
|
#include "common/network/Packets.h"
|
|
#include "common/network/Packets.h"
|
|
-#include "common/network/toserver/ControllerPacket.h"
|
|
|
|
|
|
+#include "common/network/toserver/PlayerUpdatePacket.h"
|
|
#include "rendering/renderer/WorldRenderer.h"
|
|
#include "rendering/renderer/WorldRenderer.h"
|
|
#include "utils/Logger.h"
|
|
#include "utils/Logger.h"
|
|
#include "utils/Utils.h"
|
|
#include "utils/Utils.h"
|
|
@@ -35,23 +35,17 @@ static void tickConnectedState() {
|
|
Vector3 right = back.cross(up);
|
|
Vector3 right = back.cross(up);
|
|
|
|
|
|
constexpr float rotationSpeed = 4.0f;
|
|
constexpr float rotationSpeed = 4.0f;
|
|
- ControllerPacket cp;
|
|
|
|
-
|
|
|
|
Vector3 force;
|
|
Vector3 force;
|
|
if(Game::controller.down.isDown()) {
|
|
if(Game::controller.down.isDown()) {
|
|
- cp.set(ControllerPacket::Type::DOWN);
|
|
|
|
force += back;
|
|
force += back;
|
|
}
|
|
}
|
|
if(Game::controller.up.isDown()) {
|
|
if(Game::controller.up.isDown()) {
|
|
- cp.set(ControllerPacket::Type::UP);
|
|
|
|
force -= back;
|
|
force -= back;
|
|
}
|
|
}
|
|
if(Game::controller.left.isDown()) {
|
|
if(Game::controller.left.isDown()) {
|
|
- cp.set(ControllerPacket::Type::LEFT);
|
|
|
|
force -= right;
|
|
force -= right;
|
|
}
|
|
}
|
|
if(Game::controller.right.isDown()) {
|
|
if(Game::controller.right.isDown()) {
|
|
- cp.set(ControllerPacket::Type::RIGHT);
|
|
|
|
force += right;
|
|
force += right;
|
|
}
|
|
}
|
|
if(force.squareLength() > 0.0f) {
|
|
if(force.squareLength() > 0.0f) {
|
|
@@ -60,30 +54,24 @@ static void tickConnectedState() {
|
|
Game::player.addForce(force * 0.1f);
|
|
Game::player.addForce(force * 0.1f);
|
|
|
|
|
|
if(Game::controller.jump.isDown() && Game::player.isOnGround()) {
|
|
if(Game::controller.jump.isDown() && Game::player.isOnGround()) {
|
|
- cp.set(ControllerPacket::Type::JUMP);
|
|
|
|
Game::player.addForce(up * (0.42f / 0.98f + 0.08f));
|
|
Game::player.addForce(up * (0.42f / 0.98f + 0.08f));
|
|
}
|
|
}
|
|
- if(Game::controller.sneak.isDown()) {
|
|
|
|
- cp.set(ControllerPacket::Type::SNEAK);
|
|
|
|
- }
|
|
|
|
if(Game::controller.camLeft.isDown()) {
|
|
if(Game::controller.camLeft.isDown()) {
|
|
- cp.set(ControllerPacket::Type::CAM_LEFT);
|
|
|
|
Game::player.addLengthAngle(-rotationSpeed);
|
|
Game::player.addLengthAngle(-rotationSpeed);
|
|
}
|
|
}
|
|
if(Game::controller.camRight.isDown()) {
|
|
if(Game::controller.camRight.isDown()) {
|
|
- cp.set(ControllerPacket::Type::CAM_RIGHT);
|
|
|
|
Game::player.addLengthAngle(rotationSpeed);
|
|
Game::player.addLengthAngle(rotationSpeed);
|
|
}
|
|
}
|
|
if(Game::controller.camUp.isDown()) {
|
|
if(Game::controller.camUp.isDown()) {
|
|
- cp.set(ControllerPacket::Type::CAM_UP);
|
|
|
|
Game::player.addWidthAngle(-rotationSpeed * 0.5f);
|
|
Game::player.addWidthAngle(-rotationSpeed * 0.5f);
|
|
}
|
|
}
|
|
if(Game::controller.camDown.isDown()) {
|
|
if(Game::controller.camDown.isDown()) {
|
|
- cp.set(ControllerPacket::Type::CAM_DOWN);
|
|
|
|
Game::player.addWidthAngle(rotationSpeed * 0.5f);
|
|
Game::player.addWidthAngle(rotationSpeed * 0.5f);
|
|
}
|
|
}
|
|
- OutPacket out = OutPacket::reliable(ControllerPacket::getSize());
|
|
|
|
- cp.write(out);
|
|
|
|
|
|
+
|
|
|
|
+ PlayerUpdatePacket p(Game::player);
|
|
|
|
+ OutPacket out = OutPacket::sequenced(PlayerUpdatePacket::getSize());
|
|
|
|
+ p.write(out);
|
|
GameClient::send(out);
|
|
GameClient::send(out);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -148,13 +136,6 @@ void Game::renderOverlay() {
|
|
}
|
|
}
|
|
|
|
|
|
void Game::onEntityUpdate(EntityUpdatePacket& p) {
|
|
void Game::onEntityUpdate(EntityUpdatePacket& p) {
|
|
- float distance = (p.position - player.position).squareLength();
|
|
|
|
- LOG_DEBUG(StringBuffer<50>(distance));
|
|
|
|
- if(distance > 25.0f) {
|
|
|
|
- LOG_DEBUG("set");
|
|
|
|
- player.setPosition(p.position);
|
|
|
|
- }
|
|
|
|
- // player.position = p.position;
|
|
|
|
- // player.lengthAngle = p.lengthAngle;
|
|
|
|
- // player.widthAngle = p.widthAngle;
|
|
|
|
|
|
+ LOG_DEBUG("set");
|
|
|
|
+ player.setPosition(p.position);
|
|
}
|
|
}
|