1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 19:45:32 +00:00

Change moon phase to an enum class

This commit is contained in:
Evil Eye 2020-10-26 22:16:31 +01:00
parent f6e4c7cb42
commit 2c4cafa41a
4 changed files with 34 additions and 35 deletions

View file

@ -941,10 +941,10 @@ public:
Moon(osg::Group* parentNode, Resource::ImageManager& imageManager, float scaleFactor, Type type)
: CelestialBody(parentNode, scaleFactor, 2)
, mType(type)
, mPhase(MoonState::Phase_Unspecified)
, mPhase(MoonState::Phase::Unspecified)
, mUpdater(new Updater(imageManager))
{
setPhase(MoonState::Phase_Full);
setPhase(MoonState::Phase::Full);
setVisible(true);
mGeom->addUpdateCallback(mUpdater);
@ -993,14 +993,14 @@ public:
unsigned int getPhaseInt() const
{
if (mPhase == MoonState::Phase_New) return 0;
else if (mPhase == MoonState::Phase_WaxingCrescent) return 1;
else if (mPhase == MoonState::Phase_WaningCrescent) return 1;
else if (mPhase == MoonState::Phase_FirstQuarter) return 2;
else if (mPhase == MoonState::Phase_ThirdQuarter) return 2;
else if (mPhase == MoonState::Phase_WaxingGibbous) return 3;
else if (mPhase == MoonState::Phase_WaningGibbous) return 3;
else if (mPhase == MoonState::Phase_Full) return 4;
if (mPhase == MoonState::Phase::New) return 0;
else if (mPhase == MoonState::Phase::WaxingCrescent) return 1;
else if (mPhase == MoonState::Phase::WaningCrescent) return 1;
else if (mPhase == MoonState::Phase::FirstQuarter) return 2;
else if (mPhase == MoonState::Phase::ThirdQuarter) return 2;
else if (mPhase == MoonState::Phase::WaxingGibbous) return 3;
else if (mPhase == MoonState::Phase::WaningGibbous) return 3;
else if (mPhase == MoonState::Phase::Full) return 4;
return 0;
}
@ -1090,14 +1090,14 @@ private:
else
textureName += "masser_";
if (phase == MoonState::Phase_New) textureName += "new";
else if(phase == MoonState::Phase_WaxingCrescent) textureName += "one_wax";
else if(phase == MoonState::Phase_FirstQuarter) textureName += "half_wax";
else if(phase == MoonState::Phase_WaxingGibbous) textureName += "three_wax";
else if(phase == MoonState::Phase_WaningCrescent) textureName += "one_wan";
else if(phase == MoonState::Phase_ThirdQuarter) textureName += "half_wan";
else if(phase == MoonState::Phase_WaningGibbous) textureName += "three_wan";
else if(phase == MoonState::Phase_Full) textureName += "full";
if (phase == MoonState::Phase::New) textureName += "new";
else if(phase == MoonState::Phase::WaxingCrescent) textureName += "one_wax";
else if(phase == MoonState::Phase::FirstQuarter) textureName += "half_wax";
else if(phase == MoonState::Phase::WaxingGibbous) textureName += "three_wax";
else if(phase == MoonState::Phase::WaningCrescent) textureName += "one_wan";
else if(phase == MoonState::Phase::ThirdQuarter) textureName += "half_wan";
else if(phase == MoonState::Phase::WaningGibbous) textureName += "three_wan";
else if(phase == MoonState::Phase::Full) textureName += "full";
textureName += ".dds";

View file

@ -99,17 +99,17 @@ namespace MWRender
struct MoonState
{
enum Phase
enum class Phase
{
Phase_Full = 0,
Phase_WaningGibbous,
Phase_ThirdQuarter,
Phase_WaningCrescent,
Phase_New,
Phase_WaxingCrescent,
Phase_FirstQuarter,
Phase_WaxingGibbous,
Phase_Unspecified
Full = 0,
WaningGibbous,
ThirdQuarter,
WaningCrescent,
New,
WaxingCrescent,
FirstQuarter,
WaxingGibbous,
Unspecified
};
float mRotationFromHorizon;

View file

@ -370,7 +370,7 @@ MWRender::MoonState MoonModel::calculateState(const TimeStamp& gameTime) const
{
rotationFromHorizon,
mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices.
static_cast<MWRender::MoonState::Phase>(phase(gameTime)),
phase(gameTime),
shadowBlend(rotationFromHorizon),
earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameTime.getHour())
};
@ -439,17 +439,15 @@ inline float MoonModel::rotation(float hours) const
return 15.0f * mSpeed * hours;
}
inline unsigned int MoonModel::phase(const TimeStamp& gameTime) const
MWRender::MoonState::Phase MoonModel::phase(const TimeStamp& gameTime) const
{
// Morrowind starts with a full moon on 16 Last Seed and then begins to wane 17 Last Seed, working on 3 day phase cycle.
// Note: this is an internal helper, and as such we don't want to return MWRender::MoonState::Phase since we can't
// forward declare it (C++11 strongly typed enums solve this).
// If the moon didn't rise yet today, use yesterday's moon phase.
if(gameTime.getHour() < moonRiseHour(gameTime.getDay()))
return (gameTime.getDay() / 3) % 8;
return static_cast<MWRender::MoonState::Phase>((gameTime.getDay() / 3) % 8);
else
return ((gameTime.getDay() + 1) / 3) % 8;
return static_cast<MWRender::MoonState::Phase>(((gameTime.getDay() + 1) / 3) % 8);
}
inline float MoonModel::shadowBlend(float angle) const

View file

@ -24,6 +24,7 @@ namespace ESM
namespace MWRender
{
class RenderingManager;
enum class MoonState::Phase;
}
namespace Loading
@ -261,7 +262,7 @@ namespace MWWorld
float angle(const TimeStamp& gameTime) const;
float moonRiseHour(unsigned int daysPassed) const;
float rotation(float hours) const;
unsigned int phase(const TimeStamp& gameTime) const;
MWRender::MoonState::Phase phase(const TimeStamp& gameTime) const;
float shadowBlend(float angle) const;
float hourlyAlpha(float gameHour) const;
float earlyMoonShadowAlpha(float angle) const;