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.
This commit is contained in:
Edward d'Auvergne 2018-04-03 11:59:46 +02:00
parent d8a46cffa5
commit b73dfb08ae
9 changed files with 209 additions and 212 deletions

View File

@ -28,42 +28,39 @@ namespace simgear
namespace canvas namespace canvas
{ {
class CanvasMgr: class CanvasMgr : public PropertyBasedMgr
public PropertyBasedMgr {
{ public:
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 * Create a new canvas
*/ *
CanvasMgr(SGPropertyNode_ptr node); * @param name Name of the new canvas
*/
CanvasPtr createCanvas(const std::string& name = "");
/** /**
* Create a new canvas * Get ::Canvas by index
* *
* @param name Name of the new canvas * @param index Index of texture node in /canvas/by-index/
*/ */
CanvasPtr createCanvas(const std::string& name = ""); CanvasPtr getCanvas(size_t index) const;
/** /**
* Get ::Canvas by index * Get ::Canvas by name
* *
* @param index Index of texture node in /canvas/by-index/ * @param name Value of child node "name" in
*/ * /canvas/by-index/texture[i]/name
CanvasPtr getCanvas(size_t index) const; */
CanvasPtr getCanvas(const std::string& name) const;
/** protected:
* Get ::Canvas by name void elementCreated(PropertyBasedElementPtr element) override;
* };
* @param name Value of child node "name" in
* /canvas/by-index/texture[i]/name
*/
CanvasPtr getCanvas(const std::string& name) const;
protected:
void elementCreated(PropertyBasedElementPtr element) override;
};
} // namespace canvas } // namespace canvas
} // namespace simgear } // namespace simgear

View File

@ -30,7 +30,8 @@
// code can register another one immediately without worrying about // code can register another one immediately without worrying about
// timer aliasing. // timer aliasing.
class SGInterpolator : public SGSubsystem { class SGInterpolator : public SGSubsystem
{
public: public:
SGInterpolator() { _list = 0; } SGInterpolator() { _list = 0; }
virtual void init() {} virtual void init() {}

View File

@ -29,74 +29,71 @@
namespace simgear namespace simgear
{ {
class PropertyBasedMgr: class PropertyBasedMgr : public SGSubsystem,
public SGSubsystem, public SGPropertyChangeListener
public SGPropertyChangeListener {
{ public:
public: void init() override;
void init() override; void shutdown() override;
void shutdown() override;
void update (double delta_time_sec) override; void update(double delta_time_sec) override;
/** /**
* Create a new PropertyBasedElement * Create a new PropertyBasedElement
* *
* @param name Name of the new element * @param name Name of the new element
*/ */
PropertyBasedElementPtr createElement(const std::string& name = ""); PropertyBasedElementPtr createElement(const std::string& name = "");
/** /**
* Get an existing PropertyBasedElement by its index * Get an existing PropertyBasedElement by its index
* *
* @param index Index of element node in property tree * @param index Index of element node in property tree
*/ */
PropertyBasedElementPtr getElement(size_t index) const; PropertyBasedElementPtr getElement(size_t index) const;
/** /**
* Get an existing PropertyBasedElement by its name * Get an existing PropertyBasedElement by its name
* *
* @param name Name (value of child node "name" will be matched) * @param name Name (value of child node "name" will be matched)
*/ */
PropertyBasedElementPtr getElement(const std::string& name) const; PropertyBasedElementPtr getElement(const std::string& name) const;
virtual const SGPropertyNode* getPropertyRoot() const; virtual const SGPropertyNode* getPropertyRoot() const;
protected: protected:
typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)>
ElementFactory;
typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)> /** Branch in the property tree for this property managed subsystem */
ElementFactory; SGPropertyNode_ptr _props;
/** Branch in the property tree for this property managed subsystem */ /** Property name of managed elements */
SGPropertyNode_ptr _props; const std::string _name_elements;
/** Property name of managed elements */ /** The actually managed elements */
const std::string _name_elements; std::vector<PropertyBasedElementPtr> _elements;
/** The actually managed elements */ /** Function object which creates a new element */
std::vector<PropertyBasedElementPtr> _elements; ElementFactory _element_factory;
/** Function object which creates a new element */ /**
ElementFactory _element_factory; * @param props Root node of property branch used for controlling
* this subsystem
* @param name_elements The name of the nodes for the managed elements
*/
PropertyBasedMgr( SGPropertyNode_ptr props,
const std::string& name_elements,
ElementFactory element_factory );
virtual ~PropertyBasedMgr() = 0;
/** void childAdded( SGPropertyNode * parent,
* @param props Root node of property branch used for controlling SGPropertyNode * child ) override;
* this subsystem void childRemoved( SGPropertyNode * parent,
* @param name_elements The name of the nodes for the managed elements
*/
PropertyBasedMgr( SGPropertyNode_ptr props,
const std::string& name_elements,
ElementFactory element_factory );
virtual ~PropertyBasedMgr() = 0;
void childAdded( SGPropertyNode * parent,
SGPropertyNode * child ) override; SGPropertyNode * child ) override;
void childRemoved( SGPropertyNode * parent,
SGPropertyNode * child ) override;
virtual void elementCreated(PropertyBasedElementPtr element) {} virtual void elementCreated(PropertyBasedElementPtr element) {}
};
};
} // namespace simgear } // namespace simgear

View File

@ -28,119 +28,115 @@
#include <list> #include <list>
namespace simgear namespace simgear {
/**
* Subsystem that manages interpolation of properties.
*
* By default the numeric values of the properties are interpolated. For
* example, for strings this is probably not the wanted behavior. For this
* adapter classes can be registered to allow providing specific
* interpolations for certain types of properties. Using the type "color",
* provided by ColorInterpolator, strings containing %CSS colors can also be
* interpolated.
*
* Additionally different functions can be used for easing of the animation.
* By default "linear" (constant animation speed) and "swing" (smooth
* acceleration and deceleration) are available.
*/
class PropertyInterpolationMgr : public SGSubsystem
{ {
public:
typedef PropertyInterpolator* (*InterpolatorFactory)();
/** PropertyInterpolationMgr();
* Subsystem that manages interpolation of properties.
*
* By default the numeric values of the properties are interpolated. For
* example, for strings this is probably not the wanted behavior. For this
* adapter classes can be registered to allow providing specific
* interpolations for certain types of properties. Using the type "color",
* provided by ColorInterpolator, strings containing %CSS colors can also be
* interpolated.
*
* Additionally different functions can be used for easing of the animation.
* By default "linear" (constant animation speed) and "swing" (smooth
* acceleration and deceleration) are available.
*/
class PropertyInterpolationMgr:
public SGSubsystem
{
public:
typedef PropertyInterpolator* (*InterpolatorFactory)();
PropertyInterpolationMgr(); /**
* Update all active interpolators.
*/
void update(double dt);
/** /**
* Update all active interpolators. * Create a new property interpolator.
*/ *
void update(double dt); * @note To actually use it the interpolator needs to be attached to a
* property using PropertyInterpolationMgr::interpolate.
*
* @param type Type of animation ("numeric", "color", etc.)
* @param target Property containing target value
* @param duration Duration if the animation (in seconds)
* @param easing Type of easing ("linear", "swing", etc.)
*/
PropertyInterpolator*
createInterpolator(const std::string& type,
const SGPropertyNode& target,
double duration,
const std::string& easing);
/** /**
* Create a new property interpolator. * Add animation of the given property from its current value to the
* * target value of the interpolator. If no interpolator is given any
* @note To actually use it the interpolator needs to be attached to a * existing animation of the given property is aborted.
* property using PropertyInterpolationMgr::interpolate. *
* * @param prop Property to be interpolated
* @param type Type of animation ("numeric", "color", etc.) * @param interp Interpolator used for interpolation
* @param target Property containing target value */
* @param duration Duration if the animation (in seconds) bool interpolate(SGPropertyNode* prop,
* @param easing Type of easing ("linear", "swing", etc.) PropertyInterpolatorRef interp = 0);
*/
PropertyInterpolator*
createInterpolator( const std::string& type,
const SGPropertyNode& target,
double duration,
const std::string& easing );
/** bool interpolate(SGPropertyNode* prop,
* Add animation of the given property from its current value to the const std::string& type,
* target value of the interpolator. If no interpolator is given any const SGPropertyNode& target,
* existing animation of the given property is aborted. double duration,
* const std::string& easing);
* @param prop Property to be interpolated
* @param interp Interpolator used for interpolation
*/
bool interpolate( SGPropertyNode* prop,
PropertyInterpolatorRef interp = 0 );
bool interpolate( SGPropertyNode* prop, bool interpolate(SGPropertyNode* prop,
const std::string& type, const std::string& type,
const SGPropertyNode& target, const PropertyList& values,
double duration, const double_list& deltas,
const std::string& easing ); const std::string& easing);
bool interpolate( SGPropertyNode* prop, /**
const std::string& type, * Register factory for interpolation type.
const PropertyList& values, */
const double_list& deltas, void addInterpolatorFactory(const std::string& type,
const std::string& easing ); InterpolatorFactory factory);
template <class T>
/** void addInterpolatorFactory(const std::string& type)
* Register factory for interpolation type. {
*/ addInterpolatorFactory(
void addInterpolatorFactory( const std::string& type, type,
InterpolatorFactory factory ); &simgear::make_new_derived<PropertyInterpolator, T>
template<class T>
void addInterpolatorFactory(const std::string& type)
{
addInterpolatorFactory
(
type,
&simgear::make_new_derived<PropertyInterpolator, T>
); );
} }
/** /**
* Register easing function. * Register easing function.
*/ */
void addEasingFunction(const std::string& type, easing_func_t func); void addEasingFunction(const std::string& type, easing_func_t func);
/** /**
* Set property containing real time delta (not sim time) * Set property containing real time delta (not sim time)
* *
* TODO better pass both deltas to all update methods... * TODO better pass both deltas to all update methods...
*/ */
void setRealtimeProperty(SGPropertyNode* node); void setRealtimeProperty(SGPropertyNode* node);
protected: protected:
typedef std::map<std::string, InterpolatorFactory> InterpolatorFactoryMap;
typedef std::map<std::string, easing_func_t> EasingFunctionMap;
typedef std::pair<SGPropertyNode*,
PropertyInterpolatorRef> PropertyInterpolatorPair;
typedef std::list<PropertyInterpolatorPair> InterpolatorList;
typedef std::map<std::string, InterpolatorFactory> InterpolatorFactoryMap; struct PredicateIsSameProp;
typedef std::map<std::string, easing_func_t> EasingFunctionMap;
typedef std::pair< SGPropertyNode*,
PropertyInterpolatorRef > PropertyInterpolatorPair;
typedef std::list<PropertyInterpolatorPair> InterpolatorList;
struct PredicateIsSameProp; InterpolatorFactoryMap _interpolator_factories;
EasingFunctionMap _easing_functions;
InterpolatorList _interpolators;
InterpolatorFactoryMap _interpolator_factories; SGPropertyNode_ptr _rt_prop;
EasingFunctionMap _easing_functions; };
InterpolatorList _interpolators;
SGPropertyNode_ptr _rt_prop;
};
} // namespace simgear } // namespace simgear

View File

@ -39,7 +39,6 @@ class BufferedLogCallback;
class SGTerraSync : public SGSubsystem class SGTerraSync : public SGSubsystem
{ {
public: public:
SGTerraSync(); SGTerraSync();
virtual ~SGTerraSync(); virtual ~SGTerraSync();
@ -80,6 +79,7 @@ public:
void scheduleDataDir(const std::string& dataDir); void scheduleDataDir(const std::string& dataDir);
bool isDataDirPending(const std::string& dataDir) const; bool isDataDirPending(const std::string& dataDir) const;
protected: protected:
void syncAirportsModels(); void syncAirportsModels();
string_list getSceneryPathSuffixes() const; string_list getSceneryPathSuffixes() const;

View File

@ -49,7 +49,6 @@ class SGSoundSample;
class SGSoundMgr : public SGSubsystem class SGSoundMgr : public SGSubsystem
{ {
public: public:
SGSoundMgr(); SGSoundMgr();
~SGSoundMgr(); ~SGSoundMgr();
@ -325,6 +324,7 @@ public:
bool testForError(std::string s, std::string name = "sound manager"); bool testForError(std::string s, std::string name = "sound manager");
static const char* subsystemName() { return "sound"; }; static const char* subsystemName() { return "sound"; };
private: private:
class SoundManagerPrivate; class SoundManagerPrivate;
/// private implementation object /// private implementation object

View File

@ -34,7 +34,6 @@ class SampleStatistic;
class SGPerformanceMonitor : public SGSubsystem class SGPerformanceMonitor : public SGSubsystem
{ {
public: public:
SGPerformanceMonitor(SGSubsystemMgr* subSysMgr, SGPropertyNode_ptr root); SGPerformanceMonitor(SGSubsystemMgr* subSysMgr, SGPropertyNode_ptr root);

View File

@ -8,7 +8,8 @@
class SGEventMgr; class SGEventMgr;
class SGTimer { class SGTimer
{
public: public:
~SGTimer(); ~SGTimer();
void run(); void run();
@ -20,7 +21,8 @@ public:
bool running; bool running;
}; };
class SGTimerQueue { class SGTimerQueue
{
public: public:
SGTimerQueue(int preSize=1); SGTimerQueue(int preSize=1);
~SGTimerQueue(); ~SGTimerQueue();
@ -39,6 +41,7 @@ public:
SGTimer* findByName(const std::string& name) const; SGTimer* findByName(const std::string& name) const;
void dump(); void dump();
private: private:
// The "priority" is stored as a negative time. This allows the // The "priority" is stored as a negative time. This allows the
// implementation to treat the "top" of the heap as the largest // implementation to treat the "top" of the heap as the largest
@ -50,9 +53,9 @@ private:
int rchild(int n) { return ((n+1)*2 + 1) - 1; } int rchild(int n) { return ((n+1)*2 + 1) - 1; }
double pri(int n) { return _table[n].pri; } double pri(int n) { return _table[n].pri; }
void swap(int a, int b) { void swap(int a, int b) {
HeapEntry tmp = _table[a]; HeapEntry tmp = _table[a];
_table[a] = _table[b]; _table[a] = _table[b];
_table[b] = tmp; _table[b] = tmp;
} }
void siftDown(int n); void siftDown(int n);
void siftUp(int n); void siftUp(int n);
@ -77,6 +80,7 @@ public:
virtual void update(double delta_time_sec); virtual void update(double delta_time_sec);
virtual void unbind(); virtual void unbind();
virtual void shutdown(); virtual void shutdown();
void setRealtimeProperty(SGPropertyNode* node) { _rtProp = node; } void setRealtimeProperty(SGPropertyNode* node) { _rtProp = node; }
/** /**
@ -121,6 +125,7 @@ public:
void removeTask(const std::string& name); void removeTask(const std::string& name);
void dump(); void dump();
private: private:
friend class SGTimer; friend class SGTimer;

View File

@ -127,6 +127,7 @@ typedef void (*SGSubsystemTimingCb)(void* userData, const std::string& name, Sam
* subsystems may also override the suspend() and resume() methods to * subsystems may also override the suspend() and resume() methods to
* take different actions.</p> * take different actions.</p>
*/ */
class SGSubsystem : public SGReferenced class SGSubsystem : public SGReferenced
{ {
public: public:
@ -352,14 +353,14 @@ protected:
/// protected, not private, we can't rename it easily) /// protected, not private, we can't rename it easily)
std::string _name; std::string _name;
bool _suspended = false; bool _suspended = false;
eventTimeVec timingInfo; eventTimeVec timingInfo;
static SGSubsystemTimingCb reportTimingCb; static SGSubsystemTimingCb reportTimingCb;
static void* reportTimingUserData; static void* reportTimingUserData;
static bool reportTimingStatsRequest; static bool reportTimingStatsRequest;
static int maxTimePerFrame_ms; static int maxTimePerFrame_ms;
private: private:
SGSubsystemGroup* _group = nullptr; SGSubsystemGroup* _group = nullptr;
@ -416,9 +417,9 @@ public:
*/ */
void set_fixed_update_time(double fixed_dt); void set_fixed_update_time(double fixed_dt);
/** /**
* retrive list of member subsystem names * retrive list of member subsystem names
*/ */
string_list member_names() const; string_list member_names() const;
template<class T> template<class T>
@ -431,6 +432,7 @@ public:
{ return true; } { return true; }
SGSubsystemMgr* get_manager() const override; SGSubsystemMgr* get_manager() const override;
private: private:
void forEach(std::function<void(SGSubsystem*)> f); void forEach(std::function<void(SGSubsystem*)> f);
void reverseForEach(std::function<void(SGSubsystem*)> f); void reverseForEach(std::function<void(SGSubsystem*)> f);