/// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "NamelessRogue.log4net.config";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                XmlConfigurator.Configure(LogManager.CreateRepository("NamelessRogue"), stream);
            }

            Log = LogManager.GetLogger(typeof(NamelessGame));

            Log.Info("Application started");


            SaveManager.Init();

            CurrentGame = new GameInstance();
            DebugDevice = this.GraphicsDevice;
            //TODO: move to config later
            int width  = 40;
            int height = 30;


            var commanderEntity = new Entity();

            Commander = new Commander();
            commanderEntity.AddComponent(Commander);

            settings = new GameSettings(width, height);
            graphics.PreferredBackBufferWidth  = (int)(GetActualCharacterWidth() + settings.HudWidth());
            graphics.PreferredBackBufferHeight = GetActualCharacterHeight();

            graphics.IsFullScreen                   = false;
            graphics.PreferMultiSampling            = false;
            graphics.SynchronizeWithVerticalRetrace = true;

            MyraEnvironment.Game = this;

            RenderTarget = new RenderTarget2D(
                GraphicsDevice,
                GraphicsDevice.PresentationParameters.BackBufferWidth,
                GraphicsDevice.PresentationParameters.BackBufferHeight,
                false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24, 4, RenderTargetUsage.PlatformContents);


            graphics.ApplyChanges();

            //12345 123
            worldSettings = new WorldSettings(4, WorldGenConstants.Resolution, WorldGenConstants.Resolution);

            TerrainFurnitureFactory.CreateFurnitureEntities(this);

            ContextFactory.InitAllContexts(this);



            var viewportEntity = RenderFactory.CreateViewport(settings);

            CameraEntity = viewportEntity;

            TimelineEntity = TimelineFactory.CreateTimeline(this);


            var libraries   = new Entity();
            var ammoLibrary = new AmmoLibrary();

            ammoLibrary.AmmoTypes.Add(new AmmoType()
            {
                Name = "Revolver ammo"
            });
            libraries.AddComponent(ammoLibrary);

            var timelinEntity = TimelineEntity;
            var timeline      = timelinEntity.GetComponentOfType <TimeLine>();

            WorldTile firsTile = null;

            foreach (var worldBoardWorldTile in timeline.CurrentTimelineLayer.WorldTiles)
            {
                if (worldBoardWorldTile.Settlement != null)
                {
                    firsTile = worldBoardWorldTile;
                    break;
                }
            }
            int x, y;

            if (firsTile != null)
            {
                //place everything at the center of newly generated settlement;
                x = firsTile.Settlement.Concrete.Center.X;
                y = firsTile.Settlement.Concrete.Center.Y;
            }
            else
            {
                x = WorldGenConstants.Resolution / 2;
                y = WorldGenConstants.Resolution / 2;
            }
            var player = CharacterFactory.CreateSimplePlayerCharacter(x, y, this);

            PlayerEntity = player;

            FollowedByCameraEntity = player;

            ChunkManagementSystem chunkManagementSystem = new ChunkManagementSystem();

            //initialize reality bubble
            chunkManagementSystem.Update(0, this);
            //for (int i = 1; i < 10; i++)
            //{
            //    for (int j = 1; j < 10; j++)
            //    {
            //        Entities.Add(CharacterFactory.CreateBlankNpc(x - i,
            //            y - j));
            //    }
            //}

            CharacterFactory.CreateBlankNpc(x - 6,
                                            y, this);
            //Entities.Add(CharacterFactory.CreateBlankNpc(x - 3,
            //    y));
            //Entities.Add(CharacterFactory.CreateBlankNpc(x - 5,
            //    y));
            //Entities.Add(CharacterFactory.CreateBlankNpc(x - 7,
            //    y));


            for (int i = 0; i < 2; i++)
            {
                var sword = ItemFactory.CreateSword(x - 2,
                                                    y, i, this);;
            }

            var platemail = ItemFactory.CreatePlateMail(x - 2, y, 1, this);

            var pants = ItemFactory.CreatePants(x - 2, y, 1, this);

            var boots = ItemFactory.CreateBoots(x - 2, y, 1, this);

            var cape = ItemFactory.CreateCape(x - 2, y, 1, this);

            var ring = ItemFactory.CreateRing(x - 2, y, 1, this);

            var shield = ItemFactory.CreateShield(x - 2, y, 1, this);

            var helmet = ItemFactory.CreateHelmet(x - 2, y, 1, this);


            var ammo1 = ItemFactory.CreateLightAmmo(x - 1, y, 1, 20, this, ammoLibrary);


            var ammo2 = ItemFactory.CreateLightAmmo(x - 1, y + 1, 1, 20, this, ammoLibrary);


            var revolver = ItemFactory.CreateRevolver(x + 2, y + 1, 1, this, ammoLibrary);


            var pArmor = ItemFactory.CreatePowerArmor(x - 2, y, 1, this);


            Point worldRiverPosition = new Point();
            bool  anyRivers          = false;

            foreach (var worldBoardWorldTile in timeline.CurrentTimelineLayer.WorldTiles)
            {
                var pos     = worldBoardWorldTile.WorldBoardPosiiton;
                var isWater = timeline.CurrentTimelineLayer.InlandWaterConnectivity[pos.X][pos.Y].isWater;
                if (isWater)
                {
                    anyRivers          = true;
                    worldRiverPosition = pos;
                    break;
                }
            }

            if (anyRivers)
            {
                //move player to some river
                PlayerEntity.GetComponentOfType <Position>().Point = new Point(worldRiverPosition.X * Constants.ChunkSize, worldRiverPosition.Y * Constants.ChunkSize);
                chunkManagementSystem.Update(0, this);
            }

            CursorEntity = GameInitializer.CreateCursor();


            //Paragraph.BaseSize = 1.175f;
            //UserInterface.Initialize(Content, "custom");
            //UserInterface.Active.UseRenderTarget = true;
            CurrentContext = ContextFactory.GetMainMenuContext(this);
            CurrentContext.ContextScreen.Show();
            this.IsMouseVisible = true;
            // UserInterface.Active.ShowCursor = false;
            spriteBatch = new SpriteBatch(GraphicsDevice);


            fpsLabel = new Label();
            fpsLabel.HorizontalAlignment = HorizontalAlignment.Right;
            ContextFactory.GetIngameContext(this).ContextScreen.Panel.Widgets.Add(fpsLabel);

            var stackPanel = new VerticalStackPanel();

            stackPanel.Widgets.Add(fpsLabel);

            // Desktop.Widgets.Add(stackPanel);


            // Inform Myra that external text input is available
            // So it stops translating Keys to chars


            _desktop.HasExternalTextInput = true;

            // Provide that text input
            Window.TextInput += (s, a) =>
            {
                _desktop.OnChar(a.Character);
            };
        }