• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / RevilLib / 175

19 Nov 2025 10:16PM UTC coverage: 10.614% (-0.5%) from 11.16%
175

push

github

PredatorCZ
add more mtf texture support

0 of 139 new or added lines in 2 files covered. (0.0%)

639 existing lines in 6 files now uncovered.

757 of 7132 relevant lines covered (10.61%)

6360.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.94
/src/mtf_lmt/codecs.cpp
1
/*  Revil Format Library
2
    Copyright(C) 2017-2023 Lukas Cone
3

4
    This program is free software : you can redistribute it and / or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8

9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
    GNU General Public License for more details.
13

14
    You should have received a copy of the GNU General Public License
15
    along with this program.If not, see <https://www.gnu.org/licenses/>.
16
*/
17

18
#include "codecs.hpp"
19
#include "spike/except.hpp"
20
#include "spike/io/binwritter_stream.hpp"
21
#include "spike/master_printer.hpp"
22
#include "spike/reflect/reflector_xml.hpp"
23
#include "spike/util/macroLoop.hpp"
24

25
#include <cmath>
26
#include <sstream>
27
#include <unordered_map>
28

29
REFLECT(CLASS(Buf_SingleVector3), MEMBER(data));
2✔
30
REFLECT(CLASS(Buf_LinearVector3), MEMBER(data), MEMBER(additiveFrames));
2✔
31
REFLECT(CLASS(Buf_HermiteVector3), MEMBER(flags), MEMBER(additiveFrames),
2✔
32
        MEMBER(data));
33

34
// https://en.wikipedia.org/wiki/Slerp
35
static Vector4A16 slerp(const Vector4A16 &v0, const Vector4A16 &_v1, float t) {
UNCOV
36
  Vector4A16 v1 = _v1;
×
37
  float dot = v0.Dot(v1);
38

39
  // If the dot product is negative, slerp won't take
40
  // the shorter path. Fix by reversing one quaternion.
UNCOV
41
  if (dot < 0.0f) {
×
42
    v1 *= -1;
UNCOV
43
    dot *= -1;
×
44
  }
45

46
  static const float DOT_THRESHOLD = 0.9995f;
UNCOV
47
  if (dot > DOT_THRESHOLD) {
×
48
    // If the inputs are too close for comfort, linearly interpolate
49
    // and normalize the result.
50

51
    Vector4A16 result = v0 + (v1 - v0) * t;
UNCOV
52
    return result.Normalize();
×
53
  }
54

55
  const float theta00 = acos(dot);   // theta00 = angle between input vectors
×
56
  const float theta01 = theta00 * t; // theta01 = angle between v0 and result
×
57
  const float theta02 = sin(theta01);
×
58
  const float theta03 = 1.0f / sin(theta00);
×
59
  const float s0 = cos(theta01) - dot * theta02 * theta03;
×
UNCOV
60
  const float s1 = theta02 * theta03;
×
61

UNCOV
62
  return ((v0 * s0) + (v1 * s1)).Normalized();
×
63
}
64

65
template <typename T>
66
Vector4A16 lerp(const Vector4A16 &v0, const Vector4A16 &v1, T t) {
67
  return v0 + (v1 - v0) * t;
68
}
69

70
static Vector4A16 additiveLerp(const TrackMinMax &minMax,
71
                               const Vector4A16 &value) {
72
  return minMax.max + minMax.min * value;
73
}
74

75
static Vector4A16 blerp(const Vector4A16 &v0, const Vector4A16 &v1,
76
                        const TrackMinMax &minMax, float t) {
77
  return lerp(additiveLerp(minMax, v0), additiveLerp(minMax, v1), t);
78
}
79

80
static Vector4A16 bslerp(const Vector4A16 &v0, const Vector4A16 &v1,
81
                         const TrackMinMax &minMax, float t) {
UNCOV
82
  return slerp(additiveLerp(minMax, v0), additiveLerp(minMax, v1), t);
×
83
}
84

85
template <class C>
UNCOV
86
void AppendToStringRaw(const C *clPtr, std::stringstream &buffer) {
×
87
  const uint8 *rawData = reinterpret_cast<const uint8 *>(clPtr);
88
  const size_t hexSize = clPtr->Size() * 2;
89
  size_t cBuff = 0;
90

91
  for (size_t i = 0; i < hexSize; i++) {
×
92
    bool idk = i & 1;
×
UNCOV
93
    char temp = 0x30 + (idk ? rawData[cBuff++] & 0xf : rawData[cBuff] >> 4);
×
94

95
    if (temp > 0x39) {
×
UNCOV
96
      temp += 7;
×
97
    }
98

UNCOV
99
    buffer << temp;
×
100
  }
101
}
UNCOV
102

×
103
template <class C>
104
std::string_view RetreiveFromRawString(C *clPtr, std::string_view buffer) {
105
  uint8 *rawData = reinterpret_cast<uint8 *>(clPtr);
106
  const size_t buffSize = clPtr->Size() * 2;
107
  size_t cBuff = 0;
×
108

×
UNCOV
109
  while (!buffer.empty() && cBuff < buffSize) {
×
110
    const int cRef = buffer.at(0);
111

×
UNCOV
112
    if (cRef < '0' || cRef > 'F' || (cRef > '9' && cRef < 'A')) {
×
113
      buffer.remove_prefix(1);
114
      continue;
UNCOV
115
    }
×
116

117
    if (!(cBuff & 1)) {
UNCOV
118
      rawData[cBuff] = atohLUT[cRef] << 4;
×
119
    } else {
120
      rawData[cBuff++] |= atohLUT[cRef];
121
    }
122

123
    buffer.remove_prefix(1);
×
124
  }
×
UNCOV
125

×
126
  if (cBuff < buffSize) {
127
    throw es::RuntimeError("Raw buffer is too short!");
×
UNCOV
128
  }
×
129

130
  return buffer;
UNCOV
131
}
×
132

133
static auto SeekTo(std::string_view buffer, const char T = '\n') {
UNCOV
134
  while (!buffer.empty()) {
×
135
    if (buffer.front() == T) {
136
      buffer.remove_prefix(1);
137
      return buffer;
138
    }
139

×
140
    buffer.remove_prefix(1);
×
UNCOV
141
  }
×
142

143
  return buffer;
×
UNCOV
144
}
×
145

146
size_t Buf_SingleVector3::Size() const { return 12; }
UNCOV
147

×
148
void Buf_SingleVector3::AppendToString(std::stringstream &buffer) const {
149
  ReflectorWrap<const Buf_SingleVector3> tRefl(this);
UNCOV
150

×
151
  buffer << tRefl["data"].ReflectedValue();
152
}
153

154
std::string_view
155
Buf_SingleVector3::RetreiveFromString(std::string_view buffer) {
×
156
  buffer = es::SkipStartWhitespace(buffer, true);
×
UNCOV
157

×
158
  ReflectorWrap<Buf_SingleVector3> tRefl(this);
159
  tRefl["data"] = buffer;
×
UNCOV
160
  return SeekTo(buffer);
×
161
}
162

UNCOV
163
void Buf_SingleVector3::Evaluate(Vector4A16 &out) const {
×
164
  out = Vector4A16(data, 1.0f);
165
}
UNCOV
166

×
167
void Buf_SingleVector3::Devaluate(const Vector4A16 &in) { data = in; }
168

169
void Buf_SingleVector3::GetFrame(int32 &currentFrame) const { currentFrame++; }
170

171
int32 Buf_SingleVector3::GetFrame() const { return 1; }
×
172

×
UNCOV
173
void Buf_SingleVector3::Interpolate(Vector4A16 &out,
×
174
                                    const Buf_SingleVector3 &rightFrame,
175
                                    float delta, const TrackMinMax &) const {
×
UNCOV
176
  Vector4A16 startPoint, endPoint;
×
177

178
  Evaluate(startPoint);
UNCOV
179
  rightFrame.Evaluate(endPoint);
×
180

181
  out = lerp(startPoint, endPoint, delta);
UNCOV
182
}
×
183

184
void Buf_SingleVector3::SwapEndian() { FByteswapper(data); }
185

186
void Buf_StepRotationQuat3::Evaluate(Vector4A16 &out) const {
187
  out = Vector4A16(data.X, data.Y, data.Z, 0.0f);
×
188
  out.QComputeElement();
×
UNCOV
189
}
×
190

191
void Buf_StepRotationQuat3::Interpolate(Vector4A16 &out,
×
UNCOV
192
                                        const Buf_StepRotationQuat3 &rightFrame,
×
193
                                        float delta,
194
                                        const TrackMinMax &) const {
UNCOV
195
  Vector4A16 startPoint, endPoint;
×
196

197
  Evaluate(startPoint);
198
  rightFrame.Evaluate(endPoint);
199

UNCOV
200
  out = slerp(startPoint, endPoint, delta);
×
201
}
202

203
size_t Buf_LinearVector3::Size() const { return 16; }
204

205
void Buf_LinearVector3::AppendToString(std::stringstream &buffer) const {
×
UNCOV
206
  ReflectorWrap<const Buf_LinearVector3> tRefl(this);
×
207

UNCOV
208
  buffer << "{ " << tRefl["data"].ReflectedValue() << ", "
×
209
         << tRefl["additiveFrames"].ReflectedValue() << " }";
UNCOV
210
}
×
211

212
std::string_view
213
Buf_LinearVector3::RetreiveFromString(std::string_view buffer) {
UNCOV
214
  buffer = SeekTo(buffer, '{');
×
215
  buffer = es::SkipStartWhitespace(buffer, true);
216

217
  ReflectorWrap<Buf_LinearVector3> tRefl(this);
218
  tRefl["data"] = buffer;
219

220
  buffer = SeekTo(buffer, ']');
221
  buffer = SeekTo(buffer, ',');
222
  buffer = es::SkipStartWhitespace(buffer, true);
UNCOV
223

×
224
  tRefl["additiveFrames"] = buffer;
225

226
  return SeekTo(buffer);
227
}
UNCOV
228

×
229
void Buf_LinearVector3::Devaluate(const Vector4A16 &in) { data = in; }
230

231
void Buf_LinearVector3::Evaluate(Vector4A16 &out) const {
232
  out = Vector4A16(data, 1.0f);
233
}
×
UNCOV
234

×
235
void Buf_LinearVector3::GetFrame(int32 &currentFrame) const {
UNCOV
236
  currentFrame += additiveFrames;
×
237
}
UNCOV
238

×
239
int32 Buf_LinearVector3::GetFrame() const { return additiveFrames; }
240

241
void Buf_LinearVector3::SetFrame(uint64 frame) {
UNCOV
242
  additiveFrames = static_cast<int32>(frame);
×
243
}
244

245
void Buf_LinearVector3::Interpolate(Vector4A16 &out,
246
                                    const Buf_LinearVector3 &rightFrame,
247
                                    float delta, const TrackMinMax &) const {
248
  Vector4A16 startPoint, endPoint;
249

250
  Evaluate(startPoint);
UNCOV
251
  rightFrame.Evaluate(endPoint);
×
252

253
  out = lerp(startPoint, endPoint, delta);
254
}
255

UNCOV
256
void Buf_LinearVector3::SwapEndian() {
×
257
  FByteswapper(data);
258
  FByteswapper(additiveFrames);
259
}
260

261
size_t Buf_HermiteVector3::Size() const { return size; }
×
UNCOV
262

×
263
void Buf_HermiteVector3::AppendToString(std::stringstream &buffer) const {
UNCOV
264
  ReflectorWrap<const Buf_HermiteVector3> tRefl(this);
×
265

UNCOV
266
  buffer << "{ " << tRefl["data"].ReflectedValue() << ", "
×
267
         << tRefl["additiveFrames"].ReflectedValue() << ", "
268
         << tRefl["flags"].ReflectedValue();
269

UNCOV
270
  size_t curTang = 0;
×
271

272
  for (size_t f = 0; f < 6; f++) {
273
    if (flags[static_cast<Buf_HermiteVector3_Flags>(f)]) {
274
      buffer << ", " << tangents[curTang++];
275
    }
276
  }
277

278
  buffer << " }";
UNCOV
279
}
×
280

281
std::string_view
282
Buf_HermiteVector3::RetreiveFromString(std::string_view buffer) {
283
  buffer = SeekTo(buffer, '{');
UNCOV
284
  buffer = es::SkipStartWhitespace(buffer, true);
×
285

286
  ReflectorWrap<Buf_HermiteVector3> tRefl(this);
287
  tRefl["data"] = buffer;
288

289
  buffer = SeekTo(buffer, ',');
×
UNCOV
290
  buffer = es::SkipStartWhitespace(buffer, true);
×
291

UNCOV
292
  tRefl["additiveFrames"] = buffer;
×
293

UNCOV
294
  buffer = SeekTo(buffer, ',');
×
295
  buffer = es::SkipStartWhitespace(buffer, true);
296

297
  tRefl["flags"] = buffer;
UNCOV
298

×
299
  buffer = SeekTo(buffer, ',');
300
  buffer = es::SkipStartWhitespace(buffer, true);
301

302
  size_t curTang = 0;
303

304
  for (size_t f = 0; f < 6; f++) {
305
    if (flags[static_cast<Buf_HermiteVector3_Flags>(f)]) {
306
      tangents[curTang++] = static_cast<float>(std::atof(buffer.data()));
UNCOV
307
      buffer = SeekTo(buffer, ',');
×
308
      buffer = es::SkipStartWhitespace(buffer, true);
309
    }
310
  }
311

UNCOV
312
  size = static_cast<uint8>(sizeof(Buf_HermiteVector3) - (6 - curTang) * 4);
×
313

314
  return SeekTo(buffer);
315
}
316

317
void Buf_HermiteVector3::Evaluate(Vector4A16 &out) const {
×
UNCOV
318
  out = Vector4A16(data, 1.0f);
×
319
}
UNCOV
320

×
321
void Buf_HermiteVector3::GetTangents(Vector4A16 &inTangs,
UNCOV
322
                                     Vector4A16 &outTangs) const {
×
323
  size_t currentTangIndex = 0;
324

325
  inTangs.X = flags[Buf_HermiteVector3_Flags::InTangentX]
UNCOV
326
                  ? tangents[currentTangIndex++]
×
327
                  : 0.0f;
328
  inTangs.Y = flags[Buf_HermiteVector3_Flags::InTangentY]
329
                  ? tangents[currentTangIndex++]
330
                  : 0.0f;
331
  inTangs.Z = flags[Buf_HermiteVector3_Flags::InTangentZ]
332
                  ? tangents[currentTangIndex++]
333
                  : 0.0f;
334
  outTangs.X = flags[Buf_HermiteVector3_Flags::OutTangentX]
UNCOV
335
                   ? tangents[currentTangIndex++]
×
336
                   : 0.0f;
337
  outTangs.Y = flags[Buf_HermiteVector3_Flags::OutTangentY]
338
                   ? tangents[currentTangIndex++]
339
                   : 0.0f;
UNCOV
340
  outTangs.Z = flags[Buf_HermiteVector3_Flags::OutTangentZ]
×
341
                   ? tangents[currentTangIndex++]
342
                   : 0.0f;
343
}
344

345
void Buf_HermiteVector3::GetFrame(int32 &currentFrame) const {
×
UNCOV
346
  currentFrame += additiveFrames;
×
347
}
UNCOV
348

×
349
int32 Buf_HermiteVector3::GetFrame() const { return additiveFrames; }
UNCOV
350

×
351
void Buf_HermiteVector3::SetFrame(uint64 frame) {
352
  additiveFrames = static_cast<uint16>(frame);
353
}
UNCOV
354

×
355
void Buf_HermiteVector3::Interpolate(Vector4A16 &out,
356
                                     const Buf_HermiteVector3 &rightFrame,
357
                                     float delta, const TrackMinMax &) const {
358
  Vector4A16 startPoint, endPoint, startPointOutTangent, endPointInTangent,
359
      dummy;
360

361
  Evaluate(startPoint);
362
  rightFrame.Evaluate(endPoint);
UNCOV
363
  GetTangents(startPointOutTangent, endPointInTangent);
×
364

365
  const float deltaP2 = delta * delta;
366
  const float deltaP3 = delta * deltaP2;
367
  const float deltaP32 = deltaP3 * 2;
UNCOV
368
  const float deltaP23 = deltaP2 * 3;
×
369
  const float h1 = deltaP32 - deltaP23 + 1;
370
  const float h2 = -deltaP32 + deltaP23;
371
  const float h3 = deltaP3 - 2 * deltaP2 + delta;
372
  const float h4 = deltaP3 - deltaP2;
373

×
UNCOV
374
  out = startPoint * h1 + endPoint * h2 + startPointOutTangent * h3 +
×
375
        endPointInTangent * h4;
UNCOV
376
}
×
377

UNCOV
378
void Buf_HermiteVector3::SwapEndian() {
×
379
  FByteswapper(additiveFrames);
380
  FByteswapper(data);
381

UNCOV
382
  size_t curTang = 0;
×
383

384
  for (size_t f = 0; f < 6; f++) {
385
    if (flags[static_cast<Buf_HermiteVector3_Flags>(f)]) {
386
      FByteswapper(tangents[curTang]);
387
      curTang++;
388
    }
389
  }
390
}
UNCOV
391

×
392
size_t Buf_SphericalRotation::Size() const { return 8; }
393

394
void Buf_SphericalRotation::AppendToString(std::stringstream &buffer) const {
395
  AppendToStringRaw(this, buffer);
396
}
397

398
std::string_view
×
UNCOV
399
Buf_SphericalRotation::RetreiveFromString(std::string_view buffer) {
×
400
  return RetreiveFromRawString(this, buffer);
UNCOV
401
}
×
402

403
void Buf_SphericalRotation::Devaluate(const Vector4A16 &_in) {
404
  Vector4A16 in = _in;
405
  data ^= data & dataField;
406

407
  if (in.W < 0.0f) {
408
    in = -in;
409
  }
UNCOV
410

×
411
  if (in.X < 0.0f) {
UNCOV
412
    in.X *= -1;
×
413
    data |= 1ULL << 53;
414
  }
UNCOV
415

×
416
  if (in.Y < 0.0f) {
417
    in.Y *= -1;
418
    data |= 1ULL << 54;
UNCOV
419
  }
×
420

421
  if (in.Z < 0.0f) {
422
    in.Z *= -1;
423
    data |= 1ULL << 55;
×
UNCOV
424
  }
×
425

426
  const float R = sqrtf(1.0f - in.W);
UNCOV
427
  const float magnitude_safe = sqrtf(1.0f - (in.W * in.W));
×
428
  const float magnitude = magnitude_safe < 0.001f ? 1.0f : magnitude_safe;
1✔
429

430
  const float phi = asinf(in.Y / magnitude);
431
  const float theta = asinf(in.X / (cosf(phi) * magnitude));
2✔
432

UNCOV
433
  data |= static_cast<uint64>(theta * componentMultiplierInv) & componentMask;
×
434
  data |= (static_cast<uint64>(phi * componentMultiplierInv) & componentMask)
UNCOV
435
          << 17;
×
436
  data |= (static_cast<uint64>(R * componentMaskW) & componentMaskW) << 34;
UNCOV
437
}
×
438

439
void Buf_SphericalRotation::Evaluate(Vector4A16 &out) const {
440
  out.X = static_cast<float>(data & componentMask);
441
  out.Y = static_cast<float>((data >> 17) & componentMask);
442
  float wComp =
443
      static_cast<float>((data >> 34) & componentMaskW) * componentMultiplierW;
444
  out *= componentMultiplier;
UNCOV
445

×
446
  const Vector4A16 var1(sinf(out.X), sinf(out.Y), cosf(out.X), cosf(out.Y));
447

UNCOV
448
  // Optimized Taylor series expansion of sin function, this is faster by 4ms
×
449
  // on debug, 1-2ms on release /wo inline Since this library is not frame
UNCOV
450
  // time heavy, it's disabled If enabled: invert out.X before sign check
×
451
  /*
1✔
452
  out.Z = out.X - fPI2;
453
  out.W = out.Y - fPI2;
454

UNCOV
455
  const Vector4A16 fvar1 = out * out;
×
456
  const Vector4A16 fvar2 = out * 9.53992f;
457
  const Vector4A16 var1 = out * (out - fPI) * (out + fPI) * (fvar1 - fvar2
458
  + 25.0493f) * (fvar1 + fvar2 + 25.0493f) * -0.000161476f;
459
  */
460

461
  wComp = 1.0f - (wComp * wComp);
462
  float magnitude = sqrtf(1.0f - (wComp * wComp));
463

UNCOV
464
  out.X = var1.X * var1.W * magnitude;
×
465
  out.Y = var1.Y * magnitude;
466
  out.Z = var1.Z * var1.W * magnitude;
UNCOV
467
  out.W = wComp;
×
468

UNCOV
469
  if ((data >> 53) & 1) {
×
470
    out.X *= -1;
471
  }
472

×
UNCOV
473
  if ((data >> 54) & 1) {
×
474
    out.Y *= -1;
475
  }
476

UNCOV
477
  if ((data >> 55) & 1) {
×
478
    out.Z *= -1;
479
  }
480
}
481

UNCOV
482
void Buf_SphericalRotation::GetFrame(int32 &currentFrame) const {
×
483
  currentFrame += data >> 56;
484
}
485

486
int32 Buf_SphericalRotation::GetFrame() const { return data >> 56; }
487

UNCOV
488
void Buf_SphericalRotation::SetFrame(uint64 frame) {
×
489
  data ^= data & frameField;
UNCOV
490
  data |= frame << 56;
×
491
}
492

493
void Buf_SphericalRotation::Interpolate(Vector4A16 &out,
1✔
494
                                        const Buf_SphericalRotation &rightFrame,
UNCOV
495
                                        float delta,
×
496
                                        const TrackMinMax &) const {
1✔
497
  Vector4A16 startPoint, endPoint;
498

499
  Evaluate(startPoint);
×
UNCOV
500
  rightFrame.Evaluate(endPoint);
×
501

502
  out = slerp(startPoint, endPoint, delta);
UNCOV
503
}
×
504

505
void Buf_SphericalRotation::SwapEndian() { FByteswapper(data); }
×
UNCOV
506

×
507
size_t Buf_BiLinearVector3_16bit::Size() const { return 8; }
508

UNCOV
509
void Buf_BiLinearVector3_16bit::AppendToString(
×
510
    std::stringstream &buffer) const {
511
  AppendToStringRaw(this, buffer);
512
}
513

514
std::string_view
515
Buf_BiLinearVector3_16bit::RetreiveFromString(std::string_view buffer) {
516
  return RetreiveFromRawString(this, buffer);
UNCOV
517
}
×
518

519
void Buf_BiLinearVector3_16bit::Evaluate(Vector4A16 &out) const {
520
  out = Vector4A16(data.Convert<float>(), 1.0f) * componentMultiplier;
×
521
}
×
UNCOV
522

×
523
void Buf_BiLinearVector3_16bit::Devaluate(const Vector4A16 &in) {
524
  data = USVector4((in * componentMultiplierInv).Convert<uint16>());
UNCOV
525
}
×
526

UNCOV
527
void Buf_BiLinearVector3_16bit::GetFrame(int32 &currentFrame) const {
×
528
  currentFrame += additiveFrames;
529
}
530

×
531
int32 Buf_BiLinearVector3_16bit::GetFrame() const { return additiveFrames; }
×
UNCOV
532

×
533
void Buf_BiLinearVector3_16bit::SetFrame(uint64 frame) {
534
  additiveFrames = static_cast<uint16>(frame);
535
}
536

×
537
void Buf_BiLinearVector3_16bit::Interpolate(
×
UNCOV
538
    Vector4A16 &out, const Buf_BiLinearVector3_16bit &rightFrame, float delta,
×
539
    const TrackMinMax &minMax) const {
540
  Vector4A16 startPoint, endPoint;
541

UNCOV
542
  Evaluate(startPoint);
×
543
  rightFrame.Evaluate(endPoint);
544

545
  out = blerp(startPoint, endPoint, minMax, delta);
UNCOV
546
}
×
547

548
void Buf_BiLinearVector3_16bit::SwapEndian() {
549
  FByteswapper(data);
550
  FByteswapper(additiveFrames);
UNCOV
551
}
×
552

553
constexpr float __Buf_BiLinearVector3_16bit_componentMask =
554
    static_cast<float>(Buf_BiLinearVector3_16bit::componentMask);
555

UNCOV
556
const Vector4A16 Buf_BiLinearVector3_16bit::componentMultiplierInv =
×
557
    Vector4A16(__Buf_BiLinearVector3_16bit_componentMask,
558
               __Buf_BiLinearVector3_16bit_componentMask,
559
               __Buf_BiLinearVector3_16bit_componentMask, 1.0f);
560

UNCOV
561
const Vector4A16 Buf_BiLinearVector3_16bit::componentMultiplier =
×
562
    Vector4A16(1.0f) / componentMultiplierInv;
563

564
size_t Buf_BiLinearVector3_8bit::Size() const { return 4; }
565

566
void Buf_BiLinearVector3_8bit::AppendToString(std::stringstream &buffer) const {
567
  AppendToStringRaw(this, buffer);
568
}
×
569

×
UNCOV
570
std::string_view
×
571
Buf_BiLinearVector3_8bit::RetreiveFromString(std::string_view buffer) {
572
  return RetreiveFromRawString(this, buffer);
573
}
574

575
void Buf_BiLinearVector3_8bit::Evaluate(Vector4A16 &out) const {
UNCOV
576
  out = Vector4A16(data.Convert<float>(), 1.0f) * componentMultiplier;
×
577
}
UNCOV
578

×
579
void Buf_BiLinearVector3_8bit::Devaluate(const Vector4A16 &in) {
580
  data = UCVector4((in * componentMultiplierInv).Convert<uint8>());
581
}
×
UNCOV
582

×
583
void Buf_BiLinearVector3_8bit::GetFrame(int32 &currentFrame) const {
584
  currentFrame += additiveFrames;
UNCOV
585
}
×
586

587
int32 Buf_BiLinearVector3_8bit::GetFrame() const { return additiveFrames; }
588

589
void Buf_BiLinearVector3_8bit::SetFrame(uint64 frame) {
×
UNCOV
590
  additiveFrames = static_cast<uint8>(frame);
×
591
}
592

×
UNCOV
593
void Buf_BiLinearVector3_8bit::Interpolate(
×
594
    Vector4A16 &out, const Buf_BiLinearVector3_8bit &rightFrame, float delta,
595
    const TrackMinMax &minMax) const {
×
UNCOV
596
  Vector4A16 startPoint, endPoint;
×
597

598
  Evaluate(startPoint);
×
UNCOV
599
  rightFrame.Evaluate(endPoint);
×
600

601
  out = blerp(startPoint, endPoint, minMax, delta);
×
UNCOV
602
}
×
603

604
constexpr float __Buf_BiLinearVector3_8bit_componentMask =
×
UNCOV
605
    static_cast<float>(Buf_BiLinearVector3_8bit::componentMask);
×
606

607
const Vector4A16 Buf_BiLinearVector3_8bit::componentMultiplierInv =
608
    Vector4A16(__Buf_BiLinearVector3_8bit_componentMask,
609
               __Buf_BiLinearVector3_8bit_componentMask,
×
UNCOV
610
               __Buf_BiLinearVector3_8bit_componentMask, 1.0f);
×
611

612
const Vector4A16 Buf_BiLinearVector3_8bit::componentMultiplier =
UNCOV
613
    Vector4A16(1.0f) / componentMultiplierInv;
×
614

615
void Buf_LinearRotationQuat4_14bit::Evaluate(Vector4A16 &out) const {
×
UNCOV
616
  out = IVector4A16(static_cast<int32>(data >> 42),
×
617
                    static_cast<int32>(data >> 28),
618
                    static_cast<int32>(data >> 14), static_cast<int32>(data)) &
UNCOV
619
        componentMask;
×
620

621
  const Vector4A16 signedHalf(Vector4A16(static_cast<float>(componentMask)) -
622
                              out);
623
  const Vector4A16 multSign(out.X > componentSignMax ? -1.0f : 0.0f,
624
                            out.Y > componentSignMax ? -1.0f : 0.0f,
625
                            out.Z > componentSignMax ? -1.0f : 0.0f,
626
                            out.W > componentSignMax ? -1.0f : 0.0f);
UNCOV
627

×
628
  out *= multSign + 1.0f;
629
  out += signedHalf * multSign;
×
630
  out *= componentMultiplier;
×
631
}
×
632

×
633
void Buf_LinearRotationQuat4_14bit::Devaluate(const Vector4A16 &_in) {
×
634
  Vector4A16 in = _in;
×
635
  data ^= data & dataField;
×
UNCOV
636

×
637
  in *= componentMultiplierInv;
638

639
  if (in.W < 0.0f) {
640
    data |= componentMask - static_cast<uint64>(-in.W);
641
  } else {
642
    data |= static_cast<uint64>(in.W);
×
643
  }
×
UNCOV
644

×
645
  if (in.Z < 0.0f) {
646
    data |= (componentMask - static_cast<uint64>(-in.Z)) << 14;
647
  } else {
648
    data |= static_cast<uint64>(in.Z) << 14;
×
649
  }
×
650

×
UNCOV
651
  if (in.Y < 0.0f) {
×
652
    data |= (componentMask - static_cast<uint64>(-in.Y)) << 28;
653
  } else {
654
    data |= static_cast<uint64>(in.Y) << 28;
655
  }
UNCOV
656

×
657
  if (in.X < 0.0f) {
658
    data |= (componentMask - static_cast<uint64>(-in.X)) << 42;
×
UNCOV
659
  } else {
×
660
    data |= static_cast<uint64>(in.X) << 42;
661
  }
662
}
663

×
UNCOV
664
void Buf_LinearRotationQuat4_14bit::Interpolate(
×
665
    Vector4A16 &out, const Buf_LinearRotationQuat4_14bit &rightFrame,
666
    float delta, const TrackMinMax &) const {
667
  Vector4A16 startPoint, endPoint;
1✔
668

1✔
669
  Evaluate(startPoint);
1✔
670
  rightFrame.Evaluate(endPoint);
671

1✔
672
  out = slerp(startPoint, endPoint, delta);
673
}
674

675
size_t Buf_BiLinearRotationQuat4_7bit::Size() const { return 4; }
1✔
676

×
UNCOV
677
void Buf_BiLinearRotationQuat4_7bit::AppendToString(
×
678
    std::stringstream &buffer) const {
679
  AppendToStringRaw(this, buffer);
680
}
1✔
681

1✔
682
std::string_view
1✔
683
Buf_BiLinearRotationQuat4_7bit::RetreiveFromString(std::string_view buffer) {
684
  return RetreiveFromRawString(this, buffer);
685
}
1✔
686

687
void Buf_BiLinearRotationQuat4_7bit::Evaluate(Vector4A16 &out) const {
1✔
688
  out = IVector4A16(data >> 21, data >> 14, data >> 7, data) & componentMask;
689
  out *= componentMultiplier;
690
}
1✔
691

1✔
692
void Buf_BiLinearRotationQuat4_7bit::Devaluate(const Vector4A16 &in) {
1✔
693
  data ^= data & dataField;
694

1✔
695
  UIVector4A16 store(IVector4A16(in * componentMultiplierInv));
1✔
696

697
  data |= store.W;
1✔
698
  data |= store.Z << 7;
1✔
699
  data |= store.Y << 14;
1✔
700
  data |= store.X << 21;
1✔
701
}
1✔
702

703
void Buf_BiLinearRotationQuat4_7bit::GetFrame(int32 &currentFrame) const {
1✔
704
  currentFrame += data >> 28;
1✔
705
}
1✔
706

1✔
707
int32 Buf_BiLinearRotationQuat4_7bit::GetFrame() const { return data >> 28; }
1✔
708

709
void Buf_BiLinearRotationQuat4_7bit::SetFrame(uint64 frame) {
710
  data ^= data & frameField;
1✔
711
  data |= frame << 28;
712
}
713

714
void Buf_BiLinearRotationQuat4_7bit::Interpolate(
715
    Vector4A16 &out, const Buf_BiLinearRotationQuat4_7bit &rightFrame,
716
    float delta, const TrackMinMax &minMax) const {
717
  Vector4A16 startPoint, endPoint;
718

719
  Evaluate(startPoint);
720
  rightFrame.Evaluate(endPoint);
721

722
  out = bslerp(startPoint, endPoint, minMax, delta);
723
}
724

725
void Buf_BiLinearRotationQuat4_7bit::SwapEndian() { FByteswapper(data); }
1✔
726

1✔
727
void Buf_BiLinearRotationQuatXW_14bit::Evaluate(Vector4A16 &out) const {
728
  out = IVector4A16(data, 0, 0, data >> 14) & componentMask;
1✔
729
  out *= componentMultiplier;
1✔
730
}
1✔
731

1✔
732
void Buf_BiLinearRotationQuatXW_14bit::Devaluate(const Vector4A16 &in) {
733
  data ^= data & dataField;
1✔
UNCOV
734

×
735
  UIVector4A16 store(IVector4A16(in * componentMultiplierInv));
736

737
  data |= store.X;
1✔
738
  data |= store.W << 14;
1✔
739
}
740

741
void Buf_BiLinearRotationQuatXW_14bit::Interpolate(
1✔
742
    Vector4A16 &out, const Buf_BiLinearRotationQuatXW_14bit &rightFrame,
1✔
743
    float delta, const TrackMinMax &minMax) const {
744
  Vector4A16 startPoint, endPoint;
1✔
745

746
  Evaluate(startPoint);
×
UNCOV
747
  rightFrame.Evaluate(endPoint);
×
748

749
  out = bslerp(startPoint, endPoint, minMax, delta);
UNCOV
750
}
×
751

752
void Buf_BiLinearRotationQuatYW_14bit::Evaluate(Vector4A16 &out) const {
×
753
  out = IVector4A16(0, data, 0, data >> 14) & componentMask;
×
UNCOV
754
  out *= componentMultiplier;
×
755
}
756

UNCOV
757
void Buf_BiLinearRotationQuatYW_14bit::Devaluate(const Vector4A16 &in) {
×
758
  data ^= data & dataField;
759

760
  UIVector4A16 store(IVector4A16(in * componentMultiplierInv));
761

762
  data |= store.Y;
763
  data |= store.W << 14;
×
UNCOV
764
}
×
765

UNCOV
766
void Buf_BiLinearRotationQuatYW_14bit::Interpolate(
×
767
    Vector4A16 &out, const Buf_BiLinearRotationQuatYW_14bit &rightFrame,
768
    float delta, const TrackMinMax &minMax) const {
UNCOV
769
  Vector4A16 startPoint, endPoint;
×
770

UNCOV
771
  Evaluate(startPoint);
×
772
  rightFrame.Evaluate(endPoint);
UNCOV
773

×
774
  out = bslerp(startPoint, endPoint, minMax, delta);
UNCOV
775
}
×
776

777
void Buf_BiLinearRotationQuatZW_14bit::Evaluate(Vector4A16 &out) const {
778
  out = IVector4A16(0, 0, data, data >> 14) & componentMask;
779
  out *= componentMultiplier;
×
UNCOV
780
}
×
781

782
void Buf_BiLinearRotationQuatZW_14bit::Devaluate(const Vector4A16 &in) {
UNCOV
783
  data ^= data & dataField;
×
784

785
  UIVector4A16 store(IVector4A16(in * componentMultiplierInv));
786

UNCOV
787
  data |= store.Z;
×
788
  data |= store.W << 14;
1✔
789
}
790

791
void Buf_BiLinearRotationQuatZW_14bit::Interpolate(
×
UNCOV
792
    Vector4A16 &out, const Buf_BiLinearRotationQuatZW_14bit &rightFrame,
×
793
    float delta, const TrackMinMax &minMax) const {
794
  Vector4A16 startPoint, endPoint;
UNCOV
795

×
796
  Evaluate(startPoint);
797
  rightFrame.Evaluate(endPoint);
×
UNCOV
798

×
799
  out = bslerp(startPoint, endPoint, minMax, delta);
800
}
UNCOV
801

×
802
size_t Buf_BiLinearRotationQuat4_11bit::Size() const { return 6; }
803

804
void Buf_BiLinearRotationQuat4_11bit::AppendToString(
805
    std::stringstream &buffer) const {
806
  AppendToStringRaw(this, buffer);
807
}
808

UNCOV
809
std::string_view
×
810
Buf_BiLinearRotationQuat4_11bit::RetreiveFromString(std::string_view buffer) {
811
  return RetreiveFromRawString(this, buffer);
812
}
×
813

×
UNCOV
814
void Buf_BiLinearRotationQuat4_11bit::Evaluate(Vector4A16 &out) const {
×
815
  const uint64 &rVal = reinterpret_cast<const uint64 &>(data);
816

817
  out = IVector4A16(static_cast<int32>(rVal),
818
                    static_cast<int32>(((rVal >> 11) << 6) | (data[1] & 0x3f)),
819
                    static_cast<int32>((rVal >> 22) << 1 | (data[2] & 1)),
820
                    static_cast<int32>(rVal >> 33)) &
821
        componentMask;
822
  out *= componentMultiplier;
823
}
824

825
void Buf_BiLinearRotationQuat4_11bit::Devaluate(const Vector4A16 &in) {
826
  uint64 &rVal = reinterpret_cast<uint64 &>(data);
827

UNCOV
828
  rVal ^= rVal & 0xFFFFFFFFFFF;
×
829

830
  t_Vector4<uint64> store = (in * componentMultiplierInv).Convert<uint64>();
×
UNCOV
831

×
832
  rVal |= store.X;
833
  rVal |= (store.Y >> 6 | (store.Y & 0x3f) << 5) << 11;
834
  rVal |= (store.Z >> 1 | (store.Z & 1) << 10) << 22;
835
  rVal |= store.W << 33;
×
UNCOV
836
}
×
837

838
void Buf_BiLinearRotationQuat4_11bit::GetFrame(int32 &currentFrame) const {
UNCOV
839
  currentFrame += data.Z >> 12;
×
840
}
841

842
void Buf_BiLinearRotationQuat4_11bit::Interpolate(
UNCOV
843
    Vector4A16 &out, const Buf_BiLinearRotationQuat4_11bit &rightFrame,
×
844
    float delta, const TrackMinMax &minMax) const {
1✔
845
  Vector4A16 startPoint, endPoint;
846

847
  Evaluate(startPoint);
×
UNCOV
848
  rightFrame.Evaluate(endPoint);
×
849

850
  out = bslerp(startPoint, endPoint, minMax, delta);
UNCOV
851
}
×
852

853
void Buf_BiLinearRotationQuat4_11bit::SwapEndian() { FByteswapper(data); }
×
UNCOV
854

×
855
size_t Buf_BiLinearRotationQuat4_9bit::Size() const { return 5; }
856

UNCOV
857
void Buf_BiLinearRotationQuat4_9bit::AppendToString(
×
858
    std::stringstream &buffer) const {
859
  AppendToStringRaw(this, buffer);
860
}
861

862
std::string_view
863
Buf_BiLinearRotationQuat4_9bit::RetreiveFromString(std::string_view buffer) {
864
  return RetreiveFromRawString(this, buffer);
UNCOV
865
}
×
866

867
void Buf_BiLinearRotationQuat4_9bit::Evaluate(Vector4A16 &out) const {
868
  const uint64 &rVal = reinterpret_cast<const uint64 &>(data);
869

870
  out = IVector4A16(static_cast<int32>((rVal << 1) | (data[1] & 1)),
871
                    static_cast<int32>(((rVal >> 9) << 2) | (data[2] & 3)),
872
                    static_cast<int32>(((rVal >> 18) << 3) | (data[3] & 7)),
873
                    static_cast<int32>(((rVal >> 27) << 4) | (data[4] & 0xf))) &
874
        componentMask;
875
  out *= componentMultiplier;
876
}
877

878
void Buf_BiLinearRotationQuat4_9bit::Devaluate(const Vector4A16 &in) {
879
  uint64 &rVal = reinterpret_cast<uint64 &>(data);
1✔
880

1✔
881
  rVal ^= rVal & 0xFFFFFFFFF;
1✔
882

1✔
883
  t_Vector4<uint64> store = (in * componentMultiplierInv).Convert<uint64>();
884

885
  rVal |= store.X >> 1 | (store.X & 1) << 8;
886
  rVal |= (store.Y >> 2 | (store.Y & 3) << 7) << 9;
887
  rVal |= (store.Z >> 3 | (store.Z & 7) << 6) << 18;
888
  rVal |= (store.W >> 4 | (store.W & 0xf) << 5) << 27;
889
}
890

2✔
891
void Buf_BiLinearRotationQuat4_9bit::GetFrame(int32 &currentFrame) const {
892
  currentFrame += data[4] >> 4;
893
}
894

895
void Buf_BiLinearRotationQuat4_9bit::Interpolate(
1✔
896
    Vector4A16 &out, const Buf_BiLinearRotationQuat4_9bit &rightFrame,
897
    float delta, const TrackMinMax &minMax) const {
1✔
898
  Vector4A16 startPoint, endPoint;
1✔
899

1✔
900
  Evaluate(startPoint);
901
  rightFrame.Evaluate(endPoint);
902

903
  out = bslerp(startPoint, endPoint, minMax, delta);
1✔
UNCOV
904
}
×
905

906
template <class C>
1✔
907
void Buff_EvalShared<C>::ToString(std::string &strBuff,
908
                                  size_t numIdents) const {
909
  static const char *idents[] = {
1✔
910
      "", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t",
1✔
911
  };
UNCOV
912
  std::stringstream str;
×
913
  str << std::endl << idents[numIdents];
914

915
  size_t curLine = 1;
1✔
916

1✔
917
  for (auto &d : data) {
UNCOV
918
    d.AppendToString(str);
×
919

920
    if (!(curLine % C::NEWLINEMOD)) {
921
      str << std::endl << idents[numIdents];
1✔
UNCOV
922
    }
×
923

924
    curLine++;
1✔
925
  }
926

1✔
927
  if (!((curLine - 1) % C::NEWLINEMOD)) {
UNCOV
928
    str.seekp(-1, std::ios_base::cur) << '\0';
×
929
  } else {
930
    str << std::endl << idents[numIdents - 1];
931
  }
932

933
  strBuff = std::move(str).str();
×
UNCOV
934
}
×
935

UNCOV
936
template <class C> void Buff_EvalShared<C>::FromString(std::string_view input) {
×
937
  for (auto &d : data) {
938
    input = d.RetreiveFromString(input);
UNCOV
939
  }
×
940
}
UNCOV
941

×
942
template <class C>
UNCOV
943
void Buff_EvalShared<C>::Assign(char *ptr, size_t size, bool swapEndian) {
×
944
  if constexpr (!C::VARIABLE_SIZE) {
945
    data = {reinterpret_cast<C *>(ptr), reinterpret_cast<C *>(ptr + size)};
946
  } else {
947
    const char *bufferEnd = ptr + size;
×
UNCOV
948

×
949
    while (ptr < bufferEnd) {
950
      C *block = reinterpret_cast<C *>(ptr);
UNCOV
951
      internalData.push_back(*block);
×
952
      ptr += block->Size();
1✔
953
    }
954

955
    data = internalData;
UNCOV
956
  }
×
957

1✔
958
  if (swapEndian) {
959
    SwapEndian();
960
  }
961

1✔
962
  frames.resize(NumFrames());
1✔
963
  int32 currentFrame = 0;
1✔
964
  size_t curFrameID = 0;
1✔
965

966
  for (auto &f : frames) {
967
    f = currentFrame;
×
UNCOV
968
    data[curFrameID++].GetFrame(currentFrame);
×
969
  }
970
}
UNCOV
971

×
972
template <class C> void Buff_EvalShared<C>::Save(BinWritterRef wr) const {
973
  if constexpr (!C::VARIABLE_SIZE) {
×
974
    if (!wr.SwappedEndian()) {
×
UNCOV
975
      wr.WriteBuffer(reinterpret_cast<const char *>(data.data()),
×
976
                     data.size() * sizeof(typename decltype(data)::value_type));
977
    } else {
UNCOV
978
      wr.WriteContainer(data);
×
979
    }
980
  } else {
981
    for (auto &r : data) {
982
      C tmp = r;
983
      tmp.SwapEndian();
984
      wr.WriteBuffer(reinterpret_cast<const char *>(&tmp), r.Size());
985
    }
UNCOV
986
  }
×
987
}
988

UNCOV
989
template <class C> void Buff_EvalShared<C>::SwapEndian() {
×
990
  for (auto &d : data) {
UNCOV
991
    d.SwapEndian();
×
992
  }
1✔
993
}
994

995
template <class Derived> LMTTrackController *_creatorDummyBuffEval() {
UNCOV
996
  return new Buff_EvalShared<Derived>();
×
997
}
1✔
998

999
#define TCON_REG(val) {TrackTypesShared::val, _creatorDummyBuffEval<Buf_##val>},
1000

1001
#define TCONFRC_REG(val)                                                       \
1✔
1002
  {TrackTypesShared::val, [] { return Buf_##val::componentMultiplier; }()},
1✔
1003

1004
namespace std {
UNCOV
1005
template <> struct hash<TrackTypesShared> {
×
1006
  uint32 operator()(const TrackTypesShared &t) const {
1007
    return static_cast<uint32>(t);
1008
  }
1009
};
1010
} // namespace std
1011

1012
static const std::unordered_map<TrackTypesShared, LMTTrackController *(*)()>
UNCOV
1013
    codecRegistry = {
×
1014
        {TrackTypesShared::None, nullptr},
1015
        StaticFor(TCON_REG, SingleVector3, HermiteVector3, StepRotationQuat3,
UNCOV
1016
                  SphericalRotation, LinearVector3, BiLinearVector3_16bit,
×
1017
                  BiLinearVector3_8bit, LinearRotationQuat4_14bit,
1✔
1018
                  BiLinearRotationQuat4_7bit, BiLinearRotationQuatXW_14bit,
1019
                  BiLinearRotationQuatYW_14bit, BiLinearRotationQuatZW_14bit,
1020
                  BiLinearRotationQuat4_11bit, BiLinearRotationQuat4_9bit)};
UNCOV
1021

×
1022
static const std::unordered_map<TrackTypesShared, float> fracRegistry = {
1✔
1023
    {TrackTypesShared::BiLinearVector3_16bit,
1024
     Buf_BiLinearVector3_16bit::componentMultiplier.X},
1025
    {TrackTypesShared::BiLinearVector3_8bit,
1026
     Buf_BiLinearVector3_8bit::componentMultiplier.X},
1✔
1027
    StaticFor(TCONFRC_REG, LinearRotationQuat4_14bit,
1✔
1028
              BiLinearRotationQuat4_7bit, BiLinearRotationQuatXW_14bit,
1029
              BiLinearRotationQuatYW_14bit, BiLinearRotationQuatZW_14bit,
UNCOV
1030
              BiLinearRotationQuat4_11bit, BiLinearRotationQuat4_9bit)};
×
1031

1032
LMTTrackController *LMTTrackController::CreateCodec(TrackTypesShared cType) {
1033
  if (codecRegistry.count(cType)) {
1034
    return codecRegistry.at(cType)();
1035
  }
1036

1037
  return nullptr;
UNCOV
1038
}
×
1039

1040
float LMTTrackController::GetTrackMaxFrac(TrackTypesShared type) {
UNCOV
1041
  if (fracRegistry.count(type)) {
×
1042
    return fracRegistry.at(type);
1✔
1043
  }
1044

1045
  return FLT_MAX;
UNCOV
1046
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc