feat: finish half of script exporter

This commit is contained in:
2024-08-08 17:47:27 +08:00
parent 7c5bc44724
commit 46a6222959
5 changed files with 290 additions and 5 deletions

View File

@@ -14,6 +14,79 @@ namespace VSW::Materializer::Utilities {
m_Ctx->OutputToConsole(const_cast<CKSTRING>(YYCC::EncodingHelper::UTF8ToChar(strl, CP_ACP).c_str()), FALSE);
}
#pragma endregion
#pragma region Curve 2D Builder
Curve2DBuilder::Curve2DBuilder(CK2dCurve* curve_2d) : m_Cache() {
BuildCurve(curve_2d);
}
Curve2DBuilder::~Curve2DBuilder() {}
const void* Curve2DBuilder::GetDataPtr() const { return m_Cache.c_str(); }
size_t Curve2DBuilder::GetDataLength() const { return m_Cache.size(); }
void Curve2DBuilder::BuildCurve(CK2dCurve* c) {
// check curve
if (c == nullptr) return;
// get curve control point count
int cp_count = c->GetControlPointCount();
// reserve enough space
// count * (x + y + is_linear + is_tcb + tcb_tuple)
m_Cache.reserve(static_cast<size_t>(cp_count) * (sizeof(float) * 2u + sizeof(float) * 3u + sizeof(uint32_t) + sizeof(uint32_t)));
// iterate control point
for (int i = 0; i < cp_count; ++i) {
BuildCurvePoint(c->GetControlPoint(i));
}
}
void Curve2DBuilder::BuildCurvePoint(CK2dCurvePoint* cp) {
// check control point
if (cp == nullptr) return;
// prepare variable
uint32_t int_cache;
Vx2DVector vector_cache;
float float_cache;
#define APPEND_DATA(data) m_Cache.append(reinterpret_cast<decltype(m_Cache)::value_type*>(&data), sizeof(data))
// x y value
vector_cache = cp->GetPosition();
APPEND_DATA(vector_cache);
// is linear
int_cache = static_cast<uint32_t>(cp->IsLinear());
APPEND_DATA(int_cache);
// is tcb
int_cache = static_cast<uint32_t>(cp->IsTCB());
APPEND_DATA(int_cache);
if (cp->IsTCB()) {
// TCB control point
float_cache = cp->GetTension();
APPEND_DATA(float_cache);
float_cache = cp->GetContinuity();
APPEND_DATA(float_cache);
float_cache = cp->GetBias();
APPEND_DATA(float_cache);
} else {
// non-TCB control point
float_cache = cp->GetInTangent();
APPEND_DATA(float_cache);
float_cache = cp->GetOutTangent();
APPEND_DATA(float_cache);
// To keep balance with TCB control point,
// We add a blank 0.0f in there
float_cache = 0.0f;
APPEND_DATA(float_cache);
}
#undef APPEND_DATA
}
#pragma endregion
void RelativeAddress(const EnhancedReporter& reporter, YYCC::yycc_u8string& relative_addr_str, const void* absolute_addr) {
@@ -59,6 +132,35 @@ namespace VSW::Materializer::Utilities {
}
}
//void GetBase64(YYCC::yycc_u8string& dst, const char* data, size_t data_len) {
// // Reference: https://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c
// static const YYCC::yycc_char8_t* BASE64_TABLE = YYCC_U8("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
// static const int MOD_TABLE[] = { 0, 2, 1 };
// // compute size
// size_t output_length = 4u * ((data_len + 2u) / 3u);
// dst.resize(output_length);
// // compute
// for (size_t i = 0, j = 0; i < data_len;) {
// uint32_t octet_a = i < data_len ? (unsigned char)data[i++] : 0;
// uint32_t octet_b = i < data_len ? (unsigned char)data[i++] : 0;
// uint32_t octet_c = i < data_len ? (unsigned char)data[i++] : 0;
// uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
// dst[j++] = BASE64_TABLE[(triple >> 3 * 6) & 0x3F];
// dst[j++] = BASE64_TABLE[(triple >> 2 * 6) & 0x3F];
// dst[j++] = BASE64_TABLE[(triple >> 1 * 6) & 0x3F];
// dst[j++] = BASE64_TABLE[(triple >> 0 * 6) & 0x3F];
// }
// // fill blank
// for (int i = 0; i < MOD_TABLE[data_len % 3]; i++)
// dst[output_length - 1 - i] = '=';
//}
void CopyStrGuid(const EnhancedReporter& reporter, YYCC::yycc_u8string& dst, const CKGUID& src) {
if (!YYCC::StringHelper::Printf(dst, YYCC_U8("<0x%08" PRIX32 ", 0x%08" PRIX32 ">"), src.d1, src.d2)) {
reporter.Err(YYCC_U8("Fail to format CKGUID. Some stringified GUID may be empty."));
@@ -66,7 +168,7 @@ namespace VSW::Materializer::Utilities {
}
}
void CopyGuid(const EnhancedReporter& reporter, int64_t& dst, const CKGUID& src) {
void CopyGuid(int64_t& dst, const CKGUID& src) {
// reset dst to zero
uint64_t* pdst = reinterpret_cast<uint64_t*>(&dst);
// CKGUID.d1 to high 32 bits