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

PredatorCZ / HavokLib / 89

06 Nov 2025 01:09PM UTC coverage: 63.837% (-3.2%) from 67.014%
89

push

github

PredatorCZ
s

3354 of 5254 relevant lines covered (63.84%)

129082.83 hits per line

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

43.55
/source/packfile/hk_rootlevelcontainer.cpp
1
/*  Havok Format Library
2
    Copyright(C) 2016-2022 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 "internal/hk_rootlevelcontainer.hpp"
19
#include "base.hpp"
20
#include "hk_rootlevelcontainer.inl"
21

22
struct hkRootLevelContainerSaver {
23
  const hkRootLevelContainerInternalInterface *in;
24
  const clgen::hkRootLevelContainer::Interface *out;
25

26
  void Save(BinWritterRef wr, hkFixups &fixups) {
×
27
    const size_t sBegin = wr.Tell();
×
28
    auto &locals = fixups.locals;
×
29
    auto &lay = *out->layout;
×
30

31
    wr.WriteBuffer(out->data, lay.totalSize);
×
32

33
    if (in->Size()) {
×
34
      wr.ApplyPadding();
×
35
      locals.emplace_back(sBegin, wr.Tell());
×
36
      size_t curFixup = locals.size();
×
37
      const auto varType =
38
          clgen::GetLayout(clgen::hkNamedVariant::LAYOUTS, out->lookup);
×
39
      using vm = clgen::hkNamedVariant::Members;
40

41
      for ([[maybe_unused]] auto &v : *in) {
×
42
        const size_t varBegin = wr.Tell();
×
43
        wr.Skip(varType->totalSize);
×
44

45
        for (auto v : varType->vtable) {
×
46
          locals.emplace_back(varBegin + (v * varType->ptrSize));
×
47
        }
48
      }
49

50
      for (auto &i : *in) {
×
51
        wr.ApplyPadding(8);
×
52
        locals[curFixup + vm::name].destination = wr.Tell();
×
53
        wr.WriteBuffer(i.name.data(), i.name.size() + 1);
×
54
        wr.ApplyPadding(8);
×
55
        locals[curFixup + vm::className].destination = wr.Tell();
×
56
        wr.WriteBuffer(i.className.data(), i.className.size() + 1);
×
57
        locals[curFixup + vm::variant].destClass = i.pointer;
×
58
      }
59
    }
60
  }
61
};
62

63
struct hkRootLevelContainerMidInterface
64
    : hkRootLevelContainerInternalInterface {
65
  clgen::hkRootLevelContainer::Interface interface;
66
  std::unique_ptr<hkRootLevelContainerSaver> saver;
67

68
  hkRootLevelContainerMidInterface(clgen::LayoutLookup rules, char *data)
906✔
69
      : interface {
1,812✔
70
    data, rules
71
  } {
906✔
72
  }
906✔
73

74
  void SetDataPointer(void *ptr) override {
906✔
75
    interface.data = static_cast<char *>(ptr);
906✔
76
  }
906✔
77

78
  const void *GetPointer() const override { return interface.data; }
2,418✔
79

80
  size_t Size() const override { return interface.NumVariants(); }
1,075✔
81
  const hkNamedVariant At(size_t id) const override {
1,010✔
82
    auto item = interface.Variants().Next(id);
1,010✔
83
    if (interface.LayoutVersion() >= HK700) {
1,010✔
84
      return {item.Name(), item.ClassName(),
1,428✔
85
              header->GetClass(item.VariantHK700())};
1,428✔
86
    }
87

88
    return {item.Name(), item.ClassName(),
592✔
89
            header->GetClass(item.Variant().Object())};
592✔
90
  }
91

92
  void Reflect(const IhkVirtualClass *other) override {
×
93
    interface.data = static_cast<char *>(malloc(interface.layout->totalSize));
×
94
    saver = std::make_unique<hkRootLevelContainerSaver>();
×
95
    saver->in = static_cast<const hkRootLevelContainerInternalInterface *>(
×
96
        checked_deref_cast<const hkRootLevelContainer>(other));
×
97
    saver->out = &interface;
×
98
    interface.NumVariants(saver->in->Size());
×
99
  }
100

101
  void Save(BinWritterRef wr, hkFixups &fixups) const override {
×
102
    saver->Save(wr, fixups);
×
103
  }
104

105
  void SwapEndian() override { clgen::EndianSwap(interface); }
453✔
106

107
  ~hkRootLevelContainerMidInterface() {
1,812✔
108
    if (saver) {
906✔
109
      free(interface.data);
×
110
    }
111
  }
1,812✔
112
};
906✔
113

114
CREATE_HK_CLASS(hkRootLevelContainer);
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