This commit is contained in:
MarcEricMartel 2023-10-18 09:33:56 -04:00
parent 793da52871
commit 2cb7d4c776
4 changed files with 65 additions and 22 deletions

View File

@ -10,6 +10,7 @@
#define MAX_CONNECTIONS 16
#define ID_LIST_SIZE 127
#define BUFFER_LENGTH 150
#define SRV_MANUAL_SETUP true
typedef unsigned char LogDest;
enum LOG_DEST { CONSOLE, LOGFILE, LOG_LAST };

View File

@ -65,6 +65,31 @@ int Server::Init() {
}
int Server::Ready() {
int nbrjoueurs = 0,
nbrconn = 0;
#ifdef SRV_MANUAL_SETUP
do {
Log("Entrez la durée de la partie: ", false, false);
std::cin >> m_game.countdown;
std::cout << std::endl;
} while (m_game.countdown < 1);
do {
Log("Entrez le seed de la partie: ", false, false);
std::cin >> m_game.seed;
std::cout << std::endl;
} while (m_game.seed < 1);
do {
Log("Entrez le nombre de joueurs: ", false, false);
std::cin >> nbrjoueurs;
std::cout << std::endl;
} while (nbrjoueurs > 0 && nbrjoueurs >= MAX_CONNECTIONS);
#else // setup preconfiguré
m_game.countdown = 360;
m_game.seed = 9370707;
nbrjoueurs = 1;
#endif
m_game.gameType = 1;
if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
Log("Écoute sur le port TCP.", true, true);
return 1;
@ -79,13 +104,17 @@ int Server::Ready() {
buildIdList(ID_LIST_SIZE);
m_game.countdown = 360;
m_game.gameType = 1;
m_game.seed = 9370707;
while (!readystart) {
sockaddr_in sockad;
#ifdef _WIN32
int addrlen = sizeof(sockad);
#else // maudit que c'est con, ça.
unsigned int addrlen = sizeof(sockad);
#endif
SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen);
if (sock < 0)
@ -127,6 +156,7 @@ int Server::Ready() {
Connection* conn = new Connection(sock, sockad, log, play);
m_players[log.sid] = conn;
if (++nbrconn >= nbrjoueurs)
readystart = true;
}
}

View File

@ -34,6 +34,7 @@ private:
netprot::GameInfo m_game;
World* m_world = nullptr;
const bool m_manual_setup = SRV_MANUAL_SETUP;
std::string LogTimestamp();
void Log(std::string str, bool is_error, bool is_fatal);

View File

@ -229,6 +229,10 @@ void Engine::Init() {
abort();
}
uint64_t seed = SEED;
std::string playname = "";
char ch;
glDisable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
@ -258,31 +262,37 @@ void Engine::Init() {
// Array pour les balles.
for (int x = 0; x < MAX_BULLETS; ++x) {
m_bullets[x] = nullptr;
m_whoosh[x] = nullptr; // = m_audio.m_engine.m_audio.m_engine->addSoundSourceFromFile(AUDIO_PATH "noise.ogg", irrklang::ESM_AUTO_DETECT, false);
m_whoosh[x] = nullptr;
}
uint64_t seed = SEED;
std::string playname = "La Chienne <20> Jacques";
if (NETWORK_TEST) { // Test connexion r<>seau.
#ifdef NETWORK_TEST
std::cout << "Jouer en ligne? [o/N] ";
std::cin >> ch;
std::cout << std::endl;
if (ch == 'o' || ch == 'O') {
std::cout << "Veuillez entrer un nom de joueur: ";
std::getline(std::cin, playname);
std::cout << std::endl;
if (!m_conn.Init()) {
if (!m_conn.Connect(SRV_ADDR, playname)) {
// setup jeu en r<>seau.
std::cout << "ID re<72>u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
std::cout << "Seed re<72>u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
// 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;
seed = m_conn.getSeed();
}
else std::cout << "Erreur de connexion." << std::endl;
}
else std::cout << "Erreur de cr<EFBFBD>ation de socket." << std::endl;
else std::cout << "Erreur de creation de socket." << std::endl;
}
#endif
m_world.SetSeed(seed);
// Init Chunks
m_world.GetChunks().Reset(nullptr);
// Gestion de souris.
CenterMouse();
HideCursor();
@ -461,7 +471,7 @@ void Engine::DisplayHud(int timer) {
glVertex2f(fPosX, fPosY); // Haut-Gauche
glEnd();
//TODO: Associer avec m<EFBFBD>chanique de vie du joueur
//TODO: Associer avec mechanique de vie du joueur
// Barre HP
glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
@ -472,7 +482,7 @@ void Engine::DisplayHud(int timer) {
glVertex2f(fPosX, fPosY); // Haut-Gauche
glEnd();
// Barre <EFBFBD>quip
// Barre equip
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
@ -633,6 +643,7 @@ float Engine::GetScale() const {
}
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
int Engine::GetCountdown(float elapsedTime) {
if (m_resetcountdown)
{
@ -684,16 +695,16 @@ 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(), .8f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), .8f, false);
leftright = !leftright;
break;
case Player::Sound::FALL:
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f, false);
break;
default: break;
}
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<EFBFBD>es du joueur et
// son vecteur de v<EFBFBD>locit<EFBFBD> (pour l'effet Doppler)
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnees du joueur et
// son vecteur de velocite (pour l'effet Doppler)
pollTime = 0;
}
@ -755,7 +766,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(), 1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), 1.f, false);
fell = true;
}
else if (m_player.GetPosition().y < -20.f) {
@ -813,7 +824,7 @@ void Engine::KeyPressEvent(unsigned char key) {
break;
case 10: // K - Debugging DisplayNotification()
m_keyK = true;
m_messageNotification = "notifications systeme peuvent <EFBFBD>tre affich<63>";
m_messageNotification = "notifications systeme peuvent etre affichees";
break;
case 11: // L - Debugging DisplayNotification()
m_keyL = true;