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.Collections.Generic;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using SlimDX.Direct3D9;
|
|
|
|
using SlimDX;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.VisualModes
|
|
|
|
{
|
|
|
|
public class VisualSector : ID3DResource
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
Added, Visual mode, GLDEFS, GLOOME: subtractive glow is now supported.
Changed, Visual mode: changed thing fog calculation logic. Should be closer to GZDoom now.
Fixed, GLDEFS parser: "height" texture parameter was not treated as optional.
Fixed, text lump parsers: in some cases incorrect line number was displayed in error and warning messages.
Fixed, Visual mode: glow effect was not applied to sectors with 3 sidedefs.
Fixed, Visual mode: in some cases glow effect was not updated when replacing textures.
Fixed, general interface: "Full Brightness" button state was not updated during map loading.
Fixed, Drag Linedefs/Vertices/Sectors/Things modes: positions of line length labels were not updated while panning the view.
Cosmetic: added a bunch of new icons.
Cosmetic: changed Visual mode crosshair.
2015-08-27 20:46:49 +00:00
|
|
|
public const float MAXIMUM_FOG_DISTANCE = 2805f; //mxd. 255 * 11. Straight from GZDoom source.
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Geometry
|
|
|
|
private List<VisualGeometry> fixedgeometry;
|
|
|
|
private List<VisualGeometry> allgeometry;
|
|
|
|
private Dictionary<Sidedef, List<VisualGeometry>> sidedefgeometry;
|
|
|
|
private VertexBuffer geobuffer;
|
|
|
|
private bool updategeo;
|
Added, Visual mode, GLDEFS, GLOOME: subtractive glow is now supported.
Changed, Visual mode: changed thing fog calculation logic. Should be closer to GZDoom now.
Fixed, GLDEFS parser: "height" texture parameter was not treated as optional.
Fixed, text lump parsers: in some cases incorrect line number was displayed in error and warning messages.
Fixed, Visual mode: glow effect was not applied to sectors with 3 sidedefs.
Fixed, Visual mode: in some cases glow effect was not updated when replacing textures.
Fixed, general interface: "Full Brightness" button state was not updated during map loading.
Fixed, Drag Linedefs/Vertices/Sectors/Things modes: positions of line length labels were not updated while panning the view.
Cosmetic: added a bunch of new icons.
Cosmetic: changed Visual mode crosshair.
2015-08-27 20:46:49 +00:00
|
|
|
|
|
|
|
//mxd. Rendering
|
|
|
|
protected float fogdistance; // Distance, at which fog color completely replaces texture color of this thing
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Original sector
|
|
|
|
private Sector sector;
|
|
|
|
|
|
|
|
// Disposing
|
2014-02-21 14:42:12 +00:00
|
|
|
private bool isdisposed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
internal List<VisualGeometry> FixedGeometry { get { return fixedgeometry; } }
|
|
|
|
internal List<VisualGeometry> AllGeometry { get { return allgeometry; } }
|
|
|
|
internal VertexBuffer GeometryBuffer { get { return geobuffer; } }
|
|
|
|
internal bool NeedsUpdateGeo { get { return updategeo; } set { updategeo |= value; } }
|
Added, Visual mode, GLDEFS, GLOOME: subtractive glow is now supported.
Changed, Visual mode: changed thing fog calculation logic. Should be closer to GZDoom now.
Fixed, GLDEFS parser: "height" texture parameter was not treated as optional.
Fixed, text lump parsers: in some cases incorrect line number was displayed in error and warning messages.
Fixed, Visual mode: glow effect was not applied to sectors with 3 sidedefs.
Fixed, Visual mode: in some cases glow effect was not updated when replacing textures.
Fixed, general interface: "Full Brightness" button state was not updated during map loading.
Fixed, Drag Linedefs/Vertices/Sectors/Things modes: positions of line length labels were not updated while panning the view.
Cosmetic: added a bunch of new icons.
Cosmetic: changed Visual mode crosshair.
2015-08-27 20:46:49 +00:00
|
|
|
public float FogDistance { get { return fogdistance; } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
public Sector Sector { get { return sector; } }
|
2013-09-11 08:49:45 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public VisualSector(Sector s)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.sector = s;
|
|
|
|
allgeometry = new List<VisualGeometry>();
|
|
|
|
fixedgeometry = new List<VisualGeometry>();
|
|
|
|
sidedefgeometry = new Dictionary<Sidedef, List<VisualGeometry>>();
|
2013-09-11 08:49:45 +00:00
|
|
|
this.sector.UpdateFogColor(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Register as resource
|
|
|
|
General.Map.Graphics.RegisterResource(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public virtual void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
if(geobuffer != null) geobuffer.Dispose();
|
|
|
|
geobuffer = null;
|
|
|
|
|
|
|
|
// Unregister resource
|
|
|
|
General.Map.Graphics.UnregisterResource(this);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This is called before a device is reset
|
|
|
|
// (when resized or display adapter was changed)
|
|
|
|
public virtual void UnloadResource()
|
|
|
|
{
|
|
|
|
// Trash geometry buffer
|
|
|
|
if(geobuffer != null) geobuffer.Dispose();
|
|
|
|
geobuffer = null;
|
|
|
|
updategeo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called resets when the device is reset
|
|
|
|
// (when resized or display adapter was changed)
|
|
|
|
public virtual void ReloadResource()
|
|
|
|
{
|
|
|
|
// Make new geometry
|
|
|
|
//Update();
|
|
|
|
}
|
2012-05-11 12:28:20 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd. Added to allow to properly update visual geometry from plugins
|
|
|
|
public virtual void UpdateSectorData() { }
|
2013-03-18 13:52:27 +00:00
|
|
|
public virtual void UpdateSectorGeometry(bool includeneighbours) { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This updates the visual sector
|
|
|
|
public void Update()
|
|
|
|
{
|
|
|
|
int numverts = 0;
|
|
|
|
int v = 0;
|
|
|
|
|
|
|
|
// Trash geometry buffer
|
|
|
|
if(geobuffer != null) geobuffer.Dispose();
|
|
|
|
geobuffer = null;
|
|
|
|
|
|
|
|
// Count the number of vertices there are
|
|
|
|
foreach(VisualGeometry g in allgeometry) if(g.Vertices != null) numverts += g.Vertices.Length;
|
|
|
|
|
|
|
|
// Any vertics?
|
|
|
|
if(numverts > 0)
|
|
|
|
{
|
|
|
|
// Make a new buffer
|
|
|
|
geobuffer = new VertexBuffer(General.Map.Graphics.Device, WorldVertex.Stride * numverts,
|
|
|
|
Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
|
|
|
|
|
|
|
|
// Fill the buffer
|
2014-09-17 12:46:47 +00:00
|
|
|
DataStream bufferstream = geobuffer.Lock(0, WorldVertex.Stride * numverts, LockFlags.Discard);
|
2009-04-19 18:07:22 +00:00
|
|
|
foreach(VisualGeometry g in allgeometry)
|
|
|
|
{
|
|
|
|
if((g.Vertices != null) && (g.Vertices.Length > 0))
|
|
|
|
{
|
2014-09-17 12:46:47 +00:00
|
|
|
bufferstream.WriteRange(g.Vertices);
|
2009-04-19 18:07:22 +00:00
|
|
|
g.VertexOffset = v;
|
|
|
|
v += g.Vertices.Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
geobuffer.Unlock();
|
|
|
|
bufferstream.Dispose();
|
|
|
|
}
|
2013-09-11 08:49:45 +00:00
|
|
|
|
|
|
|
this.sector.UpdateFogColor(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
updategeo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This adds geometry for this sector. If the geometry inherits from VisualSidedef then it
|
|
|
|
/// will be added to the SidedefGeometry, otherwise it will be added as FixedGeometry.
|
|
|
|
/// </summary>
|
|
|
|
public void AddGeometry(VisualGeometry geo)
|
|
|
|
{
|
|
|
|
updategeo = true;
|
|
|
|
allgeometry.Add(geo);
|
|
|
|
if(geo.Sidedef != null)
|
|
|
|
{
|
|
|
|
if(!sidedefgeometry.ContainsKey(geo.Sidedef))
|
|
|
|
sidedefgeometry[geo.Sidedef] = new List<VisualGeometry>(3);
|
|
|
|
sidedefgeometry[geo.Sidedef].Add(geo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fixedgeometry.Add(geo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This removes all geometry.
|
|
|
|
/// </summary>
|
|
|
|
public void ClearGeometry()
|
|
|
|
{
|
|
|
|
allgeometry.Clear();
|
|
|
|
fixedgeometry.Clear();
|
|
|
|
sidedefgeometry.Clear();
|
|
|
|
updategeo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This gets the geometry list for the specified sidedef
|
|
|
|
public List<VisualGeometry> GetSidedefGeometry(Sidedef sd)
|
|
|
|
{
|
2014-01-13 08:06:56 +00:00
|
|
|
if(sidedefgeometry.ContainsKey(sd)) return sidedefgeometry[sd];
|
|
|
|
return new List<VisualGeometry>();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|