public static void CheckLights() { foreach (Item item in World.Items.Values) { if (item is BaseLight && item.ParentEntity == null) { BaseLight light = item as BaseLight; int currentHour, currentMinute; Clock.GetTime(light.Map, light.X, light.Y, out currentHour, out currentMinute); if (currentHour > Settings.IgniteHour || currentHour < Settings.DouseHour) { light.Ignite(); } else if (currentHour > Settings.DouseHour || currentHour < Settings.IgniteHour) { light.Douse(); } } } Timer.DelayCall(System.TimeSpan.FromMinutes(Settings.CheckInterval), delegate { CheckLights(); }); }
public BaseMaterial() { _ambientColor = Color.White.ToVector3(); _ambientIntensity = 0.75f; _diffuseColor = Color.White.ToVector3(); _diffuseIntensity = 0.75f; _effect = null; _effectName = String.Empty; _effectLoaded = false; _texture = null; _textureName = String.Empty; _textureLoaded = false; _light = null; }
public void AddLight(BaseLight light) { if (light is DeferredDirectionalLight) { DirectionalLights.Add((DeferredDirectionalLight)light); } else if (light is DeferredConeLight) { ConeLights.Add((DeferredConeLight)light); } else if (light is DeferredPointLight) { PointLights.Add((DeferredPointLight)light); } if (light.CastShadow) { ShadowLights.Add(light); } }
/// <summary> /// Do shadow mapping for a light. /// </summary> /// <param name="gameTime"></param> /// <param name="light"></param> /// <param name="shadowCasters"></param> public void RenderLightShadows(GameTime gameTime, BaseLight light, List <Base3DObject> shadowCasters) { if (light.ShadowMap == null) { // the bigger the map the better :) try { light.ShadowMap = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width * 5, GraphicsDevice.Viewport.Height * 5, false, SurfaceFormat.Single, DepthFormat.Depth24Stencil8); } catch { light.ShadowMap = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width * 2, GraphicsDevice.Viewport.Height * 2, false, SurfaceFormat.Single, DepthFormat.Depth24Stencil8); } } // Clear shadow map.. GraphicsDevice.SetRenderTarget(light.ShadowMap); GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true }; GraphicsDevice.Clear(Color.Transparent); if (shadowMapEffect == null) { shadowMapEffect = Game.Content.Load <Effect>("Shaders/ShadowMap"); } shadowMapEffect.Parameters["vp"].SetValue(light.View * light.Projection); int cnt = shadowCasters.Count; for (int c = 0; c < cnt; c++) { shadowCasters[c].Draw(gameTime, shadowMapEffect); } GraphicsDevice.SetRenderTarget(null); }
protected override void OnTick() { foreach (Item item in World.Items.Values) { if (item is BaseLight && item.Parent == null) { BaseLight light = item as BaseLight; int currentHour, currentMinute; Clock.GetTime(light.Map, light.X, light.Y, out currentHour, out currentMinute); if (currentHour > Config.IgniteHour || currentHour < Config.DouseHour) { light.Ignite(); } else if (currentHour > Config.DouseHour || currentHour < Config.IgniteHour) { light.Douse(); } } } }
vec4 CalcLightInternal(BaseLight Light, vec3 LightDirection, vec3 Normal) { vec4 AmbientColor = new vec4(Light.Color * Light.AmbientIntensity, 1.0f); float DiffuseFactor = dot(Normal, -LightDirection); vec4 DiffuseColor = new vec4(0, 0, 0, 0); vec4 SpecularColor = new vec4(0, 0, 0, 0); if (DiffuseFactor > 0) { DiffuseColor = new vec4(Light.Color * Light.DiffuseIntensity * DiffuseFactor, 1.0f); vec3 VertexToEye = normalize(gEyeWorldPos - Position0); vec3 LightReflect = normalize(reflect(LightDirection, Normal)); float SpecularFactor = dot(VertexToEye, LightReflect); if (SpecularFactor > 0) { SpecularFactor = pow(SpecularFactor, gSpecularPower); SpecularColor = new vec4(Light.Color * gMatSpecularIntensity * SpecularFactor, 1.0f); } } return(AmbientColor + DiffuseColor + SpecularColor); }
public static void LoadItems() { Console.Write("Start Loading items..."); string filePath = "itemstosave.xml"; if (!File.Exists(filePath)) { return; } XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlElement root = doc["items"]; foreach (XmlElement node in root.GetElementsByTagName("item")) { string itemstring = Utility.GetText(node["type"], null); if (!String.IsNullOrEmpty(itemstring)) { Type itemtype = ScriptCompiler.FindTypeByFullName(itemstring, true); if (itemtype != null) { Item item = Activator.CreateInstance(itemtype) as Item; if (item != null) { item.ItemID = Utility.GetXMLInt32(Utility.GetText(node["itemid"], "0"), 0); item.Hue = Utility.GetXMLInt32(Utility.GetText(node["hue"], "0"), 0); item.Movable = false; int x = Utility.GetXMLInt32(Utility.GetAttribute(node, "x"), 0); int y = Utility.GetXMLInt32(Utility.GetAttribute(node, "y"), 0); int z = Utility.GetXMLInt32(Utility.GetAttribute(node, "z"), 0); Map map = Map.Parse(Utility.GetAttribute(node, "map")); item.MoveToWorld(new Point3D(x, y, z), map); if (item is FillableContainer) { ((FillableContainer)item).ContentType = (FillableContentType)Utility.GetXMLInt32(Utility.GetText(node["contenttype"], "0"), 0); } if (item is LockableContainer) { LockableContainer cont = item as LockableContainer; cont.MaxLockLevel = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0); cont.LockLevel = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0); cont.RequiredSkill = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0); cont.Locked = Utility.GetText(node["locked"], "false") == "true"; cont.TrapOnLockpick = Utility.GetText(node["traponlockpick"], "false") == "true"; } if (item is BaseLight) { BaseLight light = item as BaseLight; light.Protected = Utility.GetText(node["protected"], "true") == "true"; light.Duration = Utility.GetXMLTimeSpan(Utility.GetText(node["duration"], "0"), TimeSpan.Zero); light.Burning = Utility.GetText(node["burning"], "true") == "true"; } } else { Console.WriteLine("Error loading: {0}", itemtype.FullName); } } else { Console.WriteLine("Error loading type from xml: {0}", itemstring); } } else { Console.WriteLine("Error loading string from xml: {0}", itemstring); } } Console.WriteLine("done."); }
public static void SetBaseLight(this ShaderProgram shader, string name, BaseLight light) { shader[name + ".color"] = light.Color; shader[name + ".intensity"] = light.Intensity; }