pouet pouet
This commit is contained in:
parent
3249d68e60
commit
35c2a5be31
@ -812,7 +812,6 @@ std::vector<netprot::Packet> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
|||||||
std::vector<Packet> lsPck;
|
std::vector<Packet> lsPck;
|
||||||
int len = 0, end = 0;
|
int len = 0, end = 0;
|
||||||
bool pck_received = false;
|
bool pck_received = false;
|
||||||
char* cursor = nullptr;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!pck_received) {
|
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).
|
// TODO: Voir si on trouve un footer (5 '\0' d'affilee).
|
||||||
// Si oui, mettre l'index du debut du footer dans
|
// Si oui, mettre l'index du debut du footer dans
|
||||||
// la variable "end" et mettre pck_received a true.
|
// la variable "end" et mettre pck_received a true.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//buf->ptr
|
||||||
|
|
||||||
|
//end = len;
|
||||||
|
//pck_received = true;
|
||||||
}
|
}
|
||||||
|
char* cursor = nullptr;
|
||||||
|
|
||||||
cursor = &buf->ptr[end];
|
cursor = &buf->ptr[end];
|
||||||
|
|
||||||
lsPck.push_back(getPack(buf));
|
lsPck.push_back(getPack(buf));
|
||||||
|
|
||||||
while (*cursor == '\0') {
|
while (*cursor == '\0')
|
||||||
cursor++;
|
cursor++, end++;
|
||||||
end++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor) { // mettre le début du prochain paquet au début du buffer.
|
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
|
memcpy(buf->ptr, cursor, buf->len - end); // et voir s'il y a en un autre
|
||||||
len = 0;
|
len = 0;
|
||||||
pck_received = true;
|
pck_received = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,6 @@ void Engine::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t seed = SEED;
|
uint64_t seed = SEED;
|
||||||
char ch;
|
|
||||||
|
|
||||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@ -314,50 +313,53 @@ void Engine::Init() {
|
|||||||
m_whoosh[x] = nullptr;
|
m_whoosh[x] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Jouer en ligne? [o/N] ";
|
char* ch = new char[2];
|
||||||
std::cin >> ch;
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
if (ch == 'o' || ch == 'O') {
|
std::cout << "Jouer en ligne? [o/N] ";
|
||||||
char* input = new char[32];
|
std::cin.getline(ch, 2);
|
||||||
std::string playname, srvname;
|
std::cout << std::endl;
|
||||||
|
|
||||||
while (playname.size() < 1) {
|
if (*ch == 'o' || *ch == 'O') {
|
||||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
char* input = new char[32];
|
||||||
std::cin.ignore();
|
std::string playname, srvname;
|
||||||
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()) {
|
while (playname.size() < 1) {
|
||||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||||
// setup jeu en reseau.
|
std::cin.ignore();
|
||||||
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
std::cin.getline(input, 32);
|
||||||
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
std::cout << std::endl;
|
||||||
m_player = Player(m_conn.getOrigin().position);
|
playname = input;
|
||||||
|
if (playname.size() < 1 || playname.size() > 32)
|
||||||
for (auto& [key, player] : m_conn.m_players)
|
std::puts("Nom invalide.");
|
||||||
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 (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);
|
m_world.SetSeed(seed);
|
||||||
|
|
||||||
@ -913,8 +915,8 @@ void Engine::Render(float elapsedTime) {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
m_time_SplashScreen += elapsedTime;
|
m_time_SplashScreen += elapsedTime;
|
||||||
if(m_time_SplashScreen < 2)
|
if (m_time_SplashScreen < 2)
|
||||||
DrawSplachScreen();
|
DrawSplachScreen();
|
||||||
else if (m_gamestate == GameState::PLAY)
|
else if (m_gamestate == GameState::PLAY)
|
||||||
{
|
{
|
||||||
HideCursor();
|
HideCursor();
|
||||||
@ -950,11 +952,11 @@ void Engine::Render(float elapsedTime) {
|
|||||||
if (leftright)
|
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);
|
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);
|
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;
|
leftright = !leftright;
|
||||||
break;
|
break;
|
||||||
case Player::Sound::FALL:
|
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;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -995,32 +997,32 @@ void Engine::Render(float elapsedTime) {
|
|||||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (m_mouseR)
|
||||||
else if (m_mouseR)
|
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
||||||
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.
|
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
||||||
if (m_bullets[x]) {
|
if (m_bullets[x]) {
|
||||||
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
|
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
|
||||||
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
|
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
|
||||||
m_bullets[x]->~Bullet();
|
m_bullets[x]->~Bullet();
|
||||||
if (m_whoosh[x])
|
if (m_whoosh[x])
|
||||||
m_whoosh[x]->drop();
|
m_whoosh[x]->drop();
|
||||||
m_bullets[x] = nullptr;
|
m_bullets[x] = nullptr;
|
||||||
m_whoosh[x] = nullptr;
|
m_whoosh[x] = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (!m_whoosh[x]) {
|
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());
|
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 {
|
else {
|
||||||
Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
|
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_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_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);
|
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||||
@ -1034,7 +1036,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
static bool fell = false;
|
static bool fell = false;
|
||||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
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;
|
fell = true;
|
||||||
}
|
}
|
||||||
else if (m_player.GetPosition().y < -20.f) {
|
else if (m_player.GetPosition().y < -20.f) {
|
||||||
@ -1181,7 +1183,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
|||||||
case 15:
|
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").
|
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() - 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;
|
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.
|
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.
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class RemotePlayer : public Player {
|
class RemotePlayer : public Player {
|
||||||
public:
|
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);
|
RemotePlayer(netprot::PlayerInfo pinfo);
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
netprot::Output current, previous;
|
netprot::Output current, previous;
|
||||||
|
std::map<uint64_t, netprot::Output> m_outbuf;
|
||||||
netprot::PlayerInfo m_pinfo;
|
netprot::PlayerInfo m_pinfo;
|
||||||
float m_aminacc;
|
float m_aminacc;
|
||||||
Anim m_animstate;
|
Anim m_animstate;
|
||||||
|
Loading…
Reference in New Issue
Block a user