some fix/added sync boxes
This commit is contained in:
1 parent
65a2066727
commit
da2b6e5577
5 files changed
+288
-52
No files matched your search
@@ -23,6 +23,13 @@ namespace ZL {
|
||||
int killerId = -1;
|
||||
};
|
||||
|
||||
struct BoxDestroyedInfo {
|
||||
int boxIndex = -1;
|
||||
uint64_t serverTime = 0;
|
||||
Eigen::Vector3f position = Eigen::Vector3f::Zero();
|
||||
int destroyedBy = -1;
|
||||
};
|
||||
|
||||
class INetworkClient {
|
||||
public:
|
||||
virtual ~INetworkClient() = default;
|
||||
@@ -39,5 +46,6 @@ namespace ZL {
|
||||
virtual std::vector<DeathInfo> getPendingDeaths() = 0;
|
||||
virtual std::vector<int> getPendingRespawns() = 0;
|
||||
virtual int GetClientId() const { return -1; }
|
||||
virtual std::vector<BoxDestroyedInfo> getPendingBoxDestructions() = 0;
|
||||
};
|
||||
}
|
||||
@@ -85,6 +85,13 @@ namespace ZL {
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::vector<BoxDestroyedInfo> WebSocketClient::getPendingBoxDestructions() {
|
||||
std::lock_guard<std::mutex> lock(boxDestructionsMutex_);
|
||||
auto copy = pendingBoxDestructions_;
|
||||
pendingBoxDestructions_.clear();
|
||||
return copy;
|
||||
}
|
||||
|
||||
void WebSocketClient::Poll() {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
|
||||
@@ -159,6 +166,35 @@ namespace ZL {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.rfind("BOX_DESTROYED:", 0) == 0) {
|
||||
auto parts = split(msg, ':');
|
||||
if (parts.size() >= 7) {
|
||||
try {
|
||||
BoxDestroyedInfo destruction;
|
||||
destruction.boxIndex = std::stoi(parts[1]);
|
||||
destruction.serverTime = std::stoull(parts[2]);
|
||||
destruction.position = Eigen::Vector3f(
|
||||
std::stof(parts[3]),
|
||||
std::stof(parts[4]),
|
||||
std::stof(parts[5])
|
||||
);
|
||||
destruction.destroyedBy = std::stoi(parts[6]);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(boxDestructionsMutex_);
|
||||
pendingBoxDestructions_.push_back(destruction);
|
||||
}
|
||||
|
||||
std::cout << "Client: Received BOX_DESTROYED for box " << destruction.boxIndex
|
||||
<< " destroyed by player " << destruction.destroyedBy << std::endl;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Client: Error parsing BOX_DESTROYED: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.rfind("PROJECTILE:", 0) == 0) {
|
||||
auto parts = split(msg, ':');
|
||||
if (parts.size() >= 10) {
|
||||
|
||||
@@ -46,6 +46,9 @@ namespace ZL {
|
||||
std::vector<int> pendingRespawns_;
|
||||
std::mutex respawnMutex_;
|
||||
|
||||
std::vector<BoxDestroyedInfo> pendingBoxDestructions_;
|
||||
std::mutex boxDestructionsMutex_;
|
||||
|
||||
void startAsyncRead();
|
||||
void processIncomingMessage(const std::string& msg);
|
||||
|
||||
@@ -75,6 +78,7 @@ namespace ZL {
|
||||
std::vector<ProjectileInfo> getPendingProjectiles() override;
|
||||
std::vector<DeathInfo> getPendingDeaths() override;
|
||||
std::vector<int> getPendingRespawns() override;
|
||||
std::vector<BoxDestroyedInfo> getPendingBoxDestructions() override;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user