Does GetDistance called every frame hurt Frame Rate or not?

Post » Wed Aug 18, 2010 8:45 pm

I have read that GetDistance called every frame is bad and should be put under other Ifs or only run in cycles of seconds or more.

But I am seeing a lot of people here giving advice or sample scripts that include Getdistance done each frame.

So whats the deal? :blink:
User avatar
kitten maciver
 
Posts: 3472
Joined: Fri Jun 30, 2006 2:36 pm

Post » Wed Aug 18, 2010 10:24 pm

I have read that GetDistance called every frame is bad and should be put under other Ifs or only run in cycles of seconds or more.

But I am seeing a lot of people here giving advice or sample scripts that include Getdistance done each frame.

So whats the deal? :blink:


I tested with this script in the testinghall:

begin gamemodeif IsKeyPressed3 57 == 1	while count < 100	set dist to player.getdistance PTTestRef	set count to count + 1	loop		if count >= 100	set count to 0	endifendifend


As long as I didn't press space the framerate hovered between 217-225. If I pressed space it was between 206-213. About 5% performance loss for 100 getdistance checks per frame. Definitely a performance loss, but if you have a few conditions or only need one getdistance check per frame it should be negligible.

EDIT: Of course there is nothing to compare, so I can't really say whether GetDistance is worse than any other function. Calling a function 100 times per frame is probably never a good idea. :P
User avatar
Jessica White
 
Posts: 3419
Joined: Sun Aug 20, 2006 5:03 am

Post » Wed Aug 18, 2010 2:15 pm

...
As long as I didn't press space the framerate hovered between 217-225. If I pressed space it was between 206-213. About 5% performance loss for 100 getdistance checks per frame. Definitely a performance loss, but if you have a few conditions or only need one getdistance check per frame it should be negligible.
Just wanted to give a different perspective on your data anolysis. Going from 220 to 210 means that the time for one frame increases from 4.54ms to 4.76ms, or by 0.22ms.

A more typical ingame framerate is 25, which means that each frame takes 40ms. Adding 0.22 to this means 40.22ms/frame, or a framerate of 24.86. So by this, it would seem that calling GetDistance 100 times will reduce a framerate from 25 to 24.86, which is almost nothing.


No testing involved on my part, just speculations based on Phitt's testing :)
User avatar
Undisclosed Desires
 
Posts: 3388
Joined: Fri Mar 02, 2007 4:10 pm

Post » Wed Aug 18, 2010 2:32 pm

But, the 'getDistance' would not be called 100 times if you get 25 FPS. The script in a GameMode block runs once per FPS cycle, so it would only run 25 times a second which would be even less of an impact.
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Wed Aug 18, 2010 4:28 pm

I agree with WillieSea - aside from the fact that the game can't update distances while in a while loop, calling GetDistance on the same NPC / object more than once in a given frame is, well, useless, for the reason just mentioned. From all my testing, GetDistance is a rather fast function.

Now, of course, there are some caveats to using it... sometimes it doesn't return good values, and you'll need to use the Distance Formula (argh, maths!) in order to get a proper distance.
User avatar
Alberto Aguilera
 
Posts: 3472
Joined: Wed Aug 29, 2007 12:42 am

Post » Wed Aug 18, 2010 9:39 pm

One reason the distance it returns may seem er.... funny sometimes is because the distance is measured from the 0,0,0 point of one object/actor straight to the other objects 0,0,0, point. So an arrow for example that is 20 feet in the air above an actor but the arrow is only 1 foot "away" from the actor's center will still give a get-distance of over 20 feet!

So trying to see if the arrow is 3 feet away form hitting and actor when the arrow is fired 5 feet above the ground gets more difficult then it may at first seem. So I do not use get distance for this and use a few lines of script to check and calculate the distance from the x y pos instead.

I discovered this in my hundreds of hours of working worth arrows last year. So most of the time I use x and y pos and my own simple (very simple) math to get distance when I need to be precise. But GetDistance will be very convenient to use in many cases not that I know I can call it every frame.


I agree with WillieSea - aside from the fact that the game can't update distances while in a while loop, calling GetDistance on the same NPC / object more than once in a given frame is, well, useless, for the reason just mentioned. From all my testing, GetDistance is a rather fast function.

Now, of course, there are some caveats to using it... sometimes it doesn't return good values, and you'll need to use the Distance Formula (argh, maths!) in order to get a proper distance.

User avatar
Janette Segura
 
Posts: 3512
Joined: Wed Aug 22, 2007 12:36 am

Post » Wed Aug 18, 2010 11:16 pm

One reason the distance it returns may seem er.... funny sometimes is because the distance is measured from the 0,0,0 point of one object/actor straight to the other objects 0,0,0, point. So an arrow for example that is 20 feet in the air above an actor but the arrow is only 1 foot "away" from the actor's center will still give a get-distance of over 20 feet!

So trying to see if the arrow is 3 feet away form hitting and actor when the arrow is fired 5 feet above the ground gets more difficult then it may at first seem. So I do not use get distance for this and use a few lines of script to check and calculate the distance from the x y pos instead.

I discovered this in my hundreds of hours of working worth arrows last year. So most of the time I use x and y pos and my own simple (very simple) math to get distance when I need to be precise. But GetDistance will be very convenient to use in many cases not that I know I can call it every frame.
I was referring to more issues surrounding trying to get the distance between objects in an interior / exterior cell. But yes, measurements can also be off if the "center" of the NIF file isn't quite right.
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am


Return to IV - Oblivion