#include "debugging/debugging.h"
#include "imap.h"
+MapModules& ReferenceAPI_getMapModules();
#include "iselection.h"
#include "iundo.h"
#include "ibrush.h"
#include "mru.h"
#include "commands.h"
#include "autosave.h"
+#include "brushmodule.h"
+#include "brush.h"
class NameObserver
{
FlushReferences();
g_currentMap = 0;
+ Brush_unlatchPreferences();
}
class EntityFindByClassname : public scene::Graph::Walker
globalOutputStream() << "Loading map from " << filename << "\n";
ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
- g_map.m_name = filename;
- Map_UpdateTitle(g_map);
-
{
ScopeTimer timer("map load");
- g_map.m_resource = GlobalReferenceCache().capture(g_map.m_name.c_str());
- g_map.m_resource->attach(g_map);
+ const MapFormat* format = NULL;
+ const char* moduleName = findModuleName(&GlobalFiletypes(), MapFormat::Name(), path_get_extension(filename));
+ if(string_not_empty(moduleName))
+ format = ReferenceAPI_getMapModules().findModule(moduleName);
+
+ for(int i = 0; i < Brush_toggleFormatCount(); ++i)
+ {
+ if(i)
+ Map_Free();
+ Brush_toggleFormat(i);
+ g_map.m_name = filename;
+ Map_UpdateTitle(g_map);
+ g_map.m_resource = GlobalReferenceCache().capture(g_map.m_name.c_str());
+ if(format)
+ format->wrongFormat = false;
+ g_map.m_resource->attach(g_map);
+ if(format)
+ if(!format->wrongFormat)
+ break;
+ }
Node_getTraversable(GlobalSceneGraph().root())->traverse(entity_updateworldspawn());
}
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;
}
/*
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()
void ImportMap()
{
- const char* filename = map_open("Import Map");
+ const char* filename = map_import("Import Map");
if(filename != 0)
{