00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef LILITH_TIMECLOCK_INCLUDED
00023 #define LILITH_TIMECLOCK_INCLUDED
00024
00025 #include <time.h>
00026 #include "../grinliz/gltypes.h"
00027 #include "../grinliz/glcolor.h"
00028 #include "../grinliz/glvector.h"
00029 #include "worlddefine.h"
00030
00031 namespace lilith3d
00032 {
00033
00034 class Texture;
00035
00040 struct SunMoon
00041 {
00042 enum {
00043 SUNRISE, DAYTIME, SUNSET, NIGHT
00044 };
00045
00046 bool sun;
00047 grinliz::Vector3F vector;
00048 grinliz::Vector4F vector4;
00049 grinliz::Color3F ambientColorH;
00050 grinliz::Color4F ambientColorH4;
00051 grinliz::Color3F diffuseColorH;
00052 grinliz::Color4F diffuseColorH4;
00053 grinliz::Color3F ambientColorL;
00054 grinliz::Color3F diffuseColorL;
00055 grinliz::Color4F ambientColorL4;
00056 grinliz::Color4F diffuseColorL4;
00057 grinliz::Color3F rawAmbientColor;
00058 grinliz::Color3F rawDiffuseColor;
00059 float skyBlend;
00060 int primarySky;
00061 int secondarySky;
00062 grinliz::Color3F skyColor;
00063 const Texture* primarySkydomeTex;
00064 const Texture* secondarySkydomeTex;
00065 };
00066
00067
00076 class TimeClock
00077 {
00078 public:
00079 TimeClock( U32 msecPerDay, U32 msecStart );
00080 ~TimeClock() {}
00081
00083
00084
00086 U32 CurrentFrame() { return frameCount; }
00087
00088
00089 void SetFrameStart();
00090
00091 void SetFrameDrawn();
00092
00094 float Fps() { return fps; }
00096 float FastFps() { return shortFps; }
00097
00099 float TotalFPS();
00100
00102
00103
00107 float CalcVelocity( float vel ) { return float( msecToLast ) * vel / 1000.0f; }
00108
00112 float CalcChange( float value, float velocity, float minVal, float maxVal )
00113 {
00114 GLASSERT( maxVal >= minVal );
00115
00116 value = value + CalcVelocity( velocity );
00117 return grinliz::Clamp( value, minVal, maxVal );
00118 }
00119
00120
00122
00123
00125 U32 Msec() { return msec; }
00126
00128 float HoursElapsed() { return float( msec + msecStart ) * 24.0f / float( msecPerDay ); }
00129
00131 void CalcCalendarTime( U32* days, U32* hours, U32* minutes, U32* seconds );
00132
00133
00135
00136
00138 void ToggleSun() { ++holdSun;
00139 if ( holdSun == HOLD_COUNT ) holdSun = 0;
00140 }
00141
00142 const SunMoon& GetSunMoon() { return sunMoon; }
00143
00144 private:
00145 struct SkyState
00146 {
00147 float hour;
00148 int state;
00149 };
00150
00151 struct ColorState
00152 {
00153 float hour;
00154 grinliz::Color3F color;
00155 };
00156
00157 U32 msecPerDay;
00158 U32 msecStart;
00159
00160
00161
00162 void FillSunMoonStruct();
00163
00164 static TimeClock* instance;
00165
00166 U32 frameCount;
00167 U32 msec;
00168
00169 enum { HOLD_NONE, HOLD_MIDDAY, HOLD_SUNRISE, HOLD_COUNT };
00170 int holdSun;
00171
00172 SunMoon sunMoon;
00173
00174
00175 U32 longStart;
00176 U32 fpsFrame;
00177 float fps;
00178
00179
00180 U32 shortStart;
00181 U32 shortFpsFrame;
00182 float shortFps;
00183 U32 startupMsec;
00184
00185
00186 U32 msecToLast;
00187 U32 lastStart;
00188 };
00189 };
00190
00191 #endif