Author Topic: Questions about "Get2DAString"  (Read 330 times)

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Questions about "Get2DAString"
« on: July 13, 2012, 10:43:46 am »


               I figured an easy way to loop through wings (and possibly some other parts) would be to do something like this:

//Make this number match the last row of your "wingmodel" 2da.
const int MAX_2DA_ROW = 90;

void main()
{
    object oUser = GetLastUsedBy();
    int iCurrentWing = GetCreatureWingType(oUser);
    int iNewWing = iCurrentWing + 1;
    string s2DA = Get2DAString("wingmodel", "LABEL", iNewWing);
    while (s2DA == "")
    {
        iNewWing++;
        if (iNewWing >= MAX_2DA_ROW) iNewWing = 0;
        s2DA = Get2DAString("wingmodel", "LABEL", iNewWing);
    }

    SetCreatureWingType(iNewWing, oUser);

    //Debug/feedback lines
    SendMessageToPC(oUser, "Your current wing #: " + IntToString(iCurrentWing));
    SendMessageToPC(oUser, "Your new wing #: " + IntToString(iNewWing));
    SendMessageToPC(oUser, "2DA name is: " + s2DA);
}


The description for the "Get2DAString" function mentions this:

// Gets a value from a 2DA file on the server and returns it as a string
// avoid using this function in loops

But the Lexicon says this:

You can now loop using this function. It will now work (or should work)
as fast as the game would itself getting information from a 2da file.
Likely, there now should be no noticable loss of speed compared to
pre-1.64. If there is loss of speed - it'll be greatly improved upon
pre-1.64.


Now the function I posted does seem to work pretty well but I do notice a tiny bit of a "hiccup" when changing the wings and it seems to be from looping through the 2da.

So I guess my questions are; Is it still considered 'dangerous' or bad to use the function in a loop? Is it better to just manual put in all the numbers to include or exclude instead of using the Get2DAString function?

Any advice greatly appreciated. Thanks.
               
               

               


                     Modifié par GhostOfGod, 13 juillet 2012 - 09:52 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #1 on: July 13, 2012, 01:39:23 pm »


               2da files are now cached in memory when used.  There's quite a few of them though, so a TMI is possible.

 With the cep ones at least, I think all wing and tails have a similar string prefix that you could use to filter out the vfx and creatures if you wanted to, as well.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #2 on: July 13, 2012, 01:52:01 pm »


               2DAs should be cached automatically by engine per 1.69's readme. Although by default only last 10 2DAs are, if you want more you have to use 2da settings in nwplayer.ini.

Perhaps its really fast now, still using 2DA in loops isn't really good practice. Sometimes its inevitable, sometimes not. In this particular example it shouldn't be bad, the loop is large only if there is large **** gap between lower wings and higher wings.

EDIT: changing tail/wing makes client-side lag itself as some models are quite extensive - for example dragon wings from 1.69 are really bad, causing lags when you meet another player
               
               

               


                     Modifié par ShaDoOoW, 13 juillet 2012 - 03:42 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #3 on: July 13, 2012, 06:30:49 pm »


               I would think that using Get2daString in a loop doesn't necessarily pose more of a problem than other string processing functions. Problems likely arise when you try to iterate through an entire 2da row by row.

Typically I use Get2DAString when I want to know the contents of a specific column on a specific row. I have not noticed any hiccups and I do this frequently.

Where is Funky? We need some people to go after profiling this function.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #4 on: July 13, 2012, 06:39:17 pm »


               Thanks for the replies guys.

I was playing around with it a bit more and It seems you are right about the models ShaDoOoW. It's probably the models themselves that are causing the noticeable lag and not the loop. And for some reason going from a tail to "NullTail" is the worst. That one's almost as bad as changing phenotypes.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #5 on: July 14, 2012, 02:47:41 am »


               If it can be of any help, I remember I saw a post on these forums into which the author presented some results after comparing the speed of Get2DAString() vs GetLocalString() and a few other string functions, using the profiler. The results were surprising, showing that depending on the situation, Get2DAString() was faster than some other string functions(I would never have thought). I'd like to leave the link but I can't seem to find the post anew, though...

P.S.: Even considering this I can't help but agree with ShaDoOoW, performing heavy loops over 2DAs scare me a bit...

Kato
               
               

               


                     Modifié par Kato_Yang, 14 juillet 2012 - 01:51 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #6 on: July 14, 2012, 02:51:51 am »


               thanks, Kato. That confirms my thoughts on it too.

I think some of the functions that cast an int to a string or vice versa are much more resource intensive. But I have not profiled it. Just by my experience cleaning up DMFI's onload script.

Anyway....
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Questions about "Get2DAString"
« Reply #7 on: July 14, 2012, 02:55:16 am »


               

henesua wrote...

thanks, Kato. That confirms my thoughts on it too.

I think some of the functions that cast an int to a string or vice versa are much more resource intensive. But I have not profiled it. Just by my experience cleaning up DMFI's onload script.

Anyway....


Oh!? I did ignore that type conversions were such resource intensive, a curse on me for using them that much, I see some profiling ahead, ty for the info Henesua '<img'>

EDIT: Sorry for being a bit off-topic here, I like to jump on good infos whenever possible...

Kato
               
               

               


                     Modifié par Kato_Yang, 14 juillet 2012 - 04:27 .