Set B.C. to start of time string if year < 1000 B.C

This is to make it faster to check for B.C years on the frontend so we can properly show years < 0
This commit is contained in:
Andreas Engberg
2024-11-04 15:15:41 +01:00
parent 07a0912dc1
commit c00e8e40ba

View File

@@ -25,6 +25,8 @@
#ifndef __OPENSPACE_CORE___SPICEMANAGER___H__
#define __OPENSPACE_CORE___SPICEMANAGER___H__
#include <openspace/engine/globals.h>
#include <openspace/util/memorymanager.h>
#include <ghoul/format.h>
#include <ghoul/glm.h>
#include <ghoul/misc/assert.h>
@@ -589,6 +591,23 @@ public:
// The conversion failed and we need to use et2utc
constexpr int SecondsPrecision = 3;
et2utc_c(ephemerisTime, "C", SecondsPrecision, bufferSize, outBuf);
// We want to move the B.C. part to the beginning of the string so that we can
// identify B.C. years by inspecting the first character of `outBuf`
const char* bcPos = std::strstr(outBuf, "B.C.");
if (bcPos) {
const size_t bcLength = 4;
const size_t prefixYearLength = bcPos - outBuf;
// Create temporary storage
char* tmp = reinterpret_cast<char*>(
global::memoryManager->TemporaryMemory.allocate(prefixYearLength)
);
// Copy year into tmp buffer
std::memcpy(tmp, outBuf, prefixYearLength);
// Copy B.C. to beginning of outBuf, + 1 to add a space ' ' after B.C.
std::memcpy(outBuf, "B.C. ", bcLength + 1);
// Copy year to after B.C
std::memcpy(outBuf + bcLength + 1 , tmp, prefixYearLength);
}
}
}