Compare commits

..

521 Commits

Author SHA1 Message Date
Automatic Release Builder
332d9dfadb new version: 2020.3.8 2021-03-24 11:08:07 +00:00
Automatic Release Builder
c05802a498 new version: 2020.3.8 2021-03-24 11:04:18 +00:00
James Turner
0970bb1be2 Fix for local particle update
See issue at:
https://sourceforge.net/p/flightgear/codetickets/2568/
2021-03-24 09:59:13 +00:00
James Turner
c9d83fab6c TerraSync: allow an explicit osm2city server
Fixes an error case where a manual TerraSync server is specified; we
would attempt to use an empty string as the OSM2City server, with
hilarious consequences.

Sentry-Id: FLIGHTGEAR-NCZ
2021-03-16 20:14:34 +00:00
James Turner
edcce32f24 Remove stray include of std::filesystem 2021-03-07 10:53:36 +00:00
Automatic Release Builder
68d265f0e7 Set correct version files 2021-03-04 22:02:11 +00:00
Automatic Release Builder
b985bb5757 new version: 2020.3.7 2021-03-01 12:11:33 +00:00
legoboyvdlp R
f030816385 TerraSync: counter to fetch number of bytes which have been extracted from a tarball file 2021-03-01 09:56:48 +00:00
James Turner
6f9f694eff HTTPRepository: improving handling of archives
Avoid hard-coding the archive extension, and ensure the extracted
archive directory is not orphaned on update. Finally, use the
literal filename in the .dirindex when computing the hash, rather
than adding a .tgz extension.
2021-03-01 09:56:48 +00:00
James Turner
a0d7f0e172 TerraSync: allow separate OSM2City server
Lookup OSM2City using a separate service profile, and use this server
for requests for OSM2City suffix dirs.
2021-03-01 09:51:24 +00:00
James Turner
9f98e438cb Fix HTTPClient reset() behaviour
Ensure all data members are correctly re-initialzied when doing a reset.

This shoed up as negative ‘bytes downloaded’ counts after a TerraSync
abandon and retry.
2021-02-22 11:29:05 +00:00
James Turner
f029ca7b64 Particles: replace use of ParticleSystemUpdater
Extend our own particle manager to replace the OSG particle system
updater. This fixes thread-safety and also timing (better match to
simulation dt values). We also use weak pointers (observer_ptr in
OSG terminology) to ensure particle systems are released once their
frame is gone.
2021-02-22 11:29:05 +00:00
James Turner
ca6c6dd6d3 Text-animation: fix missing encoding specification
Ensure we can pass full UTF-8 strings into text animations. Will consider
for back-port after discussion on the devel list.

Ticket-Id: https://sourceforge.net/p/flightgear/codetickets/2512/
2021-02-22 11:10:37 +00:00
Automatic Release Builder
4ba4ea5602 Adding code to see if it improves crash on computeHash.
Also add a test case to verify behaviour on empty files is correct.

Sentry-Id: FLIGHTGEAR-AY2
2021-02-04 10:28:08 +00:00
Automatic Release Builder
ca5f66da9f new version: 2020.3.6 2021-01-20 13:01:25 +00:00
James Turner
92d053d850 Tolerate blank lines in buildings lists 2021-01-20 11:35:33 +00:00
Colin Geniet
001ae80723 Animations: Fix spin for Compositor lights
The 'spin' animation has a strange behaviour:
it pushes a temporary rotation matrix on the transformation stack during
cull traversal, and removes it thereafter.
Thus, the rotation matrix is missing outside of cull traversal, e.g.
when the position of Compositor lights is computed.

The same issue was fixed for the 'rotate' animation by commit
e202d4e4a5
(this mentions broken 'picking' animations as a different manifestation
of the same issue).

Fix this by setting the angle of the persistent SGRotateTransform,
instead of creating a temporary rotation matrix.
2021-01-15 15:45:26 +00:00
James Turner
58d9a6d0b5 Sentry: adjust reporting of missing shaders
Reduce noise on the backend when a shader is missing, by special-
casing how we report it.
2021-01-05 12:58:46 +00:00
Scott Giese
261316cb45 Support Boost v1.75
Resolved a breaking change.
2021-01-02 21:57:54 -06:00
Stuart Buchanan
2ad4d2e672 Fix hang on "Loading Scenery" over the sea
Previously attempting to start on an ocean tile with static
models present cause FG to spin on "Loading Scenery".

This was caused by not creating a BVH for an ocean tile in
the specific case where there was STG models, due to a PagedLOD
node being inserted in the scene graph.  So
FG never thought the scenery was loaded sufficient to place
the aircraft.

By explicitly creating a BVH for ocean tiles the problem is
fixed.

Candidate for 2020.X
2021-01-01 22:41:47 +00:00
James Turner
1d9fa929fa Launhcer: fix crashes adding a catalog
Traversing a container which is modified causes crashes, take a copy
during traversal for firePackageStatus.

Sentry-Id: FLIGHTGEAR-CJF
Sentry-Id: FLIGHTGEAR-CJ5
2021-01-01 22:41:42 +00:00
James Turner
26bb6236a0 Effect builder: catch allocation failures
Fail on bad_alloc of reading texture images, instead of crashing.
2020-12-28 15:08:49 +00:00
Scott Giese
b2acf5a623 fix: sky and cockpit to turn black
Metar sky condition without base layer height (e.g. FEW///) is the cause of this issue.
Randomize the base layer height when the actual height is unknown.
2020-12-26 10:53:49 -06:00
James Turner
bea88bb3a9 Fix BTG error reporting
Use gzerror, not strerror, for these codes.
2020-12-21 15:31:36 +00:00
Automatic Release Builder
def2af2bdd new version: 2020.3.5 2020-12-17 13:48:00 +00:00
Fernando García Liñán
6f6d705f22 Add support for anisotropic filtering in Canvas 2020-12-17 13:00:01 +00:00
Richard Harrison
e9c33104d3 DDS-TC add option to exclude all Canvas orignated images. 2020-12-17 12:59:26 +00:00
Richard Harrison
985897f8ba Emesary : change to use scoped lock
- scoped locks using lock_guard are better
- because of this the exception handler can also be removed;
  although this was originally intended to manage the locks
  it never did work properly with C++ exceptions.
2020-12-17 12:57:53 +00:00
Richard Harrison
4251b28e88 Emesary: add missing property initialisation to constructor 2020-12-17 12:56:49 +00:00
James Turner
76540a211c SGGeod: add static constructor of an invalid Geod
Use this to allow explicitly initializing a value which isValid
will return false for.
2020-12-17 12:55:30 +00:00
James Turner
904fc5a7dd Fix Nasal GC errors on tests/reset
Ensure the Context temps are cleared, and when recycling an naCode,
ensure old values are cleared explicily.

Sentry-Id: FLIGHTGEAR-Y
2020-12-17 12:55:25 +00:00
Stuart Buchanan
4aebc159d5 Use ref_ptr for ReaderWriterSPT 2020-12-07 17:18:32 +00:00
Richard Harrison
f89227fc1a Remove mutex lock on realizeTechniques
This was causing a deadlock - and I can't quite remember what problem it was intended to solve so it is best to remove it.
2020-12-07 17:17:44 +00:00
James Turner
f50f383cc0 Reporting of std::bad_alloc in Subsystem::update
Trying to trace down our bad-alloc exception, starting with the simplest
place for now.
2020-12-07 17:16:58 +00:00
James Turner
706ab387de Add reporting callback option to SimGear
Allows us to trigger an error logging callback explicitly, which can
be used to drive Sentry.io on the FlightGear side.
2020-12-07 17:16:47 +00:00
James Turner
cddfdb7d1d TerraSync: stronger fix for handling 0-byte files
Change logic so we create an empty file for such cases, i.e exactly
matching the repository. This simplifies logic in downstream code,
compared with not creating a local file.

Add a test-case to cover this

Modify TerraSync to detect a failure of Airports_archive downloading,
and fall back to file-by-file updating.
2020-12-07 17:15:51 +00:00
James Turner
3c64578848 HTTPRepository: don’t crash on empty files
Fix some additional crash cases around 0-length files
2020-12-07 17:15:38 +00:00
James Turner
e1fe9b45e0 Unzip: adjust error reporting mechanism
Don’t use local exception throw+catch to report failures in extracting
a zip archive, since this generates noise in Sentry.
2020-12-07 17:15:30 +00:00
James Turner
8fdc1d306f State-machines: don’t require name for transitions
Allow anonymous transitions, since the name is purely informational
(unlike for states).

Sentry-Id: FLIGHTGEAR-9H
2020-12-07 17:15:17 +00:00
Automatic Release Builder
6e0c39bb68 new version: 2020.3.4 2020-11-30 11:17:52 +00:00
Julian Smith
f20b416cfe simgear/props/props.cxx: use rmutex to protect SGPropertyNodeListeners.
Also added asserts to check _num_iterators always >= 0.
2020-11-29 20:16:46 +00:00
Scott Giese
47e06b5216 METAR: mitigate wind sensor failures 2020-11-29 16:25:01 +00:00
James Turner
bfcdf22705 TerraSync: fix crashes with null file return
Not sure how this is happening, but, check for a null file object
in FileGetRequest::onDone.
2020-11-29 16:23:44 +00:00
Stuart Buchanan
d0db407faa Set minimum expiry time on STG nodes. 2020-11-29 16:23:40 +00:00
Automatic Release Builder
d95b1c0441 new version: 2020.3.3 2020-11-12 11:14:23 +00:00
James Turner
837ba86d57 DNSClient: own requests, and cancel them on timeout
Fixes crashes where a request times-out, but then is completed by
UDN sometime afterwards, with a free-d object. Have the DNS::Client own
requests, and be able to retrieve the udns_query to cancel them, in 
the timeout case.

Fixes a couple of Sentry reports.
2020-11-12 09:39:58 +00:00
Automatic Release Builder
0cb1b463e1 Catalogs: fix ownership of new Catalogs
When doing the initial download of a Catalog, ensure we still keep
an owning ref to it.
2020-11-11 21:18:57 +00:00
Automatic Release Builder
8a772c8edd new version: 2020.3.2 2020-11-04 22:08:28 +00:00
James Turner
03bdad0a10 Try to capture cause of BTG load failures 2020-11-04 11:52:58 +00:00
James Turner
537776e1f8 TerraSync: fix local-file copying
Avoid downloading data corresponding to files shipped in FGData.
2020-11-04 11:22:48 +00:00
James Turner
f34a4a304e Untar: log error details when output create fails
Trying to understand why writing to the output files fails for some
users.

Sentry-Id: FLIGHTGEAR-SS
2020-11-03 21:26:03 +00:00
James Turner
a59c4e2c8b TerraSync: make tarball extraction asynchronous 2020-11-03 17:49:19 +00:00
Julian Smith
46f4967f6e Allow use of old zlib-1.2.3 on OpenBSD.
As of 2020-08-01, OpenBSD's system zlib is 1.2.3 which doesn't
have gzoffset(). However we can get away with this by making
gzfilebuf::approxOffset() always return zero.
2020-11-01 11:12:00 +00:00
James Turner
9305417207 Terrasync: tarball extraction, use larger buffer
Use a 1MB buffer, 2kByte is very 1979 :)
2020-11-01 11:11:31 +00:00
James Turner
11da8b33f9 TerraSync: switch to per-directory hash caching
Avoid a central hash cache becoming enormous, now we use the selective
download scheme for the tile dirs.

Hash name is changed to co-exist with older versions.
2020-11-01 11:11:27 +00:00
James Turner
c7b320eb55 Fix Airports/ initial sync 2020-11-01 11:11:23 +00:00
James Turner
72b2eb0ebf TerraSync: avoid 404s to probe missing tiles
Use the top-level dirIndex files to determine if a 1x1 tile dir
exists, instead of proving the server via a 404. This reduces the
number of requests we make considerably, which is … important.
2020-11-01 11:11:19 +00:00
James Turner
ec3829addb TerraSync: validate local dirs incrementally
Add a process() method to HTTPRepository, and use this to
incrementally validate subdirs after the .dirIndex is received. This 
avoids large pauses of the TerraSync thread, when all of Airports/
is validated at once.
2020-11-01 11:11:15 +00:00
James Turner
96bafef3f3 TerraSync: use an unordered_map for the hash cache
Linear-scan is a bit slow in debug builds, for the large Airports/ tree;
switch to an unordered_map.

Will back-port to the LTS once tested a bit more.
2020-11-01 11:11:12 +00:00
James Turner
3ff3bd0a6c Props: allow flushing the atomic change listener
Trying to narrow down causes of the ‘unregister listeners crashes on
shutdown’ reports.
2020-11-01 11:11:07 +00:00
Automatic Release Builder
78d073a0f0 new version: 2020.3.1 2020-10-26 09:09:22 +00:00
Scott Giese
d62796c19d METAR: When Wind unit not specified, default to knots.
FLIGHTGEAR-F6 resolved
2020-10-26 08:58:06 +00:00
Scott Giese
7ea7ff43fc METAR Wind Sensor Failure.
FLIGHTGEAR-F9 resolved.
2020-10-26 08:57:24 +00:00
James Turner
dafd185595 Fix for crash reported by Michael Danilov
In case uDNS returns a NULL txt pointer, don’t try to create a
std::string from it, since this will crash,

See: https://sourceforge.net/p/flightgear/codetickets/2398/
2020-10-26 08:54:18 +00:00
Automatic Release Builder
1568ed8b97 Catalog migration: migrate packages too
When doing a catalog migration to a new ID (eg, 2018 -> 2020), also
mark the installed packages for installation, on the new catalog.

Related to this, when manually removing a catalog, record this fact,
so we don’t re-add it automatically due to migration.

Add unit-tests covering both of these cases.
2020-10-22 21:27:47 +01:00
Automatic Release Builder
444e2ffb2d Sound: readWAV: avoid common exceptions.
Avoid exceptions for the common ‘file not found’ case, and instead
return false / nullptr. Erik says it’s fine.
2020-10-15 17:00:30 +01:00
Automatic Release Builder
32ccdaec6f Update version file 2020-10-13 22:27:38 +01:00
Automatic Release Builder
bd9f04d980 TerraSync: retry after socket failures
Assume socket failures are intermittent, up to some maximum count
(currently configured as 16). Add a test case to cover this.
2020-10-13 11:38:35 +01:00
Automatic Release Builder
9c530d6978 TerraSync: Rate-limit hash-cache writes
This helps with IO-limited performance on Windows
2020-10-07 12:23:33 +01:00
Automatic Release Builder
05094510be SGPath: optimise exists() on Windows
For a very common existence only check, use a dedicated win32 API
function, to save some time.
2020-10-07 12:21:49 +01:00
Automatic Release Builder
41e43eeba0 TerraSync: fix Windows behaviour
SGDir on Windows returns dot-files by default, which includes our
hash-cache, causing it to be orphaned.
2020-10-06 23:51:06 +01:00
Automatic Release Builder
f95cbd703a Add a hasInstance to ResourceManager
This is needed to allow order-independent shutdown, due to the dumb
ownership behaviour for providers.
2020-10-06 11:34:03 +01:00
Automatic Release Builder
e39036a635 SGFile::computeHash: check malloc result
Trying to fix a reported crash, in this code. malloc() returning null
seems unlikely but worth checking for. ALso use a unique_ptr with
a custom deleter to avoid a leak if we throw.

Sentry-Id: FLIGHTGEAR-3Y
2020-10-06 11:33:17 +01:00
Automatic Release Builder
1171d57b72 XMLSound: Avoid using exceptions for missing file
Reducing how noisy our exception reporting is, by using simple return
value from SGXMLSound::init.
2020-10-05 14:21:37 +01:00
Automatic Release Builder
852058150b TerraSync: fast start Airports/ sync
If TerraSync/Airports is missing, download Airport_archive.tgz instead.
In all other cases update as normal. This has the effect, that fresh
installs make many fewer requests to TerraSync servers.
2020-10-05 11:58:03 +01:00
Automatic Release Builder
9be955262e Terrasync: re-add persistent update cache
Re-add (with some tweaks) the persistent tile-cache code, so that
TerraSync checks the server at most once per 24 hour period, for a
given repository path.

(Disbale the cache by setting /sim/terrasync/enable-persistent-cache=0)
2020-10-01 10:00:22 +01:00
Automatic Release Builder
bfa411e9b7 Packages: fix circular refernece bug
Packages had a strong back-pointer to their catalog, creating a circular
reference loop. Break this so catalogs & packages are freed on exit.
2020-09-30 15:16:41 +01:00
Automatic Release Builder
dab015742a Catalogs: fix enabling/disabling
Relates to bug Michael found in the launcher:
https://sourceforge.net/p/flightgear/codetickets/2380/
2020-09-30 14:38:35 +01:00
Automatic Release Builder
0ab81d36b9 TerraSync: tweak warnings around checksum failures
Trying to reduce log spam when there is a server-side failure.
2020-09-29 17:43:18 +01:00
Automatic Release Builder
4d905135e8 Set optimisation flags for RelwithDebInfo
Ensure we use-O3 for AppImage (RelWithDebInfo) builds
2020-09-27 11:15:28 +01:00
Automatic Release Builder
afad224ca0 Fix level of terrasync start/stop messages 2020-09-25 13:54:36 +01:00
Automatic Release Builder
99c159d46e Harden Repo::computeHashForPath
Check for some error cases in computeHashForPath, since this showed up
in some crash reports.
2020-09-23 22:08:55 +01:00
Automatic Release Builder
733efd08dd Exceptions: optional callback for exception throws.
This is to allow recording an error+stacktrace whenever an exception
is thrown, since that’s the point when the stack is interesting.
2020-09-22 15:26:33 +01:00
James Turner
3753c62783 Add MANDATORY_INFO log priority.
New log-level to avoid using ‘ALERT’ for expected mandatory messages,
since I want to do error collection on real alerts in a future commit.

As part of this, split logstream.hxx into separate header files, and
add a new virtual hook to LogCallback which takes the complete log-entry
2020-09-18 14:49:33 +01:00
James Turner
3e804605b7 ASan: make copied files in log entries safe at init.
Ensure that if we copy file-names of log entries while startup
logging is active, we free them, but only once startup logging is
disabled, or on shutdown. This is needed to avoid crashes when
we use file-name copying for the Qt message handler.
2020-09-18 14:49:33 +01:00
Stuart Buchanan
35b1d321fe Check correctly for failed BUILDING_LIST
Previous additional checks for a value BUILDING_LIST entry
used an enum incorrectly, resulting in all BUILDING_LIST entries
failing.  Now fixed to check bad() / fail() which are bool.
2020-09-09 21:59:24 +01:00
James Turner
6ab7f68f4b Bindings: don’t cache the command pointer
Caching it complicates add/remove command logic, so making a simple
fix for now, which can be back-ported to 2020.2; ideally we would
cache the pointer but have an invalidation scheme, but that’s
considerably more work and risk.

Relates to Sentry crash:
https://sentry.io/organizations/flightgear/issues/1858764364
2020-09-06 15:23:52 +01:00
James Turner
b2e149a737 Refactor SGBuildingBin
Trying to trace a crash that was reported, but along the way fix a leak
of BuildingBins. Also avoid allocating some std::strings on the heap.
2020-09-06 15:23:48 +01:00
Erik Hofman
e28c4fa5ca Mipmapping requires a power-of-two destination buffer even if the source isn't. Neglecting this causes a massive bufferoverflow of the destination buffer. So for now we do not mipmap non-power-of-two textures and throw a warning. This affects at least the PC-9M and F-16, presumable many others. The effect will be a black texture when zoomed out and the proper texture when zooming in close enough. 2020-09-06 15:23:37 +01:00
Automatic Release Builder
61dc19f635 Fix for SGTexturedTriangleBin leaks
Adapted from next commit
0d5552851b
2020-09-06 15:23:21 +01:00
Automatic Release Builder
60634bc445 Fix include that dropped when squashing. 2020-08-26 14:21:45 +01:00
Hans Kunkell
b3e93eaf6e new method: makeStringSafeForPropertyName, replaces invalid chars 2020-08-26 10:37:54 +01:00
James Turner
36dca92c2b HTTPRepo: Fix ownership of HTTPDirectory 2020-08-26 10:37:54 +01:00
James Turner
5a1ed52d7c Particles: rewrite global manager for thread-safety
Avoid re-registering the global node callback each time a new particle
animation is loaded, and use mutexes to protected all shared data.
2020-08-26 10:37:54 +01:00
James Turner
fd191b51ce Avoid a race in MatModels loading
Add a mutex to ensure an SGMatModels only loads its models once. Caught
be ASan, hurrah.
2020-08-26 10:37:54 +01:00
James Turner
6167159795 API to reset the shared tree geometry 2020-08-26 10:37:54 +01:00
James Turner
672afdbc34 Fix for sprintf of nil numeric in Nasal
Spotted by valgrind, w00t. If you used a numerical formatter, such
as f,d or g, with. a nil value, we would read uninitialised data, and
generally get confused.
2020-08-26 10:37:54 +01:00
James Turner
27e61b3dec Ensure SGTerraSync::unbind drops all properties
Avoid some noise on reset, by dropping /all/ our SGPropertyNodes
2020-08-26 10:37:54 +01:00
legoboyvdlp R
f1d00c9b40 Drizzle is considered to be light rain. Backportable to 2020.2. Fixes ticket 1792 2020-08-26 10:37:54 +01:00
James Turner
1b00ece8c4 SGBuildingBin: avoid read of un-inited memory
Where the building line is not as long as expected, ensure we read
valid memory.
2020-08-26 10:37:54 +01:00
James Turner
d0f24229b2 HTTP: Use curl_multi_wait everywhere
Also check the result of the curl methods, in case they fail
2020-08-26 10:37:54 +01:00
Richard Harrison
ab8795f6dc Directional lighting fix
getLights modified to use points rather than triangles based on the configuration.

This fixes point lights (with directional disabled) on AMD
2020-08-26 10:37:42 +01:00
James Turner
2fe60c9635 Terraysnc: fix incorrect handling of ‘entirely ocean’ tiles
We had some confusion between two error codes, meaning we would log an
error (and treat as a failure) a pure ocean 1x1 area, even though this
was entirely correct and expected behaviour.

Terrasync.cxx expected REPO_ERROR_NOT_FOUND, we need to convert the
file-level error to that, and avoid logging a warning.
2020-08-25 21:10:54 +01:00
James Turner
27a3ee3bce TerraSync: restart after max-errors is exceeded.
When we trip the max-error count for a session, back off for a period
of time and then retry (selecting a new TerraSync server).
2020-08-25 21:02:39 +01:00
James Turner
0721db3acd TerraSync: handle reinit better
Fix various cases where re-init could get things blocked. Remove the
duplicate storage of the active paths; now we always check the primary
data, and hence it can’t be out of sync.

Also remove the obsolete persistent cache code.

Fixes some of the issues discussed in:
https://sourceforge.net/p/flightgear/codetickets/2308/

Further improvements still to come, especially to retry on a better
schedule for intermittent connections.
2020-08-25 21:02:16 +01:00
Richard Harrison
24b58cbe21 XMLSound bugfixes
- using expressions for pitch and volume didn't work
- multiple volume elements not computed properly

Discussion here: https://web.archive.org/web/20200730232940/http://fguk.me/forum/development-hangar/8360-supersonic-audio?start=40#46287

          <volume>
                <property>/a/v1</property>
                <factor>0.1</factor>
            </volume>
            <volume>
                <property>/a/v2</property>
                <offset>1</offset>
                <factor>-3</factor>
            </volume>
            <volume>
                <property>/a/v3</property>
                <offset>1</offset>
                <factor>-1</factor>
            </volume>

evaluates as follows:

update(): Have 3 volume entries
 --> 0:prop /a[0]/v1[0] => 0.110000 factor = 0.100000 v=0.011000 offset 0.000000, now 0.000000, v=0.011000 vol=0.011000 ==> 0.011000
 --> 1:prop /a[0]/v2[0] => 0.120000 factor = 3.000000 v=0.360000 -ve offset 1.000000 1.360000 = 0.014960  ==> 0.014960
 --> 2:prop /a[0]/v3[0] => 0.130000 factor = 1.000000 v=0.130000 -ve offset 1.000000 1.130000 = 0.016905  ==> 0.016905
2020-08-04 11:58:27 +01:00
Richard Harrison
5b3274e688 Exclude images with less than 16 bits per pixel from the DDS Texture Cache 2020-08-04 11:58:13 +01:00
James Turner
fcd75cfae5 Logging: add log overload which copies filename
This is needed to fix a Valgrind error in the test-cases, due to logging
Nasal filenames which are GCed.
2020-08-04 11:58:05 +01:00
James Turner
6387a1d6d0 Fix compilation for some MSVC versions 2020-07-14 13:59:14 +01:00
Julian Smith
fc4ce2528b Renamed version -> simgear-version to avoid breaking clang++ on OpenBSD.
It seems that clang++ headers #include <version>, which found simgear/version
because we need to put singear/ in include path for some code to compile.
2020-07-14 13:59:09 +01:00
James Turner
18d2bfcd8b HTTP: allow CAINFO to be set
Env var is SIMGEAR_TLS_CERT_PATH
2020-07-14 13:58:43 +01:00
James Turner
6738a3aa2b Helper to map string to log priority 2020-06-26 10:31:16 +01:00
Julian Smith
a8c1bef0bf Avoid various gcc warnings. 2020-06-26 10:30:58 +01:00
James Turner
4faf0ea468 API to reset the resource manager, and remove
providers.

Needed to fix a bug with parsing -set.xml files in the launcher;
correctly loading XML needs the resource paths to be defined.
2020-06-26 10:30:47 +01:00
Lars Toenning
80cc09fe90 Fix compiler warning of different signedness 2020-06-26 10:30:37 +01:00
James Turner
ca8dbb985e Fix zero-interval repeat on pick/knob animation
See:
https://sourceforge.net/p/flightgear/codetickets/2241/

Note did not adjust bug in knob-animation ignoring repeatable flag
(always marked repeatable) since this might break some aircraft.
2020-06-15 16:13:39 +01:00
James Turner
751cdc32a8 new version: 2020.2.1 2020-06-15 12:33:50 +01:00
Julian Smith
1d978429f5 simgear/props/props.cxx: Avoid possible SEGV e.g. if listener removes itself.
simgear/props/props_test.cxx: test for self-unregister.

SGPropertyNode::removeChangeListener() used to modify the _listeners vector or
even delete it and set _listeners to NULL, if a listener was removed.

This could cause a SEGV if removeChangeListener() was called from
a listener, because listeners are called from methods such as
SGPropertyNode::fireValueChanged() which iterate through _listeners and don't
expect it to be changed to NULL.

The fix here is to keep a track of whether we are iterating through the
_listeners vector; if we are, SGPropertyNode::removeChangeListener() sets the
entry to NULL, instead of removing it.

We have a new internal function forEachListener() which takes
care of the iterating details - incrementing/decrementing the new
_listeners->_num_iterators count and skipping NULL entries. Before returning,
if _num_iterators is now zero it removes any NULL entries in the vector of
listeners.

The nListeners() member is no longer inline, because it needs to ignore NULL
entries in the vector. And _listeners now points to an internally-defined
struct which contains a new _num_iterators as well as the vector of listeners.

Added self-unregister test to simgear/props/props_test.cxx.
2020-06-13 18:11:49 +01:00
James Turner
2b2e3ae5c4 Fix CMake value 2020-06-05 13:53:54 +01:00
James Turner
0e3ac7e078 Set CMake OpenGL VND policy 2020-06-05 13:32:43 +01:00
James Turner
01ab3b2385 New SGGeodesy::advance, taking degrees 2020-05-30 16:27:42 +01:00
James Turner
11cf87951c SIMD flags: ensure we respect other compiler flags
Ensure we only ever extend the currently set compile flags when
ENABLE_SIMD is requested
2020-05-28 10:46:18 +01:00
James Turner
7c004a4c90 Fix compilation with Boost >= 1.73 2020-05-28 10:45:47 +01:00
James Turner
a48693d273 Kill explicit setting of compiler flags in Debug
Use the CMake defaults for this.
2020-05-24 14:32:13 +01:00
James Turner
12d57a6373 Adjust RelWithDebInfo optimisation for Clang
This should give a bit of speed boost to macOS official builds.
2020-05-13 14:23:00 +01:00
James Turner
c7c8fc7777 Better RelWithDebInfo flags for CL.exe 2020-05-08 14:31:44 +01:00
James Turner
6e054e57ef Windows: ensure RelWithDebInfo is fast
Default CMake RelWithDebInfo pessimizes inlining
2020-05-07 14:13:54 +01:00
James Turner
1d89a76d13 Old-style texture compression: better check
Make even more sure new-style texture-compression is active, before
deciding which old-style mode to use.
2020-05-07 11:47:25 +01:00
James Turner
65925cccdf Enable old-style texture compression
Thanks to Dany for tracking this down!
2020-05-05 20:40:29 +01:00
James Turner
898559ab31 Add copyPropertiesIf helper 2020-05-03 12:21:36 +01:00
James Turner
ad3621e23b Add Canvas::Image.dirtyPixels() 2020-04-28 09:36:40 +01:00
James Turner
57b0f70a55 Nasal: improve message for non-object member access
Based on some discussion on this ticket:

https://sourceforge.net/p/flightgear/codetickets/2186/

Make this message slightly clearer.
2020-04-28 09:36:40 +01:00
Erik Hofman
8d6e543cc2 Only use readwav for OpenAL 2020-04-28 09:41:11 +02:00
James Turner
bd93fb279b new version: 2020.2.0 2020-04-27 09:29:55 +01:00
James Turner
81bdae283a new version: 2020.1.1 2020-04-27 09:29:54 +01:00
James Turner
00e25404c7 Add simgear::optional
This is a poor-man’s proxy for std::optional until we have it.
2020-04-25 18:05:59 +01:00
gallaert
6a157e1c08 Replace boost::tuple by std::tuple 2020-04-22 14:04:21 +01:00
gallaert
7a6f9151a6 General boost cleanup 2020-04-22 14:04:21 +01:00
gallaert
567293c14d Replace boost::function by std::function 2020-04-22 14:04:21 +01:00
gallaert
2ff6a4966a Replace boost::bind by std::bind and lambda function 2020-04-22 14:04:21 +01:00
gallaert
b13d7f9392 Replace boost::lexical_cast by std::ostringstream and std:stof/stoi/stod 2020-04-22 14:04:21 +01:00
gallaert
d21137739d Replace boost::enable_if/disable_if/enable_if_c/disable_if_c by std::enable_if 2020-04-22 14:03:47 +01:00
gallaert
1e13cf6fec Replace boost::shared_ptr/weak_ptr by std::shared_ptr/weak_ptr 2020-04-22 14:03:47 +01:00
James Turner
5c52cdc255 Fix for crash on reset:
https://sourceforge.net/p/flightgear/codetickets/2217/

Ensure that subsystem lookup during its own removal, returns nullptr.
Otherwise we cache an about-to-be dead pointer, which is Bad (TM)
2020-04-22 10:55:41 +01:00
James Turner
17d7808200 Remove a log message 2020-04-22 10:54:44 +01:00
James Turner
f144bd5a89 CanvasImage: fix updating after fillRect / setPixel 2020-04-18 21:31:16 +01:00
James Turner
b72553f6f0 Nasal: add isscalar() for Henning 2020-04-18 18:06:35 +01:00
James Turner
c82a14c252 Nasal: fix build on non-C99 mode
It seems GCC at least is strict about C99 mode.
2020-04-16 16:44:20 +01:00
James Turner
faa559e9af Nasal: add vecindex() built-in 2020-04-16 13:40:41 +01:00
James Turner
c51c0c43ed Nasal: add more isTYPE helpers from Henning 2020-04-16 11:42:41 +01:00
gallaert
2ab0122124 Replace boost::to_lower and boost::to_upper by strutils::lowercase and strutils::uppercase 2020-04-14 13:24:59 +01:00
James Turner
8626e0482d Nasal: add some type-check helpers.
These avoid building a string for the result, as typeof() does
2020-04-14 13:24:06 +01:00
gallaert
c9a4c0dac1 Replace BOOST_FOREACH by C++ 11 for range loop. 2020-04-12 14:39:12 +01:00
gallaert
825d93423d Statements following return, break, continue, goto or throw will never be executed. 2020-04-12 14:39:12 +01:00
Erik Hofman
ad24ce02e7 Remove some debugging statements 2020-04-12 14:53:16 +02:00
Erik Hofman
695616a8f2 Switch from doing the calculations ourselves in case of a bad_doppler implementation to using alDopplerFactor 2020-04-12 14:50:12 +02:00
Erik Hofman
b3bdf8636a Limit the velocity to the sound velocity after multiplying it by a foctor of 100 to compensate for bad Doppler calculations. Also add the option to set the sound velocity for the sound manager from within FlightGear (not yet used). 2020-04-11 09:48:49 +02:00
James Turner
c62c080a4b Logging: enable the WinDebug callback using an env var.
Instead of hard-coding, add an env-var SG_WINDEBUG to enable the
logging to the Windows debug stream.
2020-04-10 19:50:58 +01:00
James Turner
c90ab3df5b Packages: consider checksum failures for retry.
This means an out-of-sync mirror causes a retry on a different
mirror server.
2020-04-10 15:03:17 +01:00
James Turner
21e21a1fa8 Allow TiedPropertyList to fire valueChanged 2020-04-10 10:41:00 +01:00
James Turner
92ebdbfacc Expose compare-version helper publicly.
This helper was added for Catalog version checking, but will be used in
FlightGear now, so move it to strutils.
2020-04-09 14:39:12 +01:00
James Turner
8dbabc8b43 Texture-compression fixes
Rename a highly confusing method, and disable the older texture-
compression code since it interacts badly with the new texture-cache.
2020-04-07 12:12:52 +01:00
James Turner
c83dc79357 Revert to C++11 for now, found an alternative solution. 2020-04-06 10:44:23 +01:00
James Turner
a53c1bfe8b CMake logic to export debug symbols 2020-04-05 14:04:19 +01:00
James Turner
6185b8fd0d Fix crash with Touch animation mouse-up 2020-04-05 14:04:19 +01:00
Richard Harrison
ef002f6dfa Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/73/
2020-04-04 20:43:04 +00:00
James Turner
9cdec99fa4 Quiet some warnings 2020-04-03 10:00:22 +01:00
Fernando García Liñán
9393f84972 Compositor: Fix crash when using clustered shading with OSG 3.6 2020-04-02 21:21:55 +02:00
Stuart Buchanan
ceba006c60 Only sync scenery-path-suffix with valid name
It is possible to have a property tree with
/sim/rendering/scenery-path-suffix[n]/enabled=true
/sim/rendering/scenery-path-suffix[n]/name=<blank>

Previously this would be downloaded as scenery//[tile]

Now we just ignore such invalid paths.
2020-04-01 21:47:53 +01:00
James Turner
e9e2053c64 Strutils: add hex-decoding helper
This will be used to allow entering hex bytes in XML files, for HID
descriptor support on Windows.
2020-03-31 10:09:47 +01:00
Fernando García Liñán
bf013aea54 Compositor: Improve custom depth range handling in scene passes. 2020-03-30 19:23:03 +02:00
Stuart Buchanan
454df4872a Reduce shader attribute usage by packing floats
Previously we required 6 shader attributes to pass
in all the required information for the building shader.
By using packing techniques this has been reduced to 4.

This should improve support for integrated graphics cards.
2020-03-26 22:09:04 +00:00
James Turner
ec315bf26d Fix thumbnail cache retrieval
Use direct reading of thumbnail-cache files, instead of using libCurl
2020-03-26 16:51:00 +00:00
James Turner
74c304097d Fix for older libCurl versions 2020-03-26 16:51:00 +00:00
Erik Hofman
ad1833a4d5 Move more modern C++ idioms and use std::unique_ptr for moving daat ownership around 2020-03-26 09:54:28 +01:00
James Turner
d65bb58317 HTTP: increase the Curl download buffer size
This improves download performance with large files, i.e,
most of them.
2020-03-24 20:34:49 +00:00
James Turner
8cf11f9208 Packages: fix handling of unsafe paths in zips
This was breaking the P-51D which contains a mis-named PNG file which
tripped the unsafe path detection.
2020-03-24 13:51:57 +00:00
Fernando García Liñán
73f00bd842 Compositor: Added support for logarithmic depth buffer. 2020-03-22 17:24:48 +01:00
Fernando García Liñán
1b6545fc05 Compositor: No longer append 'Compositor/' to Effects when the Compositor is
enabled. Do not remove transparent bins in shadow passes.
2020-03-22 17:24:48 +01:00
James Turner
40725a76ab Packages: randomise mirror URL selection
Also add retry on mirrors when a download fails.
2020-03-21 18:31:53 +00:00
Erik Hofman
75f40fad95 Use more modern C++ 2020-03-20 10:40:09 +01:00
Erik Hofman
b458300c02 'lin' is a valid value for the type parameter so do not show a warning. Add a 'random' tag for pitch offset 2020-03-20 09:56:21 +01:00
Erik Hofman
6c6e74e8d1 Change logging levels to developer mode and be more descriptive 2020-03-19 13:33:30 +01:00
gallaert
4bab064ad6 - When HLA is enabled in Simgear, HLA is also enabled in Flightgear
making the build between Simgear and Flightgear consistent.
- Fix an issue with lib/lib64 path between CentOS/RedHat distributions
  and Debian derived distributions.
2020-03-15 22:29:43 +00:00
gallaert
3da2880aae Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2020-03-15 21:32:42 +00:00
James Turner
c8d802bc1d More SGPath / UTF-8 fixes
Use SGPath in more public APIs, so FlightGear doesn’t have to convert
and guess the conversion itself.
2020-03-15 14:26:42 +00:00
James Turner
c3a169319c Fix UTF-8 shader path support
Work around osg::Shader::loadShaderFromSourceFile ’s lack of UTF-8
support by loading using our own istream, and then setting the text
directly.
2020-03-15 14:26:42 +00:00
Erik Hofman
72af950573 Fix an error 2020-03-15 14:57:24 +01:00
Erik Hofman
edae7a2b75 Make warnings and alerts a single message for DEV_WARN and DEV_ALERT since they will result in a popu-dialog message 2020-03-15 14:33:05 +01:00
Erik Hofman
1fa48e7edb File readind is not of the SG_INPUT class s change it to SG_IO and make all warinigs and alerts developer-warings and developer-alerts 2020-03-15 14:24:02 +01:00
Erik Hofman
d76992efe6 Show the affected file when displaying an animation error or warning 2020-03-15 10:44:29 +01:00
James Turner
87da4680c7 Tweaks to Windows string conversion
Avoid use of code-cvt, and tolerate differences in compiler handling of
string literals (tested Clanged and MSVC, hopefully GCC is kind)
2020-03-14 20:10:20 +00:00
Richard Harrison
9cc7508b07 fixes #2123 Relocation splash distorted.
Allow splash screen as an origin and do not allow splash screens to be cached and thus the poweroftwo rules don't apply.
2020-03-13 20:07:31 +01:00
James Turner
b258bc598e Load time-zones from UTF-8 paths correctly
Use _wfopen on Windows, after converting UTF-8 paths to wchar
2020-03-13 16:48:12 +00:00
James Turner
f25c0c60a8 Use UTF8 paths in nearly all places, for OSG
We already request OSG to use UTF8 paths, so ensure whenever we pass
an SGPath to OSG, we use the correct conversion function.
2020-03-13 09:50:43 +00:00
James Turner
f350bd31bd CanvasImage: fillRect / setPixel tweaks
Fix image dirtying and allocation without an underlying fike
2020-03-11 17:12:42 +00:00
gallaert
06f1699223 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2020-03-09 22:13:16 +00:00
James Turner
3e4d528859 Additional install / download failure test
Ensure we can install again on a previously failed URL.
2020-03-09 15:00:23 +00:00
Erik Hofman
b847f57382 Fix a threads header 2020-03-09 14:56:08 +01:00
gallaert
2d7ad25031 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2020-03-01 16:14:13 +00:00
James Turner
d670cc13ac testHTTP mods to investigate macOS failure.
Disabled one test for now, since it’s blocking macOS release process
2020-02-25 16:12:12 +00:00
James Turner
43699d039f Track package install status persistently. 2020-02-25 14:27:48 +00:00
James Turner
9192b009e1 Catalog enable/disable feature 2020-02-24 11:35:04 +00:00
Stuart Buchanan
3fe85809b2 Add support for tarballs in Terrasync 2020-02-16 20:26:20 +00:00
Stuart Buchanan
a4b79d6882 Merge /u/tbmoore/simgear/ branch tmoore/canvas-mipmap into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/52/
2020-02-12 21:02:43 +00:00
gallaert
fc21e6eafa Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2020-01-31 22:51:14 +00:00
Erik Hofman
11e243a216 Clean up the threading code: remove the private classes. 2020-01-29 11:33:54 +01:00
Stuart Buchanan
9f862dcc0e Fix directional lights for AMD
Some AMD drivers do not like triangles for point sprites, which
breaks directional lights.  This works around this by allowing
users to set /rendering/triangle-directional-lights=false which
falls back to the non-directional implementation of a point.
2020-01-27 09:28:25 +00:00
Erik Hofman
faf43d2c4b Comment out Windows debugging code, for now 2020-01-24 19:30:32 +01:00
Erik Hofman
b0580b2df5 Re-order the mutex locking of the condition-mutex and the caller-mutex, add noxecept. Also add some debugging code to detect multiple locks of the same mutex. 2020-01-24 15:46:36 +01:00
Erik Hofman
308903dc91 Revert to c3ae704610 until the condition_variable problem is solved 2020-01-24 13:52:37 +01:00
Erik Hofman
1c7fd67c39 Convert condition variables to C++11 too. 2020-01-24 10:48:53 +01:00
Erik Hofman
c3ae704610 Move SGThread::current to after the system dependent code which includes the proper header files 2020-01-23 13:47:04 +01:00
Erik Hofman
9f8e6c0634 Make backwards compatible stubs so only a recompile without any modification is required. 2020-01-23 10:38:52 +01:00
Erik Hofman
aab88b411e Switch to C++11 threads, mutexes and lock_guards. Switching to C++11 condition_variables requires some more thought. 2020-01-22 13:44:47 +01:00
James Turner
867cf6b60a test_Http: Better completion checking 2020-01-19 06:30:10 -08:00
gallaert
ed87114c5e Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2020-01-11 18:52:36 +00:00
Julian Smith
213adb5f0d simgear/debug/logstream.cxx: ensure fgfs.log always includes file:line.
This is a bit of a hack - we set line = -line if m_fileLine is false, so that
the +ve value can be recovered by FileLogCallback::operator().
2019-12-31 16:50:46 +00:00
Scott Giese
c5c10a003a Rollback error until stability issues are resolved. 2019-12-31 10:29:25 -06:00
Julian Smith
e78205f071 simgear/debug/logstream.cxx: Fixed FileLogCallback to not output <filename>:-1.
logstream::LogStreamPrivate::log() sets line=-1 to turn off both filename and
line numbers in log output, if m_fileLine is false.

StderrLogCallback::operator() already omits both file and line if line == -1;
this commit does the same thing for FileLogCallback::operator().

E.g. this fixes output e.g. to ~/.fgfs/fgfs.log.
2019-12-29 19:04:47 +00:00
Richard Harrison
ba7134c2a2 Use isfinite to determine if an FP number is valid.
ref: https://forum.flightgear.org/viewtopic.php?f=30&t=36600&sid=4bdfcb69abb4a6440cd8965aa03815d5#p357164
2019-12-29 13:50:21 +01:00
Richard Harrison
1eadaa4cda Protect against null reference when effect not found 2019-12-29 13:48:40 +01:00
Richard Harrison
d93ce29b20 Exclusive thread possible fix for Linux
The deadlock is possibly caused by the thread not being joined, or because of an implementation difference with phtreads.

So this fix adds a call to release the background thread when terminating it and then also joins the thread to await for the completion of the background thread.

As before this works fine under Win32 (x64)
2019-12-29 13:48:09 +01:00
Richard Harrison
0cddb9e843 Revert "Disable NasalMainLoopRecipient"
This reverts commit 67e2860cc3.
2019-12-29 13:45:42 +01:00
Scott Giese
67e2860cc3 Disable NasalMainLoopRecipient
This is preventing FGFS shutdown on Linux OS.
Does not appear that this thread is properly joined and terminated.
2019-12-27 20:48:02 -06:00
James Turner
0cf9dd165e Add NetBeans .gitignore 2019-12-24 20:58:48 +00:00
James Turner
3aa567b672 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/70/
2019-12-24 19:47:25 +00:00
Fernando García Liñán
fa1e3cb183 Support in Effects for reading 3D textures from disk as an array of 2D textures 2019-12-24 03:37:14 +01:00
Fernando García Liñán
14845bf3f2 Compositor: Provide previous frame transformation matrices and the sunlight direction as uniforms 2019-12-24 03:34:37 +01:00
Fernando García Liñán
120328eb2b Removed 'using namespace' from header 2019-12-24 03:31:28 +01:00
gallaert
e222c0888c Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-12-19 11:48:09 +00:00
James Turner
ec19dfc2f2 Fix Windows build
__PRETTY_FUNCTION__ is not portable, alas.
2019-12-18 23:43:40 +00:00
James Turner
da45c26e7d Adding pixel manipulators to canvas::Image 2019-12-17 22:32:25 +00:00
James Turner
c39a5fd8c0 Fix some Clang warnings 2019-12-17 22:32:25 +00:00
Scott Giese
fb57fe9da7 Catching an exception by value 2019-12-15 03:12:54 -06:00
Scott Giese
02496da4d2 Logic error 2019-12-15 03:08:06 -06:00
Scott Giese
eb1afec22b Remove unused object creation 2019-12-15 02:39:43 -06:00
Scott Giese
1619df97f8 Potential unterminated string 2019-12-15 02:19:13 -06:00
Scott Giese
c653a82619 Eliminate unitialized warning 2019-12-15 02:00:16 -06:00
Scott Giese
2289618cea Fix conditional compile logic 2019-12-15 00:18:39 -06:00
Scott Giese
dc886118ba [CanvasText] Fix conditional compiles 2019-12-15 00:13:46 -06:00
Scott Giese
879b01004b [CanvasText] Fix conditional compiles 2019-12-14 23:31:13 -06:00
Stuart Buchanan
86f3169e4b Shader Buildings - fix roof orientation
Correct transformation to make roof ridges match orientation
in documentation.
2019-12-08 17:36:23 +00:00
Stuart Buchanan
d5957b8c5f Random Buildings - improved texture mapping
Previously the front and side faces of random/OSM buildings
had identical texture coordinates.  This resulted in the sides
of buildings texture mapping being squeezed or stretched.

This change generates a separate texture mapping for the sides
of the buildings.
2019-11-23 17:05:20 +00:00
James.Hester
595eb3efea Change order of test for is_plantation as per feedback. 2019-11-21 20:36:56 +11:00
James.Hester
81e93448e3 Merge branch 'plantation' into next 2019-11-17 09:05:47 +11:00
James.Hester
0f9fe8adef Add generation of plantation vegetation to TileDetailsCallback.
Plantations are regularly spaced vegetation. This effect is switched
on by the is_plantation material property. Vegetation is laid out
at integer spacings in x and y, with the spacing determined by the
usual coverage properties.
2019-11-16 11:16:09 +11:00
James.Hester
56933067c0 Add "is_plantation" property to materials definitions. 2019-11-16 11:02:35 +11:00
James.Hester
0919f5bf9c Improve comments on previous commit. 2019-11-12 08:00:04 +11:00
James.Hester
b91d4411b5 Added point_in_triangle function. 2019-11-12 07:55:09 +11:00
Erik Hofman
15c6131f0e Use a better way to set the listener position and orientation 2019-11-08 10:51:56 +01:00
James Turner
c2f2f25046 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/68/
2019-11-07 17:38:31 +00:00
Fernando García Liñán
94ced66f87 Compositor: Enable more culling for shadow passes 2019-11-07 15:46:05 +01:00
Erik Hofman
ece2f913a1 Get AeonWave up to par again by removing a number of errors, and fixing a unit type for the audio cone inner and outer angle. 2019-11-07 15:15:02 +01:00
Fernando García Liñán
2b2ada2037 Compositor: Added support for spotlights in clustered shading 2019-11-07 15:09:26 +01:00
Julian Smith
1a4568175c simgear/environment/metar.*: getDescription() can now also use single spaces.
If <tabstop> param is -1, all sequences of tabs are replaced by a single space.
2019-11-06 19:56:03 +00:00
Julian Smith
0c8949e723 simgear/environment/metar.cxx:SGMetar::getDescription(): minor improvements to returned text.
remove special characters from output. We used to include 0xb0 characters -
small 'o' degree symbol, but this isn't reliable and looks bad in flightgear's
weather window.

Consistently use space between number and its unit.

remove 'METAR Report' header.
2019-11-06 19:56:03 +00:00
James Turner
012966f6a2 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/67/
2019-11-05 09:32:28 +00:00
Erik Hofman
82b1cca247 Also add pressure to the mix 2019-11-04 15:18:59 +01:00
Erik Hofman
2976dc29d5 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2019-11-04 14:54:30 +01:00
Erik Hofman
99d5b0dc8a Switch to in-place declarations and to the ISO9613 distance attenuation model for AeonWave which also calcualtes the proper sound velocity based on atmospheric properties 2019-11-04 14:54:06 +01:00
Fernando García Liñán
d1eb768de6 Disabled CASTSHADOW_BIT on most of the scene graph geometry to optimize performance 2019-11-03 20:53:55 +01:00
Julian Smith
5db8e42c69 simgear/environment/metar.*: added getDescription().
Returns human-readable descrition of metar. Uses code from
flightgear:src/Main/metar_main.cxx.
2019-11-01 22:55:20 +00:00
Fernando García Liñán
c7efa81efe Only use effect schemes when the Compositor is enabled 2019-10-30 17:14:38 +01:00
James Turner
7d92698644 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/64/
2019-10-29 08:40:00 +00:00
Stuart Buchanan
4b280a00db Shader Buildings - fix roofs, set small tex to 5m
Fix a bug in the roof transformation that meant the
roof ridges were not sized correctly.  Also change
the texture "unit" width for small buildings from 6m
to 5m following discussions with Rick Gruber-Riemer.
2019-10-26 16:29:37 +01:00
Fernando García Liñán
02b61b145a Compositor: Shaders are looked for in $FG_ROOT/Compositor/Shaders when the compositor is enabled.
Fixed Compositor/ always being added to the effect filename. Now it is only added when the base folder is Effects/.
2019-10-26 01:53:30 +02:00
James Turner
0a7514c47b Add new ‘listener-safe’ SGProperty attribute
Used in FG to make certain tied properties as safe to use with
listeners, and hence suppress the warning.
2019-10-20 13:03:15 +01:00
James Turner
4b1a53367f Runway lights improvements from Sascha Reißner
(Sascha Reißner <reiszner@novaplan.at>)
2019-10-20 13:02:30 +01:00
James Turner
de3625d992 Fix linkage of OpenAL tests
Now we no longer list OpenAL a s apublic dependency of SimGear, we
need to  explicitly link the tests against OpenAL, since they use it
directly, in all cases.
2019-10-19 07:42:28 -07:00
Mykola Orliuk
65331599ec BoostTestTargets.cmake: support CMake 3.15
Signed-off-by: James Turner <zakalawe@mac.com>
2019-10-17 09:41:35 +01:00
Stuart Buchanan
74cd8cf75c Shader building roof types
Shader buildings now support multiple roof types:
- flat
- gabled
- hipped
- pyramidal
2019-10-08 21:38:48 +01:00
Stuart Buchanan
07586e84ce Rotate orientation of pitched roofs by 90 degrees
Also add some additional checking of parameters.
2019-10-06 12:52:12 +01:00
James Turner
ca97b4371b Use alternative name for internal expat_config.h
Avoid clashes when system has expat installed.
2019-10-05 17:19:09 +01:00
Scott Giese
b742607c76 [ReaderWriteSTG] fix for missing header. 2019-10-03 11:50:07 -05:00
ThomasS
1399cc9482 Additional interface to ReaderWriterSTG for adding callbacks for unknown STG token handler 2019-10-03 08:03:37 +02:00
Stuart Buchanan
7464e17e22 Swap width and depth for shader defined buildings
Previously the width was set as the x-axis and
depth for the y-axis when passed through to the
shader. This was incorrect, as the x-axis is actually
the depth of the building.
2019-10-01 14:56:18 +01:00
Stuart Buchanan
053bda26a4 Shader buildings - split wall and roof tex index
Previously there was very limited texture variations
as a given texture index was used for both the wall
and ceiling.  Now these can be specified separately,
allowing for more variation in both STG defined and
random buildings.
2019-09-25 21:53:19 +01:00
James Turner
93995cd742 Nasal GC : Fix crash running FG unit-tests
When freeing a context, clear its stack so that anything dangling in
them (especially the opStack) is GCed.
2019-09-19 08:05:55 +01:00
Scott Giese
202dfc9ebe Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-09-17 12:51:47 -05:00
Scott Giese
23f378cd93 Support VS 2019 - courtesy of Lars Toenning 2019-09-17 12:51:05 -05:00
Scott Giese
70c564dd2c Fix compile issue on Win10 VS2019 2019-09-16 23:30:59 -05:00
Julian Smith
9bea6afb80 Revert "simgear/scene/model/ModelRegistry.cxx: avoid noisy diagnostic from OSG."
This reverts commit 7762bc2cad.

This broke Windows and Mac builds.
2019-09-05 15:00:22 +01:00
Julian Smith
20fb7a9ce0 simgear/debug/logstream.cxx: Allow runtime control of file:line in diagnostics.
New fn logstream::setFileLine() allows other code to control whether log output
includes file:line information.
2019-09-02 16:10:38 +01:00
Julian Smith
7762bc2cad simgear/scene/model/ModelRegistry.cxx: avoid noisy diagnostic from OSG. 2019-09-02 16:10:10 +01:00
Julian Smith
f407785f10 Fixes for building on OpenBSD. 2019-08-22 17:35:13 +01:00
Stuart Buchanan
138e28fcbe Instance-based random buildings
Replace existing random buildings implementation with one using
proper instancing.  This allows better control of the buildings
themselves and allows BUILDING_LIST STG verb to specify
individual building dimensions.  See README.scenery for details.
2019-08-20 17:00:17 +01:00
Richard Harrison
38f6a5a40a Remove fairly irrelevant startup log message from NasalMainLoopRecipient
This is probably the reason why the tests are failing.
2019-08-14 16:47:25 +02:00
Scott Giese
b28f030874 [CanvasText] Restore support for OSG 3.4 2019-08-04 10:43:00 -05:00
Scott Giese
d883ab278d [osgText.getActiveFont] Breaking change within OSG 2019-08-04 02:27:57 -05:00
gallaert
40ce45c8e9 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-07-13 18:12:22 +01:00
Edward d'Auvergne
fa754ecaf8 SGSubsystem classes: Registration of all subsystems. 2019-07-01 14:37:49 +02:00
Edward d'Auvergne
c11557316d SGSubsystemMgr: Changed the Registrant class argument order.
The updateInterval argument is used a lot less than the dependency list, so
these have been swapped.  That simplifies the registration code in the subsystem
implementations as the updateInterval default of 0.0 no longer need to be
supplied.
2019-07-01 14:37:49 +02:00
Edward d'Auvergne
5bf28d3f90 SGSubsystemMgr: Expanded the dependency list types.
All the dependency types are now documented.
2019-07-01 14:37:49 +02:00
Edward d'Auvergne
c8625ce599 SGSubsystem classes: Addition of staticSubsystemClassId() to all subsystems. 2019-07-01 14:37:48 +02:00
Edward d'Auvergne
991fafb839 SGSubsystemGroup: Removal of the subsystem group naming.
This is a partial reversion of c1dd8faa29 and a
complete reversion of caea68007e and
846f024e91.  These changes are incompatible with
the subsystem class IDs.
2019-07-01 11:07:03 +02:00
Edward d'Auvergne
d7323f5f19 SGSubsystem classes: Renaming of the subsystem ID variables and functions. 2019-07-01 10:51:41 +02:00
Edward d'Auvergne
10662e4ca5 SGSubsystem classes: Subsystem and subsystem group API declaration standardisation.
This is a cleanup commit.
2019-06-16 14:12:38 +02:00
Edward d'Auvergne
b73dfb08ae SGSubsystem classes: Whitespace standardisation of the declarations.
This is a clean up commit prior to the subsystem API standardisation to simplify
the diffs.  It includes all SGSubsystem and SGSubsystemGroup derived classes.
2019-06-16 14:12:38 +02:00
Scott Giese
d8a46cffa5 [emesary] Fix naming conflict with some compilers 2019-06-15 17:22:53 -05:00
Scott Giese
3b3093c72e [nasal] remediate segfault in lib.c
state of vaCopy is altered during each usage, so it needs to be discarded and not reused by multiple calls.
2019-06-15 11:54:35 -05:00
Scott Giese
3d841a214c Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-06-14 22:12:02 -05:00
Scott Giese
2cbbb29eb5 [Emesary] Fix compile on Linux. 2019-06-14 22:11:31 -05:00
Scott Giese
c0677ad8c5 [Emesary] Fix compile on Linux. 2019-06-14 21:43:47 -05:00
James Turner
098c5b0924 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/62/
2019-06-11 21:56:28 +00:00
Richard Harrison
01ac9a71b7 Fix case sensitive filename for emesary.cxx 2019-06-11 23:40:21 +02:00
Fernando García Liñán
ab8b1d39bd Fixed undetected compiler error due to gcc accepting variable-length arrays 2019-06-11 23:05:09 +02:00
James Turner
b22a8debf2 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/61/
2019-06-11 14:59:05 +00:00
Richard Harrison
92a3c8bbd8 Added Nasal garbage collection background thread
This uses an SGThreadExclusive controlled by Emesary notifications that are received from the main loop.

When active at the end of a frame the garbage collection thread will be released; if it is already running this will do nothing. Optionally at the start of the mainloop we can wait for the previous GC to finish.

The actions of the background GC is controlled by notifications - again received from the main loop which in turn uses properties.

I initially thought that the wait at the start of the frame would be necessary; however in 100 or so hours of flight without the await for completion at the start of frame no threading problems (or any other problems) were shown; so nasal-gc-threaded-wait is defaulted to false which gives a slight boost in performance.

So what this does is to it removes the GC pause of 10-20ms every 4 seconds (test using the F-15). This change doesn't really give much extra performance per frame because normally GC is only performed when needed.
2019-06-11 13:44:52 +02:00
Richard Harrison
c71f287498 SG Threading added new class for an exclusive thread
An exclusive thread is one that is suited to being used where the thread needs to be activated at a certain point, and also that the code activating the thread may also need to wait for thread completion.

Example of this is the new background garbage collection for Nasal. The thread will be activated at the end of the frame processing and at the start of the next frame the thread can be awaited - thus allowing the thread to work in parallel with the rendering.
2019-06-11 13:30:29 +02:00
Richard Harrison
b7f8fbe7a0 Nasal lib: dosprintf
rework to measure the required length (vsnsprintf does this with a size of zero and a nullptr as the first parameters) - and then just alloc the required space. Should be more efficient than the looping version.
2019-06-11 12:38:49 +02:00
Fernando García Liñán
1ca3f60f80 Compositor: Significant rework of the clustered shading feature
- Added light definitions to the model XML files. This is not compatible with Rembrandt.
- Added depth slicing.
- Added threading support. For now it's faster to run everything on the main thread since there aren't many lights.
2019-06-10 16:02:32 +02:00
Richard Harrison
7a903361e6 Added Emesary
derived from: https://github.com/Zaretto/Emesary/tree/master/src/Emesary/EmesaryC++

This is a similar implementation to that in Nasal; currently this is only for use in C++ modules as there is no Nasal interface - however this is something that may be added later.

The basic premise of the Emesary messaging system is to allow the decoupled operation of the various components that comprise any system - usually within the same process.

The basic unit of communication is a Notification, which is passed around to any and or all objects that implement the IReceive interface (pure virtual class). Using Interfaces and ihneritance
it is possible to pass around Notifications that have special meanings to certain objects and allow them to perform the appropriate function.

Notifications are created and sent via a call to NotifyAll. Any object within the system can inherit from IReceive and register itself with a Transmitter to receive all notifications that are sent out.

The underlying concept is that one part of a system knows that something needs to be done without needing to know how to do it. The part of the system that needs something done simply creates a notification and sends it out. Once received by the part of the system that is capable of performing the requested Notification the relevant actions will be carried out and a status of OK or Finished returned.

The return code from the Receive method must follow the guidlines as follows:

If a notification is not recognised in the recipient must return ReceiptStatusNotProcessed. Normally a recipient will return ReceiptStatusOK, sometimes ReceiptStatusFail to indicate that the recipient could not properly process the notification.

The overall result of a call to NotifyAll is a composite of the results of each individual recipient's return value; and generally OK or Fail. It is acceptable to use the return code to ascertain success or failure and take appropriate action.

It is generally recommended that more detail specific to the particular purpose be included within the Notification to allow more control.

Notifications can be modified during processing to permit a multistage process; however this needs to be designed correctly.

* ReceiptStatusOK : Notification processed fine by Receive, transmitter continues with next recipient
* ReceiptStatusFail : Notification processed but failed, transmitter continues with next recipient
* ReceiptStatusAbort : Notification processed and the receive method declares a fatal error; the transmitter will stop notifying recipients
* ReceiptStatusFinished : Notification processed and the recipient declares that the processing is completed, the transmitter will stop notifying recipients
* ReceiptStatusNotProcessed : receive method does not recognise the notification

These status are for later implmentation.
* ReceiptStatusPending : (future ues); notification been sent but the return status cannot be determined as it has been queued for later processing, transmitter continues with next recipient
* ReceiptStatusPendingFinished : Message has been definitively handled but the return value cannot be determined. the transmitter will stop notifying recipients
2019-06-09 13:07:50 +02:00
Richard Harrison
4f6e72de55 UDNS Windows compatibility changes
For some reason the config file doesn't generate with WINDOWS defined on my system.
2019-06-08 15:49:15 +02:00
Richard Harrison
a68c4e9434 DDS Texture cache improvements
- change to always use the SG create mipmap function as it works better (no purple clouds)
- when enabled always generate a mipmap even if the file couldn't be compressed
- adjust level of log messages
- move lru_cache into its own header file.
2019-06-08 15:38:22 +02:00
Richard Harrison
798b90e0a5 Added Emesary 2019-06-08 10:12:22 +02:00
Richard Harrison
cba902f22b Nasal GC background threaded merge.
Merge branch 'nasal-background-thredead-gc'
2019-06-08 10:07:48 +02:00
Richard Harrison
8eb51e813f Added Emesary to SimGear Core 2019-06-03 23:32:49 +02:00
Richard Harrison
9ac3c1a394 Revert GC instrumentation committed by mistake as part of "SGTimeStamp elapsedUSec"
This reverts commit 0b114ac5cd, reversing
changes made to 39eb9837e9.
2019-05-27 18:49:33 +02:00
Tim Moore
5486ca3b4a Protect logstream startup entries with a mutex 2019-05-24 10:15:06 +01:00
Tim Moore
90845974ea nasal/lib.c: Make copy of va_list for each traversal
It's not portable to traverse a va_list more than once.
2019-05-24 10:14:50 +01:00
James Turner
57fd817486 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/58/
2019-05-22 12:57:13 +00:00
Fernando García Liñán
b322fa8f32 Use $FG_ROOT/Compositor/Effects instead of $FG_ROOT/Effects when the compositor is enabled
This allows coexistence of new compositor-compatible effects and current effects.
2019-05-20 23:40:12 +02:00
Fernando García Liñán
81d1e16d7b Compositor: Removed intersection checking
This is now responsibility of the CameraGroup.
2019-05-20 22:51:40 +02:00
Erik Hofman
4c52d77aa5 Add missing cassert incldues 2019-05-20 11:00:51 +02:00
James Turner
523d5166ef Merge /u/dancliff/simgear/ branch fix_sound_on_model_reload into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/57/
2019-05-14 20:33:12 +00:00
Dan Wickstrom
cde95864b4 Aircraft model reinit deletes sound effect samples, but leaves them defined in the sample group, so a reload doesn't re-add them. 2019-05-14 12:51:35 -04:00
Richard Harrison
7354201b5d Added background (threaded) garbage collector 2019-05-13 15:21:08 +02:00
Scott Giese
14971f88ee [soundmgr_openal] Pause/Resume Sound.
The following changes fixes a case for me where I hear the sound change levels up and down for each pause un-pause cycle.
Patch provided by daniel.c.wickstrom@gmail.com.
2019-05-09 20:52:20 -05:00
Richard Harrison
0b114ac5cd SGTimeStamp elapsedUSec 2019-05-07 05:17:28 +02:00
Richard Harrison
c06eabff24 Instrumented Nasal GC 2019-05-07 05:17:27 +02:00
Richard Harrison
b3ef2478f5 Instrumented Nasal GC 2019-05-07 05:13:55 +02:00
Richard Harrison
39eb9837e9 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/55/
2019-05-05 13:50:27 +00:00
Scott Giese
1a429b63c5 [SGImageUtils] eliminate unused variable. 2019-05-04 15:45:53 -05:00
Scott Giese
ae6ad20940 [SGDemSession] fix uninitialized members. 2019-05-04 15:26:25 -05:00
Fernando García Liñán
3e57b50066 Added support for Effect schemes
Effect schemes are a way of rendering an object in different ways depending on the Compositor pipeline. A new <scheme> tag in the Compositor pipeline definition allows the user to choose which Effect scheme is going to be used for that pass. Every Effect will then be rendered using the technique that has a matching scheme name. If no valid technique is found, it won't be rendered. Since it would be a pain to define a valid technique for every scheme and for every Effect, the file '$FG_ROOT/Effects/schemes.xml' is introduced:

<scheme>
  <name>test</name>
  <fallback>Effects/test</fallback>
</scheme>

If an Effect doesn't have a valid technique for the 'test' scheme, the 'Effects/test.eff' Effect will be merged with it. This process is done at initialization when techniques are being realized.
2019-05-04 19:15:22 +02:00
Florent Rougon
dd38e399ca Add readwav.hxx to HEADERS and readwav.cxx to SOURCES in all cases
Previously, these two files were only added when SG was built with
-DUSE_AEONWAVE:BOOL=OFF, because the SG code in use when USE_AEONWAVE is
set to ON doesn't need readwav.hxx nor readwav.cxx. However, readwav.hxx
and readwav.cxx are not only used in SG, but also in FG (at least by
flightgear/src/Sound/VoiceSynthesizer.cxx), and this was causing a build
failure when SG's USE_AEONWAVE and FG's ENABLE_FLITE flags were both set
to ON:

  https://forum.flightgear.org/viewtopic.php?f=45&t=35672#p346633

and

  https://sourceforge.net/p/flightgear/mailman/message/36645567/

This commit should fix this build failure.
2019-04-27 11:23:14 +02:00
Florent Rougon
319b59500c Convert obsolete uses of get_filename_component(<var> <FileName> PATH)
In the context of get_filename_component(), PATH is a legacy alias for
DIRECTORY. Replace it with DIRECTORY, which is recommended[1] for
CMake versions > 2.8.11.

[1] https://cmake.org/cmake/help/latest/command/get_filename_component.html
2019-04-25 19:19:19 +02:00
Fernando García Liñán
3a79b71e80 Compositor: Effects used by a compositor now receive a proper SGReaderWriterOptions and other misc fixes 2019-04-23 03:35:10 +02:00
gallaert
0c0eab9247 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-04-22 19:08:39 +01:00
James Turner
114ddcff52 Tweak code for older GCC 2019-04-11 21:39:41 +01:00
James Turner
57339486d9 Flip the default meaning of alternate-mouse-wheel-dir 2019-04-11 20:37:47 +01:00
Richard Harrison
5f9b17d55b Terrasync fixes;
- remove the old svn properties; a scan of FGAddon and FGdata showed these are not in use except for the dialog
- new property "active" - which is true when the worker thread is running.
- changes to enabled now take effect immediately; whereas before a reinit had to be issued. This could lead to confusing GUI state as the enabled property would be true but without closing the dialog (e.g. cancelling it) terrasync could be in a different state.
- use property nodes (performance optimisation)
2019-04-08 14:08:58 +02:00
Tim Moore
325b89e023 Fix automatic mipmap generation for Canvas textures
When using glTexStorage2D, OSG doesn't allocate storage for the levels
of the mipmap above the base unless an image is assigned to the
texture.
2019-04-04 12:07:34 +00:00
Tim Moore
9ebc823975 Optimize parsing of property node names
Add hand-coded versions of isalpha() and isdigit(), which were a
hotspot in profiling.
2019-04-04 12:00:18 +00:00
James Turner
5fdf6ef4f3 Simgear parts of queued command execution
Extend the command API to allow posting commands from arbitrary threads,
for deferred execution on the main thread. Additional pieces on the FG
side to follow shortly.
2019-03-24 14:13:42 +00:00
Richard Harrison
0792962591 add simgear::strutils::replace 2019-03-17 18:20:27 +01:00
Torsten Dreyer
f964374027 new version: 2019.2.0 2019-03-13 21:20:49 +01:00
Torsten Dreyer
4352c0a737 new version: 2019.1.1 2019-03-13 21:20:49 +01:00
Stuart Buchanan
a0bdcb30fd Correct log messages. 2019-03-12 21:53:22 +00:00
Stuart Buchanan
7e0a10c016 Set radius for PagedLOD
Speculative fix to address scenery chunks being unloaded
unexpectedly under high load.
2019-03-12 21:45:34 +00:00
Richard Harrison
7fb6f82ab1 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/49/
2019-03-07 15:21:35 +00:00
Scott Giese
fdcc9c9e0e Fix compile issue with OSG versions below 3.4 2019-03-05 23:56:47 -06:00
Richard Harrison
846f024e91 SGSubsytem name compatibility for other compilers;
changed to use const char* rather than const std::string & as this doesn't work on GCC; and besides std::string converts nicely to const char* and most of the times this is used it is actually a string literal.
2019-03-01 19:00:43 +01:00
James Turner
7e969f4e28 Updated star rendering phases/parameters
As part of this, adjust the normalisation so the active cutoff value
corresponds to 0.0 normalised intensity.
2019-02-25 16:12:41 +00:00
James Turner
10a701308d Make star cutoff controllable at runtime.
When a new property /environment/star-magnitude-cutoff is defined,
use this to set an upper bound on the magnitude of stars displayed.
2019-02-25 16:12:41 +00:00
Fernando García Liñán
e2bed86bfc Compositor: Enable small feature and view frustum culling by default for every pass. Added option to inherit the view master camera cull mask. 2019-02-23 23:26:27 +01:00
Richard Harrison
487cdc85cd DDS-TC; retain original filename and fix previous commit
Set the filename back to what it was after loading - seems sensible and as yet no side effects.

Also the previous commit that included the handling of sgio_exceptions also broke the DDS-TC pretty much completely.
2019-02-21 19:07:37 +01:00
Richard Harrison
052bbecc3b OSG 3.4.0 compilation fixes and anisotropy
Set anisotropy on model textures after loading.
2019-02-20 19:10:58 +01:00
Richard Harrison
c860b12b3d OSG 3.4.0 compilation fixes 2019-02-20 19:10:58 +01:00
Richard Harrison
e227008331 DDS-TC handle sgio_exceptions during hash creation.
ref: https://sourceforge.net/p/flightgear/codetickets/2113/
2019-02-20 19:10:58 +01:00
Fernando García Liñán
72f3a784de Compositor: Added support for static branching and <property> tags to be able to configure the Compositor at startup. 2019-02-20 03:05:55 +01:00
Richard Harrison
31c9df665d Fix compile error related to missing osg version include (< 3.6)
For some reason this compiles on 3.6.
2019-02-19 15:11:04 +01:00
Richard Harrison
dd240116b1 Compositor compilation fixes for OSG 3.6 and Win32 2019-02-19 08:59:54 +01:00
Richard Harrison
92ec139175 Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/47/
2019-02-19 07:28:58 +00:00
Stuart Buchanan
f076c43b90 Improve parsing of state machines
State machines will now throw exceptions if errors are encountered
when loading the XML file.

This includes:
- Unknown <source> or <target> states referenced by transitions
- States and transitions without <name> elements
- Transitions without <target> or <condition> elements
- State machines with fewer than two states

Previously the state machine would load and then crash when hitting
such malformed states or transitions.  Now it will refuse to load,
while providing useful error messages as to the problem.
2019-02-14 22:15:38 +00:00
Stuart Buchanan
98215e3dbd Improve error messages for Nasal prop references. 2019-02-14 22:13:54 +00:00
James Turner
6197098541 Guard against a potential race init-ing libCurl 2019-02-13 12:49:21 +00:00
James Turner
34b3c52a28 Improve HTTP redirect handling, and add test.
Ensure we get the final status code for the request after redirecting.
2019-02-13 12:34:17 +00:00
Richard Harrison
caea68007e Fix subsystem tests 2019-02-11 08:49:40 +01:00
Richard Harrison
c1dd8faa29 Improved subsystem performance monitoring and overrun detection
This is to help diagnose where performance is being used and augments the current performance monitor.

The easiest way to active this is to open the performance monitor; however setting the enable property will enable less intrusive logging and overrun detection.

Using the GUI performance monitor itself affects the performance when it updates.

Properties

/sim/performance-monitor/enabled - need to be true to be active (unchanged)
/sim/performance-monitor/dump-stats - hierarchical dump to console of all current timing stats for all subsysems
/sim/performance-monitor/interval-s - reporting interval (unchanged)
/sim/performance-monitor/max-time-per-frame-ms - any subsystem that takes more than this amount of will be logged to the console
2019-02-10 17:48:21 +01:00
James Turner
95d065b3d7 Add strutils::iequals helper
Replaces another boost method
2019-02-06 12:35:08 +00:00
Scott Giese
2303da846b Fix missing header for OSG macros.
Patch provided by Stewart Andreason.
2019-02-05 21:46:02 -06:00
Scott Giese
7246edcb4b [boost::enable_if] Support Boost versions < 1.56 2019-02-05 12:20:06 -06:00
Fernando García Liñán
dc2f24dbed Compositor framework initial commit. 2019-02-04 18:02:44 +01:00
Scott Giese
4b793d5344 Remove deprecated boost/utility.
This is enable compatibility with boost 1.69.
2019-02-02 19:46:04 -06:00
gallaert
72dd45388f Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2019-02-01 12:34:40 +00:00
Richard Harrison
b76f78c6da OSG < 3.4.x fixes
This will use the inherently unsafe versions of the load methods which can result in deleting an object (from the cache) that has just been loaded in the database thread.

Symptom OSG WARN deleting still referenced object.
2019-01-26 17:48:31 +01:00
Richard Harrison
30482a3599 Fix errant spaces in DDS cache log file 2019-01-26 17:48:31 +01:00
Erik Hofman
b3f9571b2d Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2019-01-26 09:13:17 +01:00
Richard Harrison
0d5afe83a2 No need to set precipitation (rain/snow) each frame when it is turned off. 2019-01-24 18:07:05 +01:00
Richard Harrison
8b35c9a4b1 Improvements to the DDS texture cache
- use a file contents hash instead of filepath.
- add a local lru cache for filepath->hash (for performance improvements)
- calculate and resize to nearest power of two
- handle normal maps and images from effects differently.
- when cache is active any image that can't be converted to a dds will have a mipmap generated (which still helps the loading process); although this may be responsible for introducing purple into transparent images..
2019-01-24 18:07:05 +01:00
Richard Harrison
a5d8eec25f Fix for deleting referenced object from model registry
This should have been in the previous commit - However I managed to mess up the merging of this module due to other changes related to the DDS texture cache.
2019-01-24 18:07:05 +01:00
James Turner
df6ec4f94c Property alias loop protection
Patch by Henning Stahlke
2019-01-22 17:24:21 +01:00
James Turner
61ebee12ad Set curl VERBOSE based on current SG log settings 2019-01-22 17:24:21 +01:00
Scott Giese
105d63a697 Simgear: LARGE_INTEGER is defined in Windows.h
Fixes build issues on Linux.
2019-01-20 20:35:08 -06:00
Richard Harrison
07036ac48f Add load origin hint to options
This is to allow the DDS cache to handle the image load differently depending on the origin.
2019-01-20 18:28:37 +01:00
Richard Harrison
4f6c8f7784 Better error handling on load failure 2019-01-20 18:28:37 +01:00
Richard Harrison
8e57a61aed Fix null ref during load.
This happened a few times
2019-01-20 18:28:37 +01:00
Richard Harrison
8707005a97 Fix particles active even when disabled during load.
Possibly this could be fixed better by using the plugin string data - but there is nothing that currently set this; and it seems easier to use the particle callback enabled flag.
2019-01-20 18:28:37 +01:00
Richard Harrison
cb024dd82d Fix for deleting still referenced object
ref https://sourceforge.net/p/flightgear/codetickets/2105/

Use the thread safe versions (getRef) of the objectcache methods
2019-01-20 18:28:37 +01:00
Richard Harrison
84046a6717 Add missing method 2019-01-20 18:28:37 +01:00
Richard Harrison
8bcaa50ba6 OSG3.7 changes 2019-01-20 18:28:37 +01:00
Richard Harrison
c433d29171 Win32: use high resolution timers (QueryPerformanceCounter) if available 2019-01-20 18:28:36 +01:00
Richard Harrison
64d51b5290 sg_file: Add compute hash method 2019-01-20 18:28:36 +01:00
Erik Hofman
6393b7704e Do not attempt to deregister the same emitter more than once 2019-01-16 14:55:37 +01:00
Erik Hofman
0a2071b2f1 Use AAX_PROCESSED since AAX_STOPPED is only a request to stop but the library decides when it is actually stopped. And AeonWave has become more picky about destroying emitters which aren't completely processed yet since MIDI support was added. 2019-01-15 11:38:38 +01:00
Erik Hofman
7981809f36 Split up SIMD support in ENABLE_SIMD which enables sse2 support for the compiler and ENABLE_SIMD_CODE which enables the hand crafted SIMD math functions which defaults to OFF now since compilers have catched up on generating optimized vectorized SIMD code. 2019-01-15 10:36:23 +01:00
Scott Giese
ed87a0b032 Eliminate compiler warnings 2018-12-23 22:16:05 -06:00
James Turner
fc2630e66d Revert "Logging API changes"
This is causing perf impact, so reverting until we figure out
a lower-impact solution.

This reverts commit 1be3e5771a.
2018-12-23 09:17:15 +00:00
Stuart Buchanan
ec14050890 General tiles with only BUILDING_LIST
Bug found during code-read.  If tile just contained BUILDING_LIST
entries (i.e. no OBJECT_STATIC or OBJECT_SIGN entries), then it would
not generate.
2018-12-22 16:52:05 +00:00
James Turner
4b17ea95fc Random buildings: reduce log output in a common case 2018-12-20 16:10:36 +00:00
James Turner
1be3e5771a Logging API changes
Remove would_log() : callbacks receive all log messages so they can
do custom filtering individually.

Also move popup message handling into the private (d-ptr) of sglog(),
to keep the header as minimal impossible (no include of <vector>)
2018-12-20 16:10:36 +00:00
Stuart Buchanan
232cbbac5e DEBUG logging of model animation counts. 2018-12-19 20:05:06 +00:00
gallaert
dee204d2b2 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-12-13 21:59:16 +00:00
Stuart Buchanan
b71e9eac51 Fix 2092 DDS cache: segmentation fault when reloading scenery.
https://sourceforge.net/p/flightgear/codetickets/2092/

DDS cache: segmentation fault when reloading scenery.
2018-12-10 21:21:44 +00:00
gallaert
f88636f47c Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-12-06 12:35:21 +00:00
Edward d'Auvergne
8a301efe8b PropertyObject: create() function support for SGPropertyNode_ptr. 2018-12-04 12:38:14 +01:00
Edward d'Auvergne
5bd393135f PropertyObject: Unit test for declaration followed by definition. 2018-12-04 12:38:14 +01:00
Edward d'Auvergne
d550eac525 PropertyObject<std::string>: Added a default ctor. 2018-12-04 12:38:14 +01:00
Edward d'Auvergne
fea59adbbe PropertyObject: Unit test for declarations.
This shows a failure for the declaration of std::string type PropertyObjects.
2018-12-04 12:38:14 +01:00
Richard Harrison
dae0d0ff8b Logging changes.
1. Anything that comes in from OSG will always be logged; it seems
somewhat redundant to have to set the FG log level to be identical to
the OSG log level to see these messages.

2. Console output will now have delta time (since start), priority and class.

3. Log file output wil also have delta time (since start), priority and class.

Times are displayed as delta decimal seconds since the logger was created

e.g.
  1294.06 [INFO]:terrain    Some log message
2018-11-29 19:29:14 +01:00
Richard Harrison
86d739cc85 DDS TextureCache: remove unused code to support non-persistent images
- this didn't compile for Stuart on OSG3.2 and it's not used.
2018-11-25 23:48:58 +01:00
Richard Harrison
9d99f4ce30 Added DDS Texture Cache.
This is a performance improvement that reduces the amount of frame pauses which are related to mipmap creation when the geometry (osg::Texture) is added to the scene graph within osg::Texture::applyTexImage2D_load

The texture cache is configured from FG as follows
- /sim/rendering/texture-cache/cache-enabled
- /sim/rendering/texture-cache/compress-transparent
- /sim/rendering/texture-cache/compress-solid
- /sim/rendering/texture-cache/compress

These properties are set via the SGSceneFeatures singleton.

When the texture cache is enabled it will auto convert files from any supported osg::Image format that can be read and store the resulting (compressed or raw) file in the texture cache.

The texture cache uses osg_nvtt to perform texture compression (and mipmap generation) if available. When not available simgear::effect::computeMipmap is used to make mimaps but compression isn't available.

The texture cache filename ends with .TIME.cache.dds where TIME is the hex modtime of the original file. As yet there isn't a clean way to maintain the texture cache to ensure that stale files are removed; and in fact this is quite difficult to do because of the dynamic nature of the cache.

The texture cache will be stored in download_dir/texture-cache unless --texture-cache is passed on the command line.

The UI has a single checkbox to turn the texture cache on or off.
2018-11-24 20:02:33 +01:00
Stuart Buchanan
460a666234 STG-defined buildings using Random Building shader
Support BUILDING_LIST STG verb which references a file
containing the cartesian coordinates of individual buildings,
to be generated using the random-building shader approach.

BUILDING_LIST buildings.txt OSM_Building -2.72943543 56.00080606 36.1 0

buildings.txt:

0 0 0 0 0
0 100 0 0 0
0 200 0 0 0
0 300 0 0 1
0 400 0 0 1
0 500 0 0 2
100 0 0 0 2
200 0 0 0 2
300 0 0 0 2
400 0 0 15 2
2018-11-18 21:08:06 +00:00
Stuart Buchanan
ba9342cd4b Fix effects for MP models - ticket 2076
https://sourceforge.net/p/flightgear/codetickets/2076/

Effects were being instantiated by the loader for
all models, rather than just simple .ac/.obj models.
2018-11-06 17:01:01 +00:00
gallaert
c37eae3b56 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-11-04 15:52:05 +00:00
Richard Harrison
61cc8d6c50 Fix exception when number of primitive sets not what assumed.
This was something that happened when random vegetation was off, but tree shadows was on.

Adding random vegetation would then reliably cause an exception.
2018-10-30 20:13:32 +01:00
Richard Harrison
758ab5e581 LOD ranges
The scenery ranges for bare and rough are now deltas, to avoid overlapping values by user error.
2018-10-30 20:12:12 +01:00
James Turner
f05ff37560 Fix for assert with empty systems
Empty subsystem groups didn’t set their init state correctly, leading
to an assert on post-init. Fix this and add a test for it.

https://sourceforge.net/p/flightgear/codetickets/2043/
2018-10-23 15:29:56 +01:00
Stuart Buchanan
14354090f9 Don't check for cloud movement every frame
Under Basic Weather, the cloudfield is finite size and clouds
are shifted as the viewpoint changes.  Previously each cloud
was checked every frame to determine if it should be shifted.
Not this only occurs if the viewpoint has moved a non-trivial
distance.

Note that this is separate from the clouds moving due to the wind.
2018-10-18 22:28:39 +01:00
James Turner
0185884ca8 Catalogs: allow migration to alternate IDs 2018-10-16 09:56:56 +01:00
gallaert
5665403d66 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-10-15 22:29:01 +01:00
James Turner
46b271d75c Packages: improve localised string support 2018-10-12 10:49:14 +01:00
James Turner
854b958797 Packages: check for existing update when scheduling
This is fixing an issue identified in the launcher in a secondary way,
to ensure if another user of the API tries to schedule an already
scheduled package, we ignore the second request.
2018-10-05 10:40:35 +01:00
James Turner
ff52b55a25 Mac: Set CMake OS-X deployment target correctly
Also raises the OS-X min version to 10.9 for libc++ compat
2018-10-01 22:28:56 +01:00
gallaert
e755735ac2 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-09-30 16:25:33 +01:00
Scott Giese
69e20a3931 Bug Fix #1922 Wrong retun type 2018-09-29 18:41:00 -05:00
James Turner
05da3db2ed Fix a debug message left in the terrasync code 2018-09-24 14:54:20 +01:00
Torsten Dreyer
6d89cc6c1d new version: 2018.4.0 2018-09-21 17:18:46 +02:00
Torsten Dreyer
0494af48a3 new version: 2018.3.1 2018-09-21 17:18:46 +02:00
James Turner
f4cad42958 Lat-lon parsing: catch exceptions from std::stod
The standard library throws exceptions in some cases, catch those
and return false. Extend the test coverage for some of the problematic
cases.
2018-09-13 23:47:24 +02:00
James Turner
32189b7239 Event-manager: add dump() method for debugging 2018-09-01 18:08:32 +01:00
James Turner
c192071f03 TerraSync: improve copy-installed-files logic 2018-08-31 16:05:48 +01:00
James Turner
8c9fda9137 Fix Utf-8 literal on MSVC 2018-08-31 16:05:48 +01:00
gallaert
35d1bb1149 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-08-29 21:01:36 +01:00
James Turner
8dd0833993 Fix setting OPENAL_DIR on Windows
We need to set this in all cases, since AeonWave is requested by
default, but may not be available.
2018-08-23 19:11:50 +01:00
James Turner
306eaeaba9 Fix subsystem-remove bug 2018-08-19 12:32:30 +01:00
James Turner
7853a5329d Extend propsfwd.hxx so it can be used in more places 2018-08-11 18:41:29 +02:00
James Turner
1fa77078fc Subsystems: bind/init/unbind on add/remove
When adding/remove subsystems to a group which is already bound or
inited, transition the subsystem automatically. This removes the
need to manually transition the subsystem in various places in
Flightgear.
2018-08-11 18:41:04 +02:00
James Turner
8e8ce04e18 Subsystems: default name to group name when adding 2018-08-11 18:16:33 +02:00
James Turner
264779e1d3 Packages: fix download progress
(Broke it when improving zip/tar support)
2018-08-08 11:12:53 +02:00
James Turner
6f505f3a76 formatGeodAsString: add ICAO route format 2018-07-30 10:08:34 +02:00
Edward d'Auvergne
3817bdd602 NotifyLogger: Shifted the class from flightgear to simgear.
This is to allow the code to be reused in the flightgear test suite.
2018-07-26 20:48:12 +02:00
Edward d'Auvergne
2c9420d9bc Logstream: Added a logging class for outputting messages in headless mode. 2018-07-26 20:48:12 +02:00
James Turner
2e3cace7f9 Canvas::path: early return for descendant changes
The ‘rect’ attributes of Path were before the early-return when the
change is for a descendant node.
2018-07-24 13:13:08 +01:00
James Turner
9553a604ac Cache parsed lat/lon values in Canvas::Map
This avoids re-parsing each lat/lon in the map from a string, each
time the project changes
2018-07-24 13:13:08 +01:00
James Turner
f1e1bf11b6 Cache x/y nodes in Canvas::Map::GeoPair
This removes a bad CPU hit when Canvas map is used continuously,
since this is two named property lookups per map coord per frame
2018-07-24 13:13:08 +01:00
James Turner
f77724a646 Fix terrasync hash persistence 2018-07-19 07:40:23 +01:00
gallaert
5921fd19fb Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-07-18 20:48:01 +01:00
James Turner
a0c4913f84 Fix .dirindex preservation on Windows
Ensure we don't treat the special files as regular children
when updating.
2018-07-18 16:30:44 +01:00
James Turner
3dfce43de2 Fixes to HTTP repo tests on Windows.
Large alloca fails, and SGFIle dtor doesn't close the handle,
which breaks _wunlink on Windows :(
2018-07-18 07:20:18 +01:00
Erik Hofman
0e9e5f77cc It turns out the 16-bit version was not introduced until gcc-4.8 2018-07-05 10:29:03 +02:00
James Turner
f2f465960b Tar code: handle symlink and PAX extensions
This now accepts the GitLab .tgz archives without problems, eg
the Tu-144.
2018-07-04 23:47:14 +01:00
James Turner
05d8ab3000 Fix Windows build
Clean out legacy crap from stdint.h while we're here
2018-07-04 14:08:57 +01:00
James Turner
126f69434b Refactor untar/unzip code
This is to enable reuse in more places, especially scenery extraction and TerraSync
2018-07-04 10:32:09 +01:00
Erik Hofman
3e081ae869 Use CPU optimized versions of endian swap functions when available 2018-07-04 09:35:45 +02:00
Erik Hofman
4e8df9dcc8 Remove a bunch og gcc-8 warnings 2018-07-04 09:33:32 +02:00
James Turner
d7a413d5e7 Lat-lon parsing: allow lon,lat order, and detect order
Flightplan/route-manager defaults to lon,lat order. Allow the parser
to detect the correct order when NSEW suffixes are provided and 
consistent.
2018-06-29 13:28:02 +01:00
James Turner
609ac93c10 Lat-lon parsing: accept lower case NSEW, fix precision
Thanks to Wkitty for catching both problems.
2018-06-28 22:43:30 +01:00
James Turner
b1d6a41c65 Fix a bug in lat-lon parsing - accept ‘*’
Previously, trailing * symbols confused the parser.
2018-06-27 14:29:45 +01:00
James Turner
a4e2fdfad2 Merge /u/scttgs0/simgear/ branch to-be-merged into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/46/
2018-06-24 20:07:40 +00:00
James Turner
22c2971c3c Lat-lon formatting: support nice degree symbols
Allow Latin-1 (for PUI fnt) and UTF-8 (for Qt, osgText and everybody
else) degree symbols as well as the use of *
2018-06-24 10:30:50 +01:00
Scott Giese
123c597e01 msvc has no support plans beyond OpenMP 2.0
We must use a signed integral data type
2018-06-23 14:44:48 -05:00
Scott Giese
05e3c29ee4 Support Visual Studio 2017 2018-06-22 22:19:49 -05:00
James Turner
9b1444deb5 Strutils to format and parse SGGeod/lat/lon
Format portion is taken from code in fg_props, parsing code is my
own horrible concoction.
2018-06-20 22:00:58 +01:00
James Turner
99d30d5bb7 CMake tweak: include headers in targets
This improves navigation in XCode (any maybe some other tools)
2018-06-20 22:00:03 +01:00
James Turner
100bb3a571 Fix flags passed to SHGetKnownFolderPath
Custom folder locations were not being picked up.
Fixes: https://sourceforge.net/p/flightgear/codetickets/2019/
2018-06-15 11:08:53 +01:00
Stuart Buchanan
7fb89e4d45 Multiple LoD levels of MP Aircraft
Support loading multiple models into PagedLOD.
2018-06-05 21:56:36 +01:00
Stuart Buchanan
1d7c3984ca Fix minor warning for no return value. 2018-06-05 21:55:23 +01:00
Erik Hofman
03156a6d94 Better AeoNWave detection 2018-06-05 09:39:51 +02:00
Erik Hofman
08258ee4b3 Detect AeonWave and if it is installed use it, otherwise fall back to OpenAL. Also let get_available_devices() use C++ strings instead of const char* 2018-06-02 14:06:15 +02:00
Erik Hofman
3dceaf7a0b Update to the latest version 2018-06-02 10:53:03 +02:00
Erik Hofman
856473ca43 Add missing headers 2018-05-29 09:44:37 +02:00
James Turner
7dfe705717 Resource manager clean-up code 2018-05-28 21:57:31 +02:00
ThomasS
dc2f142480 Feature for requesting canvas images per HTTP as described in http://wiki.flightgear.org/Read_canvas_image_by_HTTP 2018-05-28 14:23:12 +01:00
gallaert
fce06105f9 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-05-26 19:05:11 +01:00
Torsten Dreyer
94a1156a6b new version: 2018.3.0 2018-05-19 21:02:35 +02:00
Torsten Dreyer
5ed4fbd4a3 new version: 2018.2.1 2018-05-19 21:02:35 +02:00
xDraconian
d92a289c25 Bug fix: svg dirty flag 2018-05-17 09:11:07 +01:00
Edward d'Auvergne
2ba5676eb0 SGTime: Stripped trailing '\n' from some debugging messages. 2018-05-14 21:36:54 +02:00
Edward d'Auvergne
66cfa800be SGEventMgr: Reset the shutdown flag on init as a reset does not call the ctor.
This fixes the reset process that was broken by
dfed2184f1.
2018-05-14 14:05:04 +02:00
James Turner
9755110ec7 Packages: Remove deprecation warnings for now
Probably a bit over-zealous for these.
2018-05-09 10:15:07 +01:00
James Turner
f5ff969cd4 Warning improvements when requesting bad URLs
Found while debugging some issues with add-default-catalog flow in
the launcher.
2018-05-08 06:50:15 +01:00
Edward d'Auvergne
a232565b3e SGSubsystemMgr: Bug fix for the global_registrations vector.
The vector is now a static function variable that is returned by reference by
the new getGlobalRegistrations() function, which remains in the anonymous
namespace.

This solves the issue of the global_registrations vector being populated during
static init, but then been subsequently allocated and hence reset at the end of
static init.
2018-05-04 09:09:15 +02:00
Edward d'Auvergne
fd4ca1c811 Revert "Speculative fix for global symbol issues for Edward"
This reverts commit b6f5b40557.

The changes did not solve the static init vector allocation issue.
2018-05-04 09:02:08 +02:00
James Turner
b6f5b40557 Speculative fix for global symbol issues for Edward
Let’s see if an explicit static at file scope is better or different
to an anonymous namespace scope
2018-05-03 14:29:07 +01:00
James Turner
5710d33dbf Subsystem commands in the manager
Migrate and update these commands from FlightGear’s subsystem factory.
Currently disabled until subsystem-factory is removed, to avoid
duplicate registration.
2018-05-02 23:27:34 +01:00
James Turner
831369f653 Packages: add archive-path XML support
Allow the in-archive file path to differ from the after-install path.
Requested to allow easier operation with GitHub/Labs zip generation.
2018-04-27 15:25:13 +01:00
James Turner
6db59c64aa Subsystems: change naming scheme, add accessors
Add some hopefully clearer accessors for the subsystem naming, and some
comments documenting what is stored where.
2018-04-27 13:59:11 +01:00
James Turner
888d7fb262 Packages: archive-type support in catalogs
Allow URLs which don’t encode the file extension to work
2018-04-27 12:07:10 +01:00
James Turner
8b4ace6fb8 Subsystems: stub code for smart add+remove
Groups track their state, which will enable them to correctly transition
added and removed children in the future. Only stubbed for now, to avoid
breakage on the FG side.
2018-04-25 22:20:12 +01:00
James Turner
368120c479 Track a root property on subsystem-manager 2018-04-25 21:34:17 +01:00
gallaert
b01718aae7 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-04-25 21:08:46 +01:00
James Turner
48b228f68f Packages: additional test for updating invalid
This is part of trying to trace a crash reported on the devel list,
unfortunately the test passes but it’s sill good to have it
2018-04-25 17:04:07 +01:00
James Turner
bf21c0e099 MSVC build fixes, ooops 2018-04-25 11:41:40 +01:00
James Turner
d85d85e7dc Subsystem improvements for testing
- track more meta-data and a factory function for each subsystem, 
registered either explicitly or via a helper static class.
- add a delegate to receive notifications of subsystem changes
- make sub-grouped subsystems work more naturally, especially for
child lookups
- add some test coverage for all of this
2018-04-25 08:58:58 +01:00
Florent Rougon
99c1dd8124 Add compiler options for GCC and Clang when CMAKE_BUILD_TYPE is Debug
When CMAKE_BUILD_TYPE is Debug and we are compiling with GCC, add the
following options to CMAKE_C_FLAGS and CMAKE_CXX_FLAGS:

  -O0 -fno-omit-frame-pointer -fno-inline

Ditto for Clang, except that -fno-inline-functions is used instead of
-fno-inline.

cf. thread starting at
https://sourceforge.net/p/flightgear/mailman/message/36295412/
2018-04-18 08:25:10 +02:00
gallaert
9ce026e22e Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-04-12 18:56:37 +01:00
James Turner
2797970837 Catalogs: better invalid data handling 2018-04-08 23:57:24 +01:00
gallaert
4796c8b7f9 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-04-07 20:15:42 +01:00
James Turner
cf03307b70 More verbose error logging from Repository code 2018-03-30 17:24:58 +01:00
Edward d'Auvergne
dfed2184f1 SGEventMgr: Protection from timer insertion after shutdown.
This actually happens, Nasal timers are added after the event manager shutdown()
subsystem API call.
2018-03-25 22:45:04 +02:00
gallaert
2ee5127748 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-03-25 18:27:57 +01:00
Edward d'Auvergne
340a469153 LogStream: Added a testing mode to the simgear logstreams.
The new function logstream::setTestingMode() has been created to allow for a
testing mode to be set.  This stores a boolean in the private logstream thread
which modifies the behaviour of the would_log() function, allowing for
everything to be logged.  The removeCallbacks() function has also been added,
allowing for the default fgfs output to STDOUT and STDERR to be silenced when
calling setTestingMode().
2018-03-22 14:45:32 +00:00
gallaert
934e769513 Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next 2018-03-04 19:47:48 +00:00
Thomas Geymayer
62ae6ca35e Mostly canvas doxygen improvements and C++11 refactoring. 2018-03-02 09:07:01 +01:00
Thomas Geymayer
711a4fe0c8 canvas::Map: Preserve default values without new values
Ensure default values are used (instead of 0) if no values are
specified.
2018-03-01 09:10:24 +01:00
James Turner
cba07157d5 Packages: better version handling & migration
Add test coverage for disabling a catalog due to version, and also
for auto-migrating to a new version. Expose disabled catalogs on the
Root, so they can be checked for.
2018-02-28 17:26:15 +00:00
Thomas Geymayer
a653d67aae canvas: Event improvements and new events (dragstart, dragend) 2018-02-25 14:50:49 +01:00
gallaert
249e6130fd Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2018-02-22 22:33:47 +00:00
Erik Hofman
6a142bc264 Merge branch 'release/2018.1' into next 2018-02-20 10:11:38 +01:00
Erik Hofman
8bcdd89796 Properly initialize _bad_doppler 2018-02-20 10:11:04 +01:00
gallaert
8d265a8123 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2018-01-21 20:06:46 +00:00
gallaert
e6a540660d Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-12-18 19:14:12 +00:00
gallaert
12bed8e8ad Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-11-17 18:46:21 +00:00
gallaert
5305095832 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-10-09 22:04:36 +01:00
gallaert
e4b9cbcb80 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-10-01 21:25:16 +01:00
gallaert
d4198659b7 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-08-31 22:38:56 +01:00
gallaert
ef1edc7ee8 Merge branch 'next' of ssh://git.code.sf.net/p/flightgear/simgear into next 2017-08-25 20:47:36 +01:00
gallaert
3ccfb74028 Fix candidate for 'lib' vs 'lib64'. 2017-08-21 23:07:05 +01:00
371 changed files with 23968 additions and 7168 deletions

2
.gitignore vendored
View File

@@ -15,3 +15,5 @@ install_manifest.txt
build*
Build
CMakeLists.txt.user
3rdparty/expat_2.2.6/
nbproject

View File

@@ -1,7 +1,7 @@
configure_file (
"${PROJECT_SOURCE_DIR}/3rdparty/expat/expat_config_cmake.in"
"${PROJECT_BINARY_DIR}/3rdparty/expat/expat_config.h"
"${PROJECT_BINARY_DIR}/3rdparty/expat/simgear_expat_config.h"
)
set(expat_sources

View File

@@ -18,6 +18,8 @@
#include "amigaconfig.h"
#elif defined(__WATCOMC__)
#include "watcomconfig.h"
#elif defined(HAVE_SIMGEAR_EXPAT_CONFIG_H)
#include "simgear_expat_config.h"
#elif defined(HAVE_EXPAT_CONFIG_H)
#include "expat_config.h"
#endif /* ndef COMPILED_FROM_DSP */

View File

@@ -12,6 +12,8 @@
#include "amigaconfig.h"
#elif defined(__WATCOMC__)
#include "watcomconfig.h"
#elif defined(HAVE_SIMGEAR_EXPAT_CONFIG_H)
#include "simgear_expat_config.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include "expat_config.h"

View File

@@ -12,6 +12,8 @@
#include "amigaconfig.h"
#elif defined(__WATCOMC__)
#include "watcomconfig.h"
#elif defined(HAVE_SIMGEAR_EXPAT_CONFIG_H)
#include "simgear_expat_config.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include "expat_config.h"

View File

@@ -24,7 +24,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
# include <winsock2.h> /* includes <windows.h> */
# include <iphlpapi.h> /* for dns server addresses etc */
#else
@@ -53,7 +53,7 @@ static void dns_set_srch_internal(struct dns_ctx *ctx, char *srch) {
dns_add_srch(ctx, srch);
}
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
#ifndef NO_IPHLPAPI
/* Apparently, some systems does not have proper headers for IPHLPAIP to work.
@@ -217,7 +217,7 @@ int dns_init(struct dns_ctx *ctx, int do_open) {
ctx = &dns_defctx;
dns_reset(ctx);
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
if (dns_initns_iphlpapi(ctx) != 0)
dns_initns_registry(ctx);
/*XXX WINDOWS: probably good to get default domain and search list too...

View File

@@ -24,7 +24,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
# include <winsock2.h> /* includes <windows.h> */
# include <ws2tcpip.h> /* needed for struct in6_addr */
#else
@@ -392,7 +392,7 @@ dns_set_tmcbck(struct dns_ctx *ctx, dns_utm_fn *fn, void *data) {
}
static unsigned dns_nonrandom_32(void) {
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
return ft.dwLowDateTime;
@@ -551,7 +551,7 @@ int dns_open(struct dns_ctx *ctx) {
ctx->dnsc_qstatus = DNS_E_TEMPFAIL;
return -1;
}
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
{ unsigned long on = 1;
if (ioctlsocket(sock, FIONBIO, &on) == SOCKET_ERROR) {
closesocket(sock);
@@ -991,7 +991,7 @@ again: /* receive the reply */
* or remote. On local errors, we should stop, while
* remote errors should be ignored (for now anyway).
*/
#ifdef WINDOWS
#if defined(_WINDOWS) || defined(WINDOWS)
if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
if (errno == EAGAIN)

View File

@@ -27,7 +27,7 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#ifndef WINDOWS
#if !defined(_WINDOWS) && !defined(WINDOWS)
# include <sys/types.h>
# include <netinet/in.h>
#endif

View File

@@ -10,6 +10,15 @@ if(COMMAND cmake_policy)
if(POLICY CMP0067)
cmake_policy(SET CMP0067 NEW)
endif()
# OpenGL VND policy : use the old definition for now, until we can audit this
if(POLICY CMP0072)
cmake_policy(SET CMP0072 OLD)
endif()
if(POLICY CMP0093)
cmake_policy(SET CMP0093 NEW)
endif()
endif()
@@ -32,6 +41,7 @@ include (GenerateExportHeader)
# only relevant for building shared libs but let's set it regardless
set(CMAKE_OSX_RPATH 1)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
# let's use & require C++11 - note these are only functional with CMake 3.1
# we do manual fallbacks for CMake 3.0 in the compilers section
@@ -39,17 +49,12 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
# read 'version' file into a variable (stripping any newlines or spaces)
file(READ version versionFile)
file(READ simgear-version versionFile)
string(STRIP ${versionFile} SIMGEAR_VERSION)
project(SimGear VERSION ${SIMGEAR_VERSION} LANGUAGES C CXX)
# using 10.7 because boost requires libc++ and 10.6 doesn't include it
# Cmake documentation says we must set this before calling project(), but
# it only seems to be picked up setting it /after/ the call to project()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
# add a dependency on the versino file
# add a dependency on the version file
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS version)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
@@ -126,13 +131,19 @@ option(ENABLE_RTI "Set to ON to build SimGear with RTI support" OFF)
option(ENABLE_GDAL "Set to ON to build SimGear with GDAL support" OFF)
option(ENABLE_TESTS "Set to OFF to disable building SimGear's test applications" ON)
option(ENABLE_SOUND "Set to OFF to disable building SimGear's sound support" ON)
option(USE_AEONWAVE "Set to ON to use AeonWave instead of OpenAL" OFF)
option(USE_AEONWAVE "Set to ON to use AeonWave instead of OpenAL" ON)
option(ENABLE_PKGUTIL "Set to ON to build the sg_pkgutil application (default)" ON)
option(ENABLE_DNS "Set to ON to use udns library and DNS service resolver" ON)
option(ENABLE_SIMD "Enable SSE/SSE2 support for x86 compilers" ON)
option(ENABLE_SIMD "Enable SSE/SSE2 support for compilers" ON)
option(ENABLE_SIMD_CODE "Enable SSE/SSE2 support code for compilers" OFF)
option(ENABLE_OPENMP "Enable OpenMP compiler support" OFF)
if (NOT ENABLE_SIMD AND ENABLE_SIMD_CODE)
set(ENABLE_SIMD_CODE OFF)
endif()
include (DetectArch)
include (ExportDebugSymbols)
# until the fstream fix is applied and generally available in OSG,
# keep the compatability link option as the default
@@ -149,7 +160,7 @@ endif()
if (MSVC)
GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} PATH)
GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} DIRECTORY)
if (CMAKE_CL_64)
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
else (CMAKE_CL_64)
@@ -160,6 +171,11 @@ if (MSVC)
else (EXISTS ${TEST_3RDPARTY_DIR})
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
endif (EXISTS ${TEST_3RDPARTY_DIR})
# override CMake default RelWithDebInfo flags. This is important to ensure
# good performance
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Zi /O2 /Ob2 /D NDEBUG")
else (MSVC)
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
endif (MSVC)
@@ -167,14 +183,24 @@ endif (MSVC)
if (MSVC AND MSVC_3RDPARTY_ROOT)
message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
string(SUBSTRING ${MSVC_VERSION} 2 2 MSVC_VERSION_MINOR)
set( OSG_MSVC "msvc" )
if (${MSVC_VERSION} EQUAL 1900)
if (${MSVC_VERSION_MAJOR} EQUAL "19")
if (${MSVC_VERSION_MINOR} GREATER_EQUAL "20")
set( OSG_MSVC ${OSG_MSVC}142 )
elseif (${MSVC_VERSION_MINOR} GREATER_EQUAL "10")
set( OSG_MSVC ${OSG_MSVC}141 )
else ()
set( OSG_MSVC ${OSG_MSVC}140 )
elseif (${MSVC_VERSION} EQUAL 1800)
set( OSG_MSVC ${OSG_MSVC}120 )
endif ()
elseif (${MSVC_VERSION_MAJOR} EQUAL "18")
set( OSG_MSVC ${OSG_MSVC}120 )
else ()
message(FATAL_ERROR "Visual Studio 2013/2015 is required now")
message(FATAL_ERROR "Visual Studio 2013 or higher is required")
endif ()
if (CMAKE_CL_64)
set( OSG_MSVC ${OSG_MSVC}-64 )
set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
@@ -189,16 +215,13 @@ if (MSVC AND MSVC_3RDPARTY_ROOT)
# if this variable was not set by the user, set it to 3rdparty root's
# parent dir, which is the normal location for people using our
# windows-3rd-party repo
GET_FILENAME_COMPONENT(MSVC_ROOT_PARENT_DIR ${MSVC_3RDPARTY_ROOT} PATH)
get_filename_component(MSVC_ROOT_PARENT_DIR ${MSVC_3RDPARTY_ROOT} DIRECTORY)
set(BOOST_INCLUDEDIR ${MSVC_ROOT_PARENT_DIR})
message(STATUS "BOOST_INCLUDEDIR is ${BOOST_INCLUDEDIR}")
endif()
if (NOT USE_AEONWAVE)
set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
message(STATUS "OPENAL_INCLUDE_DIR is ${OPENAL_INCLUDE_DIR}")
endif()
set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
endif (MSVC AND MSVC_3RDPARTY_ROOT)
if(APPLE)
@@ -210,7 +233,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD
endif()
find_package(Boost REQUIRED)
set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION")
set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION -DBOOST_NO_STDLIB_CONFIG")
include(BoostTestTargets)
if(SIMGEAR_HEADLESS)
@@ -222,12 +245,19 @@ else()
if (ENABLE_SOUND)
if (USE_AEONWAVE)
find_package(AAX COMPONENTS aax REQUIRED)
else()
find_package(AAX)
endif()
if(NOT AAX_FOUND)
set(USE_AEONWAVE FALSE)
find_package(OpenAL REQUIRED)
endif()
message(STATUS "Sound support: ENABLED")
if(AAX_FOUND)
message(STATUS "Sound support: AeonWave")
else()
message(STATUS "Sound support: OpenAL")
endif()
endif(ENABLE_SOUND)
find_package(OpenSceneGraph 3.2.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgViewer osgUtil)
@@ -248,7 +278,15 @@ else()
endif()
endif(SIMGEAR_HEADLESS)
find_package(ZLIB 1.2.4 REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
# As of 2020-08-01, OpenBSD's system zlib is slightly old, but it's usable
# with a workaround in simgear/io/iostreams/gzfstream.cxx.
find_package(ZLIB 1.2.3 REQUIRED)
else()
find_package(ZLIB 1.2.4 REQUIRED)
endif()
find_package(LibLZMA REQUIRED)
find_package(CURL REQUIRED)
if (SYSTEM_EXPAT)
@@ -258,9 +296,6 @@ if (SYSTEM_EXPAT)
else()
message(STATUS "Using built-in expat code")
# XML_STATIC is important to avoid sg_expat_external.h
# declaring symbols as declspec(import)
add_definitions(-DHAVE_EXPAT_CONFIG_H -DXML_STATIC)
set(EXPAT_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/3rdparty/expat
${PROJECT_BINARY_DIR}/3rdparty/expat)
@@ -279,11 +314,10 @@ endif()
if(ENABLE_RTI)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
SET(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
SET(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig:$ENV{PKG_CONFIG_PATH}")
pkg_check_modules(RTI hla-rti13)
endif(PKG_CONFIG_FOUND)
if(RTI_FOUND)
SET(RTI_INCLUDE_DIR "${RTI_INCLUDE_DIRS}")
message(STATUS "RTI: ENABLED")
else()
message(STATUS "RTI: DISABLED")
@@ -397,11 +431,8 @@ if(CMAKE_COMPILER_IS_GNUCXX)
message(WARNING "GCC 4.4 will be required soon, please upgrade")
endif()
if(ENABLE_SIMD)
if (X86 OR X86_64)
set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse")
endif()
if (X86 OR X86_64)
set(SIMD_COMPILER_FLAGS "-msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize")
endif()
# certain GCC versions don't provide the atomic builds, and hence
@@ -410,6 +441,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
check_cxx_source_compiles(
"int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
GCC_ATOMIC_BUILTINS_FOUND)
# override CMake default RelWithDebInfo flags.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
endif(CMAKE_COMPILER_IS_GNUCXX)
if (CLANG)
@@ -420,12 +455,11 @@ if (CLANG)
# fix Boost compilation :(
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
if(ENABLE_SIMD)
if (X86 OR X86_64)
set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse")
endif()
endif()
# override CMake default RelWithDebInfo flags.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(SIMD_COMPILER_FLAGS "-msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize")
endif()
if (ENABLE_OPENMP)
@@ -457,14 +491,8 @@ if(WIN32)
if(MSVC)
set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /MP")
if(ENABLE_SIMD)
if (X86)
SET(CMAKE_C_FLAGS_RELEASE "/O2 /arch:SSE /arch:SSE2")
SET(CMAKE_CXX_FLAGS_RELEASE "/O2 /arch:SSE /arch:SSE2")
else()
SET(CMAKE_C_FLAGS_RELEASE "/O2")
SET(CMAKE_CXX_FLAGS_RELEASE "/O2")
endif()
if (X86)
set(SIMD_COMPILER_FLAGS "/arch:SSE /arch:SSE2")
endif()
if (NOT OSG_FSTREAM_EXPORT_FIXED)
@@ -488,6 +516,20 @@ if(WIN32)
set( RT_LIBRARY "winmm" )
endif(WIN32)
# append the SIMD flags if requested
if (ENABLE_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_COMPILER_FLAGS}")
# set for multi-configuration generators
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${SIMD_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SIMD_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${SIMD_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SIMD_COMPILER_FLAGS}")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
@@ -498,6 +540,10 @@ include(CheckCXXFeatures)
# ahead of system-installed libs
include_directories(BEFORE ${PROJECT_BINARY_DIR}/simgear)
if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
include_directories("/usr/X11R6/include")
endif()
add_definitions(-DHAVE_CONFIG_H)
# configure a header file to pass some of the CMake settings

View File

@@ -46,11 +46,17 @@ set(BOOST_TEST_TARGET_PREFIX "test")
if(NOT Boost_FOUND)
find_package(Boost 1.34.0 QUIET)
endif()
if("${Boost_VERSION}0" LESS "1034000")
if (NOT Boost_VERSION_MACRO)
# Compatibility with pre CMP0093 (CMake 3.15)
set(Boost_VERSION_MACRO ${Boost_VERSION})
endif()
if("${Boost_VERSION_MACRO}0" LESS "1034000")
set(_shared_msg
"NOTE: boost::test-based targets and tests cannot "
"be added: boost >= 1.34.0 required but not found. "
"(found: '${Boost_VERSION}'; want >=103400) ")
"(found: '${Boost_VERSION_MACRO}'; want >=103400) ")
if(ENABLE_TESTS)
message(FATAL_ERROR
${_shared_msg}
@@ -66,7 +72,7 @@ endif()
include(GetForceIncludeDefinitions)
include(CopyResourcesToBuildTree)
if(Boost_FOUND AND NOT "${Boost_VERSION}0" LESS "1034000")
if(Boost_FOUND AND NOT "${Boost_VERSION_MACRO}0" LESS "1034000")
set(_boosttesttargets_libs)
set(_boostConfig "BoostTestTargetsIncluded.h")
if(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY)
@@ -80,7 +86,7 @@ if(Boost_FOUND AND NOT "${Boost_VERSION}0" LESS "1034000")
set(_boostConfig "BoostTestTargetsDynamic.h")
endif()
endif()
get_filename_component(_moddir ${CMAKE_CURRENT_LIST_FILE} PATH)
get_filename_component(_moddir ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
configure_file("${_moddir}/${_boostConfig}"
"${CMAKE_CURRENT_BINARY_DIR}/BoostTestTargetConfig.h"
COPYONLY)
@@ -129,7 +135,7 @@ function(add_boost_test _name)
"Syntax error in use of add_boost_test: at least one source file required!")
endif()
if(Boost_FOUND AND NOT "${Boost_VERSION}0" LESS "1034000")
if(Boost_FOUND AND NOT "${Boost_VERSION_MACRO}0" LESS "1034000")
include_directories(${Boost_INCLUDE_DIRS})
@@ -221,7 +227,7 @@ function(add_boost_test _name)
set(_test_command ${_target_name})
endif()
if(TESTS AND ( "${Boost_VERSION}" VERSION_GREATER "103799" ))
if(TESTS AND ( "${Boost_VERSION_MACRO}" VERSION_GREATER "103799" ))
foreach(_test ${TESTS})
add_test(
${_name}-${_test}

View File

@@ -30,12 +30,12 @@ function(copy_resources_to_build_tree _target)
endif()
get_target_property(_path ${_target} LOCATION)
get_filename_component(_path "${_path}" PATH)
get_filename_component(_path "${_path}" DIRECTORY)
if(NOT MSVC AND NOT "${CMAKE_GENERATOR}" MATCHES "Makefiles")
foreach(_config ${CMAKE_CONFIGURATION_TYPES})
get_target_property(_path${_config} ${_target} LOCATION_${_config})
get_filename_component(_path${_config} "${_path${_config}}" PATH)
get_filename_component(_path${_config} "${_path${_config}}" DIRECTORY)
add_custom_command(TARGET ${_target}
POST_BUILD
COMMAND

View File

@@ -0,0 +1,26 @@
# placehodler target for other ones to depend upon
add_custom_target(
debug_symbols
)
function(export_debug_symbols target)
if (NOT SIMGEAR_SHARED)
return()
endif()
if (APPLE)
add_custom_target(${target}.dSYM
COMMENT "Generating dSYM files for ${target}"
COMMAND dsymutil --out=${target}.dSYM $<TARGET_FILE:${target}>
DEPENDS $<TARGET_FILE:${target}>
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${target}.dSYM DESTINATION symbols OPTIONAL)
add_dependencies(debug_symbols ${target}.dSYM)
endif()
endfunction()

View File

@@ -1,61 +1,74 @@
# Locate AAX
# Try to find AAX (AeonWave)
# This module defines
# AAX_LIBRARIES
# AAX_FOUND, if false, do not try to link to AAX
# AAX_INCLUDE_DIR, where to find the headers
#
# AAX_FOUND - if false, do not try to link to AAX
# AAX_INCLUDE_DIR - where to find the headers
# AAX_LIBRARIES - Link these to use AAX
#
# Copyright (C) 2016-2018 by Erik Hofman.
# Copyright (C) 2016-2018 by Adalin B.V.
#
# $AAXDIR is an environment variable that would
# correspond to the ./configure --prefix=$AAXDIR
# used in building AAX.
#
# Created by Erik Hofman.
# This file is Public Domain (www.unlicense.org)
# This is free and unencumbered software released into the public domain.
FIND_PATH(AAX_INCLUDE_DIR aax/aax.h
HINTS
$ENV{AAXDIR}
$ENV{ProgramFiles}/aax
$ENV{ProgramFiles}/AeonWave
$ENV{ProgramFiles}/Adalin/AeonWave
${CMAKE_SOURCE_DIR}/aax
PATH_SUFFIXES include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt
)
if (AAX_LIBRARY AND AAX_INCLUDE_DIR)
# in cache already
set(AAX_FOUND TRUE)
else()
find_path(AAX_INCLUDE_DIR aax/aax.h
HINTS
$ENV{AAXDIR}
$ENV{ProgramFiles}/aax
$ENV{ProgramFiles}/AeonWave
$ENV{ProgramFiles}/Adalin/AeonWave
${CMAKE_SOURCE_DIR}/aax
PATH_SUFFIXES include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt
)
FIND_LIBRARY(AAX_LIBRARY
NAMES AAX aax AAX32
HINTS
$ENV{AAXDIR}
$ENV{ProgramFiles}/AAX
$ENV{ProgramFiles}/AeonWave
$ENV{ProgramFiles}/Adalin/AeonWave
${CMAKE_BUILD_DIR}/aax
PATH_SUFFIXES bin lib lib/${CMAKE_LIBRARY_ARCHITECTURE} lib64 libs64 libs libs/Win32 libs/Win64
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt
)
find_library(AAX_LIBRARY
NAMES AAX aax libAAX
HINTS
$ENV{AAXDIR}
$ENV{ProgramFiles}/AAX
$ENV{ProgramFiles}/AeonWave
$ENV{ProgramFiles}/Adalin/AeonWave
${CMAKE_BUILD_DIR}/aax
PATH_SUFFIXES lib64 lib lib/${CMAKE_LIBRARY_ARCHITECTURE} libs64 libs libs/Win32 libs/Win64 bin
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt
)
IF(AAX_LIBRARY AND AAX_INCLUDE_DIR)
SET(AAX_FOUND "YES")
ELSE(AAX_LIBRARY AND AAX_INCLUDE_DIR)
IF(NOT AAX_INCLUDE_DIR)
MESSAGE(FATAL_ERROR "Unable to find the AAX library development files.")
SET(AAX_FOUND "NO")
ENDIF(NOT AAX_INCLUDE_DIR)
IF(NOT AAX_LIBRARY)
IF(SINGLE_PACKAGE)
SET(AAX_LIBRARY "${aax_BUILD_DIR}/aax/AAX32.dll")
SET(AAX_FOUND "YES")
ELSE(SINGLE_PACKAGE)
ENDIF(SINGLE_PACKAGE)
ENDIF(NOT AAX_LIBRARY)
ENDIF(AAX_LIBRARY AND AAX_INCLUDE_DIR)
set(AAX_DEFINITIONS "")
if (AAX_LIBRARY AND AAX_INCLUDE_DIR)
set(AAX_FOUND TRUE)
endif()
if (AAX_FOUND)
if (NOT Udns_FIND_QUIETLY)
message(STATUS "Found AeonWave: ${AAX_LIBRARIES}")
endif ()
else ()
if (Udns_FIND_REQUIRED)
message(FATAL_ERROR "Could not find AeonWave")
endif ()
endif ()
# show the AAX_INCLUDE_DIRS and AAX_LIBRARIES variables only in the advanced view
mark_as_advanced(AAX_INCLUDE_DIRS AAX_LIBRARIES)
endif()

View File

@@ -0,0 +1,124 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibLZMA
-----------
Find LZMA compression algorithm headers and library.
Imported Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``LibLZMA::LibLZMA``, if
liblzma has been found.
Result variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``LIBLZMA_FOUND``
True if liblzma headers and library were found.
``LIBLZMA_INCLUDE_DIRS``
Directory where liblzma headers are located.
``LIBLZMA_LIBRARIES``
Lzma libraries to link against.
``LIBLZMA_HAS_AUTO_DECODER``
True if lzma_auto_decoder() is found (required).
``LIBLZMA_HAS_EASY_ENCODER``
True if lzma_easy_encoder() is found (required).
``LIBLZMA_HAS_LZMA_PRESET``
True if lzma_lzma_preset() is found (required).
``LIBLZMA_VERSION_MAJOR``
The major version of lzma
``LIBLZMA_VERSION_MINOR``
The minor version of lzma
``LIBLZMA_VERSION_PATCH``
The patch version of lzma
``LIBLZMA_VERSION_STRING``
version number as a string (ex: "5.0.3")
#]=======================================================================]
find_path(LIBLZMA_INCLUDE_DIR lzma.h )
if(NOT LIBLZMA_LIBRARY)
find_library(LIBLZMA_LIBRARY_RELEASE NAMES lzma liblzma NAMES_PER_DIR PATH_SUFFIXES lib)
find_library(LIBLZMA_LIBRARY_DEBUG NAMES lzmad liblzmad NAMES_PER_DIR PATH_SUFFIXES lib)
include(SelectLibraryConfigurations)
select_library_configurations(LIBLZMA)
else()
file(TO_CMAKE_PATH "${LIBLZMA_LIBRARY}" LIBLZMA_LIBRARY)
endif()
if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h")
file(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS REGEX "#define LZMA_VERSION_[A-Z]+ [0-9]+")
string(REGEX REPLACE ".*#define LZMA_VERSION_MAJOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MAJOR "${LIBLZMA_HEADER_CONTENTS}")
string(REGEX REPLACE ".*#define LZMA_VERSION_MINOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MINOR "${LIBLZMA_HEADER_CONTENTS}")
string(REGEX REPLACE ".*#define LZMA_VERSION_PATCH ([0-9]+).*" "\\1" LIBLZMA_VERSION_PATCH "${LIBLZMA_HEADER_CONTENTS}")
set(LIBLZMA_VERSION_STRING "${LIBLZMA_VERSION_MAJOR}.${LIBLZMA_VERSION_MINOR}.${LIBLZMA_VERSION_PATCH}")
unset(LIBLZMA_HEADER_CONTENTS)
endif()
# We're using new code known now as XZ, even library still been called LZMA
# it can be found in http://tukaani.org/xz/
# Avoid using old codebase
if (LIBLZMA_LIBRARY)
include(CheckLibraryExists)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${LibLZMA_FIND_QUIETLY})
if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY})
elseif(LIBLZMA_LIBRARY_RELEASE)
set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY_RELEASE})
elseif(LIBLZMA_LIBRARY_DEBUG)
set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY_DEBUG})
endif()
CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_auto_decoder "" LIBLZMA_HAS_AUTO_DECODER)
CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_easy_encoder "" LIBLZMA_HAS_EASY_ENCODER)
CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_lzma_preset "" LIBLZMA_HAS_LZMA_PRESET)
unset(LIBLZMA_LIBRARY_check)
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY
LIBLZMA_INCLUDE_DIR
LIBLZMA_HAS_AUTO_DECODER
LIBLZMA_HAS_EASY_ENCODER
LIBLZMA_HAS_LZMA_PRESET
VERSION_VAR LIBLZMA_VERSION_STRING
)
mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
if (LIBLZMA_FOUND)
set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
if(NOT TARGET LibLZMA::LibLZMA)
add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${LIBLZMA_INCLUDE_DIR}
IMPORTED_LINK_INTERFACE_LANGUAGES C)
if(LIBLZMA_LIBRARY_RELEASE)
set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
IMPORTED_LOCATION_RELEASE "${LIBLZMA_LIBRARY_RELEASE}")
endif()
if(LIBLZMA_LIBRARY_DEBUG)
set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
IMPORTED_LOCATION_DEBUG "${LIBLZMA_LIBRARY_DEBUG}")
endif()
if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
IMPORTED_LOCATION "${LIBLZMA_LIBRARY}")
endif()
endif()
endif ()

View File

@@ -12,6 +12,11 @@ macro(simgear_component_common name includePath sourcesList sources headers)
set_property(GLOBAL
APPEND PROPERTY PUBLIC_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${h}")
set(fh${sourcesList} "${fh${sourcesList}}#${CMAKE_CURRENT_SOURCE_DIR}/${h}")
# also append headers to the sources list, so that IDEs find the files
# correctly (otherwise they are not in the project)
set_property(GLOBAL
APPEND PROPERTY ${sourcesList} "${CMAKE_CURRENT_SOURCE_DIR}/${h}")
endforeach()
set_property(GLOBAL APPEND PROPERTY FG_GROUPS_${sourcesList}_C "${fc${sourcesList}}@")

568
Doxyfile

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +0,0 @@
[This file is mirrored in both the FlightGear and SimGear packages.]
You *must* have the development components of OpenAL installed on your system
to build FlightGear!" You can get a copy here:
http://connect.creativelabs.com/openal/default.aspx
Build notes:
You can download a versioned release of the openal library from
http://www.openal.org/downloads.html. Download the openal source,
release 0.0.8 (dated February 11, 2006) and run:
tar xjvf openal-soft-1.5.304.tar.bz2
cd openal-soft-1.5.304/
ccmake .
[ While running ccmake: press 'c' to configure, press 'c' once more, and
then press 'g' to generate and exit ]

39
README.sound Normal file
View File

@@ -0,0 +1,39 @@
[This file is mirrored in both the FlightGear and SimGear packages.]
For Sound support FlightGear requires one of the two following packages:
- OpenAL
- AeonWave
== OpenAL ===
You *must* have the development components of OpenAL installed on your system
to build FlightGear!" You can get a copy here:
http://connect.creativelabs.com/openal/default.aspx
Build notes:
You can download a versioned release of the openal library from
http://www.openal.org/downloads.html. Download the openal source,
release 0.0.8 (dated February 11, 2006) and run:
tar xjvf openal-soft-1.5.304.tar.bz2
cd openal-soft-1.5.304/
ccmake .
[ While running ccmake: press 'c' to configure, press 'c' once more, and
then press 'g' to generate and exit ]
== AeonWave ===
For FlightGear AeonWave has a number of advantages over OpenAL:
* Correct Doppler effect behavior
* Default distance attenuation frequency filtering
* Native support for 29 types of audio formats.
* Native support for wav, mp3, vorbis and raw file formats.
The source code of AeonWave can be found on GitHub:
https://github.com/adalinbv
Optimized binary packages are available at:
http://www.adalin.com/

View File

@@ -1,6 +1,7 @@
include(CMakeFindDependencyMacro)
find_dependency(ZLIB)
find_dependency(LibLZMA)
find_dependency(Threads)
# OSG
@@ -18,6 +19,16 @@ set(USE_AEONWAVE @USE_AEONWAVE@)
set(ENABLE_SIMD @ENABLE_SIMD@)
# OpenRTI support
set(ENABLE_RTI @ENABLE_RTI@)
if(ENABLE_RTI)
set(RTI_FOUND @RTI_FOUND@)
if(RTI_FOUND)
set(RTI_INCLUDE_DIRS @RTI_INCLUDE_DIRS@)
set(RTI_LDFLAGS @RTI_LDFLAGS@)
endif(RTI_FOUND)
endif(ENABLE_RTI)
# Alternative terrain engine based on pagedLOD
set(ENABLE_GDAL @ENABLE_GDAL@)

1
simgear-version Normal file
View File

@@ -0,0 +1 @@
2020.3.8

View File

@@ -6,6 +6,7 @@ foreach( mylibfolder
bvh
debug
embedded_resources
emesary
ephemeris
io
magvar
@@ -64,6 +65,9 @@ if(SIMGEAR_SHARED)
set_property(TARGET SimGearScene PROPERTY VERSION ${SIMGEAR_VERSION})
set_property(TARGET SimGearScene PROPERTY SOVERSION ${SIMGEAR_SOVERSION})
endif()
export_debug_symbols(SimGearCore)
export_debug_symbols(SimGearScene)
else()
message(STATUS "Library building mode: STATIC LIBRARIES")
@@ -114,11 +118,22 @@ target_include_directories(SimGearCore BEFORE PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
# so simgear/simgear_config.h is found
target_include_directories(SimGearCore BEFORE PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(SimGearCore PUBLIC
${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
target_include_directories(SimGearCore PRIVATE
${EXPAT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS})
if (NOT SYSTEM_EXPAT)
# XML_STATIC is important to avoid sg_expat_external.h
# declaring symbols as declspec(import)
target_compile_definitions(SimGearCore PRIVATE HAVE_SIMGEAR_EXPAT_CONFIG_H XML_STATIC)
endif()
install(TARGETS SimGearCore
EXPORT SimGearTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -143,40 +158,44 @@ if (NOT SIMGEAR_HEADLESS)
endif()
endif()
# we expose ZLib in some of our headers
target_link_libraries(SimGearCore PUBLIC ${ZLIB_LIBRARY})
target_link_libraries(SimGearCore
${ZLIB_LIBRARY}
target_link_libraries(SimGearCore PRIVATE
${RT_LIBRARY}
${DL_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${COCOA_LIBRARY}
${CURL_LIBRARIES}
${WINSOCK_LIBRARY})
${WINSOCK_LIBRARY}
${SHLWAPI_LIBRARY}
LibLZMA::LibLZMA
)
if(SYSTEM_EXPAT)
target_link_libraries(SimGearCore
${EXPAT_LIBRARIES})
target_link_libraries(SimGearCore PRIVATE ${EXPAT_LIBRARIES})
endif()
if(ENABLE_DNS AND SYSTEM_UDNS)
target_link_libraries(SimGearCore
${UDNS_LIBRARIES})
target_link_libraries(SimGearCore PRIVATE ${UDNS_LIBRARIES})
endif()
if(NOT SIMGEAR_HEADLESS)
target_include_directories(SimGearScene PRIVATE ${PROJECT_SOURCE_DIR}/simgear/canvas/ShivaVG/include)
target_link_libraries(SimGearScene
target_link_libraries(SimGearScene PUBLIC
SimGearCore
${ZLIB_LIBRARY}
${OPENSCENEGRAPH_LIBRARIES}
)
target_link_libraries(SimGearScene PRIVATE
${ZLIB_LIBRARY}
${OPENAL_LIBRARY}
${OPENGL_LIBRARY}
${JPEG_LIBRARY})
if(ENABLE_GDAL)
target_link_libraries(SimGearScene
${GDAL_LIBRARIES})
target_link_libraries(SimGearScene PRIVATE ${GDAL_LIBRARIES})
endif()
# only actually needed by canvas/KeyboardEvent.cxx
@@ -188,5 +207,5 @@ if(ENABLE_RTI)
set_property(SOURCE hla/RTI13InteractionClass.cxx hla/RTI13ObjectClass.cxx
hla/RTI13ObjectInstance.cxx hla/RTI13Federate.cxx
hla/RTI13FederateFactory.cxx
APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIR}")
APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIRS}")
endif(ENABLE_RTI)

View File

@@ -20,9 +20,9 @@
#include "BVHPager.hxx"
#include <list>
#include <mutex>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
#include "BVHPageNode.hxx"
#include "BVHPageRequest.hxx"
@@ -37,12 +37,12 @@ struct BVHPager::_PrivateData : protected SGThread {
struct _LockedQueue {
void _push(const _Request& request)
{
SGGuard<SGMutex> scopeLock(_mutex);
std::lock_guard<std::mutex> scopeLock(_mutex);
_requestList.push_back(request);
}
_Request _pop()
{
SGGuard<SGMutex> scopeLock(_mutex);
std::lock_guard<std::mutex> scopeLock(_mutex);
if (_requestList.empty())
return _Request();
_Request request;
@@ -51,7 +51,7 @@ struct BVHPager::_PrivateData : protected SGThread {
return request;
}
private:
SGMutex _mutex;
std::mutex _mutex;
_RequestList _requestList;
};
@@ -62,7 +62,7 @@ struct BVHPager::_PrivateData : protected SGThread {
}
void _push(const _Request& request)
{
SGGuard<SGMutex> scopeLock(_mutex);
std::lock_guard<std::mutex> scopeLock(_mutex);
bool needSignal = _requestList.empty();
_requestList.push_back(request);
if (needSignal)
@@ -70,7 +70,7 @@ struct BVHPager::_PrivateData : protected SGThread {
}
_Request _pop()
{
SGGuard<SGMutex> scopeLock(_mutex);
std::lock_guard<std::mutex> scopeLock(_mutex);
while (_requestList.empty())
_waitCondition.wait(_mutex);
_Request request;
@@ -79,7 +79,7 @@ struct BVHPager::_PrivateData : protected SGThread {
return request;
}
private:
SGMutex _mutex;
std::mutex _mutex;
SGWaitCondition _waitCondition;
_RequestList _requestList;
};

View File

@@ -1,4 +1,5 @@
// The canvas for rendering with the 2d API
///@file
/// The canvas for rendering with the 2d API
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -38,6 +39,75 @@ namespace simgear
{
namespace canvas
{
static int globalinstanceid = 1;
/**
* Camera Callback for moving completed canvas images to subscribed listener.
*/
class CanvasImageCallback : public osg::Camera::DrawCallback {
public:
osg::Image *_rawImage;
CanvasImageCallback(osg::Image *rawImage)
: _min_delta_tick(1.0 / 8.0) {
_previousFrameTick = osg::Timer::instance()->tick();
_rawImage = rawImage;
SG_LOG(SG_GENERAL,SG_INFO,"CanvasImageCallback created. instance is " << instanceid);
}
virtual void operator()(osg::RenderInfo& renderInfo) const {
osg::Timer_t n = osg::Timer::instance()->tick();
double dt = osg::Timer::instance()->delta_s(_previousFrameTick, n);
if (dt < _min_delta_tick)
return;
_previousFrameTick = n;
SG_LOG(SG_GENERAL,SG_DEBUG,"CanvasImageCallback " << instanceid << ": image available for " << _subscribers.size() << " subscribers. camera is " << renderInfo.getCurrentCamera());
bool hasSubscribers = false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lock);
hasSubscribers = !_subscribers.empty();
}
if (hasSubscribers) {
//Make sure image can be overwritten by next frame while it is still returned to the client
osg::Image* image = new osg::Image(*_rawImage, osg::CopyOp::DEEP_COPY_ALL);
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lock);
while (!_subscribers.empty()) {
try {
CanvasImageReadyListener *subs = _subscribers.back();
if (subs){
subs->imageReady(image);
}else{
SG_LOG(SG_GENERAL,SG_WARN,"CanvasImageCallback subscriber null");
}
} catch (...) { }
_subscribers.pop_back();
}
}
}
}
void subscribe(CanvasImageReadyListener * subscriber) {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lock);
_subscribers.push_back(subscriber);
}
void unsubscribe(CanvasImageReadyListener * subscriber) {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lock);
_subscribers.remove(subscriber);
}
int getSubscriberCount() {
return _subscribers.size();
}
private:
mutable list<CanvasImageReadyListener*> _subscribers;
mutable OpenThreads::Mutex _lock;
mutable double _previousFrameTick;
double _min_delta_tick;
int instanceid = globalinstanceid++;
};
//----------------------------------------------------------------------------
Canvas::CullCallback::CullCallback(const CanvasWeakPtr& canvas):
@@ -247,6 +317,21 @@ namespace canvas
osg::Camera* camera = _texture.getCamera();
string canvasname = _node->getStringValue("name");
int renderToImage = _node->getBoolValue("render-to-image");
if (renderToImage){
CanvasImageCallback *_screenshotCallback = dynamic_cast<CanvasImageCallback*> (camera->getFinalDrawCallback());
if (!_screenshotCallback) {
// no draw callback yet
osg::Image* shot = new osg::Image();
shot->allocateImage(getSizeX(), getSizeY(), 24, GL_RGB, GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER, shot);
camera->setFinalDrawCallback(new CanvasImageCallback(shot));
SG_LOG(SG_GENERAL,SG_INFO,"CanvasImage: attached image and draw callback to camera " << camera << " for canvas " << canvasname << ". Ready for subscriber now.");
}
}
// TODO Allow custom render order? For now just keep in order with
// property tree.
camera->setRenderOrder(osg::Camera::PRE_RENDER, _node->getIndex());
@@ -346,6 +431,41 @@ namespace canvas
}
}
int Canvas::subscribe(CanvasImageReadyListener * subscriber) {
osg::Camera* camera = _texture.getCamera();
const string canvasname = _node->getStringValue("name");
SG_LOG(SG_GENERAL,SG_DEBUG,"CanvasImage: subscribe to canvas " << canvasname.c_str() << ", camera ="<< camera);
if (!_node->getBoolValue("render-to-image")) {
SG_LOG(SG_GENERAL,SG_INFO,"CanvasImage: Setting render-to-image");
_node->addChild("render-to-image", 0)->setBoolValue(1);
setStatusFlags(STATUS_DIRTY, true);
}
CanvasImageCallback *_screenshotCallback = dynamic_cast<CanvasImageCallback*> (camera->getFinalDrawCallback());
if (_screenshotCallback) {
// Camera ready for subscriber. Otherwise, draw callback is created by canvas thread later.
SG_LOG(SG_GENERAL,SG_DEBUG,"CanvasImage: adding subscriber to camera draw callback");
_screenshotCallback->subscribe(subscriber);
// TODO: check: Is this the correct way to ensure the canvas will be available?
enableRendering(true);
return 1;
}
return 0;
}
int Canvas::unsubscribe(CanvasImageReadyListener * subscriber) {
osg::Camera* camera = _texture.getCamera();
SG_LOG(SG_GENERAL,SG_DEBUG,"CanvasImage: unsubscribe");
CanvasImageCallback *cb = dynamic_cast<CanvasImageCallback*> (camera->getFinalDrawCallback());
if (cb) {
SG_LOG(SG_GENERAL,SG_DEBUG,"CanvasImage: unsubscribe from camera " << camera);
cb->unsubscribe(subscriber);
}
return 0;
}
//----------------------------------------------------------------------------
bool Canvas::addEventListener( const std::string& type,
const EventListener& cb )
@@ -571,6 +691,10 @@ namespace canvas
{
_sampling_dirty = true;
}
else if( name == "anisotropy" )
{
_texture.setMaxAnisotropy( node->getFloatValue() );
}
else if( name == "additive-blend" )
{
_texture.useAdditiveBlend( node->getBoolValue() );

View File

@@ -44,6 +44,17 @@ namespace canvas
class CanvasMgr;
class MouseEvent;
/**
* A listener interested in completed canvas drawing.
*/
class CanvasImageReadyListener {
public:
virtual void imageReady(osg::ref_ptr<osg::Image>) = 0;
virtual ~CanvasImageReadyListener()
{
}
};
/**
* Canvas to draw onto (to an off-screen render target).
*/
@@ -71,18 +82,18 @@ namespace canvas
public osg::NodeCallback
{
public:
CullCallback(const CanvasWeakPtr& canvas);
explicit CullCallback(const CanvasWeakPtr& canvas);
private:
CanvasWeakPtr _canvas;
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
void operator()(osg::Node* node, osg::NodeVisitor* nv) override;
};
typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
Canvas(SGPropertyNode* node);
explicit Canvas(SGPropertyNode* node);
virtual ~Canvas();
virtual void onDestroy();
void onDestroy() override;
void setCanvasMgr(CanvasMgr* canvas_mgr);
CanvasMgr* getCanvasMgr() const;
@@ -160,7 +171,12 @@ namespace canvas
*/
void enableRendering(bool force = false);
void update(double delta_time_sec);
void update(double delta_time_sec) override;
osg::Camera* getCamera();
int subscribe(CanvasImageReadyListener * subscriber);
int unsubscribe(CanvasImageReadyListener * subscriber);
int getSubscriberCount();
bool addEventListener(const std::string& type, const EventListener& cb);
bool dispatchEvent(const EventPtr& event);
@@ -184,11 +200,9 @@ namespace canvas
bool propagateEvent( EventPtr const& event,
EventPropagationPath const& path );
virtual void childAdded( SGPropertyNode * parent,
SGPropertyNode * child );
virtual void childRemoved( SGPropertyNode * parent,
SGPropertyNode * child );
virtual void valueChanged (SGPropertyNode * node);
void childAdded(SGPropertyNode* parent, SGPropertyNode* child) override;
void childRemoved(SGPropertyNode* parent, SGPropertyNode* child) override;
void valueChanged(SGPropertyNode * node) override;
osg::Texture2D* getTexture() const;
@@ -254,8 +268,8 @@ namespace canvas
static SystemAdapterPtr _system_adapter;
Canvas(const Canvas&); // = delete;
Canvas& operator=(const Canvas&); // = delete;
Canvas(const Canvas&) = delete;
Canvas& operator=(const Canvas&) = delete;
};
} // namespace canvas

View File

@@ -1,4 +1,5 @@
// Canvas Event for event model similar to DOM Level 3 Event Model
///@file
/// Canvas Event for event model similar to DOM Level 3 Event Model
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -125,10 +126,10 @@ namespace canvas
//----------------------------------------------------------------------------
std::string Event::typeToStr(int type)
{
TypeMap const& type_map = getTypeMap();
auto const& map_by_id = getTypeMap().by<id>();
TypeMap::map_by<id>::const_iterator it = type_map.by<id>().find(type);
if( it == type_map.by<id>().end() )
auto it = map_by_id.find(type);
if( it == map_by_id.end() )
return "unknown";
return it->second;
}

View File

@@ -65,6 +65,11 @@ namespace canvas
// of the actual event instances.
virtual ~Event();
/**
* Clone event and set to the given type (Same type if not specified)
*/
virtual Event* clone(int type = 0) const = 0;
/**
* Get whether this events support bubbling
*/
@@ -110,7 +115,14 @@ namespace canvas
*/
bool defaultPrevented() const;
/**
* Register a new type string or get the id of an existing type string
*
* @param type Type string
* @return Id of the given @a type
*/
static int getOrRegisterType(const std::string& type);
static int strToType(const std::string& type);
static std::string typeToStr(int type);

View File

@@ -1,4 +1,5 @@
// Manage event handling inside a Canvas similar to the DOM Level 3 Event Model
///@file
/// Manage event handling inside a Canvas similar to the DOM Level 3 Event Model
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -17,9 +18,11 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include <simgear_config.h>
#include "CanvasEventManager.hxx"
#include <simgear/canvas/events/MouseEvent.hxx>
#include <simgear/canvas/elements/CanvasElement.hxx>
#include "elements/CanvasElement.hxx"
#include "events/MouseEvent.hxx"
#include <cmath>
namespace simgear
@@ -114,6 +117,8 @@ namespace canvas
return handled;
}
case Event::DRAG:
case Event::DRAG_START:
case Event::DRAG_END:
if( !_last_mouse_down.valid() )
return false;
else

View File

@@ -1,4 +1,5 @@
// Manage event handling inside a Canvas similar to the DOM Level 3 Event Model
///@file
/// Manage event handling inside a Canvas similar to the DOM Level 3 Event Model
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Mapping between canvas gui Event types and their names
///@file
/// Mapping between canvas gui Event types and their names
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -25,6 +26,8 @@ ENUM_MAPPING(MOUSE_UP, "mouseup", MouseEvent)
ENUM_MAPPING(CLICK, "click", MouseEvent)
ENUM_MAPPING(DBL_CLICK, "dblclick", MouseEvent)
ENUM_MAPPING(DRAG, "drag", MouseEvent)
ENUM_MAPPING(DRAG_START, "dragstart", MouseEvent)
ENUM_MAPPING(DRAG_END, "dragend", MouseEvent)
ENUM_MAPPING(WHEEL, "wheel", MouseEvent)
ENUM_MAPPING(MOUSE_MOVE, "mousemove", MouseEvent)
ENUM_MAPPING(MOUSE_OVER, "mouseover", MouseEvent)

View File

@@ -1,5 +1,6 @@
// Visitor for traversing a canvas element hierarchy similar to the traversal
// of the DOM Level 3 Event Model
///@file
/// Visitor for traversing a canvas element hierarchy similar to the traversal
/// of the DOM Level 3 Event Model
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -18,9 +19,10 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include <simgear_config.h>
#include "CanvasEvent.hxx"
#include "CanvasEventVisitor.hxx"
#include <simgear/canvas/elements/CanvasElement.hxx>
#include "elements/CanvasElement.hxx"
namespace simgear
{

View File

@@ -1,5 +1,6 @@
// Visitor for traversing a canvas element hierarchy similar to the traversal
// of the DOM Level 3 Event Model
///@file
/// Visitor for traversing a canvas element hierarchy similar to the traversal
/// of the DOM Level 3 Event Model
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Canvas with 2D rendering API
///@file
/// Canvas with 2D rendering API
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -17,12 +18,11 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include <simgear_config.h>
#include "CanvasMgr.hxx"
#include "Canvas.hxx"
#include "CanvasEventManager.hxx"
#include <boost/bind.hpp>
namespace simgear
{
namespace canvas

View File

@@ -1,4 +1,5 @@
// Canvas with 2D rendering API
///@file
/// Canvas with 2D rendering API
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -27,42 +28,39 @@ namespace simgear
namespace canvas
{
class CanvasMgr:
public PropertyBasedMgr
{
public:
class CanvasMgr : public PropertyBasedMgr
{
public:
/**
* @param node Root node of branch used to control canvasses
*/
CanvasMgr(SGPropertyNode_ptr node);
/**
* @param node Root node of branch used to control canvasses
*/
CanvasMgr(SGPropertyNode_ptr node);
/**
* Create a new canvas
*
* @param name Name of the new canvas
*/
CanvasPtr createCanvas(const std::string& name = "");
/**
* Create a new canvas
*
* @param name Name of the new canvas
*/
CanvasPtr createCanvas(const std::string& name = "");
/**
* Get ::Canvas by index
*
* @param index Index of texture node in /canvas/by-index/
*/
CanvasPtr getCanvas(size_t index) const;
/**
* Get ::Canvas by index
*
* @param index Index of texture node in /canvas/by-index/
*/
CanvasPtr getCanvas(size_t index) const;
/**
* Get ::Canvas by name
*
* @param name Value of child node "name" in
* /canvas/by-index/texture[i]/name
*/
CanvasPtr getCanvas(const std::string& name) const;
/**
* Get ::Canvas by name
*
* @param name Value of child node "name" in
* /canvas/by-index/texture[i]/name
*/
CanvasPtr getCanvas(const std::string& name) const;
protected:
virtual void elementCreated(PropertyBasedElementPtr element);
};
protected:
void elementCreated(PropertyBasedElementPtr element) override;
};
} // namespace canvas
} // namespace simgear

View File

@@ -1,4 +1,5 @@
// Canvas placement for placing a canvas texture onto osg objects.
///@file
/// Canvas placement for placing a canvas texture onto osg objects
//
// It also provides a SGPickCallback for passing mouse events to the canvas and
// manages emissive lighting of the placed canvas.

View File

@@ -1,5 +1,5 @@
///@file
/// Placement for putting a canvas texture onto OpenSceneGraph objects.
/// Placement for putting a canvas texture onto OpenSceneGraph objects
///
/// It also provides a SGPickCallback for passing mouse events to the canvas and
/// manages emissive lighting of the placed canvas.
@@ -60,7 +60,7 @@ namespace canvas
*/
void setCaptureEvents(bool enable);
virtual bool childChanged(SGPropertyNode* child);
bool childChanged(SGPropertyNode* child) override;
protected:
typedef SGSharedPtr<SGPickCallback> PickCallbackPtr;

View File

@@ -1,4 +1,5 @@
// Base class for canvas placements
///@file
/// Base class for canvas placements
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Base class for canvas placements
///@file
/// Base class for canvas placements
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -40,9 +41,8 @@ namespace canvas
protected:
SGPropertyNode_ptr _node;
private:
Placement(const Placement&) /* = delete */;
Placement& operator=(const Placement&) /* = delete */;
Placement(const Placement&) = delete;
Placement& operator=(const Placement&) = delete;
};
} // namespace canvas

View File

@@ -1,4 +1,5 @@
// Adapter for using the canvas with different applications
///@file
/// Adapter for using the canvas with different applications
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -29,6 +30,10 @@ namespace HTTP { class Client; }
namespace canvas
{
/**
* Provides access to different required systems of the application to the
* Canvas
*/
class SystemAdapter
{
public:

View File

@@ -1,4 +1,5 @@
// Window for placing a Canvas onto it (for dialogs, menus, etc.)
///@file
/// Window for placing a Canvas onto it (for dialogs, menus, etc.)
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -212,6 +213,19 @@ namespace canvas
_resize_left = getRegion().l() + offset.x();
}
//----------------------------------------------------------------------------
bool Window::handleEvent(const EventPtr& event)
{
if( auto mouse_event = dynamic_cast<MouseEvent*>(event.get()) )
{
mouse_event->local_pos =
mouse_event->client_pos =
mouse_event->screen_pos - toOsg(getPosition());
}
return Image::handleEvent(event);
}
//----------------------------------------------------------------------------
void Window::parseDecorationBorder(const std::string& str)
{

View File

@@ -1,4 +1,5 @@
// Window for placing a Canvas onto it (for dialogs, menus, etc.)
///@file
/// Window for placing a Canvas onto it (for dialogs, menus, etc.)
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -67,8 +68,8 @@ namespace canvas
Element* parent = 0 );
virtual ~Window();
virtual void update(double delta_time_sec);
virtual void valueChanged(SGPropertyNode* node);
void update(double delta_time_sec) override;
void valueChanged(SGPropertyNode* node) override;
const SGVec2<float> getPosition() const;
const SGRect<float> getScreenRegion() const;
@@ -83,8 +84,8 @@ namespace canvas
bool isResizable() const;
bool isCapturingEvents() const;
virtual void setVisible(bool visible);
virtual bool isVisible() const;
void setVisible(bool visible) override;
bool isVisible() const override;
/**
* Moves window on top of all other windows with the same z-index.
@@ -96,6 +97,8 @@ namespace canvas
void handleResize( uint8_t mode,
const osg::Vec2f& offset = osg::Vec2f() );
bool handleEvent(const EventPtr& event) override;
protected:
enum Attributes

View File

@@ -1,4 +1,5 @@
// Owner Drawn Gauge helper class
///@file
/// Owner Drawn Gauge helper class
//
// Written by Harald JOHNSEN, started May 2005.
//
@@ -6,9 +7,9 @@
//
// Ported to OSG by Tim Moore - Jun 2007
//
// Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April 2012
// Supports now multisampling/mipmapping, usage of the stencil buffer and placing
// the texture in the scene by certain filter criteria
// Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April
// 2012 Supports now multisampling/mipmapping, usage of the stencil buffer and
// placing the texture in the scene by certain filter criteria.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@@ -201,6 +202,12 @@ namespace canvas
updateSampling();
}
//----------------------------------------------------------------------------
void ODGauge::setMaxAnisotropy(float anis)
{
texture->setMaxAnisotropy(anis);
}
//----------------------------------------------------------------------------
void ODGauge::setRender(bool render)
{
@@ -249,10 +256,16 @@ namespace canvas
if( !texture )
{
// It shouldn't be necessary to allocate an image for the
// texture that is the target of dynamic rendering, but
// otherwise OSG won't construct all the mipmaps for the texture
// and dynamic mipmap generation doesn't work.
osg::Image* image = new osg::Image;
image->allocateImage(_size_x, _size_y, 1, GL_RGBA, GL_UNSIGNED_BYTE);
texture = new osg::Texture2D;
texture->setResizeNonPowerOfTwoHint(false);
texture->setTextureSize(_size_x, _size_y);
texture->setInternalFormat(GL_RGBA);
texture->setImage(image);
texture->setUnRefImageDataAfterApply(true);
}
updateSampling();

View File

@@ -1,4 +1,5 @@
// Owner Drawn Gauge helper class
///@file
/// Owner Drawn Gauge helper class
//
// Written by Harald JOHNSEN, started May 2005.
//
@@ -6,9 +7,9 @@
//
// Ported to OSG by Tim Moore - Jun 2007
//
// Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April 2012
// Supports now multisampling/mipmapping, usage of the stencil buffer and placing
// the texture in the scene by certain filter criteria
// Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April
// 2012 Supports now multisampling/mipmapping, usage of the stencil buffer and
// placing the texture in the scene by certain filter criteria.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@@ -108,6 +109,8 @@ namespace canvas
int coverage_samples = 0,
int color_samples = 0 );
void setMaxAnisotropy(float anis);
/**
* Enable/Disable updating the texture (If disabled the contents of the
* texture remains with the outcome of the last rendering pass)

View File

@@ -31,6 +31,11 @@
// FreeBSD
#define VG_API_FREEBSD
#elif defined(__OpenBSD__)
// FreeBSD
#define VG_API_OPENBSD
#else
// Unsupported system

View File

@@ -34,7 +34,7 @@
#include <math.h>
#include <float.h>
#if !defined(VG_API_MACOSX) && !defined(__FreeBSD__)
#if !defined(VG_API_MACOSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
# include <malloc.h>
#endif
@@ -161,7 +161,7 @@ SHfloat getMaxFloat();
/* OpenGL headers */
#if defined(VG_API_LINUX) || defined(VG_API_FREEBSD)
#if defined(VG_API_LINUX) || defined(VG_API_FREEBSD) || defined(VG_API_OPENBSD)
#include <GL/gl.h>
#include <GL/glx.h>
#elif defined(VG_API_MACOSX)

View File

@@ -1193,7 +1193,7 @@ VG_API_CALL VGboolean vgInterpolatePath(VGPath dstPath, VGPath startPath,
SHfloat *procData1, *procData2;
SHint procSegCount1=0, procSegCount2=0;
SHint procDataCount1=0, procDataCount2=0;
SHuint8 *newSegs, *newData;
SHuint8 *newSegs, *newData=0;
void *userData[4];
SHint segment1, segment2;
SHint segindex, s,d,i;

View File

@@ -1,4 +1,5 @@
// osg::Operation to initialize the OpenVG context used for path rendering
///@file
/// osg::Operation to initialize the OpenVG context used for path rendering
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// osg::Operation to initialize the OpenVG context used for path rendering
///@file
/// osg::Operation to initialize the OpenVG context used for path rendering
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Canvas forward declarations
///@file
/// Canvas forward declarations
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -25,11 +26,9 @@
#include <osg/ref_ptr>
#include <osgText/Font>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <functional>
#include <map>
#include <memory>
#include <vector>
namespace simgear
@@ -61,8 +60,8 @@ namespace canvas
#define SG_FWD_DECL(name)\
class name;\
typedef boost::shared_ptr<name> name##Ptr;\
typedef boost::weak_ptr<name> name##WeakPtr;
typedef std::shared_ptr<name> name##Ptr;\
typedef std::weak_ptr<name> name##WeakPtr;
SG_FWD_DECL(Placement)
SG_FWD_DECL(SystemAdapter)
@@ -84,10 +83,10 @@ namespace canvas
typedef osg::ref_ptr<osgText::Font> FontPtr;
typedef std::vector<PlacementPtr> Placements;
typedef boost::function<Placements( SGPropertyNode*,
CanvasPtr )> PlacementFactory;
typedef std::function<Placements( SGPropertyNode*,
CanvasPtr )> PlacementFactory;
typedef boost::function<void(const EventPtr&)> EventListener;
typedef std::function<void(const EventPtr&)> EventListener;
} // namespace canvas
} // namespace simgear

View File

@@ -1,4 +1,5 @@
// Interface for 2D Canvas element
///@file
/// Interface for 2D Canvas element
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -271,8 +272,7 @@ namespace canvas
//----------------------------------------------------------------------------
void Element::setFocus()
{
CanvasPtr canvas = _canvas.lock();
if( canvas )
if( auto canvas = _canvas.lock() )
canvas->setFocusElement(this);
}

View File

@@ -29,9 +29,6 @@
#include <osg/BoundingBox>
#include <osg/MatrixTransform>
#include <boost/bind.hpp>
#include <boost/function.hpp>
namespace osg
{
class Drawable;
@@ -62,9 +59,9 @@ namespace canvas
OSGUserData(ElementPtr element);
};
typedef boost::function<bool(Element&, const SGPropertyNode*)>
typedef std::function<bool(Element&, const SGPropertyNode*)>
StyleSetterFunc;
typedef boost::function<void(Element&, const SGPropertyNode*)>
typedef std::function<void(Element&, const SGPropertyNode*)>
StyleSetterFuncUnchecked;
struct StyleSetter:
public SGReferenced
@@ -95,7 +92,7 @@ namespace canvas
*
*/
virtual ~Element() = 0;
virtual void onDestroy();
void onDestroy() override;
ElementPtr getParent() const;
CanvasWeakPtr getCanvas() const;
@@ -105,7 +102,7 @@ namespace canvas
*
* @param dt Frame time in seconds
*/
virtual void update(double dt);
void update(double dt) override;
bool addEventListener(const std::string& type, const EventListener& cb);
virtual void clearEventListener();
@@ -154,11 +151,9 @@ namespace canvas
*/
osg::Vec2f posToLocal(const osg::Vec2f& pos) const;
virtual void childAdded( SGPropertyNode * parent,
SGPropertyNode * child );
virtual void childRemoved( SGPropertyNode * parent,
SGPropertyNode * child );
virtual void valueChanged(SGPropertyNode * child);
void childAdded(SGPropertyNode* parent, SGPropertyNode* child) override;
void childRemoved(SGPropertyNode* parent, SGPropertyNode* child) override;
void valueChanged(SGPropertyNode* child) override;
virtual bool setStyle( const SGPropertyNode* child,
const StyleInfo* style_info = 0 );
@@ -321,7 +316,7 @@ namespace canvas
StyleSetter
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Derived&, T2)>& setter,
const std::function<void (Derived&, T2)>& setter,
bool inheritable = true )
{
StyleInfo& style_info = _style_setters[ name ];
@@ -347,13 +342,10 @@ namespace canvas
if( style->func )
style = style->next = new StyleSetter;
style->func = boost::bind
(
&type_match<Derived>::call,
_1,
_2,
bindStyleSetter<T1>(name, setter)
);
style->func = std::bind(&type_match<Derived>::call,
std::placeholders::_1,
std::placeholders::_2,
bindStyleSetter<T1>(name, setter));
return *style;
}
@@ -365,7 +357,7 @@ namespace canvas
StyleSetter
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Derived&, T)>& setter,
const std::function<void (Derived&, T)>& setter,
bool inheritable = true )
{
return addStyle<T, T>(name, type, setter, inheritable);
@@ -386,7 +378,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, T)>(setter),
std::function<void (Derived&, T)>(setter),
inheritable
);
}
@@ -407,7 +399,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, T2)>(setter),
std::function<void (Derived&, T2)>(setter),
inheritable
);
}
@@ -426,7 +418,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, const std::string&)>(setter),
std::function<void (Derived&, const std::string&)>(setter),
inheritable
);
}
@@ -489,7 +481,7 @@ namespace canvas
StyleSetter
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Other&, T2)>& setter,
const std::function<void (Other&, T2)>& setter,
OtherRef Derived::*instance_ref,
bool inheritable = true )
{
@@ -519,7 +511,7 @@ namespace canvas
(
name,
type,
boost::function<void (Other&, const std::string&)>(setter),
std::function<void (Other&, const std::string&)>(setter),
instance_ref,
inheritable
);
@@ -527,44 +519,37 @@ namespace canvas
template<typename T, class Derived, class Other, class OtherRef>
static
boost::function<void (Derived&, T)>
std::function<void (Derived&, T)>
bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref )
{
return boost::bind(setter, boost::bind(instance_ref, _1), _2);
return std::bind(setter,
std::bind(instance_ref, std::placeholders::_1),
std::placeholders::_2);
}
template<typename T, class Derived, class Other, class OtherRef>
static
boost::function<void (Derived&, T)>
bindOther( const boost::function<void (Other&, T)>& setter,
std::function<void (Derived&, T)>
bindOther( const std::function<void (Other&, T)>& setter,
OtherRef Derived::*instance_ref )
{
return boost::bind
(
setter,
boost::bind
(
&reference_from_pointer<Other, OtherRef>,
boost::bind(instance_ref, _1)
),
_2
);
return std::bind(setter,
std::bind(&reference_from_pointer<Other, OtherRef>,
std::bind(instance_ref, std::placeholders::_1)),
std::placeholders::_2);
}
template<typename T1, typename T2, class Derived>
static
StyleSetterFuncUnchecked
bindStyleSetter( const std::string& name,
const boost::function<void (Derived&, T2)>& setter )
const std::function<void (Derived&, T2)>& setter )
{
return boost::bind
(
setter,
// We will only call setters with Derived instances, so we can safely
// cast here.
boost::bind(&derived_cast<Derived>, _1),
boost::bind(&getValue<T1>, _2)
);
return std::bind(setter,
// We will only call setters with Derived instances, so we can safely
// cast here.
std::bind(&derived_cast<Derived>, std::placeholders::_1),
std::bind(&getValue<T1>, std::placeholders::_2));
}
bool isStyleEmpty(const SGPropertyNode* child) const;
@@ -597,7 +582,7 @@ namespace canvas
osg::ref_ptr<osg::Drawable> _drawable;
Element(const Element&);// = delete
Element(const Element&) = delete;
template<class Derived>
static Derived& derived_cast(Element& el)

View File

@@ -1,4 +1,5 @@
// A group of 2D Canvas elements
///@file
/// A group of 2D Canvas elements
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -168,6 +169,7 @@ namespace canvas
if( !_scene_group.valid() )
return warnSceneGroupExpired("clearEventListener");
// TODO should this be recursive?
for(size_t i = 0; i < _scene_group->getNumChildren(); ++i)
getChildByIndex(i)->clearEventListener();
}

View File

@@ -1,4 +1,5 @@
// A group of 2D Canvas elements
///@file
/// A group of 2D Canvas elements
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -86,14 +87,15 @@ namespace canvas
*/
ElementPtr getElementById(const std::string& id);
virtual void clearEventListener();
void clearEventListener() override;
virtual bool traverse(EventVisitor& visitor);
bool traverse(EventVisitor& visitor) override;
virtual bool setStyle( const SGPropertyNode* child,
const StyleInfo* style_info = 0 );
bool setStyle( const SGPropertyNode* child,
const StyleInfo* style_info = 0 ) override;
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
osg::BoundingBox
getTransformedBounds(const osg::Matrix& m) const override;
protected:
@@ -105,11 +107,11 @@ namespace canvas
*/
virtual ElementFactory getChildFactory(const std::string& type) const;
virtual void updateImpl(double dt);
void updateImpl(double dt) override;
virtual void childAdded(SGPropertyNode * child);
virtual void childRemoved(SGPropertyNode * child);
virtual void childChanged(SGPropertyNode * child);
void childAdded(SGPropertyNode * child) override;
void childRemoved(SGPropertyNode * child) override;
void childChanged(SGPropertyNode * child) override;
void handleZIndexChanged(ElementPtr child, int z_index = 0);

View File

@@ -1,4 +1,5 @@
// An image on the Canvas
///@file
/// An image on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -837,5 +838,143 @@ namespace canvas
return false;
}
void Image::fillRect(const SGRect<int>& rect, const std::string& c)
{
osg::Vec4 color(1,1,1,1);
if(!c.empty() && !parseColor(c, color))
return;
fillRect(rect, color);
}
void fillRow(GLubyte* row, GLuint pixel, GLuint width, GLuint pixelBytes)
{
GLubyte* dst = row;
for (GLuint x = 0; x < width; ++x) {
memcpy(dst, &pixel, pixelBytes);
dst += pixelBytes;
}
}
SGRect<int> intersectRect(const SGRect<int>& a, const SGRect<int>& b)
{
SGVec2<int> m1 = max(a.getMin(), b.getMin());
SGVec2<int> m2 = min(a.getMax(), b.getMax());
return SGRect<int>(m1, m2);
}
void Image::fillRect(const SGRect<int>& rect, const osg::Vec4& color)
{
osg::ref_ptr<osg::Image> image = _texture->getImage();
if (!image) {
allocateImage();
image = _texture->getImage();
}
if (image->getDataVariance() != osg::Object::DYNAMIC) {
image->setDataVariance(osg::Object::DYNAMIC);
}
const auto format = image->getInternalTextureFormat();
auto clippedRect = intersectRect(rect, SGRect<int>(0, 0, image->s(), image->t()));
if ((clippedRect.width() == 0) || (clippedRect.height() == 0)) {
return;
}
GLubyte* rowData = nullptr;
size_t rowByteSize = 0;
GLuint pixelWidth = clippedRect.width();
GLuint pixel = 0;
GLuint pixelBytes = 0;
switch (format) {
case GL_RGBA8:
case GL_RGBA:
rowByteSize = pixelWidth * 4;
rowData = static_cast<GLubyte*>(alloca(rowByteSize));
// assume litte-endian, so read out backwards, hence when we memcpy
// the data, it ends up in RGBA order
pixel = color.asABGR();
pixelBytes = 4;
fillRow(rowData, pixel, pixelWidth, pixelBytes);
break;
case GL_RGB8:
case GL_RGB:
rowByteSize = pixelWidth * 3;
rowData = static_cast<GLubyte*>(alloca(rowByteSize));
pixel = color.asABGR();
pixelBytes = 3;
fillRow(rowData, pixel, pixelWidth, pixelBytes);
break;
default:
SG_LOG(SG_IO, SG_WARN, "Image::fillRect: unsupported internal image format:" << format);
return;
}
for (int row=clippedRect.t(); row < clippedRect.b(); ++row) {
GLubyte* imageData = image->data(clippedRect.l(), row);
memcpy(imageData, rowData, rowByteSize);
}
image->dirty();
auto c = getCanvas().lock();
c->enableRendering(true); // force a repaint
}
void Image::setPixel(int x, int y, const std::string& c)
{
osg::Vec4 color(1,1,1,1);
if(!c.empty() && !parseColor(c, color))
return;
setPixel(x, y, color);
}
void Image::setPixel(int x, int y, const osg::Vec4& color)
{
osg::ref_ptr<osg::Image> image = _texture->getImage();
if (!image) {
allocateImage();
image = _texture->getImage();
}
if (image->getDataVariance() != osg::Object::DYNAMIC) {
image->setDataVariance(osg::Object::DYNAMIC);
}
image->setColor(color, x, y);
}
void Image::dirtyPixels()
{
osg::ref_ptr<osg::Image> image = _texture->getImage();
if (!image)
return;
image->dirty();
auto c = getCanvas().lock();
c->enableRendering(true); // force a repaint
}
void Image::allocateImage()
{
osg::Image* image = new osg::Image;
// default to RGBA
image->allocateImage(_node->getIntValue("size[0]"), _node->getIntValue("size[1]"), 1, GL_RGBA, GL_UNSIGNED_BYTE);
image->setInternalTextureFormat(GL_RGBA);
_texture->setImage(image);
}
osg::ref_ptr<osg::Image> Image::getImage() const
{
if (!_texture)
return {};
return _texture->getImage();
}
} // namespace canvas
} // namespace simgear

View File

@@ -1,4 +1,5 @@
// An image on the Canvas
///@file
/// An image on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -53,7 +54,7 @@ namespace canvas
ElementWeakPtr parent = 0 );
virtual ~Image();
virtual void valueChanged(SGPropertyNode* child);
void valueChanged(SGPropertyNode* child) override;
void setSrcCanvas(CanvasPtr canvas);
CanvasWeakPtr getSrcCanvas() const;
@@ -93,13 +94,35 @@ namespace canvas
const SGRect<float>& getRegion() const;
bool handleEvent(const EventPtr& event);
bool handleEvent(const EventPtr& event) override;
/**
*
*/
void setSourceRect(const SGRect<float>& sourceRect);
/**
* fill the specified rectangle of the image, with an RGB value
*/
void fillRect(const SGRect<int>& rect, const std::string& color);
/**
* fill the specified rectangle of the image, with an RGB value
*/
void fillRect(const SGRect<int>& rect, const osg::Vec4& color);
void setPixel(int x, int y, const std::string& color);
void setPixel(int x, int y, const osg::Vec4& color);
/**
* mark the image pixels as modified, so the canvas is re-painted
*/
void dirtyPixels();
osg::ref_ptr<osg::Image> getImage() const;
// void setRow(int row, int offset, )
protected:
enum ImageAttributes
{
@@ -108,9 +131,9 @@ namespace canvas
SRC_CANVAS = DEST_SIZE << 1
};
virtual void updateImpl(double dt);
void updateImpl(double dt) override;
virtual void childChanged(SGPropertyNode * child);
void childChanged(SGPropertyNode * child) override;
void setupDefaultDimensions();
SGRect<int> getTextureDimensions() const;
@@ -124,6 +147,8 @@ namespace canvas
HTTP::Request& request,
const std::string& type );
void allocateImage();
osg::ref_ptr<osg::Texture2D> _texture;
// TODO optionally forward events to canvas
CanvasWeakPtr _src_canvas;

View File

@@ -1,5 +1,6 @@
// A group of 2D Canvas elements which get automatically transformed according
// to the map parameters.
///@file
/// A group of 2D Canvas elements which get automatically transformed according
/// to the map parameters.
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -96,17 +97,26 @@ namespace canvas
|| (!geo_node->isDirty() && !_projection_dirty) )
continue;
GeoCoord lat = parseGeoCoord(geo_node->getLat());
if( lat.type != GeoCoord::LATITUDE )
continue;
GeoCoord lon = parseGeoCoord(geo_node->getLon());
if( lon.type != GeoCoord::LONGITUDE )
continue;
Projection::ScreenPosition pos =
_projection->worldToScreen(lat.value, lon.value);
double latD = -9999.0, lonD = -9999.0;
if (geo_node->isDirty()) {
GeoCoord lat = parseGeoCoord(geo_node->getLat());
if( lat.type != GeoCoord::LATITUDE )
continue;
GeoCoord lon = parseGeoCoord(geo_node->getLon());
if( lon.type != GeoCoord::LONGITUDE )
continue;
// save the parsed values so we can re-use them if only projection
// is changed (very common case for moving vehicle)
latD = lat.value;
lonD = lon.value;
geo_node->setCachedLatLon(std::make_pair(latD, lonD));
} else {
std::tie(latD, lonD) = geo_node->getCachedLatLon();
}
Projection::ScreenPosition pos = _projection->worldToScreen(latD, lonD);
geo_node->setScreenPos(pos.x, pos.y);
// geo_node->print();
@@ -199,10 +209,18 @@ namespace canvas
_projection = std::make_shared<SansonFlamsteedProjection>();
_projection->setWorldPosition(_node->getDoubleValue(REF_LAT),
_node->getDoubleValue(REF_LON) );
_projection->setOrientation(_node->getFloatValue(HDG));
_projection->setScreenRange(_node->getDoubleValue(SCREEN_RANGE));
_projection->setRange(_node->getDoubleValue(RANGE));
_node->getDoubleValue(REF_LON));
// Only set existing properties to prevent using 0 instead of default values
if( auto heading = _node->getChild(HDG) )
_projection->setOrientation(heading->getFloatValue());
if( auto screen_range = _node->getChild(SCREEN_RANGE) )
_projection->setScreenRange(screen_range->getDoubleValue());
if( auto range = _node->getChild(RANGE) )
_projection->setRange(range->getDoubleValue());
_projection_dirty = true;
}

View File

@@ -1,5 +1,6 @@
// A group of 2D Canvas elements which get automatically transformed according
// to the map parameters.
///@file
/// A group of 2D Canvas elements which get automatically transformed according
/// to the map parameters.
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -46,16 +47,14 @@ namespace canvas
virtual ~Map();
protected:
virtual void updateImpl(double dt);
void updateImpl(double dt) override;
void updateProjection(SGPropertyNode* type_node);
virtual void childAdded( SGPropertyNode* parent,
SGPropertyNode* child );
virtual void childRemoved( SGPropertyNode* parent,
SGPropertyNode* child );
virtual void valueChanged(SGPropertyNode* child);
virtual void childChanged(SGPropertyNode* child);
void childAdded(SGPropertyNode* parent, SGPropertyNode* child) override;
void childRemoved(SGPropertyNode* parent, SGPropertyNode* child) override;
void valueChanged(SGPropertyNode* child) override;
void childChanged(SGPropertyNode* child) override;
using GeoNodes =
std::unordered_map<SGPropertyNode*, std::shared_ptr<GeoNodePair>>;

View File

@@ -1,4 +1,5 @@
// An OpenVG path on the Canvas
///@file
/// An OpenVG path on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -230,9 +231,12 @@ namespace canvas
vgDestroyPaint(_paint_fill);
}
virtual const char* className() const { return "PathDrawable"; }
virtual osg::Object* cloneType() const { return new PathDrawable(_path_element); }
virtual osg::Object* clone(const osg::CopyOp&) const { return new PathDrawable(_path_element); }
const char* className() const override
{ return "PathDrawable"; }
osg::Object* cloneType() const override
{ return new PathDrawable(_path_element); }
osg::Object* clone(const osg::CopyOp&) const override
{ return new PathDrawable(_path_element); }
/**
* Replace the current path segments with the new ones
@@ -383,7 +387,7 @@ namespace canvas
/**
* Draw callback
*/
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
void drawImplementation(osg::RenderInfo& renderInfo) const override
{
if( _attributes_dirty & PATH )
return;
@@ -555,13 +559,13 @@ namespace canvas
/**
* Compute the bounding box
*/
virtual osg::BoundingBox
osg::BoundingBox
#if OSG_VERSION_LESS_THAN(3,3,2)
computeBound()
#else
computeBoundingBox()
#endif
const
const override
{
if( _path == VG_INVALID_HANDLE || (_attributes_dirty & PATH) )
return osg::BoundingBox();
@@ -667,7 +671,7 @@ namespace canvas
struct PathUpdateCallback:
public osg::Drawable::UpdateCallback
{
virtual void update(osg::NodeVisitor*, osg::Drawable* drawable)
void update(osg::NodeVisitor*, osg::Drawable* drawable) override
{
static_cast<PathDrawable*>(drawable)->update();
}
@@ -859,6 +863,9 @@ namespace canvas
//----------------------------------------------------------------------------
void Path::childChanged(SGPropertyNode* child)
{
if( child->getParent() != _node )
return;
const std::string& name = child->getNameString();
const std::string &prName = child->getParent()->getNameString();
@@ -888,16 +895,15 @@ namespace canvas
return;
}
if( child->getParent() != _node )
return;
if( name == "cmd" )
_attributes_dirty |= CMDS;
else if( name == "coord" )
_attributes_dirty |= COORDS;
else if ( name == "svg")
{
_hasSVG = true;
_attributes_dirty |= SVG;
}
}
//----------------------------------------------------------------------------

View File

@@ -1,4 +1,5 @@
// An OpenVG path on the Canvas
///@file
/// An OpenVG path on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -40,7 +41,8 @@ namespace canvas
ElementWeakPtr parent = 0 );
virtual ~Path();
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
osg::BoundingBox
getTransformedBounds(const osg::Matrix& m) const override;
/** Add a segment with the given command and coordinates */
Path& addSegment(uint8_t cmd, std::initializer_list<float> coords = {});
@@ -86,10 +88,10 @@ namespace canvas
bool _hasRect : 1;
SGRectf _rect;
virtual void updateImpl(double dt);
void updateImpl(double dt) override;
virtual void childRemoved(SGPropertyNode * child);
virtual void childChanged(SGPropertyNode * child);
void childRemoved(SGPropertyNode * child) override;
void childChanged(SGPropertyNode * child) override;
void parseRectToVGPath();
};

View File

@@ -1,4 +1,5 @@
// A text on the Canvas
///@file
/// A text on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//
@@ -17,6 +18,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include <simgear_config.h>
#include "CanvasText.hxx"
#include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasSystemAdapter.hxx>
@@ -51,27 +53,31 @@ namespace canvas
TextLine lineAt(size_t i) const;
/// Get nearest line to given y-coordinate
#if OSG_VERSION_LESS_THAN(3,6,5)
TextLine nearestLine(float pos_y) const;
SGVec2i sizeForWidth(int w) const;
virtual osg::BoundingBox
#if OSG_VERSION_LESS_THAN(3,3,2)
computeBound()
#else
computeBoundingBox()
TextLine nearestLine(float pos_y);
SGVec2i sizeForWidth(int w);
#endif
#if OSG_VERSION_LESS_THAN(3,3,2)
osg::BoundingBox computeBound() const override;
#else
osg::BoundingBox computeBoundingBox() const override;
#endif
const;
protected:
friend class TextLine;
canvas::Text *_text_element;
virtual void computePositions(unsigned int contextID) const;
};
#if OSG_VERSION_LESS_THAN(3,5,6)
void computePositions(unsigned int contextID) const override;
#else
void computePositionsImplementation() override;
#endif
};
class TextLine
{
@@ -121,6 +127,7 @@ namespace canvas
_quads = &text->_textureGlyphQuadMap.begin()->second;
#if OSG_VERSION_LESS_THAN(3,5,6)
GlyphQuads::LineNumbers const& line_numbers = _quads->_lineNumbers;
GlyphQuads::LineNumbers::const_iterator begin_it =
std::lower_bound(line_numbers.begin(), line_numbers.end(), _line);
@@ -132,6 +139,9 @@ namespace canvas
_begin = begin_it - line_numbers.begin();
_end = std::upper_bound(begin_it, line_numbers.end(), _line)
- line_numbers.begin();
#else
// TODO: Need 3.5.6 version of this
#endif
}
//----------------------------------------------------------------------------
@@ -160,34 +170,40 @@ namespace canvas
if( empty() )
return pos;
#if OSG_VERSION_LESS_THAN(3,3,5)
GlyphQuads::Coords2 const& coords = _quads->_coords;
#if OSG_VERSION_GREATER_OR_EQUAL(3,5,6)
// TODO: need 3.5.6 version of this.
#else
GlyphQuads::Coords2 refCoords = _quads->_coords;
GlyphQuads::Coords2::element_type &coords = *refCoords.get();
#if OSG_VERSION_LESS_THAN(3,3,5)
GlyphQuads::Coords2 const& coords = _quads->_coords;
#else
GlyphQuads::Coords2 refCoords = _quads->_coords;
GlyphQuads::Coords2::element_type &coords = *refCoords.get();
#endif
size_t global_i = _begin + i;
if( global_i == _begin )
// before first character of line
pos.x() = coords[_begin * 4].x();
else if( global_i == _end )
// After Last character of line
pos.x() = coords[(_end - 1) * 4 + 2].x();
else
{
float prev_l = coords[(global_i - 1) * 4].x(),
prev_r = coords[(global_i - 1) * 4 + 2].x(),
cur_l = coords[global_i * 4].x();
size_t global_i = _begin + i;
if( prev_l == prev_r )
// If previous character width is zero set to begin of next character
// (Happens eg. with spaces)
pos.x() = cur_l;
if (global_i == _begin)
// before first character of line
pos.x() = coords[_begin * 4].x();
else if (global_i == _end)
// After Last character of line
pos.x() = coords[(_end - 1) * 4 + 2].x();
else
// position at center between characters
pos.x() = 0.5 * (prev_r + cur_l);
}
{
float prev_l = coords[(global_i - 1) * 4].x(),
prev_r = coords[(global_i - 1) * 4 + 2].x(),
cur_l = coords[global_i * 4].x();
if (prev_l == prev_r)
// If previous character width is zero set to begin of next character
// (Happens eg. with spaces)
pos.x() = cur_l;
else
// position at center between characters
pos.x() = 0.5 * (prev_r + cur_l);
}
#endif
return pos;
}
@@ -195,17 +211,22 @@ namespace canvas
//----------------------------------------------------------------------------
osg::Vec2 TextLine::nearestCursor(float x) const
{
if( empty() )
if (empty())
return cursorPos(0);
GlyphQuads::Glyphs const& glyphs = _quads->_glyphs;
#if OSG_VERSION_LESS_THAN(3,3,5)
#if OSG_VERSION_GREATER_OR_EQUAL(3,5,6)
// TODO: need 3.5.7 version of this.
return cursorPos(0);
#else
#if OSG_VERSION_LESS_THAN(3,3,5)
GlyphQuads::Coords2 const& coords = _quads->_coords;
#else
GlyphQuads::Coords2 refCoords = _quads->_coords;
GlyphQuads::Coords2::element_type &coords = *refCoords.get();
#endif
GlyphQuads::Glyphs const& glyphs = _quads->_glyphs;
float const HIT_FRACTION = 0.6;
float const character_width = _text->getCharacterHeight()
* _text->getCharacterAspectRatio();
@@ -224,6 +245,7 @@ namespace canvas
}
return cursorPos(i - _begin);
#endif
}
//----------------------------------------------------------------------------
@@ -302,9 +324,16 @@ namespace canvas
}
//----------------------------------------------------------------------------
#if OSG_VERSION_LESS_THAN(3,6,5)
TextLine Text::TextOSG::nearestLine(float pos_y) const
{
osgText::Font const* font = getActiveFont();
#else
TextLine Text::TextOSG::nearestLine(float pos_y)
{
auto font = getActiveFont();
#endif
if( !font || lineCount() <= 0 )
return TextLine(0, this);
@@ -326,12 +355,21 @@ namespace canvas
// simplified version of osgText::Text::computeGlyphRepresentation() to
// just calculate the size for a given weight. Glpyh calculations/creating
// is not necessary for this...
#if OSG_VERSION_LESS_THAN(3,6,5)
SGVec2i Text::TextOSG::sizeForWidth(int w) const
#else
SGVec2i Text::TextOSG::sizeForWidth(int w)
#endif
{
if( _text.empty() )
return SGVec2i(0, 0);
#if OSG_VERSION_LESS_THAN(3,6,5)
osgText::Font* activefont = const_cast<osgText::Font*>(getActiveFont());
#else
auto activefont = getActiveFont();
#endif
if( !activefont )
return SGVec2i(-1, -1);
@@ -611,19 +649,16 @@ namespace canvas
}
//----------------------------------------------------------------------------
osg::BoundingBox
#if OSG_VERSION_LESS_THAN(3,3,2)
Text::TextOSG::computeBound()
osg::BoundingBox Text::TextOSG::computeBound() const
#else
Text::TextOSG::computeBoundingBox()
osg::BoundingBox Text::TextOSG::computeBoundingBox() const
#endif
const
{
osg::BoundingBox bb =
#if OSG_VERSION_LESS_THAN(3,3,2)
osgText::Text::computeBound();
osg::BoundingBox bb = osgText::Text::computeBound();
#else
osgText::Text::computeBoundingBox();
osg::BoundingBox bb = osgText::Text::computeBoundingBox();
#endif
#if OSG_VERSION_LESS_THAN(3,1,0)
@@ -639,7 +674,7 @@ namespace canvas
return bb;
}
//----------------------------------------------------------------------------
#if OSG_VERSION_LESS_THAN(3,5,6)
void Text::TextOSG::computePositions(unsigned int contextID) const
{
if( _textureGlyphQuadMap.empty() || _layout == VERTICAL )
@@ -709,6 +744,14 @@ namespace canvas
return osgText::Text::computePositions(contextID);
}
#else
void Text::TextOSG::computePositionsImplementation()
{
TextBase::computePositionsImplementation();
}
#endif
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
const std::string Text::TYPE_NAME = "text";

View File

@@ -1,4 +1,5 @@
// A text on the Canvas
///@file
/// A text on the Canvas
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -67,7 +67,8 @@ namespace canvas
{
_node_lat = node;
_status &= ~LAT_MISSING;
_xNode.reset();
if( node == _node_lon )
{
_node_lon = 0;
@@ -79,7 +80,8 @@ namespace canvas
{
_node_lon = node;
_status &= ~LON_MISSING;
_yNode.reset();
if( node == _node_lat )
{
_node_lat = 0;
@@ -97,19 +99,34 @@ namespace canvas
return _node_lon ? _node_lon->getStringValue() : "";
}
void setCachedLatLon(const std::pair<double, double>& latLon)
{ _cachedLatLon = latLon; }
std::pair<double, double> getCachedLatLon()
{ return _cachedLatLon; }
void setTargetName(const std::string& name)
{
_target_name = name;
_xNode.reset();
_yNode.reset();
}
void setScreenPos(float x, float y)
{
assert( isComplete() );
SGPropertyNode *parent = _node_lat->getParent();
parent->getChild(_target_name, _node_lat->getIndex(), true)
->setDoubleValue(x);
parent->getChild(_target_name, _node_lon->getIndex(), true)
->setDoubleValue(y);
if (!_xNode) {
SGPropertyNode *parent = _node_lat->getParent();
_xNode = parent->getChild(_target_name, _node_lat->getIndex(), true);
}
if (!_yNode) {
SGPropertyNode *parent = _node_lat->getParent();
_yNode = parent->getChild(_target_name, _node_lon->getIndex(), true);
}
_xNode->setDoubleValue(x);
_yNode->setDoubleValue(y);
}
void print()
@@ -125,6 +142,9 @@ namespace canvas
SGPropertyNode *_node_lat,
*_node_lon;
std::string _target_name;
SGPropertyNode_ptr _xNode,
_yNode;
std::pair<double, double> _cachedLatLon;
};

View File

@@ -1,4 +1,5 @@
// Geographic projections for Canvas map element
///@file
/// Geographic projections for Canvas map element
//
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Canvas user defined event
///@file
/// Canvas user defined event
//
// Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
//
@@ -46,6 +47,14 @@ namespace canvas
// assert( type_map.find(type_id) != type_map.end() );
}
//----------------------------------------------------------------------------
CustomEvent* CustomEvent::clone(int type) const
{
auto event = new CustomEvent(*this);
event->type = type;
return event;
}
//----------------------------------------------------------------------------
void CustomEvent::setDetail(StringMap const& data)
{

View File

@@ -38,6 +38,7 @@ namespace canvas
public:
/**
* @brief Construct a user defined event from a type string
*
* @param type_str Event type name (if name does not exist yet it will
* be registered as new event type)
@@ -49,6 +50,10 @@ namespace canvas
StringMap const& data = StringMap() );
/**
* @brief Construct a user defined event from a (previously registered)
* type id
*
* @see getOrRegisterType()
*
* @param type_id Event type id
* @param bubbles If this event should take part in the bubbling phase
@@ -58,6 +63,8 @@ namespace canvas
bool bubbles = false,
StringMap const& data = StringMap() );
CustomEvent* clone(int type = 0) const override;
/**
* Set user data
*/
@@ -74,7 +81,7 @@ namespace canvas
* @see #bubbles
* @see CustomEvent()
*/
virtual bool canBubble() const { return bubbles; }
bool canBubble() const override { return bubbles; }
StringMap detail; //!< User data map
bool bubbles; //!< Whether the event supports bubbling

View File

@@ -1,4 +1,5 @@
// Input device event
///@file
/// Input device event
//
// Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -1,4 +1,5 @@
// Keyboard event
///@file
/// Keyboard event
//
// Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
//
@@ -69,6 +70,14 @@ namespace canvas
// // TODO what to do with wrong event type?
}
//----------------------------------------------------------------------------
KeyboardEvent* KeyboardEvent::clone(int type) const
{
auto event = new KeyboardEvent(*this);
event->type = type;
return event;
}
//----------------------------------------------------------------------------
void KeyboardEvent::setKey(uint32_t key)
{

View File

@@ -45,6 +45,7 @@ namespace canvas
KeyboardEvent();
KeyboardEvent(const osgGA::GUIEventAdapter& ea);
KeyboardEvent* clone(int type = 0) const override;
void setKey(uint32_t key);
void setUnmodifiedKey(uint32_t key);

View File

@@ -1,4 +1,5 @@
// Mouse event
///@file
/// Mouse event
//
// Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
//
@@ -48,6 +49,14 @@ namespace canvas
button += 1;
}
//----------------------------------------------------------------------------
MouseEvent* MouseEvent::clone(int type) const
{
auto event = new MouseEvent(*this);
event->type = type;
return event;
}
//----------------------------------------------------------------------------
bool MouseEvent::canBubble() const
{

View File

@@ -36,8 +36,9 @@ namespace canvas
public:
MouseEvent();
MouseEvent(const osgGA::GUIEventAdapter& ea);
MouseEvent* clone(int type = 0) const override;
virtual bool canBubble() const;
bool canBubble() const override;
osg::Vec2f getScreenPos() const { return screen_pos; }
osg::Vec2f getClientPos() const { return client_pos; }

View File

@@ -1,4 +1,5 @@
// Keyboard event demo. Press some keys and get some info...
///@file
/// Keyboard event demo. Press some keys and get some info...
//
// Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
//

View File

@@ -73,7 +73,7 @@ namespace canvas
int stretch,
uint8_t alignment )
{
ItemData item_data = {0};
ItemData item_data = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
item_data.layout_item = item;
item_data.stretch = std::max(0, stretch);

View File

@@ -18,6 +18,9 @@
#include <simgear_config.h>
#include "Layout.hxx"
#include <algorithm>
#include <simgear/debug/logstream.hxx>
namespace simgear

View File

@@ -150,7 +150,7 @@ namespace canvas
//----------------------------------------------------------------------------
bool NasalWidget::hasHeightForWidth() const
{
return !_height_for_width.empty() || !_min_height_for_width.empty();
return _height_for_width || _min_height_for_width;
}
//----------------------------------------------------------------------------
@@ -186,7 +186,7 @@ namespace canvas
int NasalWidget::callHeightForWidthFunc( const HeightForWidthFunc& hfw,
int w ) const
{
if( hfw.empty() )
if( !hfw )
return -1;
try
@@ -239,17 +239,17 @@ namespace canvas
//----------------------------------------------------------------------------
int NasalWidget::heightForWidthImpl(int w) const
{
return callHeightForWidthFunc( _height_for_width.empty()
? _min_height_for_width
: _height_for_width, w );
return callHeightForWidthFunc( _height_for_width
? _height_for_width
: _min_height_for_width, w );
}
//----------------------------------------------------------------------------
int NasalWidget::minimumHeightForWidthImpl(int w) const
{
return callHeightForWidthFunc( _min_height_for_width.empty()
? _height_for_width
: _min_height_for_width, w );
return callHeightForWidthFunc( _min_height_for_width
? _min_height_for_width
: _height_for_width, w );
}

View File

@@ -40,8 +40,8 @@ namespace canvas
{
public:
typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
typedef std::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
typedef std::function<int (nasal::Me, int)> HeightForWidthFunc;
/**
*

View File

@@ -218,6 +218,9 @@ const float SG_RADIANS_TO_DEGREES = 180.0f / SG_PI;
#define SG_OBJECT_RANGE_ROUGH 9000.0
#define SG_OBJECT_RANGE_DETAILED 1500.0
/** Minimum expiry time of PagedLOD within the Tile. Overridden by /sim/rendering/plod-minimum-expiry-time-secs **/
#define SG_TILE_MIN_EXPIRY 180.0
/** Radius of scenery tiles in m **/
#define SG_TILE_RADIUS 14000.0

View File

@@ -18,30 +18,29 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear_config.h>
#include <simgear/debug/BufferedLogCallback.hxx>
#include <boost/foreach.hpp>
#include <simgear/sg_inlines.h>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
#include <cstdlib> // for malloc
#include <cstring>
#include <mutex>
namespace simgear
{
class BufferedLogCallback::BufferedLogCallbackPrivate
{
public:
SGMutex m_mutex;
std::mutex m_mutex;
vector_cstring m_buffer;
unsigned int m_stamp;
unsigned int m_maxLength;
};
BufferedLogCallback::BufferedLogCallback(sgDebugClass c, sgDebugPriority p) :
simgear::LogCallback(c,p),
d(new BufferedLogCallbackPrivate)
@@ -52,19 +51,19 @@ BufferedLogCallback::BufferedLogCallback(sgDebugClass c, sgDebugPriority p) :
BufferedLogCallback::~BufferedLogCallback()
{
BOOST_FOREACH(unsigned char* msg, d->m_buffer) {
for (auto msg : d->m_buffer) {
free(msg);
}
}
void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
{
SG_UNUSED(file);
SG_UNUSED(line);
if (!shouldLog(c, p)) return;
vector_cstring::value_type msg;
if (aMessage.size() >= d->m_maxLength) {
msg = (vector_cstring::value_type) malloc(d->m_maxLength);
@@ -73,29 +72,29 @@ void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
} else {
msg = (vector_cstring::value_type) strdup(aMessage.c_str());
}
SGGuard<SGMutex> g(d->m_mutex);
std::lock_guard<std::mutex> g(d->m_mutex);
d->m_buffer.push_back(msg);
d->m_stamp++;
}
unsigned int BufferedLogCallback::stamp() const
{
return d->m_stamp;
}
unsigned int BufferedLogCallback::threadsafeCopy(vector_cstring& aOutput)
{
SGGuard<SGMutex> g(d->m_mutex);
std::lock_guard<std::mutex> g(d->m_mutex);
size_t sz = d->m_buffer.size();
aOutput.resize(sz);
memcpy(aOutput.data(), d->m_buffer.data(), sz * sizeof(vector_cstring::value_type));
return d->m_stamp;
}
}
void BufferedLogCallback::truncateAt(unsigned int t)
{
d->m_maxLength = t;
}
} // of namespace simgear

View File

@@ -26,7 +26,7 @@
#include <vector>
#include <memory> // for std::unique_ptr
#include <simgear/debug/logstream.hxx>
#include <simgear/debug/LogCallback.hxx>
namespace simgear
{

View File

@@ -1,7 +1,14 @@
include (SimGearComponent)
set(HEADERS debug_types.h logstream.hxx BufferedLogCallback.hxx)
set(SOURCES logstream.cxx BufferedLogCallback.cxx)
set(HEADERS debug_types.h
logstream.hxx BufferedLogCallback.hxx OsgIoCapture.hxx
LogCallback.hxx LogEntry.hxx
ErrorReportingCallback.hxx)
simgear_component(debug debug "${SOURCES}" "${HEADERS}")
set(SOURCES logstream.cxx BufferedLogCallback.cxx
LogCallback.cxx LogEntry.cxx
ErrorReportingCallback.cxx
)
simgear_component(debug debug "${SOURCES}" "${HEADERS}")

View File

@@ -0,0 +1,47 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear_config.h>
#include "ErrorReportingCallback.hxx"
using std::string;
namespace simgear {
static ErrorReportCallback static_callback;
void setErrorReportCallback(ErrorReportCallback cb)
{
static_callback = cb;
}
void reportError(const std::string& msg, const std::string& more)
{
if (!static_callback)
return;
static_callback(msg, more, false);
}
void reportFatalError(const std::string& msg, const std::string& more)
{
if (!static_callback)
return;
static_callback(msg, more, true);
}
} // namespace simgear

View File

@@ -0,0 +1,31 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#pragma once
#include <functional>
#include <string>
namespace simgear {
void reportError(const std::string& msg, const std::string& more = {});
void reportFatalError(const std::string& msg, const std::string& more = {});
using ErrorReportCallback = std::function<void(const std::string& msg, const std::string& more, bool isFatal)>;
void setErrorReportCallback(ErrorReportCallback cb);
} // namespace simgear

View File

@@ -0,0 +1,116 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear_config.h>
#include "LogCallback.hxx"
using namespace simgear;
LogCallback::LogCallback(sgDebugClass c, sgDebugPriority p) : m_class(c),
m_priority(p)
{
}
void LogCallback::operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
{
// override me
}
bool LogCallback::doProcessEntry(const LogEntry& e)
{
return false;
}
void LogCallback::processEntry(const LogEntry& e)
{
if (doProcessEntry(e))
return; // derived class used the new API
// call the old API
(*this)(e.debugClass, e.debugPriority, e.file, e.line, e.message);
}
bool LogCallback::shouldLog(sgDebugClass c, sgDebugPriority p) const
{
if ((c & m_class) != 0 && p >= m_priority)
return true;
if (c == SG_OSG) // always have OSG logging as it OSG logging is configured separately.
return true;
return false;
}
void LogCallback::setLogLevels(sgDebugClass c, sgDebugPriority p)
{
m_priority = p;
m_class = c;
}
const char* LogCallback::debugPriorityToString(sgDebugPriority p)
{
switch (p) {
case SG_DEV_ALERT:
case SG_ALERT:
return "ALRT";
case SG_BULK: return "BULK";
case SG_DEBUG: return "DBUG";
case SG_MANDATORY_INFO:
case SG_INFO:
return "INFO";
case SG_POPUP: return "POPU";
case SG_DEV_WARN:
case SG_WARN:
return "WARN";
default: return "UNKN";
}
}
const char* LogCallback::debugClassToString(sgDebugClass c)
{
switch (c) {
case SG_NONE: return "none";
case SG_TERRAIN: return "terrain";
case SG_ASTRO: return "astro";
case SG_FLIGHT: return "flight";
case SG_INPUT: return "input";
case SG_GL: return "opengl";
case SG_VIEW: return "view";
case SG_COCKPIT: return "cockpit";
case SG_GENERAL: return "general";
case SG_MATH: return "math";
case SG_EVENT: return "event";
case SG_AIRCRAFT: return "aircraft";
case SG_AUTOPILOT: return "autopilot";
case SG_IO: return "io";
case SG_CLIPPER: return "clipper";
case SG_NETWORK: return "network";
case SG_ATC: return "atc";
case SG_NASAL: return "nasal";
case SG_INSTR: return "instruments";
case SG_SYSTEMS: return "systems";
case SG_AI: return "ai";
case SG_ENVIRONMENT: return "environment";
case SG_SOUND: return "sound";
case SG_NAVAID: return "navaid";
case SG_GUI: return "gui";
case SG_TERRASYNC: return "terrasync";
case SG_PARTICLES: return "particles";
case SG_HEADLESS: return "headless";
case SG_OSG: return "OSG";
default: return "unknown";
}
}

View File

@@ -0,0 +1,56 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#pragma once
#include <string>
#include "LogEntry.hxx"
#include "debug_types.h"
namespace simgear {
class LogCallback
{
public:
virtual ~LogCallback() = default;
// newer API: return true if you handled the message, otherwise
// the old API will be called
virtual bool doProcessEntry(const LogEntry& e);
// old API, kept for compatability
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage);
void setLogLevels(sgDebugClass c, sgDebugPriority p);
void processEntry(const LogEntry& e);
protected:
LogCallback(sgDebugClass c, sgDebugPriority p);
bool shouldLog(sgDebugClass c, sgDebugPriority p) const;
static const char* debugClassToString(sgDebugClass c);
static const char* debugPriorityToString(sgDebugPriority p);
private:
sgDebugClass m_class;
sgDebugPriority m_priority;
};
} // namespace simgear

View File

@@ -0,0 +1,45 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear_config.h>
#include "LogEntry.hxx"
#include <cstring> // for strdup
namespace simgear {
LogEntry::~LogEntry()
{
if (freeFilename) {
free(const_cast<char*>(file));
}
}
LogEntry::LogEntry(const LogEntry& c) : debugClass(c.debugClass),
debugPriority(c.debugPriority),
originalPriority(c.originalPriority),
file(c.file),
line(c.line),
message(c.message),
freeFilename(c.freeFilename)
{
if (c.freeFilename) {
file = strdup(c.file);
}
}
} // namespace simgear

View File

@@ -0,0 +1,54 @@
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#pragma once
#include <string>
#include "debug_types.h"
namespace simgear {
/**
* storage of a single log entry. This is used to pass log entries from
* the various threads to the logging thread, and also to store the startup
* entries
*/
class LogEntry
{
public:
LogEntry(sgDebugClass c, sgDebugPriority p,
sgDebugPriority op,
const char* f, int l, const std::string& msg) : debugClass(c), debugPriority(p), originalPriority(op),
file(f), line(l),
message(msg)
{
}
LogEntry(const LogEntry& c);
LogEntry& operator=(const LogEntry& c) = delete;
~LogEntry();
const sgDebugClass debugClass;
const sgDebugPriority debugPriority;
const sgDebugPriority originalPriority;
const char* file;
const int line;
const std::string message;
bool freeFilename = false; ///< if true, we own, and therefore need to free, the memory pointed to by 'file'
};
} // namespace simgear

View File

@@ -0,0 +1,53 @@
#include <cstring>
#include <osg/Notify>
#include <simgear/debug/logstream.hxx>
/**
* merge OSG output into our logging system, so it gets recorded to file,
* and so we can display a GUI console with renderer issues, especially
* shader compilation warnings and errors.
*/
class NotifyLogger : public osg::NotifyHandler
{
public:
// note this callback will be invoked by OSG from multiple threads.
// fortunately our Simgear logging implementation already handles
// that internally, so we simply pass the message on.
virtual void notify(osg::NotifySeverity severity, const char* message) {
// Detect whether a osg::Reference derived object is deleted with a non-zero
// reference count. In this case trigger a segfault to get a stack trace.
if (strstr(message, "the final reference count was")) {
// as this is going to segfault ignore the translation of severity and always output the message.
SG_LOG(SG_GL, SG_ALERT, message);
#ifndef DEBUG
throw new std::string(message);
//int* trigger_segfault = 0;
//*trigger_segfault = 0;
#endif
return;
}
char*tmessage = strdup(message);
char*lf = strrchr(tmessage, '\n');
if (lf)
*lf = 0;
SG_LOG(SG_OSG, translateSeverity(severity), tmessage);
free(tmessage);
}
private:
sgDebugPriority translateSeverity(osg::NotifySeverity severity) {
switch (severity) {
case osg::ALWAYS:
case osg::FATAL: return SG_ALERT;
case osg::WARN: return SG_WARN;
case osg::NOTICE:
case osg::INFO: return SG_INFO;
case osg::DEBUG_FP:
case osg::DEBUG_INFO: return SG_DEBUG;
default: return SG_ALERT;
}
}
};

View File

@@ -1,3 +1,5 @@
#pragma once
/** \file debug_types.h
* Define the various logging classes and priorities
*/
@@ -34,7 +36,11 @@ typedef enum {
SG_GUI = 0x00800000,
SG_TERRASYNC = 0x01000000,
SG_PARTICLES = 0x02000000,
SG_UNDEFD = 0x04000000, // For range checking
SG_HEADLESS = 0x04000000,
// SG_OSG (OSG notify) - will always be displayed regardless of FG log settings as OSG log level is configured
// separately and thus it makes more sense to allow these message through.
SG_OSG = 0x08000000,
SG_UNDEFD = 0x10000000, // For range checking
SG_ALL = 0xFFFFFFFF
} sgDebugClass;
@@ -48,16 +54,17 @@ typedef enum {
* appended, or the priority Nasal reports to compiled code will change.
*/
typedef enum {
SG_BULK = 1, // For frequent messages
SG_DEBUG, // Less frequent debug type messages
SG_INFO, // Informatory messages
SG_WARN, // Possible impending problem
SG_ALERT, // Very possible impending problem
SG_POPUP, // Severe enough to alert using a pop-up window
SG_BULK = 1, // For frequent messages
SG_DEBUG, // Less frequent debug type messages
SG_INFO, // Informatory messages
SG_WARN, // Possible impending problem
SG_ALERT, // Very possible impending problem
SG_POPUP, // Severe enough to alert using a pop-up window
// SG_EXIT, // Problem (no core)
// SG_ABORT // Abandon ship (core)
SG_DEV_WARN, // Warning for developers, translated to other priority
SG_DEV_ALERT // Alert for developers, translated
} sgDebugPriority;
SG_DEV_WARN, // Warning for developers, translated to other priority
SG_DEV_ALERT, // Alert for developers, translated
SG_MANDATORY_INFO // information, but should always be shown
} sgDebugPriority;

View File

@@ -24,20 +24,22 @@
#include "logstream.hxx"
#include <cstring>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <boost/foreach.hpp>
#include <mutex>
#include <simgear/sg_inlines.h>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGQueue.hxx>
#include <simgear/threads/SGGuard.hxx>
#include "LogCallback.hxx"
#include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/timing/timestamp.hxx>
#if defined (SG_WINDOWS)
// for AllocConsole, OutputDebugString
@@ -46,83 +48,55 @@
#include <io.h>
#endif
//////////////////////////////////////////////////////////////////////////////
namespace simgear
{
LogCallback::LogCallback(sgDebugClass c, sgDebugPriority p) :
m_class(c),
m_priority(p)
{
}
bool LogCallback::shouldLog(sgDebugClass c, sgDebugPriority p) const
{
return ((c & m_class) != 0 && p >= m_priority);
}
void LogCallback::setLogLevels( sgDebugClass c, sgDebugPriority p )
{
m_priority = p;
m_class = c;
}
const char* LogCallback::debugClassToString(sgDebugClass c)
{
switch (c) {
case SG_NONE: return "none";
case SG_TERRAIN: return "terrain";
case SG_ASTRO: return "astro";
case SG_FLIGHT: return "flight";
case SG_INPUT: return "input";
case SG_GL: return "opengl";
case SG_VIEW: return "view";
case SG_COCKPIT: return "cockpit";
case SG_GENERAL: return "general";
case SG_MATH: return "math";
case SG_EVENT: return "event";
case SG_AIRCRAFT: return "aircraft";
case SG_AUTOPILOT: return "autopilot";
case SG_IO: return "io";
case SG_CLIPPER: return "clipper";
case SG_NETWORK: return "network";
case SG_ATC: return "atc";
case SG_NASAL: return "nasal";
case SG_INSTR: return "instruments";
case SG_SYSTEMS: return "systems";
case SG_AI: return "ai";
case SG_ENVIRONMENT:return "environment";
case SG_SOUND: return "sound";
case SG_NAVAID: return "navaid";
case SG_GUI: return "gui";
case SG_TERRASYNC: return "terrasync";
case SG_PARTICLES: return "particles";
default: return "unknown";
}
}
} // of namespace simgear
//////////////////////////////////////////////////////////////////////////////
class FileLogCallback : public simgear::LogCallback
{
public:
SGTimeStamp logTimer;
FileLogCallback(const SGPath& aPath, sgDebugClass c, sgDebugPriority p) :
simgear::LogCallback(c, p)
{
m_file.open(aPath, std::ios_base::out | std::ios_base::trunc);
logTimer.stamp();
}
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& message)
void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& message) override
{
if (!shouldLog(c, p)) return;
m_file << debugClassToString(c) << ":" << (int) p
<< ":" << file << ":" << line << ":" << message << std::endl;
// fprintf(stderr, "%7.2f [%.8s]:%-10s %s\n", logTimer.elapsedMSec() / 1000.0, debugPriorityToString(p), debugClassToString(c), aMessage.c_str());
m_file
<< std::fixed
<< std::setprecision(2)
<< std::setw(8)
<< std::right
<< (logTimer.elapsedMSec() / 1000.0)
<< std::setw(8)
<< std::left
<< " ["+std::string(debugPriorityToString(p))+"]:"
<< std::setw(10)
<< std::left
<< debugClassToString(c)
;
if (file) {
/* <line> can be -ve to indicate that m_fileLine was false, but we
want to show file:line information regardless of m_fileLine. */
m_file
<< file
<< ":"
<< abs(line)
<< ": "
;
}
m_file
<< message << std::endl;
//m_file << debugClassToString(c) << ":" << (int)p
// << ":" << file << ":" << line << ":" << message << std::endl;
}
private:
sg_ofstream m_file;
@@ -131,9 +105,12 @@ private:
class StderrLogCallback : public simgear::LogCallback
{
public:
SGTimeStamp logTimer;
StderrLogCallback(sgDebugClass c, sgDebugPriority p) :
simgear::LogCallback(c, p)
{
logTimer.stamp();
}
#if defined (SG_WINDOWS)
@@ -143,12 +120,19 @@ public:
}
#endif
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage) override
{
if (!shouldLog(c, p)) return;
//fprintf(stderr, "%s\n", aMessage.c_str());
fprintf(stderr, "%s\n", aMessage.c_str());
if (file && line > 0) {
fprintf(stderr, "%8.2f %s:%i: [%.8s]:%-10s %s\n", logTimer.elapsedMSec()/1000.0, file, line, debugPriorityToString(p), debugClassToString(c), aMessage.c_str());
}
else {
fprintf(stderr, "%8.2f [%.8s]:%-10s %s\n", logTimer.elapsedMSec()/1000.0, debugPriorityToString(p), debugClassToString(c), aMessage.c_str());
}
// file, line, aMessage.c_str());
//fprintf(stderr, "%s:%d:%s:%d:%s\n", debugClassToString(c), p,
// file, line, aMessage.c_str());
fflush(stderr);
@@ -166,8 +150,8 @@ public:
{
}
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage) override
{
if (!shouldLog(c, p)) return;
@@ -182,28 +166,6 @@ public:
class logstream::LogStreamPrivate : public SGThread
{
private:
/**
* storage of a single log entry. This is used to pass log entries from
* the various threads to the logging thread, and also to store the startup
* entries
*/
class LogEntry
{
public:
LogEntry(sgDebugClass c, sgDebugPriority p,
const char* f, int l, const std::string& msg) :
debugClass(c), debugPriority(p), file(f), line(l),
message(msg)
{
}
const sgDebugClass debugClass;
const sgDebugPriority debugPriority;
const char* file;
const int line;
const std::string message;
};
/**
* RAII object to pause the logging thread if it's running, and restart it.
* used to safely make configuration changes.
@@ -242,10 +204,10 @@ public:
* window; stdout/stderr will not appear (except in logfiles as they do now)
* 4) When started from the Console (with --console) open a new console window
* 5) Ensure that IO redirection still works when started from the console
*
*
* Notes:
* 1) fgfs needs to be a GUI subsystem app - which it already is
* 2) What can't be done is to make the cmd prompt run fgfs synchronously;
* 2) What can't be done is to make the cmd prompt run fgfs synchronously;
* this is only something that can be done via "start /wait fgfs".
*/
@@ -269,7 +231,7 @@ public:
}
} else {
/*
* Attempt to attach to the console process of the parent process; when launched from cmd.exe this should be the console,
* Attempt to attach to the console process of the parent process; when launched from cmd.exe this should be the console,
* when launched via the RUN menu explorer, or another GUI app that wasn't started from the console this will fail.
* When it fails we will redirect to the NUL device. This is to ensure that we have valid streams.
* Later on in the initialisation sequence the --console option will be processed and this will cause the requestConsole() to
@@ -299,7 +261,7 @@ public:
if (!stdout_isNull){
if (!m_stdout_isRedirectedAlready)
freopen("conout$", "w", stdout);
else
else
/*
* for already redirected streams we need to attach the stream to the OS handle that is open.
* - this comes from part of the answer http://stackoverflow.com/a/13841522
@@ -318,7 +280,7 @@ public:
}
}
//http://stackoverflow.com/a/25927081
//Clear the error state for each of the C++ standard stream objects.
//Clear the error state for each of the C++ standard stream objects.
std::wcout.clear();
std::cout.clear();
std::wcerr.clear();
@@ -327,24 +289,34 @@ public:
m_callbacks.push_back(new StderrLogCallback(m_logClass, m_logPriority));
m_consoleCallbacks.push_back(m_callbacks.back());
#if defined (SG_WINDOWS) && !defined(NDEBUG)
m_callbacks.push_back(new WinDebugLogCallback(m_logClass, m_logPriority));
m_consoleCallbacks.push_back(m_callbacks.back());
#if defined (SG_WINDOWS)
const char* winDebugEnv = ::getenv("SG_WINDEBUG");
const bool b = winDebugEnv ? simgear::strutils::to_bool(std::string{winDebugEnv}) : false;
if (b) {
m_callbacks.push_back(new WinDebugLogCallback(m_logClass, m_logPriority));
m_consoleCallbacks.push_back(m_callbacks.back());
}
#endif
}
~LogStreamPrivate()
{
for (simgear::LogCallback* cb : m_callbacks) {
delete cb;
removeCallbacks();
// house-keeping, avoid leak warnings if we exit before disabling
// startup logging
{
std::lock_guard<std::mutex> g(m_lock);
clearStartupEntriesLocked();
}
}
SGMutex m_lock;
SGBlockingQueue<LogEntry> m_entries;
std::mutex m_lock;
SGBlockingQueue<simgear::LogEntry> m_entries;
// log entries posted during startup
std::vector<LogEntry> m_startupEntries;
std::vector<simgear::LogEntry> m_startupEntries;
bool m_startupLogging = false;
typedef std::vector<simgear::LogCallback*> CallbackVec;
@@ -362,10 +334,16 @@ public:
bool m_stdout_isRedirectedAlready = false;
#endif
bool m_developerMode = false;
bool m_fileLine = false;
// test suite mode.
bool m_testMode = false;
std::vector<std::string> _popupMessages;
void startLog()
{
SGGuard<SGMutex> g(m_lock);
std::lock_guard<std::mutex> g(m_lock);
if (m_isRunning) return;
m_isRunning = true;
start();
@@ -377,44 +355,54 @@ public:
return;
}
m_startupLogging = on;
{
std::lock_guard<std::mutex> g(m_lock);
m_startupLogging = on;
clearStartupEntriesLocked();
}
}
void clearStartupEntriesLocked()
{
m_startupEntries.clear();
}
virtual void run()
void run() override
{
while (1) {
LogEntry entry(m_entries.pop());
simgear::LogEntry entry(m_entries.pop());
// special marker entry detected, terminate the thread since we are
// making a configuration change or quitting the app
if ((entry.debugClass == SG_NONE) && !strcmp(entry.file, "done")) {
if ((entry.debugClass == SG_NONE) && entry.file && !strcmp(entry.file, "done")) {
return;
}
if (m_startupLogging) {
// save to the startup list for not-yet-added callbacks to
// pull down on startup
m_startupEntries.push_back(entry);
{
std::lock_guard<std::mutex> g(m_lock);
if (m_startupLogging) {
// save to the startup list for not-yet-added callbacks to
// pull down on startup
m_startupEntries.push_back(entry);
}
}
// submit to each installed callback in turn
for (simgear::LogCallback* cb : m_callbacks) {
(*cb)(entry.debugClass, entry.debugPriority,
entry.file, entry.line, entry.message);
cb->processEntry(entry);
}
} // of main thread loop
}
bool stop()
{
SGGuard<SGMutex> g(m_lock);
if (!m_isRunning) {
return false;
}
{
std::lock_guard<std::mutex> g(m_lock);
if (!m_isRunning) {
return false;
}
// log a special marker value, which will cause the thread to wakeup,
// and then exit
log(SG_NONE, SG_ALERT, "done", -1, "");
// log a special marker value, which will cause the thread to wakeup,
// and then exit
log(SG_NONE, SG_ALERT, "done", -1, "", false);
}
join();
m_isRunning = false;
@@ -428,9 +416,8 @@ public:
// we clear startup entries not using this, so always safe to run
// this code, container will simply be empty
for (auto entry : m_startupEntries) {
(*cb)(entry.debugClass, entry.debugPriority,
entry.file, entry.line, entry.message);
for (const auto& entry : m_startupEntries) {
cb->processEntry(entry);
}
}
@@ -443,28 +430,52 @@ public:
}
}
void removeCallbacks()
{
PauseThread pause(this);
for (simgear::LogCallback* cb : m_callbacks) {
delete cb;
}
m_callbacks.clear();
m_consoleCallbacks.clear();
}
void setLogLevels( sgDebugClass c, sgDebugPriority p )
{
PauseThread pause(this);
m_logPriority = p;
m_logClass = c;
BOOST_FOREACH(simgear::LogCallback* cb, m_consoleCallbacks) {
cb->setLogLevels(c, p);
}
for (auto cb : m_consoleCallbacks) {
cb->setLogLevels(c, p);
}
}
bool would_log( sgDebugClass c, sgDebugPriority p ) const
{
// Testing mode, so always log.
if (m_testMode) return true;
// SG_OSG (OSG notify) - will always be displayed regardless of FG log settings as OSG log level is configured
// separately and thus it makes more sense to allow these message through.
if (static_cast<unsigned>(p) == static_cast<unsigned>(SG_OSG)) return true;
p = translatePriority(p);
if (p >= SG_INFO) return true;
return ((c & m_logClass) != 0 && p >= m_logPriority);
}
void log( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg)
const char* fileName, int line, const std::string& msg,
bool freeFilename)
{
p = translatePriority(p);
LogEntry entry(c, p, fileName, line, msg);
auto tp = translatePriority(p);
if (!m_fileLine) {
/* This prevents output of file:line in StderrLogCallback. */
line = -line;
}
simgear::LogEntry entry(c, tp, p, fileName, line, msg);
entry.freeFilename = freeFilename;
m_entries.push(entry);
}
@@ -475,7 +486,7 @@ public:
}
if (in == SG_DEV_ALERT) {
return m_developerMode ? SG_POPUP : SG_WARN;
return m_developerMode ? SG_ALERT : SG_WARN;
}
return in;
@@ -485,7 +496,7 @@ public:
/////////////////////////////////////////////////////////////////////////////
static std::unique_ptr<logstream> global_logstream;
static SGMutex global_logStreamLock;
static std::mutex global_logStreamLock;
logstream::logstream()
{
@@ -495,8 +506,8 @@ logstream::logstream()
logstream::~logstream()
{
popup_msgs.clear();
d->stop();
d.reset();
}
void
@@ -510,6 +521,10 @@ void logstream::setDeveloperMode(bool devMode)
d->m_developerMode = devMode;
}
void logstream::setFileLine(bool fileLine)
{
d->m_fileLine = fileLine;
}
void
logstream::addCallback(simgear::LogCallback* cb)
@@ -527,7 +542,14 @@ void
logstream::log( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg)
{
d->log(c, p, fileName, line, msg);
d->log(c, p, fileName, line, msg, false);
}
void
logstream::logCopyingFilename( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg)
{
d->log(c, p, strdup(fileName), line, msg, true);
}
@@ -588,17 +610,18 @@ void logstream::hexdump(sgDebugClass c, sgDebugPriority p, const char* fileName,
void
logstream::popup( const std::string& msg)
{
popup_msgs.push_back(msg);
std::lock_guard<std::mutex> g(d->m_lock);
d->_popupMessages.push_back(msg);
}
std::string
logstream::get_popup()
{
std::string rv = "";
if (!popup_msgs.empty())
{
rv = popup_msgs.front();
popup_msgs.erase(popup_msgs.begin());
std::string rv;
std::lock_guard<std::mutex> g(d->m_lock);
if (!d->_popupMessages.empty()) {
rv = d->_popupMessages.front();
d->_popupMessages.erase(d->_popupMessages.begin());
}
return rv;
}
@@ -606,7 +629,8 @@ logstream::get_popup()
bool
logstream::has_popup()
{
return (popup_msgs.size() > 0) ? true : false;
std::lock_guard<std::mutex> g(d->m_lock);
return !d->_popupMessages.empty();
}
bool
@@ -639,6 +663,16 @@ logstream::set_log_classes( sgDebugClass c)
d->setLogLevels(c, d->m_logPriority);
}
sgDebugPriority logstream::priorityFromString(const std::string& s)
{
if (s == "bulk") return SG_BULK;
if (s == "debug") return SG_DEBUG;
if (s == "info") return SG_INFO;
if (s == "warn") return SG_WARN;
if (s == "alert") return SG_ALERT;
throw std::invalid_argument("Couldn't parse log prioirty:" + s);
}
logstream&
sglog()
@@ -649,7 +683,7 @@ sglog()
// http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
// in the absence of portable memory barrier ops in Simgear,
// let's keep this correct & safe
SGGuard<SGMutex> g(global_logStreamLock);
std::lock_guard<std::mutex> g(global_logStreamLock);
if( !global_logstream )
global_logstream.reset(new logstream);
@@ -711,19 +745,26 @@ void logstream::requestConsole()
#endif
}
void
logstream::setTestingMode( bool testMode )
{
d->m_testMode = testMode;
if (testMode) d->removeCallbacks();
}
namespace simgear
{
void requestConsole()
{
{
sglog().requestConsole();
}
void shutdownLogging()
{
SGGuard<SGMutex> g(global_logStreamLock);
std::lock_guard<std::mutex> g(global_logStreamLock);
global_logstream.reset();
}

View File

@@ -37,26 +37,8 @@ class SGPath;
namespace simgear
{
class LogCallback
{
public:
virtual ~LogCallback() {}
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage) = 0;
void setLogLevels(sgDebugClass c, sgDebugPriority p);
protected:
LogCallback(sgDebugClass c, sgDebugPriority p);
bool shouldLog(sgDebugClass c, sgDebugPriority p) const;
static const char* debugClassToString(sgDebugClass c);
private:
sgDebugClass m_class;
sgDebugPriority m_priority;
};
class LogCallback;
/**
* Helper force a console on platforms where it might optional, when
* we need to show a console. This basically means Windows at the
@@ -104,6 +86,11 @@ public:
sgDebugPriority get_log_priority() const;
/**
@brief convert a string value to a log prioirty.
throws std::invalid_argument if the string is not valid
*/
static sgDebugPriority priorityFromString(const std::string& s);
/**
* set developer mode on/off. In developer mode, SG_DEV_WARN messags
* are treated as warnings. In normal (non-developer) mode they are
@@ -111,12 +98,26 @@ public:
*/
void setDeveloperMode(bool devMode);
/**
* set output of file:line mode on/off. If on, all log messages are
* prefixed by the file:line of the caller of SG_LOG().
*/
void setFileLine(bool fileLine);
/**
* the core logging method
*/
void log( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg);
// overload of above, which can transfer ownership of the file-name.
// this is unecesary overhead when logging from C++, since __FILE__ points
// to constant data, but it's needed when the filename is Nasal data (for
// example) since during shutdown the filename is freed by Nasal GC
// asynchronously with the logging thread.
void logCopyingFilename( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg);
/**
* output formatted hex dump of memory block
*/
@@ -158,18 +159,26 @@ public:
void removeCallback(simgear::LogCallback* cb);
void removeCallbacks();
/**
* optionally record all entries and submit them to new log callbacks that
* are added. This allows simplified logging configuration, but still including
* early startup information in all logs.
*/
void setStartupLoggingEnabled(bool enabled);
/**
* Set up the logstream for running in test mode. For example the callbacks
* will be unregistered and the behaviour of the would_log() function
* sanitized.
*/
void setTestingMode(bool testMode);
private:
// constructor
logstream();
std::vector<std::string> popup_msgs;
class LogStreamPrivate;
std::unique_ptr<LogStreamPrivate> d;
@@ -193,9 +202,11 @@ logstream& sglog();
} } while(0)
#ifdef FG_NDEBUG
# define SG_LOG(C,P,M) do { if((P) == SG_POPUP) SG_LOGX(C,P,M) } while(0)
# define SG_LOG_NAN(C,P,M) SG_LOG(C,P,M)
# define SG_HEXDUMP(C,P,MEM,LEN)
#else
# define SG_LOG(C,P,M) SG_LOGX(C,P,M)
# define SG_LOG_NAN(C,P,M) do { SG_LOGX(C,P,M); throw std::overflow_error(M); } while(0)
# define SG_LOG_HEXDUMP(C,P,MEM,LEN) if(sglog().would_log(C,P)) sglog().hexdump(C, P, __FILE__, __LINE__, MEM, LEN)
#endif

View File

@@ -0,0 +1,33 @@
include (SimGearComponent)
set(HEADERS
Emesary.hxx
INotification.hxx
IReceiver.hxx
ITransmitter.hxx
ReceiptStatus.hxx
Transmitter.hxx
notifications.hxx
)
set(SOURCES
Emesary.cxx
)
simgear_component(emesary emesary "${SOURCES}" "${HEADERS}")
if(ENABLE_TESTS)
add_executable(test_emesary test_emesary.cxx)
set_target_properties(test_emesary PROPERTIES
COMPILE_DEFINITIONS "SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" )
target_link_libraries(test_emesary ${TEST_LIBS})
add_test(emesary ${EXECUTABLE_OUTPUT_PATH}/test_emesary)
endif(ENABLE_TESTS)

View File

@@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------
*
* Title : Emesary - class based inter-object communication
*
* File Type : Implementation File
*
* Description : Emesary main.
* : This only needs to instance the GlobalTransmitter as all of the
* : logic is in the header files (by design)
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002
*
* Version : $Header: $
*
* Copyright © 2002 Richard Harrison All Rights Reserved.
*
*---------------------------------------------------------------------------*/
#include "simgear/emesary/Emesary.hxx"
namespace simgear
{
namespace Emesary
{
}
}

View File

@@ -0,0 +1,48 @@
#ifndef EMESARY_hxx
#define EMESARY_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - class based inter-object communication
*
* File Type : Implementation File
*
* Description : Provides generic inter-object communication. For an object to receive a message it
* : must first register with a Transmitter, such as GlobalTransmitter, and implement the
* : IReceiver interface. That's it.
* : To send a message use a Transmitter with an object. That's all there is to it.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
#include <typeinfo>
#include "ReceiptStatus.hxx"
#include "INotification.hxx"
#include "IReceiver.hxx"
#include "ITransmitter.hxx"
#include "Transmitter.hxx"
#include <simgear/structure/Singleton.hxx>
namespace simgear
{
namespace Emesary
{
class GlobalTransmitter : public simgear::Singleton<Transmitter>
{
public:
GlobalTransmitter()
{
}
virtual ~GlobalTransmitter() {}
};
}
}
#endif

View File

@@ -0,0 +1,54 @@
#ifndef INOTIFICATION_hxx
#define INOTIFICATION_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - Notification base class
*
* File Type : Implementation File
*
* Description : Base class (interface) for all Notifications.
* : This is also compatible with the usual implementation of how we
* : implement queued notifications.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
namespace simgear
{
namespace Emesary
{
/// Interface (base class) for all notifications.
class INotification
{
public:
// text representation of notification type. must be unique across all notifications
virtual const char *GetType() = 0;
/// Used to control the sending of notifications. If this returns false then the Transmitter
/// should not send this notification.
virtual bool IsReadyToSend() { return true; }
/// Used to control the timeout. If this notification has timed out - then the processor is entitled
/// to true.
virtual bool IsTimedOut() { return false; }
/// when this notification has completed the processing recipient must set this to true.
/// the processing recipient is responsible for follow on notifications.
/// a notification can remain as complete until the transmit queue decides to remove it from the queue.
/// there is no requirement that elements are removed immediately upon completion merely that once complete
/// the transmitter should not notify any more elements.
/// The current notification loop may be completed - following the usual convention unless Completed or Abort
/// is returned as the status.
virtual bool IsComplete() { return true; }
};
}
}
#endif

View File

@@ -0,0 +1,47 @@
#ifndef IRECEIVER_hxx
#define IRECEIVER_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - Receiver base class
*
* File Type : Implementation File
*
* Description : Base class for all recipients.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
namespace simgear
{
namespace Emesary
{
/// Interface (base class) for a recipeint.
class IReceiver
{
public:
/// Receive notification - must be implemented
virtual ReceiptStatus Receive(INotification& message) = 0;
/// Called when registered at a transmitter
virtual void OnRegisteredAtTransmitter(class Transmitter *p)
{
}
/// Called when de-registered at a transmitter
virtual void OnDeRegisteredAtTransmitter(class Transmitter *p)
{
}
};
}
}
#endif

View File

@@ -0,0 +1,52 @@
#ifndef ITRANSMITTER_hxx
#define ITRANSMITTER_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - Transmitter base class
*
* File Type : Implementation File
*
* Description : Base class for all transmitters.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
namespace simgear
{
namespace Emesary
{
/// Interface (base clasee) for a transmitter.
/// Transmits Message derived objects. Each instance of this class provides a
/// event/databus to which any number of receivers can attach to.
class ITransmitter
{
public:
// Registers a recipient to receive message from this transmitter
virtual void Register(IReceiver& R) = 0;
// Removes a recipient from from this transmitter
virtual void DeRegister(IReceiver& R) = 0;
//Notify all registered recipients. Stop when receipt status of abort or finished are received.
//The receipt status from this method will be
// - OK > message handled
// - Fail > message not handled. A status of Abort from a recipient will result in our status
// being fail as Abort means that the message was not and cannot be handled, and
// allows for usages such as access controls.
virtual ReceiptStatus NotifyAll(INotification& M) = 0;
/// number of recipients
virtual int Count() = 0;
};
}
}
#endif

View File

@@ -0,0 +1,54 @@
#ifndef RECEIPTSTATUS_hxx
#define RECEIPTSTATUS_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - Transmitter base class
*
* File Type : Implementation File
*
* Description : Defines the receipt status that can be returned from
* : a receive method.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
namespace simgear
{
namespace Emesary
{
enum ReceiptStatus
{
/// Processing completed successfully
ReceiptStatusOK = 0,
/// Individual item failure
ReceiptStatusFail = 1,
/// Fatal error; stop processing any further recipieints of this message. Implicitly fail
ReceiptStatusAbort = 2,
/// Definitive completion - do not send message to any further recipieints
ReceiptStatusFinished = 3,
/// Return value when method doesn't process a message.
ReceiptStatusNotProcessed = 4,
/// Message has been sent but the return status cannot be determined as it has not been processed by the recipient.
/// e.g. a queue or outgoing bridge
ReceiptStatusPending = 5,
/// Message has been definitively handled but the return value cannot be determined. The message will not be sent any further
/// e.g. a point to point forwarding bridge
ReceiptStatusPendingFinished = 6,
};
}
}
#endif

View File

@@ -0,0 +1,189 @@
#ifndef TRANSMITTER_hxx
#define TRANSMITTER_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - Transmitter base class
*
* File Type : Implementation File
*
* Description : Defines the receipt status that can be returned from
* : a receive method.
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017, simgear version 2019
*
* Version : $Header: $
*
* Copyright (C)2019 Richard Harrison Licenced under GPL2 or later.
*
*---------------------------------------------------------------------------*/
#include <algorithm>
#include <string>
#include <list>
#include <set>
#include <vector>
#include <atomic>
#include <mutex>
namespace simgear
{
namespace Emesary
{
// Implementation of a ITransmitter
class Transmitter : public ITransmitter
{
protected:
typedef std::list<IReceiver *> RecipientList;
RecipientList recipient_list;
RecipientList deleted_recipients;
int CurrentRecipientIndex = 0;
std::mutex _lock;
std::atomic<int> receiveDepth;
std::atomic<int> sentMessageCount;
public:
Transmitter() : receiveDepth(0), sentMessageCount(0)
{
}
virtual ~Transmitter()
{
}
// Registers an object to receive messsages from this transmitter.
// This object is added to the top of the list of objects to be notified. This is deliberate as
// the sequence of registration and message receipt can influence the way messages are processing
// when ReceiptStatus of Abort or Finished are encountered. So it was a deliberate decision that the
// most recently registered recipients should process the messages/events first.
virtual void Register(IReceiver& r)
{
std::lock_guard<std::mutex> scopeLock(_lock);
recipient_list.push_back(&r);
r.OnRegisteredAtTransmitter(this);
if (std::find(deleted_recipients.begin(), deleted_recipients.end(), &r) != deleted_recipients.end())
deleted_recipients.remove(&r);
}
// Removes an object from receving message from this transmitter
virtual void DeRegister(IReceiver& R)
{
std::lock_guard<std::mutex> scopeLock(_lock);
if (recipient_list.size())
{
if (std::find(recipient_list.begin(), recipient_list.end(), &R) != recipient_list.end())
{
recipient_list.remove(&R);
R.OnDeRegisteredAtTransmitter(this);
if (std::find(deleted_recipients.begin(), deleted_recipients.end(), &R) == deleted_recipients.end())
deleted_recipients.push_back(&R);
}
}
}
// Notify all registered recipients. Stop when receipt status of abort or finished are received.
// The receipt status from this method will be
// - OK > message handled
// - Fail > message not handled. A status of Abort from a recipient will result in our status
// being fail as Abort means that the message was not and cannot be handled, and
// allows for usages such as access controls.
virtual ReceiptStatus NotifyAll(INotification& M)
{
ReceiptStatus return_status = ReceiptStatusNotProcessed;
sentMessageCount++;
std::vector<IReceiver*> temp;
{
std::lock_guard<std::mutex> scopeLock(_lock);
if (receiveDepth == 0)
deleted_recipients.clear();
receiveDepth++;
int idx = 0;
for (RecipientList::iterator i = recipient_list.begin(); i != recipient_list.end(); i++)
{
temp.push_back(*i);
}
}
int tempSize = temp.size();
for (int index = 0; index < tempSize; index++)
{
IReceiver* R = temp[index];
{
std::lock_guard<std::mutex> scopeLock(_lock);
if (deleted_recipients.size())
{
if (std::find(deleted_recipients.begin(), deleted_recipients.end(), R) != deleted_recipients.end())
{
continue;
}
}
}
if (R)
{
ReceiptStatus rstat = R->Receive(M);
switch (rstat)
{
case ReceiptStatusFail:
return_status = ReceiptStatusFail;
break;
case ReceiptStatusPending:
return_status = ReceiptStatusPending;
break;
case ReceiptStatusPendingFinished:
return rstat;
case ReceiptStatusNotProcessed:
break;
case ReceiptStatusOK:
if (return_status == ReceiptStatusNotProcessed)
return_status = rstat;
break;
case ReceiptStatusAbort:
return ReceiptStatusAbort;
case ReceiptStatusFinished:
return ReceiptStatusOK;
}
}
}
receiveDepth--;
return return_status;
}
// number of currently registered recipients
virtual int Count()
{
std::lock_guard<std::mutex> scopeLock(_lock);
return recipient_list.size();
}
// number of sent messages.
int SentMessageCount()
{
return sentMessageCount;
}
// ascertain if a receipt status can be interpreted as failure.
static bool Failed(ReceiptStatus receiptStatus)
{
//
// failed is either Fail or Abort.
// NotProcessed isn't a failure because it hasn't been processed.
return receiptStatus == ReceiptStatusFail
|| receiptStatus == ReceiptStatusAbort;
}
};
}
}
#endif

View File

@@ -0,0 +1,68 @@
#ifndef NOTIFICATIONS_hxx
#define NOTIFICATIONS_hxx
/*---------------------------------------------------------------------------
*
* Title : Emesary - class based inter-object communication
*
* File Type : Implementation File
*
* Description : simgear notifications
*
* References : http://www.chateau-logic.com/content/class-based-inter-object-communication
*
* Author : Richard Harrison (richard@zaretto.com)
*
* Creation Date : 18 March 2002, rewrite 2017
*
* Version : $Header: $
*
* Copyright <20> 2002 - 2017 Richard Harrison All Rights Reserved.
*
*---------------------------------------------------------------------------*/
#include "INotification.hxx"
namespace simgear
{
namespace Notifications
{
class MainLoopNotification : public simgear::Emesary::INotification
{
public:
enum Type { Started, Stopped, Begin, End };
MainLoopNotification(Type v) : _type(v) {}
virtual Type GetValue() { return _type; }
virtual const char *GetType() { return "MainLoop"; }
protected:
Type _type;
};
class NasalGarbageCollectionConfigurationNotification : public simgear::Emesary::INotification
{
public:
NasalGarbageCollectionConfigurationNotification(bool canWait, bool active) : CanWait(canWait), Active(active) {}
virtual bool GetCanWait() { return CanWait; }
virtual bool GetActive() { return Active; }
virtual const char *GetType() { return "NasalGarbageCollectionConfiguration"; }
virtual bool SetWait(bool wait) {
if (wait == CanWait)
return false;
CanWait = wait;
return true;
}
virtual bool SetActive(bool active) {
if (active == Active)
return false;
Active = active;
return true;
}
public:
bool CanWait;
bool Active;
};
}
}
#endif

View File

@@ -0,0 +1,130 @@
////////////////////////////////////////////////////////////////////////
// Test harness for Emesary.
////////////////////////////////////////////////////////////////////////
#include <simgear_config.h>
#include <simgear/compiler.h>
#include <iostream>
#include <simgear/threads/SGThread.hxx>
#include <simgear/emesary/Emesary.hxx>
using std::cout;
using std::cerr;
using std::endl;
std::atomic<int> nthread {0};
std::atomic<int> noperations {0};
const int MaxIterations = 9999;
class TestThreadNotification : public simgear::Emesary::INotification
{
protected:
const char *baseValue;
public:
TestThreadNotification(const char *v) : baseValue(v) {}
virtual const char* GetType () { return baseValue; }
};
class TestThreadRecipient : public simgear::Emesary::IReceiver
{
public:
TestThreadRecipient() : receiveCount(0)
{
}
std::atomic<int> receiveCount;
virtual simgear::Emesary::ReceiptStatus Receive(simgear::Emesary::INotification &n)
{
if (n.GetType() == (const char*)this)
{
// Unused: TestThreadNotification *tn = dynamic_cast<TestThreadNotification *>(&n);
receiveCount++;
TestThreadNotification onwardNotification("AL");
simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(onwardNotification);
return simgear::Emesary::ReceiptStatusOK;
}
return simgear::Emesary::ReceiptStatusOK;
}
};
class EmesaryTestThread : public SGThread
{
protected:
virtual void run() {
int threadId = nthread.fetch_add(1);
//System.Threading.Interlocked.Increment(ref nthread);
//var rng = new Random();
TestThreadRecipient r;
char temp[100];
sprintf(temp, "Notif %d", threadId);
printf("starting thread %s\n", temp);
TestThreadNotification tn((const char*)&r);
for (int i = 0; i < MaxIterations; i++)
{
simgear::Emesary::GlobalTransmitter::instance()->Register(r);
simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(tn);
simgear::Emesary::GlobalTransmitter::instance()->DeRegister(r);
//System.Threading.Thread.Sleep(rng.Next(MaxSleep));
noperations++;
}
printf("%s invocations %d\n", temp, (int)r.receiveCount);
printf("finish thread %s\n", temp);
}
};
class EmesaryTest
{
public:
void Emesary_MultiThreadTransmitterTest()
{
int num_threads = 12;
std::list<EmesaryTestThread*> threads;
for (int i = 0; i < num_threads; i++)
{
EmesaryTestThread *thread = new EmesaryTestThread();
threads.push_back(thread);
thread->start();
}
for (std::list<EmesaryTestThread*>::iterator i = threads.begin(); i != threads.end(); i++)
{
(*i)->join();
}
}
};
void testEmesaryThreaded()
{
TestThreadRecipient r;
TestThreadNotification tn((const char*)&r);
simgear::Emesary::GlobalTransmitter::instance()->Register(r);
for (int i = 0; i < MaxIterations*MaxIterations; i++)
{
simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(tn);
//System.Threading.Thread.Sleep(rng.Next(MaxSleep));
noperations++;
}
simgear::Emesary::GlobalTransmitter::instance()->DeRegister(r);
printf("invocations %d\n", simgear::Emesary::GlobalTransmitter::instance()->SentMessageCount());
EmesaryTest t;
t.Emesary_MultiThreadTransmitterTest();
}
int main(int ac, char ** av)
{
testEmesaryThreaded();
std::cout << "all tests passed" << std::endl;
return 0;
}

View File

@@ -38,11 +38,15 @@
# include <simgear_config.h>
#endif
#include <iomanip>
#include <string>
#include <time.h>
#include <cstring>
#include <ostream>
#include <sstream>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_random.h>
#include <simgear/structure/exception.hxx>
#include "metar.hxx"
@@ -155,6 +159,320 @@ SGMetar::~SGMetar()
}
static const char *azimuthName(double d)
{
const char *dir[] = {
"N", "NNE", "NE", "ENE",
"E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW",
"W", "WNW", "NW", "NNW"
};
d += 11.25;
while (d < 0)
d += 360;
while (d >= 360)
d -= 360;
return dir[int(d / 22.5)];
}
// round double to 10^g
static double rnd(double r, int g = 0)
{
double f = pow(10.0, g);
return f * floor(r / f + 0.5);
}
/* A manipulator that can use spaces to emulate tab characters. */
struct Tab
{
/* If <stops> is 0, we simply insert tab characters. Otherwise we insert
spaces to align with the next column at multiple of <stops>. */
explicit Tab(int stops)
:
_stops(stops)
{}
int _stops;
};
std::ostream& operator << (std::ostream& out, const Tab& t)
{
if (t._stops == 0) {
return out << '\t';
}
std::ostringstream& out2 = *(std::ostringstream*) &out;
std::string s = out2.str();
if (t._stops < 0) {
if (!s.size() || s[s.size()-1] != ' ') {
out << ' ';
}
return out;
}
auto nl = s.rfind('\n');
if (nl < 0) nl = 0;
int column = 0;
for (auto i = nl+1; i != s.size(); ++i) {
if (s[i] == '\t')
column = (column + t._stops) / t._stops * t._stops;
else
column += 1;
}
int column2 = (column + t._stops) / t._stops * t._stops;
for (int i=column; i<column2; ++i) {
out << ' ';
}
return out;
}
/* Manipulator for SGMetarVisibility using a Tab. */
struct SGMetarVisibilityManip
{
explicit SGMetarVisibilityManip(const SGMetarVisibility& v, const Tab& tab)
:
_v(v),
_tab(tab)
{}
const SGMetarVisibility& _v;
const Tab& _tab;
};
std::ostream& operator << (std::ostream& out, const SGMetarVisibilityManip& v)
{
int m = v._v.getModifier();
const char *mod;
if (m == SGMetarVisibility::GREATER_THAN)
mod = ">=";
else if (m == SGMetarVisibility::LESS_THAN)
mod = "<";
else
mod = "";
out << mod;
double dist = rnd(v._v.getVisibility_m(), 1);
if (dist < 1000.0)
out << rnd(dist, 1) << " m";
else
out << rnd(dist / 1000.0, -1) << " km";
const char *dir = "";
int i;
if ((i = v._v.getDirection()) != -1) {
dir = azimuthName(i);
out << " " << dir;
}
out << v._tab << v._tab << v._tab << v._tab << v._tab;
out << mod << rnd(v._v.getVisibility_sm(), -1) << " US-miles " << dir;
return out;
}
std::string SGMetar::getDescription(int tabstops) const
{
std::ostringstream out;
const char *s;
char buf[256];
double d;
int i, lineno;
Tab tab(tabstops);
if ((i = getReportType()) == SGMetar::AUTO)
out << "(METAR automatically generated)\n";
else if (i == SGMetar::COR)
out << "(METAR manually corrected)\n";
else if (i == SGMetar::RTD)
out << "(METAR routine delayed)\n";
out << "Airport-Id:" << tab << tab << getId() << "\n";
// date/time
int year = getYear();
int month = getMonth();
out << "Report time:" << tab << tab << year << '/' << month << '/' << getDay();
out << ' ' << getHour() << ':';
out << std::setw(2) << std::setfill('0') << getMinute() << " UTC\n";
// visibility
SGMetarVisibility minvis = getMinVisibility();
SGMetarVisibility maxvis = getMaxVisibility();
double min = minvis.getVisibility_m();
double max = maxvis.getVisibility_m();
if (min != NaN) {
if (max != NaN) {
out << "min. Visibility:" << tab << SGMetarVisibilityManip(minvis, tab) << "\n";
out << "max. Visibility:" << tab << SGMetarVisibilityManip(maxvis, tab) << "\n";
} else {
out << "Visibility:" << tab << tab << SGMetarVisibilityManip(minvis, tab) << "\n";
}
}
// directed visibility
const SGMetarVisibility *dirvis = getDirVisibility();
for (i = 0; i < 8; i++, dirvis++)
if (dirvis->getVisibility_m() != NaN)
out << tab << tab << tab << SGMetarVisibilityManip(*dirvis, tab) << "\n";
// vertical visibility
SGMetarVisibility vertvis = getVertVisibility();
if ((d = vertvis.getVisibility_ft()) != NaN)
out << "Vert. visibility:" << tab << SGMetarVisibilityManip(vertvis, tab) << "\n";
else if (vertvis.getModifier() == SGMetarVisibility::NOGO)
out << "Vert. visibility:" << tab << "impossible to determine" << "\n";
// wind
d = getWindSpeed_kmh();
out << "Wind:" << tab << tab << tab;
if (d < .1)
out << "none" << "\n";
else {
if ((i = getWindDir()) == -1)
out << "from variable directions";
else
out << "from the " << azimuthName(i) << " (" << i << " deg)";
out << " at " << rnd(d, -1) << " km/h";
out << tab << tab << rnd(getWindSpeed_kt(), -1) << " kt";
out << " = " << rnd(getWindSpeed_mph(), -1) << " mph";
out << " = " << rnd(getWindSpeed_mps(), -1) << " m/s";
out << "\n";
d = getGustSpeed_kmh();
if (d != NaN && d != 0) {
out << tab << tab << tab << "with gusts at " << rnd(d, -1) << " km/h";
out << tab << tab << tab << rnd(getGustSpeed_kt(), -1) << " kt";
out << " = " << rnd(getGustSpeed_mph(), -1) << " mph";
out << " = " << rnd(getGustSpeed_mps(), -1) << " m/s";
out << "\n";
}
int from = getWindRangeFrom();
int to = getWindRangeTo();
if (from != to) {
out << tab << tab << tab << "variable from " << azimuthName(from);
out << " to " << azimuthName(to);
out << " (" << from << "deg --" << to << " deg)" << "\n";
}
}
// temperature/humidity/air pressure
if ((d = getTemperature_C()) != NaN) {
out << "Temperature:" << tab << tab << d << " C" << tab << tab << tab << tab << tab;
out << rnd(getTemperature_F(), -1) << " F" << "\n";
if ((d = getDewpoint_C()) != NaN) {
out << "Dewpoint:" << tab << tab << d << " C" << tab << tab << tab << tab << tab;
out << rnd(getDewpoint_F(), -1) << " F" << "\n";
out << "Rel. Humidity: " << tab << tab << rnd(getRelHumidity()) << " %" << "\n";
}
}
if ((d = getPressure_hPa()) != NaN) {
out << "Pressure:" << tab << tab << rnd(d) << " hPa" << tab << tab << tab << tab;
out << rnd(getPressure_inHg(), -2) << " in. Hg" << "\n";
}
// weather phenomena
vector<string> wv = getWeather();
vector<string>::iterator weather;
for (i = 0, weather = wv.begin(); weather != wv.end(); weather++, i++) {
out << (i ? ", " : "Weather:") << tab << tab << weather->c_str();
}
if (i)
out << "\n";
// cloud layers
const char *coverage_string[5] = {
"clear skies", "few clouds", "scattered clouds", "broken clouds", "sky overcast"
};
vector<SGMetarCloud> cv = getClouds();
vector<SGMetarCloud>::iterator cloud;
for (lineno = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, lineno++) {
if (lineno) out << tab << tab << tab;
else out << "Sky condition:" << tab << tab;
if ((i = cloud->getCoverage()) != -1)
out << coverage_string[i];
if ((d = cloud->getAltitude_ft()) != NaN)
out << " at " << rnd(d, 1) << " ft";
if ((s = cloud->getTypeLongString()))
out << " (" << s << ')';
if (d != NaN)
out << tab << tab << tab << rnd(cloud->getAltitude_m(), 1) << " m";
out << "\n";
}
// runways
map<string, SGMetarRunway> rm = getRunways();
map<string, SGMetarRunway>::iterator runway;
for (runway = rm.begin(); runway != rm.end(); runway++) {
lineno = 0;
if (!strcmp(runway->first.c_str(), "ALL"))
out << "All runways:" << tab << tab;
else
out << "Runway " << runway->first << ":" << tab << tab;
SGMetarRunway rwy = runway->second;
// assemble surface string
vector<string> surface;
if ((s = rwy.getDepositString()) && strlen(s))
surface.push_back(s);
if ((s = rwy.getExtentString()) && strlen(s))
surface.push_back(s);
if ((d = rwy.getDepth()) != NaN) {
sprintf(buf, "%.1lf mm", d * 1000.0);
surface.push_back(buf);
}
if ((s = rwy.getFrictionString()) && strlen(s))
surface.push_back(s);
if ((d = rwy.getFriction()) != NaN) {
sprintf(buf, "friction: %.2lf", d);
surface.push_back(buf);
}
if (! surface.empty()) {
vector<string>::iterator rwysurf = surface.begin();
for (i = 0; rwysurf != surface.end(); rwysurf++, i++) {
if (i)
out << ", ";
out << *rwysurf;
}
lineno++;
}
// assemble visibility string
SGMetarVisibility minvis = rwy.getMinVisibility();
SGMetarVisibility maxvis = rwy.getMaxVisibility();
if ((d = minvis.getVisibility_m()) != NaN) {
if (lineno++)
out << "\n" << tab << tab << tab;
out << SGMetarVisibilityManip(minvis, tab);
}
if (maxvis.getVisibility_m() != d) {
out << "\n" << tab << tab << tab << SGMetarVisibilityManip(maxvis, tab) << "\n";
lineno++;
}
if (rwy.getWindShear()) {
if (lineno++)
out << "\n" << tab << tab << tab;
out << "critical wind shear" << "\n";
}
out << "\n";
}
out << "\n";
return out.str();
}
void SGMetar::useCurrentDate()
{
struct tm now;
@@ -314,30 +632,41 @@ bool SGMetar::scanWind()
int dir;
if (!strncmp(m, "VRB", 3))
m += 3, dir = -1;
else if (!strncmp(m, "///", 3)) // direction not measurable
m += 3, dir = -1;
else if (!scanNumber(&m, &dir, 3))
return false;
int i;
if (!scanNumber(&m, &i, 2, 3))
if (!strncmp(m, "//", 2)) // speed not measurable
m += 2, i = -1;
else if (!scanNumber(&m, &i, 2, 3))
return false;
double speed = i;
double gust = NaN;
if (*m == 'G') {
m++;
if (!scanNumber(&m, &i, 2, 3))
if (!strncmp(m, "//", 2)) // speed not measurable
m += 2, i = -1;
else if (!scanNumber(&m, &i, 2, 3))
return false;
gust = i;
if (i != -1)
gust = i;
}
double factor;
if (!strncmp(m, "KT", 2))
m += 2, factor = SG_KT_TO_MPS;
else if (!strncmp(m, "KMH", 3))
else if (!strncmp(m, "KMH", 3)) // invalid Km/h
m += 3, factor = SG_KMH_TO_MPS;
else if (!strncmp(m, "KPH", 3)) // ??
else if (!strncmp(m, "KPH", 3)) // invalid Km/h
m += 3, factor = SG_KMH_TO_MPS;
else if (!strncmp(m, "MPS", 3))
m += 3, factor = 1.0;
else if (!strncmp(m, " ", 1)) // default to Knots
factor = SG_KT_TO_MPS;
else
return false;
if (!scanBoundary(&m))
@@ -357,18 +686,28 @@ bool SGMetar::scanVariability()
{
char *m = _m;
int from, to;
if (!scanNumber(&m, &from, 3))
if (!strncmp(m, "///", 3)) // direction not measurable
m += 3, from = -1;
else if (!scanNumber(&m, &from, 3))
return false;
if (*m++ != 'V')
return false;
if (!scanNumber(&m, &to, 3))
if (!strncmp(m, "///", 3)) // direction not measurable
m += 3, to = -1;
else if (!scanNumber(&m, &to, 3))
return false;
if (!scanBoundary(&m))
return false;
_m = m;
_wind_range_from = from;
_wind_range_to = to;
_grpcount++;
return true;
}
@@ -635,6 +974,8 @@ bool SGMetar::scanWeather()
weather += string(a->text) + " ";
if (!strcmp(a->id, "RA"))
_rain = w.intensity;
else if (!strcmp(a->id, "DZ"))
_rain = LIGHT;
else if (!strcmp(a->id, "HA"))
_hail = w.intensity;
else if (!strcmp(a->id, "SN"))
@@ -728,9 +1069,12 @@ bool SGMetar::scanSkyCondition()
return false;
m += i;
if (!strncmp(m, "///", 3)) // vis not measurable (e.g. because of heavy snowing)
if (!strncmp(m, "///", 3)) { // vis not measurable (e.g. because of heavy snowing)
m += 3, i = -1;
else if (scanBoundary(&m)) {
sg_srandom_time();
// randomize the base height to avoid the black sky issue
i = 50 + static_cast<int>(sg_random() * 250.0); // range [5,000, 30,000]
} else if (scanBoundary(&m)) {
_m = m;
return true; // ignore single OVC/BKN/...
} else if (!scanNumber(&m, &i, 3))

View File

@@ -235,6 +235,11 @@ public:
inline const std::vector<std::string>& getWeather() const { return _weather; }
inline const std::vector<struct Weather> getWeather2() const { return _weather2; }
/* Returns human-readable description. If tabtops is 0, we use tab
characters. If +ve we use spaces to pad to multiple of <tabstops>. If
-1 all sequences of tabs are represented by a single space. */
std::string getDescription(int tabstops) const;
protected:
std::string _url;
int _grpcount;

Some files were not shown because too many files have changed in this diff Show More