|
@@ -6,6 +6,7 @@
|
|
#include "common/network/toserver/PlayerUpdatePacket.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/Random.h"
|
|
#include "utils/Utils.h"
|
|
#include "utils/Utils.h"
|
|
|
|
|
|
BlockRegistry Game::blockRegistry;
|
|
BlockRegistry Game::blockRegistry;
|
|
@@ -21,6 +22,9 @@ static State renderState;
|
|
static BaseGUI baseGUI;
|
|
static BaseGUI baseGUI;
|
|
static StartGUI startGUI;
|
|
static StartGUI startGUI;
|
|
|
|
|
|
|
|
+static List<PlayerUpdatePacket> delay;
|
|
|
|
+static Random rng;
|
|
|
|
+
|
|
static void tickConnectedState() {
|
|
static void tickConnectedState() {
|
|
Game::player.skip = false;
|
|
Game::player.skip = false;
|
|
Game::world.tick();
|
|
Game::world.tick();
|
|
@@ -51,10 +55,11 @@ static void tickConnectedState() {
|
|
if(force.squareLength() > 0.0f) {
|
|
if(force.squareLength() > 0.0f) {
|
|
force.normalize();
|
|
force.normalize();
|
|
}
|
|
}
|
|
- Game::player.addForce(force * 0.1f);
|
|
+ Game::player.addForce(force * Game::player.speed);
|
|
|
|
|
|
if(Game::controller.jump.isDown() && Game::player.isOnGround()) {
|
|
if(Game::controller.jump.isDown() && Game::player.isOnGround()) {
|
|
- Game::player.addForce(up * (0.42f / 0.98f + 0.08f));
|
|
+ Game::player.jump();
|
|
|
|
+
|
|
}
|
|
}
|
|
if(Game::controller.camLeft.isDown()) {
|
|
if(Game::controller.camLeft.isDown()) {
|
|
Game::player.addLengthAngle(-rotationSpeed);
|
|
Game::player.addLengthAngle(-rotationSpeed);
|
|
@@ -69,10 +74,21 @@ static void tickConnectedState() {
|
|
Game::player.addWidthAngle(rotationSpeed * 0.5f);
|
|
Game::player.addWidthAngle(rotationSpeed * 0.5f);
|
|
}
|
|
}
|
|
|
|
|
|
- PlayerUpdatePacket p(Game::player);
|
|
+ delay.add(PlayerUpdatePacket(Game::player));
|
|
- OutPacket out = OutPacket::sequenced(PlayerUpdatePacket::getSize());
|
|
+ if(rng.nextFloat() < 0.5f) {
|
|
- p.write(out);
|
|
+ OutPacket out = OutPacket::reliable(PlayerUpdatePacket::getSize());
|
|
- GameClient::send(out);
|
|
+ delay[0].write(out);
|
|
|
|
+ GameClient::send(out);
|
|
|
|
+ delay.remove(0);
|
|
|
|
+
|
|
|
|
+ if(delay.getLength() > 0) {
|
|
|
|
+ OutPacket out = OutPacket::reliable(PlayerUpdatePacket::getSize());
|
|
|
|
+ delay[0].write(out);
|
|
|
|
+ GameClient::send(out);
|
|
|
|
+ delay.remove(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ LOG_DEBUG(delay.getLength());
|
|
}
|
|
}
|
|
|
|
|
|
static void renderConnectedState() {
|
|
static void renderConnectedState() {
|
|
@@ -138,4 +154,6 @@ void Game::renderOverlay() {
|
|
void Game::onEntityUpdate(EntityUpdatePacket& p) {
|
|
void Game::onEntityUpdate(EntityUpdatePacket& p) {
|
|
LOG_DEBUG("set");
|
|
LOG_DEBUG("set");
|
|
player.setPosition(p.position);
|
|
player.setPosition(p.position);
|
|
|
|
+ player.velocity = p.velocity;
|
|
|
|
+ delay.clear();
|
|
}
|
|
}
|