forked from kittybupu/openVCB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenVCB.cpp
More file actions
99 lines (79 loc) · 2.54 KB
/
openVCB.cpp
File metadata and controls
99 lines (79 loc) · 2.54 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Code for mostly misc stuff.
#include "openVCB.h"
//extern "C" void openVCB_FreeErrorArray() noexcept;
namespace openVCB {
/****************************************************************************************/
/* Paranoia. */
static_assert(sizeof(InkState) == 4 && offsetof(InkState, logic) == 3);
static_assert(sizeof(InkPixel) == 4 && offsetof(InkPixel, meta) == 2);
static_assert(sizeof(SparseMat) == 24);
static_assert(sizeof(InstrumentBuffer) == 16);
static_assert(sizeof(SimulationResult) == 8);
static_assert(sizeof(LatchInterface) == 284);
static_assert(sizeof(VMemWrapper) == sizeof(void *));
static_assert(sizeof(int) == 4);
void Project::toggleLatch(glm::ivec2 const pos)
{
if (pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y >= height)
return;
int const gid = indexImage[pos.x + pos.y * width];
toggleLatch(gid);
}
void Project::toggleLatch(int const gid)
{
if (SetOff(stateInks[gid]) != Ink::Latch)
return;
states[gid].activeInputs = 1;
if (states[gid].visited)
return;
states[gid].visited = true;
updateQ[0][qSize++] = gid;
}
Project::Project(int64_t const seed, bool const vmemIsBytes)
: vmemIsBytes(vmemIsBytes)
{
if (seed > 0 && seed <= UINT32_MAX)
random = RandomBitProvider{static_cast<uint32_t>(seed)};
}
Project::~Project()
{
if (states_is_native)
delete[] states;
delete[] originalImage;
delete[] indexImage;
delete[] decoration[0];
delete[] decoration[1];
delete[] decoration[2];
delete[] writeMap.ptr;
delete[] writeMap.rows;
delete[] stateInks;
delete[] updateQ[0];
delete[] updateQ[1];
delete[] lastActiveInputs;
delete error_messages;
//::openVCB_FreeErrorArray();
}
std::pair<Ink, int> Project::sample(glm::ivec2 const pos) const
{
if (pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y >= height)
return {Ink::None, -1};
int idx = pos.x + pos.y * width;
Ink type = image[idx].ink;
idx = indexImage[idx];
if (type == Ink::Cross)
return {Ink::Cross, idx};
if (idx == -1)
return {Ink::None, -1};
type = (type & 0x7F) | (states[idx].logic & 0x80);
return {type, idx};
}
void Project::addBreakpoint(int const gid)
{
// breakpoints[gid] = states[gid].logic;
}
void Project::removeBreakpoint(int const gid)
{
// breakpoints.erase(gid);
}
/****************************************************************************************/
} // namespace openVCB