Ticket #2975: 2975.diff

File 2975.diff, 11.0 KB (added by trompetin17, 9 years ago)
  • source/ps/Filesystem.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4646}
    4747
    4848// try to skip unnecessary work by ignoring uninteresting notifications.
    49 static bool CanIgnore(const DirWatchNotification& notification)
     49static bool CanIgnore(const OsPath& pathname)
    5050{
    5151    // ignore directories
    52     const OsPath& pathname = notification.Pathname();
    5352    if(pathname.IsDirectory())
    5453        return true;
    5554
     
    6665    return false;
    6766}
    6867
     68Status 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
    6987Status ReloadChangedFiles()
    7088{
    7189    PROFILE3("hotload");
     
    7492    RETURN_STATUS_IF_ERR(dir_watch_Poll(notifications));
    7593    for(size_t i = 0; i < notifications.size(); i++)
    7694    {
    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;
    9198    }
    9299    return INFO::OK;
    93100}
    94101
     102void ReloadChangedFilesFromAtlas(std::wstring filename)
     103{
     104    const OsPath& osPath(filename);
     105    UpdateVFS(osPath);
     106}
     107
    95108std::wstring GetWstringFromWpath(const fs::wpath& path)
    96109{
    97110#if BOOST_FILESYSTEM_VERSION == 3
  • source/ps/Filesystem.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    5454 **/
    5555extern Status ReloadChangedFiles();
    5656
     57extern void ReloadChangedFilesFromAtlas(std::wstring filename);
     58
    5759/**
    5860 * Helper function to handle API differences between Boost Filesystem v2 and v3
    5961 */
  • source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3232#include "wx/config.h"
    3333#include "wx/debugrpt.h"
    3434#include "wx/file.h"
     35#include <wx/log.h>
    3536
    3637// wx and libxml both want to define ATTRIBUTE_PRINTF (with similar
    3738// meanings), so undef it to avoid a warning
     
    122123    g_ConfigDir = config.GetPath(wxPATH_GET_SEPARATOR);
    123124}
    124125
    125 ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type)
    126 {
    127     // Initialise libxml2
    128     // (If we're executed from the game instead, it has the responsibility to initialise libxml2)
    129     LIBXML_TEST_VERSION
    130    
    131     g_InitialWindowType = type;
    132 #ifdef __WXMSW__
    133     wxEntry(g_Module);
    134 #else
    135 #ifdef __WXGTK__
    136     // Because we do GL calls from a secondary thread, Xlib needs to
    137     // be told to support multiple threads safely
    138     int status = XInitThreads();
    139     if (status == 0)
    140     {
    141         fprintf(stderr, "Error enabling thread-safety via XInitThreads\n");
    142     }
    143 #endif
    144     int argc = 1;
    145     char atlas[] = "atlas";
    146     char *argv[] = {atlas, NULL};
    147 #ifndef __WXOSX__
    148     wxEntry(argc, argv);
    149 #else
    150     // Fix for OS X init (see http://trac.wildfiregames.com/ticket/2427 )
    151     // If we launched from in-game, SDL started NSApplication which will
    152     // break some things in wxWidgets
    153     wxEntryStart(argc, argv);
    154     wxTheApp->OnInit();
    155     wxTheApp->OnRun();
    156     wxTheApp->OnExit();
    157     wxEntryCleanup();
    158 #endif
    159 
    160 #endif
    161 }
    162 
    163126ATLASDLLIMPEXP void Atlas_DisplayError(const wchar_t* text, size_t WXUNUSED(flags))
    164127{
    165128    // This is called from the game thread.
     
    186149class AtlasDLLApp : public wxApp
    187150{
    188151public:
    189 
    190152#ifdef __WXOSX__
    191153    virtual bool OSXIsGUIApplication()
    192154    {
     
    236198            // dragging-and-dropping onto the program in Explorer.)
    237199            Datafile::SetSystemDirectory(argv[0]);
    238200        }
     201       
     202        //Disable log for file watcher
    239203
     204        wxLog::SetLogLevel(wxLOG_FatalError);
    240205        // Display the appropriate window
    241206        wxFrame* frame;
    242207        if (g_InitialWindowType == _T("ActorEditor"))
     
    246211        else if (g_InitialWindowType == _T("ScenarioEditor"))
    247212        {
    248213            frame = new ScenarioEditor(NULL);
     214            m_scenarioEditor = wxDynamicCast(frame, ScenarioEditor);
    249215        }
    250216        else
    251217        {
     
    279245        return true;
    280246    }
    281247
     248    virtual void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop))
     249    {
     250        if (m_scenarioEditor)
     251        {
     252            m_scenarioEditor->OnEventLoopEnter();
     253            m_scenarioEditor = NULL;
     254        }
     255    }
     256
    282257#if wxUSE_DEBUGREPORT && USE_WX_FATAL_EXCEPTION_REPORT
    283258    virtual void OnFatalException()
    284259    {
     
    317292*/
    318293
    319294private:
    320 
     295    ScenarioEditor* m_scenarioEditor;
    321296    bool OpenDirectory(const wxString& dir)
    322297    {
    323298        // Open a directory on the filesystem - used so people can find the
     
    365340};
    366341
    367342IMPLEMENT_APP_NO_MAIN(AtlasDLLApp);
     343
     344ATLASDLLIMPEXP 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

     
    556556    m_Timer.Start(20);
    557557}
    558558
     559void 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
     569ScenarioEditor::~ScenarioEditor()
     570{
     571    m_watcher->RemoveAll();
     572    delete m_watcher;
     573}
     574
     575void 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
    559587wxToolBar* ScenarioEditor::OnCreateToolBar(long style, wxWindowID id, const wxString& WXUNUSED(name))
    560588{
    561589    ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style);
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1919#define INCLUDED_SCENARIOEDITOR
    2020
    2121#include "wx/toolbar.h"
     22#include <wx/fswatcher.h>
    2223
    2324#include "General/AtlasWindowCommandProc.h"
    2425#include "General/Observable.h"
     
    3132{
    3233public:
    3334    ScenarioEditor(wxWindow* parent);
     35    ~ScenarioEditor();
    3436    void OnClose(wxCloseEvent& event);
    3537    void OnTimer(wxTimerEvent& event);
    3638    void OnIdle(wxIdleEvent& event);
     
    5961    void OnDumpState(wxCommandEvent& event);
    6062    void OnSelectedObjectsChange(const std::vector<AtlasMessage::ObjectID>& selectedObjects);
    6163
     64    void OnFileSystemEvent(wxFileSystemWatcherEvent &event);
     65
    6266    void OnMenuOpen(wxMenuEvent& event);
    6367
    6468    bool OpenFile(const wxString& name, const wxString& filename);
     69    void OnEventLoopEnter();
    6570
    6671    void NotifyOnMapReload();
    6772
     
    93100
    94101    wxIcon m_Icon;
    95102
     103    wxFileSystemWatcher* m_watcher;   // file system watcher
     104
    96105    DECLARE_EVENT_TABLE();
    97106};
    98107
  • source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3636#include "renderer/Renderer.h"
    3737#include "simulation2/Simulation2.h"
    3838#include "simulation2/components/ICmpSoundManager.h"
     39#include "ps/Filesystem.h"
    3940
    4041extern void (*Atlas_GLSwapBuffers)(void* context);
    4142
     
    225226    in_dispatch_event(&ev);
    226227}
    227228
     229MESSAGEHANDLER(VFSUpdateFile)
     230{
     231    ReloadChangedFilesFromAtlas(*msg->filePath);
    228232}
     233
     234}
  • source/tools/atlas/GameInterface/Messages.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    200200        ((bool, exists))
    201201        );
    202202
     203MESSAGE(VFSUpdateFile,
     204        ((std::wstring, filePath))
     205        );
     206
    203207//////////////////////////////////////////////////////////////////////////
    204208// Messages for player panel