From 354ec370468a3b3b5ad9b8ff1550e8d4473455c9 Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 25 Jun 2013 20:36:53 +0300 Subject: [PATCH] MAXIMUM SPEED UPDATE!!!!! --- plugins/rendermax/renderer_light.cpp | 14 ++++- plugins/rendermax/renderer_light.hpp | 2 + plugins/rendermax/renderer_opengl.hpp | 6 +- plugins/rendermax/rendermax.cpp | 87 ++++++++++++++++++++------- plugins/rendermax/rendermax.lua | 4 +- 5 files changed, 83 insertions(+), 30 deletions(-) diff --git a/plugins/rendermax/renderer_light.cpp b/plugins/rendermax/renderer_light.cpp index fe5396f14..35bc047b4 100644 --- a/plugins/rendermax/renderer_light.cpp +++ b/plugins/rendermax/renderer_light.cpp @@ -239,6 +239,16 @@ void lightingEngineViewscreen::doFovs() } } } +void lightingEngineViewscreen::clear() +{ + lightMap.assign(lightMap.size(),lightCell(1,1,1)); + tthread::lock_guard guard(myRenderer->dataMutex); + if(lightMap.size()==myRenderer->lightGrid.size()) + { + std::swap(myRenderer->lightGrid,lightMap); + myRenderer->invalidate(); + } +} void lightingEngineViewscreen::calculate() { rect2d vp=getMapViewport(); @@ -270,8 +280,8 @@ void lightingEngineViewscreen::updateWindow() std::swap(lightMap,myRenderer->lightGrid); rect2d vp=getMapViewport(); - //myRenderer->invalidateRect(vp.first.x,vp.first.y,vp.second.x-vp.first.x,vp.second.y-vp.first.y); - myRenderer->invalidate(); + myRenderer->invalidateRect(vp.first.x,vp.first.y,vp.second.x-vp.first.x,vp.second.y-vp.first.y); + //myRenderer->invalidate(); //std::copy(lightMap.begin(),lightMap.end(),myRenderer->lightGrid.begin()); } diff --git a/plugins/rendermax/renderer_light.hpp b/plugins/rendermax/renderer_light.hpp index 307cf465b..e3122a8ca 100644 --- a/plugins/rendermax/renderer_light.hpp +++ b/plugins/rendermax/renderer_light.hpp @@ -75,6 +75,7 @@ public: virtual void updateWindow()=0; virtual void loadSettings()=0; + virtual void clear()=0; protected: renderer_light* myRenderer; @@ -130,6 +131,7 @@ public: void updateWindow(); void loadSettings(); + void clear(); private: df::coord2d worldToViewportCoord(const df::coord2d& in,const DFHack::rect2d& r,const df::coord2d& window2d) ; diff --git a/plugins/rendermax/renderer_opengl.hpp b/plugins/rendermax/renderer_opengl.hpp index 6beba522f..57e81295b 100644 --- a/plugins/rendermax/renderer_opengl.hpp +++ b/plugins/rendermax/renderer_opengl.hpp @@ -124,13 +124,13 @@ public: for(int j=y;jdimy + j; - screen_old[index*4]=0; + screen_old[index*4]=screen[index*4]+1;//ensure tile is different } }; void invalidate() { - //invalidateRect(0,0,df::global::gps->dimx,df::global::gps->dimy); - df::global::gps->force_full_display_count++; + invalidateRect(0,0,df::global::gps->dimx,df::global::gps->dimy); + //df::global::gps->force_full_display_count++; }; protected: renderer* parent; diff --git a/plugins/rendermax/rendermax.cpp b/plugins/rendermax/rendermax.cpp index dda0d5d2c..482dfa6cb 100644 --- a/plugins/rendermax/rendermax.cpp +++ b/plugins/rendermax/rendermax.cpp @@ -3,6 +3,8 @@ #include +#include + #include "Core.h" #include "Console.h" #include "Export.h" @@ -15,12 +17,18 @@ #include "renderer_opengl.hpp" #include "renderer_light.hpp" +#include "df/viewscreen_dwarfmodest.h" +#include "df/viewscreen_dungeonmodest.h" + +using df::viewscreen_dungeonmodest; +using df::viewscreen_dwarfmodest; + using namespace DFHack; using std::vector; using std::string; enum RENDERER_MODE { - MODE_DEFAULT,MODE_TRIPPY,MODE_TRUECOLOR,MODE_LUA,MODE_LIGHT,MODE_LIGHT_OFF + MODE_DEFAULT,MODE_TRIPPY,MODE_TRUECOLOR,MODE_LUA,MODE_LIGHT }; RENDERER_MODE current_mode=MODE_DEFAULT; lightingEngine *engine=NULL; @@ -42,10 +50,44 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector calculate(); + engine->updateWindow(); + } +}; +IMPLEMENT_VMETHOD_INTERPOSE(dwarmode_render_hook, render); + +struct dungeon_render_hook : viewscreen_dungeonmodest{ + typedef df::viewscreen_dungeonmodest interpose_base; + DEFINE_VMETHOD_INTERPOSE(void,render,()) + { + CoreSuspendClaimer suspend; + INTERPOSE_NEXT(render)(); + engine->calculate(); + engine->updateWindow(); + } +}; +IMPLEMENT_VMETHOD_INTERPOSE(dungeon_render_hook, render); + void removeOld() { + if(engine) + { + CoreSuspender lock; + INTERPOSE_HOOK(dwarmode_render_hook,render).apply(false); + INTERPOSE_HOOK(dungeon_render_hook,render).apply(false); + delete engine; + + } if(current_mode!=MODE_DEFAULT) delete df::global::enabler->renderer; + current_mode=MODE_DEFAULT; } void installNew(df::renderer* r,RENDERER_MODE newMode) @@ -231,6 +273,10 @@ DFHACK_PLUGIN_LUA_COMMANDS { DFHACK_LUA_COMMAND(invalidate), DFHACK_LUA_END }; + + + + static command_result rendermax(color_ostream &out, vector & parameters) { if(parameters.size()==0) @@ -304,19 +350,22 @@ static command_result rendermax(color_ostream &out, vector & parameters } else if(cmd=="light") { - if(current_mode!=MODE_LIGHT || current_mode!=MODE_LIGHT_OFF) + if(current_mode!=MODE_LIGHT) { removeOld(); renderer_light *myRender=new renderer_light(df::global::enabler->renderer); installNew(myRender,MODE_LIGHT); engine=new lightingEngineViewscreen(myRender); - engine->calculate(); - engine->updateWindow(); + INTERPOSE_HOOK(dwarmode_render_hook,render).apply(true); + INTERPOSE_HOOK(dungeon_render_hook,render).apply(true); } else if(current_mode==MODE_LIGHT && parameters.size()>1) { if(parameters[1]=="reload") + { + CoreSuspender suspend; engine->loadSettings(); + } } else out.printerr("Light mode already enabled"); @@ -327,8 +376,6 @@ static command_result rendermax(color_ostream &out, vector & parameters { if(current_mode==MODE_DEFAULT) out.print("%s\n","Not installed, doing nothing."); - else if(current_mode==MODE_LIGHT) - current_mode=MODE_LIGHT_OFF; else removeOld(); @@ -336,27 +383,21 @@ static command_result rendermax(color_ostream &out, vector & parameters } return CR_WRONG_USAGE; } -DFhackCExport command_result plugin_onupdate (color_ostream &out) + +DFhackCExport command_result plugin_shutdown(color_ostream &) +{ + removeOld(); + return CR_OK; +} +DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { - if(engine) + if(event==SC_VIEWSCREEN_CHANGED) { - if(current_mode==MODE_LIGHT_OFF) + CoreSuspendClaimer suspender; + if(current_mode==MODE_LIGHT) { - delete engine; - engine=0; - removeOld(); - } - else - { - engine->calculate(); - engine->updateWindow(); + engine->clear(); } } - - return CR_OK; -} -DFhackCExport command_result plugin_shutdown(color_ostream &) -{ - removeOld(); return CR_OK; } \ No newline at end of file diff --git a/plugins/rendermax/rendermax.lua b/plugins/rendermax/rendermax.lua index 86d4a2fe7..4b19e2485 100644 --- a/plugins/rendermax/rendermax.lua +++ b/plugins/rendermax/rendermax.lua @@ -49,8 +49,8 @@ special.WATER=makeMaterialDef({0.5,0.5,0.8}) special.FROZEN_LIQUID=makeMaterialDef({0.2,0.7,0.9}) -- ice 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.80f,0.80f,0.90f},6) -special.LevelDim=0.2 -- darkness. do not set to 0 +special.CITIZEN=makeMaterialDef(nil,{0.80,0.80,0.90},6) +special.LevelDim=0.2 -- darkness. Do not set to 0 --TODO dragonfire --TODO daylight --materials