1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 22:45:33 +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) Moon(osg::Group* parentNode, Resource::ImageManager& imageManager, float scaleFactor, Type type)
: CelestialBody(parentNode, scaleFactor, 2) : CelestialBody(parentNode, scaleFactor, 2)
, mType(type) , mType(type)
, mPhase(MoonState::Phase_Unspecified) , mPhase(MoonState::Phase::Unspecified)
, mUpdater(new Updater(imageManager)) , mUpdater(new Updater(imageManager))
{ {
setPhase(MoonState::Phase_Full); setPhase(MoonState::Phase::Full);
setVisible(true); setVisible(true);
mGeom->addUpdateCallback(mUpdater); mGeom->addUpdateCallback(mUpdater);
@ -993,14 +993,14 @@ public:
unsigned int getPhaseInt() const unsigned int getPhaseInt() const
{ {
if (mPhase == MoonState::Phase_New) return 0; if (mPhase == MoonState::Phase::New) return 0;
else if (mPhase == MoonState::Phase_WaxingCrescent) return 1; else if (mPhase == MoonState::Phase::WaxingCrescent) return 1;
else if (mPhase == MoonState::Phase_WaningCrescent) return 1; else if (mPhase == MoonState::Phase::WaningCrescent) return 1;
else if (mPhase == MoonState::Phase_FirstQuarter) return 2; else if (mPhase == MoonState::Phase::FirstQuarter) return 2;
else if (mPhase == MoonState::Phase_ThirdQuarter) return 2; else if (mPhase == MoonState::Phase::ThirdQuarter) return 2;
else if (mPhase == MoonState::Phase_WaxingGibbous) return 3; else if (mPhase == MoonState::Phase::WaxingGibbous) return 3;
else if (mPhase == MoonState::Phase_WaningGibbous) return 3; else if (mPhase == MoonState::Phase::WaningGibbous) return 3;
else if (mPhase == MoonState::Phase_Full) return 4; else if (mPhase == MoonState::Phase::Full) return 4;
return 0; return 0;
} }
@ -1090,14 +1090,14 @@ private:
else else
textureName += "masser_"; textureName += "masser_";
if (phase == MoonState::Phase_New) textureName += "new"; if (phase == MoonState::Phase::New) textureName += "new";
else if(phase == MoonState::Phase_WaxingCrescent) textureName += "one_wax"; else if(phase == MoonState::Phase::WaxingCrescent) textureName += "one_wax";
else if(phase == MoonState::Phase_FirstQuarter) textureName += "half_wax"; else if(phase == MoonState::Phase::FirstQuarter) textureName += "half_wax";
else if(phase == MoonState::Phase_WaxingGibbous) textureName += "three_wax"; else if(phase == MoonState::Phase::WaxingGibbous) textureName += "three_wax";
else if(phase == MoonState::Phase_WaningCrescent) textureName += "one_wan"; else if(phase == MoonState::Phase::WaningCrescent) textureName += "one_wan";
else if(phase == MoonState::Phase_ThirdQuarter) textureName += "half_wan"; else if(phase == MoonState::Phase::ThirdQuarter) textureName += "half_wan";
else if(phase == MoonState::Phase_WaningGibbous) textureName += "three_wan"; else if(phase == MoonState::Phase::WaningGibbous) textureName += "three_wan";
else if(phase == MoonState::Phase_Full) textureName += "full"; else if(phase == MoonState::Phase::Full) textureName += "full";
textureName += ".dds"; textureName += ".dds";

View file

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

View file

@ -370,7 +370,7 @@ MWRender::MoonState MoonModel::calculateState(const TimeStamp& gameTime) const
{ {
rotationFromHorizon, rotationFromHorizon,
mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices. mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices.
static_cast<MWRender::MoonState::Phase>(phase(gameTime)), phase(gameTime),
shadowBlend(rotationFromHorizon), shadowBlend(rotationFromHorizon),
earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameTime.getHour()) earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameTime.getHour())
}; };
@ -439,17 +439,15 @@ inline float MoonModel::rotation(float hours) const
return 15.0f * mSpeed * hours; 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. // 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 the moon didn't rise yet today, use yesterday's moon phase.
if(gameTime.getHour() < moonRiseHour(gameTime.getDay())) if(gameTime.getHour() < moonRiseHour(gameTime.getDay()))
return (gameTime.getDay() / 3) % 8; return static_cast<MWRender::MoonState::Phase>((gameTime.getDay() / 3) % 8);
else 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 inline float MoonModel::shadowBlend(float angle) const

View file

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