Skip to content

File browser V2#512

Closed
marchc1 wants to merge 31 commits intowiremod:masterfrom
marchc1:file-browser-v2
Closed

File browser V2#512
marchc1 wants to merge 31 commits intowiremod:masterfrom
marchc1:file-browser-v2

Conversation

@marchc1
Copy link
Copy Markdown
Contributor

@marchc1 marchc1 commented Jun 28, 2025

This is a rewrite of the file browser that I've been wanting to do for three years at this point but never got around to actually doing. It is still a WIP, I only got started rewriting almost everything today, but I figured I'd put it up as I work on it.

This pull request works off the initial gripes from #467 ["Make browser loading faster"]. AdvDupe2's file browser (quite frankly, any file browser in Wiremod's suite) is insanely slow. For me, even with the work I did in #467, it still takes about 10 seconds of very-laggy time to fully load the browser. Not to mention the browser tanking my FPS to nearly 20 while active, if not lower sometimes. And this isn't just anecdotal - I've seen streams of my friends AdvDupe2 taking 15+ seconds to load with large enough dupe folders.

The work I've done here resolves both problems - the FPS drop is practically non-existent. The browser now is almost entirely separate from VGUI, while still using Derma skin functions and values to render most of the menu.

  • All UI logic is done in Lua-land with initial C function calls to retrieve data at the start of each frame.
  • The browser then checks if the current state is dirty (triggered by first frame, subsequent expand/collapse events).
  • If the state is dirty, it will rebuild a sequential array of all currently potentially visible nodes.
  • Since every node has the same height, the top-most node can be determined simply by Scroll / NodeHeight and the bottom-most by (Scroll + CanvasHeight) / NodeHeight.
  • The browser then works with a span from StartIndex -> EndIndex, with the respective above values. It performs mouse-pos-in-bounds testing on each visible node and its expander, along with checking the mouse state.
  • The current state then is somewhat like this:
    • Mouse (Cursor, scroll, mouse buttons down, clicked, released)
    • Panel width, height
    • Node state (Current scroll, start-end index calculations, hovered node, depressed node, released node, expander depressed/released, etc)

That's just what it does to minimize runtime lag - for initial lag:

  • The browser will only load paths it explicitly is requested to load (so the initial advdupe2 folder gets loaded for example, but then nothing else will be loaded until the advdupe2 folder is reopened.)
  • The lack of constant VGUI calls, Panel __indexes, VGUI adds, etc. I don't think I need to explain why this makes it faster

There's also a lot of API restructuring going on under the hood, to expose the ability to create folders underneath the Adv. Dupe 2 tab. I've abstracted away most of the operations to IRootFolder implementations (advdupe1 and advdupe2 folders now use this implementation). Other addons could totally add their own IRootFolder implementations if they wanted to provide some shared advdupe2 folder or something. Kind of niche but it was something that I think @LiddulBOFH wanted for his gamemode a while back, and that logic desperately needed refactoring anyway.

Please do not review this in full or critique it in full until I've asked for a review - or at least keep in mind that this is not the final product at all. There are still a ton of fragments of V1 left in there and almost everything doesn't work right now, but the basics do work and I wanted to show a proof of concept

Also, as a proposal in general, I also wouldn't mind this file browser being pulled into other Wire and unrelated projects - I would actually like to see it adopted once it reaches its stable form in the Wiremod file browsers too. We could also use this for the sound browser DTree which is also hilariously slow for the same reasons.

marchc1 added 4 commits June 28, 2025 00:38
Needed to define some enumerations, I figured I would do a bit more while I'm at it
will remove when PR is complete
There are still a lot of fragments of V1 left behind and most things don't work yet, but the basics work and the proof-of-concept at how fast this can be is there

Some things here refer to "immediate" - the original idea was a lot more immediate-mode style, but this is more retained in Lua-land than anything at this point
@marchc1
Copy link
Copy Markdown
Contributor Author

marchc1 commented Jun 28, 2025

Also the huge spacing in-between some parts of the code was my coping mechanism of segmenting things out when I got started (couldn't do-end a lot of it), I'll remove that at the end

@marchc1
Copy link
Copy Markdown
Contributor Author

marchc1 commented Jun 28, 2025

The big things left to do are

  • Restore other context operators
  • Add some form of searching again
  • Add an API on BROWSER for spawning text-prompts, etc
  • Remove some of the hackiness - the SetTall detours in particular that store static values is really icky
  • Maybe some more animation work like I had on the previous iteration?
  • Separate advdupe2-specific logic and data into its own segment so the file browser code can be pulled out easily
  • Cleanup my mess

Comment thread lua/advdupe2/cl_file.lua
Comment thread lua/advdupe2/file_browser.lua Outdated
Comment thread lua/advdupe2/cl_file.lua
Comment thread lua/advdupe2/file_browser.lua Outdated
@Grocel
Copy link
Copy Markdown
Contributor

Grocel commented Jul 2, 2025

I did not looked at the file browser code yet. But I checked the changes in code style which were fine so far I can tell.

@thegrb93
Copy link
Copy Markdown

thegrb93 commented Jul 2, 2025

People ignore linting = Bad
People fixing linting = Also bad?

Invalid take for me.

You maintain linting on code you touch, not reformat an entire file. If you want to do a linting pass, do it in a seperate PR.

@thegrb93
Copy link
Copy Markdown

thegrb93 commented Jul 3, 2025

The other reason is it makes an already hard to review PR even harder.

@marchc1
Copy link
Copy Markdown
Contributor Author

marchc1 commented Jul 10, 2025

Will try to get back into this sometime this weekend/next week.
The major things left are

  • Autosave
  • Searching

@marchc1
Copy link
Copy Markdown
Contributor Author

marchc1 commented Jul 12, 2025

Also; developer style concerns

@dvdvideo1234
Copy link
Copy Markdown
Contributor

Neat Cant wait to see what it will look like :D

@Astralcircle
Copy link
Copy Markdown
Contributor

You also probably want to update your branch to the latest one to see linter warnings

Comment on lines +1523 to +1547
local DescParent = Prompt:Add("Panel")
DescParent:Dock(TOP)
DescParent:DockMargin(0, 4, 0, 0)
DescParent:SetSize(20, 32)
DescParent:SetPaintBackgroundEnabled(false)
DescParent:SetZPos(10000)

local Cancel = DescParent:Add("DImageButton")
Cancel:Dock(RIGHT)
Cancel:SetSize(20)
Cancel:SetStretchToFit(false)
Cancel:SetImage("icon16/cancel.png")

local Delete = DescParent:Add("DImageButton")
Delete:Dock(RIGHT)
Delete:SetSize(24)
Delete:SetStretchToFit(false)
Delete:SetImage("icon16/bin.png")

local Name = DescParent:Add("DLabel")
Name:Dock(FILL)
Name:SetDark(true)
Name:SetText("Are you sure to want to delete\n" .. Node.Path .. "?")
Name:SetAutoStretchVertical(true)
Name:SetZPos(1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This styling looks kinda strange

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale as there haven't been any changes in the past month. It will be closed in 15 days.

@marchc1
Copy link
Copy Markdown
Contributor Author

marchc1 commented Oct 28, 2025

I tried to rebase this on master, but it really did not work. So I'm trying again on a different branch based on master. Will finish implementing whats left as well. #525

@marchc1 marchc1 closed this Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants