Пример #1
0
        /*
         * ================== CL_ParseBaseline ==================
         */
        public static void ParseBaseline()
        {
            entity_state_t nullstate = new(null);

            //memset(nullstate, 0, sizeof(nullstate));
            int[] bits   = { 0 };
            var   newnum = CL_ents.ParseEntityBits(bits);
            var   es     = Globals.cl_entities[newnum].baseline;

            CL_ents.ParseDelta(nullstate, es, newnum, bits[0]);
        }
Пример #2
0
        static void Spatialize(channel_t ch)
        {
            Single[] origin = new Single[] { 0, 0, 0 };
            if (ch.entnum == cl.playernum + 1)
            {
                ch.leftvol  = ch.master_vol;
                ch.rightvol = ch.master_vol;
                return;
            }

            if (ch.fixed_origin)
            {
                Math3D.VectorCopy(ch.origin, origin);
            }
            else
            {
                CL_ents.GetEntitySoundOrigin(ch.entnum, origin);
            }
            SpatializeOrigin(origin, ( Single )ch.master_vol, ch.dist_mult, ch);
        }
Пример #3
0
        /*
         * ================== V_RenderView
         *
         * ==================
         */
        public static void RenderView(float stereo_separation)
        {
            //		extern int entitycmpfnc( const entity_t *, const entity_t * );
            //
            if (Globals.cls.state != Defines.ca_active)
            {
                return;
            }

            if (!Globals.cl.refresh_prepped)
            {
                return;                 // still loading
            }
            if (Globals.cl_timedemo.value != 0.0f)
            {
                if (Globals.cl.timedemo_start == 0)
                {
                    Globals.cl.timedemo_start = Timer.Milliseconds();
                }

                Globals.cl.timedemo_frames++;
            }

            // an invalid frame will just use the exact previous refdef
            // we can't use the old frame if the video mode has changed, though...
            if (Globals.cl.frame.valid && (Globals.cl.force_refdef || Globals.cl_paused.value == 0.0f))
            {
                Globals.cl.force_refdef = false;
                V.ClearScene();

                // build a refresh entity list and calc cl.sim*
                // this also calls CL_CalcViewValues which loads
                // v_forward, etc.
                CL_ents.AddEntities();

                if (V.cl_testparticles.value != 0.0f)
                {
                    V.TestParticles();
                }

                if (V.cl_testentities.value != 0.0f)
                {
                    V.TestEntities();
                }

                if (V.cl_testlights.value != 0.0f)
                {
                    V.TestLights();
                }

                if (V.cl_testblend.value != 0.0f)
                {
                    Globals.cl.refdef.blend[0] = 1.0f;
                    Globals.cl.refdef.blend[1] = 0.5f;
                    Globals.cl.refdef.blend[2] = 0.25f;
                    Globals.cl.refdef.blend[3] = 0.5f;
                }

                // offset vieworg appropriately if we're doing stereo separation
                if (stereo_separation != 0)
                {
                    var tmp = new float[3];
                    Math3D.VectorScale(Globals.cl.v_right, stereo_separation, tmp);
                    Math3D.VectorAdd(Globals.cl.refdef.vieworg, tmp, Globals.cl.refdef.vieworg);
                }

                // never let it sit exactly on a node line, because a water plane
                // can
                // dissapear when viewed with the eye exactly on it.
                // the server protocol only specifies to 1/8 pixel, so add 1/16 in
                // each axis
                Globals.cl.refdef.vieworg[0] += 1.0f / 16;
                Globals.cl.refdef.vieworg[1] += 1.0f / 16;
                Globals.cl.refdef.vieworg[2] += 1.0f / 16;
                Globals.cl.refdef.x           = Globals.scr_vrect.x;
                Globals.cl.refdef.y           = Globals.scr_vrect.y;
                Globals.cl.refdef.width       = Globals.scr_vrect.width;
                Globals.cl.refdef.height      = Globals.scr_vrect.height;
                Globals.cl.refdef.fov_y       = Math3D.CalcFov(Globals.cl.refdef.fov_x, Globals.cl.refdef.width, Globals.cl.refdef.height);
                Globals.cl.refdef.time        = Globals.cl.time * 0.001f;
                Globals.cl.refdef.areabits    = Globals.cl.frame.areabits;

                if (Globals.cl_add_entities.value == 0.0f)
                {
                    V.r_numentities = 0;
                }

                if (Globals.cl_add_particles.value == 0.0f)
                {
                    V.r_numparticles = 0;
                }

                if (Globals.cl_add_lights.value == 0.0f)
                {
                    V.r_numdlights = 0;
                }

                if (Globals.cl_add_blend.value == 0)
                {
                    Math3D.VectorClear(Globals.cl.refdef.blend);
                }

                Globals.cl.refdef.num_entities  = V.r_numentities;
                Globals.cl.refdef.entities      = V.r_entities;
                Globals.cl.refdef.num_particles = V.r_numparticles;
                Globals.cl.refdef.num_dlights   = V.r_numdlights;
                Globals.cl.refdef.dlights       = V.r_dlights;
                Globals.cl.refdef.lightstyles   = V.r_lightstyles;
                Globals.cl.refdef.rdflags       = Globals.cl.frame.playerstate.rdflags;
            }

            Globals.re.RenderFrame(Globals.cl.refdef);

            if (V.cl_stats.value != 0.0f)
            {
                Com.Printf("ent:%i  lt:%i  part:%i\n", V.r_numentities, V.r_numdlights, V.r_numparticles);
            }

            if (Globals.log_stats.value != 0.0f && Globals.log_stats_file != null)
            {
                try
                {
                    Globals.log_stats_file.Write(V.r_numentities + "," + V.r_numdlights + "," + V.r_numparticles);
                }
                catch (Exception)
                {
                }
            }

            SCR.AddDirtyPoint(Globals.scr_vrect.x, Globals.scr_vrect.y);
            SCR.AddDirtyPoint(Globals.scr_vrect.x + Globals.scr_vrect.width - 1, Globals.scr_vrect.y + Globals.scr_vrect.height - 1);
            SCR.DrawCrosshair();
        }
Пример #4
0
        public static void PlayAllSounds(SingleBuffer listenerOrigin)
        {
            SingleBuffer sourceOrigin = sourceOriginBuffer;
            Channel      ch;
            int          sourceId;
            int          state;

            for (int i = 0; i < numChannels; i++)
            {
                ch = channels[i];
                if (ch.active)
                {
                    sourceId = ch.sourceId;
                    switch (ch.type)
                    {
                    case Channel.LISTENER:
                        sourceOrigin.Put(0, listenerOrigin.Get(0));
                        sourceOrigin.Put(1, listenerOrigin.Get(1));
                        sourceOrigin.Put(2, listenerOrigin.Get(2));
                        break;

                    case Channel.DYNAMIC:
                        CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin);
                        ConvertVector(entityOrigin, sourceOrigin);
                        break;

                    case Channel.FIXED:
                        ConvertVector(ch.origin, sourceOrigin);
                        break;
                    }

                    if (ch.modified)
                    {
                        if (ch.bufferChanged)
                        {
                            try
                            {
                                AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId);
                            }
                            catch (OpenALException e)
                            {
                                AL10.AlSourceStop(sourceId);
                                AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId);
                            }
                        }

                        if (ch.volumeChanged)
                        {
                            AL10.AlSourcef(sourceId, AL10.AL_GAIN, ch.volume);
                        }

                        AL10.AlSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff);
                        AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin);
                        AL10.AlSourcePlay(sourceId);
                        ch.modified = false;
                    }
                    else
                    {
                        state = AL10.AlGetSourcei(sourceId, AL10.AL_SOURCE_STATE);
                        if (state == AL10.AL_PLAYING)
                        {
                            AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin);
                        }
                        else
                        {
                            ch.Clear();
                        }
                    }

                    ch.autosound = false;
                }
            }
        }
Пример #5
0
        public static void PlayAllSounds(float[] listenerOrigin)
        {
            Channel       ch;
            int           sourceId;
            ALSourceState state;

            int[] tmp = new int[] { 0 };
            for (int i = 0; i < numChannels; i++)
            {
                ch = channels[i];
                if (ch.active)
                {
                    sourceId = ch.sourceId;
                    switch (ch.type)

                    {
                    case Channel.LISTENER:
                        Math3D.VectorCopy(listenerOrigin, sourceOrigin);
                        break;

                    case Channel.DYNAMIC:
                        CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin);
                        ConvertVector(entityOrigin, sourceOrigin);
                        break;

                    case Channel.FIXED:
                        ConvertVector(ch.origin, sourceOrigin);
                        break;
                    }

                    if (ch.modified)
                    {
                        if (ch.bufferChanged)
                        {
                            try
                            {
                                AL.Source(sourceId, ALSourcei.Buffer, ch.bufferId);
                            }
                            catch (Exception e)
                            {
                                AL.SourceStop(sourceId);
                                AL.Source(sourceId, ALSourcei.Buffer, ch.bufferId);
                            }
                        }

                        if (ch.volumeChanged)
                        {
                            AL.Source(sourceId, ALSourcef.Gain, ch.volume);
                        }

                        AL.Source(sourceId, ALSourcef.RolloffFactor, ch.rolloff);
                        AL.Source(sourceId, ALSource3f.Position, sourceOrigin[0], sourceOrigin[1], sourceOrigin[2]);
                        AL.SourcePlay(sourceId);
                        ch.modified = false;
                    }
                    else
                    {
                        AL.GetSource(sourceId, ALGetSourcei.SourceState, out tmp[0]);
                        state = (ALSourceState)tmp[0];
                        if (state == ALSourceState.Playing)
                        {
                            AL.Source(sourceId, ALSource3f.Position, sourceOrigin[0], sourceOrigin[1], sourceOrigin[2]);
                        }
                        else
                        {
                            ch.Clear();
                        }
                    }

                    ch.autosound = false;
                }
            }
        }