mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 17:32:52 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
8bac3b6a2b
10 changed files with 69 additions and 9 deletions
|
@ -391,6 +391,10 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
// give the new audio data to the matching injector agent
|
||||
agentList->updateAgentWithData(matchingInjector, packetData, receivedBytes);
|
||||
} else if (packetData[0] == PACKET_HEADER_PING) {
|
||||
|
||||
// If the packet is a ping, let processAgentData handle it.
|
||||
agentList->processAgentData(agentAddress, packetData, receivedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -833,9 +833,23 @@ void Application::wheelEvent(QWheelEvent* event) {
|
|||
}
|
||||
}
|
||||
|
||||
void sendPingPackets() {
|
||||
|
||||
char agentTypesOfInterest[] = {AGENT_TYPE_VOXEL_SERVER, AGENT_TYPE_AUDIO_MIXER, AGENT_TYPE_AVATAR_MIXER};
|
||||
long long currentTime = usecTimestampNow();
|
||||
char pingPacket[1 + sizeof(currentTime)];
|
||||
pingPacket[0] = PACKET_HEADER_PING;
|
||||
|
||||
memcpy(&pingPacket[1], ¤tTime, sizeof(currentTime));
|
||||
AgentList::getInstance()->broadcastToAgents((unsigned char*)pingPacket, 1 + sizeof(currentTime), agentTypesOfInterest, 3);
|
||||
|
||||
}
|
||||
|
||||
// Every second, check the frame rates and other stuff
|
||||
void Application::timer() {
|
||||
gettimeofday(&_timerEnd, NULL);
|
||||
sendPingPackets();
|
||||
|
||||
_fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
_packetsPerSecond = (float)_packetCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
_bytesPerSecond = (float)_bytesCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
|
@ -2279,6 +2293,24 @@ void Application::displayStats() {
|
|||
sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps",
|
||||
_fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f);
|
||||
drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats);
|
||||
|
||||
int pingAudio = 0, pingAvatar = 0, pingVoxel = 0;
|
||||
|
||||
AgentList *agentList = AgentList::getInstance();
|
||||
Agent *audioMixerAgent = agentList->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
|
||||
Agent *avatarMixerAgent = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
|
||||
Agent *voxelServerAgent = agentList->soloAgentOfType(AGENT_TYPE_VOXEL_SERVER);
|
||||
|
||||
if (audioMixerAgent != NULL)
|
||||
pingAudio = audioMixerAgent->getPingMs();
|
||||
if (avatarMixerAgent != NULL)
|
||||
pingAvatar = avatarMixerAgent->getPingMs();
|
||||
if (voxelServerAgent != NULL)
|
||||
pingVoxel = voxelServerAgent->getPingMs();
|
||||
|
||||
char pingStats[200];
|
||||
sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d ", pingAudio, pingAvatar, pingVoxel);
|
||||
drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats);
|
||||
|
||||
std::stringstream voxelStats;
|
||||
voxelStats.precision(4);
|
||||
|
|
|
@ -335,6 +335,7 @@ private:
|
|||
int _packetsPerSecond;
|
||||
int _bytesPerSecond;
|
||||
int _bytesCount;
|
||||
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__Application__) */
|
||||
|
|
|
@ -1275,7 +1275,6 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
|
|||
}
|
||||
}
|
||||
}
|
||||
_hand.render(lookingInMirror);
|
||||
} else {
|
||||
// Render the body's voxels
|
||||
float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, lookingInMirror);
|
||||
|
@ -1283,6 +1282,7 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
|
|||
_voxels.render(false);
|
||||
}
|
||||
}
|
||||
_hand.render(lookingInMirror);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -236,9 +236,9 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
fingerPositions.resize(numFingers);
|
||||
for (size_t i = 0; i < numFingers; ++i)
|
||||
{
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((uint16_t*) sourceBuffer, &(fingerPositions[i].x), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((uint16_t*) sourceBuffer, &(fingerPositions[i].y), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((uint16_t*) sourceBuffer, &(fingerPositions[i].z), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerPositions[i].x), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerPositions[i].y), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerPositions[i].z), 4);
|
||||
}
|
||||
_handData->setFingerPositions(fingerPositions);
|
||||
}
|
||||
|
@ -259,9 +259,9 @@ int packFloatScalarToSignedTwoByteFixed(unsigned char* buffer, float scalar, int
|
|||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int unpackFloatScalarFromSignedTwoByteFixed(uint16_t* byteFixedPointer, float* destinationPointer, int radix) {
|
||||
int unpackFloatScalarFromSignedTwoByteFixed(int16_t* byteFixedPointer, float* destinationPointer, int radix) {
|
||||
*destinationPointer = *byteFixedPointer / (float)(1 << radix);
|
||||
return sizeof(uint16_t);
|
||||
return sizeof(int16_t);
|
||||
}
|
||||
|
||||
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
|
||||
|
|
|
@ -169,6 +169,6 @@ int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy);
|
|||
|
||||
// Allows sending of fixed-point numbers: radix 1 makes 15.1 number, radix 8 makes 8.8 number, etc
|
||||
int packFloatScalarToSignedTwoByteFixed(unsigned char* buffer, float scalar, int radix);
|
||||
int unpackFloatScalarFromSignedTwoByteFixed(uint16_t* byteFixedPointer, float* destinationPointer, int radix);
|
||||
int unpackFloatScalarFromSignedTwoByteFixed(int16_t* byteFixedPointer, float* destinationPointer, int radix);
|
||||
|
||||
#endif /* defined(__hifi__AvatarData__) */
|
||||
|
|
|
@ -63,6 +63,9 @@ public:
|
|||
float getAverageKilobitsPerSecond();
|
||||
float getAveragePacketsPerSecond();
|
||||
|
||||
int getPingMs() const { return _pingMs; };
|
||||
void setPingMs(int pingMs) { _pingMs = pingMs; };
|
||||
|
||||
static void printLog(Agent const&);
|
||||
private:
|
||||
// privatize copy and assignment operator to disallow Agent copying
|
||||
|
@ -79,6 +82,7 @@ private:
|
|||
SimpleMovingAverage* _bytesReceivedMovingAverage;
|
||||
AgentData* _linkedData;
|
||||
bool _isAlive;
|
||||
int _pingMs;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -77,6 +77,17 @@ AgentList::~AgentList() {
|
|||
pthread_mutex_destroy(&mutex);
|
||||
}
|
||||
|
||||
void AgentList::timePingReply(sockaddr *agentAddress, unsigned char *packetData) {
|
||||
for(AgentList::iterator agent = begin(); agent != end(); agent++) {
|
||||
if (socketMatch(agent->getPublicSocket(), agentAddress) ||
|
||||
socketMatch(agent->getLocalSocket(), agentAddress)) {
|
||||
int pingTime = usecTimestampNow() - *(long long *)(packetData + 1);
|
||||
agent->setPingMs(pingTime / 1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
|
||||
switch (((char *)packetData)[0]) {
|
||||
case PACKET_HEADER_DOMAIN: {
|
||||
|
@ -84,11 +95,14 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD
|
|||
break;
|
||||
}
|
||||
case PACKET_HEADER_PING: {
|
||||
_agentSocket.send(senderAddress, &PACKET_HEADER_PING_REPLY, 1);
|
||||
char pingPacket[dataBytes];
|
||||
memcpy(pingPacket, packetData, dataBytes);
|
||||
pingPacket[0] = PACKET_HEADER_PING_REPLY;
|
||||
_agentSocket.send(senderAddress, pingPacket, dataBytes);
|
||||
break;
|
||||
}
|
||||
case PACKET_HEADER_PING_REPLY: {
|
||||
handlePingReply(senderAddress);
|
||||
timePingReply(senderAddress, packetData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ private:
|
|||
pthread_mutex_t mutex;
|
||||
|
||||
void handlePingReply(sockaddr *agentAddress);
|
||||
void timePingReply(sockaddr *agentAddress, unsigned char *packetData);
|
||||
};
|
||||
|
||||
class AgentListIterator : public std::iterator<std::input_iterator_tag, Agent> {
|
||||
|
|
|
@ -706,6 +706,10 @@ int main(int argc, const char * argv[]) {
|
|||
|
||||
agentList->updateAgentWithData(agent, packetData, receivedBytes);
|
||||
}
|
||||
// If the packet is a ping, let processAgentData handle it.
|
||||
if (packetData[0] == PACKET_HEADER_PING) {
|
||||
agentList->processAgentData(&agentPublicAddress, packetData, receivedBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue