/// <summary> /// Copies the specified amount of lights contained from the specified collection, /// but preserves the lights already present in this collection. /// </summary> /// <param name="copyFrom">Light collection to copy from</param> /// <param name="copyCount">Number of lights to copy</param> public void CopyLights(ILightCollection copyFrom, int copyCount) { if (copyCount > copyFrom.LightCount) { throw new ArgumentOutOfRangeException("Cannot copy more lights than contained in the light collection to copy from."); } if (copyCount > copyFrom.MaxLights) { copyCount = copyFrom.LightCount; } //Check if we need to resize if (copyCount + _lightCount > _lights.Length) { Light[] temp = new Light[(copyCount + _lightCount) * 2]; Array.Copy(_lights, temp, _lightCount); Array.Clear(_lights, 0, _lightCount); _lights = temp; } for (int i = _lightCount, j = 0; j < copyCount; i++, j++) { _lights[i] = copyFrom[j]; } _lightCount += copyCount; _refreshShader = true; if (_spatial != null) { _spatial.PropagateDirtyDown(DirtyMark.Lighting); } }
/// <summary> /// Copies all the lights contained from the specified collection, /// but preserves the lights already present in this collection. /// </summary> /// <param name="copyFrom">Light collection to copy from</param> public void CopyLights(ILightCollection copyFrom) { int copyCount = copyFrom.LightCount; //Check if we need to resize if (copyCount + _lightCount > _lights.Length) { Light[] temp = new Light[(copyCount + _lightCount) * 2]; Array.Copy(_lights, temp, _lightCount); Array.Clear(_lights, 0, _lightCount); _lights = temp; } for (int i = _lightCount, j = 0; j < copyCount; i++, j++) { _lights[i] = copyFrom[j]; } _lightCount += copyCount; _refreshShader = true; if (_spatial != null) { _spatial.PropagateDirtyDown(DirtyMark.Lighting); } }
/// <summary> /// Sets the specified lights. /// </summary> /// <param name="lights">The lights to copy.</param> /// <param name="copyLights">if set to <c>true</c> [copy lights].</param> public void Set(ILightCollection lights, bool copyLights) { _maxLights = lights.MaxLights; _globalAmbient = lights.GlobalAmbient; _isEnabled = lights.IsEnabled; _refreshShader = true; if (copyLights) { //Clear the array Array.Clear(_lights, 0, _lightCount); //If the collection to copy from has more lights than we can carry, expand array to fit its light count if (lights.LightCount > _lights.Length) { _lights = new Light[lights.LightCount * 2]; } //Copy lights for (int i = 0; i < lights.LightCount; i++) { _lights[i] = lights[i]; } _lightCount = lights.LightCount; //New lights, update children if (_spatial != null) { _spatial.PropagateDirtyDown(DirtyMark.Lighting); } } }
public Level(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { m_transform = Matrix4.Identity; m_timeMachine = new TimeMachine(); m_tileMap = new TileMap(this, minX, minY, minZ, maxX, maxY, maxZ); m_entities = new List <Entity>(); m_entityCollection = new EntityCollection(this); m_info = new LevelInfo(); m_depthComparer = new EntityDistanceComparer(); m_depthSortedEntities = new List <Entity>(); m_ambientLight = new AmbientLight(new Vector3(0.5f, 0.5f, 0.5f)); m_ambientLight.Active = true; m_skyLight = new DirectionalLight(new Vector3(0.6f, -1.0f, -0.6f), new Vector3(0.5f, 0.5f, 0.5f)); m_skyLight.Active = true; m_skyLight2 = new DirectionalLight(-Vector3.UnitY, Vector3.Zero); m_skyLight2.Active = false; m_pointLights = new List <PointLight>(); m_lightCollection = new LightCollection(this); m_telepadDirectory = new TelepadDirectory(); m_hintDirectory = new HintDirectory(); Visible = true; Random = new Random(); m_flatOpaqueEffect = new FlatEffectInstance(); m_flatCutoutEffect = new FlatCutoutEffectInstance(); m_litOpaqueEffect = new LitEffectInstance(RenderPass.Opaque); m_litCutoutEffect = new LitEffectInstance(RenderPass.Cutout); m_litTranslucentEffect = new LitEffectInstance(RenderPass.Translucent); m_shadowEffect = new ShadowEffectInstance(); m_particles = new ParticleManager(this); }
public ReadOnlyKeyedCollection(string[] keys, ILightCollection <T> items) { _coll = new KeyedCollection <T>(keys, items.GetItems()); }
public ReadOnlyKeyedCollection(ILightCollection <T> collection) { string[] keys = CreateFreeKeys(collection.Count); _coll = new KeyedCollection <T>(keys, collection.GetItems()); }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="items"></param> public virtual void InsertRange(int index, ILightCollection <T> items) { InsertRange(index, items.GetItems()); }
/// <summary> /// Add a range of Items to this collection /// </summary> /// <param name="items">An ILightCollection<T> derived collection</param> public virtual void AddRange(ILightCollection <T> items) { InsertRange(this._count, items.GetItems()); }
/// <summary> /// Constructor of LightCollection /// </summary> /// <param name="coll">The collection from where copy items</param> public LightCollection(ILightCollection <T> coll) { Init(coll.Count); this.AddRange(coll.GetItems()); }
/// <summary> /// Execute the logic for the given material and renderable (usually a Mesh). /// </summary> /// <param name="material">Material that is executing the logic.</param> /// <param name="renderer">Renderer used for drawing</param> /// <param name="renderable">Renderable that owns the Material</param> public override void Execute(Material material, IRenderer renderer, IRenderable renderable) { if (renderable == null || renderer == null || material == null) { return; } if (IsEnabled) { if (_needsRefresh) { CacheParameters(material.Effect); } //We assume this comes to us already sorted. ILightCollection lights = renderable.WorldLights; //Return if the collection doesn't need to update us or there are no lights to update with if (!lights.RefreshShader || lights.LightCount == 0) { //Set to zero if (_cachedLightCount != null) { _cachedLightCount.SetValue(0); } return; } //Tell the collection not to update us until it changes lights.RefreshShader = false; //Set the global ambient value if (_cachedGlobalAmbient != null) { _cachedGlobalAmbient.SetValue(lights.GlobalAmbient.ToVector3()); } //Update the actual light list if (_cachedLightList != null) { //If we're dealing with a single parameter and not an array... if (_cachedLightList.Elements.Count == 0) { SetLight(lights[0], _cachedLightList); return; } //Ensure the max light counts match, if the element count is less than //the collection's max lights, use that, otherwise use the collection's int numLights = 0; if (lights.LightCount <= _cachedLightList.Elements.Count) { numLights = lights.LightCount; } else if (lights.LightCount > _cachedLightList.Elements.Count) { numLights = _cachedLightList.Elements.Count; } //Set the number of lights if (_cachedLightCount != null) { _cachedLightCount.SetValue(numLights); } //Go through each light, and update it to the shader for (int i = 0; i < numLights; i++) { Light light = lights[i]; IEffectParameter lParam = _cachedLightList.Elements[i]; SetLight(light, lParam); } } } }
public StringCollection(ILightCollection <string> collection) { _coll = new LightCollection <string>(collection); }
public void InsertRange(int index, ILightCollection <string> items) { _coll.InsertRange(index, items); }
public void AddRange(ILightCollection <string> items) { _coll.AddRange(items); }
public ReadOnlyCollection(ILightCollection <T> collection) { _coll = (LightCollection <T>)collection; // new LightCollection<T>(collection); }
/// <summary> /// Resets the collection's data and copies the input light collection's data. /// </summary> /// <param name="lights">Light collection to copy from</param> public void Set(ILightCollection lights) { Set(lights, true); }