Added sun time manipulation, updated helpstring.

develop
Warmist 2013-06-26 22:05:22 +03:00
parent 7c0a734c97
commit 70880897f6
4 changed files with 40 additions and 7 deletions

@ -600,7 +600,12 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
void lightingEngineViewscreen::doOcupancyAndLights() void lightingEngineViewscreen::doOcupancyAndLights()
{ {
// TODO better curve (+red dawn ?) // TODO better curve (+red dawn ?)
float daycol = 0;//abs((*df::global::cur_year_tick % 1200) - 600.0) / 400.0; float daycol;
if(dayHour<0)
daycol= abs((*df::global::cur_year_tick % 1200) - 600.0) / 600.0;
else
daycol= abs(fmod(dayHour+12.0f,24.0f)-12.0f)/12.0f; //1->12h 0->24h
lightCell sky_col(daycol, daycol, daycol); lightCell sky_col(daycol, daycol, daycol);
lightSource sky(sky_col, 15); lightSource sky(sky_col, 15);
@ -880,6 +885,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)
{ {
@ -959,9 +968,9 @@ 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);
return 0; return 0;
} }
#undef LOAD_SPECIAL #undef LOAD_SPECIAL
@ -1027,6 +1036,7 @@ 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;
} }
void lightingEngineViewscreen::loadSettings() void lightingEngineViewscreen::loadSettings()
{ {
@ -1082,3 +1092,4 @@ void lightingEngineViewscreen::loadSettings()
lua_pop(s,1); lua_pop(s,1);
} }
#undef GETLUAFLAG #undef GETLUAFLAG
#undef GETLUANUMBER

@ -78,6 +78,7 @@ public:
virtual void loadSettings()=0; virtual void loadSettings()=0;
virtual void clear()=0; virtual void clear()=0;
virtual void setHour(float h)=0;
protected: protected:
renderer_light* myRenderer; renderer_light* myRenderer;
}; };
@ -182,11 +183,13 @@ private:
int nextIndex; int nextIndex;
std::vector<tthread::thread *> threadList; std::vector<tthread::thread *> threadList;
void doLightThreads(); void doLightThreads();
//misc
void setHour(float h){dayHour=h;};
public: public:
void lightWorkerThread(void * arg); void lightWorkerThread(void * arg);
private: private:
//settings //settings
float dayHour; //<0 to cycle
///set up sane settings if setting file does not exist. ///set up sane settings if setting file does not exist.
void defaultSettings(); void defaultSettings();

@ -20,6 +20,8 @@
#include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_dungeonmodest.h" #include "df/viewscreen_dungeonmodest.h"
#include <sstream>
using df::viewscreen_dungeonmodest; using df::viewscreen_dungeonmodest;
using df::viewscreen_dwarfmodest; using df::viewscreen_dwarfmodest;
@ -45,7 +47,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" rendermax trippy\n" " rendermax trippy\n"
" rendermax truecolor red|green|blue|white\n" " rendermax truecolor red|green|blue|white\n"
" rendermax lua\n" " rendermax lua\n"
" rendermax light\n" " rendermax light - lighting engine\n"
" rendermax light reload - reload the settings file\n"
" rendermax light sun <x>|cycle - set time to x or cycle (same effect if x<0)\n"
" rendermax disable\n" " rendermax disable\n"
)); ));
return CR_OK; return CR_OK;
@ -366,6 +370,21 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
CoreSuspender suspend; CoreSuspender suspend;
engine->loadSettings(); engine->loadSettings();
} }
else if(parameters[1]=="sun" && parameters.size()==3)
{
if(parameters[2]=="cycle")
{
engine->setHour(-1);
}
else
{
std::stringstream ss;
ss<<parameters[2];
float h;
ss>>h;
engine->setHour(h);
}
}
} }
else else
out.printerr("Light mode already enabled"); out.printerr("Light mode already enabled");

@ -104,8 +104,8 @@ special.AMBIENT=makeMaterialDef({0.85,0.85,0.85}) --ambient fog
special.CURSOR=makeMaterialDef({1,1,1},{0.96,0.84,0.03},11, {"flicker"}) 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
--TODO dragonfire --TODO dragonfire
--TODO daylight
--materials --materials