Merge pull request #121 from birarda/master

add some randomization to eve so there can be many
This commit is contained in:
birarda 2013-04-23 15:48:22 -07:00
commit b24ad5e89b

View file

@ -15,8 +15,9 @@
#include <AvatarData.h>
#include <AudioInjector.h>
const int EVE_AGENT_LIST_PORT = 55441;
const float DATA_SEND_INTERVAL_MSECS = 10;
const float RANDOM_POSITION_MAX_DIMENSION = 5.0f;
const float DATA_SEND_INTERVAL_MSECS = 15;
const float MIN_AUDIO_SEND_INTERVAL_SECS = 10;
const int MIN_ITERATIONS_BETWEEN_AUDIO_SENDS = (MIN_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS;
const int MAX_AUDIO_SEND_INTERVAL_SECS = 15;
@ -26,7 +27,7 @@ bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false;
int TEMP_AUDIO_LISTEN_PORT = 55439;
UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT);
// UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT);
void *receiveAgentData(void *args) {
sockaddr senderAddress;
@ -77,7 +78,7 @@ void *injectAudio(void *args) {
}
// we have an active audio mixer we can send data to
eveAudioInjector->injectAudio(&::audioSocket, audioMixer->getActiveSocket());
// eveAudioInjector->injectAudio(&::audioSocket, audioMixer->getActiveSocket());
}
::injectAudioThreadRunning = false;
@ -90,7 +91,7 @@ int main(int argc, const char* argv[]) {
srand(time(0));
// create an AgentList instance to handle communication with other agents
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR, EVE_AGENT_LIST_PORT);
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR, randIntInRange(1500, 65000));
// start telling the domain server that we are alive
agentList->startDomainServerCheckInThread();
@ -108,10 +109,14 @@ int main(int argc, const char* argv[]) {
AvatarData eve = AvatarData();
// move eve away from the origin
eve.setBodyPosition(glm::vec3(3, 0, -3));
// pick a random point inside a 10x10 grid
// turn her back towards the origin
eve.setBodyYaw(-45);
eve.setBodyPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION),
0,
randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION)));
// face any instance of eve down the z-axis
eve.setBodyYaw(0);
// put her hand out so somebody can shake it
eve.setHandPosition(glm::vec3(eve.getBodyPosition()[0] - 0.2,
@ -129,8 +134,8 @@ int main(int argc, const char* argv[]) {
timeval thisSend;
double numMicrosecondsSleep = 0;
int numIterationsLeftBeforeAudioSend = 0;
pthread_t injectAudioThread;
// int numIterationsLeftBeforeAudioSend = 0;
// pthread_t injectAudioThread;
while (true) {
// update the thisSend timeval to the current time
@ -147,17 +152,18 @@ int main(int argc, const char* argv[]) {
// use the UDPSocket instance attached to our agent list to send avatar data to mixer
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, numBytesToSend);
}
if (numIterationsLeftBeforeAudioSend == 0) {
if (!::injectAudioThreadRunning) {
pthread_create(&injectAudioThread, NULL, injectAudio, (void*) &eveAudioInjector);
numIterationsLeftBeforeAudioSend = randIntInRange(MIN_ITERATIONS_BETWEEN_AUDIO_SENDS,
MAX_ITERATIONS_BETWEEN_AUDIO_SENDS);
}
} else {
numIterationsLeftBeforeAudioSend--;
}
// temporarily disable Eve's audio sending until the file is actually available on EC2 box
// if (numIterationsLeftBeforeAudioSend == 0) {
// if (!::injectAudioThreadRunning) {
// pthread_create(&injectAudioThread, NULL, injectAudio, (void*) &eveAudioInjector);
//
// numIterationsLeftBeforeAudioSend = randIntInRange(MIN_ITERATIONS_BETWEEN_AUDIO_SENDS,
// MAX_ITERATIONS_BETWEEN_AUDIO_SENDS);
// }
// } else {
// numIterationsLeftBeforeAudioSend--;
// }
// sleep for the correct amount of time to have data send be consistently timed
if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {