1
0
Fork 0

VSCode applied formatting.

This commit is contained in:
James Turner 2022-05-16 12:15:05 +01:00
parent 15cb5ab075
commit 3f670c84b1

View file

@ -25,41 +25,41 @@
#include <config.h> #include <config.h>
#include <algorithm> #include <algorithm>
#include <cstdlib>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <cstdlib>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/exception.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/debug/OsgIoCapture.hxx> #include <simgear/debug/OsgIoCapture.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/structure/exception.hxx>
#include <osg/Camera> #include <osg/Camera>
#include <osg/GraphicsContext> #include <osg/GraphicsContext>
#include <osg/Group> #include <osg/Group>
#include <osg/Matrixd> #include <osg/Matrixd>
#include <osg/Viewport>
#include <osg/Version>
#include <osg/Notify> #include <osg/Notify>
#include <osg/Version>
#include <osg/View> #include <osg/View>
#include <osgViewer/ViewerEventHandlers> #include <osg/Viewport>
#include <osgViewer/Viewer>
#include <osgViewer/GraphicsWindow> #include <osgViewer/GraphicsWindow>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <Scenery/scenery.hxx>
#include <Main/fg_os.hxx>
#include <Main/fg_props.hxx>
#include <Main/util.hxx>
#include <Main/globals.hxx>
#include "renderer.hxx"
#include "CameraGroup.hxx" #include "CameraGroup.hxx"
#include "FGEventHandler.hxx" #include "FGEventHandler.hxx"
#include "VRManager.hxx" #include "VRManager.hxx"
#include "WindowBuilder.hxx" #include "WindowBuilder.hxx"
#include "WindowSystemAdapter.hxx" #include "WindowSystemAdapter.hxx"
#include "renderer.hxx"
#include <Main/fg_os.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Main/sentryIntegration.hxx> #include <Main/sentryIntegration.hxx>
#include <Main/util.hxx>
#include <Scenery/scenery.hxx>
#if defined(SG_MAC) #if defined(SG_MAC)
#include <GUI/CocoaHelpers.h> #include <GUI/CocoaHelpers.h>
@ -116,40 +116,23 @@ static void setStereoMode( const char * mode )
DisplaySettings::StereoMode stereoMode = DisplaySettings::QUAD_BUFFER; DisplaySettings::StereoMode stereoMode = DisplaySettings::QUAD_BUFFER;
bool stereoOn = true; bool stereoOn = true;
if (strcmp(mode,"QUAD_BUFFER")==0) if (strcmp(mode, "QUAD_BUFFER") == 0) {
{
stereoMode = DisplaySettings::QUAD_BUFFER; stereoMode = DisplaySettings::QUAD_BUFFER;
} } else if (strcmp(mode, "ANAGLYPHIC") == 0) {
else if (strcmp(mode,"ANAGLYPHIC")==0)
{
stereoMode = DisplaySettings::ANAGLYPHIC; stereoMode = DisplaySettings::ANAGLYPHIC;
} } else if (strcmp(mode, "HORIZONTAL_SPLIT") == 0) {
else if (strcmp(mode,"HORIZONTAL_SPLIT")==0)
{
stereoMode = DisplaySettings::HORIZONTAL_SPLIT; stereoMode = DisplaySettings::HORIZONTAL_SPLIT;
} } else if (strcmp(mode, "VERTICAL_SPLIT") == 0) {
else if (strcmp(mode,"VERTICAL_SPLIT")==0)
{
stereoMode = DisplaySettings::VERTICAL_SPLIT; stereoMode = DisplaySettings::VERTICAL_SPLIT;
} } else if (strcmp(mode, "LEFT_EYE") == 0) {
else if (strcmp(mode,"LEFT_EYE")==0)
{
stereoMode = DisplaySettings::LEFT_EYE; stereoMode = DisplaySettings::LEFT_EYE;
} } else if (strcmp(mode, "RIGHT_EYE") == 0) {
else if (strcmp(mode,"RIGHT_EYE")==0)
{
stereoMode = DisplaySettings::RIGHT_EYE; stereoMode = DisplaySettings::RIGHT_EYE;
} } else if (strcmp(mode, "HORIZONTAL_INTERLACE") == 0) {
else if (strcmp(mode,"HORIZONTAL_INTERLACE")==0)
{
stereoMode = DisplaySettings::HORIZONTAL_INTERLACE; stereoMode = DisplaySettings::HORIZONTAL_INTERLACE;
} } else if (strcmp(mode, "VERTICAL_INTERLACE") == 0) {
else if (strcmp(mode,"VERTICAL_INTERLACE")==0)
{
stereoMode = DisplaySettings::VERTICAL_INTERLACE; stereoMode = DisplaySettings::VERTICAL_INTERLACE;
} } else if (strcmp(mode, "CHECKERBOARD") == 0) {
else if (strcmp(mode,"CHECKERBOARD")==0)
{
stereoMode = DisplaySettings::CHECKERBOARD; stereoMode = DisplaySettings::CHECKERBOARD;
} else { } else {
stereoOn = false; stereoOn = false;
@ -218,10 +201,9 @@ void fgOSOpenWindow(bool stencil)
osg::setNotifyHandler(new NotifyLogger); osg::setNotifyHandler(new NotifyLogger);
auto composite_viewer = dynamic_cast<osgViewer::CompositeViewer*>( auto composite_viewer = dynamic_cast<osgViewer::CompositeViewer*>(
globals->get_renderer()->getViewerBase() globals->get_renderer()->getViewerBase());
); if (0) {
if (0) {} } else if (composite_viewer) {
else if (composite_viewer) {
/* We are using CompositeViewer. */ /* We are using CompositeViewer. */
SG_LOG(SG_VIEW, SG_DEBUG, "Using CompositeViewer"); SG_LOG(SG_VIEW, SG_DEBUG, "Using CompositeViewer");
osgViewer::ViewerBase* viewer = globals->get_renderer()->getViewerBase(); osgViewer::ViewerBase* viewer = globals->get_renderer()->getViewerBase();
@ -267,8 +249,7 @@ void fgOSOpenWindow(bool stencil)
// The viewer won't start without some root. // The viewer won't start without some root.
view->setSceneData(new osg::Group); view->setSceneData(new osg::Group);
globals->get_renderer()->setView(view); globals->get_renderer()->setView(view);
} } else {
else {
/* Not using CompositeViewer. */ /* Not using CompositeViewer. */
SG_LOG(SG_VIEW, SG_DEBUG, "Not CompositeViewer."); SG_LOG(SG_VIEW, SG_DEBUG, "Not CompositeViewer.");
SG_LOG(SG_VIEW, SG_DEBUG, "Creating osgViewer::Viewer"); SG_LOG(SG_VIEW, SG_DEBUG, "Creating osgViewer::Viewer");
@ -377,8 +358,7 @@ static std::ostream& operator<< (std::ostream& out, const cpu_set_t& mask)
{ {
out << "0x"; out << "0x";
unsigned char* mask2 = (unsigned char*)&mask; unsigned char* mask2 = (unsigned char*)&mask;
for (unsigned i=0; i<sizeof(mask); ++i) for (unsigned i = 0; i < sizeof(mask); ++i) {
{
char buffer[8]; char buffer[8];
snprintf(buffer, sizeof(buffer), "%02x", (unsigned)mask2[i]); snprintf(buffer, sizeof(buffer), "%02x", (unsigned)mask2[i]);
out << buffer; out << buffer;
@ -396,8 +376,7 @@ value='clear' and 'revert':
'revert' 'revert'
Restores thread affinities stored from previous 'clear'. Restores thread affinities stored from previous 'clear'.
*/ */
struct AffinityControl : SGPropertyChangeListener struct AffinityControl : SGPropertyChangeListener {
{
AffinityControl() AffinityControl()
{ {
m_node = globals->get_props()->getNode("/sim/affinity-control", true /*create*/); m_node = globals->get_props()->getNode("/sim/affinity-control", true /*create*/);
@ -407,65 +386,45 @@ struct AffinityControl : SGPropertyChangeListener
{ {
#ifdef __linux__ #ifdef __linux__
std::string s = m_node->getStringValue(); std::string s = m_node->getStringValue();
if (s == m_state) if (s == m_state) {
{
SG_LOG(SG_VIEW, SG_ALERT, "Ignoring m_node=" << s << " because same as m_state."); SG_LOG(SG_VIEW, SG_ALERT, "Ignoring m_node=" << s << " because same as m_state.");
} } else if (s == "clear") {
else if (s == "clear")
{
char buffer[64]; char buffer[64];
snprintf(buffer, sizeof(buffer), "/proc/%i/task", getpid()); snprintf(buffer, sizeof(buffer), "/proc/%i/task", getpid());
SGPath path(buffer); SGPath path(buffer);
simgear::Dir dir(path); simgear::Dir dir(path);
m_thread_masks.clear(); m_thread_masks.clear();
simgear::PathList pids = dir.children( simgear::PathList pids = dir.children(
simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
); for (SGPath path : pids) {
for (SGPath path: pids)
{
std::string leaf = path.file(); std::string leaf = path.file();
int pid = atoi(leaf.c_str()); int pid = atoi(leaf.c_str());
cpu_set_t mask; cpu_set_t mask;
int e = sched_getaffinity(pid, sizeof(mask), &mask); int e = sched_getaffinity(pid, sizeof(mask), &mask);
SG_LOG(SG_VIEW, SG_ALERT, "Called sched_getaffinity()" SG_LOG(SG_VIEW, SG_ALERT, "Called sched_getaffinity()"
<< " pid=" << pid << " pid=" << pid << " => e=" << e << " mask=" << mask);
<< " => e=" << e if (!e) {
<< " mask=" << mask
);
if (!e)
{
m_thread_masks[pid] = mask; m_thread_masks[pid] = mask;
memset(&mask, 255, sizeof(mask)); memset(&mask, 255, sizeof(mask));
e = sched_setaffinity(pid, sizeof(mask), &mask); e = sched_setaffinity(pid, sizeof(mask), &mask);
SG_LOG(SG_VIEW, SG_ALERT, "Called sched_setaffinity()" SG_LOG(SG_VIEW, SG_ALERT, "Called sched_setaffinity()"
<< " pid=" << pid << " pid=" << pid << " => e=" << e << " mask=" << mask);
<< " => e=" << e
<< " mask=" << mask
);
//assert(!e); //assert(!e);
} }
} }
m_state = s; m_state = s;
} } else if (s == "revert") {
else if (s == "revert") for (auto it : m_thread_masks) {
{
for (auto it: m_thread_masks)
{
pid_t pid = it.first; pid_t pid = it.first;
cpu_set_t mask = it.second; cpu_set_t mask = it.second;
int e = sched_setaffinity(pid, sizeof(mask), &mask); int e = sched_setaffinity(pid, sizeof(mask), &mask);
SG_LOG(SG_VIEW, SG_ALERT, "Called sched_setaffinity()" SG_LOG(SG_VIEW, SG_ALERT, "Called sched_setaffinity()"
<< " pid=" << pid << " pid=" << pid << " => e=" << e << " mask=" << mask);
<< " => e=" << e
<< " mask=" << mask
);
//assert(!e); //assert(!e);
} }
m_thread_masks.clear(); m_thread_masks.clear();
m_state = s; m_state = s;
} } else {
else
{
SG_LOG(SG_VIEW, SG_ALERT, "Unrecognised m_node=" << s); SG_LOG(SG_VIEW, SG_ALERT, "Unrecognised m_node=" << s);
} }
#endif #endif
@ -487,8 +446,7 @@ int fgOSMainLoop()
viewer_base->realize(); viewer_base->realize();
std::string affinity = fgGetString("/sim/thread-cpu-affinity"); std::string affinity = fgGetString("/sim/thread-cpu-affinity");
SG_LOG(SG_VIEW, SG_ALERT, "affinity=" << affinity); SG_LOG(SG_VIEW, SG_ALERT, "affinity=" << affinity);
if (affinity != "") if (affinity != "") {
{
ShowAffinities(); ShowAffinities();
if (affinity == "osg") { if (affinity == "osg") {
SG_LOG(SG_VIEW, SG_ALERT, "Resetting affinity of current thread getpid()=" << getpid()); SG_LOG(SG_VIEW, SG_ALERT, "Resetting affinity of current thread getpid()=" << getpid());
@ -501,18 +459,14 @@ int fgOSMainLoop()
while (!viewer_base->done()) { while (!viewer_base->done()) {
fgIdleHandler idleFunc = globals->get_renderer()->getEventHandler()->getIdleHandler(); fgIdleHandler idleFunc = globals->get_renderer()->getEventHandler()->getIdleHandler();
if (idleFunc) if (idleFunc) {
{
_lastUpdate.stamp(); _lastUpdate.stamp();
(*idleFunc)(); (*idleFunc)();
if (fgGetBool("/sim/position-finalized", false)) if (fgGetBool("/sim/position-finalized", false)) {
{ if (simHost && simFrameCount && simTotalHostTime && simFrameResetCount) {
if (simHost && simFrameCount && simTotalHostTime && simFrameResetCount)
{
int curFrameCount = simFrameCount->getIntValue(); int curFrameCount = simFrameCount->getIntValue();
double totalSimTime = simTotalHostTime->getDoubleValue(); double totalSimTime = simTotalHostTime->getDoubleValue();
if (simFrameResetCount->getBoolValue()) if (simFrameResetCount->getBoolValue()) {
{
curFrameCount = 0; curFrameCount = 0;
totalSimTime = 0; totalSimTime = 0;
simFrameResetCount->setBoolValue(false); simFrameResetCount->setBoolValue(false);
@ -521,8 +475,7 @@ int fgOSMainLoop()
double idle_wait = 0; double idle_wait = 0;
if (frameWait) if (frameWait)
idle_wait = frameWait->getDoubleValue(); idle_wait = frameWait->getDoubleValue();
if (lastSimFrame_ms > 0) if (lastSimFrame_ms > 0) {
{
totalSimTime += lastSimFrame_ms - idle_wait; totalSimTime += lastSimFrame_ms - idle_wait;
simTotalHostTime->setDoubleValue(totalSimTime); simTotalHostTime->setDoubleValue(totalSimTime);
curFrameCount++; curFrameCount++;
@ -608,8 +561,7 @@ void fgOSFullScreen()
osgViewer::GraphicsWindow* window = windows[0]; osgViewer::GraphicsWindow* window = windows[0];
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (wsi == NULL) if (wsi == NULL) {
{
SG_LOG(SG_VIEW, SG_ALERT, "ERROR: No WindowSystemInterface available. Cannot toggle window fullscreen."); SG_LOG(SG_VIEW, SG_ALERT, "ERROR: No WindowSystemInterface available. Cannot toggle window fullscreen.");
return; return;
} }
@ -637,11 +589,8 @@ void fgOSFullScreen()
//bool isFullScreen = x == 0 && y == 0 && width == (int)screenWidth && height == (int)screenHeight; //bool isFullScreen = x == 0 && y == 0 && width == (int)screenWidth && height == (int)screenHeight;
bool isFullScreen = !window->getWindowDecoration(); bool isFullScreen = !window->getWindowDecoration();
SG_LOG(SG_VIEW, SG_DEBUG, "Toggling fullscreen. Previous window rectangle (" SG_LOG(SG_VIEW, SG_DEBUG, "Toggling fullscreen. Previous window rectangle (" << x << ", " << y << ") x (" << width << ", " << height << "), fullscreen: " << isFullScreen << ", number of screens: " << wsi->getNumScreens());
<< x << ", " << y << ") x (" << width << ", " << height << "), fullscreen: " << isFullScreen if (isFullScreen) {
<< ", number of screens: " << wsi->getNumScreens());
if (isFullScreen)
{
// limit x,y coordinates and window size to screen area // limit x,y coordinates and window size to screen area
if (previous_x + previous_width > (int)screenWidth) if (previous_x + previous_width > (int)screenWidth)
previous_x = 0; previous_x = 0;
@ -653,9 +602,7 @@ void fgOSFullScreen()
y = previous_y; y = previous_y;
width = previous_width; width = previous_width;
height = previous_height; height = previous_height;
} } else {
else
{
// remember previous setting // remember previous setting
previous_x = x; previous_x = x;
previous_y = y; previous_y = y;