Jump to content

onClientPreRender limiting executions


vicisdev

Recommended Posts

53 minutes ago, MIKI785 said:

Can you post the code?

I don't know if it's enough, but basically this is what's called every frame

-- self.behavior is a table that describes the animation properties

local elapsedTime = os.time() * 1000 - initialTime
local time = elapsedTime / self.behavior.duration

local progress = bezierInterpolation(time, self.behavior["cubic-bezier"]).x
local element = self.element

local x, y, z = unpack(initialPosition)
local toX, toY, toZ = unpack(self.behavior.to)

local newX, newY, newZ = x + ((toX - x) * progress),
                         y + ((toY - y) * progress),
                         z + ((toZ - z) * progress)

setElementPosition(element, newX, newY, newZ)

if time == 1 then
  removeEventHandler("onClientPreRender", root, renderHandler)
end

This function is called every frame, but because the values is too close from each other the API tries to save processing and updates only per second, I guess.

24 FPS
100 FPS
 

Link to comment
  • Scripting Moderators
1 hour ago, vicisdev said:

I don't know if it's enough, but basically this is what's called every frame


-- self.behavior is a table that describes the animation properties

local elapsedTime = os.time() * 1000 - initialTime
local time = elapsedTime / self.behavior.duration

local progress = bezierInterpolation(time, self.behavior["cubic-bezier"]).x
local element = self.element

local x, y, z = unpack(initialPosition)
local toX, toY, toZ = unpack(self.behavior.to)

local newX, newY, newZ = x + ((toX - x) * progress),
                         y + ((toY - y) * progress),
                         z + ((toZ - z) * progress)

setElementPosition(element, newX, newY, newZ)

if time == 1 then
  removeEventHandler("onClientPreRender", root, renderHandler)
end

This function is called every frame, but because the values is too close from each other the API tries to save processing and updates only per second, I guess.

24 FPS
100 FPS
 

I know that has nothing to do with that, but calling unpack every frame, it is heavy function.

You might simply replace it with [], since you know how much data will be returned.

  • Like 1
Link to comment
18 minutes ago, majqq said:

I know that has nothing to do with that, but calling unpack every frame, it is heavy function

Oh, thanks! I really appreciate this kind of help.

17 minutes ago, MIKI785 said:

Are you just trying to move an object? Wouldn't using moveObject be sufficient?

No, because I'm trying to make something more robust, versatile.

Link to comment
17 hours ago, vicisdev said:

Is there a way to prevent this from happening?
I'm making a movement script with cubic-bezier support, but when I render the movement onClientPreRender the server kinda limit the executions.

DEMONSTRATION

Solved! The point is that os.time() returns an integer in seconds, so even if I multiply it by a thousand we miss a lot of information on cents, decimals, units in a range from 0 to 999. Just replace os.time() by getTickCount() and you're good to go, since this returns an integer in milliseconds.

Edited by vicisdev
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...