示例#1
0
        /// <summary>
        /// R_RenderDlights
        /// </summary>
        private static void RenderDlights()
        {
            //int i;
            //dlight_t* l;

            if (_glFlashBlend.Value == 0)
            {
                return;
            }

            _DlightFrameCount = _FrameCount + 1;        // because the count hasn't advanced yet for this frame

            GL.DepthMask(false);
            GL.Disable(EnableCap.Texture2D);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);

            for (int i = 0; i < Client.MAX_DLIGHTS; i++)
            {
                dlight_t l = Client.DLights[i];
                if (l.die < Client.cl.time || l.radius == 0)
                {
                    continue;
                }

                RenderDlight(l);
            }

            GL.Color3(1f, 1, 1);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.DepthMask(true);
        }
示例#2
0
        // CL_Init
        public static void Init()
        {
            InitInput();
            InitTempEntities();

            if (_Name == null)
            {
                _Name          = new Cvar("_cl_name", "player", true);
                _Color         = new Cvar("_cl_color", "0", true);
                _ShowNet       = new Cvar("cl_shownet", "0"); // can be 0, 1, or 2
                _NoLerp        = new Cvar("cl_nolerp", "0");
                _LookSpring    = new Cvar("lookspring", "0", true);
                _LookStrafe    = new Cvar("lookstrafe", "0", true);
                _Sensitivity   = new Cvar("sensitivity", "3", true);
                _MPitch        = new Cvar("m_pitch", "0.022", true);
                _MYaw          = new Cvar("m_yaw", "0.022", true);
                _MForward      = new Cvar("m_forward", "1", true);
                _MSide         = new Cvar("m_side", "0.8", true);
                _UpSpeed       = new Cvar("cl_upspeed", "200");
                _ForwardSpeed  = new Cvar("cl_forwardspeed", "200", true);
                _BackSpeed     = new Cvar("cl_backspeed", "200", true);
                _SideSpeed     = new Cvar("cl_sidespeed", "350");
                _MoveSpeedKey  = new Cvar("cl_movespeedkey", "2.0");
                _YawSpeed      = new Cvar("cl_yawspeed", "140");
                _PitchSpeed    = new Cvar("cl_pitchspeed", "150");
                _AngleSpeedKey = new Cvar("cl_anglespeedkey", "1.5");
            }

            for (int i = 0; i < _EFrags.Length; i++)
            {
                _EFrags[i] = new efrag_t();
            }

            for (int i = 0; i < _Entities.Length; i++)
            {
                _Entities[i] = new entity_t();
            }

            for (int i = 0; i < _StaticEntities.Length; i++)
            {
                _StaticEntities[i] = new entity_t();
            }

            for (int i = 0; i < _DLights.Length; i++)
            {
                _DLights[i] = new dlight_t();
            }

            //
            // register our commands
            //
            Cmd.Add("entities", PrintEntities_f);
            Cmd.Add("disconnect", Disconnect_f);
            Cmd.Add("record", Record_f);
            Cmd.Add("stop", Stop_f);
            Cmd.Add("playdemo", PlayDemo_f);
            Cmd.Add("timedemo", TimeDemo_f);
        }
示例#3
0
        static mplane_t _LightPlane;  // lightplane

        /// <summary>
        /// R_PushDlights
        /// </summary>
        public static void PushDlights()
        {
            if (_glFlashBlend.Value != 0)
            {
                return;
            }

            _DlightFrameCount = _FrameCount + 1;        // because the count hasn't advanced yet for this frame

            for (int i = 0; i < Client.MAX_DLIGHTS; i++)
            {
                dlight_t l = Client.DLights[i];
                if (l.die < Client.cl.time || l.radius == 0)
                {
                    continue;
                }
                Render.MarkLights(l, 1 << i, Client.cl.worldmodel.nodes[0]);
            }
        }
示例#4
0
        /// <summary>
        /// CL_DecayLights
        /// </summary>
        public static void DecayLights()
        {
            float time = (float)(cl.time - cl.oldtime);

            for (int i = 0; i < MAX_DLIGHTS; i++)
            {
                dlight_t dl = _DLights[i];
                if (dl.die < cl.time || dl.radius == 0)
                {
                    continue;
                }

                dl.radius -= time * dl.decay;
                if (dl.radius < 0)
                {
                    dl.radius = 0;
                }
            }
        }
示例#5
0
        /// <summary>
        /// R_MarkLights
        /// </summary>
        static void MarkLights(dlight_t light, int bit, mnodebase_t node)
        {
            if (node.contents < 0)
            {
                return;
            }

            mnode_t  n          = (mnode_t)node;
            mplane_t splitplane = n.plane;
            float    dist       = Vector3.Dot(light.origin, splitplane.normal) - splitplane.dist;

            if (dist > light.radius)
            {
                MarkLights(light, bit, n.children[0]);
                return;
            }
            if (dist < -light.radius)
            {
                MarkLights(light, bit, n.children[1]);
                return;
            }

            // mark the polygons
            for (int i = 0; i < n.numsurfaces; i++)
            {
                msurface_t surf = Client.cl.worldmodel.surfaces[n.firstsurface + i];
                if (surf.dlightframe != _DlightFrameCount)
                {
                    surf.dlightbits  = 0;
                    surf.dlightframe = _DlightFrameCount;
                }
                surf.dlightbits |= bit;
            }

            MarkLights(light, bit, n.children[0]);
            MarkLights(light, bit, n.children[1]);
        }
示例#6
0
        /// <summary>
        /// R_RenderDlight
        /// </summary>
        static void RenderDlight(dlight_t light)
        {
            float   rad = light.radius * 0.35f;
            Vector3 v   = light.origin - Render.Origin;

            if (v.Length < rad)
            {   // view is inside the dlight
                AddLightBlend(1, 0.5f, 0, light.radius * 0.0003f);
                return;
            }

            GL.Begin(PrimitiveType.TriangleFan);
            GL.Color3(0.2f, 0.1f, 0);
            v = light.origin - Render.ViewPn * rad;
            GL.Vertex3(v);
            GL.Color3(0, 0, 0);
            for (int i = 16; i >= 0; i--)
            {
                double a = i / 16.0 * Math.PI * 2;
                v = light.origin + Render.ViewRight * (float)Math.Cos(a) * rad + Render.ViewUp * (float)Math.Sin(a) * rad;
                GL.Vertex3(v);
            }
            GL.End();
        }
示例#7
0
        /// <summary>
        /// CL_RelinkEntities
        /// </summary>
        static void RelinkEntities()
        {
            // determine partial update time
            float frac = LerpPoint();

            NumVisEdicts = 0;

            //
            // interpolate player info
            //
            cl.velocity = cl.mvelocity[1] + frac * (cl.mvelocity[0] - cl.mvelocity[1]);

            if (cls.demoplayback)
            {
                // interpolate the angles
                Vector3 angleDelta = cl.mviewangles[0] - cl.mviewangles[1];
                Mathlib.CorrectAngles180(ref angleDelta);
                cl.viewangles = cl.mviewangles[1] + frac * angleDelta;
            }

            float bobjrotate = Mathlib.AngleMod(100 * cl.time);

            // start on the entity after the world
            for (int i = 1; i < cl.num_entities; i++)
            {
                entity_t ent = _Entities[i];
                if (ent.model == null)
                {
                    // empty slot
                    if (ent.forcelink)
                    {
                        Render.RemoveEfrags(ent);       // just became empty
                    }
                    continue;
                }

                // if the object wasn't included in the last packet, remove it
                if (ent.msgtime != cl.mtime[0])
                {
                    ent.model              = null;
                    ent.FrameStartTime     = 0;
                    ent.TranslateStartTime = 0;
                    ent.RotateStartTime    = 0;
                    continue;
                }

                Vector3 oldorg = ent.origin;

                if (ent.forcelink)
                {
                    // the entity was not updated in the last message
                    // so move to the final spot
                    ent.origin = ent.msg_origins[0];
                    ent.angles = ent.msg_angles[0];
                }
                else
                {
                    // if the delta is large, assume a teleport and don't lerp
                    float   f     = frac;
                    Vector3 delta = ent.msg_origins[0] - ent.msg_origins[1];
                    if (Math.Abs(delta.X) > 100 || Math.Abs(delta.Y) > 100 || Math.Abs(delta.Z) > 100)
                    {
                        f = 1; // assume a teleportation, not a motion
                    }
                    // [email protected]: model transform interpolation
                    // interpolation should be reset in the event of a large delta
                    if (f >= 1)
                    {
                        ent.FrameStartTime     = 0;
                        ent.TranslateStartTime = 0;
                        ent.RotateStartTime    = 0;
                    }

                    // interpolate the origin and angles
                    ent.origin = ent.msg_origins[1] + f * delta;
                    Vector3 angleDelta = ent.msg_angles[0] - ent.msg_angles[1];
                    Mathlib.CorrectAngles180(ref angleDelta);
                    ent.angles = ent.msg_angles[1] + f * angleDelta;
                }

                // rotate binary objects locally
                if ((ent.model.flags & EF.EF_ROTATE) != 0)
                {
                    ent.angles.Y = bobjrotate;
                }

                if ((ent.effects & EntityEffects.EF_BRIGHTFIELD) != 0)
                {
                    Render.EntityParticles(ent);
                }

                if ((ent.effects & EntityEffects.EF_MUZZLEFLASH) != 0)
                {
                    dlight_t dl = AllocDlight(i);
                    dl.origin    = ent.origin;
                    dl.origin.Z += 16;
                    Vector3 fv, rv, uv;
                    Mathlib.AngleVectors(ref ent.angles, out fv, out rv, out uv);
                    dl.origin  += fv * 18;
                    dl.radius   = 200 + (Sys.Random() & 31);
                    dl.minlight = 32;
                    dl.die      = (float)cl.time + 0.1f;
                }
                if ((ent.effects & EntityEffects.EF_BRIGHTLIGHT) != 0)
                {
                    dlight_t dl = AllocDlight(i);
                    dl.origin    = ent.origin;
                    dl.origin.Z += 16;
                    dl.radius    = 400 + (Sys.Random() & 31);
                    dl.die       = (float)cl.time + 0.001f;
                }
                if ((ent.effects & EntityEffects.EF_DIMLIGHT) != 0)
                {
                    dlight_t dl = AllocDlight(i);
                    dl.origin = ent.origin;
                    dl.radius = 200 + (Sys.Random() & 31);
                    dl.die    = (float)cl.time + 0.001f;
                }

                if ((ent.model.flags & EF.EF_GIB) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 2);
                }
                else if ((ent.model.flags & EF.EF_ZOMGIB) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 4);
                }
                else if ((ent.model.flags & EF.EF_TRACER) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 3);
                }
                else if ((ent.model.flags & EF.EF_TRACER2) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 5);
                }
                else if ((ent.model.flags & EF.EF_ROCKET) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 0);
                    dlight_t dl = AllocDlight(i);
                    dl.origin = ent.origin;
                    dl.radius = 200;
                    dl.die    = (float)cl.time + 0.01f;
                }
                else if ((ent.model.flags & EF.EF_GRENADE) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 1);
                }
                else if ((ent.model.flags & EF.EF_TRACER3) != 0)
                {
                    Render.RocketTrail(ref oldorg, ref ent.origin, 6);
                }

                ent.forcelink = false;

                if (i == cl.viewentity && !Chase.IsActive)
                {
                    continue;
                }

                if (NumVisEdicts < MAX_VISEDICTS)
                {
                    _VisEdicts[NumVisEdicts] = ent;
                    NumVisEdicts++;
                }
            }
        }