private void sldBrightness_Scroll(object sender, EventArgs e) { if (Game1.instance.selectedSector == null) { return; } if (useFloor) { if (!Game1.instance.flatLightInfoById.ContainsKey(Game1.instance.selectedSector.floorpic)) { return; } Game1.Floorlightinfo lightInfo = Game1.instance.flatLightInfoById[Game1.instance.selectedSector.floorpic]; lightInfo.brightness = (float)sldBrightness.Value / 100.0f; lightInfo.makeColor(); Game1.instance.NeedSave = true; } else { if (!Game1.instance.flatCLightInfoById.ContainsKey(Game1.instance.selectedSector.ceilingpic)) { return; } Game1.Floorlightinfo lightInfo = Game1.instance.flatCLightInfoById[Game1.instance.selectedSector.ceilingpic]; lightInfo.brightness = (float)sldBrightness.Value / 100.0f; lightInfo.makeColor(); Game1.instance.NeedSave = true; } }
private void btnAddLight_Click(object sender, EventArgs e) { if (Game1.instance.selectedSector == null) { return; } if (useFloor) { if (Game1.instance.flatLightInfoById.ContainsKey(Game1.instance.selectedSector.floorpic)) { Game1.instance.flatLightInfoById.Remove(Game1.instance.selectedSector.floorpic); foreach (r_local.sector_t sector in p_setup.sectors) { if (sector.floorpic == Game1.instance.selectedSector.floorpic) { if (sector.lightData != null) { sector.lightData.Dispose(); sector.lightData = null; } } } Game1.instance.NeedSave = true; } else { Game1.Floorlightinfo lightInfo = new Game1.Floorlightinfo(); Game1.instance.flatLightInfoById[Game1.instance.selectedSector.floorpic] = lightInfo; Game1.instance.NeedSave = true; } } else { if (Game1.instance.flatCLightInfoById.ContainsKey(Game1.instance.selectedSector.ceilingpic)) { Game1.instance.flatCLightInfoById.Remove(Game1.instance.selectedSector.ceilingpic); foreach (r_local.sector_t sector in p_setup.sectors) { if (sector.ceilingpic == Game1.instance.selectedSector.ceilingpic) { if (sector.lightDataC != null) { sector.lightDataC.Dispose(); sector.lightDataC = null; } } } Game1.instance.NeedSave = true; } else { Game1.Floorlightinfo lightInfo = new Game1.Floorlightinfo(); Game1.instance.flatCLightInfoById[Game1.instance.selectedSector.ceilingpic] = lightInfo; Game1.instance.NeedSave = true; } } fillUIWithSector(Game1.instance.selectedSector); }
public void Dispose() { sector = null; lightInfo = null; if (textureSpread != null) { textureSpread.Dispose(); } }
private void sldSpread_Scroll(object sender, EventArgs e) { if (Game1.instance.selectedSector == null) { return; } if (useFloor) { if (!Game1.instance.flatLightInfoById.ContainsKey(Game1.instance.selectedSector.floorpic)) { return; } Game1.Floorlightinfo lightInfo = Game1.instance.flatLightInfoById[Game1.instance.selectedSector.floorpic]; lightInfo.spread = (float)sldSpread.Value / 10.0f; // This causes all sector with this floorpic to invalidate foreach (r_local.sector_t sector in p_setup.sectors) { if (sector.floorpic == Game1.instance.selectedSector.floorpic) { if (sector.lightData != null) { sector.lightData.Dispose(); sector.lightData = null; } } } Game1.instance.NeedSave = true; } else { if (!Game1.instance.flatCLightInfoById.ContainsKey(Game1.instance.selectedSector.ceilingpic)) { return; } Game1.Floorlightinfo lightInfo = Game1.instance.flatCLightInfoById[Game1.instance.selectedSector.ceilingpic]; lightInfo.spread = (float)sldSpread.Value / 10.0f; // This causes all sector with this floorpic to invalidate foreach (r_local.sector_t sector in p_setup.sectors) { if (sector.ceilingpic == Game1.instance.selectedSector.ceilingpic) { if (sector.lightData != null) { sector.lightData.Dispose(); sector.lightData = null; } } } Game1.instance.NeedSave = true; } }
internal void fillUIWithSector(r_local.sector_t selectedSector) { if (selectedSector == null) { return; } if (Game1.instance.flatSelfIllumById.ContainsKey(selectedSector.floorpic)) { sldSelfIllumination.Value = (int)(Game1.instance.flatSelfIllumById[selectedSector.floorpic] * 100.0f); } else { sldSelfIllumination.Value = 0; } if (useFloor) { if (Game1.instance.flatLightInfoById.ContainsKey(Game1.instance.selectedSector.floorpic)) { btnAddLight.Text = "Remove Light"; Game1.Floorlightinfo lightInfo = Game1.instance.flatLightInfoById[Game1.instance.selectedSector.floorpic]; sldDistance.Value = (int)lightInfo.distance; sldHue.Value = lightInfo.hue; sldSaturation.Value = lightInfo.saturation; sldBrightness.Value = (int)(lightInfo.brightness * 100.0f); sldSpread.Value = (int)(lightInfo.spread * 10.0f); } else { btnAddLight.Text = "Add Light"; } } else { if (Game1.instance.flatCLightInfoById.ContainsKey(Game1.instance.selectedSector.ceilingpic)) { btnAddLight.Text = "Remove Light"; Game1.Floorlightinfo lightInfo = Game1.instance.flatCLightInfoById[Game1.instance.selectedSector.ceilingpic]; sldDistance.Value = (int)lightInfo.distance; sldHue.Value = lightInfo.hue; sldSaturation.Value = lightInfo.saturation; sldBrightness.Value = (int)(lightInfo.brightness * 100.0f); sldSpread.Value = (int)(lightInfo.spread * 10.0f); } else { btnAddLight.Text = "Add Light"; } } }
public SectorLightData(sector_t in_sector, Game1.Floorlightinfo in_lightInfo) { sector = in_sector; lightInfo = in_lightInfo; lightInfo.makeColor(); // Generate the stuff float bbminX = 100000; float bbminY = 100000; float bbmaxX = -100000; float bbmaxY = -100000; sector.floorBatch.boundingBox(ref bbminX, ref bbminY, ref bbmaxX, ref bbmaxY); int texW = Math.Max(1, (int)Math.Ceiling(((bbmaxX - bbminX) / PRECISION) + lightInfo.spread * 16 + 4)); int texH = Math.Max(1, (int)Math.Ceiling(((bbmaxY - bbminY) / PRECISION) + lightInfo.spread * 16 + 4)); int pow2 = 1; while (pow2 < texW) { pow2 *= 2; } texW = pow2; pow2 = 1; while (pow2 < texH) { pow2 *= 2; } texH = pow2; // Center it limits.X = ((bbmaxX + bbminX) - ((float)texW * PRECISION)) * .5f; limits.Y = ((bbmaxY + bbminY) - ((float)texH * PRECISION)) * .5f; limits.Z = limits.X + (float)texW * PRECISION; limits.W = limits.Y + (float)texH * PRECISION; textureSpread = new RenderTarget2D(Game1.instance.GraphicsDevice, texW, texH); RenderTarget2D textureTemp = new RenderTarget2D(Game1.instance.GraphicsDevice, texW, texH); Game1.instance.fxSectorLightInfo.Parameters["texSize"].SetValue(new Vector2((float)texW, (float)texH)); Game1.instance.fxSectorLightInfo.Parameters["spread"].SetValue(lightInfo.spread); // Render to target the sector Game1.instance.GraphicsDevice.SetRenderTarget(textureSpread); Game1.instance.GraphicsDevice.Clear(Color.Transparent); Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniquePlain"]; Game1.instance.fxSectorLightInfo.Parameters["World"].SetValue(Matrix.Identity); Game1.instance.fxSectorLightInfo.Parameters["View"].SetValue(Matrix.Identity); Game1.instance.fxSectorLightInfo.Parameters["Projection"].SetValue(Matrix.CreateOrthographicOffCenter(limits.X, limits.Z, limits.Y, limits.W, -999, 999)); Game1.instance.fxSectorLightInfo.CurrentTechnique.Passes[0].Apply(); Game1.instance.GraphicsDevice.SetVertexBuffer(sector.floorBatch.vb); Game1.instance.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, sector.floorBatch.triCount); Game1.instance.GraphicsDevice.SetRenderTargets(null); // Grow the texels for the base, and start bluring for the spread Game1.instance.GraphicsDevice.SetRenderTarget(textureTemp); Game1.instance.GraphicsDevice.Clear(Color.Transparent); Game1.instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, Game1.instance.fxSectorLightInfo); Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniqueBlurU"]; Game1.instance.spriteBatch.Draw(textureSpread, new Rectangle(0, 0, textureSpread.Width, textureSpread.Height), Color.White); Game1.instance.spriteBatch.End(); Game1.instance.GraphicsDevice.SetRenderTargets(null); // Lastly blur in V to finalize it Game1.instance.GraphicsDevice.SetRenderTarget(textureSpread); Game1.instance.GraphicsDevice.Clear(Color.Transparent); Game1.instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, Game1.instance.fxSectorLightInfo); Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniqueBlurV"]; Game1.instance.spriteBatch.Draw(textureTemp, new Rectangle(0, 0, textureTemp.Width, textureTemp.Height), Color.White); Game1.instance.spriteBatch.End(); Game1.instance.GraphicsDevice.SetRenderTargets(null); textureTemp.Dispose(); }