Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philip Rosedale 2013-05-06 13:29:34 -07:00
commit eedbb98c32
11 changed files with 198 additions and 186 deletions

View file

@ -10,4 +10,5 @@ add_subdirectory(interface)
add_subdirectory(injector)
add_subdirectory(pairing-server)
add_subdirectory(space-server)
add_subdirectory(voxel-edit)add_subdirectory(voxel-server)
add_subdirectory(voxel-edit)
add_subdirectory(voxel-server)

View file

@ -45,8 +45,6 @@ unsigned char packetData[MAX_PACKET_SIZE];
const int LOGOFF_CHECK_INTERVAL = 5000;
#define DEBUG_TO_SELF 0
int lastActiveCount = 0;
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
@ -81,10 +79,10 @@ int main(int argc, const char * argv[])
setvbuf(stdout, NULL, _IOLBF, 0);
ssize_t receivedBytes = 0;
char agentType;
char agentType = '\0';
unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE];
*broadcastPacket = PACKET_HEADER_DOMAIN;
unsigned char broadcastPacket[MAX_PACKET_SIZE];
broadcastPacket[0] = PACKET_HEADER_DOMAIN;
unsigned char* currentBufferPos;
unsigned char* startPointer;
@ -101,8 +99,8 @@ int main(int argc, const char * argv[])
if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) {
std::map<char, Agent *> newestSoloAgents;
agentType = packetData[0];
unpackSocket(&packetData[1], (sockaddr *)&agentLocalAddress);
agentType = packetData[1];
unpackSocket(&packetData[2], (sockaddr*) g&agentLocalAddress);
// check the agent public address
// if it matches our local address we're on the same box
@ -119,17 +117,19 @@ int main(int argc, const char * argv[])
(sockaddr*) &agentLocalAddress,
agentType,
agentList->getLastAgentId())) {
agentList->increaseAgentId();
} else if (packetData[0] == PACKET_HEADER_DOMAIN_RFD) {
// if this is a previous agent, and they are re-reporting for duty
// then we need to update the first receive time
Agent* refreshedAgent = agentList->agentWithAddress((sockaddr*) &agentLocalAddress);
refreshedAgent->setWakeMicrostamp(usecTimestampNow());
}
currentBufferPos = broadcastPacket + 1;
currentBufferPos = broadcastPacket + 2;
startPointer = currentBufferPos;
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (DEBUG_TO_SELF ||
!agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) {
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) {
if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) {
// this is an agent of which there can be multiple, just add them to the packet
// don't send avatar agents to other avatars, that will come from avatar mixer
@ -140,22 +140,22 @@ int main(int argc, const char * argv[])
} else {
// solo agent, we need to only send newest
if (newestSoloAgents[agent->getType()] == NULL ||
newestSoloAgents[agent->getType()]->getFirstRecvTimeUsecs() < agent->getFirstRecvTimeUsecs()) {
newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) {
// we have to set the newer solo agent to add it to the broadcast later
newestSoloAgents[agent->getType()] = &(*agent);
}
}
} else {
// this is the agent, just update last receive to now
agent->setLastRecvTimeUsecs(usecTimestampNow());
agent->setLastHeardMicrostamp(usecTimestampNow());
}
}
for (std::map<char, Agent *>::iterator agentIterator = newestSoloAgents.begin();
agentIterator != newestSoloAgents.end();
agentIterator++) {
for (std::map<char, Agent *>::iterator soloAgent = newestSoloAgents.begin();
soloAgent != newestSoloAgents.end();
soloAgent++) {
// this is the newest alive solo agent, add them to the packet
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, agentIterator->second);
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second);
}
if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) {

View file

@ -21,7 +21,9 @@
using namespace std;
const bool BALLS_ON = false;
const bool AVATAR_GRAVITY = true;
const bool USING_AVATAR_GRAVITY = true;
const float GRAVITY_SCALE = 6.0f;
const float BOUNCE = 0.3f;
const float DECAY = 0.1;
const float THRUST_MAG = 1200.0;
const float YAW_MAG = 500.0;
@ -145,6 +147,7 @@ Avatar::Avatar(bool isMine) {
_interactingOther = NULL;
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_distanceToNearestAvatar = std::numeric_limits<float>::max();
_gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default
initializeSkeleton();
@ -336,13 +339,13 @@ void Avatar::simulate(float deltaTime) {
updateHandMovementAndTouching(deltaTime);
// apply gravity and collision wiht the ground/floor
if (AVATAR_GRAVITY) {
// apply gravity and collision with the ground/floor
if (USING_AVATAR_GRAVITY) {
if (_position.y > _pelvisStandingHeight + 0.01f) {
_velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime );
_velocity += _gravity * (GRAVITY_SCALE * deltaTime);
} else if (_position.y < _pelvisStandingHeight) {
_position.y = _pelvisStandingHeight;
_velocity.y = 0.0;
_velocity.y = -_velocity.y * BOUNCE;
}
}
@ -695,7 +698,7 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi
if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) {
float bodyMomentum = 1.0f;
glm::vec3 bodyPushForce = glm::vec3( 0.0, 0.0, 0.0 );
glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f);
// loop through the joints of each avatar to check for every possible collision
for (int b=1; b<NUM_AVATAR_JOINTS; b++) {
@ -760,6 +763,11 @@ static TextRenderer* textRenderer() {
}
void Avatar::setGravity(glm::vec3 gravity) {
_gravity = gravity;
}
void Avatar::render(bool lookingInMirror) {
// render a simple round on the ground projected down from the avatar's position
@ -1523,25 +1531,6 @@ void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity
}
}
// Find and return the gravity vector at my location
glm::vec3 Avatar::getGravity(glm::vec3 pos) {
//
// For now, we'll test this with a simple global lookup, but soon we will add getting this
// from the domain/voxelserver (or something similar)
//
if ((pos.x > 0.f) &&
(pos.x < 10.f) &&
(pos.z > 0.f) &&
(pos.z < 10.f) &&
(pos.y > 0.f) &&
(pos.y < 3.f)) {
// If above ground plane, turn gravity on
return glm::vec3(0.f, -1.f, 0.f);
} else {
// If flying in space, turn gravity OFF
return glm::vec3(0.f, 0.f, 0.f);
}
}
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";

View file

@ -93,6 +93,7 @@ public:
float getLastMeasuredHeadYaw() const {return _head.yawRate;}
float getBodyYaw() {return _bodyYaw;};
void addBodyYaw(float y) {_bodyYaw += y;};
void setGravity(glm::vec3 gravity);
bool getIsNearInteractingOther();
@ -143,9 +144,6 @@ public:
void processTransmitterData(unsigned char * packetData, int numBytes);
float getTransmitterHz() { return _transmitterHz; };
// Find out what the local gravity vector is at this location
glm::vec3 getGravity(glm::vec3 pos);
void writeAvatarDataToFile();
void readAvatarDataFromFile();
@ -251,6 +249,7 @@ private:
bool _displayingHead; // should be false if in first-person view
bool _returnHeadToCenter;
float _distanceToNearestAvatar; // How close is the nearest avatar?
glm::vec3 _gravity;
// private methods...
void initializeSkeleton();

View file

@ -43,6 +43,9 @@ void SerialInterface::pair() {
int matchStatus;
regex_t regex;
if (_failedOpenAttempts < 2) {
// if we've already failed to open the detected interface twice then don't try again
// for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
if((devDir = opendir("/dev"))) {
while((entry = readdir(devDir))) {
@ -60,8 +63,9 @@ void SerialInterface::pair() {
}
closedir(devDir);
}
#endif
}
#endif
}
// connect to the serial port
@ -73,6 +77,7 @@ int SerialInterface::initializePort(char* portname, int baud) {
if (serialFd == -1) {
printLog("Failed.\n");
_failedOpenAttempts++;
return -1; // Failed to open port
}
struct termios options;

View file

@ -36,7 +36,8 @@ extern const bool USING_INVENSENSE_MPU9150;
class SerialInterface {
public:
SerialInterface() { active = false; };
SerialInterface() : active(false),
_failedOpenAttempts(0) {}
void pair();
void readData();
@ -68,6 +69,7 @@ private:
int _lastYaw;
int _lastPitch;
int _lastRoll;
int _failedOpenAttempts;
};
#endif

View file

@ -90,6 +90,8 @@ using namespace std;
void reshape(int width, int height); // will be defined below
void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below
glm::vec3 getGravity(glm::vec3 pos); //get the local gravity vector at this location in the universe
QApplication* app;
bool enableNetworkThread = true;
@ -1703,6 +1705,7 @@ void idle(void) {
}
agentList->unlock();
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
myAvatar.simulate(deltaTime);
glutPostRedisplay();
@ -1765,6 +1768,30 @@ void reshape(int width, int height) {
glLoadIdentity();
}
//Find and return the gravity vector at this location
glm::vec3 getGravity(glm::vec3 pos) {
//
// For now, we'll test this with a simple global lookup, but soon we will add getting this
// from the domain/voxelserver (or something similar)
//
if ((pos.x > 0.f) &&
(pos.x < 10.f) &&
(pos.z > 0.f) &&
(pos.z < 10.f) &&
(pos.y > 0.f) &&
(pos.y < 3.f)) {
// If above ground plane, turn gravity on
return glm::vec3(0.f, -1.f, 0.f);
} else {
// If flying in space, turn gravity OFF
return glm::vec3(0.f, 0.f, 0.f);
}
}
void mouseFunc(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {

View file

@ -52,8 +52,8 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent
type = agentType;
agentId = thisAgentId;
firstRecvTimeUsecs = usecTimestampNow();
lastRecvTimeUsecs = usecTimestampNow();
_wakeMicrostamp = usecTimestampNow();
_lastHeardMicrostamp = usecTimestampNow();
activeSocket = NULL;
linkedData = NULL;
@ -87,8 +87,8 @@ Agent::Agent(const Agent &otherAgent) {
activeSocket = NULL;
}
firstRecvTimeUsecs = otherAgent.firstRecvTimeUsecs;
lastRecvTimeUsecs = otherAgent.lastRecvTimeUsecs;
_wakeMicrostamp = otherAgent._wakeMicrostamp;
_lastHeardMicrostamp = otherAgent._lastHeardMicrostamp;
type = otherAgent.type;
if (otherAgent.linkedData != NULL) {
@ -120,8 +120,8 @@ void Agent::swap(Agent &first, Agent &second) {
swap(first.type, second.type);
swap(first.linkedData, second.linkedData);
swap(first.agentId, second.agentId);
swap(first.firstRecvTimeUsecs, second.firstRecvTimeUsecs);
swap(first.lastRecvTimeUsecs, second.lastRecvTimeUsecs);
swap(first._wakeMicrostamp, second._wakeMicrostamp);
swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp);
swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage);
}
@ -178,22 +178,6 @@ void Agent::setAgentId(uint16_t thisAgentId) {
agentId = thisAgentId;
}
double Agent::getFirstRecvTimeUsecs() {
return firstRecvTimeUsecs;
}
void Agent::setFirstRecvTimeUsecs(double newTimeUsecs) {
firstRecvTimeUsecs = newTimeUsecs;
}
double Agent::getLastRecvTimeUsecs() {
return lastRecvTimeUsecs;
}
void Agent::setLastRecvTimeUsecs(double newTimeUsecs) {
lastRecvTimeUsecs = newTimeUsecs;
}
sockaddr* Agent::getPublicSocket() {
return publicSocket;
}

View file

@ -38,11 +38,11 @@ public:
uint16_t getAgentId();
void setAgentId(uint16_t thisAgentId);
double getFirstRecvTimeUsecs();
void setFirstRecvTimeUsecs(double newTimeUsecs);
double getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
double getLastRecvTimeUsecs();
void setLastRecvTimeUsecs(double newTimeUsecs);
double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
sockaddr* getPublicSocket();
void setPublicSocket(sockaddr *newSocket);
@ -70,8 +70,8 @@ private:
sockaddr *publicSocket, *localSocket, *activeSocket;
char type;
uint16_t agentId;
double firstRecvTimeUsecs;
double lastRecvTimeUsecs;
double _wakeMicrostamp;
double _lastHeardMicrostamp;
SimpleMovingAverage* _bytesReceivedMovingAverage;
AgentData* linkedData;
bool _isAlive;

View file

@ -64,8 +64,7 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) :
agentSocket(newSocketListenPort),
ownerType(newOwnerType),
socketListenPort(newSocketListenPort),
lastAgentId(0)
{
lastAgentId(0) {
pthread_mutex_init(&mutex, 0);
}
@ -114,7 +113,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
Agent* bulkSendAgent = agentWithAddress(senderAddress);
if (bulkSendAgent) {
bulkSendAgent->setLastRecvTimeUsecs(usecTimestampNow());
bulkSendAgent->setLastHeardMicrostamp(usecTimestampNow());
bulkSendAgent->recordBytesReceived(numTotalBytes);
}
@ -161,7 +160,7 @@ int AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packe
}
int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
agent->setLastRecvTimeUsecs(usecTimestampNow());
agent->setLastHeardMicrostamp(usecTimestampNow());
if (agent->getActiveSocket() != NULL) {
agent->recordBytesReceived(dataBytes);
@ -273,7 +272,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
if (agent->getType() == AGENT_TYPE_AUDIO_MIXER || agent->getType() == AGENT_TYPE_VOXEL) {
// until the Audio class also uses our agentList, we need to update
// the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously
agent->setLastRecvTimeUsecs(usecTimestampNow());
agent->setLastHeardMicrostamp(usecTimestampNow());
}
// we had this agent already, do nothing for now
@ -383,7 +382,7 @@ void *removeSilentAgents(void *args) {
for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); ++agent) {
if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS
if ((checkTimeUSecs - agent->getLastHeardMicrostamp()) > AGENT_SILENCE_THRESHOLD_USECS
&& agent->getType() != AGENT_TYPE_VOXEL) {
printLog("Killing agent - ");
@ -418,13 +417,6 @@ void *checkInWithDomainServer(void *args) {
const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
AgentList* parentAgentList = (AgentList*) args;
timeval lastSend;
unsigned char output[7];
in_addr_t localAddress = getLocalAddress();
// Lookup the IP address of the domain server if we need to
if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo;
@ -439,14 +431,23 @@ void *checkInWithDomainServer(void *args) {
}
} else printLog("Using static domainserver IP: %s\n", DOMAIN_IP);
AgentList* parentAgentList = (AgentList*) args;
timeval lastSend;
in_addr_t localAddress = getLocalAddress();
unsigned char packet[8];
packet[0] = PACKET_HEADER_DOMAIN_RFD;
packet[1] = parentAgentList->getOwnerType();
while (!domainServerCheckinStopFlag) {
gettimeofday(&lastSend, NULL);
output[0] = parentAgentList->getOwnerType();
packSocket(output + 1, localAddress, htons(parentAgentList->getSocketListenPort()));
packSocket(packet + 2, localAddress, htons(parentAgentList->getSocketListenPort()));
parentAgentList->getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
parentAgentList->getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, packet, sizeof(packet));
packet[0] = PACKET_HEADER_DOMAIN_LIST_REQUEST;
double usecToSleep = DOMAIN_SERVER_CHECK_IN_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
@ -481,7 +482,8 @@ AgentList::iterator AgentList::begin() const {
}
}
return AgentListIterator(this, 0);
// there's no alive agent to start from - return the end
return end();
}
AgentList::iterator AgentList::end() const {

View file

@ -1,3 +1,4 @@
//
// PacketHeaders.h
// hifi
@ -23,5 +24,7 @@ const char PACKET_HEADER_ERASE_VOXEL = 'E';
const char PACKET_HEADER_VOXEL_DATA = 'V';
const char PACKET_HEADER_BULK_AVATAR_DATA = 'X';
const char PACKET_HEADER_TRANSMITTER_DATA = 't';
const char PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L';
const char PACKET_HEADER_DOMAIN_RFD = 'C';
#endif