This commit is contained in:
MarcEricMartel
2023-12-13 15:04:08 -05:00
parent 5e09305398
commit a85c5cc626
5 changed files with 61 additions and 42 deletions

View File

@@ -77,8 +77,10 @@ void Connection::getPacks(SOCKET sock) {
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
static int outs = 0;
static Timestamp last = 0;
while (!m_output_vector.empty()) {
Output out = m_output_vector.front();
for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(false))
continue;
@@ -91,8 +93,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
outs += out.timestamp + last;
if (outs >= 50) {
outs -= 50;
if (outs >= SYNC_ACC) {
outs -= SYNC_ACC;
Sync sync;
sync.hp = player->GetHP();
sync.timestamp = out.timestamp;
@@ -114,27 +116,33 @@ Timestamp Connection::Run(World* world) {
Timestamp tstamp = 0;
float el;
bool dead = player->AmIDead();
if (m_input_manifest.size() < 2)
return tstamp;
while (m_last_in < m_input_vector.size() - 1) {
in = m_input_vector.at(m_last_in + 1);
last = m_input_vector.at(m_last_in);
if (in.timestamp <= m_tstamp) {
++m_last_in;
continue;
while (m_last_in < m_input_vector.size() - 1 || dead) {
if (!dead) {
in = m_input_vector.at(m_last_in + 1);
last = m_input_vector.at(m_last_in);
if (in.timestamp <= m_tstamp) {
++m_last_in;
continue;
}
el = (double)(in.timestamp - last.timestamp) / 1000.;
if (m_shoot_acc > 0.) {
m_shoot_acc -= el;
if (m_shoot_acc < 0.)
m_shoot_acc = 0.;
}
player->SetDirection(in.direction);
}
el = (double)(in.timestamp - last.timestamp) / 1000.;
if (m_shoot_acc > 0.) {
m_shoot_acc -= el;
if (m_shoot_acc < 0.)
m_shoot_acc = 0.;
else {
el = 1. / 60.;
in = Input();
}
player->SetDirection(in.direction);
player->ApplyPhysics(player->GetInput(in.keys.forward,
in.keys.backward,
in.keys.left,
@@ -147,7 +155,10 @@ Timestamp Connection::Run(World* world) {
}
out.states.jumping = player->GetIsAirborne();
out.states.running = player->GetVelocity().Length() > .2f;
Vector3f horSpeed = player->GetVelocity();
horSpeed.y = 0;
out.states.running = horSpeed.Length() > .2f;
out.states.still = !out.states.running && !out.states.jumping;
out.states.hit = player->m_hit;
player->m_hit = false;
@@ -192,7 +203,8 @@ Timestamp Connection::Run(World* world) {
m_output_vector.push_back(out);
m_tstamp = tstamp = out.timestamp;
++m_last_in;
if (!dead)
++m_last_in;
}
return tstamp;