Exemple #1
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time, List <Input.InputAction> actions)
        {
            //Thread.Sleep(30);

            float secDelta = time.GetUpdateDeltaSeconds();

            float msDelta = time.GetUpdateDeltaMilliSeconds();

            mGD.GCam.Update(Vector3.Zero, 0f, 0f, 0f);
        }
Exemple #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            GraphicsDevice gd = new GraphicsDevice("Pathfinding Test Program",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

            PathingForm pathForm = new PathingForm();

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

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

            gd.RendForm.Location = Properties.Settings.Default.MainWindowPos;
            pathForm.Location    = Properties.Settings.Default.PathWindowPos;

            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();

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            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;

            MapStuff mapStuff = new MapStuff(gd, ".");

            EventHandler pickedAHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { Vector3EventArgs v3ea = ea as Vector3EventArgs;
                  pathForm.SetCoordA(v3ea.mVector);
                  pathForm.SetNodeA((int)s); });
            EventHandler pickedBHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { Vector3EventArgs v3ea = ea as Vector3EventArgs;
                  pathForm.SetCoordB(v3ea.mVector);
                  pathForm.SetNodeB((int)s); });
            EventHandler pickReadyHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { pathForm.SetPickReady((bool)s); });

            mapStuff.ePickedA   += pickedAHandler;
            mapStuff.ePickedB   += pickedBHandler;
            mapStuff.ePickReady += pickReadyHandler;

            EventHandler genHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.GeneratePathing(pathForm.GetGridSize(), (float)s); });
            EventHandler loadHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.LoadPathing(s as string); });
            EventHandler saveHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.SavePathing(s as string); });
            EventHandler pickAHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.PickA();
                  gd.RendForm.Focus(); });
            EventHandler pickBHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.PickB();
                  gd.RendForm.Focus(); });
            EventHandler pickBlockedHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.PickBlocked();
                  gd.RendForm.Focus(); });
            EventHandler pickUnBlockedHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.PickUnBlocked();
                  gd.RendForm.Focus(); });
            EventHandler drawChangedHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { mapStuff.DrawSettings((int)s); });
            EventHandler mobChangedHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { UInt32 box = (UInt32)s;
                  mapStuff.AlterPathMobile((int)box & 0xFF, (int)box >> 16); });
            EventHandler findPathHandler = new EventHandler(
                delegate(object s, EventArgs ea)
                { Vector3PairEventArgs v3pea = ea as Vector3PairEventArgs;
                  mapStuff.FindPath(v3pea.mVecA, v3pea.mVecB); });

            pathForm.eGenerate    += genHandler;
            pathForm.eLoadData    += loadHandler;
            pathForm.eSaveData    += saveHandler;
            pathForm.ePickA       += pickAHandler;
            pathForm.ePickB       += pickBHandler;
            pathForm.ePickBlock   += pickBlockedHandler;
            pathForm.ePickUnBlock += pickUnBlockedHandler;
            pathForm.eDrawChanged += drawChangedHandler;
            pathForm.eMobChanged  += mobChangedHandler;
            pathForm.eFindPath    += findPathHandler;

            pathForm.SetPickReady(false);

            pathForm.Show();

            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);
                }
                else if (mapStuff.Busy())
                {
                    Thread.Sleep(5);
                    return;
                }

                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);
                    }
                    mapStuff.Update(time, acts, pSteering);
                    time.UpdateDone();
                }

                mapStuff.RenderUpdate(time.GetRenderUpdateDeltaMilliSeconds());

                mapStuff.Render();

                gd.Present();

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

            Properties.Settings.Default.Save();

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

            mapStuff.ePickedA   -= pickedAHandler;
            mapStuff.ePickedB   -= pickedBHandler;
            mapStuff.ePickReady -= pickReadyHandler;

            pathForm.eGenerate    -= genHandler;
            pathForm.eLoadData    -= loadHandler;
            pathForm.eSaveData    -= saveHandler;
            pathForm.ePickA       -= pickAHandler;
            pathForm.ePickB       -= pickBHandler;
            pathForm.ePickBlock   -= pickBlockedHandler;
            pathForm.ePickUnBlock -= pickUnBlockedHandler;
            pathForm.eDrawChanged -= drawChangedHandler;
            pathForm.eMobChanged  -= mobChangedHandler;
            pathForm.eFindPath    -= findPathHandler;

            mapStuff.FreeAll();
            inp.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
Exemple #3
0
        static void Main()
        {
            //turn this on for help with leaky stuff
            Configuration.EnableObjectTracking = true;

            GraphicsDevice gd = new GraphicsDevice("Depth of Mind",
                                                   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));

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

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

            gd.CheckResize();

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

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

            //hold right click to turn, or turn anytime mouse moves?
            bool bRightClickToTurn = false;

            MapLoop mapLoop = new MapLoop(gd, rootDir);

            PlayerSteering pSteering = SetUpSteering();
            Input          inp       = SetUpInput(bRightClickToTurn);
            Random         rand      = new Random();
            UserSettings   sets      = new UserSettings();

            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();
                if (!bRightClickToTurn)
                {
                    bMouseLookOn = true;
                    gd.SetCapture(true);
                }
            });

            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, sets, gd, bRightClickToTurn,
                                       time.GetUpdateDeltaSeconds(), ref bMouseLookOn);
                    if (!gd.RendForm.Focused)
                    {
                        acts.Clear();
                        bMouseLookOn = false;
                        gd.SetCapture(false);
                    }
                    mapLoop.Update(time, acts, pSteering);
                    time.UpdateDone();
                }

                mapLoop.RenderUpdate(time.GetRenderUpdateDeltaMilliSeconds());

                mapLoop.Render();

                gd.Present();

                acts.Clear();
            });

            Settings.Default.Save();
            sets.SaveSettings();

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

            mapLoop.FreeAll();
            inp.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
Exemple #4
0
        internal void Update(UpdateTimer time, List <Input.InputAction> actions)
        {
            mFrameCheck++;

            Vector3 startPos = mGD.GCam.Position;
            Vector3 endPos   = startPos + mGD.GCam.Forward * -2000f;

            float deltaMS  = time.GetUpdateDeltaMilliSeconds();
            float deltaSec = time.GetUpdateDeltaSeconds();

            //animate characters
            for (int i = 0; i < mCharacters.Count; i++)
            {
                Character c = mCharacters[i];

                c.Update(deltaSec);

                float totTime = mCharAnims.GetAnimTime(mAnims[mCurAnims[i]]);
                float strTime = mCharAnims.GetAnimStartTime(mAnims[mCurAnims[i]]);
                float endTime = totTime + strTime;

                mAnimTimes[i] += deltaSec;
                if (mAnimTimes[i] > endTime)
                {
                    mAnimTimes[i] = strTime + (mAnimTimes[i] - endTime);
                }

                c.Animate(mAnims[mCurAnims[i]], mAnimTimes[i]);

                mCBones[i] = (mCharToArch[c] as CharacterArch).GetBoneTransforms(mCharAnims.GetSkeleton());
            }

            //check for keys
            foreach (Input.InputAction act in actions)
            {
                if (act.mAction.Equals(Program.MyActions.NextCharacter))
                {
                    mCurChar++;
                    if (mCurChar >= mCharacters.Count)
                    {
                        mCurChar = 0;
                    }
                    UpdateCAStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.NextStatic))
                {
                    mCurStatic++;
                    if (mCurStatic >= mMeshes.Count)
                    {
                        mCurStatic = 0;
                    }
                    UpdateStaticStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.NextAnim))
                {
                    if (mCharacters.Count > 0)
                    {
                        mCurAnims[mCurChar]++;
                        if (mCurAnims[mCurChar] >= mAnims.Count)
                        {
                            mCurAnims[mCurChar] = 0;
                        }
                        UpdateCAStatus();
                    }
                }
                else if (act.mAction.Equals(Program.MyActions.IncreaseInvertInterval))
                {
                    mInvertInterval += InvertIncrement;
                    foreach (Character c in mCharacters)
                    {
                        c.AutoInvert(true, mInvertInterval);
                    }
                    UpdateInvertStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.DecreaseInvertInterval))
                {
                    mInvertInterval -= InvertIncrement;
                    if (mInvertInterval < InvertIncrement)
                    {
                        mInvertInterval = InvertIncrement;
                    }
                    foreach (Character c in mCharacters)
                    {
                        c.AutoInvert(true, mInvertInterval);
                    }
                    UpdateInvertStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.RandRotateStatic))
                {
                    if (mMeshes.Count > 0)
                    {
                        //make a random rotation
                        mMeshRotations[mCurStatic] = new Vector3(
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi),
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi),
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi));
                        UpdateStaticTransform(mCurStatic);
                    }
                }
                else if (act.mAction.Equals(Program.MyActions.RandScaleStatic))
                {
                    if (mMeshes.Count > 0)
                    {
                        //make a random scale
                        mMeshScales[mCurStatic] = new Vector3(
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f),
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f),
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f));
                        UpdateStaticTransform(mCurStatic);
                    }
                }
            }

            mPartHit = null;
            mMeshHit = null;

            float bestDist = float.MaxValue;

            for (int i = 0; i < mMeshes.Count; i++)
            {
                StaticMesh sm = mMeshes[i];

                float?bHit = sm.RayIntersect(startPos, endPos, true);
                if (bHit != null)
                {
                    Mesh partHit = null;

                    bHit = sm.RayIntersect(startPos, endPos, true, out partHit);
                    if (bHit != null)
                    {
                        if (bHit.Value < bestDist)
                        {
                            bestDist = bHit.Value;
                            mPartHit = partHit;
                            mMeshHit = sm;
                        }
                    }
                }
            }

            if (mStaticMats != null)
            {
                mStaticMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }
            if (mCharMats != null)
            {
                mCharMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }

            mCPrims.Update(mGD.GCam, Vector3.Down);

            for (int i = 0; i < mCharacters.Count; i++)
            {
                Character c    = mCharacters[i];
                float?    bHit = c.RayIntersect(startPos, endPos);
                if (bHit != null)
                {
                    c.RayIntersectBones(startPos, endPos, false, out mCBone[i]);
                }
                else
                {
                    mCBone[i] = 0;
                }
            }

            if (mFrameCheck == 10)
            {
                mFrameCheck = 0;
                UpdateThreadStatus();
            }

            UpdatePosStatus();
            UpdateHitStatus();

            //this has to behind any text changes
            //otherwise the offsets will be messed up
            mST.Update(mGD.DC);
            mSUI.Update(mGD.DC);
        }
Exemple #5
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time, List <Input.InputAction> actions, PlayerSteering ps)
        {
            //Thread.Sleep(30);

            float secDelta = time.GetUpdateDeltaSeconds();

//			mZone.UpdateModels(secDelta);

            float yawAmount   = 0f;
            float pitchAmount = 0f;
            bool  bGravity    = false;
            float friction    = GroundFriction;

            if (!mbOnGround)
            {
                //gravity
                if (!mbFly)
                {
                    bGravity = true;
                }

                if (mbBadFooting)
                {
                    friction = GroundFriction;
                }
                else
                {
                    friction = AirFriction;
                }
            }
            else
            {
                if (!mbFly)
                {
                    friction = GroundFriction;
                }
                else
                {
                    friction = AirFriction;
                }
            }

            bool bCamJumped = false;

            foreach (Input.InputAction act in actions)
            {
                if (act.mAction.Equals(Program.MyActions.Jump))
                {
                    if (mbOnGround && !mbFly)
                    {
                        friction   = AirFriction;
                        bCamJumped = true;
                    }
                }
                else if (act.mAction.Equals(Program.MyActions.ToggleFly))
                {
                    mbFly     = !mbFly;
                    ps.Method = (mbFly)? PlayerSteering.SteeringMethod.Fly : PlayerSteering.SteeringMethod.FirstPerson;
                }
                else if (act.mAction.Equals(Program.MyActions.Turn))
                {
                    yawAmount = act.mMultiplier;
                }
                else if (act.mAction.Equals(Program.MyActions.Pitch))
                {
                    pitchAmount = act.mMultiplier;
                }
                else if (act.mAction.Equals(Program.MyActions.RayStart))
                {
                    mRayStart = GetModelPos();
                }
                else if (act.mAction.Equals(Program.MyActions.RayEnd))
                {
                    mRayEnd  = GetModelPos();
                    mbRayHit = mTModel.Trace(mRayStart, mRayEnd, out mRayHit);

                    mColRays.Add(mRayStart);
                    mColRays.Add(mRayEnd);

                    if (mbRayHit)
                    {
                        //scale up to view space
                        Vector3 viewHit = mRayHit;

                        viewHit.X *= 16f;
                        viewHit.Z *= 16f;

                        mColHits.Add(viewHit);
                    }

                    mDrawRays.BuildRayDrawInfo(mColRays, mColHits, 16f);
                }
                else if (act.mAction.Equals(Program.MyActions.RayCrazy))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    mColRays.Clear();
                    mColHits.Clear();

                    Vector3 randSpace = Vector3.One * 1000f;
                    randSpace.Y *= 5f;

                    for (int i = 0; i < 1000; i++)
                    {
                        Vector3 start = Mathery.RandomPosition(mRand, randSpace);
                        Vector3 end   = Mathery.RandomPosition(mRand, randSpace);

                        //wrap xz
                        if (start.X < 0)
                        {
                            start.X += 1000f;
                        }
                        if (start.Z < 0)
                        {
                            start.Z += 1000f;
                        }
                        if (end.X < 0)
                        {
                            end.X += 1000f;
                        }
                        if (end.Z < 0)
                        {
                            end.Z += 1000f;
                        }

                        Vector3 hit;
                        if (mTModel.Trace(start, end, out hit))
                        {
                            //scale up to view space
                            Vector3 viewHit = hit;

                            viewHit.X *= 16f;
                            viewHit.Z *= 16f;

                            mColHits.Add(viewHit);
                        }

                        mColRays.Add(start);
                        mColRays.Add(end);
                    }

                    sw.Stop();

                    mDrawRays.BuildRayDrawInfo(mColRays, mColHits, 16f);
                }
            }

//			UpdateDynamicLights(actions);

            Vector3 startPos = mGroundPos;
            Vector3 moveVec  = ps.Update(startPos, mGD.GCam.Forward, mGD.GCam.Left, mGD.GCam.Up, actions);

            if (mbOnGround || mbFly)
            {
                moveVec *= JogMoveForce;
            }
            else if (mbBadFooting)
            {
                moveVec *= StumbleForce;
            }
            else
            {
                moveVec *= MidAirMoveForce;
            }

            mVelocity += moveVec * 0.5f;
            mVelocity -= (friction * mVelocity * secDelta * 0.5f);

            Vector3 pos = startPos;

            if (bGravity)
            {
                mVelocity += Vector3.Down * GravityForce * (secDelta * 0.5f);
            }
            if (bCamJumped)
            {
                mVelocity += Vector3.Up * JumpForce * 0.5f;

                pos += mVelocity * (1f / 60f);
            }
            else
            {
                pos += mVelocity * secDelta;
            }

            mVelocity += moveVec * 0.5f;
            mVelocity -= (friction * mVelocity * secDelta * 0.5f);
            if (bGravity)
            {
                mVelocity += Vector3.Down * GravityForce * (secDelta * 0.5f);
            }
            if (bCamJumped)
            {
                mVelocity += Vector3.Up * JumpForce * 0.5f;
            }


            Vector3 camPos = Vector3.Zero;
            Vector3 endPos = pos;

//			Move(endPos, time.GetUpdateDeltaMilliSeconds(), false,
//				mbFly, !bCamJumped, true, true, out endPos, out camPos);

            mGroundPos += moveVec;

            bool bWrapped = WrapPosition(ref mGroundPos);

            WrapGridCoordinates();

            if (bWrapped && mTerrain != null)
            {
                mTerrain.BuildGrid(mGD, mChunkRange, mNumStreamThreads);
            }

            if (mTerrain != null)
            {
                mTerrain.SetCellCoord(mGridCoordinate);
                mTerrain.UpdatePosition(mGroundPos, mTerMats);
            }

            mGD.GCam.Update(-mGroundPos, ps.Pitch, ps.Yaw, ps.Roll);
            mOtherCam.Update(-GetViewPos(), ps.Pitch, ps.Yaw, ps.Roll);

            if (!mbFly)
            {
                if (mbOnGround)
                {
                    //kill downward velocity so previous
                    //falling momentum doesn't contribute to
                    //a new jump
                    if (mVelocity.Y < 0f)
                    {
                        mVelocity.Y = 0f;
                    }
                }
                if (mbBadFooting)
                {
                    //reduce downward velocity to avoid
                    //getting stuck in V shaped floors
                    if (mVelocity.Y < 0f)
                    {
                        mVelocity.Y -= (StumbleFriction * mVelocity.Y * secDelta);
                    }
                }
            }

            //get ground pos at current location
            float groundHeight = mTModel.GetHeight(GetModelPos());

            mAudio.Update(mGD.GCam);

            mST.ModifyStringText(mFonts[0], "Grid: " + mGridCoordinate.ToString()
                                 + ", LocalPos: " + mGroundPos.IntStr()
                                 + ", ModelPos: " + GetModelPos(), "PosStatus");

            mST.ModifyStringText(mFonts[0], "Height: " + groundHeight
                                 + ", Hit: " + mbRayHit + ", HitPos: " + mRayHit, "ColStatus");

            if (mTerrain != null)
            {
                mST.ModifyStringText(mFonts[0], "Threads Active: " + mTerrain.GetThreadsActive()
                                     + ", Thread Counter: " + mTerrain.GetThreadCounter(), "ThreadStatus");
            }

            mST.Update(mGD.DC);
        }
Exemple #6
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();
        }
Exemple #7
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time, List <Input.InputAction> actions, PlayerSteering ps)
        {
            //Thread.Sleep(30);

            float secDelta = time.GetUpdateDeltaSeconds();

            mZone.ClearPushableVelocities(secDelta);

            //update model movers
            foreach (Component c in mBModelMovers)
            {
                c.Update(time);
            }

            Vector3 pos         = Vector3.Zero;
            bool    bGroundMove = false;

            UInt32 contents = mPCamMob.GetWorldContents();

            if (mbFly)
            {
                pos = UpdateFly(secDelta, actions, ps);
            }
            else if (Misc.bFlagSet(contents, (UInt32)GameContents.Lava) ||
                     Misc.bFlagSet(contents, (UInt32)GameContents.Water) ||
                     Misc.bFlagSet(contents, (UInt32)GameContents.Slime))
            {
                pos = UpdateSwimming(secDelta, actions, ps);
            }
            else
            {
                pos = UpdateGround(secDelta, actions, ps, out bGroundMove);

                //flip ground move as it returns as a jump bool
                bGroundMove = !bGroundMove;
            }

            UpdateMiscKeys(actions, ps);
            UpdateDynamicLights(actions);

            Vector3 camPos  = Vector3.Zero;
            Vector3 endPos  = pos;
            float   msDelta = time.GetUpdateDeltaMilliSeconds();

            mPCamMob.Move(endPos, msDelta, false, mbFly,
                          bGroundMove, true, out endPos, out camPos);

            //check resulting move against triggers / pickups
            if (!mbFly)
            {
                foreach (Trigger t in mTriggers)
                {
                    t.BoxTriggerCheck(mPCamMob, mPCamMob.GetBounds(),
                                      pos, endPos, msDelta);
                }
                foreach (ConvexVolume cv in mPickUpCVs)
                {
                    if (!cv.Active)
                    {
                        continue;
                    }
                    if (cv.SphereMotionIntersects(PlayerBoxWidth, pos, endPos))
                    {
                        PickUpThing(cv);
                        cv.StateChange(ConvexVolume.State.Active, 0);
                    }
                }
            }


            //check a slightly expanded box to see if any interactives are being touched
            mModelsHit.Clear();
            if (!mbFly)
            {
                if (mZone.TraceStaticBoxVsModels(mFatBox, endPos, mModelsHit))
                {
                    //do stuff
                    foreach (int model in mModelsHit)
                    {
                        foreach (BModelMover bmm in mBModelMovers)
                        {
                            if (bmm.GetModelIndex() == model)
                            {
                                bmm.StateChange(BModelMover.States.Forward, 1);
                                bmm.StateChange(BModelMover.States.Moving, 1);
                            }
                        }
                    }
                }
            }

            mGD.GCam.Update(camPos, ps.Pitch, ps.Yaw, ps.Roll);

            if (!mbFly)
            {
                if (mPCamMob.IsOnGround())
                {
                    //kill downward velocity so previous
                    //falling momentum doesn't contribute to
                    //a new jump
                    if (mCamVelocity.Y < 0f)
                    {
                        mCamVelocity.Y = 0f;
                    }
                }
                if (mPCamMob.IsBadFooting())
                {
                    //reduce downward velocity to avoid
                    //getting stuck in V shaped floors
                    if (mCamVelocity.Y < 0f)
                    {
                        mCamVelocity.Y -= (StumbleFriction * mCamVelocity.Y * secDelta);
                    }
                }
            }

            //update pickup entities
            foreach (PickUp pu in mPickUps)
            {
                pu.Update(time);

                StaticMeshComp smc = pu.GetSMC();
                if (smc == null)
                {
                    continue;
                }
                StaticMesh sm = smc.mDrawObject as StaticMesh;
                if (sm == null)
                {
                    continue;
                }

                float yaw = pu.GetYaw();

                Matrix mat = smc.mPO.GetMatrix();

                if (pu.mSpinningPart == -1)
                {
                    smc.mPO.SetYaw(yaw);
                    sm.SetTransform(mat);
                }
                else
                {
                    sm.SetTransform(mat);

                    sm.SetPartTransform(pu.mSpinningPart,
                                        Matrix.RotationY(yaw) * mat);
                }
            }

            mPB.Update(mGD.DC, time.GetUpdateDeltaMilliSeconds());

            mAudio.Update(mGD.GCam);

            mST.ModifyStringText(mFonts[0], "ModelOn: " + mPCamMob.GetModelOn() + " : "
                                 + (int)mGD.GCam.Position.X + ", "
                                 + (int)mGD.GCam.Position.Y + ", "
                                 + (int)mGD.GCam.Position.Z + " (F)lyMode: " + mbFly
                                 + (mPCamMob.IsBadFooting()? " BadFooting!" : "")
                                 + " ModelsHit: " + mModelsHit.Count, "PosStatus");

            mST.Update(mGD.DC);
        }
Exemple #8
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();
        }
Exemple #9
0
        static void Main()
        {
            GraphicsDevice gd = new GraphicsDevice("Test Meshes",
                                                   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;

            //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 = ".";

            Game theGame = new Game(gd, rootDir);

            PlayerSteering pSteering    = SetUpSteering();
            Input          inp          = SetUpInput();
            Random         rand         = new Random();
            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;
            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 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);

                    theGame.Update(time, acts);

                    time.UpdateDone();
                }
                theGame.Render(gd.DC);

                gd.Present();

                acts.Clear();
            }, true);

            Settings.Default.Save();

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

            theGame.FreeAll();

            inp.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }
Exemple #10
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();
        }
Exemple #11
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();
        }
Exemple #12
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time,
                             List <Input.InputAction> actions, PlayerSteering ps)
        {
            //Thread.Sleep(30);

            mZone.ClearPushableVelocities(time.GetUpdateDeltaSeconds());

            Vector3 impactPos = Vector3.Zero;

            if (mbPicking)
            {
                System.Drawing.Point cPos = System.Windows.Forms.Cursor.Position;

                cPos = mGD.RendForm.PointToClient(cPos);

                Vector2 cursVec = Vector2.UnitX * cPos.X;
                cursVec += Vector2.UnitY * cPos.Y;

                int modelOn;
                impactPos = mZone.TraceScreenPointRay(mGD.GCam, mGD.GetScreenViewPort(),
                                                      cursVec, 1000f, out modelOn);

                var clicked = (from act in actions where act.mAction.Equals(Program.MyActions.MouseSelect)
                               select act).FirstOrDefault();
                if (clicked != null)
                {
                    int        node, numCons;
                    List <int> conTo = new List <int>();
                    bool       bInfo = mGraph.GetInfoAboutLocation(impactPos,
                                                                   mZone.FindWorldNodeLandedIn, out numCons, out node, conTo);

                    if (bInfo)
                    {
                        switch (mPickTarget)
                        {
                        case    PickTarget.A:
                            Misc.SafeInvoke(ePickedA, node, new Vector3EventArgs(impactPos));
                            break;

                        case    PickTarget.B:
                            Misc.SafeInvoke(ePickedB, node, new Vector3EventArgs(impactPos));
                            break;

                        case    PickTarget.Blocked:
                            mGraph.SetPathConnectionPassable(impactPos, mZone.FindWorldNodeLandedIn, false);
                            mPathDraw.BuildDrawInfo(mGraph);
                            break;

                        case    PickTarget.UnBlocked:
                            mGraph.SetPathConnectionPassable(impactPos, mZone.FindWorldNodeLandedIn, true);
                            mPathDraw.BuildDrawInfo(mGraph);
                            break;
                        }
                        mbPicking = false;
                        mST.ModifyStringText(mFonts[0], "Picked point: "
                                             + impactPos.IntStr(), "PathStatus");
                    }
                }
                else
                {
                    if (mbPicking)
                    {
                        mST.ModifyStringText(mFonts[0], "Picking point: "
                                             + impactPos.IntStr(), "PathStatus");
                    }
                }
            }

            float yawAmount   = 0f;
            float pitchAmount = 0f;

            foreach (Input.InputAction act in actions)
            {
                if (act.mAction.Equals(Program.MyActions.NextLevel))
                {
                    mCurLevel++;
                    if (mCurLevel >= mLevels.Count)
                    {
                        mCurLevel = 0;
                    }
                    ChangeLevel(mLevels[mCurLevel]);
                    mST.ModifyStringText(mFonts[0], "(L) CurLevel: " + mLevels[mCurLevel], "LevelStatus");
                }
                else if (act.mAction.Equals(Program.MyActions.Turn))
                {
                    yawAmount = act.mMultiplier;
                }
                else if (act.mAction.Equals(Program.MyActions.Pitch))
                {
                    pitchAmount = act.mMultiplier;
                }
            }

            Vector3 startPos = mCamMob.GetGroundPos();
            Vector3 moveVec  = ps.Update(startPos, mGD.GCam.Forward, mGD.GCam.Left, mGD.GCam.Up, actions);

            moveVec *= FlySpeed;

            Vector3 camPos = Vector3.Zero;
            Vector3 endPos = mCamMob.GetGroundPos() + moveVec * 100f;

            mCamMob.Move(endPos, time.GetUpdateDeltaMilliSeconds(),
                         false, mbFly, true, true, out endPos, out camPos);

            mGD.GCam.Update(camPos, ps.Pitch, ps.Yaw, ps.Roll);

            mST.ModifyStringText(mFonts[0], "Position: " + " : "
                                 + mGD.GCam.Position.IntStr(), "PosStatus");

            if (mGraph != null)
            {
                mGraph.Update();
            }
            mST.Update(mGD.DC);
        }
Exemple #13
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());
        }
Exemple #14
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

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

            GraphicsDevice gd = new GraphicsDevice("BSP tree building tools",
                                                   FeatureLevel.Level_11_0, 0.1f, 3000f);

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

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

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

            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;

            BSPBuilder bspBuild = new BSPBuilder(gd, ".");

            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);
                }
                else if (bspBuild.Busy())
                {
                    Thread.Sleep(5);
                    return;
                }

                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 moveDelta = pSteering.Update(pos, gd.GCam.Forward,
                                                         gd.GCam.Left, gd.GCam.Up, acts);

                    //scale up movement a bit
                    moveDelta *= 200f;

                    pos -= moveDelta;

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

                    time.UpdateDone();
                }

                bspBuild.Update(time.GetRenderUpdateDeltaMilliSeconds(), gd);
                bspBuild.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;

            bspBuild.FreeAll();
            inp.FreeAll();

            //Release all resources
            gd.ReleaseAll();
        }