Ascii Map mini console window

All and any discussion and development of the Mudlet Mapper.
Post Reply
User avatar
Omit
Posts: 190
Joined: Sun Aug 01, 2010 10:54 pm
Location: Middle Earth
Contact:

Ascii Map mini console window

Post by Omit » Tue Nov 29, 2011 4:02 am

The Following code will display an ascii style map in a console window at the upper right corner of the main window. (Thought was it would be nice to be able to display it without setting the mapper into grid mode... so you can still edit the map in the mapper window)
Code: [show] | [select all] lua
createMiniConsole( "ASCIIMAP", 0, 0, 600, 600 ) 
setMiniConsoleFontSize("ASCIIMAP", 16)
Fx,Fy = calcFontSize(16)
resizeWindow("ASCIIMAP",15*Fx,11*Fy)

function Amap(roomid)
local ColorKey = getCustomEnvColorTable() 
local Caa= getRoomArea(roomid) 
local Cxx,Cyy,Czz = getRoomCoordinates( roomid )
local CurLo
local WindowWidth, WindowHeight = getMainWindowSize();
moveWindow("ASCIIMAP",WindowWidth-(15*Fx)-15,2)--WindowWidth-40*Fx-18,0)
hideWindow("ASCIIMAP")
clearUserWindow("ASCIIMAP")
local xx,yy,tt,r,g,b
yy=Cyy+5
while yy >= Cyy-5 do
xx=Cxx-7
while xx <= Cxx+7 do
-- resetFormat()
CurLo = getRoomsByPosition(Caa, xx,yy,Czz)
  if CurLo[0] then
      local cc =  getRoomEnv(CurLo[0]) 
      r,g,b = ColorKey[cc][1],ColorKey[cc][2],ColorKey[cc][3]
      tt = getRoomChar(CurLo[0])
--		echo(tt)
    if tt=="" then
      tt = "O"
    end
        if xx == Cxx and yy == Cyy then
          setBgColor("ASCIIMAP",178,34,34 )
        else
          setBgColor("ASCIIMAP", 0, 0,0 )
        end
      setFgColor("ASCIIMAP",r,g,b)
      echo("ASCIIMAP",tt)
  else
   setBgColor("ASCIIMAP", 0, 0,0 )
   echo("ASCIIMAP"," ")
  end
xx=xx+1
end--while
echo("ASCIIMAP","\n")
xx=1
yy=yy-1
end--while
showWindow("ASCIIMAP")
end--func
I am not completly happy with this. It renders pretty slowly. (that is why it only displays a grid 15x11)
The slowest part of the code is getRoomsByPosition. If anyone has any thoughts of how to improve the preformance of this, I would be greatfull. (is there a way to localize the getRoomsByPosition function? grasping at straws.... swear I have had similar maps running much better than this does.)

User avatar
Vadi
Posts: 4727
Joined: Sat Mar 14, 2009 3:13 pm

Re: Ascii Map mini console window

Post by Vadi » Tue Nov 29, 2011 7:16 am

Pretty interesting :)

You could not move the miniconsole each time, localize functions you use more than once to improve performance

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Ascii Map mini console window

Post by chris » Wed Nov 30, 2011 4:20 am

You could do the getRoomsByPosition for the whole area and store it in an [x][y][z] structured table to make transversing an area easier. getRoomsByPosition currently iterates over every room in the area and populates the list with matching entries, so you are calling this loop a lot. getRoomsByRect(upper,left,width,height) might be a cool feature to select rooms in a rectangle for larger area queries. That could feed into room collision scripts too perhaps.

User avatar
Omit
Posts: 190
Joined: Sun Aug 01, 2010 10:54 pm
Location: Middle Earth
Contact:

Re: Ascii Map mini console window

Post by Omit » Wed Nov 30, 2011 6:40 am

All good ideas. I made all the changes Vadi suggested and it did improve preformance considerably. Unfortunetly it is still slow. In order to make it usable I would need to do as chris just suggested and store an area in a lua table. Some of my earlier mappers used a nested Lua table to store rooms and it was very fast drawing the map with this method. (.... table should be t[z][x][y] tho.... don't want to check for z that many times)
I have not yet decided if I am going to use this or not.... if I do, I will post an updated version.

I like the getRoomsByRect idea, I can see many uses for such a function .... maybe for version 3.

User avatar
Vadi
Posts: 4727
Joined: Sat Mar 14, 2009 3:13 pm

Re: Ascii Map mini console window

Post by Vadi » Wed Nov 30, 2011 10:29 am

Take a look at http://www.lua.org/gems/sample.pdf (the book itself is also very good, I own it and recommend it), "Reduce, reuse, recycle" chapter - it advises to use 3 tables for the coordinates, saves on memory most (and thus gc cycles later).

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests