diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj
index 4ba7bd4..c618082 100644
--- a/SQCSim-common/SQCSim-common.vcxproj
+++ b/SQCSim-common/SQCSim-common.vcxproj
@@ -48,7 +48,7 @@
StaticLibrary
false
- v143
+ ClangCL
true
Unicode
diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp
index 9b26861..a489c55 100644
--- a/SQCSim-common/bullet.cpp
+++ b/SQCSim-common/bullet.cpp
@@ -3,19 +3,32 @@
Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {}
-Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_tid(tid) {}
+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() {}
-bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map mapPlayer) {
+bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map mapPlayer, netprot::ChunkMod** chunkmod) {
int max = 100 / perframe;
float damage = 0.057f;
for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime;
for (auto& [key, player] : mapPlayer) {
- if ((m_currentpos - player->GetPosition()).Length() < .4f) {
+ bool hit = false;
+ if ((m_currentpos - player->GetPosition()).Length() < .6f) {
+ hit = true;
+ }
+ if ((m_currentpos - player->GetPOV()).Length() < .2f) {
+ damage *= 2; // HEADSHOT!
+ hit = true;
+ }
+ if (hit && !player->AmIDead()) {
player->InflictDamage(damage);
+ player->m_hit = true;
+
+ if (player->AmIDead())
+ player->Killer = m_shooter_id;
+
return true;
}
}
@@ -23,6 +36,14 @@ 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 = 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);
return true;
}
@@ -47,6 +68,6 @@ Vector3f Bullet::getVel() const {
return m_velocity;
}
-uint64_t Bullet::getTeamID(){
- return m_tid;
-}
+//uint64_t Bullet::getTeamID(){
+// return m_tid;
+//}
diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h
index 04bbfad..3f875d9 100644
--- a/SQCSim-common/bullet.h
+++ b/SQCSim-common/bullet.h
@@ -5,7 +5,7 @@
#include "define.h"
#include "vector3.h"
#include "player.h"
-
+#include "netprotocol.h"
class World;
class Player;
@@ -16,17 +16,17 @@ public:
Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
~Bullet();
- bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer);
+ bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer, netprot::ChunkMod** chunkmod);
void Transpose(int& x, int& z);
Vector3f getPos() const;
Vector3f getVel() const;
- uint64_t getTeamID();
+ //uint64_t getTeamID();
private:
Vector3f m_startpos,
m_currentpos,
m_velocity;
- uint64_t m_tid = 0;
+ uint64_t m_shooter_id = 0;
};
diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h
index 4e7b0b0..685bf5d 100644
--- a/SQCSim-common/define.h
+++ b/SQCSim-common/define.h
@@ -41,8 +41,11 @@ typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
typedef uint8_t BoostType;
enum BOOST_TYPE { BTYPE_SPEED, BTYPE_HEAL, BTYPE_DAMAGE, BTYPE_INVINCIBLE, BTYPE_BOOST_LAST };
+
+//anim
enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DEAD = 32, TYPE_LAST = 40};
enum ANIM_POS {FRONT, QUARTER_FRONT_LEFT, QUATER_FRONT_RIGHT, PROFIL_LEFT, PROFIL_RIGHT, QUARTER_BACK_LEFT, QUARTER_BACK_RIGHT, BACK , POS_LAST};
+
typedef uint64_t Timestamp;
#ifdef _WIN32
@@ -74,6 +77,7 @@ typedef uint64_t Timestamp;
#include
#include
#include
+#include
#define flag_t unsigned int
#define addrlen_t unsigned int
diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp
index ad1a24b..68feda2 100644
--- a/SQCSim-common/netprotocol.cpp
+++ b/SQCSim-common/netprotocol.cpp
@@ -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 |
- keys.backward & 0b01000000 |
- keys.left & 0b00100000 |
- keys.right & 0b00010000 |
- keys.jump & 0b00001000 |
- keys.shoot & 0b00000100 |
- keys.block & 0b00000010;
+ (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 |
- states.shooting & 0b01000000 |
- states.hit & 0b00100000 |
- states.powerup & 0b00010000 |
- states.dead & 0b00001000 |
- states.still & 0b00000100 |
- states.jumpshot & 0b00000010 |
- states.running & 0b00000001;
+ (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));
@@ -181,8 +181,6 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
- memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, &sync->hp, sizeof(uint8_t));
-
uint32_t vec[3];
memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d�naturer les floats.
@@ -200,9 +198,21 @@ 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);
- *buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
+ uint32_t hp;
+
+ memcpy(&hp, &sync->hp, sizeof(float));
+
+ 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;
}
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
@@ -210,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),
@@ -233,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),
@@ -270,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),
@@ -397,11 +410,110 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
size_t messize = std::strlen(chat->mess) + 1;
- memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize);
+ strcpy(*buf + 1 + sizeof(uint64_t) * 3, messize, chat->mess);
*buflen = messize + sizeof(uint64_t) * 3 + 2;
}
+void netprot::Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen) {
+ *buf[0] = (char)netprot::PACKET_TYPE::CHUNKMOD;
+
+ uint32_t vec[3];
+ memcpy(vec, &chmod->pos, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1, vec8, sizeof(uint32_t) * 3);
+
+ memcpy(*buf + sizeof(uint32_t) * 3 + 1, &chmod->b_type, sizeof(BlockType));
+ memcpy(*buf + sizeof(uint32_t) * 3 + 2, &chmod->old_b_type, sizeof(BlockType));
+
+ *buflen = sizeof(uint32_t) * 3 + 3;
+}
+
+void netprot::Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen) {
+ *buf[0] = (char)netprot::PACKET_TYPE::BULLET;
+
+ uint64_t tstamp = bull->tstamp;
+ uint8_t ts8[sizeof(uint64_t)] = {
+ (uint8_t)((tstamp >> 56) & 0xFF),
+ (uint8_t)((tstamp >> 48) & 0xFF),
+ (uint8_t)((tstamp >> 40) & 0xFF),
+ (uint8_t)((tstamp >> 32) & 0xFF),
+ (uint8_t)((tstamp >> 24) & 0xFF),
+ (uint8_t)((tstamp >> 16) & 0xFF),
+ (uint8_t)((tstamp >> 8) & 0xFF),
+ (uint8_t)(tstamp & 0xFF)
+ };
+
+ memcpy(*buf + 1, ts8, sizeof(uint64_t));
+
+ uint64_t tid = bull->id;
+ uint8_t tid8[sizeof(uint64_t)] = {
+ (uint8_t)((tid >> 56) & 0xFF),
+ (uint8_t)((tid >> 48) & 0xFF),
+ (uint8_t)((tid >> 40) & 0xFF),
+ (uint8_t)((tid >> 32) & 0xFF),
+ (uint8_t)((tid >> 24) & 0xFF),
+ (uint8_t)((tid >> 16) & 0xFF),
+ (uint8_t)((tid >> 8) & 0xFF),
+ (uint8_t)(tid & 0xFF)
+ };
+
+ memcpy(*buf + 1 + sizeof(uint64_t), tid8, sizeof(uint64_t));
+
+ uint32_t vec[3];
+ memcpy(vec, &bull->pos, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1 + sizeof(uint64_t) * 2, vec8, sizeof(uint32_t) * 3);
+
+ memcpy(vec, &bull->dir, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t dir8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3, dir8, sizeof(uint32_t) * 3);
+
+ *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6;
+}
+
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
*buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
@@ -416,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;
@@ -476,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;
@@ -508,10 +620,12 @@ bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
out->states.jumping = states & 0b10000000;
out->states.shooting = states & 0b01000000;
out->states.hit = states & 0b00100000;
- out->states.dead = states & 0b00010000;
- out->states.still = states & 0b00001000;
- out->states.jumpshot = states & 0b00000100;
- out->states.running = states & 0b00000010;
+ out->states.powerup = states & 0b00010000;
+ out->states.dead = states & 0b00001000;
+ out->states.still = states & 0b00000100;
+ out->states.jumpshot = states & 0b00000010;
+ out->states.running = states & 0b00000001;
+
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(uint8_t) * 12);
@@ -553,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;
@@ -592,10 +706,9 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
(uint16_t)diff[0] << 8 |
(uint16_t)diff[1];
- memcpy(&sync->hp, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t));
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 |
@@ -612,12 +725,23 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
- *buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
+ uint8_t hp8[4];
+
+ 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];
+
+ memcpy(&sync->hp, &hp, 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;
@@ -626,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));
@@ -645,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;
@@ -654,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));
@@ -684,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;
@@ -693,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));
@@ -723,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;
@@ -766,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;
@@ -806,19 +930,119 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
(uint64_t)dstt[6] << 8 |
(uint64_t)dstt[7];
- size_t messsize = std::strlen(buf + sizeof(uint64_t) * 3) + 1;
+ size_t messsize = std::strlen(&buf[sizeof(uint64_t) * 3]) + 1;
if (messsize > 140)
return false;
- memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize);
+ char* ciboire = &buf[1 + sizeof(uint64_t) * 3];
+
+ strcpy(chat->mess, 140, ciboire);
+
+ //*buflen = messsize + sizeof(uint64_t) * 3 + 1;
- *buflen = messsize + sizeof(uint64_t) * 3 + 2;
-
return true;
}
-bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t *buflen) {
+bool netprot::Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(ChunkMod))
+ return false;
+
+ uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
+ memcpy(subvec, &buf[1], sizeof(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&chmod->pos, vec, sizeof(uint32_t) * 3);
+
+ memcpy(&chmod->b_type, &buf[1 + sizeof(uint8_t) * 12], sizeof(BlockType));
+ memcpy(&chmod->old_b_type, &buf[2 + sizeof(uint8_t) * 12], sizeof(BlockType));
+
+ *buflen = sizeof(uint32_t) * 3 + 3;
+
+ return true;
+}
+
+bool netprot::Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(BulletAdd))
+ return false;
+
+ uint8_t tst[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(tst, &buf[1], sizeof(uint64_t));
+ bull->tstamp =
+ (uint64_t)tst[0] << 56 |
+ (uint64_t)tst[1] << 48 |
+ (uint64_t)tst[2] << 40 |
+ (uint64_t)tst[3] << 32 |
+ (uint64_t)tst[4] << 24 |
+ (uint64_t)tst[5] << 16 |
+ (uint64_t)tst[6] << 8 |
+ (uint64_t)tst[7];
+
+ memcpy(tst, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
+ bull->id =
+ (uint64_t)tst[0] << 56 |
+ (uint64_t)tst[1] << 48 |
+ (uint64_t)tst[2] << 40 |
+ (uint64_t)tst[3] << 32 |
+ (uint64_t)tst[4] << 24 |
+ (uint64_t)tst[5] << 16 |
+ (uint64_t)tst[6] << 8 |
+ (uint64_t)tst[7];
+
+ 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(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&bull->pos, vec, sizeof(uint32_t) * 3);
+
+ memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 12], sizeof(uint8_t) * 12);
+
+ uint32_t dir[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&bull->dir, dir, sizeof(uint32_t) * 3);
+
+ *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 24;
+
+ return true;
+}
+
+bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(ErrorLog))
return false;
@@ -845,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;
@@ -911,9 +1135,7 @@ netprot::Packet netprot::getPack(char* buf, uint32_t *buflen) {
return pck;
}
-netprot::Packet netprot::getPack(netprot::Buffer* buf) {
- return netprot::getPack(buf->ptr, &buf->len);
-}
+netprot::Packet netprot::getPack(netprot::Buffer* buf) { return netprot::getPack(buf->ptr, &buf->len); }
bool netprot::emptyPack(netprot::Packet pck) {
switch (pck.type) {
@@ -950,13 +1172,12 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
return pck;
}
-std::vector netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf) {
- std::vector lsPck;
- int len = buf->tmp? buf->tmp - buf->ptr: 0,
+void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* 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];
@@ -967,15 +1188,15 @@ std::vector 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;
@@ -998,24 +1219,14 @@ std::vector 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;
@@ -1024,8 +1235,7 @@ std::vector netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
}
}
-std::vector netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* outbuf) {
- std::vector lsPck;
+void netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector* lsPck) {
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
end = 0;
char* cursor = buf->tmp ? buf->tmp : nullptr,
@@ -1043,14 +1253,14 @@ std::vector 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;
@@ -1074,24 +1284,14 @@ std::vector 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;
diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h
index b6f78c9..6171bcf 100644
--- a/SQCSim-common/netprotocol.h
+++ b/SQCSim-common/netprotocol.h
@@ -12,14 +12,14 @@ namespace netprot {
ERR, INPUT, OUTPUT, SYNC,
TEAMINF, SELFINF, PLAYINF, LOGINF,
CHUNKMOD, PLAYERMOD, PICKUPMOD,
- GAMEINFO, ENDINFO , CHAT, ERRLOG,
- LAST_PACK
+ GAMEINFO, ENDINFO , BULLET,
+ CHAT, ERRLOG, LAST_PACK
};
/* 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;
};
@@ -38,24 +38,24 @@ namespace netprot {
/* Sous-structures */
struct Keys {
- bool forward,
- backward,
- left,
- right,
- jump,
- shoot,
- block;
+ bool forward = false,
+ backward = false,
+ left = false,
+ right = false,
+ jump = false,
+ shoot = false,
+ block = false;
};
struct States {
- bool jumping,
- shooting,
- hit,
- powerup,
- dead,
- still,
- jumpshot,
- running;
+ bool jumping = false,
+ shooting = false,
+ hit = false,
+ powerup = false,
+ dead = false,
+ still = false,
+ jumpshot = false,
+ running = false;
};
/* Structures de paquets */
@@ -80,37 +80,37 @@ namespace netprot {
uint64_t sid = 0;
uint32_t timer = 0;
uint16_t ammo = 0;
- uint8_t hp = 0;
+ float hp = 0;
Vector3f position;
Sync() {}
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
};
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,16 +125,29 @@ namespace netprot {
uint64_t src_id = 0,
dest_id = 0,
dest_team_id = 0;
- char mess[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(cha->mess, 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 {
+ Vector3f pos;
+ BlockType b_type, old_b_type;
+ };
+
+ struct BulletAdd {
+ Timestamp tstamp;
+ Vector3f pos, dir;
+ uint64_t id;
};
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 */
@@ -147,6 +160,8 @@ namespace netprot {
void Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen); // srv
void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv
void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv
+ void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv
+ void Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen); // srv
void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv
bool Deserialize(Input* in, char* buf, uint32_t* buflen); // srv
@@ -157,6 +172,8 @@ namespace netprot {
bool Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // cli
bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli
bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli
+ bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli
+ bool Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen); // cli
bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv
PACKET_TYPE getType(char* buf, uint32_t buflen);
@@ -176,8 +193,8 @@ namespace netprot {
template void sendPack(SOCKET sock, T* pack, Buffer* buf);
template void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad);
- std::vector recvPacks(SOCKET sock, Buffer* buf, Buffer* oufbuf = nullptr);
- std::vector recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* oufbuf = nullptr);
+ void recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck);
+ void recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector* lsPck);
/* Templates */
diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp
index b88ba18..85df138 100644
--- a/SQCSim-common/player.cpp
+++ b/SQCSim-common/player.cpp
@@ -14,43 +14,53 @@ void Player::TurnLeftRight(float value) {
m_rotY += value;
if (m_rotY > 360) m_rotY = 0;
else if (m_rotY < -360) m_rotY = 0;
+
+ float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
+ float xrotrad = (m_rotX / 57.2957795056f);
+
+ m_direction = Vector3f(cos(xrotrad) * sin(yrotrad),
+ -sin(xrotrad),
+ cos(xrotrad) * -cos(yrotrad));
+
+ m_direction.Normalize();
}
void Player::TurnTopBottom(float value) {
m_rotX += value;
if (m_rotX > 80) m_rotX = 80;
else if (m_rotX < -80) m_rotX = -80;
-}
-
-Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) {
-
- Vector3f delta = Vector3f(0, 0, 0);
float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
float xrotrad = (m_rotX / 57.2957795056f);
m_direction = Vector3f(cos(xrotrad) * sin(yrotrad),
- -sin(xrotrad),
- cos(xrotrad) * -cos(yrotrad));
+ -sin(xrotrad),
+ cos(xrotrad) * -cos(yrotrad));
m_direction.Normalize();
+}
+
+Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) {
+ Vector3f delta = Vector3f(0, 0, 0);
+
+ Vector3f dir = m_direction;
+
+ dir.y = 0;
if (front) {
- delta.x += float(sin(yrotrad)) * elapsedTime * 10.f;
- delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f;
+ delta += dir;
}
else if (back) {
- delta.x += float(-sin(yrotrad)) * elapsedTime * 10.f;
- delta.z += float(cos(yrotrad)) * elapsedTime * 10.f;
+ delta -= dir;
}
if (left) {
- delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f;
- delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f;
+ delta.x += dir.z;
+ delta.z += -dir.x;
}
else if (right) {
- delta.x += float(cos(yrotrad)) * elapsedTime * 10.f;
- delta.z += float(sin(yrotrad)) * elapsedTime * 10.f;
+ delta.x -= dir.z;
+ delta.z -= -dir.x;
}
delta.Normalize();
@@ -194,11 +204,11 @@ 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());
- if (!rot) {
- transformation.ApplyRotation(-m_rotX, 1, 0, 0);
- transformation.ApplyRotation(-m_rotY, 0, 1, 0);
- }
+
+
}
void Player::GetBooster(Booster boosttype)
@@ -246,8 +256,12 @@ void Player::RemoveBooster(float elapsedtime)
}
void Player::SetDirection(Vector3f dir) { m_direction = dir; }
+void Player::Move(Vector3f diff) { m_position -= diff; }
+
Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); }
+Vector3f Player::GetPositionAbs() const { return m_position; }
+
Vector3f Player::GetVelocity() const { return m_velocity; }
Vector3f Player::GetPOV() const { return Vector3f(GetPosition().x, m_POV, GetPosition().z); }
@@ -262,26 +276,24 @@ void Player::Teleport(int& x, int& z) {
m_position.x -= x * CHUNK_SIZE_X;
m_position.z -= z * CHUNK_SIZE_Z;
}
-bool Player::AmIDead()
-{
- return m_hp <= 0;
-}
+bool Player::GetIsAirborne() const { return m_airborne; }
+bool Player::AmIDead() { return m_hp <= 0; }
-void Player::InflictDamage(float hitPoints)
-{
-
+void Player::InflictDamage(float hitPoints) {
m_hp -= hitPoints;
-
- if (AmIDead())
- { // Quand le joueur est mort.
-
-
-
- }
+ if (m_hp < 0)
+ m_hp == 0;
+ //if (AmIDead())
+ //{ // Quand le joueur est mort.
+ //}
}
+int Player::getScore() const { return m_score; }
+
+void Player::addPoint() { ++m_score; }
+
uint64_t Player::getId() const { return id; }
diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h
index 4792d4a..6117605 100644
--- a/SQCSim-common/player.h
+++ b/SQCSim-common/player.h
@@ -25,7 +25,9 @@ public:
void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const;
void SetDirection(Vector3f dir);
+ void Move(Vector3f diff);
Vector3f GetPosition() const;
+ Vector3f GetPositionAbs() const;
Vector3f GetDirection() const;
Vector3f GetVelocity() const;
Vector3f GetPOV() const;
@@ -33,8 +35,14 @@ public:
float GetHP() const;
void Teleport(int& x, int& z);
+ bool GetIsAirborne() const;
bool AmIDead();
void InflictDamage(float hitPoints);
+ int getScore() const;
+ void addPoint();
+ uint64_t Killer = 0;
+ std::string m_username;
+ bool m_hit = false;
private:
uint64_t getId() const;
@@ -44,8 +52,8 @@ protected:
Vector3f m_velocity;
Vector3f m_direction;
- std::string m_username;
uint64_t id = 0;
+ int m_score = 0;
float m_rotX = 0;
float m_rotY = 0;
diff --git a/SQCSim-common/world.cpp b/SQCSim-common/world.cpp
index 70d6eb6..2791ca1 100644
--- a/SQCSim-common/world.cpp
+++ b/SQCSim-common/world.cpp
@@ -169,31 +169,26 @@ void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, Blo
UpdateWorld(player_pos, blockinfo);
//TransposeWorld(player_pos, bullets);
}
-//
-//void World::UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]) {
-// if (updates == 0 && ChunkAt(chx, 1, chy) &&
-// ChunkAt(chx, 1, chy)->IsDirty()) {
-// ChunkAt(chx, 1, chy)->Update(blockinfo, this);
-// updates = FRAMES_UPDATE_CHUNKS;
-// }
-//
-//}
-void World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block) {
+netprot::ChunkMod* World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net) {
Vector3f currentPos = player_pos;
Vector3f currentBlock = currentPos;
Vector3f ray = player_dir;
+ BlockType oldbtype;
+ netprot::ChunkMod* cmod = nullptr;
bool found = false;
- if (block) return;
+ if (block) return cmod;
while ((currentPos - currentBlock).Length() <= MAX_SELECTION_DISTANCE && !found) {
currentBlock += ray / 10.f;
BlockType bt = BlockAt(currentBlock);
- if (bt != BTYPE_AIR)
+ if (bt != BTYPE_AIR) {
found = true;
+ oldbtype = bt;
+ }
}
if (found)
@@ -219,21 +214,30 @@ void World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos,
(By == PyA ||
By == PyB ||
By == PyC) &&
- Bz == Pz))
+ Bz == Pz)) {
found = true;
+ oldbtype = bt;
+ }
}
}
}
if (found && (int)currentBlock.y < CHUNK_SIZE_Y) {
+ if (net) {
+ cmod = new netprot::ChunkMod();
+ cmod->old_b_type = oldbtype;
+ cmod->b_type = blockType;
+ cmod->pos = currentBlock;
+ }
int bx = (int)currentBlock.x % CHUNK_SIZE_X;
int by = (int)currentBlock.y % CHUNK_SIZE_Y;
int bz = (int)currentBlock.z % CHUNK_SIZE_Z;
-
ChunkAt(currentBlock)->SetBlock(bx, by, bz, blockType, this);
ChunkAt(currentBlock)->MakeModified();
block = true;
}
+
+ return cmod;
}
void World::ChangeBlockAtPosition(BlockType blockType, Vector3f pos) {
diff --git a/SQCSim-common/world.h b/SQCSim-common/world.h
index e9b4840..06c513b 100644
--- a/SQCSim-common/world.h
+++ b/SQCSim-common/world.h
@@ -11,6 +11,7 @@
#include "array2d.h"
#include "bullet.h"
#include "chunk.h"
+#include "netprotocol.h"
class Chunk;
class Bullet;
@@ -37,7 +38,7 @@ public:
void GetScope(unsigned int& x, unsigned int& y);
- void ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block);
+ netprot::ChunkMod* ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net);
void ChangeBlockAtPosition(BlockType blockType, Vector3f pos);
void CleanUpWorld(int& deleteframes, bool clear);
int GettbDeleted() const;
diff --git a/SQCSim-srv/SQCSim-srv.vcxproj b/SQCSim-srv/SQCSim-srv.vcxproj
index d080276..b0dcd9c 100644
--- a/SQCSim-srv/SQCSim-srv.vcxproj
+++ b/SQCSim-srv/SQCSim-srv.vcxproj
@@ -48,7 +48,7 @@
Application
false
- v143
+ ClangCL
true
Unicode
diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp
index 4ac9968..669ae8f 100644
--- a/SQCSim-srv/connection.cpp
+++ b/SQCSim-srv/connection.cpp
@@ -2,26 +2,28 @@
-Connection::Connection(SOCKET sock,
- sockaddr_in sockaddr,
- LoginInfo log,
- PlayerInfo play):
- m_sock(sock),
- m_addr(sockaddr),
- m_loginfo(log),
- m_playinfo(play) {
+Connection::Connection(SOCKET sock,
+ sockaddr_in sockaddr,
+ LoginInfo *log,
+ PlayerInfo *play) :
+ m_sock(sock),
+ m_addr(sockaddr),
+ 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; }
+uint64_t Connection::GetHash(bool self) const { return self ? m_loginfo.sid : m_playinfo.id; }
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
std::string Connection::GetName() const { return m_loginfo.name; }
-void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); }
+void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); m_input_vector.push_back(in); }
Output* Connection::getOutput(Timestamp time) {
auto out = m_output_manifest.find(time);
@@ -50,70 +52,157 @@ sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; }
void Connection::getPacks(SOCKET sock) {
std::vector lsPck;
Input in;
- while (true) {
- lsPck = recvPacksFrom(sock, &m_buf, m_addr);
-
- 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_input_manifest[in.timestamp] = in;
- break;
- default: break;
+ Sync sync;
+ 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)) {
+ m_input_manifest[in.timestamp] = in;
+ m_input_vector.push_back(in);
}
+ break;
+ case SYNC:
+ if (Deserialize(&sync, pck, &bsize))
+ m_nsync = true;
+ break;
+ default: break;
}
- lsPck.clear();
}
+ lsPck.clear();
}
-void Connection::sendPacks(SOCKET sock, std::unordered_map conns) {
- while (m_last_out < m_output_manifest.size()) {
- Output out = m_output_manifest.at(m_last_out++);
-
+void Connection::sendPacks(SOCKET sock, std::unordered_map conns, const uint32_t timer) {
+ static int outs = 0;
+ static Timestamp last = 0;
+ while (!m_output_vector.empty()) {
+ Output out = m_output_vector.front();
for (auto& [key, conn] : conns) {
- if (m_playinfo.id == conn->GetHash(true))
+ if (m_playinfo.id == conn->GetHash(false))
continue;
sendPackTo