Optimization
Guys, I've seen to much times here scripters talking about optimizations for good read/visual/style on the plugin. I'm learning more about it reading tutorials and plugins on that forum. I've searched a little bit and I want know more about it.
Ok, so my question is: If I have so much get_user_flags() or any other native. if I make something like this PHP Code:
PHP Code:
PHP Code:
|
Re: Optimization
Stick to the easiest way.
PHP Code:
|
Re: Optimization
Quote:
Quote:
I did som efficiency tests using 5 different methods. Spoiler: None of them are sticking out as bad, they are all fine.
Spoiler
|
Re: Optimization
So, basically, all these formats you've used doesn't make any big differente to the compiler, i'm right? The best way is use the original native instead of making new methods like macro, stock, array?
Ah, about this PHP Code:
PHP Code:
PHP Code:
Edit: off-topic LUL, now I understand your signature, haha gj |
Re: Optimization
Unfortunately you can't use a switch because get_user_flags() will return a bitsum. So it will never be EQUAL TO ADMIN_KICK, it will INCLUDE ADMIN_KICK.
You could use this: Code:
Also, if you are considering converting it to cvars to be able to change the different levels required more easily by the end user, switches are out completely. If you have all of these in multiple locations I would say that your menu system is not dynamic enough. You can definitely make it more dynamic and end up with one handler with just one message. But if you find it hard to create that kind of advanced menu, then I would suggest a stock. In the end it's a function that is called whenever someone uses a command or a menu which is rare in general. You do not have to worry about performance at all and should use the method that makes the code easy to work with without breaking readability. |
Re: Optimization
I know about it, thats want I want, check if user has ADMIN_KICK included on all his access. Not just one flag,
Example: abcdefghijklmnopqrstu, he have T flag included, so its considered VIP I'm curious now, what "hard menu" are you talking about? I want optimize it because I think I will post this here, you know. And optimization is the most important thing on plugins you know. But I understand you side and I'll continue with the current format. If someone told me to change, i'll do it. |
Re: Optimization
That is no optimization on what you did on the first post, the main goal of the optimization is to use less resources, the secondary being the readability
What you did in the first post is not helping when it comes to using less resources neither helping when it comes to readability An example of optimization is this Instead of calling a native twice, you call it once and store it's return value, then you compare it with your desired values
Spoiler
Macros / Define are for readability, not improving performance, you usually make them to save your ass writing a long story ( set_pev(id, (pev_) asadsad bla bla blabla )_) Stocks have basically the same purpose, instead of writing 10 times the same thing in every function you need it, you just write it in one, and call that stock |
Re: Optimization
@Depresie,
Yea, thats the one thing of all I have. I don't have only one check like this, I have so much, as I said, 15-20 I think. So, should I always store the get_user_flag() in one variable on all checks or should I make a stock with that feature? |
Re: Optimization
Yeah, if you have to do the exact same things in more than one function, just make a stock/function for that it's easier to handle
|
Re: Optimization
Just one thing,
If I have two things that uses the get_user_flags() but their features are different. Like this first one I said and another one. Should I create a global variable, store on client_putinserver() and client_infochanged() and use that variable on all functions that check user's flag? |
| All times are GMT -4. The time now is 20:50. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.