🔫
This commit is contained in:
@@ -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;
|
||||
|
@@ -217,7 +217,7 @@ void Server::Run() {
|
||||
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
|
||||
}
|
||||
|
||||
int timer = m_game.countdown, sync_acc = 0, deadplayers = 0;
|
||||
int timer = m_game.countdown, timer_acc = 0, deadplayers = 0;
|
||||
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
|
||||
Timestamp last = 0;
|
||||
std::vector<Chat*> chatlog;
|
||||
@@ -241,10 +241,10 @@ void Server::Run() {
|
||||
|
||||
if (last == 0)
|
||||
last = tstamp;
|
||||
sync_acc += tstamp - last;
|
||||
if (sync_acc >= SYNC_ACC) {
|
||||
while (sync_acc >= SYNC_ACC)
|
||||
sync_acc -= SYNC_ACC;
|
||||
timer_acc += tstamp - last;
|
||||
if (timer_acc >= 1000) {
|
||||
while (timer_acc >= 1000)
|
||||
timer_acc -= 1000;
|
||||
--timer;
|
||||
std::string str = "Timer: ";
|
||||
Log(str.append(std::to_string(timer)), false, false);
|
||||
@@ -280,22 +280,26 @@ void Server::Run() {
|
||||
/* Process */
|
||||
|
||||
if (conn->m_nsync) {
|
||||
if (conn->player->AmIDead())
|
||||
conn->m_nsync = false;
|
||||
|
||||
Timestamp tstamp = conn->Run(m_world);
|
||||
|
||||
if (conn->player->AmIDead()) {
|
||||
if (conn->player->AmIDead() && !conn->player->Eulogy) {
|
||||
Chat* chat = new Chat();
|
||||
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
||||
|
||||
std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
|
||||
Player* murderer = m_conns.at(conn->player->Killer)->player;
|
||||
|
||||
murderer->addPoint();
|
||||
|
||||
std::string killer = murderer->GetUsername();
|
||||
|
||||
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
|
||||
|
||||
strcpy(chat->mess, 140, mess.c_str());
|
||||
chatlog.emplace_back(chat);
|
||||
++deadplayers;
|
||||
|
||||
conn->player->Eulogy = true;
|
||||
}
|
||||
else {
|
||||
for (auto& chmo : conn->ChunkDiffs)
|
||||
@@ -367,8 +371,7 @@ void Server::Run() {
|
||||
|
||||
for (auto& [key, conn] : m_conns) {
|
||||
std::string str = conn->player->GetUsername();
|
||||
Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false);
|
||||
|
||||
Log(str.append(" ").append(std::to_string(conn->player->getScore())), false, false);
|
||||
}
|
||||
|
||||
for (auto& [key, conn] : m_conns)
|
||||
|
Reference in New Issue
Block a user