Bug fixes, perf improvement, don't load until there is a world. (breaks arena mode)

develop
Warmist 2013-07-03 10:44:23 +03:00
parent c2db761a1b
commit a3d3c34671
4 changed files with 46 additions and 18 deletions

@ -53,6 +53,8 @@ DFHack v0.34.11-r4
- outsideOnly: make raw-specified buildings impossible to build inside - outsideOnly: make raw-specified buildings impossible to build inside
- resume: A plugin to help display and resume suspended constructions conveniently - resume: A plugin to help display and resume suspended constructions conveniently
- stocks: An improved stocks display screen. - stocks: An improved stocks display screen.
- rendermax: a heap of rendering experiments. Including one that does lighting.
Internals: Internals:
- Core: there is now a per-save dfhack.init file for when the save is loaded, and another for when it is unloaded - Core: there is now a per-save dfhack.init file for when the save is loaded, and another for when it is unloaded
- EventManager: fixed job completion detection, fixed removal of TICK events, added EQUIPMENT_CHANGE event - EventManager: fixed job completion detection, fixed removal of TICK events, added EQUIPMENT_CHANGE event

@ -105,7 +105,6 @@ lightingEngineViewscreen::lightingEngineViewscreen(renderer_light* target):light
{ {
reinit(); reinit();
defaultSettings(); defaultSettings();
loadSettings();
int numTreads=tthread::thread::hardware_concurrency(); int numTreads=tthread::thread::hardware_concurrency();
if(numTreads==0)numTreads=1; if(numTreads==0)numTreads=1;
threading.start(numTreads); threading.start(numTreads);
@ -240,6 +239,11 @@ void lightingEngineViewscreen::clear()
} }
void lightingEngineViewscreen::calculate() void lightingEngineViewscreen::calculate()
{ {
if(lightMap.size()!=myRenderer->lightGrid.size())
{
reinit();
myRenderer->invalidate();
}
rect2d vp=getMapViewport(); rect2d vp=getMapViewport();
const rgbf dim(levelDim,levelDim,levelDim); const rgbf dim(levelDim,levelDim,levelDim);
lightMap.assign(lightMap.size(),rgbf(1,1,1)); lightMap.assign(lightMap.size(),rgbf(1,1,1));
@ -1035,8 +1039,7 @@ lightThread::lightThread( lightThreadDispatch& dispatch ):dispatch(dispatch),isD
} }
lightThread::~lightThread() lightThread::~lightThread()
{ {
if(myThread) delete myThread;
delete myThread;
} }
void lightThread::run() void lightThread::run()

@ -67,7 +67,7 @@ private:
void reinitLightGrid(int w,int h) void reinitLightGrid(int w,int h)
{ {
tthread::lock_guard<tthread::fast_mutex> guard(dataMutex); tthread::lock_guard<tthread::fast_mutex> guard(dataMutex);
lightGrid.resize(w*h); lightGrid.resize(w*h,rgbf(1,1,1));
} }
void reinitLightGrid() void reinitLightGrid()
{ {

@ -279,7 +279,41 @@ DFHACK_PLUGIN_LUA_COMMANDS {
DFHACK_LUA_END DFHACK_LUA_END
}; };
static void enable_hooks(bool enable)
{
INTERPOSE_HOOK(dwarmode_render_hook,render).apply(enable);
INTERPOSE_HOOK(dungeon_render_hook,render).apply(enable);
if(enable && engine)
{
engine->loadSettings();
}
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch(event)
{
case SC_VIEWSCREEN_CHANGED:
{
CoreSuspendClaimer suspender;
if(current_mode==MODE_LIGHT)
{
engine->clear();
}
}
break;
case SC_WORLD_LOADED:
enable_hooks(true);
break;
case SC_WORLD_UNLOADED:
enable_hooks(false);
break;
default:
break;
}
return CR_OK;
}
static command_result rendermax(color_ostream &out, vector <string> & parameters) static command_result rendermax(color_ostream &out, vector <string> & parameters)
@ -361,8 +395,9 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
renderer_light *myRender=new renderer_light(df::global::enabler->renderer); renderer_light *myRender=new renderer_light(df::global::enabler->renderer);
installNew(myRender,MODE_LIGHT); installNew(myRender,MODE_LIGHT);
engine=new lightingEngineViewscreen(myRender); engine=new lightingEngineViewscreen(myRender);
INTERPOSE_HOOK(dwarmode_render_hook,render).apply(true);
INTERPOSE_HOOK(dungeon_render_hook,render).apply(true); if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_WORLD_LOADED);
} }
else if(current_mode==MODE_LIGHT && parameters.size()>1) else if(current_mode==MODE_LIGHT && parameters.size()>1)
{ {
@ -417,15 +452,3 @@ DFhackCExport command_result plugin_shutdown(color_ostream &)
removeOld(); removeOld();
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
if(event==SC_VIEWSCREEN_CHANGED)
{
CoreSuspendClaimer suspender;
if(current_mode==MODE_LIGHT)
{
engine->clear();
}
}
return CR_OK;
}