1
0
Fork 0

Integrate the EmbeddedResourceManager into FlightGear

${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
(currently empty) is automatically "compiled" into
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.[ch]xx by
fgrcc inside the build directory. These files are incorporated into the
FlightGear build (FlightGear-resources.cxx is linked into FlightGear).

When the XML embedded resource declaration file added here,
FlightGear-resources.xml, is compiled, fgrcc is passed the
--root=${CMAKE_SOURCE_DIR} option, so that files referred to in
FlightGear-resources.xml are looked up relatively to the root directory
of the FlightGear repository. One could use a second XML embedded
resource declaration file compiled with a different --root option to
grab files from FGData, for instance. I would name such a file
FGData-resources.xml to be consistent with the current naming scheme.

Note: this --root option applies to the paths of real files. Don't
      confuse it with the 'prefix' attribute of <qresource> elements
      inside XML resource declaration files (such as
      FlightGear-resources.xml), which applies to the virtual path of
      each resource defined beneath.

The commands in src/Main/CMakeLists.txt ensure that
FlightGear-resources.xml is recompiled with fgrcc whenever it is
changed, and obviously also when FlightGear-resources.cxx or
FlightGear-resources.hxx is missing. However, CMake doesn't know how to
parse fgrcc XML resource declaration files, therefore when a resource is
modified but the XML file it is declared in is not (here,
FlightGear-resources.xml), you have to trigger yourself a recompilation
of the XML resource declaration file to see the new resource contents
inside FlightGear. The easiest ways to do so are:
  - either update the timestamp of the XML resource declaration file;
  - or remove one or both of the generated files
    (FlightGear-resources.cxx and FlightGear-resources.hxx here).

The EmbeddedResourceManager is created in fgMainInit() just after
Options::processOptions() set the language that was either requested by
the user or obtained from the system (locales). Resources from
FlightGear-resources.cxx are added to it, after which
EmbeddedResourceManager::selectLocale() is called with the user's
preferred locale (obtained with FGLocale::getPreferredLanguage()).

Upon reset (fgStartNewReset()), EmbeddedResourceManager::selectLocale()
is called in a similar way after Options::processOptions(), however in
this case the EmbeddedResourceManager instance doesn't have to be
recreated.
This commit is contained in:
Florent Rougon 2017-04-28 00:09:14 +02:00
parent acb5650b83
commit b2cc191bc6
4 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Superset of the resource file format used by Qt.
cf. http://doc.qt.io/qt-5/resources.html and 'fgrcc dash-dash-help'
(I can't put a double dash inside an XML comment...) -->
<FGRCC version="1.0">
</FGRCC>

View file

@ -22,6 +22,7 @@ set(SOURCES
subsystemFactory.cxx subsystemFactory.cxx
screensaver_control.cxx screensaver_control.cxx
${RESOURCE_FILE} ${RESOURCE_FILE}
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
) )
set(HEADERS set(HEADERS
@ -40,8 +41,17 @@ set(HEADERS
subsystemFactory.hxx subsystemFactory.hxx
AircraftDirVisitorBase.hxx AircraftDirVisitorBase.hxx
screensaver_control.hxx screensaver_control.hxx
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
) )
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
COMMAND fgrcc --root=${CMAKE_SOURCE_DIR} --output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx --init-func-name=initFlightGearEmbeddedResources --output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx --output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
DEPENDS
fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
)
get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES) get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS) get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS)

View file

@ -60,6 +60,7 @@
#include <simgear/misc/sg_dir.hxx> #include <simgear/misc/sg_dir.hxx>
#include <simgear/io/iostreams/sgstream.hxx> #include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/misc/strutils.hxx> #include <simgear/misc/strutils.hxx>
#include <simgear/embedded_resources/EmbeddedResourceManager.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/scene/tsync/terrasync.hxx> #include <simgear/scene/tsync/terrasync.hxx>
@ -107,6 +108,7 @@
#include <AIModel/submodel.hxx> #include <AIModel/submodel.hxx>
#include <AIModel/AIManager.hxx> #include <AIModel/AIManager.hxx>
#include <AIModel/performancedb.hxx> #include <AIModel/performancedb.hxx>
#include <Main/locale.hxx>
#include <Navaids/navdb.hxx> #include <Navaids/navdb.hxx>
#include <Navaids/navlist.hxx> #include <Navaids/navlist.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
@ -1117,7 +1119,14 @@ void fgStartNewReset()
fgInitGeneral(); // all of this? fgInitGeneral(); // all of this?
flightgear::Options::sharedInstance()->processOptions(); flightgear::Options::sharedInstance()->processOptions();
const auto& resMgr = simgear::EmbeddedResourceManager::instance();
// The language was (re)set in processOptions()
const string locale = globals->get_locale()->getPreferredLanguage();
resMgr->selectLocale(locale);
SG_LOG(SG_GENERAL, SG_INFO,
"EmbeddedResourceManager: selected locale '" << locale << "'");
// PRESERVED properties over-write state from options, intentionally // PRESERVED properties over-write state from options, intentionally
if ( copyProperties(preserved, globals->get_props()) ) { if ( copyProperties(preserved, globals->get_props()) ) {
SG_LOG( SG_GENERAL, SG_INFO, "Preserved state restored successfully" ); SG_LOG( SG_GENERAL, SG_INFO, "Preserved state restored successfully" );

View file

@ -56,6 +56,7 @@ extern bool global_crashRptEnabled;
#include <simgear/math/sg_random.h> #include <simgear/math/sg_random.h>
#include <simgear/misc/strutils.hxx> #include <simgear/misc/strutils.hxx>
#include <Main/locale.hxx>
#include <Model/panelnode.hxx> #include <Model/panelnode.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Sound/soundmanager.hxx> #include <Sound/soundmanager.hxx>
@ -80,6 +81,9 @@ extern bool global_crashRptEnabled;
#include "subsystemFactory.hxx" #include "subsystemFactory.hxx"
#include "options.hxx" #include "options.hxx"
#include <simgear/embedded_resources/EmbeddedResourceManager.hxx>
#include <EmbeddedResources/FlightGear-resources.hxx>
#if defined(HAVE_QT) #if defined(HAVE_QT)
#include <GUI/QtLauncher.hxx> #include <GUI/QtLauncher.hxx>
#endif #endif
@ -537,6 +541,15 @@ int fgMainInit( int argc, char **argv )
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
const auto& resMgr = simgear::EmbeddedResourceManager::createInstance();
initFlightGearEmbeddedResources();
// The language was set in processOptions()
const std::string locale = globals->get_locale()->getPreferredLanguage();
// Must always be done after all resources have been added to 'resMgr'
resMgr->selectLocale(locale);
SG_LOG(SG_GENERAL, SG_INFO,
"EmbeddedResourceManager: selected locale '" << locale << "'");
// Initialize the Window/Graphics environment. // Initialize the Window/Graphics environment.
fgOSInit(&argc, argv); fgOSInit(&argc, argv);
_bootstrap_OSInit++; _bootstrap_OSInit++;