thebigsleepjoe / TTT-Bots-2

Player bots for Garry's Mod TTT
Creative Commons Attribution Share Alike 4.0 International
11 stars 4 forks source link

[FEATURE] auto-nav-bake #43

Closed EntranceJew closed 5 months ago

EntranceJew commented 9 months ago

What is the new feature? (required)

when bots should spawn, attempt to run nav_generate_cheap_expanded from Navmesh Optimizer, because it's cheap and inoffensive enough that it's accurate like 99% of the time

if you do include any logic for that then you will get slightly better navmeshes if you provide player spawn positions as seeds as I have done in my side addon:

local bigNegativeZ = Vector( 0, 0, -3000 )
local function snappedToFloor( pos )
    local traceDat = {
        mask = MASK_SOLID,
        start = pos,
        endpos = pos + bigNegativeZ
    }

    local trace = util.TraceLine( traceDat )
    if not trace.Hit then return nil, nil end

    local snapped = trace.HitPos
    if not util.IsInWorld( snapped ) then return nil, nil end

    return true, snapped, trace
end

hook.Add("navoptimizer_comprehensiveseedpositions_postbuilt", "NavMeshGen_postbuilt", function(donePositions)
    local spawnPoints = plyspawn.GetPlayerSpawnPoints()
    for _, spawn in ipairs(spawnPoints) do
        local didSnap, pos = snappedToFloor(spawn.pos)
        if didSnap then
            donePositions[#donePositions + 1] = pos
        end
    end
end)

Purpose/motivation (required)

my server is a testing server largely, so not having any players on at all breaks things, including the ability to conduct a mapvote since a round never starts. this isn't the most intelligent way to handle things but even so, if a map doesn't have a nav it is still a better experience to try and make one for a player when one joins

How would you add this feature? (optional)

wherever that print about navmeshes happens, make it do this instead if navmesh optimizer exists

Context

navvmesh optimizer's incremental one might not be the perfect navmesh but it is surprisingly competent for someone like me who would never bother to go in and even begin authoring one for all the maps we have in rotation if it didn't cover 99% of the problem areas for me

and more importantly it doesn't require a map reload and a bunch of extra shit that could potentially disable a whole server as it generates

thebigsleepjoe commented 8 months ago

Will be tackled around the same time as #18 -- actually sounds pretty easy to run an incremental generation if the optimizer addon is installed. Thank you for providing a snippet and some extra background, very helpful.

thebigsleepjoe commented 8 months ago

I'm thinking of having a feature like this be a cvar that is automatically enabled (e.g., "ttt_bot_nav_auto 1") and it will generate a navmesh for the map on the first load. Thoughts?

EntranceJew commented 8 months ago

sounds good to me, I appreciate it :)

On Sat, Mar 23, 2024, 6:31 PM thebigsleepjoe @.***> wrote:

I'm thinking of having a feature like this be a cvar that is automatically enabled (e.g., "ttt_bot_nav_auto 1") and it will generate a navmesh for the map on the first load. Thoughts?

— Reply to this email directly, view it on GitHub https://github.com/thebigsleepjoe/TTT-Bots-2/issues/43#issuecomment-2016630868, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLSMTCVEFNVYHPVD2VXDPLYZYGF3AVCNFSM6AAAAABDYW4BZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJWGYZTAOBWHA . You are receiving this because you authored the thread.Message ID: @.***>

thebigsleepjoe commented 5 months ago

Since navmesh optimizer requires sv_cheats to be 1, which is a protected cvar. This is not possible to perform automatically.

Tried:

The worst part is that I only discovered this fact after writing 98% of the code.... haha....

thebigsleepjoe commented 5 months ago

In-progress, working on similar command which can be placed between sv_cheats, as such:

sv_cheats 1; ttt_bot_nav_gen; sv_cheats 0;

thebigsleepjoe commented 5 months ago

Unfortunately, I've discovered that even this ^ is impossible. Below is the only working method with the new concommand I'll be adding in v1.3:

  1. Enter sv_cheats 1 in the console
  2. Type ttt_bot_nav_gen
  3. Wait for a bit
  4. Enter sv_cheats 0

We cannot run it synchronously, as N.O. (and nav_generate_incremental, which it relies on) is asynchronous by design. Namely, N.O. uses timers and concommands heavily to generate its navmeshes. Running the above commands is an acceptable solution for small servers or servers of trusted friends, so I'm leaving it in.

If you wish to avoid the prep work, the only solution is to use find navmeshes on the workshop and limit your map pool to maps with navmeshes. I wish more mappers included navmeshes in them.