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
|
#pragma once
#include <atomic>
class cWorld;
/** Generates and lights the spawn area of the world. Runs as a separate thread. */
class cSpawnPrepare
{
public:
cSpawnPrepare(cWorld & a_World, int a_PrepareDistance, std::function<void()> a_PreparationCompletedCallback);
static void PrepareChunks(cWorld & a_World, int a_PrepareDistance, std::function<void()> a_PreparationCompletedCallback = {});
/** Generates a random spawnpoint on solid land by walking chunks and finding their biomes */
static Vector3d GenerateRandomSpawn(cWorld & a_World, int a_PrepareDistance);
protected:
cWorld & m_World;
const int m_TotalChunks;
/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
int m_NumPrepared;
/** 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;
std::function<void()> m_PreparationCompletedCallback;
void PreparedChunkCallback(int a_ChunkX, int a_ChunkZ);
/** Returns if the biome of the given chunk coordinates is a valid spawn candidate. */
static bool IsValidSpawnBiome(cWorld & a_World, int a_ChunkX, int a_ChunkZ);
/** Can the specified coordinates be used as a spawn point?
Returns true if spawn position is valid and sets a_Y to the valid spawn height */
static bool CanSpawnAt(cWorld & a_World, double a_X, double & a_Y, double a_Z);
/** Check if player starting point is acceptable */
static bool CheckPlayerSpawnPoint(cWorld & a_World, int a_PosX, int a_PosY, int a_PosZ);
friend class cSpawnPrepareCallback;
};
|