![]() |
Function library efficiency
Which of the following cases would be more efficient? I'm pretty sure I know which, but I'd like some input from eithers.
Both cases are clientside. The first case (a) is to create a class to hold groups of functions, then join it to NPCs that require functions that deal with certain objects. i.e. PHP Code:
PHP Code:
i.e. PHP Code:
PHP Code:
|
Definideatly alternative A.
|
Alternative C, which is:
PHP Code:
PHP Code:
Alternative B. |
That would require more resource, and declaring the class you're calling isn't needed if you're an organized scripter.
Actually, it's the exact same thing I posted, just written in a less efficient manner. Why the hell did you waste precious forum bytes? |
Quote:
Quote:
B. If you have >1 weapon all joining the same class (and I'm assuming there's more than one function in that class), it is less efficient to load each of those weapons with code that is unneeded for that weapon (say the weapon only uses one of many functions) using join() than to have each of these weapons calling a public function in a single existance of the library. If that's the only function in the class, the different is negligible. |
Well, I personally would most likely do:
Class PHP Code:
PHP Code:
PHP Code:
|
Same idea. But yes, very efficient nonetheless.
|
You can't call clientside functions in a class joined to a player on the serverside, silly.
|
Quote:
|
PHP Code:
|
Quote:
|
'A' would be the nicest solution, although not necessary the most efficient, because currently class scripts are not cached (need to be downloaded on first use) and the requested function might not exist yet when the class is not loaded yet (onCreated() is not called then either, even if it would be cached).
'B' is more efficient because weapons are cached, and most of the time item systems require some central control script anyway (which is creating the item objects). If you can live with the delay of the class script loading then 'A' would be best I guess, otherwise use 'B'. |
| All times are GMT +2. The time now is 05:38 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.