Ticket #2975: 2975.diff
File 2975.diff, 11.0 KB (added by , 9 years ago) |
---|
-
source/ps/Filesystem.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 46 46 } 47 47 48 48 // try to skip unnecessary work by ignoring uninteresting notifications. 49 static bool CanIgnore(const DirWatchNotification& notification)49 static bool CanIgnore(const OsPath& pathname) 50 50 { 51 51 // ignore directories 52 const OsPath& pathname = notification.Pathname();53 52 if(pathname.IsDirectory()) 54 53 return true; 55 54 … … 66 65 return false; 67 66 } 68 67 68 Status UpdateVFS(OsPath filename) 69 { 70 if(!CanIgnore(filename)) 71 { 72 VfsPath pathname; 73 RETURN_STATUS_IF_ERR(g_VFS->GetVirtualPath(filename, pathname)); 74 RETURN_STATUS_IF_ERR(g_VFS->RemoveFile(pathname)); 75 RETURN_STATUS_IF_ERR(g_VFS->RepopulateDirectory(pathname.Parent()/"")); 76 77 // Tell each hotloadable system about this file change: 78 79 for (size_t j = 0; j < g_ReloadFuncs.size(); ++j) 80 g_ReloadFuncs[j].first(g_ReloadFuncs[j].second, pathname); 81 82 RETURN_STATUS_IF_ERR(h_reload(g_VFS, pathname)); 83 } 84 return INFO::OK; 85 } 86 69 87 Status ReloadChangedFiles() 70 88 { 71 89 PROFILE3("hotload"); … … 74 92 RETURN_STATUS_IF_ERR(dir_watch_Poll(notifications)); 75 93 for(size_t i = 0; i < notifications.size(); i++) 76 94 { 77 if(!CanIgnore(notifications[i])) 78 { 79 VfsPath pathname; 80 RETURN_STATUS_IF_ERR(g_VFS->GetVirtualPath(notifications[i].Pathname(), pathname)); 81 RETURN_STATUS_IF_ERR(g_VFS->RemoveFile(pathname)); 82 RETURN_STATUS_IF_ERR(g_VFS->RepopulateDirectory(pathname.Parent()/"")); 83 84 // Tell each hotloadable system about this file change: 85 86 for (size_t j = 0; j < g_ReloadFuncs.size(); ++j) 87 g_ReloadFuncs[j].first(g_ReloadFuncs[j].second, pathname); 88 89 RETURN_STATUS_IF_ERR(h_reload(g_VFS, pathname)); 90 } 95 Status result = UpdateVFS(notifications[i].Pathname()); 96 if (result < 0) 97 return result; 91 98 } 92 99 return INFO::OK; 93 100 } 94 101 102 void ReloadChangedFilesFromAtlas(std::wstring filename) 103 { 104 const OsPath& osPath(filename); 105 UpdateVFS(osPath); 106 } 107 95 108 std::wstring GetWstringFromWpath(const fs::wpath& path) 96 109 { 97 110 #if BOOST_FILESYSTEM_VERSION == 3 -
source/ps/Filesystem.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 54 54 **/ 55 55 extern Status ReloadChangedFiles(); 56 56 57 extern void ReloadChangedFilesFromAtlas(std::wstring filename); 58 57 59 /** 58 60 * Helper function to handle API differences between Boost Filesystem v2 and v3 59 61 */ -
source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 32 32 #include "wx/config.h" 33 33 #include "wx/debugrpt.h" 34 34 #include "wx/file.h" 35 #include <wx/log.h> 35 36 36 37 // wx and libxml both want to define ATTRIBUTE_PRINTF (with similar 37 38 // meanings), so undef it to avoid a warning … … 122 123 g_ConfigDir = config.GetPath(wxPATH_GET_SEPARATOR); 123 124 } 124 125 125 ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type)126 {127 // Initialise libxml2128 // (If we're executed from the game instead, it has the responsibility to initialise libxml2)129 LIBXML_TEST_VERSION130 131 g_InitialWindowType = type;132 #ifdef __WXMSW__133 wxEntry(g_Module);134 #else135 #ifdef __WXGTK__136 // Because we do GL calls from a secondary thread, Xlib needs to137 // be told to support multiple threads safely138 int status = XInitThreads();139 if (status == 0)140 {141 fprintf(stderr, "Error enabling thread-safety via XInitThreads\n");142 }143 #endif144 int argc = 1;145 char atlas[] = "atlas";146 char *argv[] = {atlas, NULL};147 #ifndef __WXOSX__148 wxEntry(argc, argv);149 #else150 // Fix for OS X init (see http://trac.wildfiregames.com/ticket/2427 )151 // If we launched from in-game, SDL started NSApplication which will152 // break some things in wxWidgets153 wxEntryStart(argc, argv);154 wxTheApp->OnInit();155 wxTheApp->OnRun();156 wxTheApp->OnExit();157 wxEntryCleanup();158 #endif159 160 #endif161 }162 163 126 ATLASDLLIMPEXP void Atlas_DisplayError(const wchar_t* text, size_t WXUNUSED(flags)) 164 127 { 165 128 // This is called from the game thread. … … 186 149 class AtlasDLLApp : public wxApp 187 150 { 188 151 public: 189 190 152 #ifdef __WXOSX__ 191 153 virtual bool OSXIsGUIApplication() 192 154 { … … 236 198 // dragging-and-dropping onto the program in Explorer.) 237 199 Datafile::SetSystemDirectory(argv[0]); 238 200 } 201 202 //Disable log for file watcher 239 203 204 wxLog::SetLogLevel(wxLOG_FatalError); 240 205 // Display the appropriate window 241 206 wxFrame* frame; 242 207 if (g_InitialWindowType == _T("ActorEditor")) … … 246 211 else if (g_InitialWindowType == _T("ScenarioEditor")) 247 212 { 248 213 frame = new ScenarioEditor(NULL); 214 m_scenarioEditor = wxDynamicCast(frame, ScenarioEditor); 249 215 } 250 216 else 251 217 { … … 279 245 return true; 280 246 } 281 247 248 virtual void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop)) 249 { 250 if (m_scenarioEditor) 251 { 252 m_scenarioEditor->OnEventLoopEnter(); 253 m_scenarioEditor = NULL; 254 } 255 } 256 282 257 #if wxUSE_DEBUGREPORT && USE_WX_FATAL_EXCEPTION_REPORT 283 258 virtual void OnFatalException() 284 259 { … … 317 292 */ 318 293 319 294 private: 320 295 ScenarioEditor* m_scenarioEditor; 321 296 bool OpenDirectory(const wxString& dir) 322 297 { 323 298 // Open a directory on the filesystem - used so people can find the … … 365 340 }; 366 341 367 342 IMPLEMENT_APP_NO_MAIN(AtlasDLLApp); 343 344 ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type) 345 { 346 // Initialise libxml2 347 // (If we're executed from the game instead, it has the responsibility to initialise libxml2) 348 LIBXML_TEST_VERSION 349 350 g_InitialWindowType = type; 351 #ifdef __WXMSW__ 352 wxEntry(g_Module); 353 #else 354 #ifdef __WXGTK__ 355 // Because we do GL calls from a secondary thread, Xlib needs to 356 // be told to support multiple threads safely 357 int status = XInitThreads(); 358 if (status == 0) 359 { 360 fprintf(stderr, "Error enabling thread-safety via XInitThreads\n"); 361 } 362 #endif 363 int argc = 1; 364 char atlas[] = "atlas"; 365 char *argv[] = {atlas, NULL}; 366 #ifndef __WXOSX__ 367 wxEntry(argc, argv); 368 #else 369 // Fix for OS X init (see http://trac.wildfiregames.com/ticket/2427 ) 370 // If we launched from in-game, SDL started NSApplication which will 371 // break some things in wxWidgets 372 wxApp::SetInstance(new AtlasDLLApp()); 373 wxEntry(argc, argv); 374 #endif 375 376 #endif 377 } 378 No newline at end of file -
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
556 556 m_Timer.Start(20); 557 557 } 558 558 559 void ScenarioEditor::OnFileSystemEvent(wxFileSystemWatcherEvent &event) 560 { 561 wxFileName file = event.GetPath(); 562 if (!file.IsDir()) 563 { 564 wxString filename = file.GetFullPath(); 565 POST_MESSAGE(VFSUpdateFile, (filename.wc_str())); 566 } 567 } 568 569 ScenarioEditor::~ScenarioEditor() 570 { 571 m_watcher->RemoveAll(); 572 delete m_watcher; 573 } 574 575 void ScenarioEditor::OnEventLoopEnter() 576 { 577 //start watcher 578 m_watcher = new wxFileSystemWatcher(); 579 m_watcher->SetOwner(this); 580 Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler(ScenarioEditor::OnFileSystemEvent)); 581 582 wxString filename = Datafile::GetDataDirectory(); 583 const wxFileName fn = wxFileName::DirName(filename); 584 m_watcher->AddTree(fn); 585 } 586 559 587 wxToolBar* ScenarioEditor::OnCreateToolBar(long style, wxWindowID id, const wxString& WXUNUSED(name)) 560 588 { 561 589 ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style); -
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 19 19 #define INCLUDED_SCENARIOEDITOR 20 20 21 21 #include "wx/toolbar.h" 22 #include <wx/fswatcher.h> 22 23 23 24 #include "General/AtlasWindowCommandProc.h" 24 25 #include "General/Observable.h" … … 31 32 { 32 33 public: 33 34 ScenarioEditor(wxWindow* parent); 35 ~ScenarioEditor(); 34 36 void OnClose(wxCloseEvent& event); 35 37 void OnTimer(wxTimerEvent& event); 36 38 void OnIdle(wxIdleEvent& event); … … 59 61 void OnDumpState(wxCommandEvent& event); 60 62 void OnSelectedObjectsChange(const std::vector<AtlasMessage::ObjectID>& selectedObjects); 61 63 64 void OnFileSystemEvent(wxFileSystemWatcherEvent &event); 65 62 66 void OnMenuOpen(wxMenuEvent& event); 63 67 64 68 bool OpenFile(const wxString& name, const wxString& filename); 69 void OnEventLoopEnter(); 65 70 66 71 void NotifyOnMapReload(); 67 72 … … 93 100 94 101 wxIcon m_Icon; 95 102 103 wxFileSystemWatcher* m_watcher; // file system watcher 104 96 105 DECLARE_EVENT_TABLE(); 97 106 }; 98 107 -
source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 36 36 #include "renderer/Renderer.h" 37 37 #include "simulation2/Simulation2.h" 38 38 #include "simulation2/components/ICmpSoundManager.h" 39 #include "ps/Filesystem.h" 39 40 40 41 extern void (*Atlas_GLSwapBuffers)(void* context); 41 42 … … 225 226 in_dispatch_event(&ev); 226 227 } 227 228 229 MESSAGEHANDLER(VFSUpdateFile) 230 { 231 ReloadChangedFilesFromAtlas(*msg->filePath); 228 232 } 233 234 } -
source/tools/atlas/GameInterface/Messages.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 200 200 ((bool, exists)) 201 201 ); 202 202 203 MESSAGE(VFSUpdateFile, 204 ((std::wstring, filePath)) 205 ); 206 203 207 ////////////////////////////////////////////////////////////////////////// 204 208 // Messages for player panel