Add "fps-min" tweak and allow onupdate-based tweaks

develop
lethosor 2015-03-04 19:03:39 -05:00
parent abc60f53ad
commit 83cb7b48f9
4 changed files with 46 additions and 0 deletions

@ -22,6 +22,7 @@ DFHack Future
New Scripts
modtools/reaction-product-trigger: triggers callbacks when products are produced (contrast with when reactions complete)
New Tweaks
fps-min: Fixes the in-game minimum FPS setting
shift-8-scroll: Gives Shift+8 (or *) priority when scrolling menus, instead of scrolling the map
tradereq-pet-gender: Displays pet genders on the trade request screen
Removed

@ -1310,6 +1310,7 @@ Subcommands that persist until disabled or DF quits:
takes for stable-temp to stop updates again when equilibrium is disturbed.
:fast-trade: Makes Shift-Down in the Move Goods to Depot and Trade screens select
the current item (fully, in case of a stack), and scroll down one line.
:fps-min: Fixes the in-game minimum FPS setting
:import-priority-category: Allows changing the priority of all goods in a
category when discussing an import agreement with the liaison
:manager-quantity: Removes the limit of 30 jobs per manager order

@ -81,6 +81,7 @@
#include "tweaks/farm-plot-select.h"
#include "tweaks/fast-heat.h"
#include "tweaks/fast-trade.h"
#include "tweaks/fps-min.h"
#include "tweaks/import-priority-category.h"
#include "tweaks/manager-quantity.h"
#include "tweaks/max-wheelbarrow.h"
@ -98,6 +99,7 @@ using namespace DFHack;
using namespace df::enums;
DFHACK_PLUGIN("tweak");
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(ui_build_selector);
@ -108,11 +110,23 @@ REQUIRE_GLOBAL(world);
using namespace DFHack::Gui;
class tweak_onupdate_hookst {
public:
typedef void(*T_callback)(void);
tweak_onupdate_hookst(std::string name_, T_callback cb)
:name(name_), callback(cb), enabled(false) {}
bool enabled;
std::string name;
T_callback callback;
};
static command_result tweak(color_ostream &out, vector <string> & parameters);
static std::multimap<std::string, VMethodInterposeLinkBase> tweak_hooks;
static std::multimap<std::string, tweak_onupdate_hookst> tweak_onupdate_hooks;
#define TWEAK_HOOK(tweak, cls, func) tweak_hooks.insert(std::pair<std::string, VMethodInterposeLinkBase>\
(tweak, INTERPOSE_HOOK(cls, func)))
#define TWEAK_ONUPDATE_HOOK(tweak, func) tweak_onupdate_hooks.insert(\
std::pair<std::string, tweak_onupdate_hookst>(tweak, tweak_onupdate_hookst(#func, func)))
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{
@ -213,6 +227,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
TWEAK_HOOK("fast-trade", fast_trade_assign_hook, feed);
TWEAK_HOOK("fast-trade", fast_trade_select_hook, feed);
TWEAK_ONUPDATE_HOOK("fps-min", fps_min_hook);
TWEAK_HOOK("import-priority-category", takerequest_hook, feed);
TWEAK_HOOK("import-priority-category", takerequest_hook, render);
@ -236,6 +252,16 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
return CR_OK;
}
DFhackCExport command_result plugin_onupdate (color_ostream &out)
{
for (auto it = tweak_onupdate_hooks.begin(); it != tweak_onupdate_hooks.end(); ++it)
{
tweak_onupdate_hookst hook = it->second;
if (hook.enabled)
hook.callback();
}
}
DFhackCExport command_result plugin_shutdown (color_ostream &out)
{
return CR_OK;
@ -659,6 +685,17 @@ static command_result enable_tweak(string tweak, color_ostream &out, vector <str
enable_hook(out, it->second, parameters);
}
}
for (auto it = tweak_onupdate_hooks.begin(); it != tweak_onupdate_hooks.end(); ++it)
{
if (it->first == cmd)
{
bool state = (vector_get(parameters, 1) != "disable");
recognized = true;
tweak_onupdate_hookst hook = it->second;
hook.enabled = state;
out.print("%s tweak %s (%s)\n", state ? "Enabled" : "Disabled", cmd.c_str(), hook.name.c_str());
}
}
if (!recognized)
{
out.printerr("Unrecognized tweak: %s\n", cmd.c_str());

@ -0,0 +1,7 @@
#include "df/enabler.h"
using df::global::enabler;
void fps_min_hook() {
if (enabler->fps < 10)
enabler->fps = 10;
}