summaryrefslogtreecommitdiffstats
path: root/src/SpawnPrepare.h
blob: 1c7a42b2f779f73fbf3af16c8902cf49214c281f (plain) (blame)
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

#pragma once

#include <atomic>

class cWorld;



/** Generates and lights the spawn area of the world. Runs as a separate thread. */
class cSpawnPrepare
{

public:
	static void PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance);

protected:
	cWorld & m_World;
	int m_SpawnChunkX;
	int m_SpawnChunkZ;
	int m_PrepareDistance;

	/** The index of the next chunk to be queued in the lighting thread. */
	int m_NextIdx;

	/** The maximum index of the prepared chunks. Queueing stops when m_NextIdx reaches this number. */
	int m_MaxIdx;

	/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
	std::atomic<int> m_NumPrepared;

	/** Event used to signal that the preparation is finished. */
	cEvent m_EvtFinished;

	/** The timestamp of the last progress report emitted. */
	std::chrono::steady_clock::time_point m_LastReportTime;

	/** Number of chunks prepared when the last progress report was emitted. */
	int m_LastReportChunkCount;

	cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx);

	void PreparedChunkCallback(int a_ChunkX, int a_ChunkZ);

	/** Decodes the index into chunk coords. Provides the specific chunk ordering. */
	void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ);

	friend class cSpawnPrepareCallback;

};