rendering from vertexbuffers and slimdx update

This commit is contained in:
codeimp 2007-07-07 09:40:34 +00:00
parent 2cce129f70
commit 2d10662dcb
30 changed files with 1097 additions and 150 deletions

View file

@ -3,21 +3,21 @@ shortcuts
{
scrolleast = 39;
scrollsouth = 40;
zoomout = 65531;
scrollnorth = 38;
openmap = 131151;
scrollwest = 37;
newmap = 131150;
zoomin = 65530;
openmap = 131151;
zoomout = 65531;
}
mainwindow
{
positionx = 124;
sizewidth = 739;
windowstate = 2;
positionx = 378;
sizeheight = 572;
positiony = 35;
windowstate = 2;
sizewidth = 739;
positiony = 175;
}

Binary file not shown.

View file

@ -113,12 +113,17 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Rendering\Graphics.cs" />
<Compile Include="Rendering\IResource.cs" />
<Compile Include="Rendering\ManagedVertexBuffer.cs" />
<Compile Include="Rendering\PTVertex.cs" />
<Compile Include="Rendering\ReloadResourceDelegate.cs" />
<Compile Include="Rendering\Renderer2D.cs" />
<Compile Include="Rendering\Renderer3D.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="SlimDX, Version=1.0.2721.819, Culture=neutral, processorArchitecture=x86" />
<Reference Include="SlimDX, Version=1.0.2733.42401, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />

View file

@ -81,6 +81,7 @@ namespace CodeImp.DoomBuilder.Editing
// Change the view to see the whole map
renderer.ScaleView(scale);
renderer.PositionView(left + (right - left) * 0.5f, top + (bottom - top) * 0.5f);
General.Map.Data.Update();
}
// Diposer
@ -105,8 +106,8 @@ namespace CodeImp.DoomBuilder.Editing
{
if(renderer.StartRendering())
{
renderer.RenderLinedefs(General.Map.Data.Linedefs);
//renderer.RenderVertices(General.Map.Data.Vertices);
renderer.RenderLinedefs(General.Map.Data, General.Map.Data.Linedefs);
renderer.RenderVertices(General.Map.Data, General.Map.Data.Vertices);
renderer.FinishRendering();
}
}

View file

@ -29,6 +29,8 @@ using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing;
#endregion
@ -45,6 +47,11 @@ namespace CodeImp.DoomBuilder.Editing
// Graphics
protected Renderer2D renderer;
// Mouse status
protected Vector2D mousepos;
protected Vector2D mousemappos;
protected bool mouseinside;
#endregion
#region ================== Properties
@ -114,7 +121,7 @@ namespace CodeImp.DoomBuilder.Editing
public void ZoomIn()
{
// Zoom
ZoomBy(0.1f);
ZoomBy(1.2f);
}
// This zooms out
@ -122,7 +129,7 @@ namespace CodeImp.DoomBuilder.Editing
public void ZoomOut()
{
// Zoom
ZoomBy(-0.1f);
ZoomBy(0.8f);
}
// This scrolls anywhere
@ -131,16 +138,85 @@ namespace CodeImp.DoomBuilder.Editing
// Scroll now
renderer.PositionView(renderer.OffsetX + deltax, renderer.OffsetY + deltay);
RedrawDisplay();
// Determine new unprojected mouse coordinates
mousemappos = renderer.GetMapCoordinates(mousepos);
General.MainWindow.UpdateCoordinates(mousemappos);
}
// This zooms
private void ZoomBy(float deltaz)
{
Vector2D zoompos, clientsize, diff;
float newscale;
// This will be the new zoom scale
newscale = renderer.Scale * deltaz;
// Get the dimensions of the display
clientsize = new Vector2D(graphics.RenderTarget.ClientSize.Width,
graphics.RenderTarget.ClientSize.Height);
// When mouse is inside display
if(mouseinside)
{
// Zoom into or from mouse position
zoompos = (mousepos / clientsize) - new Vector2D(0.5f, 0.5f);
}
else
{
// Zoom into or from center
zoompos = new Vector2D(0f, 0f);
}
// Calculate view position difference
diff = ((clientsize / newscale) - (clientsize / renderer.Scale)) * zoompos;
// Zoom now
renderer.ScaleView(renderer.Scale + deltaz);
renderer.PositionView(renderer.OffsetX - diff.x, renderer.OffsetY + diff.y);
renderer.ScaleView(newscale);
General.Map.Data.Update();
RedrawDisplay();
// Determine new unprojected mouse coordinates
mousemappos = renderer.GetMapCoordinates(mousepos);
General.MainWindow.UpdateCoordinates(mousemappos);
}
#endregion
#region ================== Mouse input
// Mouse leaves the display
public override void MouseLeave(EventArgs e)
{
// Mouse is outside the display
mouseinside = false;
mousepos = new Vector2D(float.NaN, float.NaN);
mousemappos = mousepos;
// Determine new unprojected mouse coordinates
General.MainWindow.UpdateCoordinates(mousemappos);
// Let the base class know
base.MouseLeave(e);
}
// Mouse moved inside the display
public override void MouseMove(MouseEventArgs e)
{
// Record last position
mouseinside = true;
mousepos = new Vector2D(e.X, e.Y);
mousemappos = renderer.GetMapCoordinates(mousepos);
// Update labels in main window
General.MainWindow.UpdateCoordinates(mousemappos);
// Let the base class know
base.MouseMove(e);
}
#endregion
}
}

View file

@ -248,7 +248,7 @@ namespace CodeImp.DoomBuilder
{
MapOptions newoptions = new MapOptions();
MapOptionsForm optionswindow;
// Ask the user to save changes (if any)
if(General.AskSaveMap())
{

View file

@ -121,17 +121,20 @@ namespace CodeImp.DoomBuilder
this.changed = false;
this.options = options;
// Create objects
// Initiate graphics
graphics = new Graphics(General.MainWindow.Display);
if(!graphics.Initialize()) return false;
// Load game configuration
config = General.LoadGameConfiguration(options.ConfigFile);
data = new MapSet();
// Create map data
data = new MapSet();
data.EnableRendering();
// Create temp wadfile
tempwad = new WAD(General.MakeTempFilename());
// Initiate graphics
if(!graphics.Initialize()) return false;
// Set default mode
ChangeMode(typeof(FrozenOverviewMode));
@ -151,14 +154,20 @@ namespace CodeImp.DoomBuilder
this.changed = false;
this.options = options;
// Create objects
// Initiate graphics
graphics = new Graphics(General.MainWindow.Display);
config = General.LoadGameConfiguration(options.ConfigFile);
data = new MapSet();
if(!graphics.Initialize()) return false;
// Load game configuration
config = General.LoadGameConfiguration(options.ConfigFile);
// Create map data
data = new MapSet();
data.EnableRendering();
// Create temp wadfile
tempwad = new WAD(General.MakeTempFilename());
// Now open the map file
mapwad = new WAD(filepathname, true);
@ -171,11 +180,11 @@ namespace CodeImp.DoomBuilder
// Read the map from temp file
mapio = MapSetIO.Create(config.ReadSetting("formatinterface", ""), tempwad);
data = mapio.Read(new MapSet(), TEMP_MAP_HEADER);
// Initiate graphics
if(!graphics.Initialize()) return false;
data = mapio.Read(data, TEMP_MAP_HEADER);
// Update structures
data.Update();
// Set default mode
ChangeMode(typeof(FrozenOverviewMode));

View file

@ -26,7 +26,7 @@ using System.Text;
namespace CodeImp.DoomBuilder.Geometry
{
internal struct Angle2D
public struct Angle2D
{
#region ================== Constants

View file

@ -26,7 +26,7 @@ using System.Text;
namespace CodeImp.DoomBuilder.Geometry
{
internal struct Line2D
public struct Line2D
{
#region ================== Constants

View file

@ -26,7 +26,7 @@ using System.Text;
namespace CodeImp.DoomBuilder.Geometry
{
internal struct Vector2D
public struct Vector2D
{
#region ================== Constants

View file

@ -26,7 +26,7 @@ using System.Text;
namespace CodeImp.DoomBuilder.Geometry
{
internal struct Vector3D
public struct Vector3D
{
#region ================== Constants

View file

@ -29,6 +29,9 @@ namespace CodeImp.DoomBuilder.Interface
private void InitializeComponent()
{
System.Windows.Forms.PictureBox pictureBox1;
this.label1 = new System.Windows.Forms.Label();
this.close = new System.Windows.Forms.Button();
this.builderlink = new System.Windows.Forms.LinkLabel();
pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(pictureBox1)).BeginInit();
this.SuspendLayout();
@ -43,11 +46,46 @@ namespace CodeImp.DoomBuilder.Interface
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(166, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(342, 50);
this.label1.TabIndex = 2;
this.label1.Text = "Doom Builder is designed and programmed by Pascal vd Heiden.\r\nSeveral game config" +
"urations were written by various members of the Doom community.";
//
// close
//
this.close.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.close.Location = new System.Drawing.Point(392, 69);
this.close.Name = "close";
this.close.Size = new System.Drawing.Size(116, 25);
this.close.TabIndex = 3;
this.close.Text = "Close";
this.close.UseVisualStyleBackColor = true;
//
// builderlink
//
this.builderlink.AutoSize = true;
this.builderlink.Location = new System.Drawing.Point(166, 62);
this.builderlink.Name = "builderlink";
this.builderlink.Size = new System.Drawing.Size(121, 14);
this.builderlink.TabIndex = 5;
this.builderlink.TabStop = true;
this.builderlink.Text = "www.doombuilder.com";
this.builderlink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.builderlink_LinkClicked);
//
// AboutForm
//
this.AcceptButton = this.close;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(428, 263);
this.CancelButton = this.close;
this.ClientSize = new System.Drawing.Size(518, 104);
this.Controls.Add(this.builderlink);
this.Controls.Add(this.close);
this.Controls.Add(this.label1);
this.Controls.Add(pictureBox1);
this.DoubleBuffered = true;
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@ -55,6 +93,7 @@ namespace CodeImp.DoomBuilder.Interface
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutForm";
this.Opacity = 0;
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
@ -66,5 +105,9 @@ namespace CodeImp.DoomBuilder.Interface
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button close;
private System.Windows.Forms.LinkLabel builderlink;
}
}

View file

@ -22,6 +22,8 @@ using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
#endregion
@ -35,5 +37,53 @@ namespace CodeImp.DoomBuilder.Interface
// Initialize
InitializeComponent();
}
// Launch Doom Builder website
private void builderlink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenWebsite("http://" + builderlink.Text);
}
// This opens a URL in the default browser
private void OpenWebsite(string url)
{
RegistryKey key = null;
Process p = null;
string browser;
try
{
// Get the registry key where default browser is stored
key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
// Trim off quotes
browser = key.GetValue(null).ToString().ToLower().Replace("\"", "");
// String doesnt end in EXE?
if(!browser.EndsWith("exe"))
{
// Get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
}
}
finally
{
// Clean up
if(key != null) key.Close();
}
try
{
// Fork a process
p = new Process();
p.StartInfo.FileName = browser;
p.StartInfo.Arguments = url;
p.Start();
}
catch(Exception) { }
// Clean up
if(p != null) p.Dispose();
}
}
}

View file

@ -117,7 +117,22 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="pictureBox1.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pictureBox1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="label1.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="close.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="builderlink.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View file

@ -29,30 +29,68 @@ namespace CodeImp.DoomBuilder.Interface
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.menumain = new System.Windows.Forms.MenuStrip();
this.menufile = new System.Windows.Forms.ToolStripMenuItem();
this.itemnewmap = new System.Windows.Forms.ToolStripMenuItem();
this.itemopenmap = new System.Windows.Forms.ToolStripMenuItem();
this.itemclosemap = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.itemsavemap = new System.Windows.Forms.ToolStripMenuItem();
this.itemsavemapas = new System.Windows.Forms.ToolStripMenuItem();
this.itemsavemapinto = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.itemnorecent = new System.Windows.Forms.ToolStripMenuItem();
this.itemexit = new System.Windows.Forms.ToolStripMenuItem();
this.menuhelp = new System.Windows.Forms.ToolStripMenuItem();
this.itemhelpabout = new System.Windows.Forms.ToolStripMenuItem();
this.toolbar = new System.Windows.Forms.ToolStrip();
this.statusbar = new System.Windows.Forms.StatusStrip();
this.statuslabel = new System.Windows.Forms.ToolStripStatusLabel();
this.xposlabel = new System.Windows.Forms.ToolStripStatusLabel();
this.yposlabel = new System.Windows.Forms.ToolStripStatusLabel();
this.panelinfo = new System.Windows.Forms.Panel();
this.redrawtimer = new System.Windows.Forms.Timer(this.components);
this.display = new System.Windows.Forms.Panel();
toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.menumain.SuspendLayout();
this.statusbar.SuspendLayout();
this.SuspendLayout();
//
// toolStripMenuItem1
//
toolStripMenuItem1.Name = "toolStripMenuItem1";
toolStripMenuItem1.Size = new System.Drawing.Size(198, 6);
//
// toolStripMenuItem2
//
toolStripMenuItem2.Name = "toolStripMenuItem2";
toolStripMenuItem2.Size = new System.Drawing.Size(198, 6);
//
// toolStripMenuItem3
//
toolStripMenuItem3.Name = "toolStripMenuItem3";
toolStripMenuItem3.Size = new System.Drawing.Size(198, 6);
//
// toolStripSeparator1
//
toolStripSeparator1.Name = "toolStripSeparator1";
toolStripSeparator1.Size = new System.Drawing.Size(6, 23);
//
// toolStripStatusLabel1
//
toolStripStatusLabel1.Name = "toolStripStatusLabel1";
toolStripStatusLabel1.Size = new System.Drawing.Size(11, 18);
toolStripStatusLabel1.Text = ",";
toolStripStatusLabel1.ToolTipText = "Current X, Y coordinates on map";
//
// menumain
//
this.menumain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -70,11 +108,13 @@ namespace CodeImp.DoomBuilder.Interface
this.itemnewmap,
this.itemopenmap,
this.itemclosemap,
this.toolStripMenuItem1,
toolStripMenuItem1,
this.itemsavemap,
this.itemsavemapas,
this.itemsavemapinto,
this.toolStripMenuItem2,
toolStripMenuItem2,
this.itemnorecent,
toolStripMenuItem3,
this.itemexit});
this.menufile.Name = "menufile";
this.menufile.Size = new System.Drawing.Size(35, 20);
@ -84,7 +124,7 @@ namespace CodeImp.DoomBuilder.Interface
//
this.itemnewmap.Name = "itemnewmap";
this.itemnewmap.ShortcutKeyDisplayString = "";
this.itemnewmap.Size = new System.Drawing.Size(167, 22);
this.itemnewmap.Size = new System.Drawing.Size(201, 22);
this.itemnewmap.Tag = "newmap";
this.itemnewmap.Text = "New Map";
this.itemnewmap.Click += new System.EventHandler(this.itemnewmap_Click);
@ -92,7 +132,7 @@ namespace CodeImp.DoomBuilder.Interface
// itemopenmap
//
this.itemopenmap.Name = "itemopenmap";
this.itemopenmap.Size = new System.Drawing.Size(167, 22);
this.itemopenmap.Size = new System.Drawing.Size(201, 22);
this.itemopenmap.Tag = "openmap";
this.itemopenmap.Text = "Open Map...";
this.itemopenmap.Click += new System.EventHandler(this.itemopenmap_Click);
@ -100,42 +140,39 @@ namespace CodeImp.DoomBuilder.Interface
// itemclosemap
//
this.itemclosemap.Name = "itemclosemap";
this.itemclosemap.Size = new System.Drawing.Size(167, 22);
this.itemclosemap.Size = new System.Drawing.Size(201, 22);
this.itemclosemap.Text = "Close Map";
this.itemclosemap.Click += new System.EventHandler(this.itemclosemap_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(164, 6);
//
// itemsavemap
//
this.itemsavemap.Name = "itemsavemap";
this.itemsavemap.Size = new System.Drawing.Size(167, 22);
this.itemsavemap.Size = new System.Drawing.Size(201, 22);
this.itemsavemap.Text = "Save Map";
//
// itemsavemapas
//
this.itemsavemapas.Name = "itemsavemapas";
this.itemsavemapas.Size = new System.Drawing.Size(167, 22);
this.itemsavemapas.Size = new System.Drawing.Size(201, 22);
this.itemsavemapas.Text = "Save Map As...";
//
// itemsavemapinto
//
this.itemsavemapinto.Name = "itemsavemapinto";
this.itemsavemapinto.Size = new System.Drawing.Size(167, 22);
this.itemsavemapinto.Size = new System.Drawing.Size(201, 22);
this.itemsavemapinto.Text = "Save Map Into...";
//
// toolStripMenuItem2
// itemnorecent
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(164, 6);
this.itemnorecent.Enabled = false;
this.itemnorecent.Name = "itemnorecent";
this.itemnorecent.Size = new System.Drawing.Size(201, 22);
this.itemnorecent.Text = "No recently opened files";
//
// itemexit
//
this.itemexit.Name = "itemexit";
this.itemexit.Size = new System.Drawing.Size(167, 22);
this.itemexit.Size = new System.Drawing.Size(201, 22);
this.itemexit.Text = "Exit";
this.itemexit.Click += new System.EventHandler(this.itemexit_Click);
//
@ -167,25 +204,46 @@ namespace CodeImp.DoomBuilder.Interface
//
this.statusbar.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.statusbar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.statuslabel});
this.statusbar.Location = new System.Drawing.Point(0, 523);
this.statuslabel,
toolStripSeparator1,
this.xposlabel,
toolStripStatusLabel1,
this.yposlabel});
this.statusbar.Location = new System.Drawing.Point(0, 522);
this.statusbar.Name = "statusbar";
this.statusbar.Size = new System.Drawing.Size(731, 22);
this.statusbar.ShowItemToolTips = true;
this.statusbar.Size = new System.Drawing.Size(731, 23);
this.statusbar.TabIndex = 2;
//
// statuslabel
//
this.statuslabel.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.statuslabel.Name = "statuslabel";
this.statuslabel.Size = new System.Drawing.Size(716, 17);
this.statuslabel.Size = new System.Drawing.Size(568, 18);
this.statuslabel.Spring = true;
this.statuslabel.Text = "Initializing user interface...";
this.statuslabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// xposlabel
//
this.xposlabel.AutoSize = false;
this.xposlabel.Name = "xposlabel";
this.xposlabel.Size = new System.Drawing.Size(50, 18);
this.xposlabel.Text = "0";
this.xposlabel.ToolTipText = "Current X, Y coordinates on map";
//
// yposlabel
//
this.yposlabel.AutoSize = false;
this.yposlabel.Name = "yposlabel";
this.yposlabel.Size = new System.Drawing.Size(50, 18);
this.yposlabel.Text = "0";
this.yposlabel.ToolTipText = "Current X, Y coordinates on map";
//
// panelinfo
//
this.panelinfo.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelinfo.Location = new System.Drawing.Point(0, 422);
this.panelinfo.Location = new System.Drawing.Point(0, 421);
this.panelinfo.Name = "panelinfo";
this.panelinfo.Size = new System.Drawing.Size(731, 101);
this.panelinfo.TabIndex = 4;
@ -205,7 +263,7 @@ namespace CodeImp.DoomBuilder.Interface
this.display.Dock = System.Windows.Forms.DockStyle.Fill;
this.display.Location = new System.Drawing.Point(0, 49);
this.display.Name = "display";
this.display.Size = new System.Drawing.Size(731, 373);
this.display.Size = new System.Drawing.Size(731, 372);
this.display.TabIndex = 5;
this.display.MouseLeave += new System.EventHandler(this.display_MouseLeave);
this.display.MouseDown += new System.Windows.Forms.MouseEventHandler(this.display_MouseDown);
@ -258,11 +316,9 @@ namespace CodeImp.DoomBuilder.Interface
private System.Windows.Forms.ToolStripMenuItem menufile;
private System.Windows.Forms.ToolStripMenuItem itemnewmap;
private System.Windows.Forms.ToolStripMenuItem itemopenmap;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem itemsavemap;
private System.Windows.Forms.ToolStripMenuItem itemsavemapas;
private System.Windows.Forms.ToolStripMenuItem itemsavemapinto;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem itemexit;
private System.Windows.Forms.ToolStripStatusLabel statuslabel;
private System.Windows.Forms.ToolStripMenuItem itemclosemap;
@ -270,5 +326,8 @@ namespace CodeImp.DoomBuilder.Interface
private System.Windows.Forms.ToolStripMenuItem menuhelp;
private System.Windows.Forms.ToolStripMenuItem itemhelpabout;
private System.Windows.Forms.Panel display;
private System.Windows.Forms.ToolStripMenuItem itemnorecent;
private System.Windows.Forms.ToolStripStatusLabel xposlabel;
private System.Windows.Forms.ToolStripStatusLabel yposlabel;
}
}

View file

@ -23,6 +23,7 @@ using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Geometry;
#endregion
@ -49,6 +50,9 @@ namespace CodeImp.DoomBuilder.Interface
// Input
private bool shift, ctrl, alt;
// Recent files
private ToolStripMenuItem[] recentitems;
#endregion
#region ================== Properties
@ -176,6 +180,25 @@ namespace CodeImp.DoomBuilder.Interface
DisplayStatus(STATUS_READY_TEXT);
}
// This changes coordinates display
public void UpdateCoordinates(Vector2D coords)
{
// X position
if(float.IsNaN(coords.x))
xposlabel.Text = "--";
else
xposlabel.Text = coords.x.ToString("####0");
// Y position
if(float.IsNaN(coords.y))
yposlabel.Text = "--";
else
yposlabel.Text = coords.y.ToString("####0");
// Update status bar
statusbar.Update();
}
#endregion
#region ================== Display

View file

@ -117,18 +117,33 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStripMenuItem1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripMenuItem2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripMenuItem3.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripStatusLabel1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="menumain.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menumain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolbar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>121, 17</value>
</metadata>
<metadata name="toolbar.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="toolbar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>121, 17</value>
</metadata>
<metadata name="statusbar.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View file

@ -33,7 +33,10 @@ namespace CodeImp.DoomBuilder.Map
{
#region ================== Constants
public const int BUFFERVERTICES = 4;
public const int RENDERPRIMITIVES = 2;
public static readonly byte[] EMPTY_ARGS = new byte[5];
private const float NORMAL_LENGTH = 6f;
#endregion
@ -56,10 +59,10 @@ namespace CodeImp.DoomBuilder.Map
private Sidedef back;
// Cache
private bool updateneeded;
private float lengthsq;
private float length;
//private float angle;
private PTVertex[] lineverts;
// Properties
private int flags;
@ -67,6 +70,9 @@ namespace CodeImp.DoomBuilder.Map
private int tag;
private byte[] args;
// Rendering
private int bufferindex;
// Disposing
private bool isdisposed = false;
@ -74,11 +80,12 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
public PTVertex[] LineVertices { get { return lineverts; } }
public MapSet Map { get { return map; } }
public Vertex Start { get { return start; } }
public Vertex End { get { return end; } }
public Sidedef Front { get { return front; } }
public Sidedef Back { get { return back; } }
public int BufferIndex { get { return bufferindex; } set { bufferindex = value; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -93,14 +100,11 @@ namespace CodeImp.DoomBuilder.Map
this.mainlistitem = listitem;
this.start = start;
this.end = end;
this.lineverts = new PTVertex[4];
this.updateneeded = true;
// Attach to vertices
startvertexlistitem = start.AttachLinedef(this);
endvertexlistitem = end.AttachLinedef(this);
// Calculate values
Recalculate();
// We have no destructor
GC.SuppressFinalize(this);
@ -118,6 +122,9 @@ namespace CodeImp.DoomBuilder.Map
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Remove from rendering buffer
if(map.IsRenderEnabled) map.LinedefsBuffer.FreeItem(bufferindex);
// Detach from vertices
start.DetachLinedef(startvertexlistitem);
end.DetachLinedef(endvertexlistitem);
@ -150,7 +157,7 @@ namespace CodeImp.DoomBuilder.Map
{
// Attach and recalculate
front = s;
Recalculate();
updateneeded = true;
}
else throw new Exception("Linedef already has a front Sidedef.");
}
@ -163,29 +170,93 @@ namespace CodeImp.DoomBuilder.Map
{
// Attach and recalculate
back = s;
Recalculate();
updateneeded = true;
}
else throw new Exception("Linedef already has a back Sidedef.");
}
// This detaches a sidedef from the front
public void DetachSidedef(Sidedef s) { if(front == s) front = null; else if(back == s) back = null; else throw new Exception("Specified Sidedef is not attached to this Linedef."); }
// This recalculates cached values
public void Recalculate()
public void DetachSidedef(Sidedef s)
{
// Sidedef is on the front?
if(front == s)
{
// Remove sidedef reference
front = null;
updateneeded = true;
}
// Sidedef is on the back?
else if(back == s)
{
// Remove sidedef reference
back = null;
updateneeded = true;
}
else throw new Exception("Specified Sidedef is not attached to this Linedef.");
}
// This updates the line when changes have been made
public void Update()
{
Vector2D delta;
// Update if needed
if(updateneeded)
{
// Delta vector
delta = end.Position - start.Position;
// Recalculate values
lengthsq = delta.GetLengthSq();
length = (float)Math.Sqrt(lengthsq);
//angle = delta.GetAngle();
// Updated
updateneeded = false;
// If rendering is enabled, then update to buffer as well
if(map.IsRenderEnabled && map.IsUpdating) UpdateToBuffer();
}
}
// This flags the line needs an update
public void NeedUpdate()
{
updateneeded = true;
}
// This copies all properties to another line
public void CopyPropertiesTo(Linedef l)
{
// Copy properties
l.action = action;
l.args = (byte[])args.Clone();
l.flags = flags;
l.tag = tag;
l.updateneeded = true;
}
#endregion
#region ================== Rendering
// This writes the vertex to buffer
public void UpdateToBuffer()
{
PTVertex[] lineverts = new PTVertex[4];
Vector2D delta;
Vector2D normal;
int color;
float normallength;
// Not up to date? Then do that first (Update will call this method again)
if(updateneeded) { Update(); return; }
// Delta vector
delta = end.Position - start.Position;
// Recalculate values
lengthsq = delta.GetLengthSq();
length = (float)Math.Sqrt(lengthsq);
normal = new Vector2D(delta.x / length, delta.y / length);
//angle = delta.GetAngle();
// Single sided?
if((front == null) || (back == null))
@ -204,15 +275,18 @@ namespace CodeImp.DoomBuilder.Map
else
color = Graphics.RGB(140, 140, 140);
}
// Calculate normal length
normallength = NORMAL_LENGTH / General.Map.Graphics.Renderer2D.Scale;
// Create line normal
lineverts[0].x = start.Position.x + delta.x * 0.5f;
lineverts[0].y = start.Position.y + delta.y * 0.5f;
lineverts[1].x = lineverts[0].x + normal.y * 100f;
lineverts[1].y = lineverts[0].y - normal.x * 100f;
lineverts[1].x = lineverts[0].x + normal.y * normallength;
lineverts[1].y = lineverts[0].y - normal.x * normallength;
lineverts[0].c = color;
lineverts[1].c = color;
// Create line vertices
lineverts[2].x = start.Position.x;
lineverts[2].y = start.Position.y;
@ -220,18 +294,14 @@ namespace CodeImp.DoomBuilder.Map
lineverts[3].y = end.Position.y;
lineverts[2].c = color;
lineverts[3].c = color;
// Seek to start of item
map.LinedefsBuffer.SeekToItem(bufferindex);
// Write vertices to buffer
foreach(PTVertex v in lineverts) map.LinedefsBuffer.WriteItem(v);
}
// This copies all properties to another line
public void CopyPropertiesTo(Linedef l)
{
// Copy properties
l.action = action;
l.args = (byte[])args.Clone();
l.flags = flags;
l.tag = tag;
}
#endregion
#region ================== Methods
@ -287,6 +357,7 @@ namespace CodeImp.DoomBuilder.Map
this.tag = tag;
this.action = action;
this.args = args;
this.updateneeded = true;
}
#endregion

View file

@ -22,6 +22,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
using SlimDX.Direct3D;
using CodeImp.DoomBuilder.Rendering;
using SlimDX;
#endregion
@ -31,6 +34,10 @@ namespace CodeImp.DoomBuilder.Map
{
#region ================== Constants
// Minimum size for primitives in buffers
private const int MIN_PRIMITIVE_COUNT = 500;
private const int VERTS_PER_LINEDEF = 2;
#endregion
#region ================== Variables
@ -42,6 +49,12 @@ namespace CodeImp.DoomBuilder.Map
private LinkedList<Sector> sectors;
private LinkedList<Thing> things;
// Rendering
private bool renderenabled = false;
private int updating = 0;
private ManagedVertexBuffer verts;
private ManagedVertexBuffer lines;
// Disposing
private bool isdisposed = false;
@ -55,7 +68,11 @@ namespace CodeImp.DoomBuilder.Map
public ICollection<Sector> Sectors { get { return sectors; } }
public ICollection<Thing> Things { get { return things; } }
public bool IsDisposed { get { return isdisposed; } }
public bool IsRenderEnabled { get { return renderenabled; } }
public bool IsUpdating { get { return updating > 0; } }
public ManagedVertexBuffer VerticesBuffer { get { return verts; } }
public ManagedVertexBuffer LinedefsBuffer { get { return lines; } }
#endregion
#region ================== Constructor / Disposer
@ -85,6 +102,10 @@ namespace CodeImp.DoomBuilder.Map
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// No more rendering
DisableRendering();
updating = 0;
// Dispose all things
list = new ArrayList(things);
foreach(Thing t in list) t.Dispose();
@ -153,7 +174,7 @@ namespace CodeImp.DoomBuilder.Map
l.CopyPropertiesTo(nl);
// Recalculate
l.Recalculate();
l.Update();
}
// Go for all sectors
@ -207,6 +228,9 @@ namespace CodeImp.DoomBuilder.Map
// Add vertex to the list
vertices.AddLast(listitem);
// Add vertex to rendering bufer
if(renderenabled) v.BufferIndex = verts.AddItem();
// Return result
return v;
}
@ -227,6 +251,9 @@ namespace CodeImp.DoomBuilder.Map
// Add linedef to the list
linedefs.AddLast(listitem);
// Add linedef to rendering bufer
if(renderenabled) l.BufferIndex = lines.AddItem();
// Return result
return l;
}
@ -293,6 +320,119 @@ namespace CodeImp.DoomBuilder.Map
#endregion
#region ================== Resources
// This reloads vertices into rendering buffer
private void ReloadVertices()
{
// Update all vertices to buffer
foreach(Vertex v in vertices) v.UpdateToBuffer();
}
// This reloads linedefs into rendering buffer
private void ReloadLinedefs()
{
// Update all linedefs to buffer
foreach(Linedef l in linedefs) l.UpdateToBuffer();
}
#endregion
#region ================== Rendering
// This enables rendering of map structures
public void EnableRendering()
{
// Not already enabled?
if(!renderenabled)
{
// Enable rendering
renderenabled = true;
// Create buffers
verts = new ManagedVertexBuffer(PTVertex.Stride * Vertex.BUFFERVERTICES, vertices.Count);
lines = new ManagedVertexBuffer(PTVertex.Stride * Linedef.BUFFERVERTICES, linedefs.Count);
// Go for all vertices to add to the buffer
foreach(Vertex v in vertices) v.BufferIndex = verts.AddItem();
// Go for all linedefs to add to the buffer
foreach(Linedef l in linedefs) l.BufferIndex = lines.AddItem();
// Attach events
verts.ReloadResources += new ReloadResourceDelegate(ReloadVertices);
lines.ReloadResources += new ReloadResourceDelegate(ReloadLinedefs);
}
}
// This disables rendering of map structures
public void DisableRendering()
{
// Disable rendering
renderenabled = false;
// Stop any updating
while(updating > 0) EndUpdate();
// Trash buffers
if(verts != null) verts.Dispose();
if(lines != null) lines.Dispose();
verts = null;
lines = null;
}
// This locks the buffers for updates
public void BeginUpdate()
{
// Not already updating
if(updating == 0)
{
// Lock buffers for updating
verts.BeginUpdate();
lines.BeginUpdate();
}
// Now updating
updating++;
}
// This unlocks the buffers
public void EndUpdate()
{
// Updating?
if(updating > 0)
{
// No longer updating
updating--;
// Done updating?
if(updating == 0)
{
// Unlock buffers
verts.EndUpdate();
lines.EndUpdate();
}
}
}
// This updates all structures if needed
public void Update()
{
// Updating begins now
BeginUpdate();
// Update all vertices
foreach(Vertex v in vertices) v.Update();
// Update all linedefs
foreach(Linedef l in linedefs) l.Update();
// Updating has finished
EndUpdate();
}
#endregion
#region ================== Static Tools
// This finds the line closest to the specified position

View file

@ -61,7 +61,7 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
// Disposing
public MapSet Map { get { return map; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion

View file

@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
public MapSet Map { get { return map; } }
public bool IsFront { get { return (this == linedef.Front); } }
public Linedef Line { get { return linedef; } }
public Sidedef Other { get { if(this == linedef.Front) return linedef.Back; else return linedef.Front; } }

View file

@ -63,6 +63,7 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
public MapSet Map { get { return map; } }
public int Type { get { return type; } }
public Vector3D Position { get { return pos; } }
public bool IsDisposed { get { return isdisposed; } }

View file

@ -22,6 +22,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Rendering;
using SlimDX.Direct3D;
using System.Drawing;
#endregion
@ -30,7 +33,10 @@ namespace CodeImp.DoomBuilder.Map
internal class Vertex : IDisposable
{
#region ================== Constants
public const int BUFFERVERTICES = 1;
public const int RENDERPRIMITIVES = 1;
#endregion
#region ================== Variables
@ -47,6 +53,10 @@ namespace CodeImp.DoomBuilder.Map
// References
private LinkedList<Linedef> linedefs;
// Rendering
private bool updateneeded;
private int bufferindex;
// Disposing
private bool isdisposed = false;
@ -54,8 +64,10 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
public MapSet Map { get { return map; } }
public ICollection<Linedef> Linedefs { get { return linedefs; } }
public Vector2D Position { get { return pos; } }
public int BufferIndex { get { return bufferindex; } set { bufferindex = value; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -70,6 +82,7 @@ namespace CodeImp.DoomBuilder.Map
this.linedefs = new LinkedList<Linedef>();
this.mainlistitem = listitem;
this.pos = pos;
this.updateneeded = true;
// We have no destructor
GC.SuppressFinalize(this);
@ -86,6 +99,9 @@ namespace CodeImp.DoomBuilder.Map
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Remove from rendering buffer
if(map.IsRenderEnabled) map.VerticesBuffer.FreeItem(bufferindex);
// Dispose the lines that are attached to this vertex
// because a linedef cannot exist without 2 vertices.
@ -129,10 +145,48 @@ namespace CodeImp.DoomBuilder.Map
// Round to integrals
pos.x = (float)Math.Round(pos.x);
pos.y = (float)Math.Round(pos.y);
updateneeded = true;
}
// This updates the vertex when changes have been made
public void Update()
{
// Update if needed
if(updateneeded)
{
// Updated
updateneeded = false;
// If rendering is enabled, then update to buffer as well
if(map.IsRenderEnabled && map.IsUpdating) UpdateToBuffer();
}
}
#endregion
#region ================== Rendering
// This writes the vertex to buffer
public void UpdateToBuffer()
{
PTVertex v = new PTVertex();
// Not up to date? Then do that first (Update will call this method again)
if(updateneeded) { Update(); return; }
// Seek to start of item
map.VerticesBuffer.SeekToItem(bufferindex);
// Write vertices to buffer
v.x = pos.x;
v.y = pos.y;
v.z = 0f;
v.c = Color.SlateBlue.ToArgb();
map.VerticesBuffer.WriteItem(v);
}
#endregion
#region ================== Methods
// This returns the distance from given coordinates
@ -157,11 +211,14 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Changes
// This moves the vertex
// NOTE: This does not recalculate lines!
public void Move(Vector2D newpos)
{
// Change position
pos = newpos;
updateneeded = true;
// Let all lines know they need an update
foreach(Linedef l in linedefs) l.NeedUpdate();
}
#endregion

View file

@ -118,10 +118,10 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Splash2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Splash2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Splash2small" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Splash2small.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Splash2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Splash2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -25,6 +25,7 @@ using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using SlimDX.Direct3D9;
using SlimDX.Direct3D;
using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
@ -54,6 +55,7 @@ namespace CodeImp.DoomBuilder.Rendering
private Device device;
private Renderer2D renderer2d;
private Renderer3D renderer3d;
private Viewport viewport;
// Disposing
private bool isdisposed = false;
@ -67,6 +69,7 @@ namespace CodeImp.DoomBuilder.Rendering
public Renderer2D Renderer2D { get { return renderer2d; } }
public Renderer3D Renderer3D { get { return renderer3d; } }
public Control RenderTarget { get { return rendertarget; } }
public Viewport Viewport { get { return viewport; } }
#endregion
@ -77,6 +80,10 @@ namespace CodeImp.DoomBuilder.Rendering
{
// Set render target
this.rendertarget = rendertarget;
// Create renderers
renderer2d = new Renderer2D(this);
renderer3d = new Renderer3D(this);
// We have no destructor
GC.SuppressFinalize(this);
@ -93,7 +100,8 @@ namespace CodeImp.DoomBuilder.Rendering
renderer3d.Dispose();
device.Dispose();
rendertarget = null;
Direct3D.Terminate();
// Done
isdisposed = true;
}
@ -109,10 +117,10 @@ namespace CodeImp.DoomBuilder.Rendering
// Setup renderstates
device.SetRenderState(RenderState.AntialiasedLineEnable, false);
device.SetRenderState(RenderState.Ambient, Color.White.ToArgb());
device.SetRenderState(RenderState.AmbientMaterialSource, (int)ColorSource.Material);
device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Material);
device.SetRenderState(RenderState.ColorVertex, false);
device.SetRenderState(RenderState.DiffuseMaterialSource, (int)ColorSource.Color1);
device.SetRenderState(RenderState.FillMode, (int)FillMode.Solid);
device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1);
device.SetRenderState(RenderState.FillMode, FillMode.Solid);
device.SetRenderState(RenderState.FogEnable, false);
device.SetRenderState(RenderState.Lighting, false);
device.SetRenderState(RenderState.LocalViewer, false);
@ -125,37 +133,36 @@ namespace CodeImp.DoomBuilder.Rendering
device.SetRenderState(RenderState.ZEnable, false);
device.SetRenderState(RenderState.ZWriteEnable, false);
device.SetRenderState(RenderState.Clipping, true);
device.SetRenderState(RenderState.CullMode, (int)Cull.None);
device.SetRenderState(RenderState.CullMode, Cull.None);
device.VertexFormat = PTVertex.Format;
// Sampler settings
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MipFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
// Texture addressing
// TODO: SlimDX is missing TextureAddress enum
//device.SetSamplerState(0, SamplerState.AddressU, (int)TextureAddress.Wrap);
//device.SetSamplerState(0, SamplerState.AddressV, (int)TextureAddress.Wrap);
//device.SetSamplerState(0, SamplerState.AddressW, (int)TextureAddress.Wrap);
device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap);
device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Wrap);
device.SetSamplerState(0, SamplerState.AddressW, TextureAddress.Wrap);
// First texture stage
device.SetTextureStageState(0, TextureStage.ColorOp, (int)TextureOperation.Modulate);
device.SetTextureStageState(0, TextureStage.ColorArg1, (int)TextureArgument.Current);
device.SetTextureStageState(0, TextureStage.ColorArg2, (int)TextureArgument.TFactor);
device.SetTextureStageState(0, TextureStage.ResultArg, (int)TextureArgument.Current);
device.SetTextureStageState(0, TextureStage.ColorOp, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Diffuse);
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.TFactor);
device.SetTextureStageState(0, TextureStage.ResultArg, TextureArgument.Current);
device.SetTextureStageState(0, TextureStage.TexCoordIndex, 0);
// No more further stages
device.SetTextureStageState(1, TextureStage.ColorOp, (int)TextureOperation.Disable);
device.SetTextureStageState(1, TextureStage.ColorOp, TextureOperation.Disable);
// First alpha stage
device.SetTextureStageState(0, TextureStage.AlphaOp, (int)TextureOperation.Modulate);
device.SetTextureStageState(0, TextureStage.AlphaArg1, (int)TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.AlphaArg2, (int)TextureArgument.TFactor);
device.SetTextureStageState(0, TextureStage.AlphaOp, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.TFactor);
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.TFactor);
// No more further stages
device.SetTextureStageState(1, TextureStage.AlphaOp, (int)TextureOperation.Disable);
device.SetTextureStageState(1, TextureStage.AlphaOp, TextureOperation.Disable);
// Setup material
Material material = new Material();
@ -163,6 +170,9 @@ namespace CodeImp.DoomBuilder.Rendering
material.Diffuse = ColorValue.FromColor(Color.White);
material.Specular = ColorValue.FromColor(Color.White);
device.Material = material;
// Get the viewport
viewport = device.Viewport;
}
#endregion
@ -175,6 +185,9 @@ namespace CodeImp.DoomBuilder.Rendering
PresentParameters displaypp;
DeviceType devtype;
// Start DirectX
Direct3D.Initialize();
// Use default adapter
this.adapter = 0; // Manager.Adapters.Default.Adapter;
@ -219,10 +232,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Initialize settings
SetupSettings();
// Create renderers
renderer2d = new Renderer2D(this);
renderer3d = new Renderer3D(this);
// Done
return true;
}
@ -251,7 +260,7 @@ namespace CodeImp.DoomBuilder.Rendering
displaypp.BackBufferWidth = rendertarget.ClientSize.Width;
displaypp.BackBufferHeight = rendertarget.ClientSize.Height;
displaypp.EnableAutoDepthStencil = true;
displaypp.AutoDepthStencilFormat = Format.D16; // SLimDX is missing DepthFormat enum
displaypp.AutoDepthStencilFormat = Format.D16;
displaypp.MultiSample = MultiSampleType.None;
displaypp.PresentationInterval = PresentInterval.Immediate;

View file

@ -0,0 +1,45 @@
#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;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using SlimDX.Direct3D;
using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
using SlimDX;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
internal interface IResource : IDisposable
{
// This is used to unload the resouce
void UnloadResource();
// This is used to reload the resource
void ReloadResource();
}
}

View file

@ -0,0 +1,266 @@
#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;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using SlimDX.Direct3D9;
using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
using SlimDX;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
internal class ManagedVertexBuffer : IDisposable, IResource
{
#region ================== Constants
// Minimum items
private const int MIN_ITEMS = 500;
#endregion
#region ================== Events / Delegates
public event ReloadResourceDelegate ReloadResources;
#endregion
#region ================== Variables
// Buffer info
private int bytesperitem;
private int maxitems;
private LinkedList<int> freeitems;
// The vertexbuffer
private VertexBuffer buffer;
// The stream for updating
private GraphicsStream stream;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
public VertexBuffer VertexBuffer { get { return buffer; } }
public int ItemCapacity { get { return maxitems; } }
public int ItemCount { get { return maxitems - freeitems.Count; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public ManagedVertexBuffer(int bytesperitem, int initialsize)
{
// Initialize
this.bytesperitem = bytesperitem;
this.maxitems = initialsize;
if(this.maxitems < MIN_ITEMS) this.maxitems = MIN_ITEMS;
this.freeitems = new LinkedList<int>();
// Add free items to list
for(int i = 0; i < maxitems; i++) freeitems.AddLast(i);
// Create the buffer
CreateBuffer();
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
UnloadResource();
freeitems = null;
// Done
isdisposed = true;
}
}
#endregion
#region ================== Buffer
// This unloads the vertex buffer
public void UnloadResource()
{
// Clean up
if(stream != null) EndUpdate();
if(buffer != null) buffer.Dispose();
// Done
buffer = null;
}
// This reloads the vertex buffer
public void ReloadResource()
{
// Create the buffer
CreateBuffer();
// Signal that the buffer needs to be rebuild
if(ReloadResources != null) ReloadResources();
}
// This creates the buffer according to settings
private void CreateBuffer()
{
// Create the buffer
buffer = new VertexBuffer(General.Map.Graphics.Device, maxitems * bytesperitem,
Usage.WriteOnly, PTVertex.Format, Pool.Managed);
}
// This starts an update session
public void BeginUpdate()
{
// Lock the buffer and get the stream
stream = buffer.Lock(0, LockFlags.None);
}
// This stops an update session
public void EndUpdate()
{
// Unlock the buffer
buffer.Unlock();
stream.Dispose();
stream = null;
}
// This doubles the buffer size
private void DoubleBuffer()
{
VertexBuffer newbuf;
GraphicsStream newstream;
byte[] copybuf;
int newmaxitems;
bool updating;
// Not in an updating session yet?
if(stream == null)
{
// Start updating
BeginUpdate();
// Remember to stop updating when done
updating = false;
}
else
{
// Remember we want to keep the updating session open
updating = true;
}
// Increase size
newmaxitems = maxitems * 2;
// Add free items to list
for(int i = maxitems; i < newmaxitems; i++) freeitems.AddLast(i);
// Create a new buffer
newbuf = new VertexBuffer(General.Map.Graphics.Device, newmaxitems * bytesperitem,
Usage.WriteOnly, PTVertex.Format, Pool.Managed);
// Copy old data to new buffer
newstream = newbuf.Lock(0, LockFlags.None);
stream.Seek(0, SeekOrigin.Begin);
copybuf = new byte[maxitems * bytesperitem];
stream.Read(copybuf, 0, copybuf.Length);
newstream.Write(copybuf, 0, copybuf.Length);
// Dispose old buffer
buffer.Unlock();
stream.Dispose();
buffer.Dispose();
// Switch to new buffer
maxitems = newmaxitems;
buffer = newbuf;
stream = newstream;
// Stop updating session?
if(!updating)
{
// Stop updating now
EndUpdate();
}
}
#endregion
#region ================== Items
// This adds an item to the buffer and returns its unique index
public int AddItem()
{
int itemindex;
// Double the buffer for more items when none are available
if(freeitems.Count == 0) DoubleBuffer();
// Fetch the first free index from the list
itemindex = freeitems.First.Value;
freeitems.RemoveFirst();
// Return result
return itemindex;
}
// This frees an item
public void FreeItem(int index)
{
// Add item back into the list
freeitems.AddLast(index);
}
// This seeks the stream to the position for a specific item
public void SeekToItem(int index)
{
// Seek to item start position
stream.Seek(index * bytesperitem, SeekOrigin.Begin);
}
// This allows writing to the stream
public void WriteItem<T>(T item) where T : struct
{
// Write the item
stream.Write(item);
}
#endregion
}
}

View file

@ -25,7 +25,7 @@ using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using SlimDX.Direct3D;
using SlimDX.Direct3D9;
using System.ComponentModel;
#endregion

View file

@ -0,0 +1,38 @@
#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;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using SlimDX.Direct3D;
using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
using SlimDX;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
public delegate void ReloadResourceDelegate();
}

View file

@ -28,7 +28,9 @@ using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
#endregion
@ -50,6 +52,9 @@ namespace CodeImp.DoomBuilder.Rendering
private float offsetx;
private float offsety;
// Matrices
private Matrix matproj, matview, matworld;
// Disposing
private bool isdisposed = false;
@ -91,12 +96,11 @@ namespace CodeImp.DoomBuilder.Rendering
#endregion
#region ================== Methods
#region ================== Control
// This rebuilds matrices according to view settings
private void SetupMatrices()
{
Matrix proj;
float width, height, left, top, right, bottom;
// Build projection matrix
@ -106,12 +110,11 @@ namespace CodeImp.DoomBuilder.Rendering
top = offsety - height * 0.5f;
right = offsetx + width * 0.5f;
bottom = offsety + height * 0.5f;
proj = Matrix.OrthoOffCenterLH(left, right, top, bottom, -1f, 1f);
matproj = Matrix.OrthoOffCenterLH(left, right, top, bottom, -1f, 1f);
// Apply matrices
graphics.Device.SetTransform(TransformState.Projection, proj);
graphics.Device.SetTransform(TransformState.View, Matrix.Identity);
graphics.Device.SetTransform(TransformState.World, Matrix.Identity);
// World and view are fixed
matview = Matrix.Identity;
matworld = Matrix.Identity;
}
// This begins a drawing session
@ -120,8 +123,10 @@ namespace CodeImp.DoomBuilder.Rendering
// Can we render?
if(graphics.StartRendering())
{
// Setup matrices
SetupMatrices();
// Apply matrices
graphics.Device.SetTransform(TransformState.Projection, matproj);
graphics.Device.SetTransform(TransformState.View, matview);
graphics.Device.SetTransform(TransformState.World, matworld);
// Success
return true;
@ -146,6 +151,9 @@ namespace CodeImp.DoomBuilder.Rendering
// Change position in world coordinates
offsetx = x;
offsety = y;
// Setup new matrices
SetupMatrices();
}
// This changes zoom
@ -153,31 +161,46 @@ namespace CodeImp.DoomBuilder.Rendering
{
// Change zoom scale
this.scale = scale;
// Setup new matrices
SetupMatrices();
// Recalculate linedefs (normal lengths must be adjusted)
foreach(Linedef l in General.Map.Data.Linedefs) l.NeedUpdate();
}
// This renders a set of Linedefs
public void RenderLinedefs(ICollection<Linedef> linedefs)
// This unprojects mouse coordinates into map coordinates
public Vector2D GetMapCoordinates(Vector2D mousepos)
{
PTVertex[] verts = new PTVertex[linedefs.Count * 4];
int i = 0;
Vector3 mp, res;
// Get mouse position in Vector3
mp = new Vector3(mousepos.x, mousepos.y, 1f);
// Unproject
res = mp.Unproject(graphics.Viewport, matproj, matview, matworld);
// Return result
return new Vector2D(res.X, res.Y);
}
#endregion
#region ================== Map Rendering
// This renders a set of Linedefs
public void RenderLinedefs(MapSet map, ICollection<Linedef> linedefs)
{
// Any linedefs?
if(linedefs.Count > 0)
{
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
graphics.Device.SetStreamSource(0, map.LinedefsBuffer.VertexBuffer, 0, PTVertex.Stride);
// Go for all linedefs
foreach(Linedef l in linedefs)
{
// Make vertices
verts[i++] = l.LineVertices[0];
verts[i++] = l.LineVertices[1];
verts[i++] = l.LineVertices[2];
verts[i++] = l.LineVertices[3];
graphics.Device.DrawPrimitives(PrimitiveType.LineList, l.BufferIndex * Linedef.BUFFERVERTICES, Linedef.RENDERPRIMITIVES);
}
// Draw lines
graphics.Device.DrawUserPrimitives<PTVertex>(PrimitiveType.LineList, 0, linedefs.Count * 2, verts);
}
}