made day/night detection more accurate and did some cleanup. Closes #1304

This commit is contained in:
oy 2015-03-22 13:44:19 +01:00
parent 191d7fab81
commit cdcc641af3
4 changed files with 43 additions and 36 deletions

View file

@ -1539,6 +1539,16 @@ int time_timestamp()
return time(0);
}
int time_houroftheday()
{
time_t time_data;
struct tm *time_info;
time(&time_data);
time_info = localtime(&time_data);
return time_info->tm_hour;
}
void str_append(char *dst, const char *src, int dst_size)
{
int s = strlen(dst);

View file

@ -466,6 +466,15 @@ int64 time_freq();
*/
int time_timestamp();
/*
Function: time_houroftheday
Retrives the hours since midnight (0..23)
Returns:
The current hour of the day
*/
int time_houroftheday();
/* Group: Network General */
typedef struct
{

View file

@ -30,6 +30,27 @@ CMapLayers::CMapLayers(int t)
m_pMenuLayers = 0;
}
void CMapLayers::LoadBackgroundMap()
{
int HourOfTheDay = time_houroftheday();
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "ui/%s_%s.map", g_Config.m_ClMenuMap, (HourOfTheDay >= 6 && HourOfTheDay < 18) ? "day" : "night");
if(!m_pMenuMap->Load(aBuf, m_pClient->Storage()))
{
str_format(aBuf, sizeof(aBuf), "map '%s' not found", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
return;
}
str_format(aBuf, sizeof(aBuf), "loaded map '%s'", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
m_pMenuLayers->Init(Kernel(), m_pMenuMap);
RenderTools()->RenderTilemapGenerateSkip(m_pMenuLayers);
m_pClient->m_pMapimages->OnMenuMapLoad(m_pMenuMap);
LoadEnvPoints(m_pMenuLayers, m_lEnvPointsMenu);
}
void CMapLayers::OnInit()
{
if(m_Type == TYPE_BACKGROUND)
@ -37,24 +58,7 @@ void CMapLayers::OnInit()
m_pMenuLayers = new CLayers;
m_pMenuMap = CreateEngineMap();
int HourOfTheDay = (time_timestamp()/3600)%24;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "ui/%s_%s.map", g_Config.m_ClMenuMap, (HourOfTheDay >= 6 && HourOfTheDay < 18) ? "day" : "night");
if(!m_pMenuMap->Load(aBuf, m_pClient->Storage()))
{
str_format(aBuf, sizeof(aBuf), "map '%s' not found", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
return;
}
str_format(aBuf, sizeof(aBuf), "loaded map '%s'", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
m_pMenuLayers->Init(Kernel(), m_pMenuMap);
RenderTools()->RenderTilemapGenerateSkip(m_pMenuLayers);
m_pClient->m_pMapimages->OnMenuMapLoad(m_pMenuMap);
LoadEnvPoints(m_pMenuLayers, m_lEnvPointsMenu);
LoadBackgroundMap();
}
}
@ -368,23 +372,6 @@ void CMapLayers::BackgroundMapUpdate()
// unload map
m_pMenuMap->Unload();
int HourOfTheDay = (time_timestamp()/3600)%24;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "ui/%s_%s.map", g_Config.m_ClMenuMap, (HourOfTheDay >= 6 && HourOfTheDay < 18) ? "day" : "night");
if(!m_pMenuMap->Load(aBuf, m_pClient->Storage()))
{
str_format(aBuf, sizeof(aBuf), "map '%s' not found", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
return;
}
str_format(aBuf, sizeof(aBuf), "loaded map '%s'", g_Config.m_ClMenuMap);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
m_pMenuLayers->Init(Kernel(), m_pMenuMap);
RenderTools()->RenderTilemapGenerateSkip(m_pMenuLayers);
m_pClient->m_pMapimages->OnMenuMapLoad(m_pMenuMap);
LoadEnvPoints(m_pMenuLayers, m_lEnvPointsMenu);
LoadBackgroundMap();
}
}

View file

@ -20,6 +20,7 @@ class CMapLayers : public CComponent
static void EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser);
void LoadBackgroundMap();
void LoadEnvPoints(const CLayers *pLayers, array<CEnvPoint>& lEnvPoints);
public: