Author Topic: SET_2DA_ENTRY thoughts  (Read 6842 times)

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
SET_2DA_ENTRY thoughts
« on: May 18, 2005, 05:00:53 PM »
devSin apparently has this code:

Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  FOR (column = 4; column < 54; column = column + 1) BEGIN
    FOR (row = 32; row < 51; row = row + 1) BEGIN
      SET_2DA_ENTRY ~%row%~ ~%column%~ 54 ~0~
    END
  END
BUT_ONLY_IF_IT_CHANGES

I've mentioned before that there's no easy way to make SET_2DA_ENTRY faster. However, if you want to conditionally touch all of the entries in a single file, we could make it much faster with something like REPLACE_EVALUATE. Essentially, you write a callback that computes the new entry based on the row, column and old entry. It would look somewhat like this:

Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  SET_2DA_ENTRIES 54 BEGIN
    // this code is executed once for each 2da entry with 'row', 'column' and 'entry' set by WeiDU
    PATCH_IF column >= 4 && column < 54 && row >= 32 && row < 51 THEN BEGIN
      SPRINT entry ~0~
    END
BUT_ONLY_IF_IT_CHANGES

Would anyone want this sort of thing, or is SET_2DA_ENTRY only used in psycho never-released devSin mods? :-)

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #1 on: May 18, 2005, 05:05:48 PM »
Cam was doing this, too. He had to break it out into the following because it was so slow:
Code: [Select]
COPY_EXISTING ~WEAPPROF.2da~ ~override~
  SET_2DA_ENTRY 13 41 54 ~2~ // 1 > 2 stars for swashbucklers in katanas
  SET_2DA_ENTRY 13 51 54 ~1~ // 0 > 1 star for monk in katanas
  SET_2DA_ENTRY 17 20 54 ~2~ // 3 > 2 stars for f/m/c in clubs
  SET_2DA_ENTRY 17 21 54 ~2~ // 3 > 2 stars for c/r in clubs
  SET_2DA_ENTRY 23 41 54 ~1~ // 2 > 1 star for swashbucklers in xbows
  SET_2DA_ENTRY 25 41 54 ~1~ // 2 > 1 star for swashbucklers in shortbows
  SET_2DA_ENTRY 26 32 54 ~0~ // 5 > 0 stars for kensai in darts
  SET_2DA_ENTRY 26 33 54 ~0~ // 2 > 0 stars for cavalier in darts
  SET_2DA_ENTRY 27 41 54 ~1~ // 2 > 1 star for swashbucklers in slings
  SET_2DA_ENTRY 28 19 54 ~2~ // 1 > 2 stars for f/d in 2 handed
  SET_2DA_ENTRY 28 20 54 ~2~ // 1 > 2 stars for f/m/c in 2 handed
  SET_2DA_ENTRY 28 21 54 ~2~ // 1 > 2 stars for c/r in 2 handed
  SET_2DA_ENTRY 31  9 54 ~2~ // 3 > 2 stars for paladin in 2 wpn style
  SET_2DA_ENTRY 31 19 54 ~3~ // 1 > 3 stars for f/d in 2 wpn style
  SET_2DA_ENTRY 31 20 54 ~3~ // 2 > 3 stars for f/m/c in 2 wpn style
  SET_2DA_ENTRY 31 21 54 ~3~ // 2 > 3 stars for c/r in 2 wpn style
  SET "row" = 50 // the nested WHILE loops remove any possible points in the EXTRAx profs
  WHILE ("%row%" > 31) BEGIN
    SET_2DA_ENTRY "%row%"  5 54 ~0~
    SET_2DA_ENTRY "%row%"  8 54 ~0~
    SET_2DA_ENTRY "%row%"  9 54 ~0~
    SET_2DA_ENTRY "%row%" 11 54 ~0~
    SET_2DA_ENTRY "%row%" 12 54 ~0~
    SET_2DA_ENTRY "%row%" 14 54 ~0~
    SET_2DA_ENTRY "%row%" 15 54 ~0~
    SET_2DA_ENTRY "%row%" 20 54 ~0~
    SET_2DA_ENTRY "%row%" 21 54 ~0~
    SET_2DA_ENTRY "%row%" 30 54 ~0~
    SET_2DA_ENTRY "%row%" 31 54 ~0~
    SET_2DA_ENTRY "%row%" 32 54 ~0~
    SET_2DA_ENTRY "%row%" 33 54 ~0~
    SET_2DA_ENTRY "%row%" 34 54 ~0~
    SET_2DA_ENTRY "%row%" 35 54 ~0~
    SET_2DA_ENTRY "%row%" 36 54 ~0~
    SET_2DA_ENTRY "%row%" 37 54 ~0~
    SET_2DA_ENTRY "%row%" 38 54 ~0~
    SET_2DA_ENTRY "%row%" 42 54 ~0~
    SET_2DA_ENTRY "%row%" 43 54 ~0~
    SET_2DA_ENTRY "%row%" 44 54 ~0~
    SET_2DA_ENTRY "%row%" 52 54 ~0~
    SET "row" = ("%row%" - 1)
  END
  BUT_ONLY_IF_IT_CHANGES
This is for a mod that, unlike my particular brand of magic, will actually be available for public consumption. So, it may be a good feature. I'd caution against it, however, since I have no idea how I'm ever going to be able to re-write this:
Code: [Select]
COPY_EXISTING ~MXSPLWIZ.2DA~ ~OVERRIDE~
  FOR (column = 1; column < 10; column = column + 1) BEGIN
    FOR (row = 30; row < 33; row = row + 1) BEGIN
      SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~7~
    END
    FOR (row = 35; row < 38; row = row + 1) BEGIN
      SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~8~
    END
    PATCH_IF (~%column%~ < 6) BEGIN
      FOR (row = 20; row < 23; row = row + 1) BEGIN
        SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~5~
      END
      SET ~value~ = 6
      FOR (row = 25; row < 39; row = (row = 25) ? row + 3 : row + 5) BEGIN
        SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~%value%~
        SET ~value~ = ~%value%~ + 1
      END
    END
    PATCH_IF (~%column%~ < 8) BEGIN
      SET ~value~ = 6
      FOR (row = 26; row < 40; row = (row = 26) ? row + 3 : row + 5) BEGIN
        SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~%value%~
        SET ~value~ = ~%value%~ + 1
      END
    END
    PATCH_IF (~%column%~ < 9) BEGIN
      SET_2DA_ENTRY 23 ~%column%~ 10 ~5~
      SET_2DA_ENTRY 24 ~%column%~ 10 ~5~
    END
    PATCH_IF (~%column%~ > 5) BEGIN
      SET ~value~ = 5
      FOR (row = 25; row < 39; row = (row = 25) ? row + 3 : row + 5) BEGIN
        SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~%value%~
        SET ~value~ = ~%value%~ + 1
      END
    END
    PATCH_IF (~%column%~ > 7) BEGIN
      SET ~value~ = 5
      FOR (row = 26; row < 40; row = (row = 26) ? row + 3 : row + 5) BEGIN
        SET_2DA_ENTRY ~%row%~ ~%column%~ 10 ~%value%~
        SET ~value~ = ~%value%~ + 1
      END
    END
    PATCH_IF (~%column%~ > 8) BEGIN
      SET_2DA_ENTRY 23 ~%column%~ 10 ~4~
      SET_2DA_ENTRY 24 ~%column%~ 10 ~4~
    END
    PATCH_IF (~%column%~ = 7) OR (~%column%~ = 8) BEGIN
      SET_2DA_ENTRY 20 ~%column%~ 10 ~4~
      SET_2DA_ENTRY 21 ~%column%~ 10 ~4~
      SET_2DA_ENTRY 22 ~%column%~ 10 ~5~
    END
    SET_2DA_ENTRY 27 ~%column%~ 10 ~6~
  END
BUT_ONLY_IF_IT_CHANGES
:-D

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: SET_2DA_ENTRY thoughts
« Reply #2 on: May 18, 2005, 05:10:23 PM »
Would anyone want this sort of thing, or is SET_2DA_ENTRY only used in psycho never-released devSin mods? :-)
Oh, I feel SOOO left out here. Yes, of course. If you build wildly complicated functions, it means I can break tweak more things.

In all seriousness, I can think of a number of places where I could use something like this. And devSin just posted candidate #1. :)
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #3 on: May 18, 2005, 05:11:56 PM »
I'll advocate the use of checking if the entry is going to be changed.
Dunno why, but apparently using READ_2DA_ENTRY and PATCH_IF to check if the particular entry is going to be changed speeds stuff up a lot  :)
example of my coding (please ignore use of WHILE instead of FOR construct):
Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~                 ~override/WEAPPROF.2DA~
SET "row"=3
WHILE ("%row%" < 35) BEGIN
      READ_2DA_ENTRY "%row%" 48 1 "talos"
      READ_2DA_ENTRY "%row%" 49 1 "helm"
      READ_2DA_ENTRY "%row%" 50 1 "lath"

      READ_2DA_ENTRY "%row%" (22+"%talostF%") 1 "ac"
      PATCH_IF NOT ( "%talos%" = "%ac%" ) BEGIN
      SET_2DA_ENTRY "%row%" (22+"%talostF%") 1 "%talos%"
      SET_2DA_ENTRY "%row%" (22+"%talostw%") 1 "%talos%"
      END

      READ_2DA_ENTRY "%row%" (22+"%helmtF%") 1 "ac"
      PATCH_IF NOT ( "%helm%" = "%ac%" ) BEGIN
      SET_2DA_ENTRY "%row%" (22+"%helmtF%") 1 "%helm%"
      SET_2DA_ENTRY "%row%" (22+"%helmtw%") 1 "%helm%"
      END

      READ_2DA_ENTRY "%row%" (22+"%lathtF%") 1 "ac"
      PATCH_IF NOT ( "%lath%" = "%ac%" ) BEGIN
      SET_2DA_ENTRY "%row%" (22+"%lathtF%") 1 "%lath%"
      SET_2DA_ENTRY "%row%" (22+"%lathtw%") 1 "%lath%"
      END
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #4 on: May 18, 2005, 05:28:33 PM »
A second equally easy option would involve "storing up" SET_2DA_ENTRYs and then writing them all at once. That would look something like:

Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  FOR (column = 4; column < 54; column = column + 1) BEGIN
    FOR (row = 32; row < 51; row = row + 1) BEGIN
      SET_2DA_ENTRY_LATER ~myvar~ ~%row%~ ~%column%~ ~0~ // no changes to file yet
    END
  END
  SET_2DA_ENTRIES_NOW 54 ~myvar~ // all changes take place here
BUT_ONLY_IF_IT_CHANGES

Where 'myvar' is some unique variable name used to store the "list" of entries. This has the advantage that it is easier to convert your existing code and that it might possibly be faster if you aren't changing every single entry. The first proposal is probably faster if you're really touching everything.

Since you all seem to care, why don't you vote on one and I'll code it up?

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #5 on: May 18, 2005, 05:39:02 PM »
My vote goes for updating all at once, as in the SET_2DA_ENTRY_LATER and SET_2DA_ENTRIES_NOW construct.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #6 on: May 18, 2005, 05:41:21 PM »
Both options update "all at once" (involving a single read/write pass of the 2DA file), but I'll assume you're still voting for the _LATER.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #7 on: May 18, 2005, 05:45:13 PM »
I shouldn't drink so much while posting, I may become totally incomprensible  :-\

But yes, I'm voting for the LATER / NOW option, since it's easier to adapt existing code and all  :)
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #8 on: May 18, 2005, 06:15:33 PM »
Blah, done, whatever. Old way:

Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  FOR (column = 4; column < 54; column = column + 1) BEGIN
    FOR (row = 32; row < 51; row = row + 1) BEGIN
      SET_2DA_ENTRY ~%row%~ ~%column%~ 54 ~0~
    END
  END
BUT_ONLY_IF_IT_CHANGES

unmarshal TLK                    0.201
process_patch2                   3.255
TOTAL                            3.786

New way:

Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  FOR (column = 4; column < 54; column = column + 1) BEGIN
    FOR (row = 32; row < 51; row = row + 1) BEGIN
      SET_2DA_ENTRY_LATER ~_w~ ~%row%~ ~%column%~ ~0~
    END
  END
  SET_2DA_ENTRIES_NOW ~_w~ ~54~
BUT_ONLY_IF_IT_CHANGES

unmarshal KEY                    0.060
unmarshal TLK                    0.171
TOTAL                            0.411

Someone else gets to write this one up. Note that if you pick "myvar" as your variable, it should either be undefined or 0 before the first use of _LATER, WeiDU is free to change all variables with the prefix "myvar" to arbitrary values, and you are not allowed to change/touch them. WeiDU will reset myvar to 0 after the _NOW.

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #9 on: May 18, 2005, 06:37:23 PM »
"myvar" is ~_w~ in your example, right (I'm just hoping that it's not part of the syntax - yucky)?

Also, is there some magical limit to this, or can I do something hideously retarded (if the feature exists, you may as well use it, no?) like this:
Code: [Select]
COPY_EXISTING ~EFFTEXT.2DA~ ~OVERRIDE~
  SET_2DA_ENTRY_LATER ~myVar~ 0 2 3 ~14662~
  SET_2DA_ENTRY_NOW ~myVar~ ~whereIsThisMagical54ComingFrom~
BUT_ONLY_IF_IT_CHANGES
As the first and only person (I think) to actually find a use for BNOTting values, you know I'm gonna. (Unfortunately, there's not much call to square values or do some other simple arithmetic operations, so bit-shifting remains unused.)

EDIT: oh, and where is the magical 54 coming from. It's been in all your examples here, and I can't figure it out (is it the required column count, some limit, the number of seconds until you explode, etc.).
« Last Edit: May 18, 2005, 06:45:09 PM by devSin »

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #10 on: May 18, 2005, 06:43:59 PM »
According to my guesses, 54 is the coloumn count, as in

SET_2DA_ENTRY 0 1 2 3
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #11 on: May 18, 2005, 06:44:42 PM »
Quote
(I'm just hoping that it's not part of the syntax - yucky)?

"I find your lack of faith disturbing."

Yes, myvar is _w in the example.

Code: [Select]
SET_2DA_ENTRY_LATER ~myVar~ 0 2 3 ~14662~

I'm not sure what magical limit you're talking about, but _LATER only takes 4 arguments (variable, row, column, value) and you've given it five, so that won't work.

Code: [Select]
SET_2DA_ENTRY_NOW ~myVar~ ~whereIsThisMagical54ComingFrom~

The 54 comes from your example code. It's the "required minimum column count" or however I explained that hideousness in SET_2DA_ENTRY.

I'm not sure what limits you were worried about. Can you be a little more specific?

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #12 on: May 18, 2005, 06:46:23 PM »
Maybe the limit you're worried about has to do with the 54. In _LATER and _NOW, every SET_ must use the same column-count-thingy. So the 54 has been moved out of the SET and into the _NOW.

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #13 on: May 18, 2005, 06:54:46 PM »
I don't know what limits I was talking about (I confess to not really paying that much attention to the example). I guess I was checking to make sure it does what I think (i.e., it's a universal action that buffers the changes and then dumps them out at once, rather than having each SET_ performed individually), and that it could be used to SET_2DA_ENTRY_LATER ~stuff~ SET_2DA_ENTRY_NOW ~theStuff~ (even though there's no worldly reason).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #14 on: May 18, 2005, 06:57:06 PM »
Everything you seem to be saying is true. It's a universal action (that only works on 2DA files) that just buffers up the writes and performs them later in one fell swoop. It should work for 0 entry changes, 1 entry change, or 1000 entry changes.

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #15 on: May 18, 2005, 07:01:01 PM »
SET_2DA_ENTRY_LATER ~variable~ entryRow entryColumn ~newValue~

This takes an entry at row,column and gives it a new value. What is "variable" doing here? In your previous post, you wandered off on "prefix," so I'm guessing that WeiDU is creating separate variables for each change and magically constructing a 2DA patch for SET_2DA_ENTRIES_NOW? Is there really a need to have a user-defined variable (versus some WeiDU make-one-for-me like %projectileName% after using ADD_PRO)?

Anyway, I'm sure I'll figure it out with a little hands-on experience.

Quote
"I find your lack of faith disturbing."

Yes, myvar is _w in the example.
I don't think I'll ever be able to pass up an opportunity to poke fun at the WeiDU syntax. Sorry.

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #16 on: May 18, 2005, 07:05:37 PM »
Yes, WeiDU creates a bunch of variables to store the changes. If you do _LATER myvar row1 col1 val1 then myvar0r=row1, myvar0c=col1 and myvar0v=val1, etc. I can't pick one myself or use a global one without messing with possible INNER_ACTIONs (or whatnot). Past experience indicates that if I don't make it general someone will immediately decided that they can't live without invoking it recursively. :-) Think of myvar as the name of the linked list I'm storing the updates in.

Yeah, I hate the syntax too.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #17 on: May 18, 2005, 08:04:11 PM »
Just a lil' problem: SET_2DA_ENTRY_LATER / SET_2DA_ENTRIES_NOW cannot work on string, EG

SET_2DA_ENTRY_LATER ~_#_#_#luabbr~ 12 1 ~FMT~
SET_2DA_ENTRIES_NOW ~_#_#_#luabbr~ 2

will whine because he cannot convert FMT to a number.

If this one is a big problem to correct (as I believe it is, sadly) I'll avoid that, not a big deal  ;)

BTW: that's very fast anyway, kudos!
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #18 on: May 18, 2005, 09:03:24 PM »
Quote
cannot work on string

Actually (check the resulting file) it should work fine with strings, I just forgot to disable that message. The blaring "cannot convert" warning won't be there next version.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #19 on: May 18, 2005, 09:12:38 PM »
Quote
cannot work on string

Actually (check the resulting file) it should work fine with strings, I just forgot to disable that message. The blaring "cannot convert" warning won't be there next version.

My damned laziness. Even better then!
Regarding that blaring 27* speeding, it appears only if I use cygwin, not on a standard dos shell. And no, I didn't recompile WeiDU or anything. Weird (but, hey, the files were correct, so it's not a big problem  :D

By the way,
Code: [Select]
int main () {
int i;
for (;;) printf("You Rock!!!\n");
return 0;
}
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #20 on: May 19, 2005, 01:39:48 AM »
Keep in mind that required column count is no longer honored for SET_LATER, so most existing patches will be off by at least 3 (using _Later, the row should always be the line number - 1). Meaning the Wes' "new way" wouldn't even work
Code: [Select]
COPY_EXISTING ~WEAPPROF.2DA~ ~OVERRIDE~
  FOR (column = 4; column < 54; column = column + 1) BEGIN
    FOR (row = 32; row < 51; row = row + 1) BEGIN // could do row = 35; row < 54 here  --OR--
      SET_2DA_ENTRY_LATER ~_w~ ~%row%~ ~%column%~ ~0~ // could do ~%row%~ + 3 here
    END
  END
  SET_2DA_ENTRIES_NOW ~_w~ ~54~ // this isn't actually a variable, so cannot be ~%_w%~ (unless that's the actual name of the "myVar" value used in _Later)
BUT_ONLY_IF_IT_CHANGES

Quote
I just forgot to disable that message.
For now, those inclined can just add "eval_pe_warn := false;" to Patch2DALater and re-compile
Code: [Select]
  | TP_Patch2DALater(str,r,c,value) ->
      let row = (eval_pe game r) in
      let col = (eval_pe game c) in

      eval_pe_warn := false ; (* stupid messages be gone *)
      let value = (*... and so on*)
in case Wes disappears for any length of time.

If you happen to stop by in the near future to check on the fallout Wes, I'm *begging* you to change Patch2DANow to the newer "let's not re-format the entire 2DA" behavior. My original post was going to be that PatchLater and PatchNow didn't work at all; the re-formatting made it far too difficult to tell that it was simply off by 3 (go-go no required column count, I guess).

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #21 on: May 19, 2005, 02:00:24 AM »
Quote
Keep in mind that required column count is no longer honored for SET_LATER

I think that it is, but I guess it could be buggy. That never happens :-). Looking at the logic ... ah, it is buggy. Changing 1349-ish to something like:

Code: [Select]
          Buffer.add_char buf '\n' ;
          if this_col_size >= req_col then incr this_line ;

May well fix it.

Quote
I'm *begging* you to change Patch2DANow to the newer "let's not re-format the entire 2DA" behavior

I'll accept patches for it if someone else wants to do it. It would take way more effort (and, as second-order consideration, I've never believed in it). You can see the code for the behavior you want near 1418 -- a direct adaptation would involving reforming the buffer O(# updates) times, which would presumably remove the speed advantage.

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #22 on: May 19, 2005, 02:35:00 AM »
Quote
May well fix it.
I'll check this before going to bed. Now that I just changed all the code to account for the "no more required count" behavior, of course... ;)

Quote
reforming the buffer O(# updates) times, which would presumably remove the speed advantage
You can't have your cake and not throw up, is it? The speed improvements are so substantial that I'll definitely live with the reformatting (to give a general idea, simply updating the 10 or so SET_2DAs in loops in my Tp2 further reduced execution from TOTAL 243.600 in v180 to TOTAL 218.167).

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: SET_2DA_ENTRY thoughts
« Reply #23 on: May 19, 2005, 02:48:59 AM »
Limited testing reveals that it does restore the intended behavior:
Code: [Select]
COPY_EXISTING ~ALIGNMNT.2DA~ ~OVERRIDE~
  FOR (row = 10; row < 15; row = row + 1) BEGIN // had to change this to row=13; row<18 with default v180
    SET_2DA_ENTRY_LATER ~lawfulNeutral~ ~%row%~ 2 ~1~
    SET_2DA_ENTRY_LATER ~lawfulEvil~ ~%row%~ 3 ~1~
  END
  SET_2DA_ENTRIES_NOW ~lawfulNeutral~ 10
  SET_2DA_ENTRIES_NOW ~lawfulEvil~ 10
BUT_ONLY_IF_IT_CHANGES
With default v180, the loop had to be row=13;row<18; with the change to TP_Patch2DANow, the original row=10;row<15 patch works as expected. Many thanks for the late-night assistance.

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: SET_2DA_ENTRY thoughts
« Reply #24 on: May 19, 2005, 03:15:27 AM »
Quote
You can't have your cake and not throw up, is it?

I can't think of any obvious, easy way to do it. Loosely, when I parse the 2DA file into a two dimensional array (or list of lines, where each line is an array of words) I throw away the original position/whitespace information. SET_2DA_ENTRY gets around this by re-reading the file, searching for the cell you changed, splitting the file (as a string) into strings before and after that cell, and then pasting the three strings together (the before-bit, your new value, and the after-bit). The searching and the string concatenation both take time, and doing that whole process once per update would get you back to SET_2DA_ENTRY's performance, more or less.

Quote
Limited testing reveals that it does restore the intended behavior:

Glad to hear it.

Code: [Select]
COPY_EXISTING ~ALIGNMNT.2DA~ ~OVERRIDE~
  FOR (row = 10; row < 15; row = row + 1) BEGIN // had to change this to row=13; row<18 with default v180
    SET_2DA_ENTRY_LATER ~lawfulNeutral~ ~%row%~ 2 ~1~
    SET_2DA_ENTRY_LATER ~lawfulEvil~ ~%row%~ 3 ~1~
  END
  SET_2DA_ENTRIES_NOW ~lawfulNeutral~ 10
  SET_2DA_ENTRIES_NOW ~lawfulEvil~ 10
BUT_ONLY_IF_IT_CHANGES

I may be misreading your logic, but you could probably get away with:

Code: [Select]
COPY_EXISTING ~ALIGNMNT.2DA~ ~OVERRIDE~
  FOR (row = 10; row < 15; row = row + 1) BEGIN // had to change this to row=13; row<18 with default v180
    SET_2DA_ENTRY_LATER ~lawful~ ~%row%~ 2 ~1~
    SET_2DA_ENTRY_LATER ~lawful~ ~%row%~ 3 ~1~
  END
  SET_2DA_ENTRIES_NOW ~lawful~ 10
BUT_ONLY_IF_IT_CHANGES

... and shave off a bit more time. You don't need a separate variable for each different value stored. I'm glad to hear that it seems to be working performance-wise (10% isn't bad).

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: