2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
2015-08-24 21:49:15 +00:00
|
|
|
using System.Drawing;
|
2012-06-01 10:17:47 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
2013-04-11 09:27:16 +00:00
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2012-06-01 10:17:47 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
2016-02-01 22:04:00 +00:00
|
|
|
internal abstract class Renderer : ID3DResource, IDisposable
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Graphics
|
|
|
|
protected D3DDevice graphics;
|
2014-01-09 13:52:25 +00:00
|
|
|
protected static bool fullbrightness;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Disposing
|
2014-01-09 13:52:25 +00:00
|
|
|
protected bool isdisposed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
// Disposing
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
2014-03-03 09:52:55 +00:00
|
|
|
public static bool FullBrightness { get { return fullbrightness; } set { fullbrightness = value; } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2015-05-27 12:38:03 +00:00
|
|
|
protected Renderer(D3DDevice g)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.graphics = g;
|
|
|
|
|
|
|
|
// Register as resource
|
|
|
|
g.RegisterResource(this);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
2016-02-01 22:04:00 +00:00
|
|
|
public virtual void Dispose()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Unregister resource
|
|
|
|
graphics.UnregisterResource(this);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
graphics = null;
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2009-07-12 09:58:05 +00:00
|
|
|
// This calculates the sector brightness level
|
|
|
|
public int CalculateBrightness(int level)
|
|
|
|
{
|
|
|
|
float flevel = level;
|
|
|
|
|
|
|
|
// Simulat doom light levels
|
|
|
|
if((level < 192) && General.Map.Config.DoomLightLevels)
|
2014-02-21 14:42:12 +00:00
|
|
|
flevel = (192.0f - (192 - level) * 1.5f);
|
2009-07-12 09:58:05 +00:00
|
|
|
|
|
|
|
byte blevel = (byte)General.Clamp((int)flevel, 0, 255);
|
|
|
|
PixelColor c = new PixelColor(255, blevel, blevel, blevel);
|
|
|
|
return c.ToInt();
|
|
|
|
}
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd. This calculates wall brightness level with doom-style shading
|
2014-12-03 23:15:26 +00:00
|
|
|
public int CalculateBrightness(int level, Sidedef sd)
|
|
|
|
{
|
|
|
|
if(level < 253 && sd != null)
|
|
|
|
{
|
2013-11-20 14:59:31 +00:00
|
|
|
bool evenlighting = General.Map.Data.MapInfo.EvenLighting;
|
|
|
|
bool smoothlighting = General.Map.Data.MapInfo.SmoothLighting;
|
|
|
|
|
|
|
|
//check for possiburu UDMF overrides
|
2014-12-03 23:15:26 +00:00
|
|
|
if(General.Map.UDMF)
|
|
|
|
{
|
|
|
|
if(sd.IsFlagSet("lightabsolute") && sd.Fields.ContainsKey("light"))
|
|
|
|
{
|
2013-11-20 14:59:31 +00:00
|
|
|
evenlighting = true;
|
2014-12-03 23:15:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-20 14:59:31 +00:00
|
|
|
if(sd.IsFlagSet("nofakecontrast"))
|
|
|
|
evenlighting = true;
|
|
|
|
if(sd.IsFlagSet("smoothlighting"))
|
|
|
|
smoothlighting = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
if(!evenlighting)
|
|
|
|
{
|
2013-11-20 14:59:31 +00:00
|
|
|
//all walls are shaded by their angle
|
2014-12-03 23:15:26 +00:00
|
|
|
if(smoothlighting)
|
|
|
|
{
|
2013-11-20 14:59:31 +00:00
|
|
|
float ammount = Math.Abs((float)Math.Sin(sd.Angle));
|
|
|
|
int hAmmount = (int)((1.0f - ammount) * General.Map.Data.MapInfo.HorizWallShade);
|
|
|
|
int vAmmount = (int)(ammount * General.Map.Data.MapInfo.VertWallShade);
|
|
|
|
|
|
|
|
level = General.Clamp(level - hAmmount - vAmmount, 0, 255);
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
}
|
|
|
|
else //only horizontal/verticel walls are shaded
|
2015-07-15 09:09:47 +00:00
|
|
|
{
|
|
|
|
switch((int)Angle2D.RadToDeg(sd.Angle))
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-07-15 09:09:47 +00:00
|
|
|
// Horizontal wall
|
|
|
|
case 90:
|
|
|
|
case 270:
|
|
|
|
level = General.Clamp(level + General.Map.Data.MapInfo.HorizWallShade, 0, 255);
|
|
|
|
break;
|
|
|
|
// Vertical wall
|
|
|
|
case 180:
|
|
|
|
case 0:
|
|
|
|
level = General.Clamp(level + General.Map.Data.MapInfo.VertWallShade, 0, 255);
|
|
|
|
break;
|
2013-11-20 14:59:31 +00:00
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CalculateBrightness(level);
|
|
|
|
}
|
2012-06-01 10:17:47 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This is called when the graphics need to be reset
|
2016-01-14 22:15:54 +00:00
|
|
|
//public virtual void Reset() { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// For DirectX resources
|
|
|
|
public virtual void UnloadResource() { }
|
|
|
|
public virtual void ReloadResource() { }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|