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
# 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
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
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
tweak stable-cursor
@ -74,3 +74,8 @@ tweak readable-build-plate
# improve FPS by squashing endless item temperature update loops
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"
" tweak stable-temp [disable]\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;
}
@ -293,6 +297,52 @@ struct stable_temp_hook : df::item_actual {
IMPLEMENT_VMETHOD_INTERPOSE(stable_temp_hook, adjustTemperature);
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)
{
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, 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
return CR_WRONG_USAGE;

@ -1,5 +1,9 @@
-- Reset item temperature to the value of their tile.
local args = {...}
local apply = (args[1] == 'apply')
local count = 0
local types = {}
@ -9,13 +13,16 @@ local function update_temp(item,btemp)
local tid = item:getType()
types[tid] = (types[tid] or 0) + 1
end
item.temperature = btemp
item.temperature_fraction = 0
if item.contaminants then
for _,c in ipairs(item.contaminants) do
c.temperature = btemp
c.temperature_fraction = 0
if apply then
item.temperature = btemp
item.temperature_fraction = 0
if item.contaminants then
for _,c in ipairs(item.contaminants) do
c.temperature = btemp
c.temperature_fraction = 0
end
end
end
@ -23,7 +30,9 @@ local function update_temp(item,btemp)
update_temp(sub,btemp)
end
item:checkTemperatureDamage()
if apply then
item:checkTemperatureDamage()
end
end
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
print('Items updated: '..count)
if apply then
print('Items updated: '..count)
else
print('Items not in equilibrium: '..count)
end
local tlist = {}
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
print(' '..df.item_type[k]..':', types[k])
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