Merge remote branch 'origin/divVerent/convert-from-map-to-map'

This commit is contained in:
Rudolf Polzer 2010-10-10 16:53:39 +02:00
commit 61c537beac
13 changed files with 118 additions and 39 deletions

View File

@ -22,7 +22,7 @@ void OnExportClicked(GtkButton* button, gpointer user_data)
{
GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2");
ASSERT_NOTNULL(window);
const char* cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0);
const char* cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0, false, false, true);
if(!cpath)
return;

View File

@ -31,12 +31,15 @@ public:
: name(""), pattern("")
{
}
filetype_t(const char* _name, const char* _pattern)
: name(_name), pattern(_pattern)
filetype_t(const char* _name, const char* _pattern, bool _can_load = true, bool _can_import = true, bool _can_save = true)
: name(_name), pattern(_pattern), can_load(_can_load), can_import(_can_import), can_save(_can_save)
{
}
const char* name;
const char* pattern;
bool can_load;
bool can_import;
bool can_save;
};
@ -53,7 +56,7 @@ public:
STRING_CONSTANT(Name, "filetypes");
virtual void addType(const char* moduleType, const char* moduleName, filetype_t type) = 0;
virtual void getTypeList(const char* moduleType, IFileTypeList* typelist) = 0;
virtual void getTypeList(const char* moduleType, IFileTypeList* typelist, bool want_load = false, bool want_import = false, bool want_save = false) = 0;
};
#include "modulesystem.h"

View File

@ -71,7 +71,7 @@ typedef EMessageBoxReturn (* PFN_QERAPP_MESSAGEBOX) (GtkWidget *parent, const ch
// - 'title' is the dialog title (can be null)
// - 'path' is used to set the initial directory (can be null)
// - 'pattern': the first pattern is for the win32 mode, then comes the Gtk pattern list, see Radiant source for samples
typedef const char* (* PFN_QERAPP_FILEDIALOG) (GtkWidget *parent, bool open, const char* title, const char* path/* = 0*/, const char* pattern/* = 0*/);
typedef const char* (* PFN_QERAPP_FILEDIALOG) (GtkWidget *parent, bool open, const char* title, const char* path/* = 0*/, const char* pattern/* = 0*/, bool want_load/* = false*/, bool want_import/* = false*/, bool want_save/* = false*/);
// returns a gchar* string that must be g_free'd by the user
typedef char* (* PFN_QERAPP_DIRDIALOG) (GtkWidget *parent, const char* title/* = "Choose Directory"*/, const char* path/* = 0*/);

View File

@ -43,7 +43,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// if the spawn was fine
// TODO TTimo add functionality to track the process until it dies
bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole);
bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor);
// some easy portability crap

View File

@ -36,16 +36,23 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if defined (POSIX)
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
bool Q_Exec(const char *cmd, char *cmdline, const char *, bool, bool waitfor)
{
char fullcmd[2048];
char *pCmd;
pid_t pid;
#ifdef _DEBUG
printf("Q_Exec damnit\n");
#endif
switch (fork())
switch ((pid = fork()))
{
default:
if(waitfor)
waitpid(pid, NULL, 0);
break;
case -1:
return true;
break;
@ -84,7 +91,7 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
#include <windows.h>
// NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole)
bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor)
{
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo = {0};
@ -121,7 +128,11 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateCon
&startupinfo,
&ProcessInformation
))
{
if(waitfor)
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
return true;
}
return false;
}

View File

@ -137,7 +137,7 @@ public:
static char g_file_dialog_file[1024];
const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern, bool want_load, bool want_import, bool want_save)
{
filetype_t type;
@ -147,7 +147,7 @@ const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, co
}
FileTypeList typelist;
GlobalFiletypes().getTypeList(pattern, &typelist);
GlobalFiletypes().getTypeList(pattern, &typelist, want_load, want_import, want_save);
GTKMasks masks(typelist);
@ -288,11 +288,11 @@ char* dir_dialog(GtkWidget* parent, const char* title, const char* path)
return filename;
}
const char* file_dialog(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
const char* file_dialog(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern, bool want_load, bool want_import, bool want_save)
{
for(;;)
{
const char* file = file_dialog_show(parent, open, title, path, pattern);
const char* file = file_dialog_show(parent, open, title, path, pattern, want_load, want_import, want_save);
if(open
|| file == 0

View File

@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/// GTK+ file-chooser dialogs.
typedef struct _GtkWidget GtkWidget;
const char* file_dialog(GtkWidget *parent, bool open, const char* title, const char* path = 0, const char* pattern = 0);
const char* file_dialog(GtkWidget *parent, bool open, const char* title, const char* path = 0, const char* pattern = 0, bool want_load = false, bool want_import = false, bool want_save = false);
/// \brief Prompts the user to browse for a directory.

View File

@ -264,8 +264,9 @@ public:
MapQ3API()
{
GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("quake3 maps", "*.map"));
GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("quake3 region", "*.reg"));
GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("quake3 maps", "*.map", true, true, true));
GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("quake3 region", "*.reg", true, true, true));
GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("quake3 compiled maps", "*.bsp", false, true, false));
}
MapFormat* getTable()
{

View File

@ -35,7 +35,7 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
struct filetype_copy_t
{
filetype_copy_t(const char* moduleName, const filetype_t other)
: m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern)
: m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern), m_can_load(other.can_load), m_can_import(other.can_import), m_can_save(other.can_save)
{
}
const char* getModuleName() const
@ -44,8 +44,11 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
}
filetype_t getType() const
{
return filetype_t(m_name.c_str(), m_pattern.c_str());
return filetype_t(m_name.c_str(), m_pattern.c_str(), m_can_load, m_can_save, m_can_import);
}
bool m_can_load;
bool m_can_import;
bool m_can_save;
private:
CopiedString m_moduleName;
CopiedString m_name;
@ -62,11 +65,14 @@ public:
{
m_typelists[moduleType].push_back(filetype_copy_t(moduleName, type));
}
void getTypeList(const char* moduleType, IFileTypeList* typelist)
void getTypeList(const char* moduleType, IFileTypeList* typelist, bool want_load, bool want_import, bool want_save)
{
filetype_list_t& list_ref = m_typelists[moduleType];
for(filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i)
{
if(want_load && !(*i).m_can_load) return;
if(want_import && !(*i).m_can_import) return;
if(want_save && !(*i).m_can_save) return;
typelist->addType((*i).getModuleName(), (*i).getType());
}
}

View File

@ -1089,7 +1089,7 @@ void DoTextEditor (const char* filename, int cursorpos)
globalOutputStream() << "Launching: " << strEditCommand.c_str() << "\n";
// note: linux does not return false if the command failed so it will assume success
if (Q_Exec(0, const_cast<char*>(strEditCommand.c_str()), 0, true) == false)
if (Q_Exec(0, const_cast<char*>(strEditCommand.c_str()), 0, true, false) == false)
{
globalOutputStream() << "Failed to execute " << strEditCommand.c_str() << ", using default\n";
}

View File

@ -85,6 +85,7 @@ MapModules& ReferenceAPI_getMapModules();
#include "commands.h"
#include "autosave.h"
#include "brushmodule.h"
#include "brush.h"
class NameObserver
{
@ -1637,29 +1638,81 @@ bool Map_ImportFile(const char* filename)
ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
bool success = false;
if(extension_equal(path_get_extension(filename), "bsp"))
goto tryDecompile;
{
Resource* resource = GlobalReferenceCache().capture(filename);
resource->refresh(); // avoid loading old version if map has changed on disk since last import
if(resource->load())
if(!resource->load())
{
NodeSmartReference clone(NewMapRoot(""));
{
//ScopeTimer timer("clone subgraph");
Node_getTraversable(*resource->getNode())->traverse(CloneAll(clone));
}
Map_gatherNamespaced(clone);
Map_mergeClonedNames();
MergeMap(clone);
success = true;
GlobalReferenceCache().release(filename);
goto tryDecompile;
}
NodeSmartReference clone(NewMapRoot(""));
Node_getTraversable(*resource->getNode())->traverse(CloneAll(clone));
Map_gatherNamespaced(clone);
Map_mergeClonedNames();
MergeMap(clone);
success = true;
GlobalReferenceCache().release(filename);
}
SceneChangeNotify();
SceneChangeNotify();
return success;
tryDecompile:
const char *type = GlobalRadiant().getRequiredGameDescriptionKeyValue("q3map2_type");
int n = string_length(path_get_extension(filename));
if(n && (extension_equal(path_get_extension(filename), "bsp") || extension_equal(path_get_extension(filename), "map")))
{
StringBuffer output;
output.push_string(AppPath_get());
output.push_string("q3map2.");
output.push_string(RADIANT_EXECUTABLE);
output.push_string(" -v -game ");
output.push_string((type && *type) ? type : "quake3");
output.push_string(" -fs_basepath \"");
output.push_string(EnginePath_get());
output.push_string("\" -fs_game ");
output.push_string(gamename_get());
output.push_string(" -convert -format ");
output.push_string(Brush::m_type == eBrushTypeQuake3BP ? "map_bp" : "map");
output.push_string(" \"");
output.push_string(filename);
output.push_string("\"");
// run
Q_Exec(NULL, output.c_str(), NULL, false, true);
// rebuild filename as "filenamewithoutext_converted.map"
output.clear();
output.push_range(filename, filename + string_length(filename) - (n + 1));
output.push_string("_converted.map");
filename = output.c_str();
// open
Resource* resource = GlobalReferenceCache().capture(filename);
resource->refresh(); // avoid loading old version if map has changed on disk since last import
if(!resource->load())
{
GlobalReferenceCache().release(filename);
goto tryDecompile;
}
NodeSmartReference clone(NewMapRoot(""));
Node_getTraversable(*resource->getNode())->traverse(CloneAll(clone));
Map_gatherNamespaced(clone);
Map_mergeClonedNames();
MergeMap(clone);
success = true;
GlobalReferenceCache().release(filename);
}
SceneChangeNotify();
return success;
}
/*
@ -1897,12 +1950,17 @@ const char* getMapsPath()
const char* map_open(const char* title)
{
return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name());
return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name(), true, false, false);
}
const char* map_import(const char* title)
{
return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name(), false, true, false);
}
const char* map_save(const char* title)
{
return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name());
return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name(), false, false, true);
}
void OpenMap()
@ -1923,7 +1981,7 @@ void OpenMap()
void ImportMap()
{
const char* filename = map_open("Import Map");
const char* filename = map_import("Import Map");
if(filename != 0)
{

View File

@ -333,7 +333,7 @@ void RunBSP(const char* name)
#endif
globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
Q_Exec(batpath, NULL, NULL, true);
Q_Exec(batpath, NULL, NULL, true, false);
}
}

View File

@ -577,7 +577,7 @@ void CWatchBSP::DoEBeginStep()
globalOutputStream() << "=== running build command ===\n"
<< static_cast<const char*>(g_ptr_array_index( m_pCmd, m_iCurrentStep )) << "\n";
if (!Q_Exec(NULL, (char *)g_ptr_array_index( m_pCmd, m_iCurrentStep ), NULL, true ))
if (!Q_Exec(NULL, (char *)g_ptr_array_index( m_pCmd, m_iCurrentStep ), NULL, true, false ))
{
StringOutputStream msg(256);
msg << "Failed to execute the following command: ";
@ -815,7 +815,7 @@ void CWatchBSP::RoutineProcessing()
globalOutputStream() << cmd.c_str() << " " << cmdline.c_str() << "\n";
// execute now
if (!Q_Exec(cmd.c_str(), (char *)cmdline.c_str(), EnginePath_get(), false))
if (!Q_Exec(cmd.c_str(), (char *)cmdline.c_str(), EnginePath_get(), false, false))
{
StringOutputStream msg;
msg << "Failed to execute the following command: " << cmd.c_str() << cmdline.c_str();