Skip to content

Commit

Permalink
#1638: Show message dialog when an exception occurs while launching a…
Browse files Browse the repository at this point in the history
… game engine (#1642)

* #1638: Show message dialog when an exception occurs while launching a game engine.

* #1634: Describe using the MODS variable in the game engine dialog. Fix a typo.
  • Loading branch information
kduske committed Jan 13, 2017
1 parent 60d1cc0 commit 473f17a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
4 changes: 3 additions & 1 deletion app/resources/documentation/manual/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ It is recommended to use the following general process for compiling maps and to
1. Set the working directory to `${MAP_DIR_PATH}`.
2. Add an *Export Map* task and set its target to `${WORK_DIR_PATH}/${MAP_BASE_NAME}-compile.map`.
3. Add *Run Tool* tasks for the compilation tools that you wish to run. Use the expressions `${MAP_BASE_NAME}-compile.map`` and `${MAP_BASE_NAME}.bsp` to specify the input and output files for the tools. Since you have set a working directory, you don't need to specify absolute paths here.
4. Finally, add a *Copy Files* task and set its source to `${WORK_DIR_PATH}/${MAP_BASE_NAME}.bsp` and its target to `${GAME_DIR_PATH}/${MOD[-1]}/maps`. This copies the file to the maps directory within the last enabled mod.
4. Finally, add a *Copy Files* task and set its source to `${WORK_DIR_PATH}/${MAP_BASE_NAME}.bsp` and its target to `${GAME_DIR_PATH}/${MODS[-1]}/maps`. This copies the file to the maps directory within the last enabled mod.

The last step will copy the bsp file to the appropriate directory within the game path. You can add more *Copy Files* tasks if the compilation produces more than just a bsp file (e.g. lightmap files). Alternatively, you can use a wildcard expression such as `${WORK_DIR_PATH}/${MAP_BASE_NAME}.*` to copy related files.

Expand All @@ -1072,6 +1072,8 @@ Variable Description
`GAME_DIR_PATH` The full path to the current game as specified in the game preferences.
`MODS` An array containing all enabled mods for the current map.

The `MODS` variable is useful to pass a parameter to the engine to choose a mod. Usually, this will be the last mod in the mods for the current map. Since the `MODS` variable is an array that contains all mods for the map, its individual entries are accessed using teh subscript operator (see below). To access the last entry in the array, you can use the expression `$MODS[-1]`.

Note that the parameters are stored in the map file for each engine. To be precise, they are stored in a worldspawn property, so when you change them, the map document will be marked as modified and you'll have to save it to keep the changes to the engine parameters. The advantage is that you can have different parameters in different maps (and for different engines).

## Expression Language {#expression_language}
Expand Down
41 changes: 24 additions & 17 deletions common/src/View/LaunchGameEngineDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "View/wxUtils.h"

#include <wx/button.h>
#include <wx/msgdlg.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
Expand Down Expand Up @@ -179,26 +180,32 @@ namespace TrenchBroom {
}

void LaunchGameEngineDialog::OnLaunch(wxCommandEvent& event) {
const Model::GameEngineProfile* profile = m_gameEngineList->selectedProfile();
ensure(profile != NULL, "profile is null");

const IO::Path& path = profile->path();
const String& parameterSpec = profile->parameterSpec();
const String parameters = EL::interpolate(parameterSpec, variables());

wxString launchStr;
try {
const Model::GameEngineProfile* profile = m_gameEngineList->selectedProfile();
ensure(profile != NULL, "profile is null");

const IO::Path& path = profile->path();
const String& parameterSpec = profile->parameterSpec();
const String parameters = EL::interpolate(parameterSpec, variables());

wxString launchStr;
#ifdef __APPLE__
// We have to launch apps via the 'open' command so that we can properly pass parameters.
launchStr << "/usr/bin/open " << path.asString() << " --args " << parameters;
// We have to launch apps via the 'open' command so that we can properly pass parameters.
launchStr << "/usr/bin/open " << path.asString() << " --args " << parameters;
#else
launchStr << path.asString() << " " << parameters;
launchStr << path.asString() << " " << parameters;
#endif

wxExecuteEnv env;
env.cwd = path.deleteLastComponent().asString();

wxExecute(launchStr, wxEXEC_ASYNC, NULL, &env);
EndModal(wxOK);

wxExecuteEnv env;
env.cwd = path.deleteLastComponent().asString();

wxExecute(launchStr, wxEXEC_ASYNC, NULL, &env);
EndModal(wxOK);
} catch (const Exception& e) {
StringStream message;
message << "Could not launch game engine: " << e.what();
::wxMessageBox(message.str(), "TrenchBroom", wxOK | wxICON_ERROR, this);
}
}

void LaunchGameEngineDialog::OnUpdateLaunchButtonUI(wxUpdateUIEvent& event) {
Expand Down

0 comments on commit 473f17a

Please sign in to comment.