コード例 #1
0
ファイル: MapStuff.cs プロジェクト: Kharzette/GrogTest
        internal void FreeAll()
        {
            mZoneMats.FreeAll();
            mZoneDraw.FreeAll();

            mSKeeper.FreeAll();
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: Kharzette/GrogTest
        internal void FreeAll()
        {
            if (mStaticMats != null)
            {
                mStaticMats.FreeAll();
            }
            mKeeper.Clear();
            if (mCharMats != null)
            {
                mCharMats.FreeAll();
            }

            mSKeeper.FreeAll();
        }
コード例 #3
0
ファイル: BSPBuilder.cs プロジェクト: Kharzette/GrogTools
        internal void FreeAll()
        {
            if (mMap != null)
            {
                mMap.FreeGBSPFile();
            }

            if (mVisMap != null)
            {
                mVisMap.FreeFileVisData();
            }

            if (mZoneDraw != null)
            {
                mZoneDraw.FreeAll();
            }

            mMatLib.FreeAll();
            mDebugDraw.FreeAll();

            mSKeeper.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;
            mSKeeper.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;
            mSKeeper.FreeAll();
        }
コード例 #4
0
ファイル: MapLoop.cs プロジェクト: Kharzette/GrogTest
        internal void FreeAll()
        {
            FreeLevelData();

            mShadowHelper.FreeAll();
            mPost.FreeAll(mGD);
            mFontMats.FreeAll();
            mZoneMats.FreeAll();
            mKeeper.Clear();
            if (mStaticMats != null)
            {
                mStaticMats.FreeAll();
            }
            if (mPMats != null)
            {
                mPMats.FreeAll();
            }
            if (mPChar != null)
            {
                mPChar.FreeAll();
            }
            mPartMats.FreeAll();

            if (mPAnims != null)
            {
                mPArch.FreeAll();
            }

            if (mDynLights != null)
            {
                mDynLights.FreeAll();
            }

            foreach (KeyValuePair <string, IArch> stat in mStatics)
            {
                stat.Value.FreeAll();
            }
            mStatics.Clear();

            mAudio.FreeAll();

            mSKeeper.FreeAll();
        }
コード例 #5
0
        static void Main()
        {
            GraphicsDevice gd = new GraphicsDevice("Test Terrain",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

            //save renderform position
            gd.RendForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                          Properties.Settings.Default,
                                                                          "MainWindowPos", true,
                                                                          System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            int borderWidth  = gd.RendForm.Size.Width - gd.RendForm.ClientSize.Width;
            int borderHeight = gd.RendForm.Size.Height - gd.RendForm.ClientSize.Height;

            gd.RendForm.Location = Properties.Settings.Default.MainWindowPos;
            gd.RendForm.Size     = new System.Drawing.Size(
                1280 + borderWidth,
                720 + borderHeight);

            gd.CheckResize();

            StuffKeeper sk = new StuffKeeper();

            //set title of progress window
            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            //used to have a hard coded path here for #debug
            //but now can just use launch.json to provide it
            string rootDir = ".";

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, rootDir);

            TerrainLoop    terLoop   = new TerrainLoop(gd, sk, rootDir);
            PlayerSteering pSteering = SetUpSteering();
            Input          inp       = SetUpInput();
            Random         rand      = new Random();

            UpdateTimer time = new UpdateTimer(true, false);

            time.SetFixedTimeStepSeconds(1f / 60f);             //60fps update rate
            time.SetMaxDeltaSeconds(MaxTimeDelta);

            Vector3 pos          = Vector3.One * 5f;
            Vector3 lightDir     = -Vector3.UnitY;
            bool    bMouseLookOn = false;

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
            {
                inp.ClearInputs();
            });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            List <Input.InputAction> acts = new List <Input.InputAction>();

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                //Clear views
                gd.ClearViews();

                time.Stamp();
                while (time.GetUpdateDeltaSeconds() > 0f)
                {
                    acts = UpdateInput(inp, gd,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                    }
                    terLoop.Update(time, acts, pSteering);
                    time.UpdateDone();
                }

                terLoop.RenderUpdate(time.GetRenderUpdateDeltaMilliSeconds());

                terLoop.Render();

                gd.Present();

                acts.Clear();
            });

            Properties.Settings.Default.Save();

            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;

            terLoop.FreeAll();
            inp.FreeAll();
            sk.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
コード例 #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            GraphicsDevice gd = new GraphicsDevice("Particle Editing Tool",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

            //save renderform position
            gd.RendForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                          Settings.Default,
                                                                          "MainWindowPos", true,
                                                                          System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            gd.RendForm.Location = Settings.Default.MainWindowPos;

            //used to have a hard coded path here for #debug
            //but now can just use launch.json to provide it
            string rootDir = ".";

            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            StuffKeeper sk = new StuffKeeper();

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, rootDir);

            MatLib      matLib = new MatLib(gd, sk);
            CommonPrims cprims = new CommonPrims(gd, sk);

            matLib.InitCelShading(1);
            matLib.GenerateCelTexturePreset(gd.GD,
                                            gd.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
            matLib.SetCelTexture(0);

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            ParticleForm   partForm     = SetUpForms(gd.GD, matLib, sk);
            ParticleEditor partEdit     = new ParticleEditor(gd, partForm, matLib);
            bool           bMouseLookOn = false;

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { inp.ClearInputs(); });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            Vector3 pos      = Vector3.One * 5f;
            Vector3 lightDir = -Vector3.UnitY;
            long    lastTime = Stopwatch.GetTimestamp();
            long    freq     = Stopwatch.Frequency;

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                //Clear views
                gd.ClearViews();

                long timeNow   = Stopwatch.GetTimestamp();
                long delta     = timeNow - lastTime;
                float secDelta = Math.Min((float)delta / freq, 0.1f);
                int msDelta    = Math.Max((int)(secDelta * 1000f), 1);

                List <Input.InputAction> actions = UpdateInput(inp, gd, secDelta, ref bMouseLookOn);
                if (!gd.RendForm.Focused)
                {
                    actions.Clear();
                    bMouseLookOn = false;
                    gd.SetCapture(false);
                    inp.UnMapAxisAction(Input.MoveAxis.MouseYAxis);
                    inp.UnMapAxisAction(Input.MoveAxis.MouseXAxis);
                }

                Vector3 moveDelta = pSteering.Update(pos, gd.GCam.Forward, gd.GCam.Left, gd.GCam.Up, actions);

                moveDelta *= 300f;

                pos -= moveDelta;

                gd.GCam.Update(pos, pSteering.Pitch, pSteering.Yaw, pSteering.Roll);

                matLib.UpdateWVP(Matrix.Identity, gd.GCam.View, gd.GCam.Projection, gd.GCam.Position);

                cprims.Update(gd.GCam, lightDir);

                cprims.DrawAxis(gd.DC);

                partEdit.Update(msDelta);
                partEdit.Draw();

                gd.Present();

                lastTime = timeNow;
            }, true);                   //true here is slow but needed for winforms events

            matLib.FreeAll();

            Settings.Default.Save();

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;

            cprims.FreeAll();
            inp.FreeAll();
            matLib.FreeAll();

            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;
            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;

            sk.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Kharzette/GrogTools
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            GraphicsDevice gd = new GraphicsDevice("Terrain Editor",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

            //save form positions
            gd.RendForm.DataBindings.Add(new Binding("Location",
                                                     Settings.Default, "MainWindowPos", true,
                                                     DataSourceUpdateMode.OnPropertyChanged));

            gd.RendForm.Location = Settings.Default.MainWindowPos;

            //used to have a hard coded path here for #debug
            //but now can just use launch.json to provide it
            string rootDir = ".";

            StuffKeeper sk = new StuffKeeper();

            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, rootDir);

            TerrainAtlas ta = new TerrainAtlas(gd, sk);

            ta.DataBindings.Add(new Binding("Location",
                                            Settings.Default, "AtlasFormPos", true,
                                            DataSourceUpdateMode.OnPropertyChanged));
            ta.DataBindings.Add(new Binding("Size",
                                            Settings.Default, "AtlasFormSize", true,
                                            DataSourceUpdateMode.OnPropertyChanged));

            ta.Location = Settings.Default.AtlasFormPos;
            ta.Size     = Settings.Default.AtlasFormSize;
            ta.Visible  = true;

            TerrainForm tf = new TerrainForm();

            tf.DataBindings.Add(new Binding("Location",
                                            Settings.Default, "TerrainFormPos", true,
                                            DataSourceUpdateMode.OnPropertyChanged));

            tf.Location = Settings.Default.TerrainFormPos;
            tf.Visible  = true;

            TerrainShading ts = new TerrainShading();

            ts.DataBindings.Add(new Binding("Location",
                                            Settings.Default, "ShadingFormPos", true,
                                            DataSourceUpdateMode.OnPropertyChanged));

            ts.Location = Settings.Default.ShadingFormPos;
            ts.Visible  = true;

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            Vector3        pos          = Vector3.One * 5f;
            Vector3        lightDir     = -Vector3.UnitY;
            bool           bMouseLookOn = false;

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { inp.ClearInputs(); });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            GameLoop gLoop = new GameLoop(gd, sk, rootDir);

            EventHandler buildHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { ListEventArgs <HeightMap.TexData> lea = ea as ListEventArgs <HeightMap.TexData>;
                  gLoop.Texture((TexAtlas)s, lea.mList, ta.GetTransitionHeight()); });

            EventHandler applyHandler = new EventHandler(
                delegate(object s, EventArgs ea)
            {
                TerrainShading.ShadingInfo si = s as TerrainShading.ShadingInfo;
                gLoop.ApplyShadingInfo(si);
            });

            ta.eReBuild += buildHandler;
            ts.eApply   += applyHandler;

            EventHandler tBuildHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { int gridSize, chunkSize, tilingIterations, threads;
                  int erosionIterations, polySize, smoothPasses, seed;
                  float medianHeight, variance, borderSize;
                  float rainFall, solubility, evaporation;
                  tf.GetBuildData(out gridSize, out chunkSize,
                                  out medianHeight, out variance, out polySize,
                                  out tilingIterations, out borderSize, out smoothPasses,
                                  out seed, out erosionIterations, out rainFall,
                                  out solubility, out evaporation, out threads);
                  gLoop.TBuild(gridSize, chunkSize, medianHeight, variance,
                               polySize, tilingIterations, borderSize,
                               smoothPasses, seed, erosionIterations,
                               rainFall, solubility, evaporation, threads); });
            EventHandler tLoadHandler = new EventHandler(
                delegate(object s, EventArgs ea)
            {
                gLoop.TLoad(s as string);
                ta.LoadAtlasInfo(s as string);
            });
            EventHandler tSaveHandler = new EventHandler(
                delegate(object s, EventArgs ea)
            {
                if (gLoop.TSave(s as string))
                {
                    ta.SaveAtlasInfo(s as string);
                    ts.SaveShadingInfo(s as string);
                }
            });

            tf.eBuild += tBuildHandler;
            tf.eLoad  += tLoadHandler;
            tf.eSave  += tSaveHandler;

            UpdateTimer time = new UpdateTimer(true, false);

            time.SetFixedTimeStepSeconds(1f / 60f);             //60fps update rate
            time.SetMaxDeltaSeconds(MaxTimeDelta);

            List <Input.InputAction> acts = new List <Input.InputAction>();

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                //Clear views
                gd.ClearViews();

                time.Stamp();
                while (time.GetUpdateDeltaSeconds() > 0f)
                {
                    acts = UpdateInput(inp, gd,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseYAxis);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseXAxis);
                    }
                    gLoop.Update(time, acts, pSteering);
                    time.UpdateDone();
                }

                gLoop.RenderUpdate(time.GetRenderUpdateDeltaMilliSeconds());

                gLoop.Render();

                gd.Present();

                acts.Clear();
            }, true);                   //true here is slow but needed for winforms events

            Settings.Default.Save();

            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;
            ta.eReBuild -= buildHandler;
            tf.eBuild   -= tBuildHandler;
            ts.eApply   -= applyHandler;

            gLoop.FreeAll();
            inp.FreeAll();
            ta.FreeAll();
            sk.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Kharzette/GrogTools
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //turn this on for help with leaky stuff
            //Configuration.EnableObjectTracking	=true;

            GraphicsDevice gd = new GraphicsDevice("Collada Conversion Tool",
                                                   FeatureLevel.Level_9_3, 0.1f, 3000f);

            //save renderform position
            gd.RendForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                          Settings.Default,
                                                                          "MainWindowPos", true,
                                                                          System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            gd.RendForm.Location = Settings.Default.MainWindowPos;

            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            StuffKeeper sk = new StuffKeeper();

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, ".");

            MatLib matLib = new MatLib(gd, sk);

            matLib.InitCelShading(1);
            matLib.GenerateCelTexturePreset(gd.GD,
                                            gd.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
            matLib.SetCelTexture(0);

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            CommonPrims    comPrims     = new CommonPrims(gd, sk);
            bool           bMouseLookOn = false;

            //set up post processing module
            PostProcess post = new PostProcess(gd, matLib, "Post.fx");

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { inp.ClearInputs(); });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            int resx = gd.RendForm.ClientRectangle.Width;
            int resy = gd.RendForm.ClientRectangle.Height;

            AnimForm ss = SetUpForms(gd.GD, matLib, sk, comPrims);

            Vector3 pos      = Vector3.One * 5f;
            Vector3 lightDir = -Vector3.UnitY;

            UpdateTimer time = new UpdateTimer(true, false);

            time.SetFixedTimeStepSeconds(1f / 60f);             //60fps update rate
            time.SetMaxDeltaSeconds(MaxTimeDelta);

            List <Input.InputAction> acts = new List <Input.InputAction>();

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                //Clear views
                gd.ClearViews();

                time.Stamp();
                while (time.GetUpdateDeltaSeconds() > 0f)
                {
                    acts = UpdateInput(inp, gd,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseYAxis);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseXAxis);
                    }

                    Vector3 deltaMove = pSteering.Update(pos,
                                                         gd.GCam.Forward, gd.GCam.Left, gd.GCam.Up, acts);

                    deltaMove *= 200f;
                    pos       -= deltaMove;

                    ChangeLight(acts, ref lightDir);

                    time.UpdateDone();
                }

                //light direction is backwards now for some strange reason
                matLib.SetParameterForAll("mLightDirection", -lightDir);

                gd.GCam.Update(pos, pSteering.Pitch, pSteering.Yaw, pSteering.Roll);

                matLib.UpdateWVP(Matrix.Identity, gd.GCam.View, gd.GCam.Projection, gd.GCam.Position);

                comPrims.Update(gd.GCam, lightDir);

                ss.RenderUpdate(time.GetRenderUpdateDeltaSeconds());

                post.SetTargets(gd, "BackColor", "BackDepth");

                post.ClearTarget(gd, "BackColor", Color.CornflowerBlue);
                post.ClearDepth(gd, "BackDepth");

                ss.Render(gd.DC);

                if (ss.GetDrawAxis())
                {
                    comPrims.DrawAxis(gd.DC);
                }

                if (ss.GetDrawBox())
                {
                    comPrims.DrawBox(gd.DC, Matrix.Identity);
                }

                if (ss.GetDrawSphere())
                {
                    comPrims.DrawSphere(gd.DC, Matrix.Identity);
                }

                gd.Present();

                acts.Clear();
            }, true);                   //true here is slow but needed for winforms events

            Settings.Default.Save();

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;

            comPrims.FreeAll();
            inp.FreeAll();
            post.FreeAll(gd);
            matLib.FreeAll();

            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;
            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;

            sk.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
コード例 #9
0
ファイル: RunLoop.cs プロジェクト: Kharzette/GrogTest
 internal void FreeAll()
 {
     mSKeeper.FreeAll();
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: Kharzette/GrogTest
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            GraphicsDevice gd = new GraphicsDevice("Audio Test Program",
                                                   FeatureLevel.Level_9_3, 0.1f, 3000f);

            //save renderform position
            gd.RendForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                          Settings.Default,
                                                                          "MainWindowPos", true,
                                                                          System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            gd.RendForm.Location = Settings.Default.MainWindowPos;

            //used to have a hard coded path here for #debug
            //but now can just use launch.json to provide it
            string gameRootDir = ".";

            Audio aud = new Audio();

            aud.LoadAllSounds(gameRootDir + "/Audio/SoundFX");
            aud.LoadAllSounds(gameRootDir + "/Audio/Music");

            List <string> sounds = aud.GetSoundList();

            int curSound = 0;

            Emitter emitter = Audio.MakeEmitter(Vector3.Zero);

            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            StuffKeeper sk = new StuffKeeper();

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, gameRootDir);

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            CommonPrims    comPrims     = new CommonPrims(gd, sk);
            bool           bMouseLookOn = false;

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { inp.ClearInputs(); });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            int resx = gd.RendForm.ClientRectangle.Width;
            int resy = gd.RendForm.ClientRectangle.Height;

            MatLib fontMats = new MatLib(gd, sk);

            fontMats.CreateMaterial("Text");
            fontMats.SetMaterialEffect("Text", "2D.fx");
            fontMats.SetMaterialTechnique("Text", "Text");

            List <string> fonts = sk.GetFontList();

            ScreenText st = new ScreenText(gd.GD, fontMats, fonts[0], 1000);

            Matrix textProj = Matrix.OrthoOffCenterLH(0, resx, resy, 0, 0.1f, 5f);

            Vector4 color = Vector4.UnitX + (Vector4.UnitW * 0.95f);

            //string indicators for various statusy things
            st.AddString(fonts[0], "P - Play2D   L - Play at Emitter   [] - Prev/Next Sound  E - Set Emitter Pos to Camera Pos",
                         "Instructions", color, Vector2.UnitX * 20f + Vector2.UnitY * 520f, Vector2.One);
            st.AddString(fonts[0], "Stuffs", "CurrentSound",
                         color, Vector2.UnitX * 20f + Vector2.UnitY * 540f, Vector2.One);
            st.AddString(fonts[0], "Stuffs", "EmitterPosition",
                         color, Vector2.UnitX * 20f + Vector2.UnitY * 560f, Vector2.One);
            st.AddString(fonts[0], "Stuffs", "PosStatus",
                         color, Vector2.UnitX * 20f + Vector2.UnitY * 580f, Vector2.One);

            Vector3     pos      = Vector3.One * 5f;
            Vector3     lightDir = -Vector3.UnitY;
            UpdateTimer time     = new UpdateTimer(false, false);

            time.SetFixedTimeStepSeconds(1f / 60f);             //60fps update rate
            time.SetMaxDeltaSeconds(MaxTimeDelta);

            List <Input.InputAction> acts = new List <Input.InputAction>();

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                time.Stamp();
                while (time.GetUpdateDeltaSeconds() > 0f)
                {
                    acts = UpdateInput(inp, gd,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseYAxis);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseXAxis);
                    }
                    Vector3 moveDelta = pSteering.Update(pos, gd.GCam.Forward,
                                                         gd.GCam.Left, gd.GCam.Up, acts);

                    moveDelta *= 200f;

                    pos -= moveDelta;

                    gd.GCam.Update(pos, pSteering.Pitch, pSteering.Yaw, pSteering.Roll);

                    CheckInputKeys(acts, aud, ref curSound, sounds, emitter, gd.GCam.Position);

                    //update status text
                    st.ModifyStringText(fonts[0], "Current Sound: " + sounds[curSound], "CurrentSound");
                    st.ModifyStringText(fonts[0], "Emitter Pos: " + emitter.Position.X + ", " + emitter.Position.Y + ", " + emitter.Position.Z, "EmitterPosition");
                    st.ModifyStringText(fonts[0], "Cam Pos: " + gd.GCam.Position +
                                        ", Sounds Playing: " + aud.GetNumInstances(), "PosStatus");
                    time.UpdateDone();
                }


                st.Update(gd.DC);

                comPrims.Update(gd.GCam, lightDir);

                aud.Update(gd.GCam);

                //Clear views
                gd.ClearViews();

                comPrims.DrawAxis(gd.DC);

                st.Draw(gd.DC, Matrix.Identity, textProj);

                gd.Present();

                acts.Clear();
            }, true);                   //true here is slow but needed for winforms events

            Settings.Default.Save();

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;

            //Release all resources
            st.FreeAll();
            fontMats.FreeAll();
            comPrims.FreeAll();
            inp.FreeAll();

            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;
            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.FreeAll();

            aud.FreeAll();
            gd.ReleaseAll();
        }
コード例 #11
0
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //turn this on for help with leaky stuff
            //Configuration.EnableObjectTracking	=true;

            GraphicsDevice gd = new GraphicsDevice("BSP Light Explorer",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

            //save renderform position
            gd.RendForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                          Settings.Default,
                                                                          "MainWindowPos", true,
                                                                          System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            gd.RendForm.Location = Settings.Default.MainWindowPos;

            SharedForms.ShaderCompileHelper.mTitle = "Compiling Shaders...";

            StuffKeeper sk = new StuffKeeper();

            sk.eCompileNeeded += SharedForms.ShaderCompileHelper.CompileNeededHandler;
            sk.eCompileDone   += SharedForms.ShaderCompileHelper.CompileDoneHandler;

            sk.Init(gd, ".");

            MatLib matLib = new MatLib(gd, sk);

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            CommonPrims    comPrims     = new CommonPrims(gd, sk);
            bool           bMouseLookOn = false;
            LightExplorer  lex          = new LightExplorer(gd, sk);

            EventHandler actHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { inp.ClearInputs(); });

            EventHandler <EventArgs> deActHandler = new EventHandler <EventArgs>(
                delegate(object s, EventArgs ea)
            {
                gd.SetCapture(false);
                bMouseLookOn = false;
            });

            gd.RendForm.Activated      += actHandler;
            gd.RendForm.AppDeactivated += deActHandler;

            int resx = gd.RendForm.ClientRectangle.Width;
            int resy = gd.RendForm.ClientRectangle.Height;

            Vector3 pos      = Vector3.One * 5f;
            Vector3 lightDir = -Vector3.UnitY;

            UpdateTimer time = new UpdateTimer(true, false);

            time.SetFixedTimeStepSeconds(1f / 60f);             //60fps update rate
            time.SetMaxDeltaSeconds(MaxTimeDelta);

            List <Input.InputAction> acts = new List <Input.InputAction>();

            RenderLoop.Run(gd.RendForm, () =>
            {
                if (!gd.RendForm.Focused)
                {
                    Thread.Sleep(33);
                }

                gd.CheckResize();

                if (bMouseLookOn && gd.RendForm.Focused)
                {
                    gd.ResetCursorPos();
                }

                //Clear views
                gd.ClearViews();

                time.Stamp();
                while (time.GetUpdateDeltaSeconds() > 0f)
                {
                    acts = UpdateInput(inp, gd,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseYAxis);
                        inp.UnMapAxisAction(Input.MoveAxis.MouseXAxis);
                    }

                    //check for speediness
                    //psteering only allows speedy ground sprinting
                    bool bFast = false;
                    for (int i = 0; i < acts.Count; i++)
                    {
                        if (acts[i].mAction.Equals(MyActions.MoveForwardFast))
                        {
                            bFast = true;
                        }
                    }

                    Vector3 deltaMove = pSteering.Update(pos,
                                                         gd.GCam.Forward, gd.GCam.Left, gd.GCam.Up, acts);

                    if (bFast)
                    {
                        deltaMove *= 400f;
                    }
                    else
                    {
                        deltaMove *= 200f;
                    }
                    pos -= deltaMove;

                    ChangeLight(acts, ref lightDir);

                    lex.UpdateActions(acts);

                    time.UpdateDone();
                }

                //light direction is backwards now for some strange reason
                matLib.SetParameterForAll("mLightDirection", -lightDir);

                gd.GCam.Update(pos, pSteering.Pitch, pSteering.Yaw, pSteering.Roll);

                matLib.UpdateWVP(Matrix.Identity, gd.GCam.View, gd.GCam.Projection, gd.GCam.Position);

                comPrims.Update(gd.GCam, lightDir);

                lex.Update(time.GetUpdateDeltaMilliSeconds(), gd);
                lex.Render(gd);

                gd.Present();

                acts.Clear();
            }, true);                   //true here is slow but needed for winforms events

            Settings.Default.Save();

            gd.RendForm.Activated      -= actHandler;
            gd.RendForm.AppDeactivated -= deActHandler;

            lex.FreeAll();
            comPrims.FreeAll();
            inp.FreeAll();
            matLib.FreeAll();

            sk.eCompileDone   -= SharedForms.ShaderCompileHelper.CompileDoneHandler;
            sk.eCompileNeeded -= SharedForms.ShaderCompileHelper.CompileNeededHandler;

            sk.FreeAll();

            //Release all resources
            gd.ReleaseAll();
//			Application.Run(new Form1());
        }