Rollover Beethoven

This commit is contained in:
MarcEricMartel 2023-12-06 15:37:08 -05:00
parent 6178604d95
commit 7077b617be
4 changed files with 35 additions and 19 deletions

View File

@ -405,7 +405,14 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
size_t messize = std::strlen(chat->mess) + 1; size_t messize = std::strlen(chat->mess) + 1;
memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); std::cout << chat->mess << ": ";
strcpy(*buf + 1 + sizeof(uint64_t) * 3, messize, chat->mess);
//memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize);
for (int x = 0; x < sizeof(Chat); ++x)
std::cout << *(*buf + x);
*buflen = messize + sizeof(uint64_t) * 3 + 2; *buflen = messize + sizeof(uint64_t) * 3 + 2;
} }
@ -928,6 +935,9 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
if (messsize > 140) if (messsize > 140)
return false; return false;
for (int x = 0; x < 140; ++x)
std::cout << buf[sizeof(uint64_t) * 3 + x];
memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize); memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize);
*buflen = messsize + sizeof(uint64_t) * 3 + 2; *buflen = messsize + sizeof(uint64_t) * 3 + 2;

View File

@ -129,7 +129,7 @@ namespace netprot {
Chat() {} Chat() {}
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) {
strcpy(mess, 140, cha->mess); } strcpy(mess, 140, cha->mess); }
~Chat() { delete[] mess; } ~Chat() {/* delete[] mess; */}
}; };
struct ChunkMod { struct ChunkMod {

View File

@ -83,17 +83,18 @@ int Server::Ready() {
m_game.countdown = 0; m_game.countdown = 0;
} }
} while (m_game.countdown < 1); } while (m_game.countdown < 1);
do { m_game.seed = 9370707;
/*do {
Log("Entrez le seed de la partie: ", false, false); Log("Entrez le seed de la partie: ", false, false);
std::cin.getline(m_buf.ptr, BUFFER_LENGTH); std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
try { try {
m_game.seed = 9370707;//std::stoi(m_buf.ptr); std::stoi(m_buf.ptr);
} }
catch (const std::exception& e) { catch (const std::exception& e) {
Log(e.what(), true, false); Log(e.what(), true, false);
m_game.seed = 0; m_game.seed = 0;
} }
} while (m_game.seed < 1); } while (m_game.seed < 1);*/
do { do {
Log("Entrez le nombre de joueurs: ", false, false); Log("Entrez le nombre de joueurs: ", false, false);
std::cin.getline(m_buf.ptr, BUFFER_LENGTH); std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
@ -312,10 +313,12 @@ void Server::Run() {
endgame = true; endgame = true;
} }
for (auto& bull : netbull) for (auto& bull : netbull) {
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle. if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle.
sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr()); sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr());
delete bull;
}
for (auto& bull : bullets) { for (auto& bull : bullets) {
@ -327,6 +330,10 @@ void Server::Run() {
} }
} }
//for (auto& bull : outbox_bullets)
// delete bull;
//outbox_bullets.clear();
for (auto& chat : chatlog) { for (auto& chat : chatlog) {
Log(chat->mess, false, false); Log(chat->mess, false, false);
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
@ -340,7 +347,6 @@ void Server::Run() {
delete chmo; delete chmo;
} }
outbox_bullets.clear();
netbull.clear(); netbull.clear();
chunkdiffs.clear(); chunkdiffs.clear();
chatlog.clear(); chatlog.clear();

View File

@ -90,7 +90,7 @@ void Engine::Init() {
RemotePlayer* rt = (RemotePlayer*)m_players[key]; RemotePlayer* rt = (RemotePlayer*)m_players[key];
rt->SetPosition(Vector3f(555, 555, 555)); rt->SetPosition(Vector3f(555, 555, 555));
} }
m_player.m_username = playname;
seed = 9370707;//m_conn.getSeed(); seed = 9370707;//m_conn.getSeed();
m_networkgame = true; m_networkgame = true;
} }
@ -659,17 +659,17 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
int Engine::GetCountdown(float elapsedTime) { int Engine::GetCountdown(float elapsedTime) {
if (m_resetcountdown) { //if (m_resetcountdown) {
m_nbReductionChunk = 4; // m_nbReductionChunk = 4;
m_timerReductionChunk = 30; // m_timerReductionChunk = 30;
m_countdown = m_time + COUNTDOWN; // m_countdown = m_time + COUNTDOWN;
m_resetcountdown = false; // m_resetcountdown = false;
} // }
if (m_countdown < m_time) {} // if (m_countdown < m_time) {}
// Stop(); // Stop();
if (!m_stopcountdown) //if (!m_stopcountdown)
m_time += elapsedTime; // m_time += elapsedTime;
return m_countdown - (int)m_time; return m_countdown;// -(int)m_time;
} }
int Engine::GetOptionsChoice() { int Engine::GetOptionsChoice() {