Jump to content

Tick Rate


Recommended Posts

Just trying to hook Sanity:Recalc

I could use GetTime(), but I always thought that it's little bit pricey function.

I need update my stuff only once per second. So I need to get tick rate, to count it.

Edited by Maris
Link to comment
Share on other sites

Because it's just a dirty hook, so called proper API.

I don't want to replace Klei function. I just need to change one thing:

local sanity_comp = _G.require "components/sanity"local old_Recalc = sanity_comp.Recalcfunction sanity_comp:Recalc(dt,...)	if not self.tm_cnt or self.tm_cnt > 15 then --(if tick rate 15)		self.tm_cnt = 0		--- my stuff here		--- self.last_dapp_mult = .....................	else		self.tm_cnt = self.tm_cnt + 1	end	if self.last_dapp_mult and self.last_dapp_mult ~= 1 then		local tun = TUNING.DAPPERNESS_MED		TUNING.DAPPERNESS_MED = tun * self.last_dapp_mult		old_Recalc(self,dt,...)		TUNING.DAPPERNESS_MED = tun	else		old_Recalc(self,dt,...)	endend

Link to comment
Share on other sites

@Maris, You realize that dt = delta, which gives you the time since recalc was last called, right? I highly doubt knowing the tick rate is necessary if you're just trying to mess with sanity rates. I have no idea what you're trying to do with it in that code, but it looks like it's not the right way to go about it.

 

Edit: Something to do with rain sanity drain, I guess? More easily and neatly accomplished by a custom sanity rate fn, probably.

Edited by rezecib
Link to comment
Share on other sites

The main goal is to MULTIPLY existing sanity gain (from rain) by specific value. That's why I need to get existing value. But this value is hidden in local variables of Klei function. My trick is to pick one of the factors and change it. I don't like replacing functions.

Edited by Maris
Link to comment
Share on other sites

@Maris, So you're trying to multiply the sanity effect of rain? But why does that require counting time? Even if you're trying to get the multiplier to scale over time, it'd probably be nicer to represent it as having a change/second, then multiplying that by dt.

 

Link to comment
Share on other sites

Well, I use FindEntities to recount new rain coefficient. I think it's a little bit pricey on CPU. So I want to recount just every 0.5 sec or so.

I can't implement my multiplier in dt because it's used in another formula:

    self.rate = (dapper_delta + light_delta + aura_delta + rain_delta + ghost_delta)          if self.custom_rate_fn then        self.rate = self.rate + self.custom_rate_fn(self.inst)    end    self.rate = self.rate * self.rate_modifier    self:DoDelta(self.rate*dt, true)

For example, I have coefficient K. Then I need foolowing injection:

    self.rate = (dapper_delta + light_delta + aura_delta + rain_delta * K + ghost_delta)--<<!        if self.custom_rate_fn then        self.rate = self.rate + self.custom_rate_fn(self.inst)    end    self.rate = self.rate * self.rate_modifier    self:DoDelta(self.rate*dt, true)

​I took my look on previous strings and noticed that there is accessible coefficient that I can change:

    local rain_delta = not mitigates_rain and TheWorld.state.israining and        -1.5 * TUNING.DAPPERNESS_MED * TheWorld.state.precipitationrate or 0

​It's  ​TUNING.DAPPERNESS_MED

Edited by Maris
Link to comment
Share on other sites

Btw the tick rate is a  'preferred' type value.  Its not 100% enforced.  Its possible for events to get skipped if the game is overworked.  When this happens the  'dt' value will still be accurate saying how much time has passed since the last time a given Update() function was called.

 

So doing anything based on tickrate is WRONG and will lead to obscure bugs.   If you cant use dt then you are doing it wrong.

Link to comment
Share on other sites

  • Developer

The tick_rate in the settings, as far as I know, has nothing to do with the sim-tick, it's the network tick.

 

You should use dt indeed, and this should always be 0.033 anyhow - if a frame takes longer than 1/30th of a second it'll catch up the next time by running multiple updates if needed (within a treshold to prevent explosion) - each tick will be called with a dt of 0.033. 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...