/* * /// <summary> * /// Contains for each voxel, the type for which oncreated has been called * /// WARNING: this way of doing lifetime makes that when changing object types, they only come into correct existence on the next frame * /// This means that changing the type of a voxel and then directly manipulating it can cause problems!! * /// </summary> * private Dictionary<IVoxel, IGameVoxelType> initializedTypes = new Dictionary<IVoxel, IGameVoxelType>(); * private void simulateCreateAndDestroy() * { * var gameVoxels = changedVoxels.Cast<GameVoxel>().ToArray(); * changedVoxels.Clear(); // Clear so that we capture change events from within the oncreated and ondestroyed events * gameVoxels.ForEach(v => * { * IGameVoxelType current = null; * initializedTypes.TryGetValue(v, out current); * if (current == v.Data.Type) return;//No change * if (current != null && current.ReceiveCreationEvents) * current.OnDestroyed(v); * * if (v.Data.Type.ReceiveCreationEvents) v.Data.Type.OnCreated(v); * * initializedTypes[v] = v.Data.Type; * * }); * }*/ private void simulatePerVoxelTick() { world.ForEach((v, p) => { if (v.Type == null) { return; } v.Type.Tick(v); }); }
private void normalizeWorld() { world.ForEach((voxel, _) => voxel.Data.Height = (float)Math.Floor(voxel.Data.Height)); }