コード例 #1
0
        public virtual void Init()
        {
            Globals.dedicated = Cvar.Get("dedicated", "0", Qcommon.CVAR_NOSET);
            Program.Q2Dialog  = new Q2DataDialog();
            Locale.SetDefault(Locale.US);
            Program.Q2Dialog.SetVisible(true);
            string DRIVER = "lwjgl";

            Qcommon.Init(new string { "DancingQueens", "+set", "gl_mode", "4", "+set", "vid_fullscreen", "0", "+set", "vid_ref", DRIVER });
            VID.Shutdown();
            String[] names = Renderer.GetDriverNames();
            System.Diagnostics.Debug.WriteLine("Registered Drivers: " + Arrays.AsList(names));
            this.re    = Renderer.GetDriver(DRIVER);
            Globals.re = this.re;
            System.Diagnostics.Debug.WriteLine("Use driver: " + re);
            System.out_renamed.Flush();
            re.Init(0, 0);
            kbd = re.GetKeyboardHandler();
            kbd.Init();
            Cbuf.AddText("unbind t");
            Cbuf.Execute();
            Cmd.AddCommand("togglemouse", togglemouse);
            Cbuf.AddText("bind t togglemouse");
            Cbuf.Execute();
            Globals.cls.key_dest = Defines.key_game;
            Globals.cls.state    = Defines.ca_active;
            viddef = Globals.viddef;
            fov_y  = Math3D.CalcFov(fov_x, viddef.GetWidth(), viddef.GetHeight());
        }
コード例 #2
0
ファイル: TestRenderer.cs プロジェクト: optimus-code/Q2Sharp
        private void TestModel()
        {
            refdef_t refdef = new refdef_t();

            refdef.x      = viddef.GetWidth() / 2;
            refdef.y      = viddef.GetHeight() / 2 - 72;
            refdef.width  = 144 * 2;
            refdef.height = 168 * 2;
            refdef.fov_x  = 40;
            refdef.fov_y  = Math3D.CalcFov(refdef.fov_x, refdef.width, refdef.height);
            refdef.time   = 1F * 0.001F;
            entity_t entity      = new entity_t();
            string   modelName   = "players/female/tris.md2";
            string   modelSkin   = "players/female/athena.pcx";
            string   modelImage  = "/players/female/athena_i.pcx";
            string   modelImage1 = "/players/female/brianna_i.pcx";
            string   modelImage2 = "/players/female/cobalt_i.pcx";
            string   modelImage3 = "/players/female/lotus_i.pcx";

            entity.model = re.RegisterModel(modelName);
            DrawString(refdef.x, refdef.y - 20, (entity.model != null) ? modelName : "DEBUG: NullModel");
            entity.skin      = re.RegisterSkin(modelSkin);
            entity.flags     = Defines.RF_FULLBRIGHT;
            entity.origin[0] = 80;
            entity.origin[1] = 0;
            entity.origin[2] = 0;
            Math3D.VectorCopy(entity.origin, entity.oldorigin);
            entity.frame    = (framecount / 3) % ((qfiles.dmdl_t)entity.model.extradata).num_frames;
            entity.oldframe = 0;
            entity.backlerp = 0F;
            yaw            += KBD.mx;
            KBD.mx          = 0;
            if (yaw > 360)
            {
                yaw -= 360;
            }
            if (yaw < 0)
            {
                yaw += 360;
            }
            entity.angles[1]    = yaw;
            refdef.areabits     = null;
            refdef.num_entities = 1;
            refdef.entities     = new entity_t[] { entity };
            refdef.lightstyles  = null;
            refdef.rdflags      = Defines.RDF_NOWORLDMODEL;
            M_DrawTextBox((int)((refdef.x) * (320F / viddef.GetWidth()) - 8), (int)((viddef.GetHeight() / 2) * (240F / viddef.GetHeight()) - 77), refdef.width / 8, refdef.height / 8);
            refdef.height += 4;
            re.RenderFrame(refdef);
            re.DrawPic(refdef.x - 80, refdef.y, modelImage);
            re.DrawPic(refdef.x - 80, refdef.y + 47, modelImage1);
            re.DrawPic(refdef.x - 80, refdef.y + 94, modelImage2);
            re.DrawPic(refdef.x - 80, refdef.y + 141, modelImage3);
        }
コード例 #3
0
ファイル: TestRenderer.cs プロジェクト: optimus-code/Q2Sharp
        private void TestSprites()
        {
            if (loading)
            {
                re.DrawPic(viddef.GetWidth() / 2 - 50, viddef.GetHeight() / 2, "loading");
                string name = sprites[spriteCount];
                DrawString(viddef.GetWidth() / 2 - 50, viddef.GetHeight() / 2 + 50, name);
                re.RegisterModel(name);
                loading = ++spriteCount < sprites.Length;
                return;
            }

            refdef_t refdef = new refdef_t();

            refdef.x      = viddef.GetWidth() / 2;
            refdef.y      = viddef.GetHeight() / 2 - 72;
            refdef.width  = 144 * 2;
            refdef.height = 168 * 2;
            refdef.fov_x  = 40;
            refdef.fov_y  = Math3D.CalcFov(refdef.fov_x, refdef.width, refdef.height);
            refdef.time   = 1F * 0.001F;
            entity_t entity    = new entity_t();
            string   modelName = sprites[(framecount / 30) % sprites.Length];

            DrawString(refdef.x, refdef.y - 20, modelName);
            entity.model     = re.RegisterModel(modelName);
            entity.flags     = Defines.RF_FULLBRIGHT;
            entity.origin[0] = 80 - (framecount % 200) + 200;
            entity.origin[1] = 0 + (float)(40 * Math.Sin(Math.ToRadians(framecount)));
            entity.origin[2] = 0 + 20;
            Math3D.VectorCopy(entity.origin, entity.oldorigin);
            entity.frame        = framecount / 2;
            entity.oldframe     = 0;
            entity.backlerp     = 0F;
            refdef.areabits     = null;
            refdef.num_entities = 1;
            refdef.entities     = new entity_t {
                entity
            };
            refdef.lightstyles = null;
            refdef.rdflags     = Defines.RDF_NOWORLDMODEL;
            M_DrawTextBox((int)((refdef.x) * (320F / viddef.GetWidth()) - 8), (int)((viddef.GetHeight() / 2) * (240F / viddef.GetHeight()) - 77), refdef.width / 8, refdef.height / 8);
            refdef.height += 4;
            re.RenderFrame(refdef);
        }
コード例 #4
0
ファイル: TestRenderer.cs プロジェクト: optimus-code/Q2Sharp
        private void TestParticles()
        {
            r_numparticles = 0;
            if (active_particles.Count == 0)
            {
                if (explode)
                {
                    Explosion(target);
                }
                else
                {
                    target = new float[] { 150 + Lib.Crand() * 80, Lib.Crand() * 40, Lib.Crand() * 40 };
                    RailTrail(new float[] { 30, -20, -20 }, target);
                }

                explode = !explode;
            }

            refdef_t refdef = new refdef_t();

            refdef.x      = viddef.GetWidth() / 2;
            refdef.y      = viddef.GetHeight() / 2 - 72;
            refdef.width  = 400;
            refdef.height = 400;
            refdef.fov_x  = 50;
            refdef.fov_y  = Math3D.CalcFov(refdef.fov_x, refdef.width, refdef.height);
            refdef.time   = 1F * 0.001F;
            AnimateParticles();
            DrawString(refdef.x, refdef.y - 20, "active particles: " + r_numparticles);
            refdef.num_particles = r_numparticles;
            refdef.areabits      = null;
            refdef.num_entities  = 0;
            refdef.entities      = null;
            refdef.lightstyles   = null;
            refdef.rdflags       = Defines.RDF_NOWORLDMODEL;
            M_DrawTextBox((int)((refdef.x) * (320F / viddef.GetWidth()) - 8), (int)((viddef.GetHeight() / 2) * (240F / viddef.GetHeight()) - 77), refdef.width / 8, refdef.height / 8);
            refdef.height += 4;
            re.RenderFrame(refdef);
        }
コード例 #5
0
ファイル: TestRenderer.cs プロジェクト: optimus-code/Q2Sharp
        private void TestBeam()
        {
            refdef_t refdef = new refdef_t();

            refdef.x      = viddef.GetWidth() / 2;
            refdef.y      = viddef.GetHeight() / 2 - 72;
            refdef.width  = 144 * 2;
            refdef.height = 168 * 2;
            refdef.fov_x  = 40;
            refdef.fov_y  = Math3D.CalcFov(refdef.fov_x, refdef.width, refdef.height);
            refdef.time   = 1F * 0.001F;
            entity_t entity = new entity_t();

            DrawString(refdef.x, refdef.y - 20, "Beam Test");
            entity.flags        = Defines.RF_BEAM;
            entity.origin[0]    = 200;
            entity.origin[1]    = 0 + (float)(80 * Math.Sin(4 * Math.ToRadians(framecount)));
            entity.origin[2]    = 20 + (float)(40 * Math.Cos(4 * Math.ToRadians(framecount)));
            entity.oldorigin[0] = 20;
            entity.oldorigin[1] = 0;
            entity.oldorigin[2] = -20;
            entity.frame        = 3;
            entity.oldframe     = 0;
            entity.backlerp     = 0F;
            entity.alpha        = 0.6F;
            int[] color = new[] { 0xd0, 0xd1, 0xe0, 0xb0 };
            entity.skinnum      = color[framecount / 2 % 4];
            entity.model        = null;
            refdef.areabits     = null;
            refdef.num_entities = 1;
            refdef.entities     = new entity_t[] { entity };
            refdef.lightstyles  = null;
            refdef.rdflags      = Defines.RDF_NOWORLDMODEL;
            M_DrawTextBox((int)((refdef.x) * (320F / viddef.GetWidth()) - 8), (int)((viddef.GetHeight() / 2) * (240F / viddef.GetHeight()) - 77), refdef.width / 8, refdef.height / 8);
            refdef.height += 4;
            re.RenderFrame(refdef);
        }
コード例 #6
0
ファイル: V.cs プロジェクト: optimus-code/Quake2Sharp
        /*
         * ================== 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();
        }
コード例 #7
0
ファイル: TestMap.cs プロジェクト: optimus-code/Q2Sharp
        private void RunTest()
        {
            if (refdef == null)
            {
                refdef            = new refdef_t();
                refdef.x          = 0;
                refdef.y          = 0;
                refdef.width      = viddef.GetWidth();
                refdef.height     = viddef.GetHeight();
                refdef.fov_x      = (Globals.fov == null) ? this.fov_x : Globals.fov.value;
                refdef.fov_x      = this.fov_x;
                refdef.fov_y      = Math3D.CalcFov(refdef.fov_x, refdef.width, refdef.height);
                refdef.vieworg    = new float[] { 140, -140, 50 };
                refdef.viewangles = new float[] { 0, 0, 0 };
                refdef.blend      = new float[] { 0F, 0F, 0F, 0F };
                refdef.areabits   = null;
                ent = new entity_t();
                model_t weapon     = re.RegisterModel("models/monsters/soldier/tris.md2");
                image_t weaponSkin = re.RegisterSkin("models/monsters/soldier/skin.pcx");
                ent.model  = weapon;
                ent.skin   = weaponSkin;
                ent.origin = new float[] { -60, 80, 25 };
                Math3D.VectorCopy(ent.origin, ent.oldorigin);
                ent.angles          = new float[] { 0, 300, 0 };
                refdef.entities     = new entity_t[] { ent };
                refdef.num_entities = refdef.entities.Length;
                lightstyle_t light = new lightstyle_t();
                light.rgb          = new float[] { 1F, 1F, 1F };
                light.white        = 3F;
                refdef.lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES];
                for (int i = 0; i < Defines.MAX_LIGHTSTYLES; i++)
                {
                    refdef.lightstyles[i]       = new lightstyle_t();
                    refdef.lightstyles[i].rgb   = new float[] { 1F, 1F, 1F };
                    refdef.lightstyles[i].white = 3F;
                }

                refdef.viewangles[1] = 130;
                refdef.time          = Time() * 0.001F;
            }

            refdef.viewangles[0] += KBD.my * 0.1F;
            refdef.viewangles[1] -= KBD.mx * 0.1F;
            float dt = Time() * 0.001F - refdef.time;

            if (movePlayer != 0)
            {
                float velocity = 150F * dt;
                Math3D.AngleVectors(refdef.viewangles, vpn, vright, vup);
                if ((movePlayer & FORWARD_MASK) != 0)
                {
                    Math3D.VectorMA(refdef.vieworg, -velocity, vpn, refdef.vieworg);
                }
                if ((movePlayer & BACKWARD_MASK) != 0)
                {
                    Math3D.VectorMA(refdef.vieworg, velocity, vpn, refdef.vieworg);
                }
                if ((movePlayer & LEFT_MASK) != 0)
                {
                    Math3D.VectorMA(refdef.vieworg, velocity, vright, refdef.vieworg);
                }
                if ((movePlayer & RIGHT_MASK) != 0)
                {
                    Math3D.VectorMA(refdef.vieworg, -velocity, vright, refdef.vieworg);
                }
                refdef.vieworg[0] += 1F / 16;
                refdef.vieworg[1] += 1F / 16;
                refdef.vieworg[2] += 1F / 16;
            }

            refdef.time    = Time() * 0.001F;
            r_numparticles = 0;
            float[] diff = new float[] { 0, 0, 0 };
            Math3D.VectorSubtract(refdef.vieworg, ent.origin, diff);
            if (Math3D.VectorLength(diff) < 250 && active_particles.Size() == 0)
            {
                RailTrail(ent.origin, refdef.vieworg);
            }
            else
            {
                if (active_particles.Size() > 0)
                {
                    ent.frame = (int)((Time() * 0.013F) % 15);
                    Math3D.VectorNormalize(diff);
                    Math3D.Vectoangles(diff, ent.angles);
                    AnimateParticles();
                    refdef.num_particles = r_numparticles;
                }
                else
                {
                    ent.frame            = 0;
                    refdef.num_particles = 0;
                }
            }

            refdef.num_dlights = 0;
            re.RenderFrame(refdef);
        }
コード例 #8
0
ファイル: V.cs プロジェクト: optimus-code/Q2Sharp
        public static void RenderView(Single stereo_separation)
        {
            if (cls.state != ca_active)
            {
                return;
            }
            if (!cl.refresh_prepped)
            {
                return;
            }
            if (cl_timedemo.value != 0F)
            {
                if (cl.timedemo_start == 0)
                {
                    cl.timedemo_start = Timer.Milliseconds();
                }
                cl.timedemo_frames++;
            }

            if (cl.frame.valid && (cl.force_refdef || cl_paused.value == 0F))
            {
                cl.force_refdef = false;
                V.ClearScene();
                CL_ents.AddEntities();
                if (cl_testparticles.value != 0F)
                {
                    TestParticles();
                }
                if (cl_testentities.value != 0F)
                {
                    TestEntities();
                }
                if (cl_testlights.value != 0F)
                {
                    TestLights();
                }
                if (cl_testblend.value != 0F)
                {
                    cl.refdef.blend[0] = 1F;
                    cl.refdef.blend[1] = 0.5F;
                    cl.refdef.blend[2] = 0.25F;
                    cl.refdef.blend[3] = 0.5F;
                }

                if (stereo_separation != 0)
                {
                    Single[] tmp = new Single[3];
                    Math3D.VectorScale(cl.v_right, stereo_separation, tmp);
                    Math3D.VectorAdd(cl.refdef.vieworg, tmp, cl.refdef.vieworg);
                }

                cl.refdef.vieworg[0] += 1 / 16;
                cl.refdef.vieworg[1] += 1 / 16;
                cl.refdef.vieworg[2] += 1 / 16;
                cl.refdef.x           = scr_vrect.x;
                cl.refdef.y           = scr_vrect.y;
                cl.refdef.width       = scr_vrect.width;
                cl.refdef.height      = scr_vrect.height;
                cl.refdef.fov_y       = Math3D.CalcFov(cl.refdef.fov_x, cl.refdef.width, cl.refdef.height);
                cl.refdef.time        = cl.time * 0.001F;
                cl.refdef.areabits    = cl.frame.areabits;
                if (cl_add_entities.value == 0F)
                {
                    r_numentities = 0;
                }
                if (cl_add_particles.value == 0F)
                {
                    r_numparticles = 0;
                }
                if (cl_add_lights.value == 0F)
                {
                    r_numdlights = 0;
                }
                if (cl_add_blend.value == 0)
                {
                    Math3D.VectorClear(cl.refdef.blend);
                }

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

            re.RenderFrame(cl.refdef);
            if (cl_stats.value != 0F)
            {
                Com.Printf("ent:%i  lt:%i  part:%i\\n", r_numentities, r_numdlights, r_numparticles);
            }
            if (log_stats.value != 0F && (log_stats_file != null))
            {
                try
                {
                    log_stats_file.Write(r_numentities + "," + r_numdlights + "," + r_numparticles);
                }
                catch (Exception e)
                {
                }
            }

            SCR.AddDirtyPoint(scr_vrect.x, scr_vrect.y);
            SCR.AddDirtyPoint(scr_vrect.x + scr_vrect.width - 1, scr_vrect.y + scr_vrect.height - 1);
            SCR.DrawCrosshair();
        }