Merge pull request #158 from ey6es/master

Reverted threading change by default, since we're seeing lower frame rates.
This commit is contained in:
Philip Rosedale 2013-04-26 17:19:11 -07:00
commit ebc5d665c0

View file

@ -39,6 +39,8 @@
#include <ifaddrs.h> #include <ifaddrs.h>
#endif #endif
#include <pthread.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
@ -86,6 +88,10 @@ using namespace std;
void reshape(int width, int height); // will be defined below void reshape(int width, int height); // will be defined below
void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below
bool enableNetworkThread = true;
pthread_t networkReceiveThread;
bool stopNetworkReceiveThread = false;
unsigned char incomingPacket[MAX_PACKET_SIZE]; unsigned char incomingPacket[MAX_PACKET_SIZE];
int packetCount = 0; int packetCount = 0;
int packetsPerSecond = 0; int packetsPerSecond = 0;
@ -349,6 +355,11 @@ void terminate () {
audio.terminate(); audio.terminate();
#endif #endif
if (enableNetworkThread) {
stopNetworkReceiveThread = true;
pthread_join(networkReceiveThread, NULL);
}
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -1408,12 +1419,13 @@ void key(unsigned char k, int x, int y)
} }
// Receive packets from other agents/servers and decide what to do with them! // Receive packets from other agents/servers and decide what to do with them!
void networkReceive() void* networkReceive(void* args)
{ {
sockaddr senderAddress; sockaddr senderAddress;
ssize_t bytesReceived; ssize_t bytesReceived;
while (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { while (!stopNetworkReceiveThread) {
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
packetCount++; packetCount++;
bytesCount += bytesReceived; bytesCount += bytesReceived;
@ -1435,9 +1447,17 @@ void networkReceive()
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
break; break;
} }
} else if (!enableNetworkThread) {
break;
} }
} }
if (enableNetworkThread) {
pthread_exit(0);
}
return NULL;
}
void idle(void) { void idle(void) {
timeval check; timeval check;
gettimeofday(&check, NULL); gettimeofday(&check, NULL);
@ -1472,7 +1492,9 @@ void idle(void) {
updateAvatar(deltaTime); updateAvatar(deltaTime);
// read incoming packets from network // read incoming packets from network
networkReceive(); if (!enableNetworkThread) {
networkReceive(0);
}
//loop through all the other avatars and simulate them... //loop through all the other avatars and simulate them...
AgentList* agentList = AgentList::getInstance(); AgentList* agentList = AgentList::getInstance();
@ -1616,7 +1638,10 @@ int main(int argc, const char * argv[])
listenPort = atoi(portStr); listenPort = atoi(portStr);
} }
AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort);
enableNetworkThread = !cmdOptionExists(argc, argv, "--nonblocking");
if (!enableNetworkThread) {
AgentList::getInstance()->getAgentSocket().setBlocking(false); AgentList::getInstance()->getAgentSocket().setBlocking(false);
}
gettimeofday(&applicationStartupTime, NULL); gettimeofday(&applicationStartupTime, NULL);
const char* domainIP = getCmdOption(argc, argv, "--domain"); const char* domainIP = getCmdOption(argc, argv, "--domain");
@ -1699,6 +1724,12 @@ int main(int argc, const char * argv[])
printLog("Local Voxel File loaded.\n"); printLog("Local Voxel File loaded.\n");
} }
// create thread for receipt of data via UDP
if (enableNetworkThread) {
pthread_create(&networkReceiveThread, NULL, networkReceive, NULL);
printLog("Network receive thread created.\n");
}
glutTimerFunc(1000, Timer, 0); glutTimerFunc(1000, Timer, 0);
glutMainLoop(); glutMainLoop();