public void HashCodeCorrectlyCreated(int ax, int ay) { Vec2i a = new Vec2i(ax, ay); int hashCode = ax ^ ay; Assert.True(a.GetHashCode() == hashCode); }
/// <summary> /// Loads all chunks within a square of size 2*radius centred on the player /// </summary> /// <param name="middle"></param> /// <param name="radius"></param> public void LoadChunks(Vec2i middle, int radius, bool forceLoad) { Debug.BeginDeepProfile("load_chunks"); //We define a list of chunks to unload List <Vec2i> toUnload = new List <Vec2i>(); HashSet <int> currentlyLoadedH = new HashSet <int>(); lock (LoadedChunksLock) { //A list containing all the chunks currently loaded foreach (KeyValuePair <Vec2i, LoadedChunk2> kvp in LoadedChunks) { int distSqr = middle.QuickDistance(kvp.Key); if (distSqr > radius * radius) { toUnload.Add(kvp.Key); } currentlyLoadedH.Add(kvp.Key.GetHashCode()); } } lock (ToGetLoadedChunksLOCK) { foreach (KeyValuePair <ChunkData, int> kvp in ToGetLoadedChunks) { currentlyLoadedH.Add(kvp.Key.Position.GetHashCode()); } } foreach (Vec2i v in ChunkLoader.GetCurrentlyLoadingChunks()) { currentlyLoadedH.Add(v.GetHashCode()); } //We iterate each chunk too far from the player, and unload it foreach (Vec2i v in toUnload) { UnloadChunkSafe(v); //UnloadChunk(v); } LoadedChunksCentre = middle; Debug.EndDeepProfile("load_chunks"); Debug.BeginDeepProfile("load_chunks1"); //We now iterate the position of each chunk we require for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { //Check if the requested position is inside world bounds if (x + middle.x < 0 || x + middle.x >= World.WorldSize - 1 || z + middle.z < 0 || z + middle.z >= World.WorldSize - 1) { continue; } Vec2i pos = new Vec2i(x + middle.x, z + middle.z); int distSqr = middle.QuickDistance(pos); if (distSqr > radius * radius) { continue; } int lod = CalculateLOD(distSqr); int posHash = pos.GetHashCode(); //if our currently loaded does not contain the position, we must generate it if (!currentlyLoadedH.Contains(posHash)) { //Attempt to get the chunk data ChunkData cd = GetChunk(pos); if (cd == null) { // Debug.Log("Chunk at " + pos + " was null"); continue; } lock (ToGetLoadedChunksLOCK) { ToGetLoadedChunks.Add(cd, lod); } //Load the entities for this chunk //TODO - check this doesn't cause issues with entities loading before chunks? //ChunkLoader.LoadChunk(cd); } else if (toUnload.Contains(pos)) { //We check if 'toUnload' contains this position (this should always happen if the chunk //isn't already loaded. //We then remove it from this list, as this list will define which chunks need to be unloaded. toUnload.Remove(pos); } else { //If the chunk is loaded, we get it and set its LOD - this ensures it will update if required LoadedChunk2 lc = GetLoadedChunk(pos); lc.SetLOD(lod); } } } Debug.BeginDeepProfile("load_chunks1"); }
public void SetExternalEntrancePos(Vec2i v) { ExternalEntrancePos = v; SetSubworldID(v.GetHashCode()); }
public Rock(Vec2i worldPosition, float rockSize = 1) : base(worldPosition, null, null) { RockSize = rockSize; SetRandom(new GenerationRandom(worldPosition.GetHashCode() + 13)); }
public override int GetHashCode() { return(position.GetHashCode() + Width.GetHashCode() + Height.GetHashCode()); }