The editor no longer locks up while testing the map.

This commit is contained in:
MaxED 2014-03-23 09:08:51 +00:00
parent 82b868e5f5
commit 71ad1199d8
8 changed files with 118 additions and 78 deletions

View file

@ -103,7 +103,6 @@ namespace CodeImp.DoomBuilder.Config
private int gzMaxDynamicLights; private int gzMaxDynamicLights;
private float gzDynamicLightRadius; private float gzDynamicLightRadius;
private float gzDynamicLightIntensity; private float gzDynamicLightIntensity;
private bool gzTestFromCurrentPosition;
private bool gzStretchModels; private bool gzStretchModels;
private float gzVertexScale2D; private float gzVertexScale2D;
private bool gzShowVisualVertices; private bool gzShowVisualVertices;
@ -182,7 +181,6 @@ namespace CodeImp.DoomBuilder.Config
public bool GZToolbarGZDoom { get { return gzToolbarGZDoom; } internal set { gzToolbarGZDoom = value; } } public bool GZToolbarGZDoom { get { return gzToolbarGZDoom; } internal set { gzToolbarGZDoom = value; } }
public bool GZSynchCameras { get { return gzSynchCameras; } internal set { gzSynchCameras = value; } } public bool GZSynchCameras { get { return gzSynchCameras; } internal set { gzSynchCameras = value; } }
public bool GZShowEventLines { get { return gzShowEventLines; } internal set { gzShowEventLines = value; } } public bool GZShowEventLines { get { return gzShowEventLines; } internal set { gzShowEventLines = value; } }
public bool GZTestFromCurrentPosition { get { return gzTestFromCurrentPosition; } internal set { gzTestFromCurrentPosition = value; } }
public bool GZOldHighlightMode { get { return gzOldHighlightMode; } internal set { gzOldHighlightMode = value; } } public bool GZOldHighlightMode { get { return gzOldHighlightMode; } internal set { gzOldHighlightMode = value; } }
public int GZMaxDynamicLights { get { return gzMaxDynamicLights; } internal set { gzMaxDynamicLights = value; } } public int GZMaxDynamicLights { get { return gzMaxDynamicLights; } internal set { gzMaxDynamicLights = value; } }
public float GZDynamicLightRadius { get { return gzDynamicLightRadius; } internal set { gzDynamicLightRadius = value; } } public float GZDynamicLightRadius { get { return gzDynamicLightRadius; } internal set { gzDynamicLightRadius = value; } }

View file

@ -607,8 +607,8 @@ namespace CodeImp.DoomBuilder.Editing
} }
//mxd //mxd
public override bool OnMapTestBegin() { public override bool OnMapTestBegin(bool testFromCurrentPosition) {
if (General.Settings.GZTestFromCurrentPosition) { if(testFromCurrentPosition) {
if(!mouseinside){ if(!mouseinside){
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: mouse is outside editing vindow!"); General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: mouse is outside editing vindow!");
return false; return false;
@ -658,8 +658,8 @@ namespace CodeImp.DoomBuilder.Editing
return true; return true;
} }
public override void OnMapTestEnd() { public override void OnMapTestEnd(bool testFromCurrentPosition) {
if (General.Settings.GZTestFromCurrentPosition) { if (testFromCurrentPosition) {
//restore position //restore position
playerStart.Move(playerStartPosition); playerStart.Move(playerStartPosition);
playerStart = null; playerStart = null;

View file

@ -212,8 +212,8 @@ namespace CodeImp.DoomBuilder.Editing
public virtual void OnMapSetChangeEnd() { } public virtual void OnMapSetChangeEnd() { }
//mxd. map testing events //mxd. map testing events
public virtual bool OnMapTestBegin() { return true; } //called before test map is launched. Returns false if map launch is impossible public virtual bool OnMapTestBegin(bool testFromCurrentPosition) { return true; } //called before test map is launched. Returns false if map launch is impossible
public virtual void OnMapTestEnd() { } //called after game engine is closed public virtual void OnMapTestEnd(bool testFromCurrentPosition) { } //called after game engine is closed
#endregion #endregion
} }

View file

@ -982,6 +982,12 @@ namespace CodeImp.DoomBuilder
[BeginAction("newmap")] [BeginAction("newmap")]
internal static void NewMap() internal static void NewMap()
{ {
//mxd
if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot create a map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
return;
}
MapOptions newoptions = new MapOptions(); MapOptions newoptions = new MapOptions();
MapOptionsForm optionswindow; MapOptionsForm optionswindow;
@ -1063,6 +1069,12 @@ namespace CodeImp.DoomBuilder
internal static void ActionCloseMap() { CloseMap(); } internal static void ActionCloseMap() { CloseMap(); }
internal static bool CloseMap() internal static bool CloseMap()
{ {
//mxd
if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot close the map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
return false;
}
// Cancel volatile mode, if any // Cancel volatile mode, if any
General.Editing.DisengageVolatileMode(); General.Editing.DisengageVolatileMode();
@ -1110,6 +1122,12 @@ namespace CodeImp.DoomBuilder
[BeginAction("openmap")] [BeginAction("openmap")]
internal static void OpenMap() internal static void OpenMap()
{ {
//mxd
if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot open a map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
return;
}
// Cancel volatile mode, if any // Cancel volatile mode, if any
General.Editing.DisengageVolatileMode(); General.Editing.DisengageVolatileMode();
@ -1140,6 +1158,12 @@ namespace CodeImp.DoomBuilder
// This loads a different map from same wad file // This loads a different map from same wad file
[BeginAction("openmapincurrentwad")] [BeginAction("openmapincurrentwad")]
internal static void OpenMapInCurrentWad() { internal static void OpenMapInCurrentWad() {
//mxd
if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot change the map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
return;
}
if (map == null || string.IsNullOrEmpty(map.FilePathName) || !File.Exists(map.FilePathName)){ if (map == null || string.IsNullOrEmpty(map.FilePathName) || !File.Exists(map.FilePathName)){
Interface.DisplayStatus(StatusType.Warning, "Unable to open map from current WAD!"); Interface.DisplayStatus(StatusType.Warning, "Unable to open map from current WAD!");
return; return;
@ -1290,10 +1314,14 @@ namespace CodeImp.DoomBuilder
internal static void ActionSaveMap() { SaveMap(); } internal static void ActionSaveMap() { SaveMap(); }
internal static bool SaveMap() internal static bool SaveMap()
{ {
bool result = false; //mxd
if (map.Launcher.GameEngineRunning) {
if(map == null) ShowWarningMessage("Cannot save the map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
return false; return false;
}
if(map == null) return false;
bool result = false;
// Cancel volatile mode, if any // Cancel volatile mode, if any
General.Editing.DisengageVolatileMode(); General.Editing.DisengageVolatileMode();
@ -1348,17 +1376,20 @@ namespace CodeImp.DoomBuilder
internal static void ActionSaveMapAs() { SaveMapAs(); } internal static void ActionSaveMapAs() { SaveMapAs(); }
internal static bool SaveMapAs() internal static bool SaveMapAs()
{ {
SaveFileDialog savefile; //mxd
bool result = false; if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot save the map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
if(map == null)
return false; return false;
}
if(map == null) return false;
bool result = false;
// Cancel volatile mode, if any // Cancel volatile mode, if any
General.Editing.DisengageVolatileMode(); General.Editing.DisengageVolatileMode();
// Show save as dialog // Show save as dialog
savefile = new SaveFileDialog(); SaveFileDialog savefile = new SaveFileDialog();
savefile.Filter = "Doom WAD Files (*.wad)|*.wad"; savefile.Filter = "Doom WAD Files (*.wad)|*.wad";
savefile.Title = "Save Map As"; savefile.Title = "Save Map As";
savefile.AddExtension = true; savefile.AddExtension = true;
@ -1422,17 +1453,20 @@ namespace CodeImp.DoomBuilder
internal static void ActionSaveMapInto() { SaveMapInto(); } internal static void ActionSaveMapInto() { SaveMapInto(); }
internal static bool SaveMapInto() internal static bool SaveMapInto()
{ {
SaveFileDialog savefile; //mxd
bool result = false; if(map.Launcher.GameEngineRunning) {
ShowWarningMessage("Cannot save the map while game engine is running" + Environment.NewLine + "Please close '" + map.ConfigSettings.TestProgram + "' first.", MessageBoxButtons.OK);
if(map == null)
return false; return false;
}
if(map == null) return false;
bool result = false;
// Cancel volatile mode, if any // Cancel volatile mode, if any
General.Editing.DisengageVolatileMode(); General.Editing.DisengageVolatileMode();
// Show save as dialog // Show save as dialog
savefile = new SaveFileDialog(); SaveFileDialog savefile = new SaveFileDialog();
savefile.Filter = "Doom WAD Files (*.wad)|*.wad"; savefile.Filter = "Doom WAD Files (*.wad)|*.wad";
savefile.Title = "Save Map Into"; savefile.Title = "Save Map Into";
savefile.AddExtension = true; savefile.AddExtension = true;

View file

@ -39,14 +39,17 @@ namespace CodeImp.DoomBuilder
#region ================== Variables #region ================== Variables
private string tempwad; private string tempwad;
private Process process; //mxd
private bool isdisposed; private bool isdisposed;
delegate void EngineExitedCallback(); //mxd
#endregion #endregion
#region ================== Properties #region ================== Properties
public string TempWAD { get { return tempwad; } } public string TempWAD { get { return tempwad; } }
public bool GameEngineRunning { get { return process != null; } } //mxd
#endregion #endregion
@ -71,6 +74,12 @@ namespace CodeImp.DoomBuilder
// Unbind actions // Unbind actions
General.Actions.UnbindMethods(this); General.Actions.UnbindMethods(this);
//mxd. Terminate process?
if (process != null) {
process.CloseMainWindow();
process.Close();
}
// Remove temporary file // Remove temporary file
try { File.Delete(tempwad); } try { File.Delete(tempwad); }
catch(Exception) { } catch(Exception) { }
@ -227,29 +236,28 @@ namespace CodeImp.DoomBuilder
[BeginAction("testmap")] [BeginAction("testmap")]
public void Test() public void Test()
{ {
General.Settings.GZTestFromCurrentPosition = false; //mxd if(!General.Editing.Mode.OnMapTestBegin(false)) return; //mxd
if(!General.Editing.Mode.OnMapTestBegin()) return; //mxd
TestAtSkill(General.Map.ConfigSettings.TestSkill); TestAtSkill(General.Map.ConfigSettings.TestSkill);
General.Editing.Mode.OnMapTestEnd(); //mxd General.Editing.Mode.OnMapTestEnd(false); //mxd
} }
//mxd //mxd
[BeginAction("testmapfromview")] [BeginAction("testmapfromview")]
public void TestFromView() { public void TestFromView() {
General.Settings.GZTestFromCurrentPosition = true; if(!General.Editing.Mode.OnMapTestBegin(true)) return;
if(!General.Editing.Mode.OnMapTestBegin()) return; //mxd
General.MainWindow.StopProcessing();
TestAtSkill(General.Map.ConfigSettings.TestSkill); TestAtSkill(General.Map.ConfigSettings.TestSkill);
General.Editing.Mode.OnMapTestEnd(true);
General.Editing.Mode.OnMapTestEnd(); //mxd
General.MainWindow.EnableProcessing();
General.MainWindow.FocusDisplay();
} }
// This saves the map to a temporary file and launches a test wit hthe given skill // This saves the map to a temporary file and launches a test wit hthe given skill
public void TestAtSkill(int skill) public void TestAtSkill(int skill)
{ {
//mxd
if (process != null) {
General.ShowWarningMessage("Game engine is already running." + Environment.NewLine + " Please close '" + General.Map.ConfigSettings.TestProgram + "' before testing again", MessageBoxButtons.OK);
return;
}
Cursor oldcursor = Cursor.Current; Cursor oldcursor = Cursor.Current;
// Check if configuration is OK // Check if configuration is OK
@ -310,64 +318,61 @@ namespace CodeImp.DoomBuilder
// Output info // Output info
General.WriteLogLine("Running test program: " + processinfo.FileName); General.WriteLogLine("Running test program: " + processinfo.FileName);
General.WriteLogLine("Program parameters: " + processinfo.Arguments); General.WriteLogLine("Program parameters: " + processinfo.Arguments);
General.MainWindow.DisplayStatus(StatusType.Info, "Launching " + processinfo.FileName + "...");
// Disable interface
General.MainWindow.DisplayStatus(StatusType.Busy, "Waiting for game application to finish...");
try try
{ {
// Start the program // Start the program
Process process = Process.Start(processinfo); process = Process.Start(processinfo);
process.EnableRaisingEvents = true; //mxd
// Wait for program to complete process.Exited += ProcessOnExited; //mxd
while(!process.WaitForExit(10)) Cursor.Current = oldcursor; //mxd
{
//General.MainWindow.Update(); //mxd
}
// Done
TimeSpan deltatime = TimeSpan.FromTicks(process.ExitTime.Ticks - process.StartTime.Ticks);
General.WriteLogLine("Test program has finished.");
General.WriteLogLine("Run time: " + deltatime.TotalSeconds.ToString("###########0.00") + " seconds");
} }
catch(Exception e) catch(Exception e)
{ {
// Unable to start the program // Unable to start the program
General.ShowErrorMessage("Unable to start the test program, " + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK); General.ShowErrorMessage("Unable to start the test program, " + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
} }
General.MainWindow.DisplayReady();
} }
else else
{ {
General.MainWindow.DisplayStatus(StatusType.Warning, "Unable to test the map due to script errors."); General.MainWindow.DisplayStatus(StatusType.Warning, "Unable to test the map due to script errors.");
} }
} }
}
//mxd
private void testingFinished() {
//Done
TimeSpan deltatime = TimeSpan.FromTicks(process.ExitTime.Ticks - process.StartTime.Ticks);
process = null;
General.WriteLogLine("Test program has finished.");
General.WriteLogLine("Run time: " + deltatime.TotalSeconds.ToString("###########0.00") + " seconds");
General.MainWindow.DisplayReady();
// Clean up temp file // Clean up temp file
CleanTempFile(General.Map); CleanTempFile(General.Map);
// Done
int retries = 0; //mxd
while(!General.Map.Graphics.CheckAvailability()) {
Thread.Sleep(100);
if (retries++ > 50) { //that's 5 seconds, right?
DialogResult result = General.ShowErrorMessage("Unable to reset D3D device." + Environment.NewLine + "Press Abort to quit," + Environment.NewLine + "Retry to wait and retry," + Environment.NewLine + "Ignore to proceed anyway (high chances of D3DException)", MessageBoxButtons.AbortRetryIgnore);
if(result == DialogResult.Abort) {
General.Exit(true);
} else if (result == DialogResult.Retry) {
retries = 0;
} else {
break;
}
}
}
General.Plugins.OnMapSaveEnd(SavePurpose.Testing); General.Plugins.OnMapSaveEnd(SavePurpose.Testing);
General.MainWindow.RedrawDisplay();
General.MainWindow.FocusDisplay(); General.MainWindow.FocusDisplay();
Cursor.Current = oldcursor; }
//mxd
public void StopGameEngine() {
//mxd. Terminate process?
if(process != null) {
process.CloseMainWindow();
process.Close();
process = null;
// Remove temporary file
try { if(File.Exists(tempwad)) File.Delete(tempwad); } catch(Exception) { }
}
}
//mxd
private void ProcessOnExited(object sender, EventArgs eventArgs) {
General.MainWindow.Invoke(new EngineExitedCallback(testingFinished));
} }
// This deletes the previous temp file and creates a new, empty temp file // This deletes the previous temp file and creates a new, empty temp file

View file

@ -265,8 +265,8 @@ namespace CodeImp.DoomBuilder.VisualModes
} }
//mxd //mxd
public override bool OnMapTestBegin() { public override bool OnMapTestBegin(bool testFromCurrentPosition) {
if (General.Settings.GZTestFromCurrentPosition) { if (testFromCurrentPosition) {
//find Single Player Start. Should have Type 1 in all games //find Single Player Start. Should have Type 1 in all games
Thing start = null; Thing start = null;
@ -317,8 +317,8 @@ namespace CodeImp.DoomBuilder.VisualModes
} }
//mxd //mxd
public override void OnMapTestEnd() { public override void OnMapTestEnd(bool testFromCurrentPosition) {
if (General.Settings.GZTestFromCurrentPosition) { if (testFromCurrentPosition) {
//restore position //restore position
playerStart.Move(playerStartPosition); playerStart.Move(playerStartPosition);
playerStart.Rotate(playerStartAngle); playerStart.Rotate(playerStartAngle);

View file

@ -586,6 +586,9 @@ namespace CodeImp.DoomBuilder.Windows
if(e.CloseReason != CloseReason.ApplicationExitCall) if(e.CloseReason != CloseReason.ApplicationExitCall)
{ {
//mxd
if(General.Map != null && General.Map.Launcher.GameEngineRunning) General.Map.Launcher.StopGameEngine();
// Close the map // Close the map
if(General.CloseMap()) if(General.CloseMap())
{ {

View file

@ -161,8 +161,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
//mxd //mxd
public override void OnMapTestEnd() { public override void OnMapTestEnd(bool testFromCurrentPosition) {
base.OnMapTestEnd(); base.OnMapTestEnd(testFromCurrentPosition);
General.Interface.RedrawDisplay(); // Redraw display to hide changes :) General.Interface.RedrawDisplay(); // Redraw display to hide changes :)
} }