-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhva.cpp
71 lines (57 loc) · 1.57 KB
/
hva.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "hva.h"
hva::hva(const std::string& filename) :hva()
{
load(filename);
}
bool hva::load(const std::string& filename)
{
auto data = read_whole_file(filename);
return load(data.get());
}
bool hva::load(const void* data)
{
if (!data)
{
return false;
}
char* filedata = reinterpret_cast<char*>(const_cast<void*>(data));
char* filecur = filedata;
purge();
memcpy_s(_signature, sizeof _signature, filecur, sizeof _signature);
filecur += sizeof _signature;
_framecount = *reinterpret_cast<uint32_t*>(filecur);
filecur += sizeof _framecount;
_sectioncount = *reinterpret_cast<uint32_t*>(filecur);
filecur += sizeof _sectioncount + /*section names*/section_count() * sizeof _signature;
size_t total_maxticx_count = section_count() * frame_count();
_totalmatrices.resize(total_maxticx_count);
memcpy_s(_totalmatrices.data(), total_maxticx_count * sizeof vxlmatrix, filecur, total_maxticx_count * sizeof vxlmatrix);
return true;
}
bool hva::is_loaded() const
{
return !_totalmatrices.empty();
}
void hva::purge()
{
_signature[0] = 0;
_framecount = _sectioncount = 0;
_totalmatrices.clear();
}
file_type hva::type() const
{
return file_type::hva;
}
const size_t hva::frame_count() const
{
return _framecount;
}
const size_t hva::section_count() const
{
return _sectioncount;
}
const vxlmatrix* hva::matrix(const size_t frame, const size_t section) const
{
return (is_loaded() && frame < frame_count() && section < section_count()) ?
&_totalmatrices[frame * section_count() + section] : nullptr;
}