mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
made a version of firstVertexForCode() that doesn't allocate memory, for improved performance and use
- created new copyFirstVertexForCode(code,output) which copies to the output buffer - converted firstVertexForCode() to behave same way as before, but use copy version
This commit is contained in:
parent
b8692d8f46
commit
4085c94aa7
2 changed files with 14 additions and 5 deletions
|
@ -104,9 +104,8 @@ unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber
|
|||
return newCode;
|
||||
}
|
||||
|
||||
float * firstVertexForCode(unsigned char * octalCode) {
|
||||
float * firstVertex = new float[3];
|
||||
memset(firstVertex, 0, 3 * sizeof(float));
|
||||
void copyFirstVertexForCode(unsigned char * octalCode, float* output) {
|
||||
memset(output, 0, 3 * sizeof(float));
|
||||
|
||||
float currentScale = 0.5;
|
||||
|
||||
|
@ -114,11 +113,16 @@ float * firstVertexForCode(unsigned char * octalCode) {
|
|||
int sectionIndex = sectionValue(octalCode + 1 + (3 * i / 8), (3 * i) % 8);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
firstVertex[j] += currentScale * (int)oneAtBit(sectionIndex, 5 + j);
|
||||
output[j] += currentScale * (int)oneAtBit(sectionIndex, 5 + j);
|
||||
}
|
||||
|
||||
currentScale *= 0.5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float * firstVertexForCode(unsigned char * octalCode) {
|
||||
float * firstVertex = new float[3];
|
||||
copyFirstVertexForCode(octalCode, firstVertex);
|
||||
return firstVertex;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ int bytesRequiredForCodeLength(unsigned char threeBitCodes);
|
|||
bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode);
|
||||
int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode);
|
||||
unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber);
|
||||
|
||||
|
||||
// Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return
|
||||
// but other than that these do the same thing.
|
||||
float * firstVertexForCode(unsigned char * octalCode);
|
||||
void copyFirstVertexForCode(unsigned char * octalCode, float* output);
|
||||
|
||||
#endif /* defined(__hifi__OctalCode__) */
|
||||
|
|
Loading…
Reference in a new issue