pouet pouet

This commit is contained in:
MarcEricMartel 2023-10-30 15:36:43 -04:00
parent 3249d68e60
commit 35c2a5be31
3 changed files with 96 additions and 88 deletions

View File

@ -812,7 +812,6 @@ std::vector<netprot::Packet> netprot::recvPacks(SOCKET sock, Buffer* buf) {
std::vector<Packet> lsPck;
int len = 0, end = 0;
bool pck_received = false;
char* cursor = nullptr;
while (true) {
while (!pck_received) {
@ -823,21 +822,27 @@ std::vector<netprot::Packet> netprot::recvPacks(SOCKET sock, Buffer* buf) {
// TODO: Voir si on trouve un footer (5 '\0' d'affilee).
// Si oui, mettre l'index du debut du footer dans
// la variable "end" et mettre pck_received a true.
//buf->ptr
//end = len;
//pck_received = true;
}
char* cursor = nullptr;
cursor = &buf->ptr[end];
lsPck.push_back(getPack(buf));
while (*cursor == '\0') {
cursor++;
end++;
}
while (*cursor == '\0')
cursor++, end++;
if (cursor) { // mettre le début du prochain paquet au début du buffer.
memcpy(buf->ptr, cursor, buf->len - end); // et voir s'il y a en un autre
len = 0;
pck_received = true;
pck_received = false;
}
}
}

View File

@ -82,7 +82,7 @@ void Engine::DrawMenu()
static const int sButton = 225;
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
@ -280,10 +280,9 @@ void Engine::Init() {
}
uint64_t seed = SEED;
char ch;
glDisable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_BLEND);
@ -300,7 +299,7 @@ void Engine::Init() {
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_SUBTRACT);
//
// Objet de skybox avec sa propre texture et son propre shader!
m_skybox.Init(0.2f);
@ -314,50 +313,53 @@ void Engine::Init() {
m_whoosh[x] = nullptr;
}
std::cout << "Jouer en ligne? [o/N] ";
std::cin >> ch;
std::cout << std::endl;
char* ch = new char[2];
if (ch == 'o' || ch == 'O') {
char* input = new char[32];
std::string playname, srvname;
std::cout << "Jouer en ligne? [o/N] ";
std::cin.getline(ch, 2);
std::cout << std::endl;
while (playname.size() < 1) {
std::cout << "Veuillez entrer un nom de joueur: ";
std::cin.ignore();
std::cin.getline(input, 32);
std::cout << std::endl;
playname = input;
if (playname.size() < 1 || playname.size() > 32)
std::puts("Nom invalide.");
}
while (srvname.size() < 1) {
std::cout << "Veuillez entrer une adresse de serveur: ";
std::cin.getline(input, 32);
std::cout << std::endl;
srvname = input;
if (srvname.size() < 1 || srvname.size() > 32)
std::puts("Adresse serveur invalide.");
}
delete[] input;
if (*ch == 'o' || *ch == 'O') {
char* input = new char[32];
std::string playname, srvname;
if (!m_conn.Init()) {
if (!m_conn.Connect(srvname.c_str(), playname)) {
// setup jeu en reseau.
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
m_player = Player(m_conn.getOrigin().position);
for (auto& [key, player] : m_conn.m_players)
m_players[key] = new RemotePlayer(player);
seed = m_conn.getSeed();
m_networkgame = true;
}
else std::cout << "Erreur de connexion." << std::endl;
}
else std::cout << "Erreur de creation de socket." << std::endl;
while (playname.size() < 1) {
std::cout << "Veuillez entrer un nom de joueur: ";
std::cin.ignore();
std::cin.getline(input, 32);
std::cout << std::endl;
playname = input;
if (playname.size() < 1 || playname.size() > 32)
std::puts("Nom invalide.");
}
while (srvname.size() < 1) {
std::cout << "Veuillez entrer une adresse de serveur: ";
std::cin.getline(input, 32);
std::cout << std::endl;
srvname = input;
if (srvname.size() < 1 || srvname.size() > 32)
std::puts("Adresse serveur invalide.");
}
delete[] input;
if (!m_conn.Init()) {
if (!m_conn.Connect(srvname.c_str(), playname)) {
// setup jeu en reseau.
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
m_player = Player(m_conn.getOrigin().position);
for (auto& [key, player] : m_conn.m_players)
m_players[key] = new RemotePlayer(player);
seed = m_conn.getSeed();
m_networkgame = true;
}
else std::cout << "Erreur de connexion." << std::endl;
}
else std::cout << "Erreur de creation de socket." << std::endl;
}
delete[] ch;
m_world.SetSeed(seed);
@ -749,8 +751,8 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fBackPosX, fBackPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fBackWidth, fBackPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight);
glEnd();
float centerX = (Width() / 2.0f);
@ -761,9 +763,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
// Solo game indicator
m_textureTitle.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY);
glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(titleWidth, centerY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight);
glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX, titleHeight);
glEnd();
@ -777,9 +779,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, soloHeight);
glEnd();
@ -789,9 +791,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, multiPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, multiHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight);
glEnd();
// TODO: Add SOLO / MULTIPLAYER text with font
@ -913,8 +915,8 @@ void Engine::Render(float elapsedTime) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_time_SplashScreen += elapsedTime;
if(m_time_SplashScreen < 2)
DrawSplachScreen();
if (m_time_SplashScreen < 2)
DrawSplachScreen();
else if (m_gamestate == GameState::PLAY)
{
HideCursor();
@ -950,11 +952,11 @@ void Engine::Render(float elapsedTime) {
if (leftright)
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false,.8f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, .8f);
leftright = !leftright;
break;
case Player::Sound::FALL:
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false,1.f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, 1.f);
break;
default: break;
}
@ -995,32 +997,32 @@ void Engine::Render(float elapsedTime) {
glClearColor(0.f, 0.f, 0.f, 1.f);
return;
}
}
}
}
else if (m_mouseR)
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
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_bullets[x]->~Bullet();
if (m_whoosh[x])
m_whoosh[x]->drop();
m_bullets[x] = nullptr;
m_whoosh[x] = nullptr;
break;
}
else if (!m_whoosh[x]) {
m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
}
else {
Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
else if (m_mouseR)
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
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_bullets[x]->~Bullet();
if (m_whoosh[x])
m_whoosh[x]->drop();
m_bullets[x] = nullptr;
m_whoosh[x] = nullptr;
break;
}
else if (!m_whoosh[x]) {
m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
}
else {
Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
}
}
}
}
}
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
@ -1034,7 +1036,7 @@ void Engine::Render(float elapsedTime) {
static bool fell = false;
if (m_player.GetPosition().y < 1.7f && !fell) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
fell = true;
}
else if (m_player.GetPosition().y < -20.f) {
@ -1181,7 +1183,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
case 15:
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() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f,0.f,1.f));
m_bullets[x] = new Bullet(m_player.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f, 0.f, 1.f));
break;
}
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<6D>re balle de l'array.

View File

@ -8,7 +8,7 @@
class RemotePlayer : public Player {
public:
enum Anim { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 };
enum Anim: uint8_t { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 };
RemotePlayer(netprot::PlayerInfo pinfo);
@ -17,6 +17,7 @@ public:
private:
netprot::Output current, previous;
std::map<uint64_t, netprot::Output> m_outbuf;
netprot::PlayerInfo m_pinfo;
float m_aminacc;
Anim m_animstate;