-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlimeArea.cpp
112 lines (92 loc) · 3.09 KB
/
SlimeArea.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "GlobalSeedMatrix.cpp"
#include "Util.cpp"
#include <experimental/simd>
namespace stdx = std::experimental;
//storage[z][x]
template<uint32_t farmHeight>
class SlimeArea //silly algorithm to make everything faster
{
public:
SlimeArea(const GlobalSeedMatrix& matrix, const uint32_t matrixX, const uint32_t matrixZ):
matrix(matrix),
currentMatrixX(matrixX),
currentMatrixZ(matrixZ)
{
for(uint32_t j = 0; j < 16; j++)
for(uint32_t i = 0; i < 16; i++)
{
const bool isSlimeChunk = Util::isSlimeChunk(matrix, matrixX+i, matrixZ+j);
const bool isWithinSphere = Util::isChunkWithinSphere(i, j, farmHeight);
storage[j][i] = isSlimeChunk;
totalScore+=(isSlimeChunk&isWithinSphere ? Util::getChunkScore(i, j, farmHeight) : 0);
}
}
uint32_t getTotalScore() const
{
return totalScore;
}
void shiftToPositiveX()
{
substractFromScore();
calculateNewColumn();
addToScore();
incrementGenerateToX();
}
private:
const GlobalSeedMatrix& matrix;
bool storage[16][16];
uint32_t totalScore = 0;
uint32_t generateToX = 0;
uint32_t currentMatrixX;
const uint32_t currentMatrixZ;
void calculateNewColumn()
{
//slime seed
const uint64_t xValue = matrix.getXValue(currentMatrixX+16);
stdx::fixed_size_simd<uint64_t, 16> seed([&](const uint32_t j)
{
return matrix.getZValue(currentMatrixZ+j);
});
seed+=xValue;
seed^=0x3ad8025f;
//javarandom seed
seed^=0x5deece66dULL;
seed&=0xffffffffffffULL;
for(uint32_t j = 0; j < 16; j++)
storage[j][generateToX] = (JavaRandom::nextIntForRawSeed(seed[j], 10) == 0);
currentMatrixX++;
}
void incrementGenerateToX()
{
generateToX++;
generateToX = (generateToX >= 16 ? generateToX-16 : generateToX);
}
bool getFromStorageWithShiftedIndex(const uint32_t x, const uint32_t z)
{
const uint32_t i = generateToX+x;
return storage[z][(i >= 16 ? i-16 : i)];
}
template<uint32_t i = 0>
void substractFromScore()
{
const uint32_t score = Util::getChunkScore(i%8, i/8, farmHeight);
const uint32_t lastScore = Util::getChunkScore(i%8-1, i/8, farmHeight);
const int32_t diff = (i%8 == 0 ? score : score-lastScore);
if constexpr(diff != 0)
totalScore-=diff*getFromStorageWithShiftedIndex(i%8, i/8);
if constexpr(i+1 < 128)
substractFromScore<i+1>();
}
template<uint32_t i = 0>
void addToScore()
{
const uint32_t score = Util::getChunkScore(i%8+9, i/8, farmHeight);
const uint32_t lastScore = Util::getChunkScore(i%8+8, i/8, farmHeight);
const int32_t diff = score-lastScore;
const uint32_t I = (i%8+9 == 16 ? 0 : i%8+9);
if constexpr(diff != 0)
totalScore-=diff*getFromStorageWithShiftedIndex(I, i/8);
if constexpr(i+1 < 128)
addToScore<i+1>();
}
};