Пример #1
0
        static ParticleForm SetUpForms(Device gd, MatLib matLib, StuffKeeper sk)
        {
            ParticleForm partForm = new ParticleForm(matLib, sk);

            //save positions
            partForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                       Settings.Default, "ParticleFormPos", true,
                                                                       System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            partForm.Visible = true;

            return(partForm);
        }
Пример #2
0
        internal ParticleForm(MatLib mats, StuffKeeper sk) : base()
        {
            InitializeComponent();

            mMats    = mats;
            mSKeeper = sk;

            StartColor.BackColor = mCurrentColor;

            Array shapeVals = Enum.GetValues(typeof(ParticleLib.Emitter.Shapes));

            Shape.Items.Clear();

            foreach (object val in shapeVals)
            {
                Shape.Items.Add(val);
            }
            Shape.SelectedIndex = 0;

            List <string> texs = sk.GetTexture2DList();

            if (texs.Count <= 0)
            {
                return;
            }

            foreach (string tex in texs)
            {
                if (tex.StartsWith("Particles"))
                {
                    mParticleTextures.Add(tex);
                }
            }

            if (mParticleTextures.Count <= 0)
            {
                TextureBox.Items.Add("Empty!");
                return;
            }

            foreach (string tex in mParticleTextures)
            {
                //strip particles off the front
                string justTex = tex.Substring(10);

                TextureBox.Items.Add(justTex);
            }
            TextureBox.SelectedIndex = 0;
        }
Пример #3
0
        internal LightExplorer(GraphicsDevice gd, StuffKeeper sk)
        {
            mGD = gd;
            mSK = sk;

            mResX = gd.RendForm.ClientRectangle.Width;
            mResY = gd.RendForm.ClientRectangle.Height;

            mGD.eDeviceLost += OnDeviceLost;

            mEForm.Visible = true;
            mOForm.Visible = true;

            mEForm.eOpenGBSP += OnOpenGBSP;

            mFontMats = new MatLib(gd, sk);

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

            mFonts = sk.GetFontList();

            mST  = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);
            mSUI = new ScreenUI(gd.GD, mFontMats, 100);

            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            Vector4 color = Vector4.UnitY + (Vector4.UnitW * 0.15f);

            mSUI.AddGump("UI\\CrossHair", "CrossHair", Vector4.One,
                         Vector2.UnitX * ((mResX / 2) - 16)
                         + Vector2.UnitY * ((mResY / 2) - 16),
                         Vector2.One);

            mST.AddString(mFonts[0], "Face Index: " + mFaceIndex, "FaceIndex",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 400f, Vector2.One);
            mST.AddString(mFonts[0], "Face aimed at: " + mFaceAimedAt, "FaceAimedAt",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 420f, Vector2.One);
        }
Пример #4
0
        internal TerrainAtlas(GraphicsDevice gd, StuffKeeper sk)
        {
            mGD = gd;
            mSK = sk;

            InitializeComponent();

            AtlasGrid.DataSource = mGridData;

            //initial guess at data
            AutoFill();

            AtlasX.DataBindings.Add(new Binding("Value",
                                                Settings.Default, "AtlasX", true,
                                                DataSourceUpdateMode.OnPropertyChanged));
            AtlasY.DataBindings.Add(new Binding("Value",
                                                Settings.Default, "AtlasY", true,
                                                DataSourceUpdateMode.OnPropertyChanged));
            TransitionHeight.DataBindings.Add(new Binding("Value",
                                                          Settings.Default, "TransitionHeight", true,
                                                          DataSourceUpdateMode.OnPropertyChanged));
        }
Пример #5
0
        internal RunLoop(GraphicsDevice gd, string gameRootDir)
        {
            mGD          = gd;
            mGameRootDir = gameRootDir;

            int resX = gd.RendForm.ClientRectangle.Width;
            int resY = gd.RendForm.ClientRectangle.Height;

            mSKeeper = new StuffKeeper();

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

            mSKeeper.Init(mGD, gameRootDir);

            mScreenMatLib = new MatLib(gd, mSKeeper);
            mScreenMatLib.CreateMaterial("TextMode");
            mScreenMatLib.SetMaterialEffect("TextMode", "TextMode.fx");
            mScreenMatLib.SetMaterialTechnique("TextMode", "TextMode");

            mScreen = new Screen(gd, mSKeeper, mScreenMatLib);

            mScreenJunx = new byte[40 * 25];
        }
Пример #6
0
        internal TerrainLoop(GraphicsDevice gd, StuffKeeper sk, string gameRootDir)
        {
            mGD   = gd;
            mSK   = sk;
            mResX = gd.RendForm.ClientRectangle.Width;
            mResY = gd.RendForm.ClientRectangle.Height;

            mFontMats = new MatLib(gd, sk);

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

            mFonts = sk.GetFontList();

            mST = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);

            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            string path = gameRootDir + "\\Levels\\Testa.Terrain";

            mTerrain = new Terrain(path);

            //build model for raycasts/collisions
            mTModel = mTerrain.ConstructModel();
            mTModel.FixBoxHeights();

//			Vector4	color	=Vector4.UnitY + (Vector4.UnitW * 0.15f);
            Vector4 color = Vector4.UnitX * 0.25f +
                            Vector4.UnitZ * 0.25f + (Vector4.UnitW * 0.55f);

            //string indicators for various statusy things
            mST.AddString(mFonts[0], "Stuffs", "PosStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 610f, Vector2.One);
            mST.AddString(mFonts[0], "Stuffs", "ColStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 630f, Vector2.One);
            mST.AddString(mFonts[0], "Thread Status...", "ThreadStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 650f, Vector2.One);

            mTerMats = new MatLib(mGD, sk);

            Vector3 lightDir = Mathery.RandomDirection(mRand);

            Vector4 lightColor2 = Vector4.One * 0.4f;
            Vector4 lightColor3 = Vector4.One * 0.1f;

            lightColor2.W = lightColor3.W = 1f;

            mTerMats.CreateMaterial("Terrain");
            mTerMats.SetMaterialEffect("Terrain", "Terrain.fx");
            mTerMats.SetMaterialTechnique("Terrain", "TriTerrain");
            mTerMats.SetMaterialParameter("Terrain", "mLightColor0", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mLightColor1", lightColor2);
            mTerMats.SetMaterialParameter("Terrain", "mLightColor2", lightColor3);
            mTerMats.SetMaterialParameter("Terrain", "mLightDirection", lightDir);
            mTerMats.SetMaterialParameter("Terrain", "mSolidColour", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mSpecPower", 1);
            mTerMats.SetMaterialParameter("Terrain", "mSpecColor", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mWorld", Matrix.Identity);

            mTerMats.CreateMaterial("Sky");
            mTerMats.SetMaterialEffect("Sky", "Terrain.fx");
            mTerMats.SetMaterialTechnique("Sky", "SkyGradient");

            LoadShading(path);

            mTerMats.InitCelShading(1);
            mTerMats.GenerateCelTexturePreset(mGD.GD, mGD.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
            mTerMats.SetCelTexture(0);

            mSkyCube = PrimFactory.CreateCube(gd.GD, -5f);

            LoadTerrainTextureStuff(path);

            //debug draw
            mDebugMats = new MatLib(gd, sk);

            Vector4 redColor   = Vector4.One;
            Vector4 greenColor = Vector4.One;
            Vector4 blueColor  = Vector4.One;

            redColor.Y = redColor.Z = greenColor.X = greenColor.Z = blueColor.X = blueColor.Y = 0f;

            mDebugMats.CreateMaterial("DebugBoxes");
            mDebugMats.SetMaterialEffect("DebugBoxes", "Static.fx");
            mDebugMats.SetMaterialTechnique("DebugBoxes", "TriSolidSpec");
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor0", Vector4.One);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor1", lightColor2);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor2", lightColor3);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSolidColour", blueColor);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecPower", 1);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecColor", Vector4.One);

            mNumStreamThreads = 2;
            mGroundPos.Y      = 3000f;                  //start above
            mCellGridMax      = mTerrain.GetCellGridMax();
            mBoundary         = mTerrain.GetBoundary();

            Viewport vp = mGD.GetScreenViewPort();

            mGD.GCam.Projection = Matrix.PerspectiveFovLH(
                MathUtil.DegreesToRadians(45f),
                vp.Width / (float)vp.Height, 0.1f, FogEnd);

            mGD.SetClip(0.1f, FogEnd);

            mDrawRays = new DrawRays(mGD, mSK);
            mOtherCam = new GameCamera(vp.Width, vp.Height, vp.Width / (float)vp.Height, 0.1f, FogEnd);
        }
Пример #7
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();
        }
Пример #8
0
        internal MapLoop(GraphicsDevice gd, string gameRootDir)
        {
            mGD          = gd;
            mGameRootDir = gameRootDir;
            mResX        = gd.RendForm.ClientRectangle.Width;
            mResY        = gd.RendForm.ClientRectangle.Height;

            mSKeeper = new StuffKeeper();

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

            mSKeeper.Init(mGD, gameRootDir);

            mZoneMats = new MatLib(gd, mSKeeper);
            mZone     = new Zone();
            mZoneDraw = new MeshLib.IndoorMesh(gd, mZoneMats);
            mPartMats = new MatLib(mGD, mSKeeper);
            mPB       = new ParticleBoss(gd.GD, mPartMats);
            mFontMats = new MatLib(gd, mSKeeper);

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

            mFonts = mSKeeper.GetFontList();

            mST = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);

            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            //grab two UI textures to show how to do gumpery
            List <string> texs  = mSKeeper.GetTexture2DList();
            List <string> uiTex = new List <string>();

            foreach (string tex in texs)
            {
                if (tex.StartsWith("UI"))
                {
                    uiTex.Add(tex);
                }
            }

            Vector4 color = Vector4.UnitY + (Vector4.UnitW * 0.15f);

            //string indicators for various statusy things
            mST.AddString(mFonts[0], "Stuffs", "ClimbStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 600f, Vector2.One);
            mST.AddString(mFonts[0], "Stuffs", "LevelStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 620f, Vector2.One);
            mST.AddString(mFonts[0], "Stuffs", "PosStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 640f, Vector2.One);
            mST.AddString(mFonts[0], "(G), (H) to clear:  Dynamic Lights: 0", "DynStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 660f, Vector2.One);

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

            float   [] thresholds = new float[3 - 1];
            float   [] levels     = new float[3];

            thresholds[0] = 0.7f;
            thresholds[1] = 0.3f;

            levels[0] = 1;
            levels[1] = 0.8f;
            levels[2] = 0.5f;

            mZoneMats.GenerateCelTexture(gd.GD,
                                         gd.GD.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_3,
                                         0, 256, thresholds, levels);
            mZoneMats.SetCelTexture(0);

            mZoneDraw = new IndoorMesh(gd, mZoneMats);

            mAudio.LoadAllSounds(mGameRootDir + "\\Audio\\SoundFX");

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

#if true
            mPost.MakePostTarget(gd, "SceneColor", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostDepth(gd, "SceneDepth", mResX, mResY,
                                (gd.GD.FeatureLevel != FeatureLevel.Level_9_3)?
                                Format.D32_Float_S8X24_UInt : Format.D24_UNorm_S8_UInt);
            mPost.MakePostTarget(gd, "SceneDepthMatNorm", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostTarget(gd, "Bleach", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostTarget(gd, "Outline", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostTargetHalfRes(gd, "Bloom1", mResX / 2, mResY / 2, Format.R16G16B16A16_Float);
            mPost.MakePostTargetHalfRes(gd, "Bloom2", mResX / 2, mResY / 2, Format.R16G16B16A16_Float);
#elif ThirtyTwo
            mPost.MakePostTarget(gd, "SceneColor", mResX, mResY, Format.R8G8B8A8_UNorm);
            mPost.MakePostDepth(gd, "SceneDepth", mResX, mResY,
                                (gd.GD.FeatureLevel != FeatureLevel.Level_9_3)?
                                Format.D32_Float_S8X24_UInt : Format.D24_UNorm_S8_UInt);
            mPost.MakePostTarget(gd, "SceneDepthMatNorm", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostTarget(gd, "Bleach", mResX, mResY, Format.R8G8B8A8_UNorm);
            mPost.MakePostTarget(gd, "Outline", mResX, mResY, Format.R8G8B8A8_UNorm);
            mPost.MakePostTarget(gd, "Bloom1", mResX / 2, mResY / 2, Format.R8G8B8A8_UNorm);
            mPost.MakePostTarget(gd, "Bloom2", mResX / 2, mResY / 2, Format.R8G8B8A8_UNorm);
#else
            mPost.MakePostTarget(gd, "SceneColor", mResX, mResY, Format.B5G5R5A1_UNorm);
            mPost.MakePostDepth(gd, "SceneDepth", mResX, mResY,
                                (gd.GD.FeatureLevel != FeatureLevel.Level_9_3)?
                                Format.D32_Float_S8X24_UInt : Format.D24_UNorm_S8_UInt);
            mPost.MakePostTarget(gd, "SceneDepthMatNorm", mResX, mResY, Format.R16G16B16A16_Float);
            mPost.MakePostTarget(gd, "Bleach", mResX, mResY, Format.B5G5R5A1_UNorm);
            mPost.MakePostTarget(gd, "Outline", mResX, mResY, Format.B5G5R5A1_UNorm);
            mPost.MakePostTarget(gd, "Bloom1", mResX / 2, mResY / 2, Format.B5G5R5A1_UNorm);
            mPost.MakePostTarget(gd, "Bloom2", mResX / 2, mResY / 2, Format.B5G5R5A1_UNorm);
#endif

            if (gd.GD.FeatureLevel != FeatureLevel.Level_9_3)
            {
                mDynLights = new DynamicLights(mGD, mZoneMats, "BSP.fx");
            }

            //see if any static stuff
            if (Directory.Exists(mGameRootDir + "/Statics"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Statics");

                FileInfo[] fi = di.GetFiles("*.MatLib", SearchOption.TopDirectoryOnly);

                if (fi.Length > 0)
                {
                    mStaticMats = new MatLib(gd, mSKeeper);
                    mStaticMats.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);

                    mStaticMats.InitCelShading(1);
                    mStaticMats.GenerateCelTexturePreset(gd.GD,
                                                         (gd.GD.FeatureLevel == FeatureLevel.Level_9_3),
                                                         true, 0);
                    mStaticMats.SetCelTexture(0);
                }
                mStatics = Mesh.LoadAllStaticMeshes(mGameRootDir + "\\Statics", gd.GD);

                //gen bounds, they don't seem to save correctly
                foreach (KeyValuePair <string, IArch> ia in mStatics)
                {
                    ia.Value.UpdateBounds();
                }
            }

            //load character stuff if any around
            if (Directory.Exists(mGameRootDir + "/Characters"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Characters");

                FileInfo[] fi = di.GetFiles("*.AnimLib", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mPAnims = new AnimLib();
                    mPAnims.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);

                    List <Anim> anims = mPAnims.GetAnims();
                    foreach (Anim a in anims)
                    {
                        mAnims.Add(a.Name);
                    }
                }

                fi = di.GetFiles("*.MatLib", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mPMats = new MatLib(mGD, mSKeeper);
                    mPMats.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);
                    mPMats.InitCelShading(1);
                    mPMats.GenerateCelTexturePreset(gd.GD,
                                                    gd.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
                    mPMats.SetCelTexture(0);
                }

                fi = di.GetFiles("*.Character", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mPArch = new CharacterArch();
                    mPArch.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name, mGD.GD, false);
                }

                fi = di.GetFiles("*.CharacterInstance", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mPChar = new Character(mPArch, mPAnims);
                    mPChar.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);
                    mPChar.SetMatLib(mPMats);

                    mPShad = new ShadowHelper.Shadower();

                    mPShad.mChar    = mPChar;
                    mPShad.mContext = this;

                    mPEntity = new Entity(true, mEBoss);

                    mPMeshLighting = new MeshLighting(mPEntity, mZone, PlayerBoxStanding / 2f, mZoneDraw.GetStyleStrength);

                    mPEntity.AddComponent(mPMeshLighting);
                }
            }

            mPMob    = new Mobile(mPChar, PlayerBoxWidth, PlayerBoxStanding, PlayerEyeStanding, true);
            mPCamMob = new Mobile(mPChar, PlayerBoxWidth, PlayerBoxStanding, PlayerEyeStanding, true);
            mFatBox  = Misc.MakeBox(PlayerBoxWidth + 1, PlayerBoxStanding);

            mKeeper.AddLib(mZoneMats);

            if (mStaticMats != null)
            {
                mKeeper.AddLib(mStaticMats);
            }

            if (mPMats != null)
            {
                mKeeper.AddLib(mPMats);
            }

            //example material groups
            //these treat all materials in the group
            //as a single material for the purposes
            //of drawing cartoony outlines around them
            List <string> skinMats = new List <string>();

            skinMats.Add("Face");
            skinMats.Add("Skin");
            skinMats.Add("EyeWhite");
            skinMats.Add("EyeLiner");
            skinMats.Add("LeftIris");
            skinMats.Add("LeftPupil");
            skinMats.Add("RightIris");
            skinMats.Add("RightPupil");
//			skinMats.Add("Nails");
            mKeeper.AddMaterialGroup("SkinGroup", skinMats);

            if (Directory.Exists(mGameRootDir + "/Levels"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Levels");

                FileInfo[] fi = di.GetFiles("*.Zone", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in fi)
                {
                    mLevels.Add(f.Name.Substring(0, f.Name.Length - 5));
                }
            }

            //if debugger lands here, levels are sort of needed
            //otherwise there's not much point for this test prog
            ChangeLevel(mLevels[mCurLevel]);
            mST.ModifyStringText(mFonts[0], "(L) CurLevel: " + mLevels[mCurLevel], "LevelStatus");
        }
Пример #9
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();
        }
Пример #10
0
        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();
        }
Пример #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());
        }
Пример #12
0
        static AnimForm SetUpForms(Device gd, MatLib matLib, StuffKeeper sk, CommonPrims ep)
        {
            MeshLib.AnimLib animLib = new MeshLib.AnimLib();
            AnimForm        af      = new AnimForm(gd, matLib, animLib);
            StripElements   se      = new StripElements();
            SkeletonEditor  skel    = new SkeletonEditor();

            SharedForms.MaterialForm matForm = new SharedForms.MaterialForm(matLib, sk);
            SharedForms.CelTweakForm celForm = new SharedForms.CelTweakForm(gd, matLib);
            SharedForms.Output       outForm = new SharedForms.Output();

            //save positions
            matForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                      Settings.Default, "MaterialFormPos", true,
                                                                      System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            matForm.DataBindings.Add(new System.Windows.Forms.Binding("Size",
                                                                      Settings.Default, "MaterialFormSize", true,
                                                                      System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            af.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                 Settings.Default, "AnimFormPos", true,
                                                                 System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            skel.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                   Settings.Default, "SkeletonEditorFormPos", true,
                                                                   System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            skel.DataBindings.Add(new System.Windows.Forms.Binding("Size",
                                                                   Settings.Default, "SkeletonEditorFormSize", true,
                                                                   System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            celForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                      Settings.Default, "CelTweakFormPos", true,
                                                                      System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            outForm.DataBindings.Add(new System.Windows.Forms.Binding("Location",
                                                                      Settings.Default, "OutputFormPos", true,
                                                                      System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            outForm.DataBindings.Add(new System.Windows.Forms.Binding("Size",
                                                                      Settings.Default, "OutputFormSize", true,
                                                                      System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            SeamEditor seam = null;

            MakeSeamForm(ref seam);

            af.eMeshChanged        += (sender, args) => matForm.SetMesh(sender);
            af.ePrint              += (sender, args) => outForm.Print(sender as string);
            matForm.eNukedMeshPart += (sender, args) => af.NukeMeshPart(sender as List <int>);
            matForm.eStripElements += (sender, args) =>
            { if (se.Visible)
              {
                  return;
              }
              se.Populate(args as ArchEventArgs); };
            matForm.eGenTangents += (sender, args) =>
            { ArchEventArgs aea = args as ArchEventArgs;
              if (aea != null)
              {
                  aea.mArch.GenTangents(gd, aea.mIndexes, matForm.GetTexCoordSet());
              }
            };
            matForm.eFoundSeams += (sender, args) =>
            { if (seam.IsDisposed)
              {
                  MakeSeamForm(ref seam);
              }
              seam.Initialize(gd);
              seam.AddSeams(sender as List <EditorMesh.WeightSeam>);
              seam.SizeColumns();
              seam.Visible = true; };
            se.eDeleteElement += (sender, args) =>
            { List <int> elements = sender as List <int>;
              af.NukeVertexElement(se.GetIndexes(), elements);
              se.Populate(null);      se.Visible = false;
              matForm.RefreshMeshPartList(); };
            se.eEscape += (sender, args) =>
            { se.Populate(null);      se.Visible = false; };
            af.eSkeletonChanged += (sender, args) => skel.Initialize(sender as MeshLib.Skeleton);
            af.eBoundsChanged   += (sender, args) => ep.ReBuildBoundsDrawData(gd, sender);

            skel.eSelectUnUsedBones += (sender, args) => af.GetBoneNamesInUseByDraw(sender as List <string>);
            skel.eBonesChanged      += (sender, args) => af.BonesChanged();

            af.Visible      = true;
            matForm.Visible = true;
            skel.Visible    = true;
            celForm.Visible = true;
            outForm.Visible = true;

            return(af);
        }
Пример #13
0
        internal BSPBuilder(GraphicsDevice gd, string gameRootDir)
        {
            mGD          = gd;
            mGameRootDir = gameRootDir;

            mGD.eDeviceLost += OnDeviceLost;

            mSKeeper = new StuffKeeper();

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

            LoadStuff();

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

            mMatForm = new SharedForms.MaterialForm(mMatLib, mSKeeper);
            mCTForm  = new SharedForms.CelTweakForm(gd.GD, mMatLib);

            SetFormPos(mBSPForm, "BSPFormPos");
            SetFormPos(mVisForm, "VisFormPos");
            SetFormPos(mZoneForm, "ZoneFormPos");
            SetFormPos(mOutForm, "OutputFormPos");
            SetFormPos(mMatForm, "MaterialFormPos");
            SetFormPos(mCTForm, "CelTweakFormPos");
            SetFormSize(mMatForm, "MaterialFormSize");

            //show forms
            mBSPForm.Visible  = true;
            mVisForm.Visible  = true;
            mZoneForm.Visible = true;
            mOutForm.Visible  = true;
            mMatForm.Visible  = true;
            mCTForm.Visible   = true;

            //form events
            mZoneForm.eMaterialVis         += OnMaterialVis;
            mZoneForm.eSaveZone            += OnSaveZone;
            mZoneForm.eZoneGBSP            += OnZoneGBSP;
            mZoneForm.eLoadDebug           += OnLoadDebug;
            mZoneForm.eDumpTextures        += OnDumpTextures;
            mBSPForm.eBuild                += OnBuild;
            mBSPForm.eLight                += OnLight;
            mBSPForm.eOpenMap              += OnOpenMap;
            mBSPForm.eStaticToMap          += OnOpenStatic;
            mBSPForm.eMapToStatic          += OnMapToStatic;
            mBSPForm.eSave                 += OnSaveGBSP;
            mBSPForm.eFullBuild            += OnFullBuild;
            mBSPForm.eUpdateEntities       += OnUpdateEntities;
            mVisForm.eResumeVis            += OnResumeVis;
            mVisForm.eStopVis              += OnStopVis;
            mVisForm.eVis                  += OnVis;
            mMatForm.eMatLibNotReadyToSave += OnMatLibNotReadyToSave;
            mMatForm.eMatTechniqueChanged  += OnMatTechChanged;

            //core events
            CoreEvents.eBuildDone    += OnBuildDone;
            CoreEvents.eLightDone    += OnLightDone;
            CoreEvents.eGBSPSaveDone += OnGBSPSaveDone;
            CoreEvents.eVisDone      += OnVisDone;
            CoreEvents.ePrint        += OnPrint;

            //stats
            CoreEvents.eNumPortalsChanged  += OnNumPortalsChanged;
            CoreEvents.eNumClustersChanged += OnNumClustersChanged;
            CoreEvents.eNumPlanesChanged   += OnNumPlanesChanged;
            CoreEvents.eNumVertsChanged    += OnNumVertsChanged;

            ProgressWatcher.eProgressUpdated += OnProgress;

            SetUpCommonIgnores();
        }
Пример #14
0
        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();
        }
Пример #15
0
        internal MapStuff(GraphicsDevice gd, string gameRootDir)
        {
            mGD          = gd;
            mGameRootDir = gameRootDir;
            mResX        = gd.RendForm.ClientRectangle.Width;
            mResY        = gd.RendForm.ClientRectangle.Height;

            mSKeeper = new StuffKeeper();

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

            mSKeeper.Init(mGD, gameRootDir);

            mZoneMats = new MatLib(gd, mSKeeper);
            mZone     = new Zone();
            mZoneDraw = new MeshLib.IndoorMesh(gd, mZoneMats);
            mFontMats = new MatLib(gd, mSKeeper);
            mPathDraw = new DrawPathing(gd, mSKeeper);

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

            mFonts = mSKeeper.GetFontList();

            mST       = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);
            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            Vector4 color = Vector4.UnitY + (Vector4.UnitW * 0.15f);

            //string indicators for various statusy things
            mST.AddString(mFonts[0], "Stuffs", "LevelStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 640f, Vector2.One);
            mST.AddString(mFonts[0], "Stuffs", "PosStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 660f, Vector2.One);
            mST.AddString(mFonts[0], "", "PathStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 680f, Vector2.One);

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

            mZoneDraw = new IndoorMesh(gd, mZoneMats);

            mCamMob  = new Mobile(this, 16f, 50f, 45f, true);
            mPathMob = new Mobile(this, 16f, 50f, 45f, false);

            if (Directory.Exists(mGameRootDir + "/Levels"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Levels");

                FileInfo[] fi = di.GetFiles("*.Zone", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in fi)
                {
                    mLevels.Add(f.Name.Substring(0, f.Name.Length - 5));
                }
            }

            //if debugger lands here, levels are sort of needed
            //otherwise there's not much point for this test prog
            ChangeLevel(mLevels[mCurLevel]);
            mST.ModifyStringText(mFonts[0], "(L) CurLevel: " + mLevels[mCurLevel], "LevelStatus");
        }
Пример #16
0
        const float InvertIncrement = 0.01f;            //10ms


        internal Game(GraphicsDevice gd, string gameRootDir)
        {
            mGD          = gd;
            mGameRootDir = gameRootDir;
            mResX        = gd.RendForm.ClientRectangle.Width;
            mResY        = gd.RendForm.ClientRectangle.Height;

            mSKeeper = new StuffKeeper();

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

            mSKeeper.Init(mGD, gameRootDir);

            mFontMats = new MatLib(gd, mSKeeper);
            mCPrims   = new CommonPrims(gd, mSKeeper);

            mFonts = mSKeeper.GetFontList();

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

            mST  = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);
            mSUI = new ScreenUI(gd.GD, mFontMats, 100);

            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            //load avail static stuff
            if (Directory.Exists(mGameRootDir + "/Statics"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Statics");

                FileInfo[] fi = di.GetFiles("*.MatLib", SearchOption.TopDirectoryOnly);

                if (fi.Length > 0)
                {
                    mStaticMats = new MatLib(gd, mSKeeper);
                    mStaticMats.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);

                    mStaticMats.InitCelShading(1);
                    mStaticMats.GenerateCelTexturePreset(gd.GD,
                                                         (gd.GD.FeatureLevel == FeatureLevel.Level_9_3),
                                                         false, 0);
                    mStaticMats.SetCelTexture(0);
                    mKeeper.AddLib(mStaticMats);
                }

                mStatics = Mesh.LoadAllStaticMeshes(mGameRootDir + "\\Statics", gd.GD);

                foreach (KeyValuePair <string, IArch> arch in mStatics)
                {
                    arch.Value.UpdateBounds();
                }

                fi = di.GetFiles("*.StaticInstance", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in fi)
                {
                    string archName = FileUtil.StripExtension(f.Name);
                    if (archName.Contains('_'))
                    {
                        archName = archName.Substring(0, f.Name.IndexOf('_'));
                    }

                    archName += ".Static";

                    if (!mStatics.ContainsKey(archName))
                    {
                        continue;
                    }

                    StaticMesh sm = new StaticMesh(mStatics[archName]);

                    sm.ReadFromFile(f.DirectoryName + "\\" + f.Name);

                    mMeshes.Add(sm);

                    sm.UpdateBounds();
                    sm.SetMatLib(mStaticMats);
                    Vector3 randPos = Mathery.RandomPosition(mRand,
                                                             Vector3.UnitX * 100f +
                                                             Vector3.UnitZ * 100f);
                    mMeshPositions.Add(randPos);
                    mMeshRotations.Add(Vector3.Zero);
                    mMeshScales.Add(Vector3.One);
                    UpdateStaticTransform(mMeshes.Count - 1);
                }
                AddStaticCollision();
            }

            //skip hair stuff when computing bone bounds
            //hits to hair usually wouldn't activate much
            List <string> skipMats = new List <string>();

            skipMats.Add("Hair");

            //load character stuff if any around
            if (Directory.Exists(mGameRootDir + "/Characters"))
            {
                DirectoryInfo di = new DirectoryInfo(mGameRootDir + "/Characters");

                FileInfo[] fi = di.GetFiles("*.AnimLib", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mCharAnims = new AnimLib();
                    mCharAnims.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);

                    List <Anim> anims = mCharAnims.GetAnims();
                    foreach (Anim a in anims)
                    {
                        mAnims.Add(a.Name);
                    }
                }

                fi = di.GetFiles("*.MatLib", SearchOption.TopDirectoryOnly);
                if (fi.Length > 0)
                {
                    mCharMats = new MatLib(mGD, mSKeeper);
                    mCharMats.ReadFromFile(fi[0].DirectoryName + "\\" + fi[0].Name);
                    mCharMats.InitCelShading(1);
                    mCharMats.GenerateCelTexturePreset(gd.GD,
                                                       gd.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
                    mCharMats.SetCelTexture(0);
                    mKeeper.AddLib(mCharMats);
                }

                fi = di.GetFiles("*.Character", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in fi)
                {
                    IArch arch = new CharacterArch();
                    arch.ReadFromFile(f.DirectoryName + "\\" + f.Name, mGD.GD, true);

                    mCharArchs.Add(FileUtil.StripExtension(f.Name), arch);
                }

                fi = di.GetFiles("*.CharacterInstance", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in fi)
                {
                    string archName = f.Name;
                    if (archName.Contains('_'))
                    {
                        archName = f.Name.Substring(0, f.Name.IndexOf('_'));
                    }

                    if (!mCharArchs.ContainsKey(archName))
                    {
                        continue;
                    }

                    Character c = new Character(mCharArchs[archName], mCharAnims);

                    //map this to an arch
                    mCharToArch.Add(c, mCharArchs[archName]);

                    c.ReadFromFile(f.DirectoryName + "\\" + f.Name);

                    c.SetMatLib(mCharMats);

                    c.SetTransform(Matrix.Translation(
                                       Mathery.RandomPosition(mRand,
                                                              Vector3.UnitX * 100f +
                                                              Vector3.UnitZ * 100f)));

                    c.ComputeBoneBounds(skipMats);

                    c.AutoInvert(true, mInvertInterval);

                    mCharacters.Add(c);
                }

                if (mCharacters.Count > 0)
                {
                    mAnimTimes = new float[mCharacters.Count];
                    mCurAnims  = new int[mCharacters.Count];
                    mCBone     = new int[mCharacters.Count];
                    mCBones    = new Dictionary <int, Matrix> [mCharacters.Count];
                }

                foreach (KeyValuePair <string, IArch> arch in mCharArchs)
                {
                    //build draw data for bone bounds
                    (arch.Value as CharacterArch).BuildDebugBoundDrawData(mGD.GD, mCPrims);
                }
            }

            //typical material group for characters
            //or at least it works with the ones
            //I have right now
            //TODO: way to define these in the asset?
            List <string> skinMats = new List <string>();

            skinMats.Add("Face");
            skinMats.Add("Skin");
            skinMats.Add("EyeWhite");
            skinMats.Add("EyeLiner");
            skinMats.Add("IrisLeft");
            skinMats.Add("PupilLeft");
            skinMats.Add("IrisRight");
            skinMats.Add("PupilRight");
            skinMats.Add("Nails");
            mKeeper.AddMaterialGroup("SkinGroup", skinMats);

            mTextColor  = Vector4.UnitY + (Vector4.UnitW * 0.15f);
            mHitColor   = Vector4.One * 0.9f;
            mHitColor.Y = mHitColor.Z = 0f;

            mSUI.AddGump("UI\\CrossHair", "CrossHair", Vector4.One,
                         Vector2.UnitX * ((mResX / 2) - 16)
                         + Vector2.UnitY * ((mResY / 2) - 16),
                         Vector2.One);

            //string indicators for various statusy things
            mST.AddString(mFonts[0], "", "StaticStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 460f, Vector2.One);
            mST.AddString(mFonts[0], "", "InvertStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 480f, Vector2.One);
            mST.AddString(mFonts[0], "", "AnimStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 500f, Vector2.One);
            mST.AddString(mFonts[0], "", "CharStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 520f, Vector2.One);
            mST.AddString(mFonts[0], "", "PosStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 540f, Vector2.One);
            mST.AddString(mFonts[0], "", "HitStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 560f, Vector2.One);
            mST.AddString(mFonts[0], "", "ThreadStatus",
                          mTextColor, Vector2.UnitX * 20f + Vector2.UnitY * 580f, Vector2.One);

            UpdateCAStatus();
            UpdateInvertStatus();
            UpdateStaticStatus();
        }
Пример #17
0
        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();
        }
Пример #18
0
        internal GameLoop(GraphicsDevice gd, StuffKeeper sk, string gameRootDir)
        {
            mGD   = gd;
            mSK   = sk;
            mResX = gd.RendForm.ClientRectangle.Width;
            mResY = gd.RendForm.ClientRectangle.Height;

            mFontMats = new MatLib(gd, sk);

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

            mFonts = sk.GetFontList();

            mST = new ScreenText(gd.GD, mFontMats, mFonts[0], 1000);

            mTextProj = Matrix.OrthoOffCenterLH(0, mResX, mResY, 0, 0.1f, 5f);

            Vector4 color = Vector4.UnitY + (Vector4.UnitW * 0.15f);

            //string indicators for various statusy things
            mST.AddString(mFonts[0], "Stuffs", "PosStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 580f, Vector2.One);
            mST.AddString(mFonts[0], "Thread Status...", "ThreadStatus",
                          color, Vector2.UnitX * 20f + Vector2.UnitY * 560f, Vector2.One);

            mTerMats = new MatLib(mGD, sk);

            Vector3 lightDir = Mathery.RandomDirection(mRand);

            Vector4 lightColor2 = Vector4.One * 0.4f;
            Vector4 lightColor3 = Vector4.One * 0.1f;

            lightColor2.W = lightColor3.W = 1f;

            mTerMats.CreateMaterial("Terrain");
            mTerMats.SetMaterialEffect("Terrain", "Terrain.fx");
            mTerMats.SetMaterialTechnique("Terrain", "TriTerrain");
            mTerMats.SetMaterialParameter("Terrain", "mLightColor0", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mLightColor1", lightColor2);
            mTerMats.SetMaterialParameter("Terrain", "mLightColor2", lightColor3);
            mTerMats.SetMaterialParameter("Terrain", "mLightDirection", lightDir);
            mTerMats.SetMaterialParameter("Terrain", "mSolidColour", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mSpecPower", 1);
            mTerMats.SetMaterialParameter("Terrain", "mSpecColor", Vector4.One);
            mTerMats.SetMaterialParameter("Terrain", "mWorld", Matrix.Identity);

            mTerMats.CreateMaterial("Sky");
            mTerMats.SetMaterialEffect("Sky", "Terrain.fx");
            mTerMats.SetMaterialTechnique("Sky", "SkyGradient");

            mTerMats.InitCelShading(1);
            mTerMats.GenerateCelTexturePreset(mGD.GD, mGD.GD.FeatureLevel == FeatureLevel.Level_9_3, false, 0);
            mTerMats.SetCelTexture(0);

            mSkyCube = PrimFactory.CreateCube(gd.GD, -5f);

            //debug draw
            mDebugMats = new MatLib(gd, sk);

            Vector4 redColor   = Vector4.One;
            Vector4 greenColor = Vector4.One;
            Vector4 blueColor  = Vector4.One;

            redColor.Y = redColor.Z = greenColor.X = greenColor.Z = blueColor.X = blueColor.Y = 0f;

            mDebugMats.CreateMaterial("DebugBoxes");
            mDebugMats.SetMaterialEffect("DebugBoxes", "Static.fx");
            mDebugMats.SetMaterialTechnique("DebugBoxes", "TriSolidSpec");
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor0", Vector4.One);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor1", lightColor2);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mLightColor2", lightColor3);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSolidColour", blueColor);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecPower", 1);
            mDebugMats.SetMaterialParameter("DebugBoxes", "mSpecColor", Vector4.One);
        }