Skip to content

Commit 869504a

Browse files
markatkMicky5991
authored andcommitted
Add position updates for 3D sound
1 parent b6ac540 commit 869504a

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

JustAnotherVoiceChat.Server.GTMP.Resource/Client/JustAnotherVoiceChat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class GtmpVoiceHandler {
8787
}
8888

8989
sendRotation() {
90-
const rotation = API.getGameplayCamRot().Z + 180;
90+
const rotation = ((API.getGamePlayCamRot().Z * -1) * Math.PI) / 180;
9191

9292
if (Math.abs(this.lastRotation - rotation) < rotationThreshold) {
9393
return;

JustAnotherVoiceChat.Server/include/client.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ namespace justAnotherVoiceChat {
8181
void addRelativeAudibleClient(Client *client, linalg::aliases::float3 position);
8282
void removeRelativeAudibleClient(Client *client);
8383
void removeAllRelativeAudibleClients();
84+
8485
void sendUpdate();
86+
void sendPositions();
8587

8688
void setPosition(linalg::aliases::float3 position);
8789
linalg::aliases::float3 position() const;

JustAnotherVoiceChat.Server/src/client.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void Client::sendUpdate() {
213213
_relativeAudibleClients.erase(*it);
214214
}
215215

216-
if (updatePacket.audioUpdates.empty() && updatePacket.positionUpdates.empty()) {
216+
if (updatePacket.audioUpdates.empty()) {
217217
return;
218218
}
219219

@@ -238,6 +238,39 @@ void Client::sendUpdate() {
238238
_removeRelativeAudibleClients.clear();
239239
}
240240

241+
void Client::sendPositions() {
242+
positionPacket_t packet;
243+
packet.x = _position.x;
244+
packet.y = _position.y;
245+
packet.z = _position.z;
246+
packet.rotation = _rotation;
247+
248+
for (auto it = _audibleClients.begin(); it != _audibleClients.end(); it++) {
249+
clientPositionUpdate_t positionUpdate;
250+
positionUpdate.teamspeakId = (*it)->teamspeakId();
251+
positionUpdate.x = (*it)->position().x;
252+
positionUpdate.y = (*it)->position().y;
253+
positionUpdate.z = (*it)->position().z;
254+
positionUpdate.voiceRange = (*it)->voiceRange();
255+
256+
packet.positions.push_back(positionUpdate);
257+
}
258+
259+
// serialize packet
260+
std::ostringstream os;
261+
262+
try {
263+
cereal::BinaryOutputArchive archive(os);
264+
archive(packet);
265+
} catch (std::exception &e) {
266+
logMessage(e.what(), LOG_LEVEL_ERROR);
267+
return;
268+
}
269+
270+
auto data = os.str();
271+
sendPacket((void *)data.c_str(), data.size(), NETWORK_POSITION_CHANNEL, false);
272+
}
273+
241274
void Client::setPosition(linalg::aliases::float3 position) {
242275
_position = position;
243276
_positionChanged = true;

JustAnotherVoiceChat.Server/src/server.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void Server::updateClients() {
303303
continue;
304304
}
305305

306-
if (audibleClient->positionChanged() == false) {
306+
if (client->positionChanged() == false && audibleClient->positionChanged() == false) {
307307
continue;
308308
}
309309

@@ -316,6 +316,9 @@ void Server::updateClients() {
316316

317317
// create update packet
318318
client->sendUpdate();
319+
320+
// send positions after audible list was updated
321+
client->sendPositions();
319322
}
320323

321324
// reset all position flags

0 commit comments

Comments
 (0)