Merge branch 'master' of https://github.com/worklist/hifi into view_frustum_work

This commit is contained in:
ZappoMan 2013-04-19 20:08:47 -07:00
commit 67910a2c29
17 changed files with 733 additions and 706 deletions

View file

@ -133,7 +133,7 @@ int main(int argc, const char * argv[])
if (DEBUG_TO_SELF ||
!agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) {
if (strchr(SOLO_AGENT_TYPES_STRING, (int) agent->getType()) == NULL) {
if (memchr(SOLO_AGENT_TYPES_STRING, agent->getType(), 1) == NULL) {
// this is an agent of which there can be multiple, just add them to the packet
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
} else {

File diff suppressed because it is too large Load diff

View file

@ -40,7 +40,7 @@ enum AvatarMode
{
AVATAR_MODE_STANDING = 0,
AVATAR_MODE_WALKING,
AVATAR_MODE_COMMUNICATING,
AVATAR_MODE_INTERACTING,
NUM_AVATAR_MODES
};
@ -91,14 +91,48 @@ struct AvatarBone
float radius; // used for detecting collisions for certain physical effects
};
struct Avatar
struct AvatarHead
{
glm::dvec3 velocity;
glm::vec3 thrust;
float maxArmLength;
Orientation orientation;
float pitch;
float yaw;
float roll;
float pitchRate;
float yawRate;
float rollRate;
float noise;
float eyeballPitch[2];
float eyeballYaw [2];
float eyebrowPitch[2];
float eyebrowRoll [2];
float eyeballScaleX;
float eyeballScaleY;
float eyeballScaleZ;
float interPupilDistance;
float interBrowDistance;
float nominalPupilSize;
float pupilSize;
float mouthPitch;
float mouthYaw;
float mouthWidth;
float mouthHeight;
float leanForward;
float leanSideways;
float pitchTarget;
float yawTarget;
float noiseEnvelope;
float pupilConverge;
float scale;
int eyeContact;
float browAudioLift;
eyeContactTargets eyeContactTarget;
// Sound loudness information
float loudness, lastLoudness;
float averageLoudness;
float audioAttack;
};
class Head : public AvatarData {
public:
Head(bool isMine);
@ -106,30 +140,29 @@ class Head : public AvatarData {
Head(const Head &otherHead);
Head* clone() const;
void reset();
void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
void setNoise (float mag) { _noise = mag; }
void setPitch(float p) {_headPitch = p; }
void setYaw(float y) {_headYaw = y; }
void setRoll(float r) {_headRoll = r; };
void setScale(float s) {_scale = s; };
void setRenderYaw(float y) {_renderYaw = y;}
void setRenderPitch(float p) {_renderPitch = p;}
void reset();
void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
void setNoise (float mag) { _head.noise = mag; }
void setPitch(float p) {_head.pitch = p; }
void setYaw(float y) {_head.yaw = y; }
void setRoll(float r) {_head.roll = r; };
void setScale(float s) {_head.scale = s; };
void setRenderYaw(float y) {_renderYaw = y;}
void setRenderPitch(float p) {_renderPitch = p;}
float getRenderYaw() {return _renderYaw;}
float getRenderPitch() {return _renderPitch;}
void setLeanForward(float dist);
void setLeanSideways(float dist);
void addPitch(float p) {_headPitch -= p; }
void addYaw(float y){_headYaw -= y; }
void addRoll(float r){_headRoll += r; }
void addLean(float x, float z);
float getPitch() {return _headPitch;}
float getRoll() {return _headRoll;}
float getYaw() {return _headYaw;}
float getLastMeasuredYaw() {return _headYawRate;}
void setLeanForward(float dist);
void setLeanSideways(float dist);
void addPitch(float p) {_head.pitch -= p; }
void addYaw(float y){_head.yaw -= y; }
void addRoll(float r){_head.roll += r; }
void addLean(float x, float z);
float getPitch() {return _head.pitch;}
float getRoll() {return _head.roll;}
float getYaw() {return _head.yaw;}
float getLastMeasuredYaw() {return _head.yawRate;}
float getBodyYaw() {return _bodyYaw;};
void addBodyYaw(float y) {_bodyYaw += y;};
void addBodyYaw(float y) {_bodyYaw += y;};
glm::vec3 getHeadLookatDirection();
glm::vec3 getHeadLookatDirectionUp();
@ -145,17 +178,18 @@ class Head : public AvatarData {
void renderBody();
void renderHead( int faceToFace);
//void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void simulate(float);
void setHandMovement( glm::vec3 movement );
void startHandMovement();
void stopHandMovement();
void setHandMovementValues( glm::vec3 movement );
void updateHandMovement();
float getLoudness() {return _loudness;};
float getAverageLoudness() {return _averageLoudness;};
void setAverageLoudness(float al) {_averageLoudness = al;};
void setLoudness(float l) {_loudness = l;};
float getLoudness() {return _head.loudness;};
float getAverageLoudness() {return _head.averageLoudness;};
void setAverageLoudness(float al) {_head.averageLoudness = al;};
void setLoudness(float l) {_head.loudness = l;};
void SetNewHeadTarget(float, float);
@ -164,9 +198,9 @@ class Head : public AvatarData {
bool getDriveKeys(int key) { return _driveKeys[key]; };
// Set/Get update the thrust that will move the avatar around
void setThrust(glm::vec3 newThrust) { _avatar.thrust = newThrust; };
void addThrust(glm::vec3 newThrust) { _avatar.thrust += newThrust; };
glm::vec3 getThrust() { return _avatar.thrust; };
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; };
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };
glm::vec3 getThrust() { return _thrust; };
//
// Related to getting transmitter UDP data used to animate the avatar hand
@ -176,67 +210,30 @@ class Head : public AvatarData {
float getTransmitterHz() { return _transmitterHz; };
private:
bool _isMine;
float _noise;
float _headPitch;
float _headYaw;
float _headRoll;
float _headPitchRate;
float _headYawRate;
float _headRollRate;
float _eyeballPitch[2];
float _eyeballYaw[2];
float _eyebrowPitch[2];
float _eyebrowRoll[2];
float _eyeballScaleX, _eyeballScaleY, _eyeballScaleZ;
float _interPupilDistance;
float _interBrowDistance;
float _nominalPupilSize;
float _pupilSize;
float _mouthPitch;
float _mouthYaw;
float _mouthWidth;
float _mouthHeight;
float _leanForward;
float _leanSideways;
float _pitchTarget;
float _yawTarget;
float _noiseEnvelope;
float _pupilConverge;
float _scale;
// Sound loudness information
float _loudness, _lastLoudness;
float _averageLoudness;
float _audioAttack;
float _browAudioLift;
AvatarHead _head;
bool _isMine;
glm::vec3 _TEST_bigSpherePosition;
float _TEST_bigSphereRadius;
glm::vec3 _DEBUG_otherAvatarListPosition[ NUM_OTHER_AVATARS ];
float _DEBUG_otherAvatarListTimer [ NUM_OTHER_AVATARS ];
bool _triggeringAction;
float _bodyYawDelta;
float _closeEnoughToInteract;
int _closestOtherAvatar;
bool _usingSprings;
bool _handBeingMoved;
bool _previousHandBeingMoved;
bool _usingBodySprings;
glm::vec3 _movedHandOffset;
float _springVelocityDecay;
float _springForce;
glm::quat _rotation; // the rotation of the avatar body as a whole
AvatarBone _bone[ NUM_AVATAR_BONES ];
AvatarMode _mode;
Avatar _avatar;
glm::dvec3 _velocity;
glm::vec3 _thrust;
float _maxArmLength;
Orientation _orientation;
int _driveKeys[MAX_DRIVE_KEYS];
int _eyeContact;
eyeContactTargets _eyeContactTarget;
GLUquadric *_sphere;
float _renderYaw;
float _renderPitch; // Pitch from view frustum when this is own head.
GLUquadric* _sphere;
float _renderYaw;
float _renderPitch; // Pitch from view frustum when this is own head.
//
// Related to getting transmitter UDP data used to animate the avatar hand

View file

@ -93,24 +93,24 @@ long int VoxelSystem::getVoxelsCreated() {
return tree->voxelsCreated;
}
long int VoxelSystem::getVoxelsCreatedRunningAverage() {
return tree->voxelsCreatedStats.getRunningAverage();
float VoxelSystem::getVoxelsCreatedPerSecondAverage() {
return (1 / tree->voxelsCreatedStats.getEventDeltaAverage());
}
long int VoxelSystem::getVoxelsColored() {
return tree->voxelsColored;
}
long int VoxelSystem::getVoxelsColoredRunningAverage() {
return tree->voxelsColoredStats.getRunningAverage();
float VoxelSystem::getVoxelsColoredPerSecondAverage() {
return (1 / tree->voxelsColoredStats.getEventDeltaAverage());
}
long int VoxelSystem::getVoxelsBytesRead() {
return tree->voxelsBytesRead;
}
long int VoxelSystem::getVoxelsBytesReadRunningAverage() {
return tree->voxelsBytesReadStats.getRunningAverage();
float VoxelSystem::getVoxelsBytesReadPerSecondAverage() {
return tree->voxelsBytesReadStats.getAverageSampleValuePerSecond();
}

View file

@ -41,9 +41,9 @@ public:
long int getVoxelsCreated();
long int getVoxelsColored();
long int getVoxelsBytesRead();
long int getVoxelsCreatedRunningAverage();
long int getVoxelsColoredRunningAverage();
long int getVoxelsBytesReadRunningAverage();
float getVoxelsCreatedPerSecondAverage();
float getVoxelsColoredPerSecondAverage();
float getVoxelsBytesReadPerSecondAverage();
// Methods that recurse tree
void randomizeVoxelColors();

View file

@ -74,10 +74,11 @@
#include "Oscilloscope.h"
#include "UDPSocket.h"
#include "SerialInterface.h"
#include <PerfStat.h>
#include <SharedUtil.h>
#include <PacketHeaders.h>
#include <AvatarData.h>
#include <PerfStat.h>
#include <SimpleMovingAverage.h>
#include "ViewFrustum.h"
@ -167,15 +168,90 @@ int displayField = 0;
int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement
int headMouseX, headMouseY;
int mouseX, mouseY; // Where is the mouse
int mouseX = 0;
int mouseY = 0;
// Mouse location at start of last down click
int mouseStartX = WIDTH / 2;
int mouseStartY = HEIGHT / 2;
int mousePressed = 0; // true if mouse has been pressed (clear when finished)
Menu menu; // main menu
int menuOn = 1; // Whether to show onscreen menu
Menu menu; // main menu
int menuOn = 1; // Whether to show onscreen menu
struct HandController
{
bool enabled;
int startX;
int startY;
int x;
int y;
int lastX;
int lastY;
int velocityX;
int velocityY;
float rampUpRate;
float rampDownRate;
float envelope;
};
HandController handController;
void initializeHandController() {
handController.enabled = false;
handController.startX = WIDTH / 2;
handController.startY = HEIGHT / 2;
handController.x = 0;
handController.y = 0;
handController.lastX = 0;
handController.lastY = 0;
handController.velocityX = 0;
handController.velocityY = 0;
handController.rampUpRate = 0.05;
handController.rampDownRate = 0.02;
handController.envelope = 0.0f;
}
void updateHandController( int x, int y ) {
handController.lastX = handController.x;
handController.lastY = handController.y;
handController.x = x;
handController.y = y;
handController.velocityX = handController.x - handController.lastX;
handController.velocityY = handController.y - handController.lastY;
if (( handController.velocityX != 0 )
|| ( handController.velocityY != 0 )) {
handController.enabled = true;
myAvatar.startHandMovement();
if ( handController.envelope < 1.0 ) {
handController.envelope += handController.rampUpRate;
if ( handController.envelope >= 1.0 ) {
handController.envelope = 1.0;
}
}
}
if ( ! handController.enabled ) {
if ( handController.envelope > 0.0 ) {
handController.envelope -= handController.rampDownRate;
if ( handController.envelope <= 0.0 ) {
handController.startX = WIDTH / 2;
handController.startY = HEIGHT / 2;
handController.envelope = 0.0;
myAvatar.stopHandMovement();
}
}
}
if ( handController.envelope > 0.0 ) {
float leftRight = ( ( handController.x - handController.startX ) / (float)WIDTH ) * handController.envelope;
float downUp = ( ( handController.y - handController.startY ) / (float)HEIGHT ) * handController.envelope;
float backFront = 0.0;
myAvatar.setHandMovementValues( glm::vec3( leftRight, downUp, backFront ) );
}
}
//
// Serial USB Variables
@ -239,31 +315,36 @@ void displayStats(void)
std::stringstream voxelStats;
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
drawtext(10, statsVerticalOffset + 70, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() << " (" << voxels.getVoxelsCreatedRunningAverage()
<< "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() << " (" << voxels.getVoxelsCreatedPerSecondAverage()
<< "/sec) ";
drawtext(10, statsVerticalOffset + 250, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() << " (" << voxels.getVoxelsColoredRunningAverage()
<< "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() << " (" << voxels.getVoxelsColoredPerSecondAverage()
<< "/sec) ";
drawtext(10, statsVerticalOffset + 270, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Bytes Read: " << voxels.getVoxelsBytesRead()
<< " (" << voxels.getVoxelsBytesReadRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
voxelStats << "Voxels Bytes Read: " << voxels.getVoxelsBytesRead()
<< " (" << voxels.getVoxelsBytesReadPerSecondAverage() << " Bps)";
drawtext(10, statsVerticalOffset + 290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
long int voxelsBytesPerColored = voxels.getVoxelsColored() ? voxels.getVoxelsBytesRead()/voxels.getVoxelsColored() : 0;
long int voxelsBytesPerColoredAvg = voxels.getVoxelsColoredRunningAverage() ?
voxels.getVoxelsBytesReadRunningAverage()/voxels.getVoxelsColoredRunningAverage() : 0;
voxelStats << "Voxels Bytes per Colored: " << voxelsBytesPerColored
<< " (" << voxelsBytesPerColoredAvg << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
float voxelsBytesPerColored = voxels.getVoxelsColored()
? ((float) voxels.getVoxelsBytesRead() / voxels.getVoxelsColored())
: 0;
voxelStats << "Voxels Bytes per Colored: " << voxelsBytesPerColored;
drawtext(10, statsVerticalOffset + 310, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
Agent *avatarMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
char avatarMixerStats[200];
sprintf(avatarMixerStats, "Avatar Mixer - %.f kbps, %.f pps",
roundf(avatarMixer->getAverageKilobitsPerSecond()),
roundf(avatarMixer->getAveragePacketsPerSecond()));
drawtext(10, statsVerticalOffset + 330, 0.10f, 0, 1.0, 0, avatarMixerStats);
if (::perfStatsOn) {
// Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
@ -298,6 +379,8 @@ void init(void)
voxels.init();
voxels.setViewerHead(&myAvatar);
myAvatar.setRenderYaw(startYaw);
initializeHandController();
headMouseX = WIDTH/2;
headMouseY = HEIGHT/2;
@ -363,20 +446,6 @@ void reset_sensors()
}
}
void updateAvatarHand(float deltaTime) {
// If mouse is being dragged, send current force to the hand controller
if (mousePressed == 1)
{
// NOTE--PER: Need to re-implement when ready for new avatar hand movements
const float MOUSE_HAND_FORCE = 1.5;
float dx = mouseX - mouseStartX;
float dy = mouseY - mouseStartY;
glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0);
//myAvatar.hand->addVelocity(vel*deltaTime);
}
}
//
// Using gyro data, update both view frustum and avatar head position
//
@ -828,10 +897,10 @@ void display(void)
agent != agentList->getAgents().end();
agent++) {
if (agent->getLinkedData() != NULL) {
Head *agentHead = (Head *)agent->getLinkedData();
glPushMatrix();
agentHead->render(0);
glPopMatrix();
Head *avatar = (Head *)agent->getLinkedData();
//glPushMatrix();
avatar->render(0);
//glPopMatrix();
}
}
@ -1368,55 +1437,49 @@ void idle(void) {
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
//if ( myAvatar.getMode() == AVATAR_MODE_COMMUNICATING ) {
float leftRight = ( mouseX - mouseStartX ) / (float)WIDTH;
float downUp = ( mouseY - mouseStartY ) / (float)HEIGHT;
float backFront = 0.0;
glm::vec3 handMovement( leftRight, downUp, backFront );
myAvatar.setHandMovement( handMovement );
/*}
else {
mouseStartX = mouseX;
mouseStartY = mouseY;
//mouseStartX = (float)WIDTH / 2.0f;
//mouseStartY = (float)HEIGHT / 2.0f;
}
*/
//--------------------------------------------------------
float deltaTime = 1.f/FPS;
// update behaviors for avatar hand movement
updateHandController( mouseX, mouseY );
// when the mouse is being pressed, an 'action' is being
// triggered in the avatar. The action is context-based.
//--------------------------------------------------------
if ( mousePressed == 1 ) {
myAvatar.setTriggeringAction( true );
}
else {
myAvatar.setTriggeringAction( false );
}
// walking triggers the handController to stop
if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) {
handController.enabled = false;
}
//
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
//
updateAvatar( 1.f/FPS );
//loop through all the other avatars and simulate them.
AgentList * agentList = AgentList::getInstance();
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++)
{
if (agent->getLinkedData() != NULL)
{
Head *agentHead = (Head *)agent->getLinkedData();
agentHead->simulate(1.f/FPS);
Head *avatar = (Head *)agent->getLinkedData();
avatar->simulate(deltaTime);
}
}
updateAvatarHand(1.f/FPS);
//updateAvatarHand(1.f/FPS);
field.simulate(1.f/FPS);
myAvatar.simulate(1.f/FPS);
balls.simulate(1.f/FPS);
cloud.simulate(1.f/FPS);
field.simulate (deltaTime);
myAvatar.simulate(deltaTime);
balls.simulate (deltaTime);
cloud.simulate (deltaTime);
glutPostRedisplay();
lastTimeIdle = check;
@ -1490,8 +1553,6 @@ void mouseFunc( int button, int state, int x, int y )
mouseX = x;
mouseY = y;
mousePressed = 1;
//mouseStartX = x;
//mouseStartY = y;
}
}
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
@ -1511,12 +1572,17 @@ void motionFunc( int x, int y)
void mouseoverFunc( int x, int y)
{
menu.mouseOver(x, y);
mouseX = x;
mouseY = y;
if (mousePressed == 0)
{}
}
void attachNewHeadToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Head(false));

View file

@ -20,8 +20,7 @@ using avatars_lib::printLog;
//
// tosh - yep, I noticed... :-)
//
// JJV - I noticed too :-)
//
static bool testingForNormalizationAndOrthogonality = false;
Orientation::Orientation() {

View file

@ -37,6 +37,7 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent
activeSocket = NULL;
linkedData = NULL;
_bytesReceivedMovingAverage = NULL;
deleteMutex = new pthread_mutex_t;
pthread_mutex_init(deleteMutex, NULL);
@ -69,6 +70,13 @@ Agent::Agent(const Agent &otherAgent) {
linkedData = NULL;
}
if (otherAgent._bytesReceivedMovingAverage != NULL) {
_bytesReceivedMovingAverage = new SimpleMovingAverage(100);
memcpy(_bytesReceivedMovingAverage, otherAgent._bytesReceivedMovingAverage, sizeof(SimpleMovingAverage));
} else {
_bytesReceivedMovingAverage = NULL;
}
deleteMutex = new pthread_mutex_t;
pthread_mutex_init(deleteMutex, NULL);
}
@ -89,6 +97,7 @@ void Agent::swap(Agent &first, Agent &second) {
swap(first.agentId, second.agentId);
swap(first.firstRecvTimeUsecs, second.firstRecvTimeUsecs);
swap(first.lastRecvTimeUsecs, second.lastRecvTimeUsecs);
swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage);
swap(first.deleteMutex, second.deleteMutex);
}
@ -99,6 +108,7 @@ Agent::~Agent() {
delete publicSocket;
delete localSocket;
delete linkedData;
delete _bytesReceivedMovingAverage;
}
char Agent::getType() const {
@ -199,7 +209,6 @@ void Agent::setLinkedData(AgentData *newData) {
linkedData = newData;
}
bool Agent::operator==(const Agent& otherAgent) {
return matches(otherAgent.publicSocket, otherAgent.localSocket, otherAgent.type);
}
@ -211,6 +220,30 @@ bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, cha
&& socketMatch(localSocket, otherLocalSocket);
}
void Agent::recordBytesReceived(int bytesReceived) {
if (_bytesReceivedMovingAverage == NULL) {
_bytesReceivedMovingAverage = new SimpleMovingAverage(100);
}
_bytesReceivedMovingAverage->updateAverage((float) bytesReceived);
}
float Agent::getAveragePacketsPerSecond() {
if (_bytesReceivedMovingAverage != NULL) {
return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage());
} else {
return 0;
}
}
float Agent::getAverageKilobitsPerSecond() {
if (_bytesReceivedMovingAverage != NULL) {
return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000));
} else {
return 0;
}
}
void Agent::printLog(Agent const& agent) {
sockaddr_in *agentPublicSocket = (sockaddr_in *) agent.publicSocket;

View file

@ -11,7 +11,6 @@
#include <stdint.h>
#include <ostream>
#include "AgentData.h"
#ifdef _WIN32
#include "Syssocket.h"
@ -19,6 +18,9 @@
#include <sys/socket.h>
#endif
#include "SimpleMovingAverage.h"
#include "AgentData.h"
class Agent {
public:
Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId);
@ -34,32 +36,45 @@ public:
char getType() const;
const char* getTypeName() const;
void setType(char newType);
uint16_t getAgentId();
void setAgentId(uint16_t thisAgentId);
double getFirstRecvTimeUsecs();
void setFirstRecvTimeUsecs(double newTimeUsecs);
double getLastRecvTimeUsecs();
void setLastRecvTimeUsecs(double newTimeUsecs);
sockaddr* getPublicSocket();
void setPublicSocket(sockaddr *newSocket);
sockaddr* getLocalSocket();
void setLocalSocket(sockaddr *newSocket);
sockaddr* getActiveSocket();
void activatePublicSocket();
void activateLocalSocket();
AgentData* getLinkedData();
void setLinkedData(AgentData *newData);
void recordBytesReceived(int bytesReceived);
float getAverageKilobitsPerSecond();
float getAveragePacketsPerSecond();
static void printLog(Agent const&);
friend std::ostream& operator<<(std::ostream& os, const Agent* agent);
private:
void swap(Agent &first, Agent &second);
sockaddr *publicSocket, *localSocket, *activeSocket;
char type;
uint16_t agentId;
double firstRecvTimeUsecs;
double lastRecvTimeUsecs;
AgentData *linkedData;
SimpleMovingAverage* _bytesReceivedMovingAverage;
AgentData* linkedData;
};
std::ostream& operator<<(std::ostream& os, const Agent* agent);

View file

@ -24,7 +24,12 @@
using shared_lib::printLog;
const char * SOLO_AGENT_TYPES_STRING = "MV";
const char SOLO_AGENT_TYPES_STRING[] = {
AGENT_TYPE_AVATAR_MIXER,
AGENT_TYPE_AUDIO_MIXER,
AGENT_TYPE_VOXEL
};
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102;
@ -108,6 +113,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
if (bulkSendAgentIndex >= 0) {
Agent *bulkSendAgent = &agents[bulkSendAgentIndex];
bulkSendAgent->setLastRecvTimeUsecs(usecTimestampNow());
bulkSendAgent->recordBytesReceived(numTotalBytes);
}
unsigned char *startPosition = packetData;
@ -144,6 +150,7 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *pack
void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
agent->setLastRecvTimeUsecs(usecTimestampNow());
agent->recordBytesReceived(dataBytes);
if (agent->getLinkedData() == NULL) {
if (linkedDataCreateCallback != NULL) {
@ -285,6 +292,18 @@ void AgentList::handlePingReply(sockaddr *agentAddress) {
}
}
Agent* AgentList::soloAgentOfType(char agentType) {
if (memchr(SOLO_AGENT_TYPES_STRING, agentType, 1)) {
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
if (agent->getType() == agentType) {
return &*agent;
}
}
}
return NULL;
}
void *pingUnknownAgents(void *args) {
AgentList *agentList = (AgentList *)args;

View file

@ -22,7 +22,7 @@
const int MAX_PACKET_SIZE = 1500;
const unsigned int AGENT_SOCKET_LISTEN_PORT = 40103;
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;
extern const char *SOLO_AGENT_TYPES_STRING;
extern const char SOLO_AGENT_TYPES_STRING[];
extern char DOMAIN_HOSTNAME[];
extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup
@ -59,6 +59,8 @@ public:
char getOwnerType();
unsigned int getSocketListenPort();
Agent* soloAgentOfType(char agentType);
void startSilentAgentRemovalThread();
void stopSilentAgentRemovalThread();
void startDomainServerCheckInThread();

View file

@ -1,142 +0,0 @@
//
// CounterStats.cpp
// hifi
//
// Created by Brad Hefta-Gaub on 2013/04/08.
//
// Poor-man's counter stats collector class. Useful for collecting running averages
// and other stats for countable things.
//
//
#include "CounterStats.h"
#include <cstdio>
#ifdef _WIN32
#include "Systime.h"
#else
#include <sys/time.h>
#endif
#include <string>
#include <map>
#include "shared_Log.h"
//private:
// long int currentCount;
// long int currentDelta;
// double currentTime;
// double totalTime;
//
// long int countSamples[COUNTETSTATS_SAMPLES_TO_KEEP] = {};
// long int deltaSamples[COUNTETSTATS_SAMPLES_TO_KEEP] = {};
// double timeSamples[COUNTETSTATS_SAMPLES_TO_KEEP] = {};
// int sampleAt;
CounterStatHistory::CounterStatHistory() :
currentCount(0),
currentDelta(0),
currentTime(0.0),
lastCount(0),
lastTime(0.0),
totalTime(0.0),
sampleAt(-1),
sampleCount(0) {
}
CounterStatHistory::CounterStatHistory(std::string myName) :
name(myName),
currentCount(0),
currentDelta(0),
currentTime(0.0),
lastCount(0),
lastTime(0.0),
totalTime(0.0),
sampleAt(-1),
sampleCount(0) {
}
CounterStatHistory::CounterStatHistory(std::string myName, double initialTime, long initialCount) :
name(myName),
currentCount(initialCount),
currentDelta(0),
currentTime(initialTime),
lastCount(initialCount),
lastTime(initialTime),
totalTime(initialTime),
sampleAt(-1),
sampleCount(0) {
}
void CounterStatHistory::init() {
currentCount = 0;
currentDelta = 0;
currentTime = 0.0;
lastCount = 0;
lastTime = 0.0;
totalTime = 0.0;
sampleAt = -1;
sampleCount = 0;
}
void CounterStatHistory::recordSample(long thisCount) {
timeval now;
gettimeofday(&now,NULL);
double nowSeconds = (now.tv_usec/1000000.0)+(now.tv_sec);
this->recordSample(nowSeconds,thisCount);
}
void CounterStatHistory::recordSample(double thisTime, long thisCount) {
// how much did we change since last sample?
long thisDelta = thisCount - this->lastCount;
double elapsed = thisTime - this->lastTime;
// record the latest values
this->currentCount = thisCount;
this->currentTime = thisTime;
this->currentDelta = thisDelta;
//printLog("CounterStatHistory[%s]::recordSample(thisTime %lf, thisCount= %ld)\n",this->name.c_str(),thisTime,thisCount);
// if more than 1/10th of a second has passed, then record
// things in our rolling history
if (elapsed > 0.1) {
this->lastTime = thisTime;
this->lastCount = thisCount;
// record it in our history...
this->sampleAt = (this->sampleAt+1)%COUNTETSTATS_SAMPLES_TO_KEEP;
if (this->sampleCount<COUNTETSTATS_SAMPLES_TO_KEEP) {
this->sampleCount++;
}
this->countSamples[this->sampleAt]=thisCount;
this->timeSamples[this->sampleAt]=thisTime;
this->deltaSamples[this->sampleAt]=thisDelta;
//printLog("CounterStatHistory[%s]::recordSample() ACTUALLY RECORDING IT sampleAt=%d thisTime %lf, thisCount= %ld)\n",this->name.c_str(),this->sampleAt,thisTime,thisCount);
}
}
long CounterStatHistory::getRunningAverage() {
// before we calculate our running average, always "reset" the current count, with the current time
// this will flush out old data, if we haven't been adding any new data.
this->recordSample(this->currentCount);
long runningTotal = 0;
double minTime = this->timeSamples[0];
double maxTime = this->timeSamples[0];
for (int i =0; i < this->sampleCount; i++) {
minTime = std::min(minTime,this->timeSamples[i]);
maxTime = std::max(maxTime,this->timeSamples[i]);
runningTotal += this->deltaSamples[i];
}
double elapsedTime = maxTime-minTime;
long runningAverage = runningTotal/elapsedTime;
return runningAverage;
}

View file

@ -1,65 +0,0 @@
//
// CounterStats.h
// hifi
//
// Created by Brad Hefta-Gaub on 3/29/13.
//
// Poor-man's counter stats collector class. Useful for collecting running averages
// and other stats for countable things.
//
//
#ifndef __hifi__CounterStats__
#define __hifi__CounterStats__
#include <cstring>
#include <string>
#include <map>
// TIME_FRAME should be SAMPLES_TO_KEEP * TIME_BETWEEN_SAMPLES
#define COUNTETSTATS_SAMPLES_TO_KEEP 50
#define COUNTETSTATS_TIME_BETWEEN_SAMPLES 0.1
#define COUNTETSTATS_TIME_FRAME (COUNTETSTATS_SAMPLES_TO_KEEP*COUNTETSTATS_TIME_BETWEEN_SAMPLES)
class CounterStatHistory {
public:
std::string name;
CounterStatHistory();
CounterStatHistory(std::string myName);
CounterStatHistory(std::string myName, double initialTime, long initialCount);
void recordSample(long thisCount);
void recordSample(double thisTime, long thisCount);
long getRunningAverage();
long getAverage() {
return currentCount/totalTime;
};
double getTotalTime() {
return totalTime;
};
long getCount() {
return currentCount;
};
private:
void init();
long currentCount;
long currentDelta;
double currentTime;
long lastCount;
double lastTime;
double totalTime;
long countSamples[COUNTETSTATS_SAMPLES_TO_KEEP];
long deltaSamples[COUNTETSTATS_SAMPLES_TO_KEEP];
double timeSamples[COUNTETSTATS_SAMPLES_TO_KEEP];
int sampleAt;
int sampleCount;
};
#endif /* defined(__hifi__CounterStat__) */

View file

@ -0,0 +1,54 @@
//
// SimpleMovingAverage.cpp
// hifi
//
// Created by Stephen Birarda on 4/18/13.
//
//
#include "SharedUtil.h"
#include "SimpleMovingAverage.h"
SimpleMovingAverage::SimpleMovingAverage(int numSamplesToAverage) :
_numSamples(0),
_average(0),
_eventDeltaAverage(0),
WEIGHTING(1.0f / numSamplesToAverage),
ONE_MINUS_WEIGHTING(1 - WEIGHTING) {
}
int SimpleMovingAverage::updateAverage(float sample) {
if (_numSamples > 0) {
_average = (ONE_MINUS_WEIGHTING * _average) + (WEIGHTING * sample);
float eventDelta = (usecTimestampNow() - _lastEventTimestamp) / 1000000;
if (_numSamples > 1) {
_eventDeltaAverage = (ONE_MINUS_WEIGHTING * _eventDeltaAverage) +
(WEIGHTING * eventDelta);
} else {
_eventDeltaAverage = eventDelta;
}
} else {
_average = sample;
_eventDeltaAverage = 0;
}
_lastEventTimestamp = usecTimestampNow();
return ++_numSamples;
}
void SimpleMovingAverage::reset() {
_numSamples = 0;
}
float SimpleMovingAverage::getEventDeltaAverage() {
return (ONE_MINUS_WEIGHTING * _eventDeltaAverage) +
(WEIGHTING * ((usecTimestampNow() - _lastEventTimestamp) / 1000000));
}
float SimpleMovingAverage::getAverageSampleValuePerSecond() {
return _average * (1 / getEventDeltaAverage());
}

View file

@ -0,0 +1,36 @@
//
// SimpleMovingAverage.h
// hifi
//
// Created by Stephen Birarda on 4/18/13.
// Replaces Brad Hefta-Gaub's CounterStats class (RIP)
//
//
#ifndef __hifi__Stats__
#define __hifi__Stats__
#include <iostream>
class SimpleMovingAverage {
public:
SimpleMovingAverage(int numSamplesToAverage);
int updateAverage(float sample);
void reset();
int getSampleCount() { return _numSamples; };
float getAverage() { return _average; };
float getEventDeltaAverage();
float getAverageSampleValuePerSecond();
private:
int _numSamples;
double _lastEventTimestamp;
float _average;
float _eventDeltaAverage;
const float WEIGHTING;
const float ONE_MINUS_WEIGHTING;
};
#endif /* defined(__hifi__Stats__) */

View file

@ -15,7 +15,6 @@
#include "SharedUtil.h"
#include "voxels_Log.h"
#include "PacketHeaders.h"
#include "CounterStats.h"
#include "OctalCode.h"
#include "VoxelTree.h"
#include <fstream> // to load voxels from file
@ -46,19 +45,17 @@ int boundaryDistanceForRenderLevel(unsigned int renderLevel) {
}
}
VoxelTree::VoxelTree() {
VoxelTree::VoxelTree() :
voxelsCreated(0),
voxelsColored(0),
voxelsBytesRead(0),
voxelsCreatedStats(100),
voxelsColoredStats(100),
voxelsBytesReadStats(100) {
rootNode = new VoxelNode();
rootNode->octalCode = new unsigned char[1];
*rootNode->octalCode = 0;
// Some stats tracking
this->voxelsCreated = 0; // when a voxel is created in the tree (object new'd)
this->voxelsColored = 0; // when a voxel is colored/set in the tree (object may have already existed)
this->voxelsBytesRead = 0;
voxelsCreatedStats.name = "voxelsCreated";
voxelsColoredStats.name = "voxelsColored";
voxelsBytesReadStats.name = "voxelsBytesRead";
}
VoxelTree::~VoxelTree() {
@ -147,7 +144,7 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode,
if (destinationNode->children[i] == NULL) {
destinationNode->addChildAtIndex(i);
this->voxelsCreated++;
this->voxelsCreatedStats.recordSample(this->voxelsCreated);
this->voxelsCreatedStats.updateAverage(1);
}
// pull the color for this child
@ -156,7 +153,7 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode,
newColor[3] = 1;
destinationNode->children[i]->setColor(newColor);
this->voxelsColored++;
this->voxelsColoredStats.recordSample(this->voxelsColored);
this->voxelsColoredStats.updateAverage(1);
bytesRead += 3;
}
@ -179,7 +176,7 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode,
// add a child at that index, if it doesn't exist
destinationNode->addChildAtIndex(childIndex);
this->voxelsCreated++;
this->voxelsCreatedStats.recordSample(this->voxelsCreated);
this->voxelsCreatedStats.updateAverage(this->voxelsCreated);
}
// tell the child to read the subsequent data
@ -207,7 +204,7 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, int bufferSizeByt
readNodeData(bitstreamRootNode, bitstream + octalCodeBytes, bufferSizeBytes - octalCodeBytes);
this->voxelsBytesRead += bufferSizeBytes;
this->voxelsBytesReadStats.recordSample(this->voxelsBytesRead);
this->voxelsBytesReadStats.updateAverage(bufferSizeBytes);
}
// Note: uses the codeColorBuffer format, but the color's are ignored, because

View file

@ -9,7 +9,7 @@
#ifndef __hifi__VoxelTree__
#define __hifi__VoxelTree__
#include "CounterStats.h"
#include "SimpleMovingAverage.h"
#include "VoxelNode.h"
#include "MarkerNode.h"
@ -23,13 +23,15 @@ typedef bool (*RecurseVoxelTreeOperation)(VoxelNode* node, bool down, void* extr
class VoxelTree {
public:
// when a voxel is created in the tree (object new'd)
long voxelsCreated;
// when a voxel is colored/set in the tree (object may have already existed)
long voxelsColored;
long voxelsBytesRead;
CounterStatHistory voxelsCreatedStats;
CounterStatHistory voxelsColoredStats;
CounterStatHistory voxelsBytesReadStats;
SimpleMovingAverage voxelsCreatedStats;
SimpleMovingAverage voxelsColoredStats;
SimpleMovingAverage voxelsBytesReadStats;
VoxelTree();
~VoxelTree();