mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:08:00 +02:00
Merge pull request #348 from ZappoMan/voxel_animation
Improved Animation Server
This commit is contained in:
commit
438191f436
2 changed files with 181 additions and 88 deletions
|
@ -28,8 +28,10 @@
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool shouldShowPacketsPerSecond = false; // do we want to debug packets per second
|
||||||
|
|
||||||
const int ANIMATION_LISTEN_PORT = 40107;
|
const int ANIMATION_LISTEN_PORT = 40107;
|
||||||
const int ACTUAL_FPS = 20;
|
const int ACTUAL_FPS = 60;
|
||||||
const double OUR_FPS_IN_MILLISECONDS = 1000.0/ACTUAL_FPS; // determines FPS from our desired FPS
|
const double OUR_FPS_IN_MILLISECONDS = 1000.0/ACTUAL_FPS; // determines FPS from our desired FPS
|
||||||
const int ANIMATE_VOXELS_INTERVAL_USECS = OUR_FPS_IN_MILLISECONDS * 1000.0; // converts from milliseconds to usecs
|
const int ANIMATE_VOXELS_INTERVAL_USECS = OUR_FPS_IN_MILLISECONDS * 1000.0; // converts from milliseconds to usecs
|
||||||
|
|
||||||
|
@ -42,11 +44,22 @@ static void sendVoxelServerZMessage() {
|
||||||
AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
|
AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long packetsSent = 0;
|
||||||
|
unsigned long bytesSent = 0;
|
||||||
|
|
||||||
static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
|
static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
|
||||||
unsigned char* bufferOut;
|
unsigned char* bufferOut;
|
||||||
int sizeOut;
|
int sizeOut;
|
||||||
|
|
||||||
if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){
|
if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){
|
||||||
|
|
||||||
|
::packetsSent++;
|
||||||
|
::bytesSent += sizeOut;
|
||||||
|
|
||||||
|
if (::shouldShowPacketsPerSecond) {
|
||||||
|
printf("sending packet of size=%d\n",sizeOut);
|
||||||
|
}
|
||||||
|
|
||||||
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||||
delete[] bufferOut;
|
delete[] bufferOut;
|
||||||
}
|
}
|
||||||
|
@ -101,56 +114,71 @@ const float STRING_OF_LIGHTS_SIZE = 0.125f / TREE_SCALE; // approximately 1/8th
|
||||||
static void sendBlinkingStringOfLights() {
|
static void sendBlinkingStringOfLights() {
|
||||||
PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; // we're a bully!
|
PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; // we're a bully!
|
||||||
float lightScale = STRING_OF_LIGHTS_SIZE;
|
float lightScale = STRING_OF_LIGHTS_SIZE;
|
||||||
VoxelDetail detail;
|
static VoxelDetail details[LIGHTS_PER_SEGMENT];
|
||||||
|
unsigned char* bufferOut;
|
||||||
detail.s = lightScale;
|
int sizeOut;
|
||||||
|
|
||||||
// first initialized the string of lights if needed...
|
// first initialized the string of lights if needed...
|
||||||
if (!stringOfLightsInitialized) {
|
if (!stringOfLightsInitialized) {
|
||||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
for (int segment = 0; segment < SEGMENT_COUNT; segment++) {
|
||||||
|
for (int indexInSegment = 0; indexInSegment < LIGHTS_PER_SEGMENT; indexInSegment++) {
|
||||||
// four different segments on sides of initial platform
|
|
||||||
int segment = floor(i / LIGHTS_PER_SEGMENT);
|
int i = (segment * LIGHTS_PER_SEGMENT) + indexInSegment;
|
||||||
int indexInSegment = i - (segment * LIGHTS_PER_SEGMENT);
|
|
||||||
switch (segment) {
|
// four different segments on sides of initial platform
|
||||||
case 0:
|
switch (segment) {
|
||||||
// along x axis
|
case 0:
|
||||||
stringOfLights[i] = glm::vec3(indexInSegment * lightScale, 0, 0);
|
// along x axis
|
||||||
break;
|
stringOfLights[i] = glm::vec3(indexInSegment * lightScale, 0, 0);
|
||||||
case 1:
|
break;
|
||||||
// parallel to Z axis at outer X edge
|
case 1:
|
||||||
stringOfLights[i] = glm::vec3(LIGHTS_PER_SEGMENT * lightScale, 0, indexInSegment * lightScale);
|
// parallel to Z axis at outer X edge
|
||||||
break;
|
stringOfLights[i] = glm::vec3(LIGHTS_PER_SEGMENT * lightScale, 0, indexInSegment * lightScale);
|
||||||
case 2:
|
break;
|
||||||
// parallel to X axis at outer Z edge
|
case 2:
|
||||||
stringOfLights[i] = glm::vec3((LIGHTS_PER_SEGMENT-indexInSegment) * lightScale, 0,
|
// parallel to X axis at outer Z edge
|
||||||
LIGHTS_PER_SEGMENT * lightScale);
|
stringOfLights[i] = glm::vec3((LIGHTS_PER_SEGMENT-indexInSegment) * lightScale, 0,
|
||||||
break;
|
LIGHTS_PER_SEGMENT * lightScale);
|
||||||
case 3:
|
break;
|
||||||
// on Z axis
|
case 3:
|
||||||
stringOfLights[i] = glm::vec3(0, 0, (LIGHTS_PER_SEGMENT-indexInSegment) * lightScale);
|
// on Z axis
|
||||||
break;
|
stringOfLights[i] = glm::vec3(0, 0, (LIGHTS_PER_SEGMENT-indexInSegment) * lightScale);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[indexInSegment].s = STRING_OF_LIGHTS_SIZE;
|
||||||
|
details[indexInSegment].x = stringOfLights[i].x;
|
||||||
|
details[indexInSegment].y = stringOfLights[i].y;
|
||||||
|
details[indexInSegment].z = stringOfLights[i].z;
|
||||||
|
|
||||||
|
details[indexInSegment].red = offColor[0];
|
||||||
|
details[indexInSegment].green = offColor[1];
|
||||||
|
details[indexInSegment].blue = offColor[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
detail.x = stringOfLights[i].x;
|
// send entire segment at once
|
||||||
detail.y = stringOfLights[i].y;
|
if (createVoxelEditMessage(message, 0, LIGHTS_PER_SEGMENT, (VoxelDetail*)&details, bufferOut, sizeOut)){
|
||||||
detail.z = stringOfLights[i].z;
|
|
||||||
|
::packetsSent++;
|
||||||
|
::bytesSent += sizeOut;
|
||||||
|
|
||||||
|
if (::shouldShowPacketsPerSecond) {
|
||||||
|
printf("sending packet of size=%d\n",sizeOut);
|
||||||
|
}
|
||||||
|
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||||
|
delete[] bufferOut;
|
||||||
|
}
|
||||||
|
|
||||||
detail.red = offColor[0];
|
|
||||||
detail.green = offColor[1];
|
|
||||||
detail.blue = offColor[2];
|
|
||||||
sendVoxelEditMessage(message, detail);
|
|
||||||
}
|
}
|
||||||
stringOfLightsInitialized = true;
|
stringOfLightsInitialized = true;
|
||||||
} else {
|
} else {
|
||||||
// turn off current light
|
// turn off current light
|
||||||
detail.x = detail.s * floor(stringOfLights[currentLight].x / detail.s);
|
details[0].x = stringOfLights[currentLight].x;
|
||||||
detail.y = detail.s * floor(stringOfLights[currentLight].y / detail.s);
|
details[0].y = stringOfLights[currentLight].y;
|
||||||
detail.z = detail.s * floor(stringOfLights[currentLight].z / detail.s);
|
details[0].z = stringOfLights[currentLight].z;
|
||||||
detail.red = offColor[0];
|
details[0].red = offColor[0];
|
||||||
detail.green = offColor[1];
|
details[0].green = offColor[1];
|
||||||
detail.blue = offColor[2];
|
details[0].blue = offColor[2];
|
||||||
sendVoxelEditMessage(message, detail);
|
|
||||||
|
|
||||||
// move current light...
|
// move current light...
|
||||||
// if we're at the end of our string, then change direction
|
// if we're at the end of our string, then change direction
|
||||||
|
@ -163,19 +191,31 @@ static void sendBlinkingStringOfLights() {
|
||||||
currentLight += lightMovementDirection;
|
currentLight += lightMovementDirection;
|
||||||
|
|
||||||
// turn on new current light
|
// turn on new current light
|
||||||
detail.x = detail.s * floor(stringOfLights[currentLight].x / detail.s);
|
details[1].x = stringOfLights[currentLight].x;
|
||||||
detail.y = detail.s * floor(stringOfLights[currentLight].y / detail.s);
|
details[1].y = stringOfLights[currentLight].y;
|
||||||
detail.z = detail.s * floor(stringOfLights[currentLight].z / detail.s);
|
details[1].z = stringOfLights[currentLight].z;
|
||||||
detail.red = onColor[0];
|
details[1].red = onColor[0];
|
||||||
detail.green = onColor[1];
|
details[1].green = onColor[1];
|
||||||
detail.blue = onColor[2];
|
details[1].blue = onColor[2];
|
||||||
sendVoxelEditMessage(message, detail);
|
|
||||||
|
// send both changes in same message
|
||||||
|
if (createVoxelEditMessage(message, 0, 2, (VoxelDetail*)&details, bufferOut, sizeOut)){
|
||||||
|
|
||||||
|
::packetsSent++;
|
||||||
|
::bytesSent += sizeOut;
|
||||||
|
|
||||||
|
if (::shouldShowPacketsPerSecond) {
|
||||||
|
printf("sending packet of size=%d\n",sizeOut);
|
||||||
|
}
|
||||||
|
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||||
|
delete[] bufferOut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool billboardInitialized = false;
|
bool billboardInitialized = false;
|
||||||
const int BILLBOARD_HEIGHT = 9;
|
const int BILLBOARD_HEIGHT = 9;
|
||||||
const int BILLBOARD_WIDTH = 44;
|
const int BILLBOARD_WIDTH = 45;
|
||||||
glm::vec3 billboardPosition((0.125f / TREE_SCALE),(0.125f / TREE_SCALE),0);
|
glm::vec3 billboardPosition((0.125f / TREE_SCALE),(0.125f / TREE_SCALE),0);
|
||||||
glm::vec3 billboardLights[BILLBOARD_HEIGHT][BILLBOARD_WIDTH];
|
glm::vec3 billboardLights[BILLBOARD_HEIGHT][BILLBOARD_WIDTH];
|
||||||
unsigned char billboardOffColor[3] = { 240, 240, 240 };
|
unsigned char billboardOffColor[3] = { 240, 240, 240 };
|
||||||
|
@ -186,26 +226,29 @@ float billboardGradientIncrement = 0.01f;
|
||||||
const float BILLBOARD_MAX_GRADIENT = 1.0f;
|
const float BILLBOARD_MAX_GRADIENT = 1.0f;
|
||||||
const float BILLBOARD_MIN_GRADIENT = 0.0f;
|
const float BILLBOARD_MIN_GRADIENT = 0.0f;
|
||||||
const float BILLBOARD_LIGHT_SIZE = 0.125f / TREE_SCALE; // approximately 1/8 meter per light
|
const float BILLBOARD_LIGHT_SIZE = 0.125f / TREE_SCALE; // approximately 1/8 meter per light
|
||||||
|
const int VOXELS_PER_PACKET = 135;
|
||||||
|
const int PACKETS_PER_BILLBOARD = VOXELS_PER_PACKET / (BILLBOARD_HEIGHT * BILLBOARD_WIDTH);
|
||||||
|
|
||||||
|
|
||||||
// top to bottom...
|
// top to bottom...
|
||||||
bool billBoardMessage[BILLBOARD_HEIGHT][BILLBOARD_WIDTH] = {
|
bool billboardMessage[BILLBOARD_HEIGHT][BILLBOARD_WIDTH] = {
|
||||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
|
||||||
{ 0,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,0,0 },
|
{ 0,0,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,0,0 },
|
||||||
{ 0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,0,0,0 },
|
{ 0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,0,0,0 },
|
||||||
{ 0,1,1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,0,1,0 },
|
{ 0,0,1,1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,0,1,0 },
|
||||||
{ 0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0 },
|
{ 0,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0 },
|
||||||
{ 0,1,0,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,1,1,0 },
|
{ 0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,1,1,0 },
|
||||||
{ 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
|
{ 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
|
||||||
{ 0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0 },
|
{ 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0 },
|
||||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sendBillboard() {
|
static void sendBillboard() {
|
||||||
PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; // we're a bully!
|
PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; // we're a bully!
|
||||||
float lightScale = BILLBOARD_LIGHT_SIZE;
|
float lightScale = BILLBOARD_LIGHT_SIZE;
|
||||||
VoxelDetail detail;
|
static VoxelDetail details[VOXELS_PER_PACKET];
|
||||||
|
unsigned char* bufferOut;
|
||||||
detail.s = lightScale;
|
int sizeOut;
|
||||||
|
|
||||||
// first initialized the billboard of lights if needed...
|
// first initialized the billboard of lights if needed...
|
||||||
if (!billboardInitialized) {
|
if (!billboardInitialized) {
|
||||||
|
@ -231,27 +274,44 @@ static void sendBillboard() {
|
||||||
|
|
||||||
for (int i = 0; i < BILLBOARD_HEIGHT; i++) {
|
for (int i = 0; i < BILLBOARD_HEIGHT; i++) {
|
||||||
for (int j = 0; j < BILLBOARD_WIDTH; j++) {
|
for (int j = 0; j < BILLBOARD_WIDTH; j++) {
|
||||||
|
|
||||||
|
int nthVoxel = ((i * BILLBOARD_WIDTH) + j);
|
||||||
|
int item = nthVoxel % VOXELS_PER_PACKET;
|
||||||
|
|
||||||
billboardLights[i][j] = billboardPosition + glm::vec3(j * lightScale, (float)((BILLBOARD_HEIGHT - i) * lightScale), 0);
|
billboardLights[i][j] = billboardPosition + glm::vec3(j * lightScale, (float)((BILLBOARD_HEIGHT - i) * lightScale), 0);
|
||||||
|
|
||||||
detail.x = billboardLights[i][j].x;
|
details[item].s = lightScale;
|
||||||
detail.y = billboardLights[i][j].y;
|
details[item].x = billboardLights[i][j].x;
|
||||||
detail.z = billboardLights[i][j].z;
|
details[item].y = billboardLights[i][j].y;
|
||||||
|
details[item].z = billboardLights[i][j].z;
|
||||||
|
|
||||||
if (billBoardMessage[i][j]) {
|
if (billboardMessage[i][j]) {
|
||||||
detail.red = (billboardOnColorA[0] + ((billboardOnColorB[0] - billboardOnColorA[0]) * ::billboardGradient));
|
details[item].red = (billboardOnColorA[0] + ((billboardOnColorB[0] - billboardOnColorA[0]) * ::billboardGradient));
|
||||||
detail.green = (billboardOnColorA[1] + ((billboardOnColorB[1] - billboardOnColorA[1]) * ::billboardGradient));
|
details[item].green = (billboardOnColorA[1] + ((billboardOnColorB[1] - billboardOnColorA[1]) * ::billboardGradient));
|
||||||
detail.blue = (billboardOnColorA[2] + ((billboardOnColorB[2] - billboardOnColorA[2]) * ::billboardGradient));
|
details[item].blue = (billboardOnColorA[2] + ((billboardOnColorB[2] - billboardOnColorA[2]) * ::billboardGradient));
|
||||||
} else {
|
} else {
|
||||||
detail.red = billboardOffColor[0];
|
details[item].red = billboardOffColor[0];
|
||||||
detail.green = billboardOffColor[1];
|
details[item].green = billboardOffColor[1];
|
||||||
detail.blue = billboardOffColor[2];
|
details[item].blue = billboardOffColor[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item == VOXELS_PER_PACKET - 1) {
|
||||||
|
if (createVoxelEditMessage(message, 0, VOXELS_PER_PACKET, (VoxelDetail*)&details, bufferOut, sizeOut)){
|
||||||
|
::packetsSent++;
|
||||||
|
::bytesSent += sizeOut;
|
||||||
|
if (::shouldShowPacketsPerSecond) {
|
||||||
|
printf("sending packet of size=%d\n", sizeOut);
|
||||||
|
}
|
||||||
|
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||||
|
delete[] bufferOut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sendVoxelEditMessage(message, detail);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double start = 0;
|
||||||
|
|
||||||
|
|
||||||
void* animateVoxels(void* args) {
|
void* animateVoxels(void* args) {
|
||||||
|
|
||||||
|
@ -265,7 +325,13 @@ void* animateVoxels(void* args) {
|
||||||
//sendVoxelBlinkMessage();
|
//sendVoxelBlinkMessage();
|
||||||
sendBlinkingStringOfLights();
|
sendBlinkingStringOfLights();
|
||||||
sendBillboard();
|
sendBillboard();
|
||||||
|
|
||||||
|
double end = usecTimestampNow();
|
||||||
|
double elapsedSeconds = (end - ::start) / 1000000.0;
|
||||||
|
if (::shouldShowPacketsPerSecond) {
|
||||||
|
printf("packetsSent=%ld, bytesSent=%ld pps=%f bps=%f\n",packetsSent,bytesSent,
|
||||||
|
(float)(packetsSent/elapsedSeconds),(float)(bytesSent/elapsedSeconds));
|
||||||
|
}
|
||||||
// dynamically sleep until we need to fire off the next set of voxels
|
// dynamically sleep until we need to fire off the next set of voxels
|
||||||
double usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
|
double usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
|
||||||
|
|
||||||
|
@ -282,9 +348,15 @@ void* animateVoxels(void* args) {
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
|
::start = usecTimestampNow();
|
||||||
|
|
||||||
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_ANIMATION_SERVER, ANIMATION_LISTEN_PORT);
|
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_ANIMATION_SERVER, ANIMATION_LISTEN_PORT);
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
|
// Handle Local Domain testing with the --local command line
|
||||||
|
const char* showPPS = "--showPPS";
|
||||||
|
::shouldShowPacketsPerSecond = cmdOptionExists(argc, argv, showPPS);
|
||||||
|
|
||||||
// Handle Local Domain testing with the --local command line
|
// Handle Local Domain testing with the --local command line
|
||||||
const char* local = "--local";
|
const char* local = "--local";
|
||||||
::wantLocalDomain = cmdOptionExists(argc, argv,local);
|
::wantLocalDomain = cmdOptionExists(argc, argv,local);
|
||||||
|
|
|
@ -56,6 +56,9 @@ bool wantLocalDomain = false;
|
||||||
|
|
||||||
bool wantColorRandomizer = false;
|
bool wantColorRandomizer = false;
|
||||||
bool debugVoxelSending = false;
|
bool debugVoxelSending = false;
|
||||||
|
bool shouldShowAnimationDebug = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EnvironmentData environmentData;
|
EnvironmentData environmentData;
|
||||||
|
|
||||||
|
@ -352,7 +355,8 @@ void persistVoxelsWhenDirty() {
|
||||||
if (::wantVoxelPersist && ::randomTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) {
|
if (::wantVoxelPersist && ::randomTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) {
|
||||||
|
|
||||||
{
|
{
|
||||||
PerformanceWarning warn(true, "persistVoxelsWhenDirty() - reaverageVoxelColors()", true);
|
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||||
|
"persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug);
|
||||||
|
|
||||||
// after done inserting all these voxels, then reaverage colors
|
// after done inserting all these voxels, then reaverage colors
|
||||||
randomTree.reaverageVoxelColors(randomTree.rootNode);
|
randomTree.reaverageVoxelColors(randomTree.rootNode);
|
||||||
|
@ -360,7 +364,8 @@ void persistVoxelsWhenDirty() {
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
PerformanceWarning warn(true, "persistVoxelsWhenDirty() - writeToFileV2()", true);
|
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||||
|
"persistVoxelsWhenDirty() - writeToFileV2()", ::shouldShowAnimationDebug);
|
||||||
|
|
||||||
printf("saving voxels to file...\n");
|
printf("saving voxels to file...\n");
|
||||||
randomTree.writeToFileV2(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
|
randomTree.writeToFileV2(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
|
||||||
|
@ -441,6 +446,10 @@ int main(int argc, const char * argv[])
|
||||||
::debugVoxelSending = cmdOptionExists(argc, argv, DEBUG_VOXEL_SENDING);
|
::debugVoxelSending = cmdOptionExists(argc, argv, DEBUG_VOXEL_SENDING);
|
||||||
printf("debugVoxelSending=%s\n", (::debugVoxelSending ? "yes" : "no"));
|
printf("debugVoxelSending=%s\n", (::debugVoxelSending ? "yes" : "no"));
|
||||||
|
|
||||||
|
const char* WANT_ANIMATION_DEBUG = "--shouldShowAnimationDebug";
|
||||||
|
::shouldShowAnimationDebug = cmdOptionExists(argc, argv, WANT_ANIMATION_DEBUG);
|
||||||
|
printf("shouldShowAnimationDebug=%s\n", (::shouldShowAnimationDebug ? "yes" : "no"));
|
||||||
|
|
||||||
const char* WANT_COLOR_RANDOMIZER = "--wantColorRandomizer";
|
const char* WANT_COLOR_RANDOMIZER = "--wantColorRandomizer";
|
||||||
::wantColorRandomizer = cmdOptionExists(argc, argv, WANT_COLOR_RANDOMIZER);
|
::wantColorRandomizer = cmdOptionExists(argc, argv, WANT_COLOR_RANDOMIZER);
|
||||||
printf("wantColorRandomizer=%s\n", (::wantColorRandomizer ? "yes" : "no"));
|
printf("wantColorRandomizer=%s\n", (::wantColorRandomizer ? "yes" : "no"));
|
||||||
|
@ -527,14 +536,17 @@ int main(int argc, const char * argv[])
|
||||||
if (packetData[0] == PACKET_HEADER_SET_VOXEL || packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) {
|
if (packetData[0] == PACKET_HEADER_SET_VOXEL || packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) {
|
||||||
bool destructive = (packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE);
|
bool destructive = (packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE);
|
||||||
|
|
||||||
PerformanceWarning warn(true,
|
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||||
destructive ? "PACKET_HEADER_SET_VOXEL_DESTRUCTIVE" : "PACKET_HEADER_SET_VOXEL",
|
destructive ? "PACKET_HEADER_SET_VOXEL_DESTRUCTIVE" : "PACKET_HEADER_SET_VOXEL",
|
||||||
true);
|
::shouldShowAnimationDebug);
|
||||||
|
|
||||||
unsigned short int itemNumber = (*((unsigned short int*)&packetData[1]));
|
unsigned short int itemNumber = (*((unsigned short int*)&packetData[1]));
|
||||||
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
|
|
||||||
destructive ? "PACKET_HEADER_SET_VOXEL_DESTRUCTIVE" : "PACKET_HEADER_SET_VOXEL",
|
if (::shouldShowAnimationDebug) {
|
||||||
receivedBytes,itemNumber);
|
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
|
||||||
|
destructive ? "PACKET_HEADER_SET_VOXEL_DESTRUCTIVE" : "PACKET_HEADER_SET_VOXEL",
|
||||||
|
receivedBytes,itemNumber);
|
||||||
|
}
|
||||||
int atByte = 3;
|
int atByte = 3;
|
||||||
unsigned char* pVoxelData = (unsigned char*)&packetData[3];
|
unsigned char* pVoxelData = (unsigned char*)&packetData[3];
|
||||||
while (atByte < receivedBytes) {
|
while (atByte < receivedBytes) {
|
||||||
|
@ -547,20 +559,29 @@ int main(int argc, const char * argv[])
|
||||||
int red = pVoxelData[voxelCodeSize+0];
|
int red = pVoxelData[voxelCodeSize+0];
|
||||||
int green = pVoxelData[voxelCodeSize+1];
|
int green = pVoxelData[voxelCodeSize+1];
|
||||||
int blue = pVoxelData[voxelCodeSize+2];
|
int blue = pVoxelData[voxelCodeSize+2];
|
||||||
printf("insert voxels - wantColorRandomizer=%s old r=%d,g=%d,b=%d \n",
|
|
||||||
(::wantColorRandomizer?"yes":"no"),red,green,blue);
|
if (::shouldShowAnimationDebug) {
|
||||||
|
printf("insert voxels - wantColorRandomizer=%s old r=%d,g=%d,b=%d \n",
|
||||||
|
(::wantColorRandomizer?"yes":"no"),red,green,blue);
|
||||||
|
}
|
||||||
|
|
||||||
red = std::max(0,std::min(255,red + colorRandomizer));
|
red = std::max(0,std::min(255,red + colorRandomizer));
|
||||||
green = std::max(0,std::min(255,green + colorRandomizer));
|
green = std::max(0,std::min(255,green + colorRandomizer));
|
||||||
blue = std::max(0,std::min(255,blue + colorRandomizer));
|
blue = std::max(0,std::min(255,blue + colorRandomizer));
|
||||||
printf("insert voxels - wantColorRandomizer=%s NEW r=%d,g=%d,b=%d \n",
|
|
||||||
(::wantColorRandomizer?"yes":"no"),red,green,blue);
|
if (::shouldShowAnimationDebug) {
|
||||||
|
printf("insert voxels - wantColorRandomizer=%s NEW r=%d,g=%d,b=%d \n",
|
||||||
|
(::wantColorRandomizer?"yes":"no"),red,green,blue);
|
||||||
|
}
|
||||||
pVoxelData[voxelCodeSize+0]=red;
|
pVoxelData[voxelCodeSize+0]=red;
|
||||||
pVoxelData[voxelCodeSize+1]=green;
|
pVoxelData[voxelCodeSize+1]=green;
|
||||||
pVoxelData[voxelCodeSize+2]=blue;
|
pVoxelData[voxelCodeSize+2]=blue;
|
||||||
|
|
||||||
float* vertices = firstVertexForCode(pVoxelData);
|
if (::shouldShowAnimationDebug) {
|
||||||
printf("inserting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
float* vertices = firstVertexForCode(pVoxelData);
|
||||||
delete []vertices;
|
printf("inserting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
||||||
|
delete []vertices;
|
||||||
|
}
|
||||||
|
|
||||||
randomTree.readCodeColorBufferToTree(pVoxelData, destructive);
|
randomTree.readCodeColorBufferToTree(pVoxelData, destructive);
|
||||||
// skip to next
|
// skip to next
|
||||||
|
|
Loading…
Reference in a new issue