static float SCR_DrawFPS(float y) { var new_y = MathX.FtoiFast(y) + 300; // don't use serverTime, because that will be drifting to correct for internet lag changes, timescales, timedemos, etc var t = SysW.Milliseconds; var frameTime = t - SCR_DrawFPS_previous; SCR_DrawFPS_previous = t; SCR_DrawFPS_previousTimes[SCR_DrawFPS_index % FPS_FRAMES] = frameTime; SCR_DrawFPS_index++; if (SCR_DrawFPS_index > FPS_FRAMES) { // average multiple frames together to smooth changes out a bit var total = 0; for (var i = 0; i < FPS_FRAMES; i++) { total += SCR_DrawFPS_previousTimes[i]; } if (total == 0) { total = 1; } SCR_DrawFPS_fps = 10000 * FPS_FRAMES / total; SCR_DrawFPS_fps = (SCR_DrawFPS_fps + 5) / 10; var s = $"{SCR_DrawFPS_fps}fps"; var w = s.Length * R.SMALLCHAR_WIDTH; renderSystem.DrawSmallStringExt((634 / 2) - w, new_y, s, colorWhite, true, localConsole.charSetShader); } return(y + R.BIGCHAR_HEIGHT + 4); }
// adds a point public void AddPoint(float x, float y) { var ix = (short)MathX.FtoiFast(x); var iy = (short)MathX.FtoiFast(y); if (ix < x1) { x1 = ix; } if (ix > x2) { x2 = ix; } if (iy < y1) { y1 = iy; } if (iy > y2) { y2 = iy; } }
public override IRenderModel InstantiateDynamicModel(RenderEntity ent, ViewDef view, IRenderModel cachedModel) { RenderModelStatic staticModel; SrfTriangles tri; ModelSurface surf; if (cachedModel != null && !r_useCachedDynamicModels.Bool) { cachedModel.Dispose(); cachedModel = null; } if (ent == null || view == null) { cachedModel.Dispose(); cachedModel = null; } if (cachedModel != null) { Debug.Assert(cachedModel is RenderModelStatic); Debug.Assert(string.Equals(cachedModel.Name, sprite_SnapshotName, StringComparison.OrdinalIgnoreCase)); staticModel = (RenderModelStatic)cachedModel; surf = staticModel.Surface(0); tri = surf.geometry; } else { staticModel = new RenderModelStatic(); staticModel.InitEmpty(sprite_SnapshotName); tri = R_AllocStaticTriSurf(); R_AllocStaticTriSurfVerts(tri, 4); R_AllocStaticTriSurfIndexes(tri, 6); tri.verts[0].Clear(); tri.verts[0].normal.Set(1f, 0f, 0f); tri.verts[0].tangents0.Set(0f, 1f, 0f); tri.verts[0].tangents1.Set(0f, 0f, 1f); tri.verts[0].st.x = 0f; tri.verts[0].st.y = 0f; tri.verts[1].Clear(); tri.verts[1].normal.Set(1f, 0f, 0f); tri.verts[1].tangents0.Set(0f, 1f, 0f); tri.verts[1].tangents1.Set(0f, 0f, 1f); tri.verts[1].st.x = 1f; tri.verts[1].st.y = 0f; tri.verts[2].Clear(); tri.verts[2].normal.Set(1f, 0f, 0f); tri.verts[2].tangents0.Set(0f, 1f, 0f); tri.verts[2].tangents1.Set(0f, 0f, 1f); tri.verts[2].st.x = 1f; tri.verts[2].st.y = 1f; tri.verts[3].Clear(); tri.verts[3].normal.Set(1f, 0f, 0f); tri.verts[3].tangents0.Set(0f, 1f, 0f); tri.verts[3].tangents1.Set(0f, 0f, 1f); tri.verts[3].st.x = 0f; tri.verts[3].st.y = 1f; tri.indexes[0] = 0; tri.indexes[1] = 1; tri.indexes[2] = 3; tri.indexes[3] = 1; tri.indexes[4] = 2; tri.indexes[5] = 3; tri.numVerts = 4; tri.numIndexes = 6; surf = new(); surf.geometry = tri; surf.id = 0; surf.shader = tr.defaultMaterial; staticModel.AddSurface(surf); } var red = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_RED] * 255f); var green = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_GREEN] * 255f); var blue = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_BLUE] * 255f); var alpha = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_ALPHA] * 255f); var right = new Vector3(0f, ent.shaderParms[IRenderWorld.SHADERPARM_SPRITE_WIDTH] * 0.5f, 0f); var up = new Vector3(0f, 0f, ent.shaderParms[IRenderWorld.SHADERPARM_SPRITE_HEIGHT] * 0.5f); tri.verts[0].xyz = up + right; tri.verts[0].color0 = red; tri.verts[0].color1 = green; tri.verts[0].color2 = blue; tri.verts[0].color3 = alpha; tri.verts[1].xyz = up - right; tri.verts[1].color0 = red; tri.verts[1].color1 = green; tri.verts[1].color2 = blue; tri.verts[1].color3 = alpha; tri.verts[2].xyz = -right - up; tri.verts[2].color0 = red; tri.verts[2].color1 = green; tri.verts[2].color2 = blue; tri.verts[2].color3 = alpha; tri.verts[3].xyz = right - up; tri.verts[3].color0 = red; tri.verts[3].color1 = green; tri.verts[3].color2 = blue; tri.verts[3].color3 = alpha; R_BoundTriSurf(tri); staticModel.bounds = tri.bounds; return(staticModel); }
=> true; // don't ever need to load public override IRenderModel InstantiateDynamicModel(RenderEntity ent, ViewDef view, IRenderModel cachedModel) { RenderModelStatic staticModel; SrfTriangles tri; ModelSurface surf; if (cachedModel != null) { cachedModel = null; } if (ent == null || view == null) { return(null); } if (cachedModel != null) { Debug.Assert(cachedModel is RenderModelStatic); Debug.Assert(string.Equals(cachedModel.Name, beam_SnapshotName, StringComparison.OrdinalIgnoreCase)); staticModel = (RenderModelStatic)cachedModel; surf = staticModel.Surface(0); tri = surf.geometry; } else { staticModel = new RenderModelStatic(); staticModel.InitEmpty(beam_SnapshotName); tri = R_AllocStaticTriSurf(); R_AllocStaticTriSurfVerts(tri, 4); R_AllocStaticTriSurfIndexes(tri, 6); tri.verts[0].Clear(); tri.verts[0].st.x = 0; tri.verts[0].st.y = 0; tri.verts[1].Clear(); tri.verts[1].st.x = 0; tri.verts[1].st.y = 1; tri.verts[2].Clear(); tri.verts[2].st.x = 1; tri.verts[2].st.y = 0; tri.verts[3].Clear(); tri.verts[3].st.x = 1; tri.verts[3].st.y = 1; tri.indexes[0] = 0; tri.indexes[1] = 2; tri.indexes[2] = 1; tri.indexes[3] = 2; tri.indexes[4] = 3; tri.indexes[5] = 1; tri.numVerts = 4; tri.numIndexes = 6; surf = new(); surf.geometry = tri; surf.id = 0; surf.shader = tr.defaultMaterial; staticModel.AddSurface(surf); } Vector3 target = reinterpret.cast_vec3(ent.shaderParms, IRenderWorld.SHADERPARM_BEAM_END_X); // we need the view direction to project the minor axis of the tube as the view changes var modelMatrix = stackalloc float[16]; R_AxisToModelMatrix(ent.axis, ent.origin, modelMatrix); R_GlobalPointToLocal(modelMatrix, view.renderView.vieworg, out var localView); R_GlobalPointToLocal(modelMatrix, target, out var localTarget); Vector3 major = localTarget; Vector3 minor = default; Vector3 mid = 0.5f * localTarget; Vector3 dir = mid - localView; minor.Cross(major, dir); minor.Normalize(); if (ent.shaderParms[IRenderWorld.SHADERPARM_BEAM_WIDTH] != 0f) { minor *= ent.shaderParms[IRenderWorld.SHADERPARM_BEAM_WIDTH] * 0.5f; } var red = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_RED] * 255f); var green = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_GREEN] * 255f); var blue = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_BLUE] * 255f); var alpha = (byte)MathX.FtoiFast(ent.shaderParms[IRenderWorld.SHADERPARM_ALPHA] * 255f); tri.verts[0].xyz = minor; tri.verts[0].color0 = red; tri.verts[0].color1 = green; tri.verts[0].color2 = blue; tri.verts[0].color3 = alpha; tri.verts[1].xyz = -minor; tri.verts[1].color0 = red; tri.verts[1].color1 = green; tri.verts[1].color2 = blue; tri.verts[1].color3 = alpha; tri.verts[2].xyz = localTarget + minor; tri.verts[2].color0 = red; tri.verts[2].color1 = green; tri.verts[2].color2 = blue; tri.verts[2].color3 = alpha; tri.verts[3].xyz = localTarget - minor; tri.verts[3].color0 = red; tri.verts[3].color1 = green; tri.verts[3].color2 = blue; tri.verts[3].color3 = alpha; R_BoundTriSurf(tri); staticModel.bounds = tri.bounds; return(staticModel); }