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

@ -12,7 +12,7 @@ Bullet::~Bullet() {}
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
int max = 100 / perframe;
float damage = 0.057f;
float damage = 0.098f;
for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime;
@ -40,15 +40,17 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
if (!world->ChunkAt(m_currentpos))
return true;
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
if (chunkmod) {
using namespace netprot;
*chunkmod = new ChunkMod();
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
(*chunkmod)->b_type = BTYPE_AIR;
(*chunkmod)->pos = m_currentpos;
}
if (m_canhurt) {
if (chunkmod) {
using namespace netprot;
*chunkmod = new ChunkMod();
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
(*chunkmod)->b_type = BTYPE_AIR;
(*chunkmod)->pos = m_currentpos;
}
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
}
return true;
}
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;

View File

@ -37,8 +37,8 @@
#define STRENGTH_SPEED_BOOST 10 //Pourcentage
#define BULLET_TIME .1
#define SYNC_ACC 200
#define CMOD_ACC 1500
#define SYNC_ACC 200 // ms
#define CMOD_ACC 1500 // ms
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };

View File

@ -45,6 +45,8 @@ public:
std::string m_username;
bool m_hit = false;
bool Eulogy = false;
private:
uint64_t getId() const;

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;

View File

@ -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)