mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-25 13:21:28 +00:00
more stuff added/updated
This commit is contained in:
parent
9bf5dc136c
commit
a8ff115cc3
13 changed files with 710 additions and 23 deletions
|
@ -2,9 +2,9 @@
|
|||
mainwindow
|
||||
{
|
||||
positionx = 27;
|
||||
sizeheight = 572;
|
||||
windowstate = 2;
|
||||
sizewidth = 739;
|
||||
positiony = 15;
|
||||
sizeheight = 572;
|
||||
sizewidth = 739;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
|
@ -44,6 +44,9 @@
|
|||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Editing\EditMode.cs" />
|
||||
<Compile Include="Editing\FrozenOverviewMode.cs" />
|
||||
<Compile Include="Editing\ViewClassicMode.cs" />
|
||||
<Compile Include="General\ConfigurationInfo.cs" />
|
||||
<Compile Include="General\MapManager.cs" />
|
||||
<Compile Include="Geometry\Angle2D.cs" />
|
||||
|
@ -88,11 +91,13 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Rendering\Graphics.cs" />
|
||||
<Compile Include="Rendering\PTVertex.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SlimDX, Version=1.0.2721.819, Culture=neutral, processorArchitecture=x86">
|
||||
<Aliases>global</Aliases>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.DirectX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
|
||||
<Reference Include="Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
|
||||
<Reference Include="Microsoft.DirectX.Direct3DX, Version=1.0.2911.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
@ -148,7 +153,4 @@
|
|||
<Isolated>False</Isolated>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Editing\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
95
Source/Editing/EditMode.cs
Normal file
95
Source/Editing/EditMode.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Interface;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Editing
|
||||
{
|
||||
internal class EditMode : IDisposable
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// Disposing
|
||||
protected bool isdisposed = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
// Disposing
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public EditMode()
|
||||
{
|
||||
// Initialize
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public virtual void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// Optional interface methods
|
||||
public virtual void MouseClick(MouseEventArgs e) { }
|
||||
public virtual void MouseDoubleClick(MouseEventArgs e) { }
|
||||
public virtual void MouseDown(MouseEventArgs e) { }
|
||||
public virtual void MouseEnter(EventArgs e) { }
|
||||
public virtual void MouseLeave(EventArgs e) { }
|
||||
public virtual void MouseMove(MouseEventArgs e) { }
|
||||
public virtual void MouseUp(MouseEventArgs e) { }
|
||||
public virtual void Cancel() { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
77
Source/Editing/FrozenOverviewMode.cs
Normal file
77
Source/Editing/FrozenOverviewMode.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Interface;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Editing
|
||||
{
|
||||
internal class FrozenOverviewMode : ViewClassicMode
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public FrozenOverviewMode()
|
||||
{
|
||||
// Initialize
|
||||
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
|
||||
// Dispose base
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
77
Source/Editing/ViewClassicMode.cs
Normal file
77
Source/Editing/ViewClassicMode.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Interface;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Editing
|
||||
{
|
||||
internal class ViewClassicMode : EditMode
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public ViewClassicMode()
|
||||
{
|
||||
// Initialize
|
||||
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
|
||||
// Dispose base
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder
|
|||
private static string configspath;
|
||||
|
||||
// Main objects
|
||||
private static Assembly thisasm;
|
||||
private static MainForm mainwindow;
|
||||
private static Configuration settings;
|
||||
private static MapManager map;
|
||||
|
@ -61,6 +62,7 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
#region ================== Properties
|
||||
|
||||
public static Assembly ThisAssembly { get { return thisasm; } }
|
||||
public static string AppPath { get { return apppath; } }
|
||||
public static string TempPath { get { return temppath; } }
|
||||
public static string ConfigsPath { get { return configspath; } }
|
||||
|
@ -153,9 +155,13 @@ namespace CodeImp.DoomBuilder
|
|||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Uri localpath;
|
||||
|
||||
// Get a reference to this assembly
|
||||
thisasm = Assembly.GetExecutingAssembly();
|
||||
|
||||
// Find application path
|
||||
string dirpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
|
||||
Uri localpath = new Uri(dirpath);
|
||||
localpath = new Uri(Path.GetDirectoryName(thisasm.GetName().CodeBase));
|
||||
apppath = Uri.UnescapeDataString(localpath.AbsolutePath);
|
||||
|
||||
// Temporary directory
|
||||
|
@ -222,7 +228,7 @@ namespace CodeImp.DoomBuilder
|
|||
{
|
||||
// Display status
|
||||
mainwindow.DisplayStatus("Creating new map...");
|
||||
|
||||
|
||||
// Clear the display
|
||||
mainwindow.ClearDisplay();
|
||||
|
||||
|
@ -230,7 +236,21 @@ namespace CodeImp.DoomBuilder
|
|||
if(map != null) map.Dispose();
|
||||
|
||||
// Create map manager with given options
|
||||
map = new MapManager(newoptions);
|
||||
map = new MapManager();
|
||||
if(!map.InitializeNewMap(newoptions))
|
||||
{
|
||||
// Unable to create map manager
|
||||
map.Dispose();
|
||||
map = null;
|
||||
|
||||
// Show splash logo on display
|
||||
mainwindow.ShowSplashDisplay();
|
||||
|
||||
// Failed
|
||||
mainwindow.UpdateMenus();
|
||||
mainwindow.DisplayReady();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Done
|
||||
mainwindow.UpdateMenus();
|
||||
|
|
|
@ -27,6 +27,9 @@ using System.Reflection;
|
|||
using CodeImp.DoomBuilder.Interface;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Editing;
|
||||
using System.Diagnostics;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -49,7 +52,9 @@ namespace CodeImp.DoomBuilder
|
|||
private MapSet data;
|
||||
private MapOptions options;
|
||||
private Configuration config;
|
||||
|
||||
private EditMode mode;
|
||||
private Graphics graphics;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
|
@ -60,6 +65,7 @@ namespace CodeImp.DoomBuilder
|
|||
public string FilePathName { get { return filepathname; } }
|
||||
public string FileTitle { get { return filetitle; } }
|
||||
public MapOptions Options { get { return options; } }
|
||||
public EditMode Mode { get { return mode; } }
|
||||
public bool IsChanged { get { return changed; } set { changed = value; } }
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
|
@ -68,16 +74,8 @@ namespace CodeImp.DoomBuilder
|
|||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor for new map
|
||||
public MapManager(MapOptions options)
|
||||
public MapManager()
|
||||
{
|
||||
// Initialize
|
||||
this.filetitle = "unnamed.wad";
|
||||
this.filepathname = "";
|
||||
this.changed = false;
|
||||
this.options = options;
|
||||
this.config = General.LoadGameConfiguration(options.ConfigFile);
|
||||
this.data = new MapSet();
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
@ -90,6 +88,8 @@ namespace CodeImp.DoomBuilder
|
|||
{
|
||||
// Dispose
|
||||
data.Dispose();
|
||||
mode.Dispose();
|
||||
graphics.Dispose();
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
|
@ -98,7 +98,59 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
#endregion
|
||||
|
||||
#region ================== Initialize
|
||||
|
||||
// Initializes for a new map
|
||||
public bool InitializeNewMap(MapOptions options)
|
||||
{
|
||||
// Apply settings
|
||||
this.filetitle = "unnamed.wad";
|
||||
this.filepathname = "";
|
||||
this.changed = false;
|
||||
this.options = options;
|
||||
|
||||
// Create objects
|
||||
data = new MapSet();
|
||||
graphics = new Graphics(General.MainWindow.Display);
|
||||
config = General.LoadGameConfiguration(options.ConfigFile);
|
||||
|
||||
// Initiate graphics
|
||||
if(!graphics.Initialize()) return false;
|
||||
|
||||
// Set default mode
|
||||
ChangeMode(typeof(FrozenOverviewMode));
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This changes editing mode
|
||||
public void ChangeMode(Type modetype, params object[] args)
|
||||
{
|
||||
// Dispose current mode
|
||||
if(mode != null) mode.Dispose();
|
||||
|
||||
try
|
||||
{
|
||||
// Create new mode
|
||||
mode = (EditMode)General.ThisAssembly.CreateInstance(modetype.FullName, false,
|
||||
BindingFlags.Default, null, args, CultureInfo.CurrentCulture, new object[0]);
|
||||
}
|
||||
// Catch errors
|
||||
catch(TargetInvocationException e)
|
||||
{
|
||||
// Throw the actual exception
|
||||
Debug.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
|
||||
Debug.WriteLine(e.InnerException.Source + " throws " + e.InnerException.GetType().Name + ":");
|
||||
Debug.WriteLine(e.InnerException.Message);
|
||||
Debug.WriteLine(e.InnerException.StackTrace);
|
||||
throw e.InnerException;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
7
Source/Interface/MainForm.Designer.cs
generated
7
Source/Interface/MainForm.Designer.cs
generated
|
@ -181,6 +181,13 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.display.Size = new System.Drawing.Size(731, 373);
|
||||
this.display.TabIndex = 5;
|
||||
this.display.TabStop = false;
|
||||
this.display.MouseLeave += new System.EventHandler(this.display_MouseLeave);
|
||||
this.display.MouseDown += new System.Windows.Forms.MouseEventHandler(this.display_MouseDown);
|
||||
this.display.MouseMove += new System.Windows.Forms.MouseEventHandler(this.display_MouseMove);
|
||||
this.display.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseDoubleClick);
|
||||
this.display.MouseClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseClick);
|
||||
this.display.MouseUp += new System.Windows.Forms.MouseEventHandler(this.display_MouseUp);
|
||||
this.display.MouseEnter += new System.EventHandler(this.display_MouseEnter);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
|
|
|
@ -164,6 +164,7 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
display.BackColor = System.Drawing.SystemColors.AppWorkspace;
|
||||
display.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.Splash2;
|
||||
display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
|
||||
this.Update();
|
||||
}
|
||||
|
||||
// This clears the display
|
||||
|
@ -173,7 +174,29 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
display.BackColor = Color.Black;
|
||||
display.BackgroundImage = null;
|
||||
display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Tile;
|
||||
this.Update();
|
||||
}
|
||||
|
||||
// Mouse click
|
||||
private void display_MouseClick(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseClick(e); }
|
||||
|
||||
// Mouse doubleclick
|
||||
private void display_MouseDoubleClick(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseDoubleClick(e); }
|
||||
|
||||
// Mouse down
|
||||
private void display_MouseDown(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseDown(e); }
|
||||
|
||||
// Mouse enters
|
||||
private void display_MouseEnter(object sender, EventArgs e) { if(General.Map != null) General.Map.Mode.MouseEnter(e); }
|
||||
|
||||
// Mouse leaves
|
||||
private void display_MouseLeave(object sender, EventArgs e) { if(General.Map != null) General.Map.Mode.MouseLeave(e); }
|
||||
|
||||
// Mouse moves
|
||||
private void display_MouseMove(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseMove(e); }
|
||||
|
||||
// Mouse up
|
||||
private void display_MouseUp(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseUp(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
285
Source/Rendering/Graphics.cs
Normal file
285
Source/Rendering/Graphics.cs
Normal file
|
@ -0,0 +1,285 @@
|
|||
|
||||
#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 Microsoft.DirectX.Direct3D;
|
||||
using System.ComponentModel;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
internal class Graphics : IDisposable
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
// NVPerfHUD device name
|
||||
public const string NVPERFHUD_ADAPTER = "NVPerfHUD";
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// Settings
|
||||
private int adapter;
|
||||
|
||||
// Main objects
|
||||
private Control rendertarget;
|
||||
private Caps devicecaps;
|
||||
private Device d3dd;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
// Disposing
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public Graphics(Control rendertarget)
|
||||
{
|
||||
// Set render target
|
||||
this.rendertarget = rendertarget;
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
d3dd.Dispose();
|
||||
rendertarget = null;
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Renderstates
|
||||
|
||||
// This completes initialization after the device has started or has been reset
|
||||
private void SetupSettings()
|
||||
{
|
||||
// Setup renderstates
|
||||
d3dd.SetRenderState(RenderStates.AntialiasedLineEnable, true);
|
||||
d3dd.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
|
||||
d3dd.SetRenderState(RenderStates.AmbientMaterialSource, (int)ColorSource.Material);
|
||||
d3dd.SetRenderState(RenderStates.ColorVertex, false);
|
||||
d3dd.SetRenderState(RenderStates.DiffuseMaterialSource, (int)ColorSource.Color1);
|
||||
d3dd.SetRenderState(RenderStates.FillMode, (int)FillMode.Solid);
|
||||
d3dd.SetRenderState(RenderStates.FogEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.Lighting, false);
|
||||
d3dd.SetRenderState(RenderStates.LocalViewer, false);
|
||||
d3dd.SetRenderState(RenderStates.NormalizeNormals, false);
|
||||
d3dd.SetRenderState(RenderStates.SpecularEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.StencilEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.PointSpriteEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.DitherEnable, true);
|
||||
d3dd.SetRenderState(RenderStates.AlphaBlendEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.ZEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.ZBufferWriteEnable, false);
|
||||
d3dd.SetRenderState(RenderStates.Clipping, true);
|
||||
d3dd.SetRenderState(RenderStates.CullMode, (int)Cull.CounterClockwise);
|
||||
d3dd.VertexFormat = PTVertex.Format;
|
||||
|
||||
// Sampler settings
|
||||
d3dd.SamplerState[0].MagFilter = TextureFilter.Linear;
|
||||
d3dd.SamplerState[0].MinFilter = TextureFilter.Linear;
|
||||
d3dd.SamplerState[0].MipFilter = TextureFilter.Linear;
|
||||
|
||||
// Texture addressing
|
||||
d3dd.SamplerState[0].AddressU = TextureAddress.Wrap;
|
||||
d3dd.SamplerState[0].AddressV = TextureAddress.Wrap;
|
||||
d3dd.SamplerState[0].AddressW = TextureAddress.Wrap;
|
||||
|
||||
// First texture stage
|
||||
d3dd.TextureState[0].ColorOperation = TextureOperation.Modulate;
|
||||
d3dd.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
|
||||
d3dd.TextureState[0].ColorArgument2 = TextureArgument.TFactor;
|
||||
d3dd.TextureState[0].ResultArgument = TextureArgument.Current;
|
||||
d3dd.TextureState[0].TextureCoordinateIndex = 0;
|
||||
|
||||
// No more further stages
|
||||
d3dd.TextureState[1].ColorOperation = TextureOperation.Disable;
|
||||
|
||||
// First alpha stage
|
||||
d3dd.TextureState[0].AlphaOperation = TextureOperation.Modulate;
|
||||
d3dd.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
|
||||
d3dd.TextureState[0].AlphaArgument2 = TextureArgument.TFactor;
|
||||
|
||||
// No more further stages
|
||||
d3dd.TextureState[1].AlphaOperation = TextureOperation.Disable;
|
||||
|
||||
// Setup material
|
||||
Material material = new Material();
|
||||
material.Ambient = Color.White;
|
||||
material.Diffuse = Color.White;
|
||||
material.Specular = Color.White;
|
||||
d3dd.Material = material;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Initialization
|
||||
|
||||
// This initializes the graphics
|
||||
public bool Initialize()
|
||||
{
|
||||
AdapterInformation adapterinfo;
|
||||
PresentParameters displaypp;
|
||||
DeviceType devtype;
|
||||
|
||||
// Use default adapter
|
||||
this.adapter = Manager.Adapters.Default.Adapter;
|
||||
|
||||
// Make present parameters
|
||||
displaypp = CreatePresentParameters(adapter);
|
||||
|
||||
// Determine device type for compatability with NVPerfHUD
|
||||
if(Manager.Adapters[adapter].Information.Description.EndsWith(NVPERFHUD_ADAPTER))
|
||||
devtype = DeviceType.Reference;
|
||||
else
|
||||
devtype = DeviceType.Hardware;
|
||||
|
||||
// Get the device capabilities
|
||||
devicecaps = Manager.GetDeviceCaps(adapter, devtype);
|
||||
|
||||
try
|
||||
{
|
||||
// Check if this adapter supports TnL
|
||||
if(devicecaps.DeviceCaps.SupportsHardwareTransformAndLight)
|
||||
{
|
||||
// Initialize with hardware TnL
|
||||
d3dd = new Device(adapter, devtype, rendertarget,
|
||||
CreateFlags.HardwareVertexProcessing, displaypp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initialize with software TnL
|
||||
d3dd = new Device(adapter, devtype, rendertarget,
|
||||
CreateFlags.SoftwareVertexProcessing, displaypp);
|
||||
}
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
// Failed
|
||||
MessageBox.Show(General.MainWindow, "Unable to initialize the Direct3D video device. Another application may have taken exclusive mode on this video device.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add event to cancel resize event
|
||||
d3dd.DeviceResizing += new CancelEventHandler(CancelResize);
|
||||
|
||||
// Initialize settings
|
||||
SetupSettings();
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is to disable the automatic resize reset
|
||||
private static void CancelResize(object sender, CancelEventArgs e)
|
||||
{
|
||||
// Cancel resize event
|
||||
e.Cancel = true;
|
||||
}
|
||||
|
||||
// This creates present parameters
|
||||
private PresentParameters CreatePresentParameters(int adapter)
|
||||
{
|
||||
PresentParameters displaypp = new PresentParameters();
|
||||
DisplayMode currentmode;
|
||||
|
||||
// Get current display mode
|
||||
currentmode = Manager.Adapters[adapter].CurrentDisplayMode;
|
||||
|
||||
// Make present parameters
|
||||
displaypp.Windowed = true;
|
||||
displaypp.SwapEffect = SwapEffect.Discard;
|
||||
displaypp.BackBufferCount = 1;
|
||||
displaypp.BackBufferFormat = currentmode.Format;
|
||||
displaypp.BackBufferWidth = rendertarget.ClientSize.Width;
|
||||
displaypp.BackBufferHeight = rendertarget.ClientSize.Height;
|
||||
displaypp.EnableAutoDepthStencil = true;
|
||||
displaypp.AutoDepthStencilFormat = DepthFormat.D16;
|
||||
displaypp.MultiSample = MultiSampleType.None;
|
||||
displaypp.PresentationInterval = PresentInterval.Immediate;
|
||||
|
||||
// Return result
|
||||
return displaypp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Resetting
|
||||
|
||||
// This resets the device and returns true on success
|
||||
private bool Reset()
|
||||
{
|
||||
PresentParameters displaypp;
|
||||
|
||||
// TODO: Unload all Direct3D resources
|
||||
|
||||
// Make present parameters
|
||||
displaypp = CreatePresentParameters(adapter);
|
||||
|
||||
try
|
||||
{
|
||||
// Reset the device
|
||||
d3dd.Reset(displaypp);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
// Failed to re-initialize
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize settings
|
||||
SetupSettings();
|
||||
|
||||
// TODO: Reload all Direct3D resources
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
49
Source/Rendering/PTVertex.cs
Normal file
49
Source/Rendering/PTVertex.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
#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 Microsoft.DirectX.Direct3D;
|
||||
using System.ComponentModel;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
// PTVertex
|
||||
public struct PTVertex
|
||||
{
|
||||
// Vertex format
|
||||
public static readonly VertexFormats Format = VertexFormats.Position | VertexFormats.Texture1;
|
||||
public static readonly int Stride = 5 * 4;
|
||||
|
||||
// Members
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
public float u;
|
||||
public float v;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue