mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:58:09 +02:00
Added toggle for nonblocking networking; default to threaded for now, since
we're seeing lower frame rates.
This commit is contained in:
parent
1804357eab
commit
c26becf6cb
1 changed files with 56 additions and 25 deletions
|
@ -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>
|
||||||
|
@ -85,6 +87,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;
|
||||||
|
@ -416,6 +422,11 @@ void terminate () {
|
||||||
audio.terminate();
|
audio.terminate();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (enableNetworkThread) {
|
||||||
|
stopNetworkReceiveThread = true;
|
||||||
|
pthread_join(networkReceiveThread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1474,34 +1485,43 @@ 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) {
|
||||||
packetCount++;
|
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
bytesCount += bytesReceived;
|
packetCount++;
|
||||||
|
bytesCount += bytesReceived;
|
||||||
switch (incomingPacket[0]) {
|
|
||||||
case PACKET_HEADER_TRANSMITTER_DATA:
|
switch (incomingPacket[0]) {
|
||||||
myAvatar.processTransmitterData(incomingPacket, bytesReceived);
|
case PACKET_HEADER_TRANSMITTER_DATA:
|
||||||
break;
|
myAvatar.processTransmitterData(incomingPacket, bytesReceived);
|
||||||
case PACKET_HEADER_VOXEL_DATA:
|
break;
|
||||||
case PACKET_HEADER_Z_COMMAND:
|
case PACKET_HEADER_VOXEL_DATA:
|
||||||
case PACKET_HEADER_ERASE_VOXEL:
|
case PACKET_HEADER_Z_COMMAND:
|
||||||
voxels.parseData(incomingPacket, bytesReceived);
|
case PACKET_HEADER_ERASE_VOXEL:
|
||||||
break;
|
voxels.parseData(incomingPacket, bytesReceived);
|
||||||
case PACKET_HEADER_BULK_AVATAR_DATA:
|
break;
|
||||||
AgentList::getInstance()->processBulkAgentData(&senderAddress,
|
case PACKET_HEADER_BULK_AVATAR_DATA:
|
||||||
incomingPacket,
|
AgentList::getInstance()->processBulkAgentData(&senderAddress,
|
||||||
bytesReceived);
|
incomingPacket,
|
||||||
break;
|
bytesReceived);
|
||||||
default:
|
break;
|
||||||
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
default:
|
||||||
break;
|
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (!enableNetworkThread) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enableNetworkThread) {
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle(void) {
|
void idle(void) {
|
||||||
|
@ -1536,7 +1556,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();
|
||||||
|
@ -1680,7 +1702,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);
|
||||||
AgentList::getInstance()->getAgentSocket().setBlocking(false);
|
enableNetworkThread = !cmdOptionExists(argc, argv, "--nonblocking");
|
||||||
|
if (!enableNetworkThread) {
|
||||||
|
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");
|
||||||
|
@ -1763,6 +1788,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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue