Added day colors and day speed parameters.

develop
Warmist 2013-06-27 00:14:03 +03:00
parent 70880897f6
commit b4091b5056
4 changed files with 54 additions and 8 deletions

@ -274,7 +274,7 @@ bool lightingEngineViewscreen::lightUpCell(std::vector<lightCell> & target, ligh
} }
if(ls.radius>0 && dsq>0) if(ls.radius>0 && dsq>0)
{ {
if(power<ls.power) if(power<=ls.power)
return false; return false;
} }
//float dt=sqrt(dsq); //float dt=sqrt(dsq);
@ -597,17 +597,38 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
} }
} }
} }
lightCell lightingEngineViewscreen::getSkyColor(float v)
{
if(dayColors.size()<2)
{
v=abs(fmod(v+0.5,1)-0.5)*2;
return lightCell(v,v,v);
}
else
{
float pos=v*(dayColors.size()-1);
int pre=floor(pos);
pos-=pre;
if(pre==dayColors.size()-1)
return dayColors[pre];
return dayColors[pre]*(1-pos)+dayColors[pre+1]*pos;
}
}
void lightingEngineViewscreen::doOcupancyAndLights() void lightingEngineViewscreen::doOcupancyAndLights()
{ {
// TODO better curve (+red dawn ?) // TODO better curve (+red dawn ?)
float daycol; float daycol;
if(dayHour<0) if(dayHour<0)
daycol= abs((*df::global::cur_year_tick % 1200) - 600.0) / 600.0; {
int length=1200/daySpeed;
daycol= (*df::global::cur_year_tick % length)/ (float)length;
}
else else
daycol= abs(fmod(dayHour+12.0f,24.0f)-12.0f)/12.0f; //1->12h 0->24h daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h
lightCell sky_col(daycol, daycol, daycol); lightCell sky_col=getSkyColor(daycol);
lightSource sky(sky_col, 15); lightSource sky(sky_col, 15);//auto calculate best size
lightSource candle(lightCell(0.96f,0.84f,0.03f),5); lightSource candle(lightCell(0.96f,0.84f,0.03f),5);
lightSource torch(lightCell(0.9f,0.75f,0.3f),8); lightSource torch(lightCell(0.9f,0.75f,0.3f),8);
@ -970,7 +991,18 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L)
LOAD_SPECIAL(CITIZEN,matCitizen); LOAD_SPECIAL(CITIZEN,matCitizen);
GETLUANUMBER(engine->levelDim,levelDim); GETLUANUMBER(engine->levelDim,levelDim);
GETLUANUMBER(engine->dayHour,dayHour); GETLUANUMBER(engine->dayHour,dayHour);
GETLUANUMBER(engine->daySpeed,daySpeed);
lua_getfield(L,-1,"dayColors");
if(lua_istable(L,-1))
{
engine->dayColors.clear();
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
engine->dayColors.push_back(lua_parseLightCell(L));
lua_pop(L,1);
}
lua_pop(L,1);
}
return 0; return 0;
} }
#undef LOAD_SPECIAL #undef LOAD_SPECIAL
@ -1037,6 +1069,10 @@ void lightingEngineViewscreen::defaultSettings()
matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6); matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6);
levelDim=0.2f; levelDim=0.2f;
dayHour=-1; dayHour=-1;
daySpeed=1;
dayColors.push_back(lightCell(0,0,0));
dayColors.push_back(lightCell(1,1,1));
dayColors.push_back(lightCell(0,0,0));
} }
void lightingEngineViewscreen::loadSettings() void lightingEngineViewscreen::loadSettings()
{ {
@ -1075,6 +1111,7 @@ void lightingEngineViewscreen::loadSettings()
lua_pushlightuserdata(s, this); lua_pushlightuserdata(s, this);
lua_pushvalue(s,env); lua_pushvalue(s,env);
Lua::SafeCall(out,s,2,0); Lua::SafeCall(out,s,2,0);
out.print("%d day light colors loaded\n",dayColors.size());
lua_pushcfunction(s, parseBuildings); lua_pushcfunction(s, parseBuildings);
lua_pushlightuserdata(s, this); lua_pushlightuserdata(s, this);

@ -188,8 +188,11 @@ private:
public: public:
void lightWorkerThread(void * arg); void lightWorkerThread(void * arg);
private: private:
lightCell getSkyColor(float v);
//settings //settings
float daySpeed;
float dayHour; //<0 to cycle float dayHour; //<0 to cycle
std::vector<lightCell> dayColors; // a gradient of colors, first to 0, last to 24
///set up sane settings if setting file does not exist. ///set up sane settings if setting file does not exist.
void defaultSettings(); void defaultSettings();

@ -223,9 +223,9 @@ struct lightCell
{ {
return lightCell(r+other.r,g+other.g,b+other.b); return lightCell(r+other.r,g+other.g,b+other.b);
} }
bool operator<(const lightCell& other) const bool operator<=(const lightCell& other) const
{ {
return r<other.r && g<other.g && b<other.b; return r<=other.r && g<=other.g && b<=other.b;
} }
float dot(const lightCell& other) const float dot(const lightCell& other) const
{ {

@ -105,6 +105,12 @@ special.CURSOR=makeMaterialDef({1,1,1},{0.96,0.84,0.03},11, {"flicker"})
special.CITIZEN=makeMaterialDef(nil,{0.80,0.80,0.90},6) special.CITIZEN=makeMaterialDef(nil,{0.80,0.80,0.90},6)
special.LevelDim=0.2 -- darkness. Do not set to 0 special.LevelDim=0.2 -- darkness. Do not set to 0
special.dayHour=-1 -- <0 cycle, else hour of the day special.dayHour=-1 -- <0 cycle, else hour of the day
special.dayColors={ {0,0,0}, --dark at 0 hours
{0.6,0.5,0.5}, --reddish twilight
{1,1,1}, --fullbright at 12 hours
{0.5,0.5,0.5},
{0,0,0}} --dark at 24 hours
special.daySpeed=1 -- 1->1200 cur_year_ticks per day. 2->600 ticks
--TODO dragonfire --TODO dragonfire
--materials --materials