🚫 👂 🐆

This commit is contained in:
MarcEricMartel
2023-12-09 12:02:04 -05:00
parent 63d70be488
commit 9aaad6426c
11 changed files with 130 additions and 74 deletions

View File

@@ -65,7 +65,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
netprot::Buffer bf;
netprot::LoginInfo log;
strcpy(log.name, name.c_str());
strcpy(log.name, 32, name.c_str());
netprot::sendPack(m_sock_tcp, &log, &bf);

View File

@@ -18,7 +18,7 @@ struct Notification {
// Use a vector to manage notifications
std::vector<Notification> notifications;
Engine::Engine() : m_remotePlayer(&m_pinfo), m_pinfo() {}
Engine::Engine() {}
Engine::~Engine() {
m_world.CleanUpWorld(m_renderCount, true);
@@ -103,7 +103,7 @@ void Engine::Init() {
m_world.SetSeed(seed);
m_startTime = std::chrono::high_resolution_clock::now();
m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5));
// Gestion de souris.
CenterMouse();
HideCursor();
@@ -1258,7 +1258,7 @@ void Engine::Render(float elapsedTime) {
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
netprot::ChunkMod* cmod = nullptr;
if (m_mouseL) {
if (!m_player.AmIDead() && m_mouseL) {
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]) {
@@ -1282,14 +1282,20 @@ void Engine::Render(float elapsedTime) {
else if (m_mouseR)
cmod = m_world.ChangeBlockAtCursor(BTYPE_METAL, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame);
static netprot::ChunkMod** wat = &m_chunkmod;
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
if (m_bullets[x]) {
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players, m_networkgame ? &m_chunkmod : nullptr)) {
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players, m_networkgame ? wat : nullptr)) {
m_bullets[x]->~Bullet();
if (m_chunkmod) {
m_chunkmod_manifest.push_back(std::move(m_chunkmod));
m_chunkmod = nullptr;
}
m_bullets[x] = nullptr;
//if (m_whoosh[x])
// m_whoosh[x]->drop();
//m_bullets[x] = nullptr;
//m_whoosh[x] = nullptr;
break;
}
@@ -1324,7 +1330,7 @@ void Engine::Render(float elapsedTime) {
std::string user = m_player.m_username.append(" (Dead)");
m_player = Player(Vector3f(.5, CHUNK_SIZE_Y + 1.7f, .5), 0, 0);
m_player.m_username = user;
m_player.InflictDamage(-m_player.GetHP());
}
m_time += elapsedTime;
@@ -1349,6 +1355,7 @@ void Engine::Render(float elapsedTime) {
sync_acc += tstamp - last;
cmod_acc += tstamp - last;
last = tstamp;
if (sync_acc >= 1000) {
sync_acc -= 1000;
@@ -1363,9 +1370,9 @@ void Engine::Render(float elapsedTime) {
m_syncs[sync.timestamp] = sync;
}
if (cmod_acc >= 1000) {
while (cmod_acc >= 1000)
cmod_acc -= 1000;
if (cmod_acc >= 3000) {
while (cmod_acc >= 3000)
cmod_acc -= 3000;
if (!m_chunkmod_manifest.empty()) {
ChunkMod* cmod = m_chunkmod_manifest.front();
m_chunkmod_manifest.pop_front();
@@ -1389,8 +1396,9 @@ void Engine::Render(float elapsedTime) {
recvPacks(m_conn.m_sock_udp, &m_buf, &lsPck);
char* prevptr = nullptr;
Chat chat;
for (auto& pck : lsPck) { // We could make a few threads out of this.
Sync sync; Output out; ChunkMod cmod; BulletAdd bull; Chat chat;
Sync sync; Output out; ChunkMod cmod; BulletAdd bull;
if (!prevptr)
prevptr = m_buf.ptr;
uint32_t bsize = m_buf.len - (pck - prevptr);
@@ -1406,7 +1414,9 @@ void Engine::Render(float elapsedTime) {
if (m_syncs.count(sync.timestamp)) {
Sync comp = m_syncs[sync.timestamp];
//m_player.InflictDamage(sync.hp - comp.hp);
std::cout << sync.hp << std::endl;
m_player.InflictDamage(sync.hp - comp.hp);
Vector3f diff = sync.position - comp.position;
@@ -1463,7 +1473,7 @@ void Engine::Render(float elapsedTime) {
m_bullets[0] = bult;
break;
}
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir * 10, false, .5f);
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, 1.f);
}
else SystemNotification("Bullet is kraput.");
break;

View File

@@ -218,9 +218,8 @@ private:
std::unordered_map<uint64_t, Player*> m_players;
netprot::Buffer m_buf, m_bufout;
netprot::ChunkMod* m_chunkmod = nullptr;
netprot::PlayerInfo m_pinfo;
std::unordered_map<uint64_t, netprot::Sync> m_syncs;
RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f));
std::string m_messageNotification = "";
};