private bool TryImmediateSnowUpdate(WeatherSimulationRegion simregion, IServerMapChunk mc, Vec2i chunkCoord, IWorldChunk[] chunksCol) { UpdateSnowLayerChunk dummy = new UpdateSnowLayerChunk() { Coords = chunkCoord }; lock (updateSnowLayerQueue) { if (updateSnowLayerQueue.Contains(dummy)) { return(false); } } double nowTotalHours = ws.api.World.Calendar.TotalHours; if (nowTotalHours - simregion.LastUpdateTotalHours > 1) // Lets wait until WeatherSimulationRegion is done updating { return(false); } UpdateSnowLayerChunk ch = GetSnowUpdate(simregion, mc, chunkCoord, chunksCol); if (ch == null) { return(true); // The only path returning null, if we provided a full set of chunksCol, will be where newCount == 0 } if (ch.SetBlocks.Count == 0) { return(true); } cuba.SetChunks(chunkCoord, chunksCol); processBlockUpdates(mc, ch, cuba); cuba.Commit(); lock (updateSnowLayerQueue) { updateSnowLayerQueue.Enqueue(dummy); } return(true); }
public static void TestSimple() { UniqueQueue <int> queue = new UniqueQueue <int>(); Assert.IsTrue(queue.Enqueue(0)); Assert.IsFalse(queue.Enqueue(0)); Assert.IsTrue(queue.Contains(0)); Assert.AreEqual(queue.Peek(), 0); Assert.AreEqual(queue.Dequeue(), 0); }
public bool IsInUpdateList(MetaDataNode node) { return(updateList.Contains(node)); }
private void Update() { timePassed += Time.deltaTime; timePassed2 += Time.deltaTime; if (timePassed2 >= 0.1) { int count = winds.Count; if (count > 0) { for (int i = 0; i < count; i++) { if (winds.TryDequeue(out var windyNode)) { foreach (var pushable in matrix.Get <PushPull>(windyNode.Position, true)) { float correctedForce = windyNode.WindForce / ( int )pushable.Pushable.Size; if (correctedForce >= AtmosConstants.MinPushForce) { if (pushable.Pushable.IsTileSnap) { byte pushes = (byte)Mathf.Clamp((int)correctedForce / 10, 1, 10); for (byte j = 0; j < pushes; j++) { //converting push to world coords because winddirection is in local coords pushable.QueuePush((transform.rotation * windyNode.WindDirection.To3Int()).To2Int(), Random.Range(( float )(correctedForce * 0.8), correctedForce)); } } else { pushable.Pushable.Nudge(new NudgeInfo { OriginPos = pushable.Pushable.ServerPosition, Trajectory = (Vector2)windyNode.WindDirection, SpinMode = SpinMode.None, SpinMultiplier = 1, InitialSpeed = correctedForce, }); } } } windyNode.WindForce = 0; windyNode.WindDirection = Vector2Int.zero; } } } timePassed2 = 0; } if (timePassed < 0.5) { return; } foreach (MetaDataNode node in hotspots.Values.ToArray()) { if (node.Hotspot != null) { if (node.Hotspot.Process()) { if (node.Hotspot.Volume > 0.95 * node.GasMix.Volume) { for (var i = 0; i < node.Neighbors.Length; i++) { MetaDataNode neighbor = node.Neighbors[i]; if (neighbor != null) { ExposeHotspot(node.Neighbors[i].Position, node.GasMix.Temperature * 0.85f, node.GasMix.Volume / 4); } } } tileChangeManager.UpdateTile(node.Position, TileType.Effects, "Fire"); } else { RemoveHotspot(node); } } } //Here we check to see if chemical fog fx needs to be applied, and if so, add them. If not, we remove them int addFogCount = addFog.Count; if (addFogCount > 0) { for (int i = 0; i < addFogCount; i++) { if (addFog.TryDequeue(out var addFogNode)) { if (!hotspots.ContainsKey(addFogNode.Position)) //Make sure the tile currently isn't on fire. If it is on fire, we don't want to overright the fire effect { tileChangeManager.UpdateTile(addFogNode.Position, TileType.Effects, "PlasmaAir"); } else if (!removeFog.Contains(addFogNode)) //If the tile is on fire, but there is still plasma on the tile, put this tile back into the queue so we can try again { addFog.Enqueue(addFogNode); } } } } //Similar to above, but for removing chemical fog fx int removeFogCount = removeFog.Count; if (removeFogCount > 0) { for (int i = 0; i < removeFogCount; i++) { if (removeFog.TryDequeue(out var removeFogNode)) { if (!hotspots.ContainsKey(removeFogNode.Position)) //Make sure the tile isn't on fire, as we don't want to delete fire effects here { tileChangeManager.RemoveTile(removeFogNode.Position, LayerType.Effects); } //If it's on fire, we don't need to do anything else, as the system managing fire will remove all effects from the tile //after the fire burns out } } } timePassed = 0; }
public bool IsSelected(WeaponIndex index) { WeaponItem item = playerWeapons[index]; return(selectedWeapons.Contains(index) && !(item.Health == 0 && !item.IsAmmo)); }
public void UpdateSnowLayerOffThread(WeatherSimulationRegion simregion, IServerMapChunk mc, Vec2i chunkPos) { #region Tyrons brain cloud // Trick 1: Each x/z coordinate gets a "snow accum" threshold by using a locational random (murmurhash3). Once that threshold is reached, spawn snow. If its doubled, spawn 2nd layer of snow. => Patchy "fade in" of snow \o/ // Trick 2: We store a region wide snow accum value for the ground level and the map ceiling level. We can now interpolate between those values for each Y-Coordinate \o/ // Trick 3: We loop through each x/z block in a separate thread, then hand over "place snow" tasks to the main thread // Trick 4: Lets pre-gen 50 random shuffles for every x/z coordinate of a chunk. Loop through the region chunks, check which one is loaded and select one random shuffle from the list, then iterate over every x/z coord // Trick 5: Snowed over blocks: // - New VSMC util: "Automatically Try to add a snow cover to all horizontal faces" // - New Block property: SnowCoverableShape. // - Block.OnJsonTesselation adds snow adds cover shape to the sourceMesh!! // Trick 6: Turn Cloud Patterns into a "dumb slave system". They are visual information only, so lets make them follow internal mechanisms. // - Create a precipitation perlin noise generator. If the precipitation value goes above or below a certain value, we force the cloud pattern system to adapt to a fitting pattern // => We gain easy to probe, deterministic precipitation values!! // => We gain the ability to do unloaded chunk snow accumulation and unloaded chunk farmland rain-wetness accum // Trick 6 v2.0: // Rain clouds are simply overlaid onto the normal clouds. // Questions: // - Q1: When should it hail now? // - Q2: How is particle size determined? // - Q3: When should there be thunder? // - Q4: How to control the precipitation by command? // A1/A3: What if we read the slope of precipitation change. If there is a drastic increase of rain fall launch a // a. wind + thunder event // b. thunder event // c. rarely a hail event // d. extra rarely thunder + hail event // A2: Particle size is determiend by precipitation intensity // Trick 7 v2.0 // - Hail and Thunder are also triggered by a perlin noise generator. That way I don't need to care about event range. // A4: /weather setprecip [auto or 0..1] // - Q5: How do we overlay rain clouds onto the normal clouds? // Q5a: Will they be hardcoded? Or configurable? // Q5b: How does the overlay work? Lerp? // Q5c: Rain cloud intensity should relate to precip level. // How? Lerp from zero to max rain clouds? Multiple cloud configs and lerp between them? // - A5a: Configurable // A5b: Lerp. // A5c: Single max rain cloud config seems sufficient // TODO: // 1. Rain cloud overlay // 2. Snow accum // 3. Hail, Thunder perlin noise // 4. Done? // Idea 8: // - F**K the region based weather sim. // - Generate clouds patterns like you generate terrain from landforms // - Which is grid based indices, neatly abstracted with LerpedIndex2DMap and nicely shaped with domain warping // - Give it enough padding to ensure domain warping does not go out of bounds // - Every 2-3 minutes regenerate this map in a seperate thread, cloud renderer lerps between old and new map. // - Since the basic indices input is grid based, we can cycle those individually through time // for a future version // Hm. Maybe one noise generator for cloud coverage? // => Gain the ability to affect local temperature based on cloud coverage // Hm. Or maybe one noise generator for each cloud pattern? // => Gain the abillity for small scale and very large scale cloud patterns // Maybe even completely ditch per-region simulation? // => Gain the ability for migrating weather patterns // but then what will determine the cloud pattern? // Region-less Concept: // Take an LCGRandom. Use xpos and zpos+((int)totalDays) / 5 for coords // Iterate over every player // - iterate over a 20x20 chunk area around it (or max view dist + 5 chunks) // - domain warp x/z coords. use those coords to init position seed on lcgrand. get random value // - store in an LerpedWeightedIndex2DMap // Iterate over every cloud tile // - read cloud pattern data from the map // Snow accum needs to take the existing world information into account, i.e. current snow level // We should probably // - Store snow accumulation as a float value in mapchunkdata as Dictionary<BlockPos, float> // - Every 3 seconds or so, "commit" that snow accum into actual snow layer blocks, i.e. if accum >= 1 then add one snow layer and do accum-=1 #endregion UpdateSnowLayerChunk ch = new UpdateSnowLayerChunk() { Coords = chunkPos }; // Lets wait until we're done with the current job for this chunk if (updateSnowLayerQueue.Contains(ch)) { return; } double nowTotalHours = ws.api.World.Calendar.TotalHours; if (nowTotalHours - simregion.LastUpdateTotalHours > 1) // Lets wait until WeatherSimulationRegion is done updating { return; } byte[] data = mc.GetData("lastSnowAccumUpdateTotalHours"); double lastSnowAccumUpdateTotalHours = data == null ? 0 : SerializerUtil.Deserialize <double>(data); double startTotalHours = lastSnowAccumUpdateTotalHours; int reso = WeatherSimulationRegion.snowAccumResolution; SnowAccumSnapshot sumsnapshot = new SnowAccumSnapshot() { //SumTemperatureByRegionCorner = new API.FloatDataMap3D(reso, reso, reso), SnowAccumulationByRegionCorner = new API.FloatDataMap3D(reso, reso, reso) }; float[] sumdata = sumsnapshot.SnowAccumulationByRegionCorner.Data; if (simregion == null) { return; } // Can't grow bigger than one full snow block float max = ws.GeneralConfig.SnowLayerBlocks.Count + 0.5f; int len = simregion.SnowAccumSnapshots.Length; int i = simregion.SnowAccumSnapshots.Start; int newCount = 0; lock (WeatherSimulationRegion.lockTest) { while (len-- > 0) { SnowAccumSnapshot hoursnapshot = simregion.SnowAccumSnapshots[i]; i = (i + 1) % simregion.SnowAccumSnapshots.Length; if (hoursnapshot == null || lastSnowAccumUpdateTotalHours >= hoursnapshot.TotalHours) { continue; } float[] snowaccumdata = hoursnapshot.SnowAccumulationByRegionCorner.Data; for (int j = 0; j < snowaccumdata.Length; j++) { sumdata[j] = GameMath.Clamp(sumdata[j] + snowaccumdata[j], -max, max); } lastSnowAccumUpdateTotalHours = Math.Max(lastSnowAccumUpdateTotalHours, hoursnapshot.TotalHours); newCount++; } } if (newCount == 0) { return; } bool ignoreOldAccum = false; if (lastSnowAccumUpdateTotalHours - startTotalHours >= sapi.World.Calendar.DaysPerYear * sapi.World.Calendar.HoursPerDay) { ignoreOldAccum = true; } ch = UpdateSnowLayer(sumsnapshot, ignoreOldAccum, mc, chunkPos); if (ch != null) { //Console.WriteLine("{0} snaps used for {1}/{2}", newCount, chunkPos.X, chunkPos.Y); ch.LastSnowAccumUpdateTotalHours = lastSnowAccumUpdateTotalHours; ch.Coords = chunkPos.Copy(); lock (updateSnowLayerQueueLock) { updateSnowLayerQueue.Enqueue(ch); } } }