PWAD9< $2=HS^it$/:EP[fq| !,7BP]ipv-- SRB2PERSONA Render_Screen -- Base screen rendering functions -- these two funcs handle steep lines, we don't need them outside of here since R_drawLine will do this for us local function R_LineLow(v, x0,y0, x1,y1, c, thicc) local dx = x1 - x0 local dy = y1 - y0 local yi = 1 if dy < 0 yi = -1 dy = -dy end local D = 2*dy - dx local y = y0 for x = x0, x1 v.drawFill(x, y, thicc or 1, thicc or 1, c) if D > 0 y = y + yi D = D - 2*dx end D = D + 2*dy end end local function R_LineHigh(v, x0,y0, x1,y1, c, thicc) local dx = x1 - x0 local dy = y1 - y0 local xi = 1 if dx < 0 xi = -1 dx = -dx end local D = 2*dx - dy local x = x0 for y = y0, y1 v.drawFill(x, y, thicc or 1, thicc or 1, c) if D > 0 x = x + xi D = D - 2*dy end D = D + 2*dx end end -- lazy line drawer rawset(_G, "R_drawLine", function(v, x0, y0, x1, y1, c, thicc) if abs(y1 - y0) < abs(x1 - x0) if x0 > x1 R_LineLow(v, x1, y1, x0, y0, c, thicc) else R_LineLow(v, x0, y0, x1, y1, c, thicc) end else if y0 > y1 R_LineHigh(v, x1, y1, x0, y0, c, thicc) else R_LineHigh(v, x0, y0, x1, y1, c, thicc) end end end) -- line drawer with angle -- reminder that angle 0 is ---> and then counts counterclockwise. (think trigonometric circle) rawset(_G, "R_drawAngledLine", function(v, x, y, an, llen, c, thicc) -- shift all coords to be fixed: local newx = x<>FRACBITS end local function R_LineLow_640(v, x0,y0, x1,y1, c, flags, thicc, thicc2) local dx = x1 - x0 local dy = y1 - y0 local yi = 1 if dy < 0 yi = -1 dy = -dy end local D = 2*dy - dx local y = y0 for x = x0, x1 v.drawFill(R_NSC(x, dupx), R_NSC(y, hdupy), thicc, thicc2, c) if D > 0 y = y + yi D = D - 2*dx end D = D + 2*dy end end local function R_LineHigh_640(v, x0,y0, x1,y1, c, flags, thicc, thicc2) local dx = x1 - x0 local dy = y1 - y0 local xi = 1 if dx < 0 xi = -1 dx = -dx end local D = 2*dx - dy local x = x0 for y = y0, y1 v.drawFill(R_NSC(x, hdupx), R_NSC(y, dupy), thicc, thicc2, c) if D > 0 x = x + xi D = D - 2*dy end D = D + 2*dx end end -- lazy line drawer rawset(_G, "R_drawLine_640", function(v, x0, y0, x1, y1, c, flags, thicc) c = $|V_NOSCALESTART nfdupx, dupx = v.dupx() nfdupy, dupy = v.dupy() -- do not fetch these each pixel... -- precache sizes local sizex = R_NSC(thicc or 1, dupx) local sizey = R_NSC(thicc or 1, dupy) -- optimize line drawing hdupx, hdupy = dupx/2, dupy/2 x0 = $*2 x1 = $*2 y0 = $*2 y1 = $*2 if abs(y1 - y0) < abs(x1 - x0) if x0 > x1 R_LineLow_640(v, x1/2, y1, x0/2, y0, c, flags, sizex, sizey) else R_LineLow_640(v, x0/2, y0, x1/2, y1, c, flags, sizex, sizey) end else if y0 > y1 R_LineHigh_640(v, x1, y1/2, x0, y0/2, c, flags, sizex, sizey) else R_LineHigh_640(v, x0, y0/2, x1, y1/2, c, flags, sizex, sizey) end end end) -- line drawer with angle -- reminder that angle 0 is ---> and then counts counterclockwise. (think trigonometric circle) rawset(_G, "R_drawAngledLine_640", function(v, x, y, an, llen, c, thicc) -- shift all coords to be fixed: local newx = x< 0) and FixedDiv((B.x-A.x)< 0) and FixedDiv((C.x-A.x)< 0) and FixedDiv((C.x-B.x)< dx2 then while iy <= B.y<>FRACBITS, iy>>FRACBITS, (ex-ix)/FRACUNIT, 1, color) -- << divide ex-ix because we will get errors if we bitshift iy = $+FRACUNIT ix = $+dx2 ex = $+dx1 end ex, ey = B.x<>FRACBITS, iy>>FRACBITS, (ex-ix)/FRACUNIT, 1, color) iy = $+FRACUNIT ix = $+dx2 ex = $+dx3 end else while iy <= B.y<>FRACBITS, iy>>FRACBITS, (ex-ix)/FRACUNIT, 1, color) iy = $+FRACUNIT ix = $+dx1 ex = $+dx2 end ix, iy = B.x<>FRACBITS, iy>>FRACBITS, (ex-ix)/FRACUNIT, 1, color) iy = $+FRACUNIT ix = $+dx3 ex = $+dx2 end end end) local BASEVIDWIDTH = 320 local BASEVIDHEIGHT = 200 -- man this resolution is awful rawset(_G, "drawScreenwidePatch", function(v, patch, colormap, flags, hack) -- for GL use the default because it scales with it anyway local patchScale = FixedDiv(BASEVIDWIDTH*FRACUNIT, ((patch.width + (hack or 0))*FRACUNIT)) local xOffset = 0 local yOffset = (BASEVIDHEIGHT*FRACUNIT - FixedMul(patch.height*FRACUNIT, patchScale)) / 2 -- centre it vertically -- Scale the patch so that it always fills the entire screen local sxf = FixedDiv(v.width()*FRACUNIT, BASEVIDWIDTH*FRACUNIT) local syf = FixedDiv(v.height()*FRACUNIT, BASEVIDHEIGHT*FRACUNIT) local oldPatchScale,newPatchScale if sxf > syf then oldPatchScale = (v.height() / BASEVIDHEIGHT)*FRACUNIT else oldPatchScale = (v.width() / BASEVIDWIDTH)*FRACUNIT end newPatchScale = sxf patchScale = FixedMul(patchScale, FixedDiv(newPatchScale, oldPatchScale)) -- need to offset if scaled -- someone please end my suffering local patchRealHeight = FixedMul(FixedMul(patch.height*FRACUNIT, patchScale), oldPatchScale) yOffset = (v.height()*FRACUNIT - patchRealHeight) / 2 yOffset = FixedDiv(yOffset, oldPatchScale) v.drawScaled(xOffset, yOffset, patchScale, patch, V_SNAPTOTOP|V_SNAPTOLEFT|(flags or 0), colormap) end) rawset(_G, "R_GetNoscaledCoords", function(v, x, y) -- this is for software because hud rendering fucking sucks on software return FixedMul(x, select(2,v.dupx())) / FRACUNIT, FixedMul(y, select(2,v.dupy())) / FRACUNIT end) rawset(_G, "R_NoScaleX", function(v, x) return FixedMul(x, select(2,v.dupx())) end) rawset(_G, "R_NoScaleY", function(v, y) return FixedMul(y, select(2,v.dupy())) end) rawset(_G, "R_GetScreenCoords", function(v, p, c, mx, my, mz) local camx, camy, camz, camangle, camaiming if p.awayviewtics then camx = p.awayviewmobj.x camy = p.awayviewmobj.y camz = p.awayviewmobj.z camangle = p.awayviewmobj.angle camaiming = p.awayviewaiming elseif c.chase then camx = c.x camy = c.y camz = c.z camangle = c.angle camaiming = c.aiming else camx = p.mo.x camy = p.mo.y camz = p.viewz-20*FRACUNIT camangle = p.mo.angle camaiming = p.aiming end local x = camangle-R_PointToAngle2(camx, camy, mx, my) local distfact = cos(x) if not distfact then distfact = 1 end -- MonsterIestyn, your bloody table fixing... if x > ANGLE_90 or x < ANGLE_270 then return -9, -9, 0 else x = FixedMul(tan(x, true), 160< 1 -- 3p / 4p basex = $/2 basey = $/2 if splitnum(p) == 1 splitflags = V_HORZSCREEN elseif splitnum(p) == 2 splitflags = V_SPLITSCREEN|V_SNAPTOBOTTOM elseif splitnum(p) == 3 splitflags = V_SPLITSCREEN|V_HORZSCREEN|V_SNAPTOBOTTOM end end -- encore mode (flip to the other side of the screen): if encoremode basex = 320<>FRACBITS) - 23 -- round down to avoid any leftover space! local bary = (basey>>FRACBITS) - 1 -- draw the background v.drawFill(barx, bary, 47, 6, 23|splitflags) -- draw prev level if driftlevel_colors[driftlevel-1] ~= nil v.drawFill(barx, bary, 47, 5, driftlevel_colors[driftlevel-1][1]|splitflags) for i = 2, 3 local newbarcolor = driftlevel_colors[driftlevel-1][i] v.drawFill(barx, bary + 1 + i, 47, 1, newbarcolor|splitflags) end end -- draw the bar local barlength = (driftcharge-startat)*47 / (driftlimit-startat) local barcolor = driftlevel_colors[driftlevel][1] if barcolor == nil barcolor = rainbow_indexes[leveltime%(#rainbow_indexes)+1] end v.drawFill(barx, bary, barlength, 5, barcolor|splitflags) -- use some darker shades to make it look cool for i = 2, 3 local newbarcolor if driftlevel_colors[driftlevel] and driftlevel_colors[driftlevel][i] ~= nil newbarcolor = driftlevel_colors[driftlevel][i] else newbarcolor = barcolor + (i-1)*3 end v.drawFill(barx, bary + 1 + i, barlength, 1, newbarcolor|splitflags) end -- finally, draw the gauge overlay... god, kill me... v.drawScaled(basex, basey, FRACUNIT, v.cachePatch("K_DGAU"), splitflags) -- rght, also draw a cool number local cmap if leveltime%2 local c = driftlevel_ncolors[driftlevel] if c and c >= 0 cmap = v.getColormap(TC_RAINBOW, c) elseif c and c < 0 cmap = v.getColormap(TC_RAINBOW, leveltime%MAXSKINCOLORS) end end V_drawPeggedPingNum(v, (basex>>FRACBITS) + 32, basey>>FRACBITS, driftcharge*100/driftval, 3, splitflags, cmap) end end -- flush table if #splitplayers > splitscreen splitplayers = {} end end) GX_START |K_DGAUGX_END!LUA_SCRt%LUA_YURI