Skip to content

Commit 4d37a7f

Browse files
committed
Simplify BasicProcessor
1 parent dc36ca0 commit 4d37a7f

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

sg2-core/src/cz/hartrik/sg2/engine/process/BasicProcessor.java

+22-35
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ public void nextCycle() {
6464
for (int cy = verChunkCount - 1; cy >= 0; --cy) {
6565
this.running = runningAll[cy];
6666

67-
// nejvyšší a nejnišší hor. pozice v ch.
68-
final int cyTop = cy * world.getChunkSize();
69-
final int cyBottom = cyTop + world.getChunkSize() - 1;
70-
7167
// zjistí horizontální chunky, které (ne)byly změněny
7268
int runningCount = 0;
7369

@@ -86,8 +82,7 @@ public void nextCycle() {
8682
// elementy zůstali viset ve vzduchu pokud bychom pod nimi
8783
// něco vymazali tak, že by nedošlo ke změně jejich chunku
8884

89-
final boolean test = testChunkFast(cx, cy, cyTop, cyBottom);
90-
if (test) {
85+
if (testChunkFast(chunk)) {
9186
running[cx] = true;
9287
runningCount++;
9388
}
@@ -99,6 +94,10 @@ public void nextCycle() {
9994

10095
updated += runningCount;
10196

97+
// nejvyšší a nejnišší hor. pozice v ch.
98+
int cyTop = cy * world.getChunkSize();
99+
int cyBottom = cyTop + world.getChunkSize() - 1;
100+
102101
iterate(cyTop, cyBottom, runningCount);
103102

104103
// kontrola chunků, které se nezměnily
@@ -109,7 +108,7 @@ public void nextCycle() {
109108
// pořádně otestovat - v jednom kole se totiž nutně nemusí
110109
// změnit vše co může a některé částečky by tak mohly zůstat
111110
// ve vzduchu atd.
112-
if (testChunkFull(cx, cyTop, cyBottom)) {
111+
if (testChunkFull(chunk)) {
113112
// chunk nemůže být uspát - probudíme ho
114113
chunk.change();
115114
}
@@ -124,51 +123,39 @@ public void nextCycle() {
124123
// testování
125124
// -----------------------------------------------------
126125

127-
protected final boolean testChunkFast(
128-
int cx, final int cy,
129-
final int cyTop, final int cyBottom) {
130-
131-
final int cxLeft = cx * world.getChunkSize();
132-
final int cxRight = cxLeft + world.getChunkSize() - 1;
133-
126+
protected final boolean testChunkFast(Chunk chunk) {
134127
// testuje pouze pokud je vedle aktivní chunk
135128

136129
// levá strana
137-
if (cx > 0 && running[cx - 1]) {
138-
for (int y = cyBottom; y >= cyTop; --y)
139-
if (testPoint(cxLeft, y)) return true;
130+
if (chunk.getChunkX() > 0 && running[chunk.getChunkX() - 1]) {
131+
for (int y = chunk.getTopLeftY() + 1; y < chunk.getBottomRightY(); y++)
132+
if (testPoint(chunk.getTopLeftX(), y)) return true;
140133
}
141134

142135
// pravá strana
143-
if (cx < (horChunkCount - 1) && running[cx + 1]) {
144-
for (int y = cyBottom; y >= cyTop; --y)
145-
if (testPoint(cxRight, y)) return true;
136+
if (chunk.getChunkX() < (horChunkCount - 1) && running[chunk.getChunkX() + 1]) {
137+
for (int y = chunk.getTopLeftY() + 1; y < chunk.getBottomRightY(); y++)
138+
if (testPoint(chunk.getBottomRightX(), y)) return true;
146139
}
147140

148141
// horní strana
149-
if (cy > 0 && runningAll[cy - 1][cx]) {
150-
for (int x = cxLeft; x <= cxRight; x++)
151-
if (testPoint(x, cyTop)) return true;
142+
if (chunk.getChunkY() > 0 && runningAll[chunk.getChunkY() - 1][chunk.getChunkX()]) {
143+
for (int x = chunk.getTopLeftX(); x <= chunk.getBottomRightX(); x++)
144+
if (testPoint(x, chunk.getTopLeftY())) return true;
152145
}
153146

154147
// dolní strana
155-
if (cy < (verChunkCount - 1) && runningAll[cy + 1][cx]) {
156-
for (int x = cxLeft; x <= cxRight; x++)
157-
if (testPoint(x, cyBottom)) return true;
148+
if (chunk.getChunkY() < (verChunkCount - 1) && runningAll[chunk.getChunkY() + 1][chunk.getChunkX()]) {
149+
for (int x = chunk.getTopLeftX(); x <= chunk.getBottomRightX(); x++)
150+
if (testPoint(x, chunk.getBottomRightY())) return true;
158151
}
159152

160153
return false;
161154
}
162155

163-
protected final boolean testChunkFull(
164-
final int cx,
165-
final int cyTop, final int cyBottom) {
166-
167-
final int cxLeft = cx * world.getChunkSize();
168-
final int cxRight = cxLeft + world.getChunkSize() - 1;
169-
170-
for (int y = cyBottom; y >= cyTop; --y)
171-
for (int x = cxLeft; x <= cxRight; x++)
156+
protected final boolean testChunkFull(Chunk chunk) {
157+
for (int y = chunk.getTopLeftY(); y <= chunk.getBottomRightY(); y++)
158+
for (int x = chunk.getTopLeftX(); x <= chunk.getBottomRightX(); x++)
172159
if (testPoint(x, y)) return true;
173160

174161
return false;

0 commit comments

Comments
 (0)