Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- ////////////////////////////////SERVER//////////////////////////////////////////
- --------------------------------------------------------------------------------
- ///ServerGameLogic.h\\\
- float gameStartTime_;
- __int64 gameStartUtcTime_;
- __int64 GetUtcGameTime();
- ///ServerGameLogic.cpp\\\
- void ServerGameLogic::Init(const GBGameInfo& ginfo, uint32_t creatorID) //při spuštění serveru
- {
- //blablabla
- //zde server inicializuje čas (reálný?)
- // init game time
- gameStartTime_ = r3dGetTime(); // - nevim přesně co dělá r3dGetTime() - tuším, že měří čas od dané inicializace
- __int64 utcTime = GetUtcGameTime();
- struct tm* tm = _gmtime64(&utcTime); // - struct tm - struktura pro lepší práci s časem - převod na hodiny, minuty, atd.
- r3d_assert(tm);
- char buf[128];
- asctime_s(buf, sizeof(buf), tm);
- r3dOutToLog("Server time is %s", buf); // - vypíše tm ve formátu DEN MĚSÍC DEN (DATUM) HH:MM:SS ROK -> obsahuje převod času
- //blablabla inicializace serveru - nezajímavé věci
- return;
- }
- ///////////////////////////////
- část paketu PKT_C2S_JoinGameReq
- PKT_S2C_JoinGameAns_s n;
- //blablabla
- n.gameTime = GetUtcGameTime(); // - posíláme klientovi informaci o čase
- //blablabla
- ///////////////////////////////
- __int64 ServerGameLogic::GetUtcGameTime()
- {
- // "world time start" offset, so gametime at 1st sep 2012 will be in 2018 range
- struct tm toff = {0};
- toff.tm_year = 2011-1900;
- toff.tm_mon = 6;
- toff.tm_mday = 1;
- toff.tm_isdst = -1; // A value less than zero to have the C run-time library code compute whether standard time or daylight saving time is in effect.
- __int64 secs0 = _mkgmtime64(&toff); // world start time
- __int64 secs1 = _time64(&secs1); // current UTC time
- // reassemble time, with speedup factor
- return secs0 + (secs1 - secs0) * (__int64)GPP_Data.c_iGameTimeCompression;
- }
- --------------------------------------------------------------------------------
- ////////////////////////////////CLIENT//////////////////////////////////////////
- --------------------------------------------------------------------------------
- ///ClientGameLogic.h\\\
- __int64 gameStartUtcTime_;
- float gameStartTime_;
- __int64 GetServerGameTime() const;
- void UpdateTimeOfDay();
- ///ClientGameLogic.cpp\\\
- část paketu PKT_C2S_JoinGameAns
- //blablabla
- gameStartUtcTime_ = n.gameTime;
- gameStartTime_ = r3dGetTime();
- UpdateTimeOfDay();
- //blablabla
- __int64 ClientGameLogic::GetServerGameTime() const
- {
- float secs = (r3dGetTime() - gameStartTime_) * (float)GPP->c_iGameTimeCompression;
- __int64 gameUtcTime = gameStartUtcTime_ + __int64(secs);
- return gameUtcTime;
- }
- void ClientGameLogic::UpdateTimeOfDay()
- {
- //blablabla
- __int64 gameUtcTime = GetServerGameTime();
- struct tm* tm = _gmtime64(&gameUtcTime);
- r3d_assert(tm);
- r3dGameLevel::Environment.__CurTime = (float)tm->tm_hour + (float)tm->tm_min / 59.0f;
- //do not add seconds, much shadow flicker
- //r3dGameLevel::Environment.__CurTime += (float)tm->tm_sec / (59.0f * 59.0f);
- // reset shadow cache if environment time is changed
- if(fabs(r3dGameLevel::Environment.__CurTime - lastShadowCacheReset_) > 0.01f)
- {
- //r3dOutToLog("Server time: %f %d %d %d %d:%d\n", r3dGameLevel::Environment.__CurTime, tm->tm_mon, tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour, tm->tm_min);
- lastShadowCacheReset_ = r3dGameLevel::Environment.__CurTime;
- ResetShadowCache();
- }
- }
- čas je zobrazován v ESC menu
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- tj. uvedeno v HUDPause.cpp jako funkce SetTime(__int64 utcTime) - dosazujeme gameUtcTime tedy GetServerGameTime()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement