SMB - Server Map Browser

[release]
Server Map Browser - AKA SMB

What is it?
-SBM is an addon which gives you an easy to use interface to find and switch the map of the server you are playing on

How is this different from the main menu map selector?
-SBM will work in multiplayer. If you are an addon on the server it is installed on, you can bring up the menu and select which map to play from the list.

But what if the server doesn’t have the map I pick?
-This well never happen. SBM sends the lists of maps from the server to the client, so you only see what maps the server has, not which you have on your computer.

Does the search bar actually work?
-You bet your sweet ass it does.

What are the different sorting options?
-SBM provides you with four different options to sort the list
–The first is the default sort. This is how the game retrieves the servers maps without any modification. It appears to be organized somewhat by game, but some of the GMod maps are mixed in with the others. Not entirely sure why.
–The second is Alphabetical - Ascending. As the name would imply, it sorts the maps by their names alphabetically, starting with A and ending with Z
–The third is Alphabetical - Descending. Same as the second, only the reverse.
—(Note: In the menu I misspelled “Descending” (it’s missing its S) but I don’t feel the need to reupload just for a typo. If I make any other adjustments I will include the fix for this)
–The third is Magic. Magically sorts the list differently every time (randomly scrambles the table)

Are there any drawbacks to this?
-It adds a second or two onto your initial spawn into the server that has the addon installed. This is due to sending the tables from the server to the client so they have the required data.
-Loading may be slower with a not so great computer and will also take longer the more maps you have.
-With about 295 maps installed I only have a second or two of extra loading onto my Initial Spawn.
-When you load in GMod may go “Not Responding” for a second but just wait and it will load (if it doesn’t it’s not fault of SBM)

Are there any known bugs?
-None that I know of. Please let me know if you find any.

How do I open the menu?
-Bind a key to “SelectMap”

Images are in the download link

Download:
http://www.garrysmod.org/img/?t=dll&id=121614
[/release]

Awesome work!

This is really cool. I’m glad someone finally made this an independent addon. I have a few criticisms, instead of sending the table of maps to every player on Initialspawn, why don’t you have it stream the maps the the player when he first opens, and another slowdown may or may not be due to caching loads of materials at once, why don’t you do that over a period of one second or so?

I opted on loading them on InitialSpawn so you could just deal with the lag once. All the methods that I tried ended up making the panel take forever to load if I loaded it when I opened the frame and I figured if I just tacked it onto the spawn people wouldn’t notice much.
I also thought of progressively loading them, but I really have no idea how I would go about doing that.
I am using datastream to send the map list (which for me is currently 295 maps, but others will have much larger tables) but I don’t think that switching to umsgs will really net me that much of a bonus in speed, not to mention breaking down the tables per umsg then reassembling them would be annoying.

If you know how to progressively load it I would be interested in implementing something like that to make this run smoother.

Well you can the “SelectMap” concommand to be a serverside one and once it’s ran check if the play has been sent the maps if not then datastream and give the client a warning about it. Once the datastream is completed open the panel.

To slowly cache the materials i suggest you have one static “no material” material for the start, then when all the separate panels are created (i’m assuming you are using your own paint function) save the “no material” material as panel.mat and save the panels in a table, then as you go through and slowly and cache the materials, change the panel.mat to the new one.

May be possible. I’d have to somehow add a flag to the datastream to whether or not its the original stream or the update stream. You CAN update the list mid-game if you add a new map, but that can be removed, it’s not essential.

I don’t really see how that would be any faster, but I can try it.

Change it so an update if you add a new map is a usermessage and the instant loading of lots of materials is indeed a huge slowdown.
[lua]
local mats = file.Find(“materials/trails/*.vtf”,true)
local matlist = {}

local T = SysTime()
for i = 1 , #mats do
matlist[#matlist + 1] = Material(mats*)
end
print(SysTime() - T , #matlist) --> 1.38671875 seconds 173 materials
[/lua]

OK, I optimized it a bit, but at this point I can’t tell if its this lagging me or just the addons that I have installed (just my work).

The icons are now initially set at the noicon material and are progressively set (as they’re cached) to the appropriate icon from the map.
I also changed up how and when the map list is sent - On the client on InitPostEntity there is now a concommand being sent to request the map list, which is then returned with a datastream, but its sent just a bit after InitPostEntity, not on InitialPlayerSpawn so you shouldn’t see much of the lag from it.

Doing a little more testing to see if I can make it any better.

That InitPostEntity concommand thing was the same thing as i did for another tool, imo its a good way to do it.

Yeah, it’s how you should handle things in general, I think. Its how most proticals behave - a request and response system going back and forth.

With everything that I’ve added optimization wise, there is still a second or two of hang tacked onto InitialSpawn that I can’t seem to get rid of. Its either have it here or whenever you open the panel.

What would you guys like to see more? Lag on panel open or lag on spawn (which typically is slow anyway) with an instant panel?

I would put out the more optimized version right now but there was another feature I was going to put in but I can’t for the life of me remember what that was.