Thread: Compass
View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-12-2010 , 01:04   Re: Compass
Reply With Quote #4

More:
There are two places that I see that a switch would be more efficient.

You should only need to do if(method) once because if method is 0 then nothing happens anyways (except for the very last hud message) so why do anything?

Also, it looks like when you are pointing only in one of the cardinal directions it uses whole words but if you move 1 degree then it switches to short names. So, this would make it look like the full names pop up every so often and not look consistent.

Quote:
Originally Posted by Tirant View Post
While the braces on line 42 server no purpose to the code, they help my eyes see what part handles the actual angle->hud float conversions.

I cached one of the variables, but not the other because I didn't think it was necessary because it was only being questioned once.

What do you mean by recreating variables? Do you mean that I should make them all global?

Thank you for your comments, I really appreciate you taking your time to go through my code and help me.
When you do something in prethink it is called thousands of times per second* so accessing a variable is much more efficient than retrieving the value again using a native. Besides, how often is a cvar going to change? It's definitely not going to change more than once per second or even minute or maybe even for the whole map. Personally, I would probably only read the cvars once per map or even on a new round event.

By recreating variables I mean that when you use "new" it creates the variable then when the function is complete the variable is destroyed. Repeat thousands of times per second*. You should be able to use static variabls.

* I'm not sure about the 1000 times per second but it's sure is a lot.
__________________
fysiks is offline