Ça plane pour pasmoi.

This commit is contained in:
MarcEricMartel 2023-11-26 12:12:09 -05:00
parent ea3d2ffc34
commit 935216e9c3
4 changed files with 22 additions and 16 deletions

View File

@ -246,6 +246,8 @@ void Player::RemoveBooster(float elapsedtime)
}
void Player::SetDirection(Vector3f dir) { m_direction = dir; }
void Player::Move(Vector3f diff) { m_position -= diff; }
Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); }
Vector3f Player::GetPositionAbs() const { return m_position; }

View File

@ -25,6 +25,7 @@ public:
void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const;
void SetDirection(Vector3f dir);
void Move(Vector3f diff);
Vector3f GetPosition() const;
Vector3f GetPositionAbs() const;
Vector3f GetDirection() const;

View File

@ -75,11 +75,11 @@ void Connection::getPacks(SOCKET sock) {
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) {
while (!m_output_vector.empty()) {
std::cout << "c";
Output out = m_output_vector.front();
for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(false))
continue;
std::cout << "c";
sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr());
}
m_output_vector.pop_front();

View File

@ -400,8 +400,8 @@ void Engine::Init() {
for (auto& [key, player] : m_conn.m_players) {
m_players[key] = new RemotePlayer(player);
RemotePlayer* rt = (RemotePlayer*)m_players[key];
rt->SetPosition(Vector3f(555, 555, 555));
//RemotePlayer* rt = (RemotePlayer*)m_players[key];
m_players[key]->SetPosition(Vector3f(555, 555, 555));
}
seed = m_conn.getSeed();
@ -1244,20 +1244,14 @@ void Engine::Render(float elapsedTime) {
gameTime += elapsedTime * 10;
//Vector3f dance = Vector3f(sin(gameTime), 0, cos(-gameTime));
//dance.Normalize();
//m_remotePlayer.ApplyPhysics(dance, &m_world, elapsedTime);
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
//m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime);
//m_booster.RenderBillboard({ 195,16,195 }, m_textureAtlas, m_shader01, all);
if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
//glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime);
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
if (m_isSkybox) m_skybox.Render(skybox);
@ -1332,12 +1326,21 @@ void Engine::Render(float elapsedTime) {
if (Deserialize(&sync, pck, &bsize)) {
if (sync.sid != m_conn.getId())
break;
// TODO: Vérifier si les positions concordent au sync local.
if (m_syncs.contains(sync.timestamp)) {
Sync comp = m_syncs[sync.timestamp];
m_player.InflictDamage(sync.hp - comp.hp);
Vector3f diff = sync.position - comp.position;
if (diff.Length() > .5)
m_player.Move(diff);
// TODO: m_timer = sync.timer;
}
}
break;
case OUTPUT:
if (Deserialize(&out, pck, &bsize)) {
RemotePlayer* r = (RemotePlayer*)m_players[out.id];
RemotePlayer* r = m_players[out.id];
if (!r)
break;
r->Feed(out);
@ -1350,9 +1353,9 @@ void Engine::Render(float elapsedTime) {
lsPck.clear();
for (auto& [key, player] : m_players) {
RemotePlayer* rt = (RemotePlayer*)player;
rt->Render(m_animeAtlas, m_shader01, all, elapsedTime);
m_otherplayerpos = rt->GetPosition();
std::cout << key << ": "; player->GetPosition().Afficher();
player->Render(m_animeAtlas, m_shader01, all, elapsedTime);
m_otherplayerpos = player->GetPosition();
}
}