X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fmap.cpp;h=91fb5c51d24d4f8cdf891abfb025ae149c02f423;hb=32833fdf3f6a1ad95ba0574d58160b942a34f673;hp=c846ca7ea7e722aeb89b1a0b7bc581789eed0537;hpb=d584d9454904666d8de69a99dd4fb29e5dbab433;p=xonotic%2Fnetradiant.git diff --git a/radiant/map.cpp b/radiant/map.cpp index c846ca7e..91fb5c51 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -64,6 +64,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "modulesystem/singletonmodule.h" #include "modulesystem/moduleregistry.h" #include "stream/stringstream.h" +#include "signal/signal.h" #include "gtkutil/filechooser.h" #include "timer.h" @@ -311,8 +312,7 @@ public: bool m_modified; void (*m_modified_changed)(const Map&); - typedef std::vector MapValidCallbacks; - MapValidCallbacks m_mapValidCallbacks; + Signal0 m_mapValidCallbacks; WorldNode m_world_node; // "classname" "worldspawn" ! @@ -363,9 +363,9 @@ public: Map g_map; Map* g_currentMap = 0; -void Map_addValidCallback(Map& map, const Callback& callback) +void Map_addValidCallback(Map& map, const SignalHandler& handler) { - map.m_mapValidCallbacks.push_back(callback); + map.m_mapValidCallbacks.connectLast(handler); } bool Map_Valid(const Map& map) @@ -376,7 +376,7 @@ bool Map_Valid(const Map& map) void Map_SetValid(Map& map, bool valid) { map.m_valid = valid; - std::for_each(map.m_mapValidCallbacks.begin(), map.m_mapValidCallbacks.end(), CallbackInvoke()); + map.m_mapValidCallbacks(); } @@ -1408,7 +1408,7 @@ void AddRegionBrushes (void) for(i=0; i<6; i++) { region_sides[i] = &GlobalBrushCreator().createBrush(); - Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(*region_sides[i]); + Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(NodeSmartReference(*region_sides[i])); } region_startpoint = &GlobalEntityCreator().createEntity(GlobalEntityClassManager().findOrInsert("info_player_start", false)); @@ -1416,7 +1416,7 @@ void AddRegionBrushes (void) ConstructRegionBrushes(region_sides, region_mins, region_maxs); ConstructRegionStartpoint(region_startpoint, region_mins, region_maxs); - Node_getTraversable(GlobalSceneGraph().root())->insert(*region_startpoint); + Node_getTraversable(GlobalSceneGraph().root())->insert(NodeSmartReference(*region_startpoint)); } void RemoveRegionBrushes (void) @@ -1870,25 +1870,21 @@ void NewMap() } } -void maps_directory(StringOutputStream& buffer) +CopiedString g_mapsPath; + +const char* getMapsPath() { - ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty"); - buffer << g_qeglobals.m_userGamePath.c_str() << "maps/"; - Q_mkdir(buffer.c_str()); + return g_mapsPath.c_str(); } const char* map_open(const char* title) { - StringOutputStream buf(256); - maps_directory(buf); - return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, buf.c_str(), MapFormat::Name()); + return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name()); } const char* map_save(const char* title) { - StringOutputStream buf(256); - maps_directory(buf); - return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, buf.c_str(), MapFormat::Name()); + return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name()); } void OpenMap() @@ -2232,6 +2228,11 @@ void DoFind() gtk_widget_destroy(GTK_WIDGET(window)); } +void Map_constructPreferences(PreferencesPage& page) +{ + page.appendCheckBox("", "Load last map on open", g_bLoadLastMap); +} + class MapEntityClasses : public ModuleObserver { @@ -2267,10 +2268,34 @@ public: MapEntityClasses g_MapEntityClasses; -void Map_constructPreferences(PreferencesPage& page) +class MapModuleObserver : public ModuleObserver { - page.appendCheckBox("", "Load last map on open", g_bLoadLastMap); -} + std::size_t m_unrealised; +public: + MapModuleObserver() : m_unrealised(1) + { + } + void realise() + { + if(--m_unrealised == 0) + { + ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty"); + StringOutputStream buffer(256); + buffer << g_qeglobals.m_userGamePath.c_str() << "maps/"; + Q_mkdir(buffer.c_str()); + g_mapsPath = buffer.c_str(); + } + } + void unrealise() + { + if(++m_unrealised == 1) + { + g_mapsPath = ""; + } + } +}; + +MapModuleObserver g_MapModuleObserver; #include "preferencesystem.h" @@ -2291,9 +2316,11 @@ void Map_Construct() PreferencesDialog_addSettingsPreferences(FreeCaller1()); GlobalEntityClassManager().attach(g_MapEntityClasses); + Radiant_attachHomePathsObserver(g_MapModuleObserver); } void Map_Destroy() { + Radiant_detachHomePathsObserver(g_MapModuleObserver); GlobalEntityClassManager().detach(g_MapEntityClasses); }