Move tide calculations from FGLight into it's own subsystem
This commit is contained in:
parent
5fcbd46d53
commit
23252df726
7 changed files with 139 additions and 6 deletions
|
@ -115,6 +115,7 @@
|
|||
#include <Sound/voice.hxx>
|
||||
#include <Sound/soundmanager.hxx>
|
||||
#include <Systems/system_mgr.hxx>
|
||||
#include <Time/tide.hxx>
|
||||
#include <Time/light.hxx>
|
||||
#include <Time/TimeManager.hxx>
|
||||
|
||||
|
@ -1117,6 +1118,7 @@ void fgCreateSubsystems(bool duringReset) {
|
|||
if (!duringReset) {
|
||||
globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
|
||||
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
|
||||
globals->add_subsystem("tides", new FGTide );
|
||||
}
|
||||
|
||||
globals->add_new_subsystem<FGAircraftModel>(SGSubsystemMgr::DISPLAY);
|
||||
|
|
|
@ -114,6 +114,7 @@ SGSubsystem* createSubsystemByName(const std::string& name)
|
|||
#ifdef ENABLE_SWIFT
|
||||
MAKE_SUB(SwiftConnection, "swift");
|
||||
#endif
|
||||
MAKE_SUB(FGLight, "tides");
|
||||
MAKE_SUB(FGLight, "lighting");
|
||||
MAKE_SUB(FGAircraftModel, "aircraft-model");
|
||||
MAKE_SUB(FGModelMgr, "model-manager");
|
||||
|
|
|
@ -3,12 +3,14 @@ include(FlightGearComponent)
|
|||
set(SOURCES
|
||||
TimeManager.cxx
|
||||
light.cxx
|
||||
tide.cxx
|
||||
bodysolver.cxx
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
TimeManager.hxx
|
||||
light.hxx
|
||||
tide.hxx
|
||||
bodysolver.hxx
|
||||
)
|
||||
|
||||
|
|
|
@ -108,8 +108,6 @@ void FGLight::bind () {
|
|||
_sunAngleRad->setDoubleValue(_sun_angle);
|
||||
_moonAngleRad = prop->getNode("/sim/time/moon-angle-rad", true);
|
||||
_moonAngleRad->setDoubleValue(_moon_angle);
|
||||
_tideLevelNorm = prop->getNode("/sim/time/tide-level-norm", true);
|
||||
_tideLevelNorm->setDoubleValue(_tide_level_norm);
|
||||
_humidity = fgGetNode("/environment/relative-humidity", true);
|
||||
|
||||
// Read Only
|
||||
|
@ -362,9 +360,6 @@ void FGLight::updateObjects()
|
|||
// update the moon position
|
||||
updateBodyPos("moon", &_moon_lon, &_moon_gc_lat, &_moon_vec, &_moon_vec_inv,
|
||||
&_moon_angle, _moonAngleRad, &_moon_rotation);
|
||||
|
||||
_tide_level_norm = _moon_angle/SGD_PI;
|
||||
_tideLevelNorm->setDoubleValue(_tide_level_norm);
|
||||
}
|
||||
|
||||
// update the position of one solar system body
|
||||
|
|
|
@ -73,7 +73,6 @@ private:
|
|||
// (in radians)
|
||||
double _sun_angle = 0.0 , _moon_angle = 0.0;
|
||||
double _prev_sun_angle = 0.0;
|
||||
double _tide_level_norm = 0;
|
||||
|
||||
// the rotation around our vertical axis of the sun (relative to
|
||||
// due south with positive numbers going in the counter clockwise
|
||||
|
@ -108,6 +107,7 @@ private:
|
|||
|
||||
double _dt_total = 0.0;
|
||||
|
||||
void update_tide();
|
||||
void update_sky_color ();
|
||||
void update_adj_fog_color ();
|
||||
|
||||
|
|
71
src/Time/tide.cxx
Normal file
71
src/Time/tide.cxx
Normal file
|
@ -0,0 +1,71 @@
|
|||
// tide.cxx -- interface for tidal movement
|
||||
//
|
||||
// Written by Erik Hofman, Octover 2020
|
||||
//
|
||||
// Copyright (C) 2020 Erik Hofman <erik@ehofman.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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
|
||||
// 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/constants.h>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
#include <simgear/structure/SGExpression.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
#include "tide.hxx"
|
||||
#include "light.hxx"
|
||||
#include "bodysolver.hxx"
|
||||
|
||||
void FGTide::reinit() {
|
||||
_prev_moon_rotation = -9999.0;
|
||||
}
|
||||
|
||||
void FGTide::bind()
|
||||
{
|
||||
SGPropertyNode *prop = globals->get_props();
|
||||
|
||||
_tideAnimation = prop->getNode("/environment/sea/surface/delta-T-tide", true);
|
||||
|
||||
_tideLevelNorm = prop->getNode("/sim/time/tide-level-norm", true);
|
||||
_tideLevelNorm->setDoubleValue(_tide_level);
|
||||
}
|
||||
|
||||
void FGTide::unbind()
|
||||
{
|
||||
_tideLevelNorm.reset();
|
||||
_tideAnimation.reset();
|
||||
}
|
||||
|
||||
void FGTide::update(double dt)
|
||||
{
|
||||
FGLight *l = static_cast<FGLight*>(globals->get_subsystem("lighting"));
|
||||
double moon_rotation = l->get_moon_rotation();
|
||||
if (fabs(_prev_moon_rotation - moon_rotation) > (SGD_PI/180.0))
|
||||
{
|
||||
// double sun_rotation = _sunAngleRad->getDoubleValue();
|
||||
_prev_moon_rotation = moon_rotation;
|
||||
|
||||
// Angles range from 0.0 (straight up) to pi (straight down).
|
||||
// The sun and moon rotate once every day (approximately) but tides
|
||||
// happen twice a day.
|
||||
_tide_level = cos(2.0*moon_rotation);
|
||||
|
||||
_tideLevelNorm->setDoubleValue(_tide_level);
|
||||
_tideAnimation->setDoubleValue(0.5 + 0.5*_tide_level);
|
||||
}
|
||||
}
|
||||
|
||||
// Register the subsystem.
|
||||
SGSubsystemMgr::Registrant<FGTide> registrantFGTide;
|
62
src/Time/tide.hxx
Normal file
62
src/Time/tide.hxx
Normal file
|
@ -0,0 +1,62 @@
|
|||
// tide.hxx -- interface for tidal movement
|
||||
//
|
||||
// Written by Erik Hofman, Octover 2020
|
||||
//
|
||||
// Copyright (C) 2020 Erik Hofman <erik@ehofman.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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
|
||||
// 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.
|
||||
//
|
||||
|
||||
#ifndef __FGTIDE_HXX
|
||||
#define __FGTIDE_HXX
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/props/tiedpropertylist.hxx>
|
||||
|
||||
class FGTide : public SGSubsystem
|
||||
{
|
||||
public:
|
||||
FGTide() = default;
|
||||
virtual ~FGTide() = default;
|
||||
|
||||
// Subsystem API.
|
||||
void bind() override;
|
||||
void reinit() override;
|
||||
void unbind() override;
|
||||
void update(double dt) override;
|
||||
|
||||
// Subsystem identification.
|
||||
static const char* staticSubsystemClassId() { return "tides"; }
|
||||
|
||||
private:
|
||||
// the rotation between the celestial object and the local horizontal
|
||||
// (in radians)
|
||||
double _prev_moon_rotation = -9999.0;
|
||||
double _tide_level = 0;
|
||||
|
||||
SGPropertyNode_ptr _tideLevelNorm;
|
||||
SGPropertyNode_ptr _tideAnimation;
|
||||
};
|
||||
|
||||
#endif // __FGTIDE_HXX
|
Loading…
Add table
Reference in a new issue