Add yet one more performance-oriented tweak for temperature updates.

develop
Alexander Gavrilov 2012-09-14 12:14:36 +04:00
parent c927623050
commit aaf5d181bd
4 changed files with 105 additions and 12 deletions

@ -51,7 +51,7 @@ keybinding add Shift-G "job-material GLASS_GREEN"
keybinding add Ctrl-M@dwarfmode/QueryBuilding/Some gui/mechanisms keybinding add Ctrl-M@dwarfmode/QueryBuilding/Some gui/mechanisms
# browse rooms of same owner # browse rooms of same owner
keybinding add Alt-R@dwarfmode/QueryBuilding/Some gui/room-list.work keybinding add Alt-R@dwarfmode/QueryBuilding/Some gui/room-list
# interface for the liquids plugin # interface for the liquids plugin
keybinding add Alt-L@dwarfmode/LookAround gui/liquids keybinding add Alt-L@dwarfmode/LookAround gui/liquids
@ -59,9 +59,9 @@ keybinding add Alt-L@dwarfmode/LookAround gui/liquids
# machine power sensitive pressure plate construction # machine power sensitive pressure plate construction
keybinding add Ctrl-Shift-M@dwarfmode/Build/Position/Trap gui/power-meter keybinding add Ctrl-Shift-M@dwarfmode/Build/Position/Trap gui/power-meter
################### ############################
# UI logic tweaks # # UI and game logic tweaks #
################### ############################
# stabilize the cursor of dwarfmode when switching menus # stabilize the cursor of dwarfmode when switching menus
tweak stable-cursor tweak stable-cursor
@ -74,3 +74,8 @@ tweak readable-build-plate
# improve FPS by squashing endless item temperature update loops # improve FPS by squashing endless item temperature update loops
tweak stable-temp tweak stable-temp
# speed up items reaching temp equilibrium with environment by
# capping the rate to no less than 1 degree change per 500 frames
# Note: will also cause stuff to melt faster in magma etc
tweak fast-heat 500

@ -89,6 +89,10 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" Fixes rendering of creature weight limits in pressure plate build menu.\n" " Fixes rendering of creature weight limits in pressure plate build menu.\n"
" tweak stable-temp [disable]\n" " tweak stable-temp [disable]\n"
" Fixes performance bug 6012 by squashing jitter in temperature updates.\n" " Fixes performance bug 6012 by squashing jitter in temperature updates.\n"
" tweak fast-heat [max-ticks]\n"
" Further improves temperature updates by ensuring that 1 degree of\n"
" item temperature is crossed in no more than specified number of frames\n"
" when updating from the environment temperature.\n"
)); ));
return CR_OK; return CR_OK;
} }
@ -293,6 +297,52 @@ struct stable_temp_hook : df::item_actual {
IMPLEMENT_VMETHOD_INTERPOSE(stable_temp_hook, adjustTemperature); IMPLEMENT_VMETHOD_INTERPOSE(stable_temp_hook, adjustTemperature);
IMPLEMENT_VMETHOD_INTERPOSE(stable_temp_hook, updateContaminants); IMPLEMENT_VMETHOD_INTERPOSE(stable_temp_hook, updateContaminants);
static int map_temp_mult = -1;
static int max_heat_ticks = 0;
struct fast_heat_hook : df::item_actual {
typedef df::item_actual interpose_base;
DEFINE_VMETHOD_INTERPOSE(
bool, updateTempFromMap,
(bool local, bool contained, bool adjust, int32_t rate_mult)
) {
int cmult = map_temp_mult;
map_temp_mult = rate_mult;
bool rv = INTERPOSE_NEXT(updateTempFromMap)(local, contained, adjust, rate_mult);
map_temp_mult = cmult;
return rv;
}
DEFINE_VMETHOD_INTERPOSE(
bool, updateTemperature,
(uint16_t temp, bool local, bool contained, bool adjust, int32_t rate_mult)
) {
// Some items take ages to cross the last degree, so speed them up
if (map_temp_mult > 0 && temp != temperature && max_heat_ticks > 0)
{
int spec = getSpecHeat();
if (spec != 60001)
rate_mult = std::max(map_temp_mult, spec/max_heat_ticks/abs(temp - temperature));
}
return INTERPOSE_NEXT(updateTemperature)(temp, local, contained, adjust, rate_mult);
}
DEFINE_VMETHOD_INTERPOSE(bool, adjustTemperature, (uint16_t temp, int32_t rate_mult))
{
if (map_temp_mult > 0)
rate_mult = map_temp_mult;
return INTERPOSE_NEXT(adjustTemperature)(temp, rate_mult);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(fast_heat_hook, updateTempFromMap);
IMPLEMENT_VMETHOD_INTERPOSE(fast_heat_hook, updateTemperature);
IMPLEMENT_VMETHOD_INTERPOSE(fast_heat_hook, adjustTemperature);
static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector <string> &parameters) static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector <string> &parameters)
{ {
if (vector_get(parameters, 1) == "disable") if (vector_get(parameters, 1) == "disable")
@ -430,6 +480,17 @@ static command_result tweak(color_ostream &out, vector <string> &parameters)
enable_hook(out, INTERPOSE_HOOK(stable_temp_hook, adjustTemperature), parameters); enable_hook(out, INTERPOSE_HOOK(stable_temp_hook, adjustTemperature), parameters);
enable_hook(out, INTERPOSE_HOOK(stable_temp_hook, updateContaminants), parameters); enable_hook(out, INTERPOSE_HOOK(stable_temp_hook, updateContaminants), parameters);
} }
else if (cmd == "fast-heat")
{
if (parameters.size() < 2)
return CR_WRONG_USAGE;
max_heat_ticks = atoi(parameters[1].c_str());
if (max_heat_ticks <= 0)
parameters[1] = "disable";
enable_hook(out, INTERPOSE_HOOK(fast_heat_hook, updateTempFromMap), parameters);
enable_hook(out, INTERPOSE_HOOK(fast_heat_hook, updateTemperature), parameters);
enable_hook(out, INTERPOSE_HOOK(fast_heat_hook, adjustTemperature), parameters);
}
else else
return CR_WRONG_USAGE; return CR_WRONG_USAGE;

@ -1,5 +1,9 @@
-- Reset item temperature to the value of their tile. -- Reset item temperature to the value of their tile.
local args = {...}
local apply = (args[1] == 'apply')
local count = 0 local count = 0
local types = {} local types = {}
@ -9,13 +13,16 @@ local function update_temp(item,btemp)
local tid = item:getType() local tid = item:getType()
types[tid] = (types[tid] or 0) + 1 types[tid] = (types[tid] or 0) + 1
end end
item.temperature = btemp
item.temperature_fraction = 0
if item.contaminants then if apply then
for _,c in ipairs(item.contaminants) do item.temperature = btemp
c.temperature = btemp item.temperature_fraction = 0
c.temperature_fraction = 0
if item.contaminants then
for _,c in ipairs(item.contaminants) do
c.temperature = btemp
c.temperature_fraction = 0
end
end end
end end
@ -23,7 +30,9 @@ local function update_temp(item,btemp)
update_temp(sub,btemp) update_temp(sub,btemp)
end end
item:checkTemperatureDamage() if apply then
item:checkTemperatureDamage()
end
end end
local last_frame = df.global.world.frame_counter-1 local last_frame = df.global.world.frame_counter-1
@ -39,7 +48,11 @@ for _,item in ipairs(df.global.world.items.all) do
end end
end end
print('Items updated: '..count) if apply then
print('Items updated: '..count)
else
print('Items not in equilibrium: '..count)
end
local tlist = {} local tlist = {}
for k,_ in pairs(types) do tlist[#tlist+1] = k end for k,_ in pairs(types) do tlist[#tlist+1] = k end
@ -47,3 +60,7 @@ table.sort(tlist, function(a,b) return types[a] > types[b] end)
for _,k in ipairs(tlist) do for _,k in ipairs(tlist) do
print(' '..df.item_type[k]..':', types[k]) print(' '..df.item_type[k]..':', types[k])
end end
if not apply then
print("Use 'fix/stable-temp apply' to force-change temperature.")
end

@ -0,0 +1,10 @@
-- Set the FPS cap at runtime.
local cap = ...
local capnum = tonumber(cap)
if not capnum or capnum < 1 then
qerror('Invalid FPS cap value: '..cap)
end
df.global.enabler.fps = capnum