• 0

    posted a message on Removing WoW escape sequences from a string
    You're right that each match will generate new strings for the color code and pipes, but because identical strings are re-used in Lua's string pool, this technique doesn't generate nearly as much garbage. It works especially well when the number of unique color codes you might encounter is limited, such as with syntax highlighted tokens.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Removing WoW escape sequences from a string
    Yep, forgot to mention that.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Removing WoW escape sequences from a string
    Rather than replacing all escaped pipes with "|!", you could rewrite your patterns to match "(|*)|r" and then count the string length of the pipes sub-match. If the length is even (#pipes % 2 == 0), then the control code is active and should be replaced by just the pipes sub-match. This technique avoids making a complete copy of your edit box's contents escaped with exclamation points.

    Feel free to gut any useful algorithms from _DevPad; It's already fairly well-optimized and seems to share a lot of functionality with your Grease Goblin prototype.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Getting current MiniMap tiles.
    Here's what I've learned from a map project of my own. For clarity, I refer to the contents of the world map as "map areas", and the 3D world geometry datafiles as "maps".

    You can get the player's map-relative (as opposed to map-area-relative) position with the following functions:
    --- @return ID of the current map, even if it has no map areas.
    local function GetCurrentMapID ()
            return ( select( 8, GetInstanceInfo() ) );
    end
    --- @return Map (X, Y) coordinate of UnitID based on the current map area.
    local function GetPlayerPoint ( UnitID )
            local X, Y = GetPlayerMapPosition( UnitID );
            if ( X ~= 0 and Y ~= 0 ) then -- Player appears on the current map area
                    local MapID, Y, X = GetWorldLocFromMapPos( X, Y );
                    if ( MapID == GetCurrentMapID() ) then -- Not a virtual map transformation
                            return -X, Y; -- X-axis is flipped in map coordinates
                    end
            end
    end
    [FONT="Courier New"]GetPlayerPoint[/FONT] operates based on the selected map according to the API, i.e. [FONT="Courier New"]SetMapByID[/FONT]. Any map that shows the player's arrow on it should yield valid coordinates.

    All game maps range from -17066.66656 yd to 17066.66656 yd on each side, divided into a 64x64 grid of minimap tiles. Therefore the following function should translate a player's point in yards to their position in minimap "tile coordinates":
    local MAP_SIZE, MAP_CHUNKS = 34133.33312, 64;
    --- @return Coord converted from map-relative yards to a minimap tile offset.
    local function YardsToTile ( Coord )
            return ( Coord / MAP_SIZE + 0.5 ) * MAP_CHUNKS;
    end
    --- @return Tile offsets corresponding to map-relative position (X, Y).
    local function GetTileOffsets ( X, Y )
            return YardsToTile( X ), YardsToTile( -Y ); -- Y-axis increases downwards
    end


    [FONT="Courier New"]GetTileOffsets( GetPlayerPoint( "player" ) )[/FONT] should return a floating point value between 0 and 64, mapping the player to the grid of minimap tiles. I may have misremembered the Y-axis direction for the image tiles, but that should be an easy fix if everything appears inverted.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Possible bug with taint but not sure
    Blizzard protected UseEquipmentSet in combat, but forgot to move the EQUIP_SET slash command from SlashCmdList to SecureCmdList.
    Posted in: Lua Code Discussion
  • 0

    posted a message on frame level issues
    I think you're right about frames trying to compact themselves to remove unused framelevels. I just did a test with two movable, toplevel frames in the same strata, and any time they passed over eachother, the one I was currently dragging would change its framelevel to jump above the other.

    Imagine two frames, A and B, like I tested with. A starts at level 10 with one child at 11, and B starts at 20 with a child at 21. On the same strata, another frame has level 3, with no children. No matter what levels A and B are at, dragging the lower over the higher will cause a recalculation to compact unused frame levels.

    Using the example above, dragging B over A will do nothing since B is already higher. Dragging A over B will reshuffle levels for all frames on that strata though. B's frame level will become 4, just above the background frame at 3. B's child will maintain its relative level of +1 to B, becoming level 5. Frame A then gets moved just above B's highest child, to level 6, and so on for all frames on that strata. Realistically, even the background frame at level 3 may have been dropped down a few levels if nothing was below it.

    Oddly enough, the compacting algorithm doesn't have any limitation on changing frame levels. It can jump from 500 to 1, and properly recalculate child frame levels with a difference far greater than 128.
    Posted in: Lua Code Discussion
  • 0

    posted a message on frame level issues
    Frame methods like :StartMoving or :StartSizing automatically enable the user-placed flag. You could either disable the flag during PLAYER_LOGOUT, or disable saving that frame's position to the layout cache with :SetDontSavePosition(true).
    Posted in: Lua Code Discussion
  • 0

    posted a message on [idea] Read ID Character Name on Login
    I had a similar idea, to have an addon add your RealID friend's character to your normal WoW friends list temporarily. That way their names would get highlighted in the game-world like normal friends.

    I'm too lazy though. :P
    Posted in: Addon Ideas
  • 0

    posted a message on Grid
    If I remember right, UnitInRange doesn't work for dead units and under a bunch of other situations too. His setup is probably using it for a 38 yd range check.
    Posted in: Grid & Grid2
  • 0

    posted a message on Local Variable Optimization
    I benchmarked this for some math-heavy OnUpdate rendering code, and upvalues were definitely faster than pushing values to the stack, but only by milliseconds over thousands of calls. Of course, this makes the code hard to maintain, ugly, and breaks recursion. Use it as a last resort, if ever.
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.