/// <summary> /// Returns the CacheData at a specific point from the grid array. Does not /// interfere with the savedChunk data (loading or saving). Throws an /// IndexOutOfRangeException if the specified chunk coordinates are out /// of the range of the grid. /// </summary> /// <param name="chunkX"></param> /// <param name="chunkZ"></param> /// <returns></returns> private CacheData this[int chunkX, int chunkZ] { get { lock (CacheLock) { ChunkCoordinate coord = new ChunkCoordinate(chunkX, chunkZ); if (savedChunkData.ContainsKey(coord)) return savedChunkData[coord]; if (!IsInGridRange(chunkX, chunkZ)) throw new IndexOutOfRangeException(); int xIndex = Numerical.IntMod(chunkX, Width); int zIndex = Numerical.IntMod(chunkZ, Height); return cache[xIndex, zIndex]; } } set { lock (CacheLock) { if (!IsInGridRange(chunkX, chunkZ)) throw new IndexOutOfRangeException(); int xIndex = Numerical.IntMod(chunkX, Width); int zIndex = Numerical.IntMod(chunkZ, Height); cache[xIndex, zIndex] = value; } } }
public bool Equals(ChunkCoordinate other) { return other.X == this.X && other.Z == this.Z; }
public void RemoveEntityFromCache(Entity e, ChunkCoordinate chunkMin, ChunkCoordinate chunkMax) { for (int x = chunkMin.X; x <= chunkMax.X; x++) { for (int z = chunkMin.Z; z <= chunkMax.Z; z++) { Cache.RemoveEntity(e, x, z); } } }
public IEnumerable<Entity> CachedEntities(ChunkCoordinate chunkMin, ChunkCoordinate chunkMax) { for (int x = chunkMin.X; x <= chunkMax.X; x++) { for (int z = chunkMin.Z; z <= chunkMax.Z; z++) { foreach (Entity e in Cache.CachedEntities(x, z)) yield return e; } } }
public void AddEntityToCache(Entity e, ChunkCoordinate chunkMin, ChunkCoordinate chunkMax) { for (int x = chunkMin.X; x <= chunkMax.X; x++) { for (int z = chunkMin.Z; z <= chunkMax.Z; z++) { Cache.AddEntity(e, x, z); } } }
public override void Update(GameTime gametime) { if (WantVisible) { //no physics here! //base.physicsUpdate(gametime); // :)~~ int chunkX, chunkZ; Block lookAtBlock; Point3 blockPosition; Face faceTouched; bool successful; WorldManager.BlockLookedAt(TestDistance, true, true, out lookAtBlock, out chunkX, out chunkZ, out blockPosition, out faceTouched, out successful); if (successful) { HasFixedPosition = true; switch (faceTouched) { case Face.LEFT: blockPosition.X--; break; case Face.RIGHT: blockPosition.X++; break; case Face.TOP: blockPosition.Y++; break; case Face.BOTTOM: blockPosition.Y--; break; case Face.FRONT: blockPosition.Z--; break; case Face.BACK: blockPosition.Z++; break; default: throw new NotImplementedException(); } fixedChunkCoordinate = new ChunkCoordinate(chunkX, chunkZ); fixedBlockCoordinate = blockPosition; HelperMethods.FixCoordinates(ref fixedChunkCoordinate, ref fixedBlockCoordinate); this.Position = new WorldPosition(fixedChunkCoordinate.X, fixedChunkCoordinate.Z, fixedBlockCoordinate.X, fixedBlockCoordinate.Y, fixedBlockCoordinate.Z); } else { HasFixedPosition = false; } } }