From e1daa16d9e7063e922c8f2c14f0f83efe5de293d Mon Sep 17 00:00:00 2001 From: Warmist Date: Wed, 26 Jun 2013 22:05:22 +0300 Subject: [PATCH 1/2] Added sun time manipulation, updated helpstring. --- plugins/rendermax/renderer_light.cpp | 19 +++++++++++++++---- plugins/rendermax/renderer_light.hpp | 5 ++++- plugins/rendermax/rendermax.cpp | 21 ++++++++++++++++++++- plugins/rendermax/rendermax.lua | 2 +- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/plugins/rendermax/renderer_light.cpp b/plugins/rendermax/renderer_light.cpp index ab3910fd7..12cffb958 100644 --- a/plugins/rendermax/renderer_light.cpp +++ b/plugins/rendermax/renderer_light.cpp @@ -598,7 +598,12 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache& void lightingEngineViewscreen::doOcupancyAndLights() { // TODO better curve (+red dawn ?) - float daycol = 1;//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); lightSource sky(sky_col, 15); @@ -878,6 +883,10 @@ lightCell lua_parseLightCell(lua_State* L) if(lua_isnil(L,-1)){field=false;}\ else{lua_getfield(L,-1,#name);field=lua_isnil(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) { @@ -957,9 +966,9 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L) LOAD_SPECIAL(AMBIENT,matAmbience); LOAD_SPECIAL(CURSOR,matCursor); LOAD_SPECIAL(CITIZEN,matCitizen); - lua_getfield(L,-1,"LevelDim"); - if(!lua_isnil(L,-1) && lua_isnumber(L,-1))engine->levelDim=lua_tonumber(L,-1); - lua_pop(L,1); + GETLUANUMBER(engine->levelDim,levelDim); + GETLUANUMBER(engine->dayHour,dayHour); + return 0; } #undef LOAD_SPECIAL @@ -1025,6 +1034,7 @@ void lightingEngineViewscreen::defaultSettings() matWall=matLightDef(lightCell(0,0,0)); matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6); levelDim=0.2f; + dayHour=-1; } void lightingEngineViewscreen::loadSettings() { @@ -1080,3 +1090,4 @@ void lightingEngineViewscreen::loadSettings() lua_pop(s,1); } #undef GETLUAFLAG +#undef GETLUANUMBER \ No newline at end of file diff --git a/plugins/rendermax/renderer_light.hpp b/plugins/rendermax/renderer_light.hpp index 2e8b03c54..465d46ce0 100644 --- a/plugins/rendermax/renderer_light.hpp +++ b/plugins/rendermax/renderer_light.hpp @@ -78,6 +78,7 @@ public: virtual void loadSettings()=0; virtual void clear()=0; + virtual void setHour(float h)=0; protected: renderer_light* myRenderer; }; @@ -182,11 +183,13 @@ private: int nextIndex; std::vector threadList; void doLightThreads(); + //misc + void setHour(float h){dayHour=h;}; public: void lightWorkerThread(void * arg); private: //settings - + float dayHour; //<0 to cycle ///set up sane settings if setting file does not exist. void defaultSettings(); diff --git a/plugins/rendermax/rendermax.cpp b/plugins/rendermax/rendermax.cpp index 482dfa6cb..6a1b40890 100644 --- a/plugins/rendermax/rendermax.cpp +++ b/plugins/rendermax/rendermax.cpp @@ -20,6 +20,8 @@ #include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dungeonmodest.h" +#include + using df::viewscreen_dungeonmodest; using df::viewscreen_dwarfmodest; @@ -45,7 +47,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector |cycle - set time to x or cycle (same effect if x<0)\n" " rendermax disable\n" )); return CR_OK; @@ -366,6 +370,21 @@ static command_result rendermax(color_ostream &out, vector & parameters CoreSuspender suspend; engine->loadSettings(); } + else if(parameters[1]=="sun" && parameters.size()==3) + { + if(parameters[2]=="cycle") + { + engine->setHour(-1); + } + else + { + std::stringstream ss; + ss<>h; + engine->setHour(h); + } + } } else out.printerr("Light mode already enabled"); diff --git a/plugins/rendermax/rendermax.lua b/plugins/rendermax/rendermax.lua index ed790be48..4140a8068 100644 --- a/plugins/rendermax/rendermax.lua +++ b/plugins/rendermax/rendermax.lua @@ -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.CITIZEN=makeMaterialDef(nil,{0.80,0.80,0.90},6) special.LevelDim=0.2 -- darkness. Do not set to 0 +special.dayHour=-1 -- <0 cycle, else hour of the day --TODO dragonfire ---TODO daylight --materials From 7c9f0fd7810b5c2e356425f64dc48b71d947ce7d Mon Sep 17 00:00:00 2001 From: Warmist Date: Thu, 27 Jun 2013 00:14:03 +0300 Subject: [PATCH 2/2] Added day colors and day speed parameters. --- plugins/rendermax/renderer_light.cpp | 49 +++++++++++++++++++++++---- plugins/rendermax/renderer_light.hpp | 3 ++ plugins/rendermax/renderer_opengl.hpp | 4 +-- plugins/rendermax/rendermax.lua | 6 ++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/plugins/rendermax/renderer_light.cpp b/plugins/rendermax/renderer_light.cpp index 12cffb958..88ba41b71 100644 --- a/plugins/rendermax/renderer_light.cpp +++ b/plugins/rendermax/renderer_light.cpp @@ -275,7 +275,7 @@ bool lightingEngineViewscreen::lightUpCell(std::vector & target, ligh } if(ls.radius>0 && dsq>0) { - if(power12h 0->24h + daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h - lightCell sky_col(daycol, daycol, daycol); - lightSource sky(sky_col, 15); + 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 torch(lightCell(0.9f,0.75f,0.3f),8); @@ -968,7 +989,18 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L) LOAD_SPECIAL(CITIZEN,matCitizen); GETLUANUMBER(engine->levelDim,levelDim); 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; } #undef LOAD_SPECIAL @@ -1035,6 +1067,10 @@ void lightingEngineViewscreen::defaultSettings() matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6); 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() { @@ -1073,6 +1109,7 @@ void lightingEngineViewscreen::loadSettings() lua_pushlightuserdata(s, this); lua_pushvalue(s,env); Lua::SafeCall(out,s,2,0); + out.print("%d day light colors loaded\n",dayColors.size()); lua_pushcfunction(s, parseBuildings); lua_pushlightuserdata(s, this); diff --git a/plugins/rendermax/renderer_light.hpp b/plugins/rendermax/renderer_light.hpp index 465d46ce0..e5a9db787 100644 --- a/plugins/rendermax/renderer_light.hpp +++ b/plugins/rendermax/renderer_light.hpp @@ -188,8 +188,11 @@ private: public: void lightWorkerThread(void * arg); private: + lightCell getSkyColor(float v); //settings + float daySpeed; float dayHour; //<0 to cycle + std::vector dayColors; // a gradient of colors, first to 0, last to 24 ///set up sane settings if setting file does not exist. void defaultSettings(); diff --git a/plugins/rendermax/renderer_opengl.hpp b/plugins/rendermax/renderer_opengl.hpp index 57e81295b..8ba35f5ea 100644 --- a/plugins/rendermax/renderer_opengl.hpp +++ b/plugins/rendermax/renderer_opengl.hpp @@ -223,9 +223,9 @@ struct lightCell { return lightCell(r+other.r,g+other.g,b+other.b); } - bool operator<(const lightCell& other) const + bool operator<=(const lightCell& other) const { - return r1200 cur_year_ticks per day. 2->600 ticks --TODO dragonfire --materials