MAXIMUM SPEED UPDATE!!!!!

develop
Warmist 2013-06-25 20:36:53 +03:00
parent 3957fac531
commit 588ca8b8dd
5 changed files with 83 additions and 30 deletions

@ -209,6 +209,16 @@ void lightingEngineViewscreen::doFovs()
} }
} }
} }
void lightingEngineViewscreen::clear()
{
lightMap.assign(lightMap.size(),lightCell(1,1,1));
tthread::lock_guard<tthread::fast_mutex> guard(myRenderer->dataMutex);
if(lightMap.size()==myRenderer->lightGrid.size())
{
std::swap(myRenderer->lightGrid,lightMap);
myRenderer->invalidate();
}
}
void lightingEngineViewscreen::calculate() void lightingEngineViewscreen::calculate()
{ {
rect2d vp=getMapViewport(); rect2d vp=getMapViewport();
@ -240,8 +250,8 @@ void lightingEngineViewscreen::updateWindow()
std::swap(lightMap,myRenderer->lightGrid); std::swap(lightMap,myRenderer->lightGrid);
rect2d vp=getMapViewport(); rect2d vp=getMapViewport();
//myRenderer->invalidateRect(vp.first.x,vp.first.y,vp.second.x-vp.first.x,vp.second.y-vp.first.y); myRenderer->invalidateRect(vp.first.x,vp.first.y,vp.second.x-vp.first.x,vp.second.y-vp.first.y);
myRenderer->invalidate(); //myRenderer->invalidate();
//std::copy(lightMap.begin(),lightMap.end(),myRenderer->lightGrid.begin()); //std::copy(lightMap.begin(),lightMap.end(),myRenderer->lightGrid.begin());
} }
void lightSource::combine(const lightSource& other) void lightSource::combine(const lightSource& other)

@ -75,6 +75,7 @@ public:
virtual void updateWindow()=0; virtual void updateWindow()=0;
virtual void loadSettings()=0; virtual void loadSettings()=0;
virtual void clear()=0;
protected: protected:
renderer_light* myRenderer; renderer_light* myRenderer;
@ -133,6 +134,7 @@ public:
void updateWindow(); void updateWindow();
void loadSettings(); void loadSettings();
void clear();
private: private:
df::coord2d worldToViewportCoord(const df::coord2d& in,const DFHack::rect2d& r,const df::coord2d& window2d) ; df::coord2d worldToViewportCoord(const df::coord2d& in,const DFHack::rect2d& r,const df::coord2d& window2d) ;

@ -124,13 +124,13 @@ public:
for(int j=y;j<y+h;j++) for(int j=y;j<y+h;j++)
{ {
int index=i*df::global::gps->dimy + j; int index=i*df::global::gps->dimy + j;
screen_old[index*4]=0; screen_old[index*4]=screen[index*4]+1;//ensure tile is different
} }
}; };
void invalidate() void invalidate()
{ {
//invalidateRect(0,0,df::global::gps->dimx,df::global::gps->dimy); invalidateRect(0,0,df::global::gps->dimx,df::global::gps->dimy);
df::global::gps->force_full_display_count++; //df::global::gps->force_full_display_count++;
}; };
protected: protected:
renderer* parent; renderer* parent;

@ -3,6 +3,8 @@
#include <LuaTools.h> #include <LuaTools.h>
#include <VTableInterpose.h>
#include "Core.h" #include "Core.h"
#include "Console.h" #include "Console.h"
#include "Export.h" #include "Export.h"
@ -15,12 +17,18 @@
#include "renderer_opengl.hpp" #include "renderer_opengl.hpp"
#include "renderer_light.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 namespace DFHack;
using std::vector; using std::vector;
using std::string; using std::string;
enum RENDERER_MODE 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; RENDERER_MODE current_mode=MODE_DEFAULT;
lightingEngine *engine=NULL; lightingEngine *engine=NULL;
@ -42,10 +50,44 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
)); ));
return CR_OK; return CR_OK;
} }
struct dwarmode_render_hook : viewscreen_dwarfmodest{
typedef df::viewscreen_dwarfmodest interpose_base;
DEFINE_VMETHOD_INTERPOSE(void,render,())
{
CoreSuspendClaimer suspend;
INTERPOSE_NEXT(render)();
engine->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() 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) if(current_mode!=MODE_DEFAULT)
delete df::global::enabler->renderer; delete df::global::enabler->renderer;
current_mode=MODE_DEFAULT; current_mode=MODE_DEFAULT;
} }
void installNew(df::renderer* r,RENDERER_MODE newMode) void installNew(df::renderer* r,RENDERER_MODE newMode)
@ -231,6 +273,10 @@ DFHACK_PLUGIN_LUA_COMMANDS {
DFHACK_LUA_COMMAND(invalidate), DFHACK_LUA_COMMAND(invalidate),
DFHACK_LUA_END DFHACK_LUA_END
}; };
static command_result rendermax(color_ostream &out, vector <string> & parameters) static command_result rendermax(color_ostream &out, vector <string> & parameters)
{ {
if(parameters.size()==0) if(parameters.size()==0)
@ -304,19 +350,22 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
} }
else if(cmd=="light") else if(cmd=="light")
{ {
if(current_mode!=MODE_LIGHT || current_mode!=MODE_LIGHT_OFF) if(current_mode!=MODE_LIGHT)
{ {
removeOld(); removeOld();
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);
engine->calculate(); INTERPOSE_HOOK(dwarmode_render_hook,render).apply(true);
engine->updateWindow(); INTERPOSE_HOOK(dungeon_render_hook,render).apply(true);
} }
else if(current_mode==MODE_LIGHT && parameters.size()>1) else if(current_mode==MODE_LIGHT && parameters.size()>1)
{ {
if(parameters[1]=="reload") if(parameters[1]=="reload")
{
CoreSuspender suspend;
engine->loadSettings(); engine->loadSettings();
}
} }
else else
out.printerr("Light mode already enabled"); out.printerr("Light mode already enabled");
@ -327,8 +376,6 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
{ {
if(current_mode==MODE_DEFAULT) if(current_mode==MODE_DEFAULT)
out.print("%s\n","Not installed, doing nothing."); out.print("%s\n","Not installed, doing nothing.");
else if(current_mode==MODE_LIGHT)
current_mode=MODE_LIGHT_OFF;
else else
removeOld(); removeOld();
@ -336,27 +383,21 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
} }
return CR_WRONG_USAGE; 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->clear();
engine=0;
removeOld();
}
else
{
engine->calculate();
engine->updateWindow();
} }
} }
return CR_OK;
}
DFhackCExport command_result plugin_shutdown(color_ostream &)
{
removeOld();
return CR_OK; return CR_OK;
} }

@ -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.FROZEN_LIQUID=makeMaterialDef({0.2,0.7,0.9}) -- ice
special.AMBIENT=makeMaterialDef({0.85,0.85,0.85}) --ambient fog 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.80f,0.80f,0.90f},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
--TODO dragonfire --TODO dragonfire
--TODO daylight --TODO daylight
--materials --materials