• 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

40.35
/source/packfile/hkx_environment.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/hkx_environment.hpp"
19
#include "base.hpp"
20
#include "hkx_environment.inl"
21

22
struct hkxEnvironmentSaver {
23
  const hkxEnvironmentInternalInterface *in;
24
  const clgen::hkxEnvironment::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
    using mm = clgen::hkxEnvironment::Members;
33

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

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

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

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

63
struct hkxEnvironmentMidInterface : hkxEnvironmentInternalInterface {
64
  clgen::hkxEnvironment::Interface interface;
65
  std::unique_ptr<hkxEnvironmentSaver> saver;
66

67
  hkxEnvironmentMidInterface(clgen::LayoutLookup rules, char *data)
834✔
68
      : interface {
1,668✔
69
    data, rules
70
  } {
834✔
71
  }
834✔
72

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

77
  const void *GetPointer() const override { return interface.data; }
849✔
78

79
  void SwapEndian() override { clgen::EndianSwap(interface); }
417✔
80

81
  size_t Size() const override { return interface.NumVariables(); }
151✔
82

83
  const hkxEnvironmentVariable At(size_t id) const override {
462✔
84
    auto item = interface.Variables().Next(id);
462✔
85
    return {item.Name(), item.Value()};
924✔
86
  }
87

88
  void Reflect(const IhkVirtualClass *other) override {
×
89
    interface.data = static_cast<char *>(malloc(interface.layout->totalSize));
×
90
    saver = std::make_unique<hkxEnvironmentSaver>();
×
91
    saver->in = static_cast<const hkxEnvironmentInternalInterface *>(
×
92
        checked_deref_cast<const hkxEnvironment>(other));
×
93
    saver->out = &interface;
×
94
    interface.NumVariables(saver->in->Size());
×
95
  }
96

97
  void Save(BinWritterRef wr, hkFixups &fixups) const override {
×
98
    saver->Save(wr, fixups);
×
99
  }
100

101
  ~hkxEnvironmentMidInterface() {
1,668✔
102
    if (saver) {
834✔
103
      free(interface.data);
×
104
    }
105
  }
1,668✔
106
};
834✔
107

108
CREATE_HK_CLASS(hkxEnvironment);
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

© 2026 Coveralls, Inc