@@ -64,10 +64,6 @@ public void nextCycle() {
64
64
for (int cy = verChunkCount - 1 ; cy >= 0 ; --cy ) {
65
65
this .running = runningAll [cy ];
66
66
67
- // nejvyšší a nejnišší hor. pozice v ch.
68
- final int cyTop = cy * world .getChunkSize ();
69
- final int cyBottom = cyTop + world .getChunkSize () - 1 ;
70
-
71
67
// zjistí horizontální chunky, které (ne)byly změněny
72
68
int runningCount = 0 ;
73
69
@@ -86,8 +82,7 @@ public void nextCycle() {
86
82
// elementy zůstali viset ve vzduchu pokud bychom pod nimi
87
83
// něco vymazali tak, že by nedošlo ke změně jejich chunku
88
84
89
- final boolean test = testChunkFast (cx , cy , cyTop , cyBottom );
90
- if (test ) {
85
+ if (testChunkFast (chunk )) {
91
86
running [cx ] = true ;
92
87
runningCount ++;
93
88
}
@@ -99,6 +94,10 @@ public void nextCycle() {
99
94
100
95
updated += runningCount ;
101
96
97
+ // nejvyšší a nejnišší hor. pozice v ch.
98
+ int cyTop = cy * world .getChunkSize ();
99
+ int cyBottom = cyTop + world .getChunkSize () - 1 ;
100
+
102
101
iterate (cyTop , cyBottom , runningCount );
103
102
104
103
// kontrola chunků, které se nezměnily
@@ -109,7 +108,7 @@ public void nextCycle() {
109
108
// pořádně otestovat - v jednom kole se totiž nutně nemusí
110
109
// změnit vše co může a některé částečky by tak mohly zůstat
111
110
// ve vzduchu atd.
112
- if (testChunkFull (cx , cyTop , cyBottom )) {
111
+ if (testChunkFull (chunk )) {
113
112
// chunk nemůže být uspát - probudíme ho
114
113
chunk .change ();
115
114
}
@@ -124,51 +123,39 @@ public void nextCycle() {
124
123
// testování
125
124
// -----------------------------------------------------
126
125
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 ) {
134
127
// testuje pouze pokud je vedle aktivní chunk
135
128
136
129
// 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 ;
140
133
}
141
134
142
135
// 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 ;
146
139
}
147
140
148
141
// 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 ;
152
145
}
153
146
154
147
// 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 ;
158
151
}
159
152
160
153
return false ;
161
154
}
162
155
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 ++)
172
159
if (testPoint (x , y )) return true ;
173
160
174
161
return false ;
0 commit comments