mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:41:02 +02:00
Send all environment data in the same packet and only send it about once a
second.
This commit is contained in:
parent
b6e78064d8
commit
629c7b0146
5 changed files with 41 additions and 22 deletions
|
@ -114,19 +114,29 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
|
||||||
}
|
}
|
||||||
|
|
||||||
int Environment::parseData(sockaddr *senderAddress, unsigned char* sourceBuffer, int numBytes) {
|
int Environment::parseData(sockaddr *senderAddress, unsigned char* sourceBuffer, int numBytes) {
|
||||||
EnvironmentData newData;
|
// push past the packet header
|
||||||
int bytesRead = newData.parseData(sourceBuffer, numBytes);
|
unsigned char* start = sourceBuffer;
|
||||||
|
sourceBuffer++;
|
||||||
|
numBytes--;
|
||||||
|
|
||||||
// get the lock for the duration of the call
|
// get the lock for the duration of the call
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
|
|
||||||
// update the mapping by address/ID
|
EnvironmentData newData;
|
||||||
_data[*senderAddress][newData.getID()] = newData;
|
while (numBytes > 0) {
|
||||||
|
int dataLength = newData.parseData(sourceBuffer, numBytes);
|
||||||
|
|
||||||
|
// update the mapping by address/ID
|
||||||
|
_data[*senderAddress][newData.getID()] = newData;
|
||||||
|
|
||||||
|
sourceBuffer += dataLength;
|
||||||
|
numBytes -= dataLength;
|
||||||
|
}
|
||||||
|
|
||||||
// remove the default mapping, if any
|
// remove the default mapping, if any
|
||||||
_data.remove(getZeroAddress());
|
_data.remove(getZeroAddress());
|
||||||
|
|
||||||
return bytesRead;
|
return sourceBuffer - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
|
ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
|
||||||
|
|
|
@ -52,6 +52,10 @@ bool randomBoolean() {
|
||||||
return rand() % 2;
|
return rand() % 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldDo(float desiredInterval, float deltaTime) {
|
||||||
|
return randFloat() < deltaTime / desiredInterval;
|
||||||
|
}
|
||||||
|
|
||||||
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
|
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
outputBits(buffer[i], false);
|
outputBits(buffer[i], false);
|
||||||
|
@ -417,4 +421,3 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex,
|
||||||
}
|
}
|
||||||
return -1; // error case
|
return -1; // error case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ float randFloatInRange (float min,float max);
|
||||||
unsigned char randomColorValue(int minimum);
|
unsigned char randomColorValue(int minimum);
|
||||||
bool randomBoolean();
|
bool randomBoolean();
|
||||||
|
|
||||||
|
bool shouldDo(float desiredInterval, float deltaTime);
|
||||||
|
|
||||||
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine = true);
|
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine = true);
|
||||||
void outputBits(unsigned char byte, bool withNewLine = true);
|
void outputBits(unsigned char byte, bool withNewLine = true);
|
||||||
void printVoxelCode(unsigned char* voxelCode);
|
void printVoxelCode(unsigned char* voxelCode);
|
||||||
|
|
|
@ -28,8 +28,6 @@ EnvironmentData::EnvironmentData(int id) :
|
||||||
int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
||||||
unsigned char* bufferStart = destinationBuffer;
|
unsigned char* bufferStart = destinationBuffer;
|
||||||
|
|
||||||
*destinationBuffer++ = PACKET_HEADER_ENVIRONMENT_DATA;
|
|
||||||
|
|
||||||
memcpy(destinationBuffer, &_id, sizeof(_id));
|
memcpy(destinationBuffer, &_id, sizeof(_id));
|
||||||
destinationBuffer += sizeof(_id);
|
destinationBuffer += sizeof(_id);
|
||||||
|
|
||||||
|
@ -64,9 +62,6 @@ int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int EnvironmentData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
int EnvironmentData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
// increment to push past the packet header
|
|
||||||
sourceBuffer++;
|
|
||||||
|
|
||||||
unsigned char* startPosition = sourceBuffer;
|
unsigned char* startPosition = sourceBuffer;
|
||||||
|
|
||||||
memcpy(&_id, sourceBuffer, sizeof(_id));
|
memcpy(&_id, sourceBuffer, sizeof(_id));
|
||||||
|
|
|
@ -49,6 +49,8 @@ int PACKETS_PER_CLIENT_PER_INTERVAL = 50;
|
||||||
|
|
||||||
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
|
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
|
||||||
|
|
||||||
|
const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000;
|
||||||
|
|
||||||
VoxelTree randomTree(true); // this is a reaveraging tree
|
VoxelTree randomTree(true); // this is a reaveraging tree
|
||||||
bool wantVoxelPersist = true;
|
bool wantVoxelPersist = true;
|
||||||
bool wantLocalDomain = false;
|
bool wantLocalDomain = false;
|
||||||
|
@ -161,8 +163,8 @@ void resInVoxelDistributor(AgentList* agentList,
|
||||||
int trueBytesSent = 0;
|
int trueBytesSent = 0;
|
||||||
double start = usecTimestampNow();
|
double start = usecTimestampNow();
|
||||||
|
|
||||||
int environmentPacketCount = sizeof(environmentData) / sizeof(environmentData[0]);
|
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
|
||||||
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - environmentPacketCount) {
|
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
|
||||||
if (!agentData->nodeBag.isEmpty()) {
|
if (!agentData->nodeBag.isEmpty()) {
|
||||||
VoxelNode* subTree = agentData->nodeBag.extract();
|
VoxelNode* subTree = agentData->nodeBag.extract();
|
||||||
bytesWritten = randomTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree,
|
bytesWritten = randomTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree,
|
||||||
|
@ -194,13 +196,16 @@ void resInVoxelDistributor(AgentList* agentList,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// send the environment packets
|
// send the environment packets
|
||||||
for (int i = 0; i < environmentPacketCount; i++) {
|
if (shouldSendEnvironments) {
|
||||||
int envPacketLength = environmentData[i].getBroadcastData(tempOutputBuffer);
|
int envPacketLength = 1;
|
||||||
|
*tempOutputBuffer = PACKET_HEADER_ENVIRONMENT_DATA;
|
||||||
|
for (int i = 0; i < sizeof(environmentData) / sizeof(environmentData[0]); i++) {
|
||||||
|
envPacketLength += environmentData[i].getBroadcastData(tempOutputBuffer + envPacketLength);
|
||||||
|
}
|
||||||
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
|
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
|
||||||
trueBytesSent += envPacketLength;
|
trueBytesSent += envPacketLength;
|
||||||
truePacketsSent++;
|
truePacketsSent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
double end = usecTimestampNow();
|
double end = usecTimestampNow();
|
||||||
double elapsedmsec = (end - start)/1000.0;
|
double elapsedmsec = (end - start)/1000.0;
|
||||||
if (elapsedmsec > 100) {
|
if (elapsedmsec > 100) {
|
||||||
|
@ -301,8 +306,8 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
|
||||||
int trueBytesSent = 0;
|
int trueBytesSent = 0;
|
||||||
double start = usecTimestampNow();
|
double start = usecTimestampNow();
|
||||||
|
|
||||||
int environmentPacketCount = sizeof(environmentData) / sizeof(environmentData[0]);
|
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
|
||||||
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - environmentPacketCount) {
|
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
|
||||||
if (!agentData->nodeBag.isEmpty()) {
|
if (!agentData->nodeBag.isEmpty()) {
|
||||||
VoxelNode* subTree = agentData->nodeBag.extract();
|
VoxelNode* subTree = agentData->nodeBag.extract();
|
||||||
bytesWritten = randomTree.encodeTreeBitstream(INT_MAX, subTree,
|
bytesWritten = randomTree.encodeTreeBitstream(INT_MAX, subTree,
|
||||||
|
@ -334,9 +339,13 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
|
||||||
packetsSentThisInterval = PACKETS_PER_CLIENT_PER_INTERVAL; // done for now, no nodes left
|
packetsSentThisInterval = PACKETS_PER_CLIENT_PER_INTERVAL; // done for now, no nodes left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// send the environment packets
|
// send the environment packet
|
||||||
for (int i = 0; i < environmentPacketCount; i++) {
|
if (shouldSendEnvironments) {
|
||||||
int envPacketLength = environmentData[i].getBroadcastData(tempOutputBuffer);
|
int envPacketLength = 1;
|
||||||
|
*tempOutputBuffer = PACKET_HEADER_ENVIRONMENT_DATA;
|
||||||
|
for (int i = 0; i < sizeof(environmentData) / sizeof(environmentData[0]); i++) {
|
||||||
|
envPacketLength += environmentData[i].getBroadcastData(tempOutputBuffer + envPacketLength);
|
||||||
|
}
|
||||||
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
|
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
|
||||||
trueBytesSent += envPacketLength;
|
trueBytesSent += envPacketLength;
|
||||||
truePacketsSent++;
|
truePacketsSent++;
|
||||||
|
|
Loading…
Reference in a new issue