Example #1
0
    /// <summary>
    /// Per frame update.
    /// </summary>
    public void Update(CInputState InputState)
    {
        if (!_started)
        {
            return;
        }

        float timeNow = Time.realtimeSinceStartup;

        _primaryLoopDuration = timeNow - _lastUpdateTime;
        _lastUpdateTime      = timeNow;

        if (_world.mMap.GetFloorAlwaysVisible() != CGame.VarNoFow.mValue)
        {
            _world.mMap.SetFloorAlwaysVisible(CGame.VarNoFow.mValue);
        }

        CGame.CameraManager.mCanZoom = !InputState.mOverUI;

        // Intersect mouse with floor
        Ray     r = CGame.PrimaryResources.PrimaryCamera.ScreenPointToRay(InputState.mMousePosition);
        Plane   p = new Plane(Vector3.up, 0.0f);
        float   t;
        bool    hit           = p.Raycast(r, out t);
        Vector3 mouseFloorPos = r.direction * t + r.origin;

        if (!_crashed)
        {
            if (!_userWorldView.Update(mouseFloorPos.ToWorldVec2()))
            {
                _crashed = true;
                CGame.UIManager.ShowErrorMessage(_world.mCrashMessage, "Simulation Thread Exception");
            }
        }

        _userSession.Update(InputState);

        // TODO: For debug purposes, maybe put this in a more sane place so we don't stall the whole world.
        lock (_world)
        {
            _world.DrawDebug(InputState);

            if (CGame.VarShowDDATest.mValue)
            {
                DDATest(InputState);
            }

            if (CGame.VarShowArcTest.mValue)
            {
                TrajectoryTest(InputState);
            }

            if (CGame.VarShowProxies.mValue > 0)
            {
                int playerId = CGame.VarShowProxies.mValue - 1;

                for (int iX = 0; iX < 100; ++iX)
                {
                    for (int iY = 0; iY < 100; ++iY)
                    {
                        if (_world.mMap.IsTileVisible(playerId, iX, iY))
                        {
                            CDebug.DrawYRectQuad(new Vector3(iX + 0.5f, 0.0f, iY + 0.5f), 0.9f, 0.9f, new Color(1, 0, 0, 0.5f), false);
                        }
                    }
                }

                for (int i = 0; i < _world.mItemProxies[playerId].Count; ++i)
                {
                    CDebug.DrawBounds(_world.mItemProxies[playerId][i].mBounds, new Color(0, 1, 0, 1), false);
                }
            }
        }

        if (CGame.VarShowFlowField.mValue)
        {
            if (Input.GetMouseButtonDown(1))
            {
                _userWorldView.GenerateFlowField(new Rect(mouseFloorPos.x * 2, mouseFloorPos.z * 2, 2, 2));
            }
        }
    }