public GameObject ChunkObjectAt(ChunkPoint point) { if (_goCache.ContainsKey(point)) { return(_goCache[point]); } return(null); }
void Start() { var origin = new ChunkPoint(0, 0); var corner = new ChunkPoint(viewDistance, viewDistance); var corner2 = new ChunkPoint(-viewDistance, -viewDistance); maxMagnitude = (origin - corner2).magnitude; Debug.Log((origin - corner).magnitude); }
public Chunk ChunkAt(ChunkPoint point, bool forceLoad = true) { if (_chunks.ContainsKey(point)) { return(_chunks[point]); } if (!forceLoad) { return(null); } var c = LoadChunkAt(point); return(c); }
public bool WithinRange(Vector3 position, Chunk chunk) { if (chunk == null) { return(false); } ChunkPoint point = chunk.Position; var cx = (int)(position.x / chunkSize); var cz = (int)(position.z / chunkSize); var playerPoint = new ChunkPoint(cx, cz); var difference = playerPoint - point; return(difference.magnitude <= maxMagnitude); }
public Chunk LoadChunkAt(ChunkPoint point) { var x = point.X; var z = point.Z; var origin = new Vector3(x * voxelSize * chunkSize, 0.0f, z * voxelSize * chunkSize); Chunk c; int index = 0; do { c = chunkProviderQueue[index].LoadChunkAt(origin); index++; } while (c == null && index < chunkProviderQueue.Count); if (c != null) { Debug.Log("Loaded chunk " + point); } return(c); }
void Update() { //Ensure the chunks for all players are loaded foreach (var player in players) { var point = VectorToPoint(player.transform.position); for (int xadd = (int)-viewDistance; xadd < viewDistance; xadd++) { for (int zadd = (int)-viewDistance; zadd < viewDistance; zadd++) { var pointToCheck = new ChunkPoint(point.X + xadd, point.Z + zadd); //First query to see if this chunk exists var c = ChunkAt(pointToCheck, false); //If this chunk doesn't exist, then load it and spawn the game object if (c == null) { //1. First frame will load it into the job queue, but return null //2. Second frame will check the job status, and if its done, return the chunk, otherwise null //3. Thrid frame will check the job status, and if its done return the chunk, otherwise null //.. //.. c = LoadChunkAt(pointToCheck); //Ensure the chunk was loaded/generated successfully if (c != null) { //Finally, spawn the chunk SpawnChunk(c); } } } } } }
public Vector3 PointToOrigin(ChunkPoint point) { return(new Vector3(point.X * voxelSize * chunkSize, 0.0f, point.Z * voxelSize * chunkSize)); }
if (hasMeshData && frustum.BoxInFrustum(new BoundingBox(ChunkPoint, ChunkExtents))) {