Compare commits
123 Commits
d1f02c34e9
...
DemoReleas
Author | SHA1 | Date | |
---|---|---|---|
|
82747990d9 | ||
|
0782f37e0a | ||
|
75f745efb8 | ||
|
6efda6122d | ||
|
678776d6e6 | ||
|
4df53a5f9b | ||
|
90892ce7d3 | ||
|
5e1e8366ce | ||
|
7f9462881c | ||
|
2eacc0477b | ||
|
745f40bc37 | ||
|
ba6b383251 | ||
|
1065357e70 | ||
|
4a4f353250 | ||
|
63d1f997ca | ||
|
da94565c3e | ||
|
1c2a691638 | ||
|
7803f46a6b | ||
|
38bab49806 | ||
|
547d0fb3f8 | ||
|
dec9da6395 | ||
|
f564e37544 | ||
|
ca1ab7301d | ||
|
7a7ba94cbd | ||
|
ac50a044c7 | ||
|
8062d8e31d | ||
|
4d278dfdea | ||
|
da9fd2477d | ||
|
de8fe3c1c5 | ||
|
5ee3fd143b | ||
|
77a982b1fa | ||
|
e4316e7d8d | ||
|
935a977bdf | ||
|
82bae1c21a | ||
|
58c06f9f84 | ||
|
8e77565bb4 | ||
|
e5b0c742dd | ||
|
1af88ba3e3 | ||
|
383a19cbd2 | ||
|
67270a0b21 | ||
|
b101add0e7 | ||
|
0a0c70883b | ||
|
879f93e2cd | ||
|
f7934be7f9 | ||
|
0b4546eee9 | ||
|
6ba316aa2d | ||
|
bb247d0afe | ||
|
26d03ca5cc | ||
|
b8899b8f86 | ||
|
325c6b60f9 | ||
|
7b350fa403 | ||
|
71691c55c8 | ||
|
49374a7dea | ||
|
5a3ce00cb2 | ||
|
136f589975 | ||
|
6d4f592278 | ||
|
37a86d42a3 | ||
|
a08a6c7db3 | ||
|
2f3260b16a | ||
|
08204934c8 | ||
|
74875709af | ||
|
28dc760cba | ||
|
c7c38ed44d | ||
|
53e0af3f94 | ||
|
a11c52cf77 | ||
|
b1fc9d7d92 | ||
|
a85c5cc626 | ||
|
4c3803c02e | ||
|
5e09305398 | ||
|
fd1fe66d13 | ||
|
edebad86a6 | ||
|
2dbaf84844 | ||
|
e31e670720 | ||
|
d8cbc27ca9 | ||
|
c801877a0c | ||
|
f4347d35df | ||
|
f509b01827 | ||
|
18d6d58203 | ||
|
83fc600ce2 | ||
|
0e45b2b81e | ||
|
d3c6353f17 | ||
|
8fbb92ec5b | ||
|
64655856e9 | ||
|
a6b6ac870a | ||
|
5ef6ab5006 | ||
|
7ffccc8bf8 | ||
|
c9ebfd348c | ||
|
ae247a58a8 | ||
|
2f53f74ca9 | ||
|
3d0b35123a | ||
|
aacfb880f0 | ||
|
6c68114fbb | ||
|
b840e3ad19 | ||
|
7a30e43001 | ||
|
c099a3b8eb | ||
|
7498076d7a | ||
|
7c1f70646a | ||
|
5b0be2d985 | ||
|
c176fddea1 | ||
|
46298f8256 | ||
|
461a8aa11b | ||
|
9aaad6426c | ||
|
09979f1e72 | ||
|
c88143c2bc | ||
|
ff10207257 | ||
|
06cd890506 | ||
|
850f5a59d8 | ||
|
9562dc00b8 | ||
|
d6b1870b5b | ||
|
63d70be488 | ||
|
3da68297e4 | ||
|
34976ef7ec | ||
|
7d46536acc | ||
|
721fef57e2 | ||
|
7e98eeb852 | ||
|
db95c6ef10 | ||
|
486c823da1 | ||
|
fcd1c869b9 | ||
|
8bfee4a9ff | ||
|
58c97587bf | ||
|
ab87da7d88 | ||
|
c66e49ab0c | ||
|
63d8a62429 |
@@ -48,7 +48,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>ClangCL</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
@@ -3,29 +3,34 @@
|
||||
|
||||
Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {}
|
||||
|
||||
Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {}
|
||||
Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id) : m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {}
|
||||
|
||||
|
||||
Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id, bool canhurt): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id), m_canhurt(canhurt) {}
|
||||
|
||||
Bullet::~Bullet() {}
|
||||
|
||||
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
|
||||
int max = 100 / perframe;
|
||||
float damage = 0.057f;
|
||||
float damage = 0.098f;
|
||||
for (int x = 0; x < max; ++x) {
|
||||
m_currentpos += m_velocity * elapsedtime;
|
||||
|
||||
for (auto& [key, player] : mapPlayer) {
|
||||
if (key == m_shooter_id)
|
||||
continue;
|
||||
|
||||
bool hit = false;
|
||||
if ((m_currentpos - player->GetPosition()).Length() < .6f) {
|
||||
std::cout << "hit" << std::endl;
|
||||
if ((m_currentpos - player->GetPosition()).Length() < 1.5f) {
|
||||
hit = true;
|
||||
}
|
||||
if ((m_currentpos - player->GetPOV()).Length() < .2f) {
|
||||
std::cout << "headshot" << std::endl;
|
||||
else if ((m_currentpos - player->GetPOV()).Length() < .7f) {
|
||||
damage *= 2; // HEADSHOT!
|
||||
hit = true;
|
||||
}
|
||||
if (hit && !player->AmIDead()) {
|
||||
player->InflictDamage(damage);
|
||||
if (m_canhurt)
|
||||
player->InflictDamage(damage);
|
||||
player->m_hit = true;
|
||||
|
||||
if (player->AmIDead())
|
||||
@@ -38,16 +43,17 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
||||
if (!world->ChunkAt(m_currentpos))
|
||||
return true;
|
||||
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
|
||||
if (chunkmod) {
|
||||
using namespace netprot;
|
||||
ChunkMod* cmod = *chunkmod;
|
||||
cmod = new ChunkMod();
|
||||
cmod->old_b_type = world->BlockAt(m_currentpos);
|
||||
cmod->b_type = BTYPE_AIR;
|
||||
cmod->pos = m_currentpos;
|
||||
}
|
||||
if (m_canhurt) {
|
||||
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;
|
||||
}
|
||||
|
||||
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
|
||||
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
|
||||
|
@@ -14,6 +14,7 @@ class Bullet {
|
||||
public:
|
||||
Bullet(Vector3f pos, Vector3f dir);
|
||||
Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
|
||||
Bullet(Vector3f pos, Vector3f dir, uint64_t tid, bool canhurt);
|
||||
~Bullet();
|
||||
|
||||
bool Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> m_mapPlayer, netprot::ChunkMod** chunkmod);
|
||||
@@ -27,6 +28,8 @@ private:
|
||||
m_currentpos,
|
||||
m_velocity;
|
||||
uint64_t m_shooter_id = 0;
|
||||
|
||||
bool m_canhurt = true;
|
||||
|
||||
|
||||
};
|
||||
|
@@ -35,7 +35,10 @@
|
||||
#define TIME_DAMAGE_BOOST 10 //secondes
|
||||
#define TIME_INVINCIBLE_BOOST 4 //secondes
|
||||
#define STRENGTH_SPEED_BOOST 10 //Pourcentage
|
||||
#define BULLET_TIME .1
|
||||
#define BULLET_TIME .2 //secondes
|
||||
|
||||
#define SYNC_ACC 600 // ms
|
||||
#define CMOD_ACC 1000 // ms
|
||||
|
||||
typedef uint8_t BlockType;
|
||||
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
|
||||
|
@@ -29,13 +29,13 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
||||
|
||||
Keys keys = in->keys;
|
||||
uint8_t keys8 = // Reste un bit.
|
||||
(keys.forward? 0b10000000: 0) |
|
||||
(keys.backward? 0b01000000: 0) |
|
||||
(keys.left? 0b00100000: 0) |
|
||||
(keys.right? 0b00010000: 0) |
|
||||
(keys.jump? 0b00001000: 0) |
|
||||
(keys.shoot? 0b00000100: 0) |
|
||||
(keys.block? 0b00000010: 0);
|
||||
(keys.forward ? 0b10000000 : 0) |
|
||||
(keys.backward ? 0b01000000 : 0) |
|
||||
(keys.left ? 0b00100000 : 0) |
|
||||
(keys.right ? 0b00010000 : 0) |
|
||||
(keys.jump ? 0b00001000 : 0) |
|
||||
(keys.shoot ? 0b00000100 : 0) |
|
||||
(keys.block ? 0b00000010 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
|
||||
|
||||
@@ -90,14 +90,14 @@ void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
||||
|
||||
States states = out->states;
|
||||
uint8_t states8 =
|
||||
(states.jumping? 0b10000000: 0) |
|
||||
(states.shooting? 0b01000000: 0) |
|
||||
(states.hit? 0b00100000: 0) |
|
||||
(states.powerup? 0b00010000: 0) |
|
||||
(states.dead? 0b00001000: 0) |
|
||||
(states.still? 0b00000100: 0) |
|
||||
(states.jumpshot? 0b00000010: 0) |
|
||||
(states.running? 0b00000001: 0);
|
||||
(states.jumping ? 0b10000000 : 0) |
|
||||
(states.shooting ? 0b01000000 : 0) |
|
||||
(states.hit ? 0b00100000 : 0) |
|
||||
(states.powerup ? 0b00010000 : 0) |
|
||||
(states.dead ? 0b00001000 : 0) |
|
||||
(states.still ? 0b00000100 : 0) |
|
||||
(states.jumpshot ? 0b00000010 : 0) |
|
||||
(states.running ? 0b00000001 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t));
|
||||
|
||||
@@ -198,18 +198,20 @@ 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) + 2, vec8, sizeof(uint32_t) * 3);
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
uint32_t hp;
|
||||
|
||||
memcpy(&hp, &sync->hp, sizeof(float));
|
||||
|
||||
uint8_t hp8[4] = {
|
||||
uint8_t hp8[4] = {
|
||||
(uint8_t)((hp >> 24) & 0xFF),
|
||||
(uint8_t)((hp >> 16) & 0xFF),
|
||||
(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;
|
||||
}
|
||||
|
||||
@@ -218,7 +220,8 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(tinfo->name) + 1;
|
||||
|
||||
memcpy(*buf + 1, &tinfo->name, namesize);
|
||||
strcpy(*buf + 1, namesize, tinfo->name);
|
||||
|
||||
uint64_t tid = tinfo->id;
|
||||
uint8_t tid8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((tid >> 56) & 0xFF),
|
||||
@@ -241,7 +244,8 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(linfo->name) + 1;
|
||||
|
||||
memcpy(*buf + 1, &linfo->name, namesize);
|
||||
strcpy(*buf + 1, namesize, linfo->name);
|
||||
|
||||
uint64_t sid = linfo->sid;
|
||||
uint8_t sid8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((sid >> 56) & 0xFF),
|
||||
@@ -278,7 +282,8 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
|
||||
|
||||
size_t namesize = std::strlen(pinfo->name) + 1;
|
||||
|
||||
memcpy(*buf + 1, &pinfo->name, namesize);
|
||||
strcpy(*buf + 1, namesize, pinfo->name);
|
||||
|
||||
uint64_t id = pinfo->id;
|
||||
uint8_t id8[sizeof(uint64_t)] = {
|
||||
(uint8_t)((id >> 56) & 0xFF),
|
||||
@@ -523,7 +528,7 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
|
||||
|
||||
|
||||
bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Input))
|
||||
return false;
|
||||
|
||||
@@ -538,7 +543,7 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
|
||||
(uint64_t)diff[5] << 16 |
|
||||
(uint64_t)diff[6] << 8 |
|
||||
(uint64_t)diff[7];
|
||||
|
||||
|
||||
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
|
||||
in->sid =
|
||||
(uint64_t)diff[0] << 56 |
|
||||
@@ -583,7 +588,7 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(Output* out, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Output))
|
||||
return false;
|
||||
|
||||
@@ -662,7 +667,7 @@ bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Sync))
|
||||
return false;
|
||||
|
||||
@@ -703,7 +708,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[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
|
||||
memcpy(subvec, &buf[1 + 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 |
|
||||
@@ -722,21 +727,21 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
|
||||
|
||||
uint8_t hp8[4];
|
||||
|
||||
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
|
||||
memcpy(&hp8, &buf[1 + 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 |
|
||||
(uint32_t)hp8[2] << 8 |
|
||||
(uint32_t)hp8[3];
|
||||
(uint32_t)hp8[1] << 16 |
|
||||
(uint32_t)hp8[2] << 8 |
|
||||
(uint32_t)hp8[3];
|
||||
|
||||
memcpy(&sync->hp, &hp, sizeof(float));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(LoginInfo))
|
||||
return false;
|
||||
|
||||
@@ -745,7 +750,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t *buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
memcpy(&tinfo->name, &buf[1], namesize);
|
||||
strcpy(tinfo->name, namesize, &buf[1]);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
@@ -764,7 +769,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(LoginInfo))
|
||||
return false;
|
||||
|
||||
@@ -773,7 +778,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t *buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
memcpy(&linfo->name, &buf[1], namesize);
|
||||
strcpy(linfo->name, namesize, &buf[1]);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
@@ -803,7 +808,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(PlayerInfo))
|
||||
return false;
|
||||
|
||||
@@ -812,7 +817,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t *buflen) {
|
||||
if (namesize > 32)
|
||||
return false;
|
||||
|
||||
memcpy(&pinfo->name, &buf[1], namesize);
|
||||
strcpy(pinfo->name, namesize, &buf[1]);
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
||||
@@ -842,7 +847,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(GameInfo))
|
||||
return false;
|
||||
|
||||
@@ -885,7 +890,7 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(Chat* chat, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Chat))
|
||||
return false;
|
||||
|
||||
@@ -935,7 +940,7 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
|
||||
strcpy(chat->mess, 140, ciboire);
|
||||
|
||||
//*buflen = messsize + sizeof(uint64_t) * 3 + 1;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1037,7 +1042,7 @@ bool netprot::Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t *buflen) {
|
||||
bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(ErrorLog))
|
||||
return false;
|
||||
|
||||
@@ -1064,7 +1069,7 @@ netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
|
||||
return (netprot::PACKET_TYPE)buf[0];
|
||||
}
|
||||
|
||||
netprot::Packet netprot::getPack(char* buf, uint32_t *buflen) {
|
||||
netprot::Packet netprot::getPack(char* buf, uint32_t* buflen) {
|
||||
Packet pck = { nullptr, PACKET_TYPE::ERR };
|
||||
Input* in = nullptr;
|
||||
Output* out = nullptr;
|
||||
@@ -1167,13 +1172,12 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
|
||||
return pck;
|
||||
}
|
||||
|
||||
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf) {
|
||||
std::vector<char*> lsPck;
|
||||
int len = buf->tmp? buf->tmp - buf->ptr: 0,
|
||||
void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector<char*>* lsPck) {
|
||||
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
||||
end = 0;
|
||||
char * cursor = buf->tmp ? buf->tmp: nullptr ,
|
||||
* next = buf->tmp ? buf->tmp + 1: buf->ptr,
|
||||
* last = buf->tmp ? buf->tmp: buf->ptr;
|
||||
char* cursor = buf->tmp ? buf->tmp : nullptr,
|
||||
* next = buf->tmp ? buf->tmp + 1 : buf->ptr,
|
||||
* last = buf->tmp ? buf->tmp : buf->ptr;
|
||||
bool ended = true;
|
||||
struct pollfd fds[1];
|
||||
|
||||
@@ -1184,15 +1188,15 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
|
||||
if (!poll(fds, 1, 0)) {
|
||||
if (ended)
|
||||
buf->tmp = nullptr;
|
||||
return lsPck;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
|
||||
if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
|
||||
if (ended)
|
||||
buf->tmp = nullptr;
|
||||
return lsPck;
|
||||
}
|
||||
return;
|
||||
}
|
||||
len += bytes;
|
||||
end = len;
|
||||
|
||||
@@ -1215,24 +1219,14 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
|
||||
|
||||
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
|
||||
if (cmp == 0) {
|
||||
if (!outbuf) {
|
||||
lsPck.push_back(last);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
else {
|
||||
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
|
||||
lsPck.push_back(&outbuf->ptr[cursor - last]);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
lsPck->push_back(last);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!outbuf)
|
||||
buf->tmp = last;
|
||||
buf->tmp = last;
|
||||
cursor = &buf->ptr[len];
|
||||
next = cursor + 1;
|
||||
break;
|
||||
@@ -1241,8 +1235,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* outbuf) {
|
||||
std::vector<char*> lsPck;
|
||||
void netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector<char*>* lsPck) {
|
||||
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
||||
end = 0;
|
||||
char* cursor = buf->tmp ? buf->tmp : nullptr,
|
||||
@@ -1260,14 +1253,14 @@ std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in
|
||||
if (!poll(fds, 1, 0)) {
|
||||
if (ended)
|
||||
buf->tmp = nullptr;
|
||||
return lsPck;
|
||||
return;
|
||||
}
|
||||
|
||||
int bytes = recvfrom(sock, &buf->ptr[len], buf->len - len, 0, (sockaddr*)&sockad, &socklen);
|
||||
if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
|
||||
if (ended)
|
||||
buf->tmp = nullptr;
|
||||
return lsPck;
|
||||
return;
|
||||
}
|
||||
len += bytes;
|
||||
end = len;
|
||||
@@ -1291,24 +1284,14 @@ std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in
|
||||
|
||||
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
|
||||
if (cmp == 0) {
|
||||
if (!outbuf) {
|
||||
lsPck.push_back(last);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
else {
|
||||
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
|
||||
lsPck.push_back(&outbuf->ptr[cursor - last]);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
lsPck->push_back(last);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!outbuf)
|
||||
buf->tmp = last;
|
||||
buf->tmp = last;
|
||||
cursor = &buf->ptr[len];
|
||||
next = cursor + 1;
|
||||
break;
|
||||
|
@@ -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[32];
|
||||
char *name = new char[32];
|
||||
uint64_t id = 0;
|
||||
TeamInfo() {}
|
||||
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(tem->name, name); }
|
||||
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(name, 32, tem->name); }
|
||||
~TeamInfo() { delete[] name; }
|
||||
};
|
||||
|
||||
struct LoginInfo { // cli <-> srv TCP once
|
||||
char name[32];
|
||||
char *name = new char[32];
|
||||
uint64_t sid = 0,
|
||||
tid = 0;
|
||||
LoginInfo() {}
|
||||
LoginInfo(LoginInfo* ply): sid(ply->sid), tid(ply->tid) { strcpy(ply->name, name); }
|
||||
LoginInfo(LoginInfo* log): sid(log->sid), tid(log->tid) { strcpy(name, 32, log->name); }
|
||||
~LoginInfo() { delete[] name; }
|
||||
};
|
||||
|
||||
struct PlayerInfo { // cli <-> srv TCP once
|
||||
char name[32];
|
||||
char *name = new char[32];
|
||||
uint64_t id = 0,
|
||||
tid = 0;
|
||||
PlayerInfo() {}
|
||||
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());
|
||||
}
|
||||
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; }
|
||||
};
|
||||
|
||||
struct GameInfo { // cli <-> srv TCP event (before game start)/ once
|
||||
@@ -125,11 +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() {/* delete[] 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; }
|
||||
};
|
||||
|
||||
struct ChunkMod {
|
||||
@@ -144,10 +143,11 @@ namespace netprot {
|
||||
};
|
||||
|
||||
struct ErrorLog { // srv -> cli TCP event
|
||||
char mess[140];
|
||||
bool is_fatal;
|
||||
char *mess = new char[140];
|
||||
bool is_fatal = false;
|
||||
ErrorLog() {};
|
||||
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(err->mess, mess); }
|
||||
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(mess, 140, err->mess); }
|
||||
~ErrorLog() { delete[] mess; }
|
||||
};
|
||||
|
||||
/* Fonctions */
|
||||
@@ -193,8 +193,8 @@ namespace netprot {
|
||||
template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf);
|
||||
template <class T> void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad);
|
||||
|
||||
std::vector<char*> recvPacks(SOCKET sock, Buffer* buf, Buffer* oufbuf = nullptr);
|
||||
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* oufbuf = nullptr);
|
||||
void recvPacks(SOCKET sock, Buffer* buf, std::vector<char*>* lsPck);
|
||||
void recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector<char*>* lsPck);
|
||||
|
||||
/* Templates */
|
||||
|
||||
|
@@ -4,14 +4,15 @@
|
||||
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
|
||||
m_velocity = Vector3f(0, 0, 0);
|
||||
m_airborne = true;
|
||||
m_hp = 1.0f; //TODO: Remettre <20> 1.0f
|
||||
m_hp = 1.0f;
|
||||
m_sensitivity = 0.5f;
|
||||
m_username = "Zelda Bee-Bop56";
|
||||
}
|
||||
|
||||
Player::~Player() {}
|
||||
|
||||
void Player::TurnLeftRight(float value) {
|
||||
m_rotY += value;
|
||||
void Player::TurnLeftRight(float value, float sensitivity) {
|
||||
m_rotY += value * sensitivity;
|
||||
if (m_rotY > 360) m_rotY = 0;
|
||||
else if (m_rotY < -360) m_rotY = 0;
|
||||
|
||||
@@ -25,8 +26,8 @@ void Player::TurnLeftRight(float value) {
|
||||
m_direction.Normalize();
|
||||
}
|
||||
|
||||
void Player::TurnTopBottom(float value) {
|
||||
m_rotX += value;
|
||||
void Player::TurnTopBottom(float value, float sensitivity) {
|
||||
m_rotX += value * sensitivity;
|
||||
if (m_rotX > 80) m_rotX = 80;
|
||||
else if (m_rotX < -80) m_rotX = -80;
|
||||
|
||||
@@ -78,7 +79,7 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
|
||||
}
|
||||
|
||||
if (shoot) // Recoil!
|
||||
TurnTopBottom(-1);
|
||||
TurnTopBottom(-1, 1.0f);
|
||||
|
||||
return delta;
|
||||
}
|
||||
@@ -122,35 +123,55 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
if (input.x > 0)
|
||||
input.x = m_velocity.x = 0.5f;
|
||||
else
|
||||
input.x = m_velocity.x = -0.5f;
|
||||
m_velocity.y = 0.3;
|
||||
m_velocity.z *= .5f;
|
||||
}
|
||||
else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.x = m_velocity.x = 0;
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.x = m_velocity.x = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
}
|
||||
|
||||
bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
if (input.z > 0)
|
||||
input.z = m_velocity.z = 0.5f;
|
||||
else
|
||||
input.z = m_velocity.z = -0.5f;
|
||||
m_velocity.y = 0.3;
|
||||
m_velocity.x *= .5f;
|
||||
}
|
||||
else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.z = m_velocity.z = 0;
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.z = m_velocity.z = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
//bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
//bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.x > 0)
|
||||
// input.x = m_velocity.x = 0.5f;
|
||||
// else
|
||||
// input.x = m_velocity.x = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.x = m_velocity.x = 0;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
//bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
//bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.z > 0)
|
||||
// input.z = m_velocity.z = 0.5f;
|
||||
// else
|
||||
// input.z = m_velocity.z = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.z = m_velocity.z = 0;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
|
||||
/* Fin gestion de collisions */
|
||||
/* Gestion de la friction */
|
||||
|
||||
@@ -204,11 +225,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const {
|
||||
transformation.ApplyRotation(-m_rotX, 1, 0, 0);
|
||||
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
|
||||
|
||||
|
||||
if (rel) transformation.ApplyTranslation(-GetPOV());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Player::GetBooster(Booster boosttype)
|
||||
@@ -270,8 +287,24 @@ Vector3f Player::GetDirection() const { return m_direction; }
|
||||
|
||||
std::string Player::GetUsername() const { return m_username; }
|
||||
|
||||
void Player::SetUsername(std::string username) {
|
||||
m_username = username;
|
||||
}
|
||||
|
||||
float Player::GetSensitivity() const {
|
||||
return m_sensitivity;
|
||||
}
|
||||
|
||||
void Player::SetSensitivity(float sensitivity) {
|
||||
m_sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
float Player::GetHP() const { return m_hp; }
|
||||
|
||||
void Player::SetHP(float hp) {
|
||||
m_hp = hp;
|
||||
}
|
||||
|
||||
void Player::Teleport(int& x, int& z) {
|
||||
m_position.x -= x * CHUNK_SIZE_X;
|
||||
m_position.z -= z * CHUNK_SIZE_Z;
|
||||
@@ -285,9 +318,6 @@ void Player::InflictDamage(float hitPoints) {
|
||||
|
||||
if (m_hp < 0)
|
||||
m_hp == 0;
|
||||
//if (AmIDead())
|
||||
//{ // Quand le joueur est mort.
|
||||
//}
|
||||
}
|
||||
|
||||
int Player::getScore() const { return m_score; }
|
||||
|
@@ -16,8 +16,8 @@ public:
|
||||
Player(const Vector3f& position, float rotX = 0, float rotY = 0);
|
||||
~Player();
|
||||
|
||||
void TurnLeftRight(float value);
|
||||
void TurnTopBottom(float value);
|
||||
void TurnLeftRight(float value, float sensitivity);
|
||||
void TurnTopBottom(float value, float sensitivity);
|
||||
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
|
||||
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime);
|
||||
void GetBooster(Booster boosttype);
|
||||
@@ -32,7 +32,11 @@ public:
|
||||
Vector3f GetVelocity() const;
|
||||
Vector3f GetPOV() const;
|
||||
std::string GetUsername() const;
|
||||
void SetUsername(std::string username);
|
||||
float GetSensitivity() const;
|
||||
void SetSensitivity(float sensitivity);
|
||||
float GetHP() const;
|
||||
void SetHP(float hp);
|
||||
void Teleport(int& x, int& z);
|
||||
|
||||
bool GetIsAirborne() const;
|
||||
@@ -44,6 +48,8 @@ public:
|
||||
std::string m_username;
|
||||
bool m_hit = false;
|
||||
|
||||
bool Eulogy = false;
|
||||
|
||||
private:
|
||||
uint64_t getId() const;
|
||||
|
||||
@@ -61,6 +67,7 @@ protected:
|
||||
float timeboostspeed;
|
||||
float timeboostdamage;
|
||||
float timeboostinvincible;
|
||||
float m_sensitivity;
|
||||
|
||||
float m_hp;
|
||||
|
||||
@@ -69,8 +76,6 @@ protected:
|
||||
bool boostdamage;
|
||||
bool boostinvincible;
|
||||
|
||||
|
||||
|
||||
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
|
||||
};
|
||||
#endif //_PLAYER_H__
|
||||
|
@@ -49,8 +49,6 @@ void World::RemoveChunk(int nbReduit)
|
||||
if (x > WORLD_SIZE_X - nbReduit)
|
||||
chk = m_chunks.Remove(x, y);
|
||||
|
||||
// TODO: MakeDirty() les voisins pour qu'ils se redessinent.
|
||||
|
||||
if (!chk)
|
||||
continue;
|
||||
|
||||
@@ -167,7 +165,6 @@ void World::GetScope(unsigned int& x, unsigned int& y) {
|
||||
|
||||
void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
UpdateWorld(player_pos, blockinfo);
|
||||
//TransposeWorld(player_pos, bullets);
|
||||
}
|
||||
|
||||
netprot::ChunkMod* World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net) {
|
||||
@@ -258,7 +255,6 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]
|
||||
int side = 0;
|
||||
int threads = 0;
|
||||
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
|
||||
//std::future<void> delThList[THREADS_DELETE_CHUNKS];
|
||||
|
||||
if (frameGenerate > 0) --frameGenerate;
|
||||
if (frameUpdate > 0) --frameUpdate;
|
||||
@@ -349,101 +345,6 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]
|
||||
|
||||
side = 0;
|
||||
threads = 0;
|
||||
|
||||
//if (!frameUpdate)
|
||||
// while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2) {
|
||||
// int tx = -side, ty = -side;
|
||||
|
||||
// for (; tx <= side; ++tx) {
|
||||
// if (frameUpdate)
|
||||
// break;
|
||||
// unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
// if (ChunkAt(chx, 1, chy) &&
|
||||
// ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
// updateThList[threads++] =
|
||||
// std::async(std::launch::async,
|
||||
// [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) {
|
||||
// chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
|
||||
// if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
|
||||
// }
|
||||
// }
|
||||
// for (; ty <= side; ++ty) {
|
||||
// if (frameUpdate)
|
||||
// break;
|
||||
// unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
// if (ChunkAt(chx, 1, chy) &&
|
||||
// ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
// updateThList[threads++] =
|
||||
// std::async(std::launch::async,
|
||||
// [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) {
|
||||
// chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
|
||||
// if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
|
||||
// }
|
||||
// }
|
||||
// for (; tx >= -side; --tx) {
|
||||
// if (frameUpdate)
|
||||
// break;
|
||||
// unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
// if (ChunkAt(chx, 1, chy) &&
|
||||
// ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
// updateThList[threads++] =
|
||||
// std::async(std::launch::async,
|
||||
// [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) {
|
||||
// chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
|
||||
// if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
|
||||
// }
|
||||
// }
|
||||
// for (; ty >= -side; --ty) {
|
||||
// if (frameUpdate)
|
||||
// break;
|
||||
// unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
// if (ChunkAt(chx, 1, chy) &&
|
||||
// ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
// updateThList[threads++] =
|
||||
// std::async(std::launch::async,
|
||||
// [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) {
|
||||
// chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
|
||||
// if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
|
||||
// }
|
||||
// }
|
||||
// if (frameUpdate)
|
||||
// break;
|
||||
// ++side;
|
||||
// }
|
||||
|
||||
//if (threads > 0) {
|
||||
// for (int i = 0; i < threads; ++i) {
|
||||
// updateThList[i].wait();
|
||||
// Chunk* chunk = updateThList[i].get();
|
||||
// chunk->FlushMeshToVBO();
|
||||
// }
|
||||
//}
|
||||
|
||||
threads = 0;
|
||||
|
||||
//int del = THREADS_DELETE_CHUNKS;
|
||||
//while (!m_tbDeleted.empty() && del--) { // Moins rapide que le bout en dessous, mais -beaucoup- plus stable.
|
||||
// m_tbDeleted.back()->FlushVBO();
|
||||
// m_tbDeleted.back()->~Chunk();
|
||||
// m_tbDeleted.pop_back();
|
||||
//}
|
||||
|
||||
/*while (!m_tbDeleted.empty() && !frameDelete) {
|
||||
if (m_tbDeleted.back()) {
|
||||
m_tbDeleted.back()->FlushVBO();
|
||||
delThList[threads] =
|
||||
std::async(std::launch::async,
|
||||
[](Chunk* chunk) { delete chunk; }, m_tbDeleted.back());
|
||||
m_tbDeleted.pop_back();
|
||||
if (++threads > THREADS_DELETE_CHUNKS) frameDelete = FRAMES_DELETE_CHUNKS;
|
||||
}
|
||||
else m_tbDeleted.pop_back();
|
||||
}*/
|
||||
|
||||
/*for (int x = 0; x < threads; ++x) {
|
||||
delThList[x].wait();
|
||||
delThList[x].get();
|
||||
}*/
|
||||
}
|
||||
|
||||
int World::GettbDeleted() const { return m_tbDeleted.size(); }
|
||||
|
@@ -48,7 +48,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>ClangCL</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
@@ -4,16 +4,18 @@
|
||||
|
||||
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() { closesocket(m_sock); }
|
||||
Connection::~Connection() {
|
||||
delete player;
|
||||
closesocket(m_sock); }
|
||||
|
||||
uint64_t Connection::GetHash(bool self) const { return self ? m_loginfo.sid : m_playinfo.id; }
|
||||
|
||||
@@ -51,13 +53,15 @@ void Connection::getPacks(SOCKET sock) {
|
||||
std::vector<char*> lsPck;
|
||||
Input in;
|
||||
Sync sync;
|
||||
lsPck = recvPacksFrom(sock, &m_buf, m_addr);
|
||||
recvPacksFrom(sock, &m_buf, m_addr, &lsPck);
|
||||
for (auto& pck : lsPck) {
|
||||
uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
|
||||
switch (netprot::getType(pck, 1)) {
|
||||
using enum netprot::PACKET_TYPE;
|
||||
case INPUT:
|
||||
if (Deserialize(&in, pck, &bsize)) {
|
||||
if (player->AmIDead())
|
||||
break;
|
||||
else if (Deserialize(&in, pck, &bsize)) {
|
||||
m_input_manifest[in.timestamp] = in;
|
||||
m_input_vector.push_back(in);
|
||||
}
|
||||
@@ -75,8 +79,23 @@ void Connection::getPacks(SOCKET sock) {
|
||||
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
||||
static int outs = 0;
|
||||
static Timestamp last = 0;
|
||||
static uint32_t lasttimer = timer;
|
||||
|
||||
if (m_output_vector.empty() && player->AmIDead()) {
|
||||
if (timer != lasttimer) {
|
||||
lasttimer = timer;
|
||||
Sync sync;
|
||||
sync.timestamp = sync.sid = m_loginfo.sid;
|
||||
sync.hp = 0;
|
||||
sync.ammo = -1;
|
||||
sync.timer = timer;
|
||||
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
|
||||
}
|
||||
}
|
||||
|
||||
while (!m_output_vector.empty()) {
|
||||
Output out = m_output_vector.front();
|
||||
|
||||
for (auto& [key, conn] : conns) {
|
||||
if (m_playinfo.id == conn->GetHash(false))
|
||||
continue;
|
||||
@@ -89,16 +108,23 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
||||
|
||||
outs += out.timestamp + last;
|
||||
|
||||
if (outs >= 1000) {
|
||||
outs -= 1000;
|
||||
static bool syncdead = false;
|
||||
bool dead = player->AmIDead();
|
||||
|
||||
if (outs >= SYNC_ACC || (!syncdead && dead)) {
|
||||
Sync sync;
|
||||
sync.hp = player->GetHP();
|
||||
outs -= SYNC_ACC;
|
||||
sync.timestamp = out.timestamp;
|
||||
sync.position = out.position;
|
||||
sync.sid = m_loginfo.sid;
|
||||
sync.timer = timer;
|
||||
sync.timestamp = out.timestamp;
|
||||
sync.ammo = -1;
|
||||
sync.hp = player->GetHP();
|
||||
if (dead) {
|
||||
sync.timestamp = m_loginfo.sid;
|
||||
syncdead = true;
|
||||
}
|
||||
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
|
||||
}
|
||||
|
||||
@@ -112,27 +138,33 @@ Timestamp Connection::Run(World* world) {
|
||||
Timestamp tstamp = 0;
|
||||
float el;
|
||||
|
||||
if (m_input_manifest.size() < 2)
|
||||
bool dead = player->AmIDead();
|
||||
|
||||
if (m_input_manifest.size() < 2 && !dead)
|
||||
return tstamp;
|
||||
|
||||
if (player->AmIDead()) {
|
||||
m_input_manifest.clear();
|
||||
return tstamp;
|
||||
}
|
||||
|
||||
while (m_last_in < m_input_vector.size() - 1) {
|
||||
in = m_input_vector.at(m_last_in + 1);
|
||||
last = m_input_vector.at(m_last_in);
|
||||
|
||||
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
||||
|
||||
if (m_shoot_acc > 0.) {
|
||||
m_shoot_acc -= el;
|
||||
if (m_shoot_acc < 0.)
|
||||
m_shoot_acc = 0;
|
||||
while (m_last_in < m_input_vector.size() - 1 || dead) {
|
||||
if (!dead) {
|
||||
in = m_input_vector.at(m_last_in + 1);
|
||||
last = m_input_vector.at(m_last_in);
|
||||
if (in.timestamp <= m_tstamp) {
|
||||
++m_last_in;
|
||||
continue;
|
||||
}
|
||||
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
||||
if (m_shoot_acc > 0.) {
|
||||
m_shoot_acc -= el;
|
||||
if (m_shoot_acc < 0.)
|
||||
m_shoot_acc = 0.;
|
||||
}
|
||||
player->SetDirection(in.direction);
|
||||
}
|
||||
|
||||
player->SetDirection(in.direction);
|
||||
else {
|
||||
el = 1. / 60.;
|
||||
in = Input();
|
||||
|
||||
}
|
||||
|
||||
player->ApplyPhysics(player->GetInput(in.keys.forward,
|
||||
in.keys.backward,
|
||||
in.keys.left,
|
||||
@@ -144,8 +176,11 @@ Timestamp Connection::Run(World* world) {
|
||||
player->Killer = GetHash(true);
|
||||
}
|
||||
|
||||
out.states.jumping = player->GetIsAirborne(); //abs(player->GetVelocity().y) > .2f;
|
||||
out.states.running = player->GetVelocity().Length() > .5f;
|
||||
out.states.jumping = player->GetIsAirborne();
|
||||
|
||||
Vector3f horSpeed = player->GetVelocity();
|
||||
horSpeed.y = 0;
|
||||
out.states.running = horSpeed.Length() > .2f;
|
||||
out.states.still = !out.states.running && !out.states.jumping;
|
||||
out.states.hit = player->m_hit;
|
||||
player->m_hit = false;
|
||||
@@ -166,7 +201,7 @@ Timestamp Connection::Run(World* world) {
|
||||
player->GetDirection(),
|
||||
block, true);
|
||||
if (cmod)
|
||||
ChunkDiffs.emplace_back(cmod);
|
||||
ChunkDiffs.push_back(std::move(cmod));
|
||||
}
|
||||
}
|
||||
else toggle = false;
|
||||
@@ -188,9 +223,12 @@ Timestamp Connection::Run(World* world) {
|
||||
out.id = m_playinfo.id;
|
||||
m_output_manifest[out.timestamp] = out;
|
||||
m_output_vector.push_back(out);
|
||||
tstamp = out.timestamp;
|
||||
m_tstamp = tstamp = out.timestamp;
|
||||
|
||||
++m_last_in;
|
||||
if (!dead)
|
||||
++m_last_in;
|
||||
|
||||
dead = false;
|
||||
}
|
||||
|
||||
return tstamp;
|
||||
|
@@ -16,8 +16,8 @@ public:
|
||||
Connection(
|
||||
SOCKET sock,
|
||||
sockaddr_in sockaddr,
|
||||
LoginInfo log,
|
||||
PlayerInfo play);
|
||||
LoginInfo *log,
|
||||
PlayerInfo *play);
|
||||
~Connection();
|
||||
|
||||
Player* player = nullptr;
|
||||
|
@@ -3,6 +3,11 @@
|
||||
int main() {
|
||||
std::unique_ptr<Server> server = std::make_unique<Server>();
|
||||
if (server->Init() == 0)
|
||||
if (server->Ready() == 0)
|
||||
while (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;
|
||||
PlayerInfo* play = new PlayerInfo();
|
||||
|
||||
m_buf.len = BUFFER_LENGTH;
|
||||
Packet pck = getPack(&m_buf);
|
||||
@@ -153,23 +153,20 @@ int Server::Ready() {
|
||||
|
||||
sendPackTo<LoginInfo>(m_sock_udp, log, &m_buf, &sockad);
|
||||
|
||||
play.id = getUniqueId();
|
||||
play.tid = log->tid;
|
||||
strcpy(play.name, log->name);
|
||||
play->id = getUniqueId();
|
||||
play->tid = log->tid;
|
||||
strcpy(play->name, 32, 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);
|
||||
std::cout << m_game.seed << std::endl;
|
||||
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;
|
||||
}
|
||||
@@ -201,8 +198,12 @@ void Server::Run() {
|
||||
m_world->BuildWorld();
|
||||
|
||||
for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync.
|
||||
int x = 0,// (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)),// -(CHUNK_SIZE_X * WORLD_SIZE_X / 2),
|
||||
y = 0;// (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1));// -(CHUNK_SIZE_Y * WORLD_SIZE_Y / 2);
|
||||
if (!conn) {
|
||||
m_conns.erase(key);
|
||||
continue;
|
||||
}
|
||||
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 16,
|
||||
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 16;
|
||||
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;
|
||||
@@ -216,92 +217,102 @@ void Server::Run() {
|
||||
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
|
||||
}
|
||||
|
||||
int timer = m_game.countdown, sync_acc = 0, deadplayers = 0;
|
||||
int timer = m_game.countdown, timer_acc = 0, deadplayers = 0;
|
||||
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
|
||||
Timestamp last = 0;
|
||||
std::vector<Chat*> chatlog;
|
||||
std::vector<ChunkMod*> chunkdiffs;
|
||||
std::vector<Bullet*> bullets, outbox_bullets;
|
||||
std::vector<Bullet*> bullets;
|
||||
std::vector<std::vector<Bullet*>::iterator> bullit;
|
||||
std::vector<BulletAdd*> netbull;
|
||||
std::vector<char*> lsPck;
|
||||
|
||||
Chat* startchat = new Chat();
|
||||
startchat->src_id = 0;
|
||||
char startmess[] = "How would -YOU- like to die today, motherfuckers?";
|
||||
|
||||
char startmess[] = "How would -YOU- like to die today, motherf-words?";
|
||||
float endtime = 0.;
|
||||
strcpy(startchat->mess, 140, startmess);
|
||||
|
||||
chatlog.emplace_back(startchat);
|
||||
|
||||
while (!endgame) {
|
||||
while (!endgame && endtime < 1.) {
|
||||
using namespace std::chrono;
|
||||
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
|
||||
|
||||
if (last == 0)
|
||||
last = tstamp;
|
||||
sync_acc += tstamp - last;
|
||||
if (sync_acc >= 1000) {
|
||||
while (sync_acc >= 1000)
|
||||
sync_acc -= 1000;
|
||||
--timer;
|
||||
timer_acc += tstamp - last;
|
||||
if (timer_acc >= 1000) {
|
||||
while (timer_acc >= 1000)
|
||||
timer_acc -= 1000;
|
||||
if (!endgame)
|
||||
--timer;
|
||||
std::string str = "Timer: ";
|
||||
Log(str.append(std::to_string(timer)), false, false);
|
||||
}
|
||||
last = tstamp;
|
||||
|
||||
for (auto& [key, conn] : m_conns) {
|
||||
|
||||
for (auto& [key, conn] : m_conns) {
|
||||
|
||||
/* In */
|
||||
|
||||
std::vector<char*> lsPck;
|
||||
Input in; Chat chat; Sync sync;
|
||||
Input in; Sync sync;
|
||||
|
||||
lsPck = recvPacks(m_sock_udp, &m_buf);
|
||||
recvPacks(m_sock_udp, &m_buf, &lsPck);
|
||||
for (auto& pck : lsPck) {
|
||||
uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
|
||||
switch (netprot::getType(pck, 1)) {
|
||||
using enum netprot::PACKET_TYPE;
|
||||
case INPUT:
|
||||
if (Deserialize(&in, pck, &bsize))
|
||||
m_conns[in.sid]->AddInput(in);
|
||||
if (Deserialize(&in, pck, &bsize)) {
|
||||
if (m_conns.count(in.sid))
|
||||
m_conns[in.sid]->AddInput(in);
|
||||
}
|
||||
break;
|
||||
case SYNC:
|
||||
if (Deserialize(&sync, pck, &bsize)) {}
|
||||
break;
|
||||
case CHAT:
|
||||
//if (Deserialize(&chat, pck, &bsize))
|
||||
//chatlog.push_back(chat);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
lsPck.clear();
|
||||
if (!lsPck.empty())
|
||||
lsPck.clear();
|
||||
|
||||
/* Process */
|
||||
|
||||
if (conn->m_nsync) {
|
||||
|
||||
Timestamp tstamp = conn->Run(m_world);
|
||||
|
||||
if (conn->player->AmIDead()) {
|
||||
if (conn->player->AmIDead() && !conn->player->Eulogy) {
|
||||
Chat* chat = new Chat();
|
||||
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
||||
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
||||
|
||||
std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
|
||||
Player* murderer = m_conns.at(conn->player->Killer)->player;
|
||||
|
||||
if (murderer != conn->player)
|
||||
murderer->addPoint();
|
||||
|
||||
std::string killer = murderer->GetUsername();
|
||||
|
||||
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
|
||||
|
||||
strcpy(chat->mess, 140, mess.c_str());
|
||||
chatlog.emplace_back(chat);
|
||||
++deadplayers;
|
||||
|
||||
conn->player->Eulogy = true;
|
||||
conn->m_nsync = false;
|
||||
}
|
||||
else {
|
||||
for (auto& chmo : conn->ChunkDiffs)
|
||||
chunkdiffs.emplace_back(std::move(chmo));
|
||||
conn->ChunkDiffs.clear();
|
||||
if (!conn->ChunkDiffs.empty())
|
||||
conn->ChunkDiffs.clear();
|
||||
|
||||
for (auto& bull : conn->Bullets) {
|
||||
bullets.emplace_back(bull);
|
||||
Log("POW!", false, false);
|
||||
BulletAdd* nbul = new BulletAdd();
|
||||
nbul->pos = bull->getPos();
|
||||
nbul->dir = bull->getVel();
|
||||
@@ -310,68 +321,149 @@ void Server::Run() {
|
||||
|
||||
netbull.emplace_back(std::move(nbul));
|
||||
}
|
||||
conn->Bullets.clear();
|
||||
if (!conn->Bullets.empty())
|
||||
conn->Bullets.clear();
|
||||
}
|
||||
|
||||
/* Out */
|
||||
|
||||
conn->sendPacks(m_sock_udp, m_conns, timer);
|
||||
}
|
||||
if ((deadplayers == players - 1 && deadplayers != 0) || timer <= 0)
|
||||
/* Out */
|
||||
conn->sendPacks(m_sock_udp, m_conns, timer);
|
||||
|
||||
if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0) {
|
||||
if (!endgame) {
|
||||
Chat* gameover = new Chat();
|
||||
gameover->dest_id = gameover->dest_team_id = gameover->src_id = 0;
|
||||
std::string winner, winmess;
|
||||
int score = 0;
|
||||
bool plural = false;
|
||||
for (auto& [key, conn] : m_conns) {
|
||||
if (conn->player->getScore() > score) {
|
||||
winner = conn->player->GetUsername();
|
||||
score = conn->player->getScore();
|
||||
plural = false;
|
||||
}
|
||||
else if (conn->player->getScore() == score) {
|
||||
winner = winner.append(" and ").append(conn->player->GetUsername());
|
||||
plural = true;
|
||||
}
|
||||
}
|
||||
|
||||
winmess = "And the winner";
|
||||
if (!plural)
|
||||
winmess = winmess.append(" is ");
|
||||
else winmess = winmess.append("s are ");
|
||||
|
||||
winmess = winmess.append(winner).append(" with ").append(std::to_string(score)).append(" point");
|
||||
|
||||
if (score > 1)
|
||||
winmess = winmess.append("s.");
|
||||
else winmess = winmess.append(".");
|
||||
|
||||
strcpy(gameover->mess, 140, winmess.c_str());
|
||||
|
||||
chatlog.emplace_back(gameover);
|
||||
}
|
||||
endgame = true;
|
||||
endtime += .001;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto& bull : netbull) {
|
||||
for (auto& [key, conn] : m_conns)
|
||||
if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle.
|
||||
sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr());
|
||||
delete bull;
|
||||
}
|
||||
|
||||
if (!netbull.empty())
|
||||
netbull.clear();
|
||||
|
||||
for (auto& bull : bullets) {
|
||||
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
|
||||
ChunkMod* cmod = nullptr;
|
||||
if (bull->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
|
||||
Bullet* bullet = *bull;
|
||||
if (bullet->Update(m_world, (1. / 60.), 50, m_players, &cmod)) {
|
||||
if (cmod)
|
||||
chunkdiffs.emplace_back(std::move(cmod));
|
||||
outbox_bullets.emplace_back(std::move(bull));
|
||||
chunkdiffs.emplace_back(cmod);
|
||||
bullit.push_back(bull);
|
||||
}
|
||||
}
|
||||
netbull.clear();
|
||||
|
||||
for (auto& bull : bullit) {
|
||||
delete* bull;
|
||||
bullets.erase(bull);
|
||||
}
|
||||
|
||||
if (!bullit.empty())
|
||||
bullit.clear();
|
||||
|
||||
for (auto& chat : chatlog) {
|
||||
Log(chat->mess, false, false);
|
||||
Log(chat->mess, false, false);
|
||||
for (auto& [key, conn] : m_conns)
|
||||
sendPackTo<Chat>(m_sock_udp, chat, &m_buf, conn->getAddr());
|
||||
delete chat;
|
||||
}
|
||||
chatlog.clear();
|
||||
if (!chatlog.empty())
|
||||
chatlog.clear();
|
||||
|
||||
for (auto& chmo : chunkdiffs) {
|
||||
for (auto& [key, conn] : m_conns)
|
||||
sendPackTo<ChunkMod>(m_sock_udp, chmo, &m_buf, conn->getAddr());
|
||||
delete chmo;
|
||||
}
|
||||
chunkdiffs.clear();
|
||||
|
||||
for (auto& bull : outbox_bullets)
|
||||
delete bull;
|
||||
outbox_bullets.clear();
|
||||
if (!chunkdiffs.empty())
|
||||
chunkdiffs.clear();
|
||||
}
|
||||
|
||||
Chat end;
|
||||
end.src_id = 0;
|
||||
char endmess[] = "Game over, man. Game over.";
|
||||
|
||||
strcpy(end.mess, 140, endmess);
|
||||
|
||||
for (auto& [key, conn] : m_conns) {
|
||||
std::string str = conn->player->GetUsername();
|
||||
Log(str.append(" ").append(std::to_string(conn->player->getScore())), false, false);
|
||||
}
|
||||
|
||||
for (auto& [key, conn] : m_conns)
|
||||
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.
|
||||
system("pause");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -452,7 +544,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));
|
||||
mess.append(temp.substr(ind + 1, indk - 1));
|
||||
mess.append(killer);
|
||||
mess.append(temp.substr(indk + 1));
|
||||
}
|
||||
@@ -461,7 +553,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));
|
||||
mess.append(temp.substr(indk + 1, ind - 1));
|
||||
mess.append(username);
|
||||
mess.append(temp.substr(ind + 1));
|
||||
}
|
||||
|
@@ -24,6 +24,9 @@ public:
|
||||
int Init();
|
||||
int Ready();
|
||||
void Run();
|
||||
void Cleanup();
|
||||
void DeInit();
|
||||
bool NewGameRequested() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -44,7 +47,7 @@ private:
|
||||
GameInfo m_game;
|
||||
|
||||
World* m_world = nullptr;
|
||||
const bool m_manual_setup = SRV_MANUAL_SETUP;
|
||||
bool m_exit = true;
|
||||
|
||||
std::string LogTimestamp();
|
||||
void Log(std::string str, bool is_error, bool is_fatal);
|
||||
|
@@ -91,7 +91,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>ClangCL</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
@@ -196,7 +196,7 @@
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
@@ -2,26 +2,40 @@
|
||||
|
||||
Audio::Audio() {
|
||||
m_engine = irrklang::createIrrKlangDevice();
|
||||
m_engine->setDopplerEffectParameters(10);
|
||||
m_engine->setRolloffFactor(2);
|
||||
m_engine->setDefault3DSoundMinDistance(.1);
|
||||
m_engine->setDopplerEffectParameters(1);
|
||||
m_engine->setRolloffFactor(1);
|
||||
m_engine->setDefault3DSoundMinDistance(1);
|
||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||
}
|
||||
|
||||
Audio::Audio(const char * music) {
|
||||
Audio::Audio(const char * music, const char* menumusic) {
|
||||
m_engine = irrklang::createIrrKlangDevice();
|
||||
m_engine->setDopplerEffectParameters(1);
|
||||
m_engine->setRolloffFactor(2);
|
||||
m_engine->setDefault3DSoundMinDistance(.1);
|
||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||
m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING);
|
||||
m_engine->setRolloffFactor(1);
|
||||
m_engine->setDefault3DSoundMinDistance(1);
|
||||
m_engine->setDefault3DSoundMaxDistance(100);
|
||||
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
||||
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
|
||||
m_music->setVolume(.5);
|
||||
m_menumusic->setVolume(.5);
|
||||
m_mainvolume = 0.5f;
|
||||
m_engine->setSoundVolume(m_mainvolume);
|
||||
m_sfxvolume = 0.5f;
|
||||
}
|
||||
|
||||
Audio::~Audio() {
|
||||
if (m_music) m_music->drop();
|
||||
if (m_menumusic) m_menumusic->drop();
|
||||
if (m_engine) m_engine->drop();
|
||||
}
|
||||
|
||||
void Audio::playSound(const char* name, float volume = 1.) {
|
||||
irrklang::ISound* sfx = m_engine->play2D(name, false, true);
|
||||
sfx->setVolume(volume);
|
||||
sfx->setIsPaused(false);
|
||||
m_sfxes.push_back(sfx);
|
||||
}
|
||||
|
||||
void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
|
||||
m_engine->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z),
|
||||
irrklang::vec3df(dir.x, dir.y, dir.z),
|
||||
@@ -29,9 +43,10 @@ void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
|
||||
}
|
||||
|
||||
irrklang::ISound* Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped = false, float volume = 1) {
|
||||
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, false, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
|
||||
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, true, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
|
||||
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
||||
sound->setVolume(volume);
|
||||
sound->setIsPaused(false);
|
||||
return sound;
|
||||
}
|
||||
|
||||
@@ -45,10 +60,76 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
|
||||
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
|
||||
//}
|
||||
|
||||
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
||||
void Audio::CleanupSFX() {
|
||||
while (!m_sfxes.empty()) {
|
||||
irrklang::ISound* sfx = m_sfxes.back();
|
||||
if (sfx->isFinished()) {
|
||||
sfx->drop(); // drop() fait deja la job du delete sfx.
|
||||
}
|
||||
else break;
|
||||
m_sfxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::ToggleMusicState(GameState state) {
|
||||
if (m_music_on) {
|
||||
switch (state) {
|
||||
case PLAY:
|
||||
m_music->setIsPaused(false);
|
||||
m_menumusic->setIsPaused(true);
|
||||
break;
|
||||
case PAUSE:
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
break;
|
||||
default:
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::SetMusic(bool ison, GameState state) {
|
||||
m_music_on = state;
|
||||
if (!state) {
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
}
|
||||
else ToggleMusicState(state);
|
||||
}
|
||||
|
||||
bool Audio::GetMusic() {
|
||||
return m_music_on;
|
||||
}
|
||||
|
||||
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
|
||||
|
||||
float Audio::GetMusicVolume() const {
|
||||
return m_music->getVolume();
|
||||
}
|
||||
|
||||
void Audio::SetMusicVolume(float volume) {
|
||||
m_music->setVolume(volume);
|
||||
m_menumusic->setVolume(volume);
|
||||
}
|
||||
|
||||
float Audio::GetMainVolume() const {
|
||||
return m_engine->getSoundVolume();
|
||||
}
|
||||
|
||||
void Audio::SetMainVolume(float volume) {
|
||||
m_engine->setSoundVolume(volume);
|
||||
}
|
||||
|
||||
float Audio::GetSfxVolume() const {
|
||||
return m_sfxvolume;
|
||||
}
|
||||
|
||||
void Audio::SetSfxVolume(float volume) {
|
||||
m_sfxvolume = volume;
|
||||
}
|
||||
|
@@ -15,26 +15,46 @@
|
||||
class Audio {
|
||||
private:
|
||||
irrklang::ISound* m_music;
|
||||
irrklang::ISound* m_menumusic;
|
||||
float m_mainvolume;
|
||||
float m_sfxvolume;
|
||||
bool m_music_on = true;
|
||||
std::vector<irrklang::ISound*> m_sfxes;
|
||||
|
||||
public:
|
||||
Audio();
|
||||
Audio(const char* music);
|
||||
Audio(const char* music, const char* menumusic);
|
||||
~Audio();
|
||||
irrklang::ISoundEngine* m_engine;
|
||||
|
||||
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
|
||||
|
||||
|
||||
irrklang::ISound* Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped, float volume);
|
||||
|
||||
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
|
||||
|
||||
//void PlaySong(const char* music);
|
||||
|
||||
void ToggleMusicState();
|
||||
void CleanupSFX();
|
||||
|
||||
void ToggleMusicState(GameState state);
|
||||
|
||||
void playSound(const char* sound, float volume);
|
||||
|
||||
void SetMusic(bool ison, GameState state);
|
||||
bool GetMusic();
|
||||
|
||||
void PauseEngine();
|
||||
|
||||
float GetMainVolume() const;
|
||||
void SetMainVolume(float volume);
|
||||
|
||||
float GetMusicVolume() const;
|
||||
void SetMusicVolume(float volume);
|
||||
|
||||
float GetSfxVolume() const;
|
||||
void SetSfxVolume(float volume);
|
||||
};
|
||||
|
||||
#endif // AUDIO_H__
|
||||
|
@@ -65,7 +65,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
|
||||
netprot::Buffer bf;
|
||||
netprot::LoginInfo log;
|
||||
strcpy(log.name, name.c_str());
|
||||
strcpy(log.name, 32, name.c_str());
|
||||
|
||||
netprot::sendPack(m_sock_tcp, &log, &bf);
|
||||
|
||||
@@ -73,7 +73,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
int errors = 0;
|
||||
std::vector<char*> lsPck;
|
||||
while (!ready) {
|
||||
lsPck = netprot::recvPacks(m_sock_udp, &bf);
|
||||
netprot::recvPacks(m_sock_udp, &bf, &lsPck);
|
||||
|
||||
for (auto& pck : lsPck) {
|
||||
uint32_t bsize = bf.len - (pck - bf.ptr);
|
||||
@@ -94,6 +94,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
++errors;
|
||||
else {
|
||||
m_players[pl->id] = pl;
|
||||
std::cout << "A challenger appears! " << pl->name << std::endl;
|
||||
}
|
||||
break;
|
||||
case TEAMINF:
|
||||
|
@@ -25,8 +25,8 @@
|
||||
|
||||
#define BULLET_UPDATES_PER_FRAME 20
|
||||
|
||||
#define BASE_WIDTH 640
|
||||
#define BASE_HEIGHT 480
|
||||
#define BASE_WIDTH 1280
|
||||
#define BASE_HEIGHT 720
|
||||
|
||||
|
||||
#define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/"
|
||||
@@ -48,8 +48,8 @@
|
||||
enum GameState {
|
||||
MAIN_MENU,
|
||||
SPLASH,
|
||||
LOBBY,
|
||||
OPTIONS,
|
||||
QUIT,
|
||||
PLAY,
|
||||
PAUSE
|
||||
};
|
||||
@@ -58,7 +58,7 @@ enum Resolution {
|
||||
HD = 0, // 1280x720 (High Definition)
|
||||
FHD, // 1920x1080 (Full HD)
|
||||
QHD, // 2560x1440 (Quad HD)
|
||||
UHD // 3840x2160 (Ultra HD)
|
||||
UHD, // 3840x2160 (Ultra HD)
|
||||
};
|
||||
|
||||
#endif // DEFINE_H__
|
||||
|
@@ -1 +0,0 @@
|
||||
|
@@ -46,8 +46,10 @@ 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);
|
||||
void ChangeResolution(Resolution resolution);
|
||||
|
||||
void InstantDamage();
|
||||
void SystemNotification(std::string systemLog);
|
||||
@@ -62,13 +64,18 @@ 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 DisplayPauseMenu(float elapsedTime);
|
||||
|
||||
void DisplayOptionsMenu();
|
||||
void DisplayAudioMenu(float centerX, float centerY);
|
||||
void DisplayGraphicsMenu(float centerX, float centerY);
|
||||
@@ -77,11 +84,12 @@ 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);
|
||||
|
||||
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav", AUDIO_PATH "menumusic01.wav");
|
||||
irrklang::ISound* m_powpow, * m_scream;
|
||||
irrklang::ISound* m_whoosh[MAX_BULLETS];
|
||||
|
||||
@@ -99,7 +107,7 @@ private:
|
||||
BlockInfo* m_blockinfo[BTYPE_LAST];
|
||||
BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
|
||||
|
||||
GameState m_gamestate = GameState::PLAY;
|
||||
GameState m_gamestate = GameState::SPLASH;
|
||||
|
||||
Shader m_shader01;
|
||||
|
||||
@@ -116,6 +124,7 @@ private:
|
||||
Texture m_texturePovGun;
|
||||
Texture m_textureSkybox;
|
||||
|
||||
Texture m_textureLobbyMenu;
|
||||
Texture m_textureMainMenu;
|
||||
Texture m_textureOptionsMenu;
|
||||
Texture m_texturePauseMenu;
|
||||
@@ -125,9 +134,15 @@ private:
|
||||
Texture m_textureFhd;
|
||||
Texture m_textureQhd;
|
||||
Texture m_textureUhd;
|
||||
|
||||
Texture m_textureLobbyServer;
|
||||
Texture m_textureLobbyIdentify;
|
||||
Texture m_textureCheck;
|
||||
Texture m_textureChecked;
|
||||
|
||||
Texture m_texturePauseResume;
|
||||
Texture m_texturePauseMainMenu;
|
||||
|
||||
Texture m_textureOptAudio;
|
||||
Texture m_textureOptBack;
|
||||
Texture m_textureOptGameplay;
|
||||
@@ -162,10 +177,10 @@ private:
|
||||
int m_nbReductionChunk = 4;
|
||||
int m_timerReductionChunk = 30;
|
||||
|
||||
float m_volPrincipal = 0.0f;
|
||||
float m_volMusique = 0.0f;
|
||||
float m_volEffets = 0.0f;
|
||||
float m_volSensible = 0.0f;
|
||||
float m_mainvolume;
|
||||
float m_musicvolume;
|
||||
float m_sfxvolume;
|
||||
float m_sensitivity;
|
||||
|
||||
int m_selectedOption = 0;
|
||||
|
||||
@@ -190,6 +205,21 @@ 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_selectedSinglePlayer = false;
|
||||
bool m_selectedMultiPlayer = false;
|
||||
bool m_singleReady = false;
|
||||
bool m_multiReady = false;
|
||||
|
||||
|
||||
bool m_key1 = false;
|
||||
bool m_key2 = false;
|
||||
@@ -199,7 +229,10 @@ 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;
|
||||
@@ -216,11 +249,11 @@ private:
|
||||
std::deque<netprot::ChunkMod*> m_chunkmod_manifest;
|
||||
std::chrono::high_resolution_clock::time_point m_startTime;
|
||||
std::unordered_map<uint64_t, Player*> m_players;
|
||||
std::set<uint64_t> m_deadplayers;
|
||||
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 = "";
|
||||
};
|
||||
|
||||
|
BIN
SQCSim2021/media/audio/menumusic01.wav
Normal file
BIN
SQCSim2021/media/audio/snap.wav
Normal file
BIN
SQCSim2021/media/textures/menus/backgrounds/bgLobby.png
Normal file
After Width: | Height: | Size: 505 KiB |
Before Width: | Height: | Size: 562 KiB After Width: | Height: | Size: 596 KiB |
BIN
SQCSim2021/media/textures/menus/buttons/pause/pauseMainMenu.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
SQCSim2021/media/textures/menus/buttons/pause/pauseResume.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
SQCSim2021/media/textures/menus/labels/labelIdentify.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
SQCSim2021/media/textures/menus/labels/labelServer.png
Normal file
After Width: | Height: | Size: 11 KiB |
@@ -53,9 +53,9 @@ protected:
|
||||
void ShowCrossCursor() const;
|
||||
|
||||
bool m_istarted = false;
|
||||
void InitWindow(int width, int height);
|
||||
|
||||
private:
|
||||
void InitWindow(int width, int height);
|
||||
MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const;
|
||||
|
||||
private:
|
||||
|
@@ -8,11 +8,11 @@
|
||||
|
||||
|
||||
|
||||
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){
|
||||
RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)) {
|
||||
|
||||
}
|
||||
|
||||
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) {
|
||||
RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo, const Vector3f& pos) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) {
|
||||
|
||||
}
|
||||
|
||||
@@ -24,63 +24,16 @@ RemotePlayer::~RemotePlayer()
|
||||
|
||||
void RemotePlayer::Init()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RemotePlayer::Feed(const netprot::Output out) {
|
||||
|
||||
m_position = Vector3f(out.position);
|
||||
m_direction = Vector3f(out.direction);
|
||||
|
||||
std::cout << "Dead: " << out.states.dead << " Hit:" << out.states.hit << " Jump:" << out.states.jumping << " JumpShot: " << out.states.jumpshot << " Running: " << out.states.running << " Shooting: " << out.states.shooting << " Still: " << out.states.still << std::endl;
|
||||
//std::cout << "powerUp " << out.states.powerup << std::endl;
|
||||
current.states = out.states;
|
||||
|
||||
|
||||
//current.position = out.position;
|
||||
//current.direction = out.direction;
|
||||
//current.states = out.states;
|
||||
//current.id = out.id;
|
||||
|
||||
//if (current.position != previous.position)
|
||||
//{
|
||||
// Vector3f positionDelta = current.position - previous.position;
|
||||
// m_position = current.position + positionDelta;
|
||||
// m_direction = current.direction;
|
||||
|
||||
//}
|
||||
|
||||
//if(current.direction != previous.direction)
|
||||
//{
|
||||
// m_direction = current.direction;
|
||||
// current.direction = current.direction;
|
||||
//}
|
||||
|
||||
//if (current.states.shooting) {
|
||||
// m_animstate = Anim::SHOOTING;
|
||||
//}
|
||||
//else if (current.states.jumping) {
|
||||
// m_animstate = Anim::JUMPING;
|
||||
//}
|
||||
//else if (current.states.dead) {
|
||||
// m_animstate = Anim::DEAD;
|
||||
//}
|
||||
//else if(current.states.powerup){
|
||||
// m_animstate = Anim::POWERUP;
|
||||
//}
|
||||
//else if (current.states.still) {
|
||||
// m_animstate = Anim::STILL;
|
||||
//}
|
||||
//else if (current.states.running) {
|
||||
// m_animstate = Anim::RUNNING;
|
||||
//}
|
||||
|
||||
//previous.direction = current.direction;
|
||||
//previous.position = current.position;
|
||||
//previous.states = current.states;
|
||||
//previous.id = current.id;
|
||||
|
||||
//m_direction = current.direction;
|
||||
//m_position = current.position;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +63,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
|
||||
Vector3f angleRemote = GetDirection();
|
||||
Vector3f angleCam = (v1 - v2).Cross(v3 - v2);
|
||||
|
||||
|
||||
angleCam.y = 0;
|
||||
angleRemote.y = 0;
|
||||
angleCam.Normalize();
|
||||
@@ -120,26 +73,25 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
int index = 0;
|
||||
angle = -angle;
|
||||
Vector3f side = angleRemote.Cross(angleCam);
|
||||
side = -side;
|
||||
|
||||
static float time = 0.f;
|
||||
static bool Shooting = false;
|
||||
bool isLeft = side.y > 0;
|
||||
|
||||
time += elapsedTime;
|
||||
if (time >= 200)
|
||||
if (time >= 0.05)
|
||||
{
|
||||
time -= 200;
|
||||
if (!current.states.shooting)
|
||||
Shooting = false;
|
||||
else
|
||||
Shooting = !Shooting;
|
||||
time -= 0.05;
|
||||
|
||||
Shooting = !Shooting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl;
|
||||
|
||||
if (angle >= 0.75) //Face - side positif
|
||||
{
|
||||
if(current.states.shooting){
|
||||
if (current.states.shooting) {
|
||||
if (Shooting)
|
||||
index = 17;
|
||||
else
|
||||
@@ -153,7 +105,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
}
|
||||
else if (current.states.jumping)
|
||||
index = 25;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 0;
|
||||
|
||||
}
|
||||
@@ -164,6 +116,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
index = 18;
|
||||
else
|
||||
index = 10;
|
||||
|
||||
}
|
||||
else if (current.states.jumpshot) {
|
||||
if (Shooting)
|
||||
@@ -171,11 +124,12 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
else
|
||||
index = 34;
|
||||
}
|
||||
else if (current.states.jumping )
|
||||
else if (current.states.jumping)
|
||||
index = 26;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 1;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (angle >= -0.25 && isLeft) //ProfileLeft
|
||||
{
|
||||
@@ -184,18 +138,20 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
index = 20;
|
||||
else
|
||||
index = 12;
|
||||
|
||||
}
|
||||
else if (current.states.jumpshot ) {
|
||||
else if (current.states.jumpshot) {
|
||||
if (Shooting)
|
||||
index = 44;
|
||||
else
|
||||
index = 36;
|
||||
}
|
||||
else if (current.states.jumping )
|
||||
else if (current.states.jumping)
|
||||
index = 28;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 3;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (angle >= -0.75 && isLeft) //BackLeft
|
||||
{
|
||||
@@ -204,6 +160,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
index = 22;
|
||||
else
|
||||
index = 14;
|
||||
|
||||
}
|
||||
else if (current.states.jumpshot) {
|
||||
if (Shooting)
|
||||
@@ -213,8 +170,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
}
|
||||
else if (current.states.jumping)
|
||||
index = 30;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 5;
|
||||
|
||||
|
||||
}
|
||||
else if (angle < -0.75) //Dos - side n<>gatif
|
||||
{
|
||||
@@ -223,6 +182,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
index = 24;
|
||||
else
|
||||
index = 16;
|
||||
|
||||
}
|
||||
else if (current.states.jumpshot) {
|
||||
if (Shooting)
|
||||
@@ -230,13 +190,14 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
else
|
||||
index = 40;
|
||||
}
|
||||
else if (current.states.jumping )
|
||||
else if (current.states.jumping)
|
||||
index = 32;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 7;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (angle >= 0.25 && !isLeft) //FrontRight
|
||||
else if (angle >= 0.25 && !isLeft) //FrontRight //REVOIR L'ANIME DE SHOOTING EST PAS DRETTE
|
||||
{
|
||||
if (current.states.shooting) {
|
||||
if (Shooting)
|
||||
@@ -252,9 +213,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
}
|
||||
else if (current.states.jumping)
|
||||
index = 27;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 2;
|
||||
|
||||
|
||||
}
|
||||
else if (angle >= -0.25 && !isLeft) //ProfileRight
|
||||
{
|
||||
@@ -272,9 +234,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
}
|
||||
else if (current.states.jumping)
|
||||
index = 29;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 4;
|
||||
|
||||
|
||||
}
|
||||
else if (angle >= -0.75 && !isLeft) //BackRight
|
||||
{
|
||||
@@ -283,6 +246,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
index = 23;
|
||||
else
|
||||
index = 15;
|
||||
|
||||
}
|
||||
else if (current.states.jumpshot) {
|
||||
if (Shooting)
|
||||
@@ -292,11 +256,12 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
}
|
||||
else if (current.states.jumping)
|
||||
index = 31;
|
||||
else if (current.states.running && current.states.still)
|
||||
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot)
|
||||
index = 6;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float u, v, w, h;
|
||||
@@ -306,10 +271,25 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
|
||||
atlas.TextureIndexToCoord(index, u, v, w, h);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
if (current.states.hit)
|
||||
{
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendColor(1.f, 0.f, 0.f, 1.f);
|
||||
|
||||
}
|
||||
else {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
|
||||
|
||||
|
||||
glLoadMatrixf(tran.GetMatrix().GetInternalValues());
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z);
|
||||
glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z);
|
||||
|
@@ -14,8 +14,8 @@ class RemotePlayer : public Player {
|
||||
public:
|
||||
enum Anim: uint8_t { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 }; // A REVOIR VOIR DEFINE.H POUR LES ANIMES
|
||||
|
||||
RemotePlayer(netprot::PlayerInfo pinfo);
|
||||
RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos);
|
||||
RemotePlayer(netprot::PlayerInfo* pinfo);
|
||||
RemotePlayer(netprot::PlayerInfo* pinfo, const Vector3f& pos);
|
||||
~RemotePlayer();
|
||||
|
||||
|
||||
|
@@ -9,7 +9,7 @@ Settings::Settings(Audio& audio)
|
||||
m_fullscreen(false),
|
||||
m_brightness(0.5f),
|
||||
m_contrast(0.5f),
|
||||
m_mouseSensitivity(0.5f) {
|
||||
m_mouseSensitivity(0.0f) {
|
||||
ApplyResolution(m_resolution);
|
||||
}
|
||||
|
||||
|