2020-05-04 16:38:54 -06:00
|
|
|
#include <mutex>
|
|
|
|
#include <sstream>
|
2013-06-22 04:29:58 -06:00
|
|
|
#include <string>
|
2020-05-04 16:38:54 -06:00
|
|
|
#include <vector>
|
2013-06-22 04:29:58 -06:00
|
|
|
|
|
|
|
#include "Console.h"
|
2020-05-04 16:38:54 -06:00
|
|
|
#include "Core.h"
|
2013-06-22 04:29:58 -06:00
|
|
|
#include "Export.h"
|
2020-05-04 16:38:54 -06:00
|
|
|
#include "LuaTools.h"
|
2013-06-22 04:29:58 -06:00
|
|
|
#include "PluginManager.h"
|
2020-05-04 16:38:54 -06:00
|
|
|
#include "VTableInterpose.h"
|
2013-06-22 04:29:58 -06:00
|
|
|
|
|
|
|
#include "df/enabler.h"
|
2020-05-04 16:38:54 -06:00
|
|
|
#include "df/renderer.h"
|
|
|
|
#include "df/viewscreen_dungeonmodest.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
2013-06-22 04:29:58 -06:00
|
|
|
|
|
|
|
#include "renderer_opengl.hpp"
|
2013-06-23 10:25:42 -06:00
|
|
|
#include "renderer_light.hpp"
|
2013-06-22 04:29:58 -06:00
|
|
|
|
2013-06-25 11:36:53 -06:00
|
|
|
using df::viewscreen_dungeonmodest;
|
|
|
|
using df::viewscreen_dwarfmodest;
|
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
2014-12-06 16:47:35 -07:00
|
|
|
|
|
|
|
DFHACK_PLUGIN("rendermax");
|
|
|
|
REQUIRE_GLOBAL(cur_year_tick);
|
|
|
|
REQUIRE_GLOBAL(cursor);
|
|
|
|
REQUIRE_GLOBAL(enabler);
|
|
|
|
REQUIRE_GLOBAL(gametype);
|
|
|
|
REQUIRE_GLOBAL(gps);
|
2023-01-05 18:11:01 -07:00
|
|
|
REQUIRE_GLOBAL(plotinfo);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(window_x);
|
|
|
|
REQUIRE_GLOBAL(window_y);
|
|
|
|
REQUIRE_GLOBAL(window_z);
|
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
enum RENDERER_MODE
|
|
|
|
{
|
2013-06-25 11:36:53 -06:00
|
|
|
MODE_DEFAULT,MODE_TRIPPY,MODE_TRUECOLOR,MODE_LUA,MODE_LIGHT
|
2013-06-22 04:29:58 -06:00
|
|
|
};
|
|
|
|
RENDERER_MODE current_mode=MODE_DEFAULT;
|
2013-06-23 10:25:42 -06:00
|
|
|
lightingEngine *engine=NULL;
|
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
static command_result rendermax(color_ostream &out, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand(
|
2022-07-29 17:31:37 -06:00
|
|
|
"rendermax",
|
|
|
|
"Modify the map lighting.",
|
|
|
|
rendermax));
|
2013-06-22 04:29:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2013-06-25 11:36:53 -06:00
|
|
|
|
|
|
|
struct dwarmode_render_hook : viewscreen_dwarfmodest{
|
|
|
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void,render,())
|
|
|
|
{
|
|
|
|
CoreSuspendClaimer suspend;
|
2014-02-14 02:50:12 -07:00
|
|
|
engine->preRender();
|
2013-06-25 11:36:53 -06:00
|
|
|
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;
|
2014-02-14 02:50:12 -07:00
|
|
|
engine->preRender();
|
2013-06-25 11:36:53 -06:00
|
|
|
INTERPOSE_NEXT(render)();
|
|
|
|
engine->calculate();
|
|
|
|
engine->updateWindow();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(dungeon_render_hook, render);
|
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
void removeOld()
|
|
|
|
{
|
2014-01-25 16:11:26 -07:00
|
|
|
CoreSuspender lock;
|
2013-06-25 11:36:53 -06:00
|
|
|
if(engine)
|
|
|
|
{
|
|
|
|
INTERPOSE_HOOK(dwarmode_render_hook,render).apply(false);
|
|
|
|
INTERPOSE_HOOK(dungeon_render_hook,render).apply(false);
|
|
|
|
delete engine;
|
2013-06-30 13:03:07 -06:00
|
|
|
engine=0;
|
2013-06-25 11:36:53 -06:00
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
if(current_mode!=MODE_DEFAULT)
|
2014-12-06 16:47:35 -07:00
|
|
|
delete enabler->renderer;
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
current_mode=MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
void installNew(df::renderer* r,RENDERER_MODE newMode)
|
|
|
|
{
|
2014-12-06 16:47:35 -07:00
|
|
|
enabler->renderer=r;
|
2013-06-22 04:29:58 -06:00
|
|
|
current_mode=newMode;
|
|
|
|
}
|
2013-06-22 08:40:52 -06:00
|
|
|
static void lockGrids()
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return ;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-22 08:40:52 -06:00
|
|
|
r->dataMutex.lock();
|
|
|
|
}
|
|
|
|
static void unlockGrids()
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return ;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-22 08:40:52 -06:00
|
|
|
r->dataMutex.unlock();
|
|
|
|
}
|
|
|
|
static void resetGrids()
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return ;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-22 08:40:52 -06:00
|
|
|
for(size_t i=0;i<r->foreMult.size();i++)
|
|
|
|
{
|
2013-06-30 06:05:59 -06:00
|
|
|
r->foreMult[i]=rgbf(1,1,1);
|
|
|
|
r->foreOffset[i]=rgbf(0,0,0);
|
|
|
|
r->backMult[i]=rgbf(1,1,1);
|
|
|
|
r->backOffset[i]=rgbf(0,0,0);
|
2013-06-22 08:40:52 -06:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 00:19:29 -06:00
|
|
|
static int getGridsSize(lua_State* L)
|
2013-06-22 08:40:52 -06:00
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return -1;
|
2014-12-06 16:47:35 -07:00
|
|
|
lua_pushnumber(L,gps->dimx);
|
|
|
|
lua_pushnumber(L,gps->dimy);
|
2013-06-22 08:40:52 -06:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
static int getCell(lua_State* L)
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return 0;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-22 08:40:52 -06:00
|
|
|
int x=luaL_checknumber(L,1);
|
|
|
|
int y=luaL_checknumber(L,2);
|
|
|
|
int id=r->xyToTile(x,y);
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf fo=r->foreOffset[id];
|
|
|
|
rgbf fm=r->foreMult[id];
|
|
|
|
rgbf bo=r->backOffset[id];
|
|
|
|
rgbf bm=r->backMult[id];
|
2013-06-22 08:40:52 -06:00
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L,fo.r);
|
|
|
|
lua_setfield(L,-2,"r");
|
|
|
|
lua_pushnumber(L,fo.g);
|
|
|
|
lua_setfield(L,-2,"g");
|
|
|
|
lua_pushnumber(L,fo.b);
|
|
|
|
lua_setfield(L,-2,"b");
|
|
|
|
lua_setfield(L,-2,"fo");
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L,fm.r);
|
|
|
|
lua_setfield(L,-2,"r");
|
|
|
|
lua_pushnumber(L,fm.g);
|
|
|
|
lua_setfield(L,-2,"g");
|
|
|
|
lua_pushnumber(L,fm.b);
|
|
|
|
lua_setfield(L,-2,"b");
|
|
|
|
lua_setfield(L,-2,"fm");
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L,bo.r);
|
|
|
|
lua_setfield(L,-2,"r");
|
|
|
|
lua_pushnumber(L,bo.g);
|
|
|
|
lua_setfield(L,-2,"g");
|
|
|
|
lua_pushnumber(L,bo.b);
|
|
|
|
lua_setfield(L,-2,"b");
|
|
|
|
lua_setfield(L,-2,"bo");
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L,bm.r);
|
|
|
|
lua_setfield(L,-2,"r");
|
|
|
|
lua_pushnumber(L,bm.g);
|
|
|
|
lua_setfield(L,-2,"g");
|
|
|
|
lua_pushnumber(L,bm.b);
|
|
|
|
lua_setfield(L,-2,"b");
|
|
|
|
lua_setfield(L,-2,"bm");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static int setCell(lua_State* L)
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return 0;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-22 08:40:52 -06:00
|
|
|
int x=luaL_checknumber(L,1);
|
|
|
|
int y=luaL_checknumber(L,2);
|
|
|
|
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf fo;
|
2013-06-22 08:40:52 -06:00
|
|
|
lua_getfield(L,3,"fo");
|
|
|
|
lua_getfield(L,-1,"r");
|
|
|
|
fo.r=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"g");
|
|
|
|
fo.g=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"b");
|
|
|
|
fo.b=lua_tonumber(L,-1);lua_pop(L,1);
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf fm;
|
2013-06-22 08:40:52 -06:00
|
|
|
lua_getfield(L,3,"fm");
|
|
|
|
lua_getfield(L,-1,"r");
|
|
|
|
fm.r=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"g");
|
|
|
|
fm.g=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"b");
|
|
|
|
fm.b=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf bo;
|
2013-06-22 08:40:52 -06:00
|
|
|
lua_getfield(L,3,"bo");
|
|
|
|
lua_getfield(L,-1,"r");
|
|
|
|
bo.r=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"g");
|
|
|
|
bo.g=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"b");
|
|
|
|
bo.b=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf bm;
|
2013-06-22 08:40:52 -06:00
|
|
|
lua_getfield(L,3,"bm");
|
|
|
|
lua_getfield(L,-1,"r");
|
|
|
|
bm.r=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"g");
|
|
|
|
bm.g=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,-1,"b");
|
|
|
|
bm.b=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
int id=r->xyToTile(x,y);
|
|
|
|
r->foreMult[id]=fm;
|
|
|
|
r->foreOffset[id]=fo;
|
|
|
|
r->backMult[id]=bm;
|
|
|
|
r->backOffset[id]=bo;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-23 03:20:35 -06:00
|
|
|
static int invalidate(lua_State* L)
|
|
|
|
{
|
|
|
|
if(current_mode!=MODE_LUA)
|
|
|
|
return 0;
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_lua* r=reinterpret_cast<renderer_lua*>(enabler->renderer);
|
2013-06-23 03:20:35 -06:00
|
|
|
if(lua_gettop(L)==0)
|
|
|
|
{
|
|
|
|
r->invalidate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x,y,w,h;
|
|
|
|
lua_getfield(L,1,"x");
|
|
|
|
x=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,1,"y");
|
|
|
|
y=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,1,"w");
|
|
|
|
w=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
lua_getfield(L,1,"h");
|
|
|
|
h=lua_tonumber(L,-1);lua_pop(L,1);
|
|
|
|
r->invalidateRect(x,y,w,h);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-22 08:40:52 -06:00
|
|
|
bool isEnabled()
|
|
|
|
{
|
|
|
|
return current_mode==MODE_LUA;
|
|
|
|
}
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
DFHACK_LUA_FUNCTION(isEnabled),
|
|
|
|
DFHACK_LUA_FUNCTION(lockGrids),
|
|
|
|
DFHACK_LUA_FUNCTION(unlockGrids),
|
|
|
|
DFHACK_LUA_FUNCTION(resetGrids),
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|
|
|
|
DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
DFHACK_LUA_COMMAND(getCell),
|
|
|
|
DFHACK_LUA_COMMAND(setCell),
|
2013-06-23 00:19:29 -06:00
|
|
|
DFHACK_LUA_COMMAND(getGridsSize),
|
2013-06-23 03:20:35 -06:00
|
|
|
DFHACK_LUA_COMMAND(invalidate),
|
2013-06-22 08:40:52 -06:00
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|
2013-06-25 11:36:53 -06:00
|
|
|
|
2013-07-03 01:44:23 -06:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 11:36:53 -06:00
|
|
|
|
2013-07-03 01:44:23 -06:00
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
2013-07-03 09:47:51 -06:00
|
|
|
if(current_mode!=MODE_LIGHT)
|
|
|
|
return CR_OK;
|
2013-07-03 01:44:23 -06:00
|
|
|
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;
|
|
|
|
}
|
2013-06-25 11:36:53 -06:00
|
|
|
|
|
|
|
|
2013-06-22 04:29:58 -06:00
|
|
|
static command_result rendermax(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
if(parameters.size()==0)
|
|
|
|
return CR_WRONG_USAGE;
|
2014-12-06 16:47:35 -07:00
|
|
|
if(!enabler->renderer->uses_opengl())
|
2013-06-23 14:56:01 -06:00
|
|
|
{
|
2022-07-29 17:31:37 -06:00
|
|
|
out.printerr("Sorry, this plugin needs open GL-enabled printmode. Try STANDARD or other non-2D.\n");
|
2013-06-23 14:56:01 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
string cmd=parameters[0];
|
|
|
|
if(cmd=="trippy")
|
|
|
|
{
|
|
|
|
removeOld();
|
2014-12-06 16:47:35 -07:00
|
|
|
installNew(new renderer_trippy(enabler->renderer),MODE_TRIPPY);
|
2013-06-22 04:29:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2013-06-22 05:14:35 -06:00
|
|
|
else if(cmd=="truecolor")
|
2013-06-22 04:29:58 -06:00
|
|
|
{
|
2013-06-22 05:14:35 -06:00
|
|
|
if(current_mode!=MODE_TRUECOLOR)
|
|
|
|
{
|
|
|
|
removeOld();
|
2014-12-06 16:47:35 -07:00
|
|
|
installNew(new renderer_test(enabler->renderer),MODE_TRUECOLOR);
|
2013-06-22 05:14:35 -06:00
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
if(current_mode==MODE_TRUECOLOR && parameters.size()==2)
|
|
|
|
{
|
2013-06-30 06:05:59 -06:00
|
|
|
rgbf red(1,0,0),green(0,1,0),blue(0,0,1),white(1,1,1);
|
|
|
|
rgbf cur=white;
|
|
|
|
rgbf dim(0.2f,0.2f,0.2f);
|
2013-06-22 05:14:35 -06:00
|
|
|
string col=parameters[1];
|
|
|
|
if(col=="red")
|
|
|
|
cur=red;
|
|
|
|
else if(col=="green")
|
|
|
|
cur=green;
|
|
|
|
else if(col=="blue")
|
|
|
|
cur=blue;
|
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_test* r=reinterpret_cast<renderer_test*>(enabler->renderer);
|
2020-05-04 16:38:54 -06:00
|
|
|
std::lock_guard<std::mutex> guard{r->dataMutex};
|
2014-12-06 16:47:35 -07:00
|
|
|
int h=gps->dimy;
|
|
|
|
int w=gps->dimx;
|
2013-06-22 04:29:58 -06:00
|
|
|
int cx=w/2;
|
|
|
|
int cy=h/2;
|
|
|
|
int rad=cx;
|
|
|
|
if(rad>cy)rad=cy;
|
|
|
|
rad/=2;
|
|
|
|
int radsq=rad*rad;
|
2013-06-22 05:14:35 -06:00
|
|
|
for(size_t i=0;i<r->lightGrid.size();i++)
|
|
|
|
{
|
|
|
|
r->lightGrid[i]=dim;
|
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
for(int i=-rad;i<rad;i++)
|
|
|
|
for(int j=-rad;j<rad;j++)
|
|
|
|
{
|
|
|
|
if((i*i+j*j)<radsq)
|
2013-06-22 05:14:35 -06:00
|
|
|
{
|
|
|
|
float val=(radsq-i*i-j*j)/(float)radsq;
|
|
|
|
r->lightGrid[(cx+i)*h+(cy+j)]=dim+cur*val;
|
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2013-06-22 08:40:52 -06:00
|
|
|
}
|
|
|
|
else if(cmd=="lua")
|
|
|
|
{
|
|
|
|
removeOld();
|
2014-12-06 16:47:35 -07:00
|
|
|
installNew(new renderer_lua(enabler->renderer),MODE_LUA);
|
2013-06-22 08:40:52 -06:00
|
|
|
lockGrids();
|
|
|
|
resetGrids();
|
|
|
|
unlockGrids();
|
|
|
|
return CR_OK;
|
2013-06-22 04:29:58 -06:00
|
|
|
}
|
2013-06-23 10:25:42 -06:00
|
|
|
else if(cmd=="light")
|
|
|
|
{
|
2013-06-25 11:36:53 -06:00
|
|
|
if(current_mode!=MODE_LIGHT)
|
2013-06-24 09:18:57 -06:00
|
|
|
{
|
|
|
|
removeOld();
|
2014-12-06 16:47:35 -07:00
|
|
|
renderer_light *myRender=new renderer_light(enabler->renderer);
|
2013-06-24 09:18:57 -06:00
|
|
|
installNew(myRender,MODE_LIGHT);
|
|
|
|
engine=new lightingEngineViewscreen(myRender);
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2013-07-03 01:44:23 -06:00
|
|
|
if (Core::getInstance().isWorldLoaded())
|
|
|
|
plugin_onstatechange(out, SC_WORLD_LOADED);
|
2013-06-24 09:18:57 -06:00
|
|
|
}
|
|
|
|
else if(current_mode==MODE_LIGHT && parameters.size()>1)
|
|
|
|
{
|
|
|
|
if(parameters[1]=="reload")
|
2013-06-25 11:36:53 -06:00
|
|
|
{
|
2013-07-03 09:47:51 -06:00
|
|
|
enable_hooks(true);
|
2013-06-25 11:36:53 -06:00
|
|
|
}
|
2013-06-26 13:05:22 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-06-28 14:34:47 -06:00
|
|
|
else if(parameters[1]=="occlusionON")
|
|
|
|
{
|
|
|
|
engine->debug(true);
|
|
|
|
}else if(parameters[1]=="occlusionOFF")
|
|
|
|
{
|
|
|
|
engine->debug(false);
|
|
|
|
}
|
2013-06-24 09:18:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
out.printerr("Light mode already enabled");
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2013-06-23 10:25:42 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2013-06-22 04:29:58 -06:00
|
|
|
else if(cmd=="disable")
|
|
|
|
{
|
|
|
|
if(current_mode==MODE_DEFAULT)
|
|
|
|
out.print("%s\n","Not installed, doing nothing.");
|
|
|
|
else
|
|
|
|
removeOld();
|
2013-06-30 13:03:07 -06:00
|
|
|
CoreSuspender guard;
|
2014-12-06 16:47:35 -07:00
|
|
|
gps->force_full_display_count++;
|
2013-06-22 04:29:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
return CR_WRONG_USAGE;
|
2013-06-23 10:25:42 -06:00
|
|
|
}
|
2013-06-25 11:36:53 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream &)
|
|
|
|
{
|
|
|
|
removeOld();
|
|
|
|
return CR_OK;
|
|
|
|
}
|