X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fmap.cpp;h=7b8c570de4d5f54610ee5cfa7d6a24c9e6203fc5;hb=cc6bdd4869b80171d5690094f46254ecc2a2e860;hp=ece542bb1a25ca6cc6c1b0cff841e36370dbfbd8;hpb=182f62c459ad1b9e5439fd9d1f141e29c0138840;p=xonotic%2Fnetradiant.git diff --git a/radiant/map.cpp b/radiant/map.cpp index ece542bb..7b8c570d 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -85,6 +85,7 @@ MapModules& ReferenceAPI_getMapModules(); #include "commands.h" #include "autosave.h" #include "brushmodule.h" +#include "brush.h" class NameObserver { @@ -1032,29 +1033,28 @@ void Map_LoadFile (const char *filename) 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()); + 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); - const MapFormat* format = ReferenceAPI_getMapModules().findModule("mapq3"); - format->wrongFormat = false; - g_map.m_resource->attach(g_map); - if(format->wrongFormat) + for(int i = 0; i < Brush_toggleFormatCount(); ++i) { - // try toggling BrushPrimitives - for(i = 1; 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()); - g_map.m_resource->attach(g_map); - } + 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()); @@ -1638,28 +1638,80 @@ 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; } @@ -1898,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() @@ -1924,7 +1981,7 @@ void OpenMap() void ImportMap() { - const char* filename = map_open("Import Map"); + const char* filename = map_import("Import Map"); if(filename != 0) {