diff --git a/LAUNCH compile.cmd b/LAUNCH compile.cmd index 6cdfc5a..ef96224 100644 --- a/LAUNCH compile.cmd +++ b/LAUNCH compile.cmd @@ -250,6 +250,8 @@ echo Skipping packing. "%mapfile%.bspzip" not found. :extrabspzip_ok + + :ldr @echo ================= Generating LDR Cubemaps ================= @cd /d "%CMD_LC_ROOT%" @@ -266,16 +268,34 @@ call extras\gmodcommander.cmd cubemaps_ldr "%mapname%" :navmesh @echo ================= Generating navmesh ================= + +@if not exist "%mapfolder%\%mapfile%.lm.txt" @goto navmesh_noseeds + @cd /d "%CMD_LC_ROOT%" +@copy /Y "%mapfolder%\%mapfile%.lm.txt" "%GameDir%"\data\navmesh_landmarks.txt @call extras\gmodcommander.cmd navmesh "%mapname%" @if ERRORLEVEL 1 goto failed @cd /d "%CMD_LC_ROOT%" - -@echo ================= bzip2 Packing ================= -start /low /min bzip2 -kf -9 "%GameDir%\maps\%mapname%.bsp" -start /low /min bzip2 -kf -9 "%GameDir%\maps\graphs\%mapname%.ain" -start /low /min bzip2 -kf -9 "%GameDir%\maps\%mapname%.nav" +goto navmesh_end +:navmesh_noseeds +@echo SKIPPING: Seed file missing "%mapfolder%\%mapfile%.lm.txt" +:navmesh_end + +:docompress +@echo ================= Compressing to .bz2 files for fastdl ================= +@start /low /min bzip2 -kf -9 "%GameDir%\maps\%mapname%.bsp" +@start /low /min bzip2 -kf -9 "%GameDir%\maps\graphs\%mapname%.ain" + +@set "filename=%GameDir%\maps\%mapname%.nav" +set size=0 +@for /f %%A in (%filename%) do set size=%%~zA +@if %size% GTR 2048 @goto navok +@echo NAVMESH GENERATION FAILED +@goto navcskip +:navok +@start /low /min bzip2 -kf -9 "%GameDir%\maps\%mapname%.nav" +:navcskip @echo ================= TESTING MAP (HDR) ================= diff --git a/config.bat b/config.bat index ccd5f25..a7179e6 100644 --- a/config.bat +++ b/config.bat @@ -44,7 +44,7 @@ @set mapwsid=0 @rem no addons on gmodcommander by default -set GCNOADDONS=-noaddons +@set GCNOADDONS=-noaddons @rem Should the compiler bundle missing materials @set NO_MISSING_BUNDLING=0 diff --git a/extras/gmodcommander.cmd b/extras/gmodcommander.cmd index 4ae30f0..34953ca 100644 --- a/extras/gmodcommander.cmd +++ b/extras/gmodcommander.cmd @@ -17,6 +17,9 @@ copy /Y mapcomp_write_missing.lua "%GameDir%"\lua\autorun\client\mapcomp_write_m copy /Y navmesh.lua "%GameDir%"\lua\autorun\server\navmesh.lua > nul @if ERRORLEVEL 1 goto fail +copy /Y landmark.lua "%GameDir%"\lua\includes\modules\landmark.lua > nul +@if ERRORLEVEL 1 goto fail + @cd /D %GameExeDir% @If "%1"=="missing" @goto missing @If "%1"=="cubemaps_ldr" @goto cubemaps_ldr diff --git a/extras/landmark.lua b/extras/landmark.lua new file mode 100644 index 0000000..e972fea --- /dev/null +++ b/extras/landmark.lua @@ -0,0 +1,261 @@ +local _M = {} +local landmark=_M +local _MM = {} +setmetatable(_M,_MM) +function _MM.__call(self,id) + return _M.get(id) +end + +--- Parse landmarks --- +local function int(str,endian,signed) -- use length of string to determine 8,16,32,64 bits + local t={str:byte(1,-1)} + if endian==true then --reverse bytes + local tt={} + for k=1,#t do + tt[#t-k+1]=t[k] + end + t=tt + end + local n=0 + for k=1,#t do + n=n+t[k]*2^((k-1)*8) + end + if signed then + n = (n > 2^(#t*8-1) -1) and (n - 2^(#t*8)) or n -- if last bit set, negative. + end + return n +end + + +local landmarks +local function getlandmarks() + if landmarks then return landmarks end + + local name = 'maps/'..game.GetMap()..'.bsp' + + + local f = file.Open(name,"rb","GAME") + + assert(f:Read(4)=='VBSP',"not a bsp") -- ident + + local version = int(f:Read(4),false,false) + assert(version==20,"new version?") + + -- entity info + local pos = int(f:Read(4)) + local len = int(f:Read(4)) + local ver = int(f:Read(4)) + local fourCC = f:Read(4) + f:Seek(pos) + local dat = f:Read(len) + + f:Close() + + local lastfindpos=30 + for _=1,10000 do + local l,r=dat:find('"info_landmark"\n',lastfindpos,true) + if l==nil then + break + end + + --print(l,r,dat:sub(l-100,r+100)) + + local L + for i=l,l-1000,-1 do + local char = dat:sub(i,i) + if char=='{' then + if dat:sub(i-1,i-1)~="\n" then error"eek" end + + L=i + break + end + end + + local R=dat:find("}\n",r,true) + R=R and R+1 + + if L and R then + landmarks = landmarks or {} + local t = util.KeyValuesToTable('"x"\n'..dat:sub(L,R)) + if not t or not t.classname then continue end + local name = t and t.targetname + local classname=name and t.classname=="info_landmark" + if classname and name then + landmarks[name]=Vector(t.origin) + end + + lastfindpos=R+4 + --return + else + lastfindpos=r+1 + end + + end + if not landmarks then + landmarks = {} + end + + return landmarks + +end + +_M.getlandmarks=getlandmarks + +_M.getall=getlandmarks +local get get = function(id) + if landmarks==nil then + getlandmarks() + get = function(id) return landmarks[id] end + _M.get = get + end + return landmarks[id] +end +_M.get = get + +function _M.toworld(id,vec) + if landmarks==nil then + getlandmarks() + end + local lmvec = landmarks[id] + if not lmvec then return end + return lmvec+vec +end +function _M.fromworld(id,vec) + if landmarks==nil then + getlandmarks() + end + local lmvec = landmarks[id] + if not lmvec then return end + return vec-lmvec +end + +local added +function _M.needcs() + if added then return end + added = true + + if SERVER then + AddCSLuaFile("includes/modules/landmark.lua") -- just () does not work!? + end + +end + +local function nearest(start_pos) + local closest,closest_pos,closest_dist=nil,nil,math.huge + + for name,pos in next,getlandmarks() do + local dist = start_pos:DistToSqr(pos) + if dist 3 and offset:Trim():find"^%d+ %d+ %d+$" and Vector(offset:Trim()) or Vector(0,0,0) + local pos = landmark.get(name:Trim()) + + if pos then + pos = pos + offset + local tr = util.TraceLine{ + start = pos, + endpos = pos - Vector(0, 0, 512) + } + if tr.Hit then + navmesh.AddWalkableSeed(tr.HitPos, tr.HitNormal) + debugoverlay.Cross(tr.HitPos,128,120,Color(255,255,255),true) + err=false + else err="trace did not hit" end + + else err="landmark missing or invalid" end + else err="could not parse name" end + if err then + system.FlashWindow() + print(("Adding seed did not succeed: %s %q"):format(err,lm)) end end print("begin",navmesh.BeginGeneration())