Compare commits
No commits in common. "5b0be2d98535e4a2e601b6364b8ea80774703651" and "63d70be48870d538c538881ea956852e5654ae61" have entirely different histories.
5b0be2d985
...
63d70be488
@ -38,10 +38,11 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
||||
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
|
||||
if (chunkmod) {
|
||||
using namespace netprot;
|
||||
*chunkmod = new ChunkMod();
|
||||
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
|
||||
(*chunkmod)->b_type = BTYPE_AIR;
|
||||
(*chunkmod)->pos = m_currentpos;
|
||||
ChunkMod* cmod = *chunkmod;
|
||||
cmod = new ChunkMod();
|
||||
cmod->old_b_type = world->BlockAt(m_currentpos);
|
||||
cmod->b_type = BTYPE_AIR;
|
||||
cmod->pos = m_currentpos;
|
||||
}
|
||||
|
||||
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
|
||||
|
@ -198,7 +198,7 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
(uint8_t)((vec[2] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[2] & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, vec8, sizeof(uint32_t) * 3);
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
uint32_t hp;
|
||||
|
||||
@ -210,8 +210,6 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
(uint8_t)((hp >> 8) & 0xFF),
|
||||
(uint8_t)(hp & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
|
||||
}
|
||||
|
||||
@ -220,8 +218,7 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(tinfo->name) + 1;
|
||||
|
||||
strcpy(*buf + 1, namesize, tinfo->name);
|
||||
|
||||
memcpy(*buf + 1, &tinfo->name, namesize);
|
||||
uint64_t tid = tinfo->id;
|
||||
uint8_t tid8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((tid >> 56) & 0xFF),
|
||||
@ -244,8 +241,7 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(linfo->name) + 1;
|
||||
|
||||
strcpy(*buf + 1, namesize, linfo->name);
|
||||
|
||||
memcpy(*buf + 1, &linfo->name, namesize);
|
||||
uint64_t sid = linfo->sid;
|
||||
uint8_t sid8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((sid >> 56) & 0xFF),
|
||||
@ -282,8 +278,7 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(pinfo->name) + 1;
|
||||
|
||||
strcpy(*buf + 1, namesize, pinfo->name);
|
||||
|
||||
memcpy(*buf + 1, &pinfo->name, namesize);
|
||||
uint64_t id = pinfo->id;
|
||||
uint8_t id8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((id >> 56) & 0xFF),
|
||||
@ -708,7 +703,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
|
||||
uint32_t vec[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
@ -727,7 +722,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
|
||||
uint8_t hp8[4];
|
||||
|
||||
memcpy(&hp8, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
|
||||
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
|
||||
|
||||
uint32_t hp = (uint32_t)hp8[0] << 24 |
|
||||
(uint32_t)hp8[1] << 16 |
|
||||
@ -736,7 +731,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
|
||||
memcpy(&sync->hp, &hp, sizeof(float));
|
||||
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -750,7 +745,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
strcpy(tinfo->name, namesize, &buf[1]);
|
||||
memcpy(&tinfo->name, &buf[1], namesize);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
@ -778,7 +773,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
strcpy(linfo->name, namesize, &buf[1]);
|
||||
memcpy(&linfo->name, &buf[1], namesize);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
@ -817,7 +812,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
strcpy(pinfo->name, namesize, &buf[1]);
|
||||
memcpy(&pinfo->name, &buf[1], namesize);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
|
@ -19,7 +19,7 @@ namespace netprot {
|
||||
/* Structures */
|
||||
|
||||
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
|
||||
char *ptr = new char[BUFFER_LENGTH] { 1 }, *tmp = nullptr;
|
||||
char* ptr = new char[BUFFER_LENGTH] { 1 }, * tmp = nullptr;
|
||||
uint32_t len = BUFFER_LENGTH;
|
||||
|
||||
~Buffer() { delete[] ptr; }
|
||||
@ -27,7 +27,7 @@ namespace netprot {
|
||||
};
|
||||
|
||||
struct Packet { // Pour pouvoir recevoir les paquets du recv() sans avoir à les aiguiller dans la même thread.
|
||||
void *ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile.
|
||||
void* ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile.
|
||||
PACKET_TYPE type = PACKET_TYPE::ERR;
|
||||
};
|
||||
|
||||
@ -87,30 +87,30 @@ namespace netprot {
|
||||
};
|
||||
|
||||
struct TeamInfo { // cli <-> srv TCP once
|
||||
char *name = new char[32];
|
||||
char name[32];
|
||||
uint64_t id = 0;
|
||||
TeamInfo() {}
|
||||
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(name, 32, tem->name); }
|
||||
~TeamInfo() { delete[] name; }
|
||||
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(tem->name, name); }
|
||||
};
|
||||
|
||||
struct LoginInfo { // cli <-> srv TCP once
|
||||
char *name = new char[32];
|
||||
char name[32];
|
||||
uint64_t sid = 0,
|
||||
tid = 0;
|
||||
LoginInfo() {}
|
||||
LoginInfo(LoginInfo* log): sid(log->sid), tid(log->tid) { strcpy(name, 32, log->name); }
|
||||
~LoginInfo() { delete[] name; }
|
||||
LoginInfo(LoginInfo* ply): sid(ply->sid), tid(ply->tid) { strcpy(ply->name, name); }
|
||||
};
|
||||
|
||||
struct PlayerInfo { // cli <-> srv TCP once
|
||||
char *name = new char[32];
|
||||
char name[32];
|
||||
uint64_t id = 0,
|
||||
tid = 0;
|
||||
PlayerInfo() {}
|
||||
PlayerInfo(PlayerInfo* ply) : id(ply->id), tid(ply->tid) { strcpy(name, 32, ply->name); };
|
||||
PlayerInfo(int id, int tid, std::string strname) : id(id), tid(tid) { strcpy(name, 32, strname.c_str()); }
|
||||
~PlayerInfo() { delete[] name; }
|
||||
PlayerInfo(PlayerInfo* log) : id(log->id), tid(log->tid) {
|
||||
strcpy(log->name, name);
|
||||
};
|
||||
PlayerInfo(int id, int tid, std::string strname) : id(id), tid(tid) { memcpy((void*)strname.c_str(), name, strname.length());
|
||||
}
|
||||
};
|
||||
|
||||
struct GameInfo { // cli <-> srv TCP event (before game start)/ once
|
||||
@ -125,9 +125,10 @@ namespace netprot {
|
||||
uint64_t src_id = 0,
|
||||
dest_id = 0,
|
||||
dest_team_id = 0;
|
||||
char *mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
|
||||
char* mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
|
||||
Chat() {}
|
||||
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); }
|
||||
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); }
|
||||
~Chat() { delete[] mess; }
|
||||
};
|
||||
|
||||
@ -143,11 +144,10 @@ namespace netprot {
|
||||
};
|
||||
|
||||
struct ErrorLog { // srv -> cli TCP event
|
||||
char *mess = new char[140];
|
||||
bool is_fatal = false;
|
||||
char mess[140];
|
||||
bool is_fatal;
|
||||
ErrorLog() {};
|
||||
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(mess, 140, err->mess); }
|
||||
~ErrorLog() { delete[] mess; }
|
||||
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(err->mess, mess); }
|
||||
};
|
||||
|
||||
/* Fonctions */
|
||||
|
@ -4,18 +4,16 @@
|
||||
|
||||
Connection::Connection(SOCKET sock,
|
||||
sockaddr_in sockaddr,
|
||||
LoginInfo *log,
|
||||
PlayerInfo *play) :
|
||||
LoginInfo log,
|
||||
PlayerInfo play) :
|
||||
m_sock(sock),
|
||||
m_addr(sockaddr),
|
||||
m_loginfo(*log),
|
||||
m_playinfo(*play) {
|
||||
m_loginfo(log),
|
||||
m_playinfo(play) {
|
||||
|
||||
}
|
||||
|
||||
Connection::~Connection() {
|
||||
delete player;
|
||||
closesocket(m_sock); }
|
||||
Connection::~Connection() { closesocket(m_sock); }
|
||||
|
||||
uint64_t Connection::GetHash(bool self) const { return self ? m_loginfo.sid : m_playinfo.id; }
|
||||
|
||||
@ -146,7 +144,7 @@ Timestamp Connection::Run(World* world) {
|
||||
player->Killer = GetHash(true);
|
||||
}
|
||||
|
||||
out.states.jumping = player->GetIsAirborne();
|
||||
out.states.jumping = player->GetIsAirborne(); //abs(player->GetVelocity().y) > .2f;
|
||||
out.states.running = player->GetVelocity().Length() > .5f;
|
||||
out.states.still = !out.states.running && !out.states.jumping;
|
||||
out.states.hit = player->m_hit;
|
||||
@ -168,7 +166,7 @@ Timestamp Connection::Run(World* world) {
|
||||
player->GetDirection(),
|
||||
block, true);
|
||||
if (cmod)
|
||||
ChunkDiffs.push_back(std::move(cmod));
|
||||
ChunkDiffs.emplace_back(cmod);
|
||||
}
|
||||
}
|
||||
else toggle = false;
|
||||
@ -180,7 +178,7 @@ Timestamp Connection::Run(World* world) {
|
||||
else out.states.jumpshot = false;
|
||||
|
||||
if (in.keys.shoot && m_shoot_acc <= 0.) {
|
||||
Bullets.push_back(std::move(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true))));
|
||||
Bullets.emplace_back(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true)));
|
||||
m_shoot_acc = BULLET_TIME;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ public:
|
||||
Connection(
|
||||
SOCKET sock,
|
||||
sockaddr_in sockaddr,
|
||||
LoginInfo *log,
|
||||
PlayerInfo *play);
|
||||
LoginInfo log,
|
||||
PlayerInfo play);
|
||||
~Connection();
|
||||
|
||||
Player* player = nullptr;
|
||||
|
@ -3,11 +3,6 @@
|
||||
int main() {
|
||||
std::unique_ptr<Server> server = std::make_unique<Server>();
|
||||
if (server->Init() == 0)
|
||||
while (server->Ready() == 0) {
|
||||
if (server->Ready() == 0)
|
||||
server->Run();
|
||||
if (!server->NewGameRequested())
|
||||
break;
|
||||
server->Cleanup();
|
||||
}
|
||||
server->DeInit();
|
||||
}
|
@ -132,7 +132,7 @@ int Server::Ready() {
|
||||
str.append(inet_ntop(AF_INET, &sockad.sin_addr, m_buf.ptr, m_buf.len)).append(": ").append(std::to_string(sockad.sin_port));
|
||||
|
||||
if (recv(sock, m_buf.ptr, m_buf.len, 0) > 0) {
|
||||
PlayerInfo* play = new PlayerInfo();
|
||||
PlayerInfo play;
|
||||
|
||||
m_buf.len = BUFFER_LENGTH;
|
||||
Packet pck = getPack(&m_buf);
|
||||
@ -153,20 +153,22 @@ int Server::Ready() {
|
||||
|
||||
sendPackTo<LoginInfo>(m_sock_udp, log, &m_buf, &sockad);
|
||||
|
||||
play->id = getUniqueId();
|
||||
play->tid = log->tid;
|
||||
strcpy(play->name, 32, log->name);
|
||||
play.id = getUniqueId();
|
||||
play.tid = log->tid;
|
||||
strcpy(play.name, log->name);
|
||||
|
||||
Log(str.append(play->name).append(" SID: [").append(std::to_string(log->sid)).append("]")
|
||||
.append(" ID: [").append(std::to_string(play->id)).append("]")
|
||||
.append(" TID: [").append(std::to_string(play->tid)).append("]"), false, false);
|
||||
play->tid = log->tid;
|
||||
Log(str.append(play.name).append(" SID: [").append(std::to_string(log->sid)).append("]")
|
||||
.append(" ID: [").append(std::to_string(play.id)).append("]")
|
||||
.append(" TID: [").append(std::to_string(play.tid)).append("]"), false, false);
|
||||
play.tid = log->tid;
|
||||
|
||||
sendPackTo<GameInfo>(m_sock_udp, &m_game, &m_buf, &sockad);
|
||||
Connection* conn = new Connection(sock, sockad, log, play);
|
||||
Connection* conn = new Connection(sock, sockad, *log, play);
|
||||
|
||||
m_conns[log->sid] = conn;
|
||||
|
||||
delete log;
|
||||
|
||||
if (++nbrconn >= nbrjoueurs)
|
||||
readystart = true;
|
||||
}
|
||||
@ -202,8 +204,8 @@ void Server::Run() {
|
||||
m_conns.erase(key);
|
||||
continue;
|
||||
}
|
||||
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 8,
|
||||
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 8;
|
||||
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 4,
|
||||
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 4;
|
||||
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
|
||||
conn->player->m_username = conn->GetName();
|
||||
m_players[key] = conn->player;
|
||||
@ -302,7 +304,7 @@ void Server::Run() {
|
||||
|
||||
for (auto& bull : conn->Bullets) {
|
||||
bullets.emplace_back(bull);
|
||||
//Log("POW!", false, false);
|
||||
Log("POW!", false, false);
|
||||
BulletAdd* nbul = new BulletAdd();
|
||||
nbul->pos = bull->getPos();
|
||||
nbul->dir = bull->getVel();
|
||||
@ -375,44 +377,9 @@ void Server::Run() {
|
||||
sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr());
|
||||
|
||||
// TODO: Gérer les 2-3 secondes post-game avant le billboard pour pas avoir un whiplash à la fin de la game.
|
||||
|
||||
char* ch = new char[2];
|
||||
std::cout << "Nouvelle partie? [o/N] ";
|
||||
std::cin.getline(ch, 2);
|
||||
std::cout << std::endl;
|
||||
|
||||
m_exit = true;
|
||||
if (ch[0] == 'o' || ch[0] == 'O')
|
||||
m_exit = false;
|
||||
|
||||
delete[] ch;
|
||||
system("pause");
|
||||
}
|
||||
|
||||
void Server::Cleanup() {
|
||||
for (auto& [key, conn] : m_conns)
|
||||
delete conn;
|
||||
|
||||
m_conns.clear();
|
||||
m_players.clear();
|
||||
delete m_world;
|
||||
m_world = nullptr;
|
||||
}
|
||||
|
||||
void Server::DeInit() {
|
||||
if (m_logfile.is_open())
|
||||
m_logfile.close();
|
||||
if (m_sock_udp)
|
||||
closesocket(m_sock_udp);
|
||||
if (m_sock_tcp)
|
||||
closesocket(m_sock_tcp);
|
||||
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Server::NewGameRequested() const { return !m_exit; }
|
||||
|
||||
inline std::string Server::LogTimestamp() {
|
||||
time_t rawtime;
|
||||
tm timeinfo;
|
||||
@ -493,7 +460,7 @@ std::string Server::getDeathMessage(std::string username, std::string killer) co
|
||||
mess.append(temp.substr(0, ind));
|
||||
mess.append(username);
|
||||
if (!bypass) {
|
||||
mess.append(temp.substr(ind + 1, indk - 1));
|
||||
mess.append(temp.substr(ind + 1, indk));
|
||||
mess.append(killer);
|
||||
mess.append(temp.substr(indk + 1));
|
||||
}
|
||||
@ -502,7 +469,7 @@ std::string Server::getDeathMessage(std::string username, std::string killer) co
|
||||
else {
|
||||
mess.append(temp.substr(0, indk));
|
||||
mess.append(killer);
|
||||
mess.append(temp.substr(indk + 1, ind - 1));
|
||||
mess.append(temp.substr(indk + 1, ind));
|
||||
mess.append(username);
|
||||
mess.append(temp.substr(ind + 1));
|
||||
}
|
||||
|
@ -24,9 +24,6 @@ public:
|
||||
int Init();
|
||||
int Ready();
|
||||
void Run();
|
||||
void Cleanup();
|
||||
void DeInit();
|
||||
bool NewGameRequested() const;
|
||||
|
||||
private:
|
||||
|
||||
@ -47,7 +44,7 @@ private:
|
||||
GameInfo m_game;
|
||||
|
||||
World* m_world = nullptr;
|
||||
bool m_exit = true;
|
||||
const bool m_manual_setup = SRV_MANUAL_SETUP;
|
||||
|
||||
std::string LogTimestamp();
|
||||
void Log(std::string str, bool is_error, bool is_fatal);
|
||||
|
@ -14,7 +14,7 @@ Audio::Audio(const char * music) {
|
||||
m_engine->setRolloffFactor(2);
|
||||
m_engine->setDefault3DSoundMinDistance(.1);
|
||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
||||
m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING);
|
||||
}
|
||||
|
||||
Audio::~Audio() {
|
||||
|
@ -65,7 +65,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
|
||||
netprot::Buffer bf;
|
||||
netprot::LoginInfo log;
|
||||
strcpy(log.name, 32, name.c_str());
|
||||
strcpy(log.name, name.c_str());
|
||||
|
||||
netprot::sendPack(m_sock_tcp, &log, &bf);
|
||||
|
||||
|
@ -48,9 +48,8 @@
|
||||
enum GameState {
|
||||
MAIN_MENU,
|
||||
SPLASH,
|
||||
LOBBY,
|
||||
OPTIONS,
|
||||
QUIT,
|
||||
QUIT,
|
||||
PLAY,
|
||||
PAUSE
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ struct Notification {
|
||||
// Use a vector to manage notifications
|
||||
std::vector<Notification> notifications;
|
||||
|
||||
Engine::Engine() {}
|
||||
Engine::Engine() : m_remotePlayer(&m_pinfo), m_pinfo() {}
|
||||
|
||||
Engine::~Engine() {
|
||||
m_world.CleanUpWorld(m_renderCount, true);
|
||||
@ -29,6 +29,9 @@ Engine::~Engine() {
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
|
||||
uint64_t seed = SEED;
|
||||
|
||||
if (m_istarted)
|
||||
return;
|
||||
else m_istarted = true;
|
||||
@ -36,16 +39,74 @@ void Engine::Init() {
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
// Objet de musique!
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
|
||||
//m_audio.ToggleMusicState();
|
||||
|
||||
// Array pour les balles.
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) {
|
||||
m_bullets[x] = nullptr;
|
||||
m_whoosh[x] = nullptr;
|
||||
}
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
m_world.SetSeed(SEED);
|
||||
|
||||
char* ch = new char[2];
|
||||
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
std::cin.getline(ch, 2);
|
||||
std::cout << std::endl;
|
||||
|
||||
if (*ch == 'o' || *ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
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);
|
||||
RemotePlayer* rt = (RemotePlayer*)m_players[key];
|
||||
rt->SetPosition(Vector3f(555, 555, 555));
|
||||
}
|
||||
m_player.m_username = playname;
|
||||
seed = 9370707;//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_startTime = std::chrono::high_resolution_clock::now();
|
||||
m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5));
|
||||
// Gestion de souris.
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
}
|
||||
|
||||
void Engine::DeInit() {}
|
||||
@ -82,9 +143,8 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||
LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false);
|
||||
|
||||
LoadTexture(m_textureLobbyMenu, TEXTURE_PATH "menus/backgrounds/bgLobby.png", false);
|
||||
LoadTexture(m_textureMainMenu, TEXTURE_PATH "menus/backgrounds/bgMainMenu.png", false);
|
||||
//LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false);
|
||||
LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false);
|
||||
LoadTexture(m_textureOptionsMenu, TEXTURE_PATH "menus/backgrounds/bgOptions.png", false);
|
||||
LoadTexture(m_textureSplashScreen, TEXTURE_PATH "menus/backgrounds/bgSplash.png", false);
|
||||
|
||||
@ -102,9 +162,6 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_textureOptSensitivity, TEXTURE_PATH "menus/buttons/options/optSensitivity.png", false);
|
||||
LoadTexture(m_textureOptSfx, TEXTURE_PATH "menus/buttons/options/optSfx.png", false);
|
||||
|
||||
LoadTexture(m_textureLobbyServer, TEXTURE_PATH "menus/labels/labelServer.png", false);
|
||||
LoadTexture(m_textureLobbyIdentify, TEXTURE_PATH "menus/labels/labelIdentify.png", false);
|
||||
LoadTexture(m_textureHd, TEXTURE_PATH "menus/labels/labelHd.png", false);
|
||||
LoadTexture(m_textureHd, TEXTURE_PATH "menus/labels/labelHd.png", false);
|
||||
LoadTexture(m_textureFhd, TEXTURE_PATH "menus/labels/labelFhd.png", false);
|
||||
LoadTexture(m_textureQhd, TEXTURE_PATH "menus/labels/labelQhd.png", false);
|
||||
@ -545,10 +602,14 @@ void Engine::DisplayPovGun() {
|
||||
glLoadIdentity();
|
||||
glTranslated(xTranslation, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2i(quadWidth, 0);
|
||||
glTexCoord2f(1, 1); glVertex2i(quadWidth, quadHeight);
|
||||
glTexCoord2f(0, 1); glVertex2i(0, quadHeight);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(quadWidth, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(quadWidth, quadHeight);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, quadHeight);
|
||||
glEnd();
|
||||
|
||||
// Reset du blend function
|
||||
@ -605,34 +666,6 @@ int Engine::GetOptionsChoice() {
|
||||
return m_selectedOption;
|
||||
}
|
||||
|
||||
bool Engine::StartMultiplayerGame() {
|
||||
bool ok = true;
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(m_serverAddr.c_str(), m_username)) {
|
||||
// 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);
|
||||
|
||||
//m_world.SetSeed(m_conn.getSeed());
|
||||
m_world.SetSeed(9370707);
|
||||
m_networkgame = true;
|
||||
}
|
||||
else {
|
||||
std::cout << "Erreur de connexion." << std::endl;
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cout << "Erreur de creation de socket." << std::endl;
|
||||
ok = false;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
@ -718,81 +751,15 @@ void Engine::DisplaySplashScreen() {
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::DisplayLobbyMenu(float elapsedTime) {
|
||||
void Engine::DisplayPauseMenu() {
|
||||
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
m_textureLobbyMenu.Bind();
|
||||
m_texturePauseMenu.Bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width(), 0);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width(), Height());
|
||||
glTexCoord2f(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width(), 0);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width(), Height());
|
||||
glTexCoord2f(0, 1); glVertex2i(0, Height());
|
||||
glEnd();
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (m_settingUsername) {
|
||||
SetPlayerUsername(elapsedTime);
|
||||
}
|
||||
else if (m_settingServer) {
|
||||
SetServerAddress(elapsedTime);
|
||||
}
|
||||
|
||||
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::SetPlayerUsername(float elapsedTime) {
|
||||
m_textureLobbyIdentify.Bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95);
|
||||
glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95);
|
||||
glEnd();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
HandlePlayerInput(elapsedTime);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void Engine::SetServerAddress(float elapsedTime) {
|
||||
m_textureLobbyServer.Bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95);
|
||||
glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95);
|
||||
glEnd();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
HandlePlayerInput(elapsedTime);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void Engine::DisplayMainMenu() {
|
||||
@ -1230,27 +1197,14 @@ void Engine::Render(float elapsedTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_gamestate == GameState::LOBBY) {
|
||||
DisplayLobbyMenu(elapsedTime);
|
||||
if (m_multiReady) {
|
||||
if (StartMultiplayerGame()) {
|
||||
std::cout << "Starting multiplayer game reached" << std::endl;
|
||||
m_gamestate = GameState::PLAY;
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState();
|
||||
m_startTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else {
|
||||
std::cout << "Cannot reach server." << std::endl;
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
}
|
||||
}
|
||||
if (m_gamestate == GameState::PAUSE) {
|
||||
DisplayPauseMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_gamestate == GameState::PLAY) {
|
||||
HideCursor();
|
||||
CenterMouse();
|
||||
CenterMouse(); //D<>placement de centermouse dans l'action de jouer
|
||||
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float pollTime = 0;
|
||||
@ -1304,7 +1258,7 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
|
||||
netprot::ChunkMod* cmod = nullptr;
|
||||
if (!m_player.AmIDead() && m_mouseL) {
|
||||
if (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]) {
|
||||
@ -1328,20 +1282,14 @@ 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 ? wat : nullptr)) {
|
||||
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players, m_networkgame ? &m_chunkmod : 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;
|
||||
}
|
||||
@ -1376,7 +1324,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;
|
||||
@ -1401,7 +1349,6 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
sync_acc += tstamp - last;
|
||||
cmod_acc += tstamp - last;
|
||||
last = tstamp;
|
||||
|
||||
if (sync_acc >= 1000) {
|
||||
sync_acc -= 1000;
|
||||
@ -1416,9 +1363,9 @@ void Engine::Render(float elapsedTime) {
|
||||
m_syncs[sync.timestamp] = sync;
|
||||
}
|
||||
|
||||
if (cmod_acc >= 3000) {
|
||||
while (cmod_acc >= 3000)
|
||||
cmod_acc -= 3000;
|
||||
if (cmod_acc >= 1000) {
|
||||
while (cmod_acc >= 1000)
|
||||
cmod_acc -= 1000;
|
||||
if (!m_chunkmod_manifest.empty()) {
|
||||
ChunkMod* cmod = m_chunkmod_manifest.front();
|
||||
m_chunkmod_manifest.pop_front();
|
||||
@ -1442,9 +1389,8 @@ 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;
|
||||
Sync sync; Output out; ChunkMod cmod; BulletAdd bull; Chat chat;
|
||||
if (!prevptr)
|
||||
prevptr = m_buf.ptr;
|
||||
uint32_t bsize = m_buf.len - (pck - prevptr);
|
||||
@ -1460,9 +1406,7 @@ void Engine::Render(float elapsedTime) {
|
||||
if (m_syncs.count(sync.timestamp)) {
|
||||
Sync comp = m_syncs[sync.timestamp];
|
||||
|
||||
std::cout << sync.hp << std::endl;
|
||||
|
||||
m_player.InflictDamage(sync.hp - comp.hp);
|
||||
//m_player.InflictDamage(sync.hp - comp.hp);
|
||||
|
||||
Vector3f diff = sync.position - comp.position;
|
||||
|
||||
@ -1519,7 +1463,7 @@ void Engine::Render(float elapsedTime) {
|
||||
m_bullets[0] = bult;
|
||||
break;
|
||||
}
|
||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, 1.f);
|
||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir * 10, false, .5f);
|
||||
}
|
||||
else SystemNotification("Bullet is kraput.");
|
||||
break;
|
||||
@ -1639,11 +1583,9 @@ void Engine::DrawSlider(float centerX, float centerY, float value, float minVal,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Engine::KeyPressEvent(unsigned char key) {
|
||||
if (m_gamestate == LOBBY) {
|
||||
m_inputChar = SimulateKeyboard(key);
|
||||
return;
|
||||
}
|
||||
switch (key) {
|
||||
case 0: // A - Gauche
|
||||
if (!m_keyA) {
|
||||
@ -1674,8 +1616,7 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
else if (m_gamestate == GameState::PAUSE) {
|
||||
m_gamestate = GameState::PLAY;
|
||||
}
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState();
|
||||
//Stop();
|
||||
break;
|
||||
case 57: // Space - Sauter
|
||||
if (!m_keySpace) {
|
||||
@ -1727,12 +1668,6 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
}
|
||||
|
||||
void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
if (m_gamestate == LOBBY) {
|
||||
if (key == 38) {
|
||||
m_keyShift = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
switch (key) {
|
||||
case 0: // A - Stop gauche
|
||||
m_keyA = false;
|
||||
@ -1765,7 +1700,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
m_keyL = false;
|
||||
break;
|
||||
case 12: // M - Toggle music
|
||||
//m_audio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState();
|
||||
break;
|
||||
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").
|
||||
@ -1804,264 +1739,12 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
case 28: // 2
|
||||
m_key2 = true;
|
||||
break;
|
||||
case 38: // Shift
|
||||
m_keyShift = false;
|
||||
break;
|
||||
case 57: // Espace - Stop sauter
|
||||
m_keySpace = false;
|
||||
break;
|
||||
case 58: // Enter - comfirm input
|
||||
m_keyEnter = false;
|
||||
break;
|
||||
case 59: // backspace - remove char
|
||||
m_keyBackspace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char Engine::SimulateKeyboard(unsigned char key) {
|
||||
switch (key) {
|
||||
case 0: // A
|
||||
if (!m_keyShift) { m_inputChar = 'a'; }
|
||||
else { m_inputChar = 'A'; }
|
||||
break;
|
||||
case 1: // B
|
||||
if (!m_keyShift) { m_inputChar = 'b'; }
|
||||
else { m_inputChar = 'B'; }
|
||||
break;
|
||||
case 2: // C
|
||||
if (!m_keyShift) { m_inputChar = 'c'; }
|
||||
else { m_inputChar = 'C'; }
|
||||
break;
|
||||
case 3: // D
|
||||
if (!m_keyShift) { m_inputChar = 'd'; }
|
||||
else { m_inputChar = 'D'; }
|
||||
break;
|
||||
case 4: // E
|
||||
if (!m_keyShift) { m_inputChar = 'e'; }
|
||||
else { m_inputChar = 'E'; }
|
||||
break;
|
||||
case 5: // F
|
||||
if (!m_keyShift) { m_inputChar = 'f'; }
|
||||
else { m_inputChar = 'F'; }
|
||||
break;
|
||||
case 6: // G
|
||||
if (!m_keyShift) { m_inputChar = 'g'; }
|
||||
else { m_inputChar = 'G'; }
|
||||
break;
|
||||
case 7: // H
|
||||
if (!m_keyShift) { m_inputChar = 'h'; }
|
||||
else { m_inputChar = 'H'; }
|
||||
break;
|
||||
case 8: // I
|
||||
if (!m_keyShift) { m_inputChar = 'i'; }
|
||||
else { m_inputChar = 'I'; }
|
||||
break;
|
||||
case 9: // J
|
||||
if (!m_keyShift) { m_inputChar = 'j'; }
|
||||
else { m_inputChar = 'J'; }
|
||||
break;
|
||||
case 10: // K
|
||||
if (!m_keyShift) { m_inputChar = 'k'; }
|
||||
else { m_inputChar = 'K'; }
|
||||
break;
|
||||
case 11: // L
|
||||
if (!m_keyShift) { m_inputChar = 'l'; }
|
||||
else { m_inputChar = 'L'; }
|
||||
break;
|
||||
case 12: // M
|
||||
if (!m_keyShift) { m_inputChar = 'm'; }
|
||||
else { m_inputChar = 'M'; }
|
||||
break;
|
||||
case 13: // N
|
||||
if (!m_keyShift) { m_inputChar = 'n'; }
|
||||
else { m_inputChar = 'N'; }
|
||||
break;
|
||||
case 14: // O
|
||||
if (!m_keyShift) { m_inputChar = 'o'; }
|
||||
else { m_inputChar = 'O'; }
|
||||
break;
|
||||
case 15: // P
|
||||
if (!m_keyShift) { m_inputChar = 'p'; }
|
||||
else { m_inputChar = 'P'; }
|
||||
break;
|
||||
case 16: // Q
|
||||
if (!m_keyShift) { m_inputChar = 'q'; }
|
||||
else { m_inputChar = 'Q'; }
|
||||
break;
|
||||
case 17: // R
|
||||
if (!m_keyShift) { m_inputChar = 'r'; }
|
||||
else { m_inputChar = 'R'; }
|
||||
break;
|
||||
case 18: // S
|
||||
if (!m_keyShift) { m_inputChar = 's'; }
|
||||
else { m_inputChar = 'S'; }
|
||||
break;
|
||||
case 19: // T
|
||||
if (!m_keyShift) { m_inputChar = 't'; }
|
||||
else { m_inputChar = 'T'; }
|
||||
break;
|
||||
case 20: // U
|
||||
if (!m_keyShift) { m_inputChar = 'u'; }
|
||||
else { m_inputChar = 'U'; }
|
||||
break;
|
||||
case 21: // V
|
||||
if (!m_keyShift) { m_inputChar = 'v'; }
|
||||
else { m_inputChar = 'V'; }
|
||||
break;
|
||||
case 22: // W
|
||||
if (!m_keyShift) { m_inputChar = 'w'; }
|
||||
else { m_inputChar = 'W'; }
|
||||
break;
|
||||
case 23: // X
|
||||
if (!m_keyShift) { m_inputChar = 'x'; }
|
||||
else { m_inputChar = 'X'; }
|
||||
break;
|
||||
case 24: // Y
|
||||
if (!m_keyShift) { m_inputChar = 'y'; }
|
||||
else { m_inputChar = 'Y'; }
|
||||
break;
|
||||
case 25: // Z
|
||||
if (!m_keyShift) { m_inputChar = 'z'; }
|
||||
else { m_inputChar = 'Z'; }
|
||||
break;
|
||||
case 26: // 0
|
||||
if (!m_keyShift) { m_inputChar = '0'; }
|
||||
else { m_inputChar = ')'; }
|
||||
break;
|
||||
case 27: // 1
|
||||
if (!m_keyShift) { m_inputChar = '1'; }
|
||||
else { m_inputChar = '!'; }
|
||||
break;
|
||||
case 28: // 2
|
||||
if (!m_keyShift) { m_inputChar = '2'; }
|
||||
else { m_inputChar = '\"'; }
|
||||
break;
|
||||
case 29: // 3
|
||||
if (!m_keyShift) { m_inputChar = '3'; }
|
||||
else { m_inputChar = '/'; }
|
||||
break;
|
||||
case 30: // 4
|
||||
if (!m_keyShift) { m_inputChar = '4'; }
|
||||
else { m_inputChar = '$'; }
|
||||
break;
|
||||
case 31: // 5
|
||||
if (!m_keyShift) { m_inputChar = '5'; }
|
||||
else { m_inputChar = '%'; }
|
||||
break;
|
||||
case 32: // 6
|
||||
if (!m_keyShift) { m_inputChar = '6'; }
|
||||
else { m_inputChar = '?'; }
|
||||
break;
|
||||
case 33: // 7
|
||||
if (!m_keyShift) { m_inputChar = '7'; }
|
||||
else { m_inputChar = '&'; }
|
||||
break;
|
||||
case 34: // 8
|
||||
if (!m_keyShift) { m_inputChar = '8'; }
|
||||
else { m_inputChar = '*'; }
|
||||
break;
|
||||
case 35: // 9
|
||||
if (!m_keyShift) { m_inputChar = '9'; }
|
||||
else { m_inputChar = ')'; }
|
||||
break;
|
||||
case 38: // SHIFT
|
||||
m_keyShift = true;
|
||||
break;
|
||||
case 50: // . (Period)
|
||||
m_inputChar = '.';
|
||||
break;
|
||||
case 56: // _ (Underscore)
|
||||
if (!m_keyShift) { m_inputChar = '-'; }
|
||||
else { m_inputChar = '_'; }
|
||||
break;
|
||||
case 57: // SPACE
|
||||
m_inputChar = ' ';
|
||||
break;
|
||||
case 58: // ENTER
|
||||
m_keyEnter = true;
|
||||
break;
|
||||
case 59: // BACKSPACE
|
||||
m_keyBackspace = true;
|
||||
break;
|
||||
default:
|
||||
m_invalidChar = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int)key != 38 && !m_invalidChar) {
|
||||
m_charChanged = true;
|
||||
std::cout << "Key pressed: " << (int)key << " (" << m_inputChar << ")" << std::endl;
|
||||
}
|
||||
|
||||
m_invalidChar = false;
|
||||
return m_inputChar;
|
||||
}
|
||||
|
||||
void Engine::HandlePlayerInput(float elapsedTime) {
|
||||
static float lobbyTime = 0.0f;
|
||||
lobbyTime += elapsedTime;
|
||||
float onInterval = 0.5f;
|
||||
float offInterval = 1.0f;
|
||||
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (m_charChanged) {
|
||||
if (m_keyBackspace) {
|
||||
if (!m_currentInputString.empty()) {
|
||||
m_currentInputString.pop_back();
|
||||
}
|
||||
m_keyBackspace = false;
|
||||
}
|
||||
else if (m_keyEnter) {
|
||||
if (m_settingUsername) {
|
||||
if (!m_currentInputString.empty() &&
|
||||
m_currentInputString.size() > 1 &&
|
||||
m_currentInputString.size() < 26) {
|
||||
m_username = m_currentInputString;
|
||||
m_currentInputString = "";
|
||||
m_settingUsername = false;
|
||||
m_settingServer = true;
|
||||
}
|
||||
}
|
||||
else if (m_settingServer) {
|
||||
if (!m_currentInputString.empty()) {
|
||||
m_serverAddr = m_currentInputString;
|
||||
m_currentInputString = "";
|
||||
m_settingServer = false;
|
||||
m_multiReady = true;
|
||||
}
|
||||
}
|
||||
m_keyEnter = false;
|
||||
}
|
||||
else if (m_settingUsername && m_currentInputString.size() < 26) {
|
||||
m_currentInputString += m_inputChar;
|
||||
}
|
||||
else if (m_settingServer && m_currentInputString.size() < 15) {
|
||||
m_currentInputString += m_inputChar;
|
||||
}
|
||||
}
|
||||
|
||||
ss << m_currentInputString;
|
||||
m_charChanged = false;
|
||||
|
||||
if (lobbyTime < onInterval) {
|
||||
ss << "_";
|
||||
}
|
||||
else if (lobbyTime > onInterval && lobbyTime < offInterval) {
|
||||
ss << " ";
|
||||
}
|
||||
else {
|
||||
lobbyTime = 0.0f;
|
||||
}
|
||||
|
||||
PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f);
|
||||
}
|
||||
|
||||
|
||||
void Engine::MouseMoveEvent(int x, int y) {
|
||||
if (m_gamestate == GameState::PLAY) {
|
||||
m_player.TurnLeftRight(x - (Width() / 2));
|
||||
@ -2149,8 +1832,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
}
|
||||
else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) {
|
||||
if (m_selectedPlayOptions) {
|
||||
m_gamestate = GameState::LOBBY;
|
||||
m_settingUsername = true;
|
||||
m_gamestate = GameState::PLAY;
|
||||
}
|
||||
else {
|
||||
m_gamestate = GameState::OPTIONS;
|
||||
|
@ -46,7 +46,6 @@ private:
|
||||
int GetFps(float elapsedTime) const;
|
||||
int GetCountdown(float elapsedTime);
|
||||
int GetOptionsChoice();
|
||||
bool StartMultiplayerGame();
|
||||
|
||||
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
|
||||
|
||||
@ -63,16 +62,13 @@ private:
|
||||
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||
|
||||
void DisplaySplashScreen();
|
||||
void DisplayPauseMenu();
|
||||
|
||||
void DisplayMainMenu();
|
||||
void DrawButtonBackgrounds(float centerX, float centerY, int iterations);
|
||||
void DrawMainMenuButtons(float centerX, float centerY);
|
||||
void DrawSingleMultiButtons(float centerX, float centerY);
|
||||
|
||||
void DisplayLobbyMenu(float elapsedTime);
|
||||
void SetPlayerUsername(float elapsedTime);
|
||||
void SetServerAddress(float elapsedTime);
|
||||
|
||||
void DisplayOptionsMenu();
|
||||
void DisplayAudioMenu(float centerX, float centerY);
|
||||
void DisplayGraphicsMenu(float centerX, float centerY);
|
||||
@ -81,13 +77,11 @@ private:
|
||||
void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value);
|
||||
void DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue);
|
||||
|
||||
|
||||
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
|
||||
void ProcessNotificationQueue();
|
||||
char SimulateKeyboard(unsigned char key);
|
||||
void HandlePlayerInput(float elapsedTime);
|
||||
|
||||
//udio m_menuaudio = Audio(AUDIO_PATH "menumusic.wav");
|
||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
||||
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||
irrklang::ISound* m_powpow, * m_scream;
|
||||
irrklang::ISound* m_whoosh[MAX_BULLETS];
|
||||
|
||||
@ -105,7 +99,7 @@ private:
|
||||
BlockInfo* m_blockinfo[BTYPE_LAST];
|
||||
BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
|
||||
|
||||
GameState m_gamestate = GameState::SPLASH;
|
||||
GameState m_gamestate = GameState::PLAY;
|
||||
|
||||
Shader m_shader01;
|
||||
|
||||
@ -122,7 +116,6 @@ private:
|
||||
Texture m_texturePovGun;
|
||||
Texture m_textureSkybox;
|
||||
|
||||
Texture m_textureLobbyMenu;
|
||||
Texture m_textureMainMenu;
|
||||
Texture m_textureOptionsMenu;
|
||||
Texture m_texturePauseMenu;
|
||||
@ -132,9 +125,6 @@ private:
|
||||
Texture m_textureFhd;
|
||||
Texture m_textureQhd;
|
||||
Texture m_textureUhd;
|
||||
|
||||
Texture m_textureLobbyServer;
|
||||
Texture m_textureLobbyIdentify;
|
||||
Texture m_textureCheck;
|
||||
Texture m_textureChecked;
|
||||
|
||||
@ -200,16 +190,6 @@ private:
|
||||
bool m_selectedPlayOptions = false;
|
||||
bool m_selectedOptions = false;
|
||||
bool m_selectedQuit = false;
|
||||
|
||||
std::string m_currentInputString;
|
||||
std::string m_username;
|
||||
std::string m_serverAddr;
|
||||
char m_inputChar = 0;
|
||||
bool m_invalidChar = false;
|
||||
bool m_charChanged = false;
|
||||
bool m_settingUsername = false;
|
||||
bool m_settingServer = false;
|
||||
bool m_multiReady = false;
|
||||
|
||||
bool m_key1 = false;
|
||||
bool m_key2 = false;
|
||||
@ -219,10 +199,7 @@ private:
|
||||
bool m_keyA = false;
|
||||
bool m_keyS = false;
|
||||
bool m_keyD = false;
|
||||
bool m_keyEnter = false;
|
||||
bool m_keySpace = false;
|
||||
bool m_keyShift = false;
|
||||
bool m_keyBackspace = false;
|
||||
|
||||
bool m_mouseL = false;
|
||||
bool m_mouseR = false;
|
||||
@ -241,8 +218,9 @@ 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 = "";
|
||||
};
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 505 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
Loading…
Reference in New Issue
Block a user