MCPcopy Create free account
hub / github.com/cuberite/cuberite / Execute

Method Execute

src/Generating/ChunkGenerator.cpp:193–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191
192
193void cChunkGenerator::Execute(void)
194{
195 // To be able to display performance information, the generator counts the chunks generated.
196 // When the queue gets empty, the count is reset, so that waiting for the queue is not counted into the total time.
197 int NumChunksGenerated = 0; // Number of chunks generated since the queue was last empty
198 clock_t GenerationStart = clock(); // Clock tick when the queue started to fill
199 clock_t LastReportTick = clock(); // Clock tick of the last report made (so that performance isn't reported too often)
200
201 while (!m_ShouldTerminate)
202 {
203 cCSLock Lock(m_CS);
204 while (m_Queue.empty())
205 {
206 if ((NumChunksGenerated > 16) && (clock() - LastReportTick > CLOCKS_PER_SEC))
207 {
208 LOG("Chunk generator performance: %.2f ch/s (%d ch total)",
209 (double)NumChunksGenerated * CLOCKS_PER_SEC/ (clock() - GenerationStart),
210 NumChunksGenerated
211 );
212 }
213 cCSUnlock Unlock(Lock);
214 m_Event.Wait();
215 if (m_ShouldTerminate)
216 {
217 return;
218 }
219 NumChunksGenerated = 0;
220 GenerationStart = clock();
221 LastReportTick = clock();
222 }
223
224 if (m_Queue.empty())
225 {
226 // Sometimes the queue remains empty
227 // If so, we can't do any front() operations on it!
228 continue;
229 }
230
231 cChunkCoords coords = m_Queue.front(); // Get next coord from queue
232 m_Queue.erase( m_Queue.begin() ); // Remove coordinate from queue
233 bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT);
234 Lock.Unlock(); // Unlock ASAP
235 m_evtRemoved.Set();
236
237 // Display perf info once in a while:
238 if ((NumChunksGenerated > 16) && (clock() - LastReportTick > 2 * CLOCKS_PER_SEC))
239 {
240 LOG("Chunk generator performance: %.2f ch/s (%d ch total)",
241 (double)NumChunksGenerated * CLOCKS_PER_SEC / (clock() - GenerationStart),
242 NumChunksGenerated
243 );
244 LastReportTick = clock();
245 }
246
247 // Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set
248 if ((coords.m_ChunkY == 0) && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ))
249 {
250 LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ);

Callers

nothing calls this directly

Calls 9

LOGFunction · 0.85
emptyMethod · 0.80
beginMethod · 0.80
sizeMethod · 0.80
UnlockMethod · 0.80
WaitMethod · 0.45
SetMethod · 0.45
IsChunkValidMethod · 0.45
HasChunkAnyClientsMethod · 0.45

Tested by

no test coverage detected