logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
APS vs Local Variables

 
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
weldieran



Joined: 05 Aug 2005
Posts: 71

PostPosted: Fri Aug 05, 2005 3:38    Post subject: APS vs Local Variables Reply with quote

I've looked around for awhile looking for any actual figures comparing Local Variables and NWNx/APS mysql calls.

Can anyone tell me with any certainty which is actually faster? And by how much?

Ever since bioware made local varibles on items persistant, I've been using that for everything I can.

The only speed issue I can imagine would be in nwscripts GetObjectPossessedBy function - as I don't know what it does to locate the item in oPCs inventory.
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Fri Aug 05, 2005 7:23    Post subject: Re: APS vs Local Variables Reply with quote

weldieran wrote:
I've looked around for awhile looking for any actual figures comparing Local Variables and NWNx/APS mysql calls.

Can anyone tell me with any certainty which is actually faster? And by how much?

Ever since bioware made local varibles on items persistant, I've been using that for everything I can.

The only speed issue I can imagine would be in nwscripts GetObjectPossessedBy function - as I don't know what it does to locate the item in oPCs inventory.


ANY database access is slower than a local variable. But NWNX is fast enough for most things to pull directly even on a loaded server as long as you aren't being silly with your database access. There was another post on how fast it is, in the order of 40 ms retrieval times for 500 integers. Your best scenario is local variables with occasional database updates if your system starts bogging down.

GetItemPossessedBy is EXTREMELY slow as it cycles through every item in the inventory. Remember that a stack of arrows is actually 99 items. ON a PW many players will carry thousands of arrows and potions. You are better off setting the object storing the variables on the PC on login and calling that Object instead:

SetLocalObject(oPlayer,"VariableStorage",GetItemPossessedBy(oPlayer,"Storage_Item"));

NWNX has one VERY important function that you can never get with item variables. The ability to manipulate the data stored. With NWNX you can directly access that data to clear quests, locations, fix things, etc....
Back to top
View user's profile Send private message
weldieran



Joined: 05 Aug 2005
Posts: 71

PostPosted: Fri Aug 05, 2005 18:43    Post subject: Reply with quote

aha! see I was always uncertain about that "new" function they gave us.

I didn't know if it was just a simple wrapper for the self made functions we used to make to loop thru inventory or not.

Apparently, by your say, it is. I had kinda assumed it wasn't, is it didn't provide a Nth option. I figured if bioware made that wrapper, they'd also give the power to grab the first or second or 9th item it found matching. Since they didn't include this option, i had assumed they found a better way to search inventory.

*sigh* Well, i've got a lot to change, hehe.
Back to top
View user's profile Send private message
weldieran



Joined: 05 Aug 2005
Posts: 71

PostPosted: Fri Aug 05, 2005 19:54    Post subject: Reply with quote

As a side note

Can anyone tell me why


StringToFloat("1430.7") returns float 1430.699951172


Just found that out doing a little testing to see how bioware's conversion functions worked.
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Fri Aug 05, 2005 20:13    Post subject: Reply with quote

Re-reading my post I wasn't very clear the advantages of setting the LocalObject.

To get the best results you would put the previous line in the Player's OnEnter script:
Code:

SetLocalObject(oPlayer,"VariableStorage",GetItemPossessedBy(oPC,"Storage_Item"));


Then when you NEED it you would call it in the scripts:
Code:

object oPC=OBJECT_SELF;
object oVariableStorage=GetLocalObject(oPC,"VariableStorage");

SetLocalLocation(oVariableStorage,"MyLocation",GetLocation(oPC));



By doing this you are only cycling through the inventory when you set the itemOnEnter. Later when you call it you are pointing straight at that item.

You still cannot edit those variables outside of the game though....
Back to top
View user's profile Send private message
weldieran



Joined: 05 Aug 2005
Posts: 71

PostPosted: Sat Aug 06, 2005 0:12    Post subject: Reply with quote

I catch yer meaning.

One thought:

Code:

object oItem = GetItemPossessedBy(oPC, sTag);

if (GetIsObjectValid(oItem))
    SetLocalObject(oPC, sTag, oItem);

DestroyObject(oItem);


OK from the example code above, we set the local object to that item found. Then we immediately destroyed the item that SetLocalObject pointed to.

SO - Is the Local Variable still taking up memory? Do I need to process a DeleteLocalObject(oPC, sTag) to clear things up?

Or does it not matter since GetLocalObject(oPC, sTag) would return OBJECT_INVALID now?
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Sat Aug 06, 2005 0:31    Post subject: Reply with quote

The scripts are still setting variables on the object in the INVENTORY, the SetLocalObject is just a pointer to it for easy and fast access.

Remove the item, break the link.....
Back to top
View user's profile Send private message
shadguy



Joined: 03 Jan 2005
Posts: 6
Location: Raleigh, NC

PostPosted: Sun Aug 07, 2005 20:51    Post subject: Reply with quote

//somewhat offtpic

Another idea. Since your OnAcquire script is fired for every item in inventory on joining a mod, you could move this...

Code:

object oVariableStorage=GetLocalObject(oPC,"VariableStorage");


...into an item tag-based OnAcquire routine and skip searching through the inventory at all. It'd look a bit different, but should work nicely.

-shad
_________________
Dreu Noctem
Back to top
View user's profile Send private message Visit poster's website
weldieran



Joined: 05 Aug 2005
Posts: 71

PostPosted: Mon Aug 08, 2005 21:34    Post subject: Reply with quote

Aye - Can do that, however, there's one warning to this:

When the PC first enters the game (since last server reset), it does run onAcquire for every item, thus caching the appropriate items is easily done.

HOWEVER - If that PC relogs, NWN does NOT reacquire all the items that PC has. (thank god) And that item that you once cached in LocalObject on the PC is now OBJECT_INVALID.

Why? Because the item in that person's inventory has a new address. Gets a new address every time that person relogs. The LocalVariable still exists, as it should, it just doesn't point to that object anymore.


SO - The only way for object caching to work is to:

Code:

if (ThisIsNOTtheFirstTimeLoggingIn(oPC))
   TrampleThruInventoryCachingPredefinedItems();



I've personally gone ahead and created an ItemCaching system for every single item every called from a person's inventory. onLogin they are cached and every script uses a custom GetItemPossessedBy function that checks for the LocalObject first.

I know this is much more aggressive on memory, and I'm not entirely certain if it is advantatious, but when I log every trample through a PCs inventory as things stand now, its QUITE A HUGE LIST. Seems like the module is constantly trampling through inventories - usually back to back. And with 40+ players on, that makes for some serious lag. (ATS crafting system is full of this - quite nasty)

So I'm hoping that even tho I have to run the Inventory Cache onLogin (as per my notes above), it will give me a large overall increase in performance. Although, it ends up being quite a few items to cache times 40+ players - just not sure how that'll pan out. But I can always get more RAM, its the CPU that i'm maxed on.

(multiple items of same item on a PC?)
yes, you have to account for this. I did so with a pseudo LocalObject array. Then make a cleaner script for that array that fires once the array has reached X entries - just to be sure all the entries are still valid - if not, readjust array.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group