|
|
@ -275,7 +275,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);
|
|
|
@ -595,12 +595,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 = 1;//abs((*df::global::cur_year_tick % 1200) - 600.0) / 400.0;
|
|
|
|
|
|
|
|
lightCell sky_col(daycol, daycol, daycol);
|
|
|
|
float daycol;
|
|
|
|
lightSource sky(sky_col, 15);
|
|
|
|
if(dayHour<0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int length=1200/daySpeed;
|
|
|
|
|
|
|
|
daycol= (*df::global::cur_year_tick % length)/ (float)length;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lightCell sky_col=getSkyColor(daycol);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -878,6 +904,10 @@ lightCell lua_parseLightCell(lua_State* L)
|
|
|
|
if(lua_isnil(L,-1)){field=false;}\
|
|
|
|
if(lua_isnil(L,-1)){field=false;}\
|
|
|
|
else{lua_getfield(L,-1,#name);field=lua_isnil(L,-1);lua_pop(L,1);}\
|
|
|
|
else{lua_getfield(L,-1,#name);field=lua_isnil(L,-1);lua_pop(L,1);}\
|
|
|
|
lua_pop(L,1)
|
|
|
|
lua_pop(L,1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define GETLUANUMBER(field,name) lua_getfield(L,-1,#name);\
|
|
|
|
|
|
|
|
if(!lua_isnil(L,-1) && lua_isnumber(L,-1))field=lua_tonumber(L,-1);\
|
|
|
|
|
|
|
|
lua_pop(L,1)
|
|
|
|
matLightDef lua_parseMatDef(lua_State* L)
|
|
|
|
matLightDef lua_parseMatDef(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -957,9 +987,20 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L)
|
|
|
|
LOAD_SPECIAL(AMBIENT,matAmbience);
|
|
|
|
LOAD_SPECIAL(AMBIENT,matAmbience);
|
|
|
|
LOAD_SPECIAL(CURSOR,matCursor);
|
|
|
|
LOAD_SPECIAL(CURSOR,matCursor);
|
|
|
|
LOAD_SPECIAL(CITIZEN,matCitizen);
|
|
|
|
LOAD_SPECIAL(CITIZEN,matCitizen);
|
|
|
|
lua_getfield(L,-1,"LevelDim");
|
|
|
|
GETLUANUMBER(engine->levelDim,levelDim);
|
|
|
|
if(!lua_isnil(L,-1) && lua_isnumber(L,-1))engine->levelDim=lua_tonumber(L,-1);
|
|
|
|
GETLUANUMBER(engine->dayHour,dayHour);
|
|
|
|
lua_pop(L,1);
|
|
|
|
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
|
|
|
@ -1025,6 +1066,11 @@ void lightingEngineViewscreen::defaultSettings()
|
|
|
|
matWall=matLightDef(lightCell(0,0,0));
|
|
|
|
matWall=matLightDef(lightCell(0,0,0));
|
|
|
|
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;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1063,6 +1109,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);
|
|
|
@ -1080,3 +1127,4 @@ void lightingEngineViewscreen::loadSettings()
|
|
|
|
lua_pop(s,1);
|
|
|
|
lua_pop(s,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef GETLUAFLAG
|
|
|
|
#undef GETLUAFLAG
|
|
|
|
|
|
|
|
#undef GETLUANUMBER
|
|
|
|