-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoxler.h
More file actions
69 lines (53 loc) · 1.54 KB
/
Copy pathVoxler.h
File metadata and controls
69 lines (53 loc) · 1.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
#pragma once
#include "Poxel.h"
#include <amp.h>
using namespace Concurrency;
Poxel* poxels = static_cast<Poxel*>(malloc(px * py * sizeof(Poxel)));
void ensureDefaults() {
for (unsigned int i = 0; i < px * py; i++)
poxels[i].setDefault();
}
void doBrushDelete(unsigned int x, unsigned int y) {
for (unsigned int _x = x - brushSize, _y = y - brushSize; _y < y + brushSize;) {
if (_x >= 0 && _x < px && _y >= 0 && _y < py) {
poxels[_x + ((py - _y) * px)] = Poxel();
}
_x++;
if (_x == x + brushSize) { _x = x - brushSize; _y++; }
}
}
void doBrushPlace(unsigned int x, unsigned int y, Poxel pox) {
for (unsigned int _x = x - brushSize, _y = y - brushSize; _y < y + brushSize;) {
if (_x >= 0 && _x < px && _y >= 0 && _y < py) {
Poxel p(pox);
p.enabled = true;
poxels[_x + ((py - _y) * px)] = p;
}
_x++;
if (_x == x + brushSize) { _x = x - brushSize; _y++; }
}
}
completion_future processTick(array_view<Color, 3> rgbView, bool bufferSwitch) {
Color _bgColor = bgColor;
array_view<Poxel, 2> poxel(py, px, poxels);
if (useGPU)
parallel_for_each(
poxel.extent,
[=](index<2> idx) restrict(amp) {
if (poxel[idx].enabled) {
poxel[idx].doStep(poxel, rgbView, idx, bufferSwitch);
}
else rgbView[bufferSwitch][idx] = _bgColor;
}
);
else
for (unsigned int y = 0, x = 0; y < py;) {
if (poxel[y][x].enabled) {
poxel[y][x].doStep(poxel, rgbView, index<2>(y, x), bufferSwitch);
}
//else rgbView[bufferSwitch][y][x] = _bgColor;
x++;
if (x == px) { x = 0; y++; }
}
return poxel.synchronize_async();
}