From aaf5d181bd2a54e378c91b7a02a558126c4d5105 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 14 Sep 2012 12:14:36 +0400 Subject: [PATCH] Add yet one more performance-oriented tweak for temperature updates. --- dfhack.init-example | 13 +++++--- plugins/tweak.cpp | 61 +++++++++++++++++++++++++++++++++++++ scripts/fix/stable-temp.lua | 33 +++++++++++++++----- scripts/setfps.lua | 10 ++++++ 4 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 scripts/setfps.lua diff --git a/dfhack.init-example b/dfhack.init-example index 5af527099..a9b69b826 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -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 diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index fbea30231..de7695fb3 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -89,6 +89,10 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector 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 ¶meters) { if (vector_get(parameters, 1) == "disable") @@ -430,6 +480,17 @@ static command_result tweak(color_ostream &out, vector ¶meters) 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; diff --git a/scripts/fix/stable-temp.lua b/scripts/fix/stable-temp.lua index d06d0fcce..27a88ef7b 100644 --- a/scripts/fix/stable-temp.lua +++ b/scripts/fix/stable-temp.lua @@ -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 diff --git a/scripts/setfps.lua b/scripts/setfps.lua new file mode 100644 index 000000000..690f82702 --- /dev/null +++ b/scripts/setfps.lua @@ -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