Before the merge....
This commit is contained in:
parent
4841e8d5ba
commit
988b2c330c
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection(SOCKET sock,
|
Connection::Connection(SOCKET sock,
|
||||||
sockaddr_in sockaddr,
|
sockaddr_in sockaddr,
|
||||||
LoginInfo log,
|
LoginInfo log,
|
||||||
PlayerInfo play):
|
PlayerInfo play) :
|
||||||
m_sock(sock),
|
m_sock(sock),
|
||||||
m_addr(sockaddr),
|
m_addr(sockaddr),
|
||||||
m_loginfo(log),
|
m_loginfo(log),
|
||||||
m_playinfo(play) {
|
m_playinfo(play) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection::~Connection() { closesocket(m_sock); }
|
Connection::~Connection() { closesocket(m_sock); }
|
||||||
|
|
||||||
uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
|
uint64_t Connection::GetHash(bool self) const { return self ? m_loginfo.sid : m_playinfo.id; }
|
||||||
|
|
||||||
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
|
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
|
||||||
|
|
||||||
@ -51,25 +51,25 @@ void Connection::getPacks(SOCKET sock) {
|
|||||||
std::vector<char*> lsPck;
|
std::vector<char*> lsPck;
|
||||||
Input in;
|
Input in;
|
||||||
Sync sync;
|
Sync sync;
|
||||||
lsPck = recvPacksFrom(sock, &m_buf, m_addr);
|
lsPck = recvPacksFrom(sock, &m_buf, m_addr);
|
||||||
for (auto& pck : lsPck) {
|
for (auto& pck : lsPck) {
|
||||||
uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
|
uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
|
||||||
switch (netprot::getType(pck, 1)) {
|
switch (netprot::getType(pck, 1)) {
|
||||||
using enum netprot::PACKET_TYPE;
|
using enum netprot::PACKET_TYPE;
|
||||||
case INPUT:
|
case INPUT:
|
||||||
if (Deserialize(&in, pck, &bsize)) {
|
if (Deserialize(&in, pck, &bsize)) {
|
||||||
m_input_manifest[in.timestamp] = in;
|
m_input_manifest[in.timestamp] = in;
|
||||||
m_input_vector.push_back(in);
|
m_input_vector.push_back(in);
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SYNC:
|
|
||||||
if (Deserialize(&sync, pck, &bsize))
|
|
||||||
m_nsync = true;
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case SYNC:
|
||||||
|
if (Deserialize(&sync, pck, &bsize))
|
||||||
|
m_nsync = true;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
lsPck.clear();
|
}
|
||||||
|
lsPck.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
||||||
@ -131,12 +131,12 @@ Timestamp Connection::Run(World* world) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player->SetDirection(in.direction);
|
player->SetDirection(in.direction);
|
||||||
player->ApplyPhysics(player->GetInput(in.keys.forward,
|
player->ApplyPhysics(player->GetInput(in.keys.forward,
|
||||||
in.keys.backward,
|
in.keys.backward,
|
||||||
in.keys.left,
|
in.keys.left,
|
||||||
in.keys.right,
|
in.keys.right,
|
||||||
in.keys.jump, false, el), world, el);
|
in.keys.jump, false, el), world, el);
|
||||||
|
|
||||||
if (player->GetPosition().y < -10.) {
|
if (player->GetPosition().y < -10.) {
|
||||||
player->InflictDamage(9000);
|
player->InflictDamage(9000);
|
||||||
player->Killer = GetHash(true);
|
player->Killer = GetHash(true);
|
||||||
@ -144,28 +144,34 @@ Timestamp Connection::Run(World* world) {
|
|||||||
|
|
||||||
out.states.jumping = in.keys.jump;
|
out.states.jumping = in.keys.jump;
|
||||||
out.states.running = player->GetVelocity().Length() > .3f;
|
out.states.running = player->GetVelocity().Length() > .3f;
|
||||||
|
|
||||||
if (player->AmIDead()) {
|
if (player->AmIDead()) {
|
||||||
in.keys.shoot = false;
|
in.keys.shoot = false;
|
||||||
in.keys.block = false;
|
in.keys.block = false;
|
||||||
out.states.dead = true;
|
out.states.dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool toggle = false;
|
||||||
if (in.keys.block) {
|
if (in.keys.block) {
|
||||||
bool block = false;
|
if (!toggle) {
|
||||||
ChunkMod* cmod = world->ChangeBlockAtCursor(BLOCK_TYPE::BTYPE_METAL,
|
toggle = true;
|
||||||
player->GetPosition(),
|
bool block = false;
|
||||||
player->GetDirection(),
|
ChunkMod* cmod = world->ChangeBlockAtCursor(BLOCK_TYPE::BTYPE_METAL,
|
||||||
block, true);
|
player->GetPosition(),
|
||||||
if (cmod)
|
player->GetDirection(),
|
||||||
ChunkDiffs.emplace_back(cmod);
|
block, true);
|
||||||
|
if (cmod)
|
||||||
|
ChunkDiffs.emplace_back(cmod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else toggle = false;
|
||||||
|
|
||||||
if (in.keys.shoot && m_shoot_acc <= 0.) {
|
if (in.keys.shoot && m_shoot_acc <= 0.) {
|
||||||
Bullets.emplace_back(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true)));
|
Bullets.emplace_back(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true)));
|
||||||
out.states.shooting = true;
|
out.states.shooting = true;
|
||||||
|
m_shoot_acc = BULLET_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.position = player->GetPositionAbs();
|
out.position = player->GetPositionAbs();
|
||||||
out.direction = in.direction;
|
out.direction = in.direction;
|
||||||
out.timestamp = in.timestamp;
|
out.timestamp = in.timestamp;
|
||||||
@ -173,7 +179,7 @@ Timestamp Connection::Run(World* world) {
|
|||||||
m_output_manifest[out.timestamp] = out;
|
m_output_manifest[out.timestamp] = out;
|
||||||
m_output_vector.push_back(out);
|
m_output_vector.push_back(out);
|
||||||
tstamp = out.timestamp;
|
tstamp = out.timestamp;
|
||||||
|
|
||||||
++m_last_in;
|
++m_last_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +187,10 @@ Timestamp Connection::Run(World* world) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Connection::CleanInputManifest(Timestamp time) {
|
void Connection::CleanInputManifest(Timestamp time) {
|
||||||
// auto wat = m_input_manifest.find(time);
|
// auto wat = m_input_manifest.find(time);
|
||||||
|
|
||||||
// while (wat != m_input_manifest.begin())
|
// while (wat != m_input_manifest.begin())
|
||||||
// m_input_manifest.erase(wat--);
|
// m_input_manifest.erase(wat--);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timestamp Connection::GetTStamp() const { return m_tstamp; }
|
Timestamp Connection::GetTStamp() const { return m_tstamp; }
|
||||||
|
@ -1267,20 +1267,17 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
m_player.ApplyTransformation(remotePlayer, true, false);
|
m_player.ApplyTransformation(remotePlayer, true, false);
|
||||||
|
|
||||||
if (m_key1) bloc++;
|
//if (m_key1) bloc++;
|
||||||
else if (m_key2) bloc--;
|
//else if (m_key2) bloc--;
|
||||||
|
|
||||||
if (m_mouseWU) bloc++;
|
//if (m_mouseWU) bloc++;
|
||||||
else if (m_mouseWD) bloc--;
|
//else if (m_mouseWD) bloc--;
|
||||||
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
|
//if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
|
||||||
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
|
//else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
|
||||||
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
|
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
|
||||||
netprot::ChunkMod* cmod = nullptr;
|
netprot::ChunkMod* cmod = nullptr;
|
||||||
|
|
||||||
if (m_mouseL) {
|
if (m_mouseL) {
|
||||||
if (bloc != BTYPE_LAST)
|
if (bulletTime <= 0.f) {
|
||||||
cmod = m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
|
|
||||||
else if (bulletTime <= 0.f) {
|
|
||||||
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||||
if (!m_bullets[x]) {
|
if (!m_bullets[x]) {
|
||||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||||
@ -1301,7 +1298,35 @@ void Engine::Render(float elapsedTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_mouseR)
|
else if (m_mouseR)
|
||||||
cmod = m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
|
cmod = m_world.ChangeBlockAtCursor(BTYPE_METAL, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//if (m_mouseL) {
|
||||||
|
// if (bloc != BTYPE_LAST)
|
||||||
|
// cmod = m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
|
||||||
|
// else if (bulletTime <= 0.f) {
|
||||||
|
// for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||||
|
// if (!m_bullets[x]) {
|
||||||
|
// m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
|
||||||
|
// m_bullets[0]->~Bullet();
|
||||||
|
// m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||||
|
// }
|
||||||
|
// bulletTime = BULLET_TIME;
|
||||||
|
// m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
|
||||||
|
// if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
|
||||||
|
// glClearColor(.8f, .8f, .8f, 1.f);
|
||||||
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
// glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//else if (m_mouseR)
|
||||||
|
// cmod = m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
|
||||||
|
|
||||||
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
||||||
if (m_bullets[x]) {
|
if (m_bullets[x]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user