diff --git a/MonoGame.sln b/MonoGame.sln index d6d5a9d..808ff8a 100644 --- a/MonoGame.sln +++ b/MonoGame.sln @@ -33,6 +33,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Systems.Debugging", "src\Li EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features.Debugging", "src\Libs\Features.Debugging\Features.Debugging.csproj", "{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nez.MG38.Persistence", "src\Libs\External\Nez\Nez.Persistence\Nez.MG38.Persistence.csproj", "{49086DC7-94D4-4715-AEFD-D685D0473FA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nez.MG38", "src\Libs\External\Nez\Nez.Portable\Nez.MG38.csproj", "{439580AE-4535-4BB8-A706-FEB2A6FF783C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -82,6 +86,14 @@ Global {8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Release|Any CPU.Build.0 = Release|Any CPU + {49086DC7-94D4-4715-AEFD-D685D0473FA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49086DC7-94D4-4715-AEFD-D685D0473FA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49086DC7-94D4-4715-AEFD-D685D0473FA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49086DC7-94D4-4715-AEFD-D685D0473FA8}.Release|Any CPU.Build.0 = Release|Any CPU + {439580AE-4535-4BB8-A706-FEB2A6FF783C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {439580AE-4535-4BB8-A706-FEB2A6FF783C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {439580AE-4535-4BB8-A706-FEB2A6FF783C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {439580AE-4535-4BB8-A706-FEB2A6FF783C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5E3B6238-A92E-4703-8527-1C2410D7906A} = {F5258F7E-B0BA-466D-8CF8-4DAB84722BE3} @@ -98,5 +110,7 @@ Global {8232C7AA-E217-465B-95A3-C42D1000FA3B} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} {7AD01EBF-370B-4F35-9AEC-172A889D643F} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} {8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} + {439580AE-4535-4BB8-A706-FEB2A6FF783C} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E} + {49086DC7-94D4-4715-AEFD-D685D0473FA8} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E} EndGlobalSection EndGlobal diff --git a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs index 53584e4..f467ced 100644 --- a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs +++ b/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs @@ -8,24 +8,11 @@ namespace GameDesktop.CompositionRoots; internal class GameCompositionRoot : ICompositionRoot { private const float TargetFramesPerSecond = 120.0f; - private const bool IsMouseVisible = true; public void Compose(IServiceRegistry serviceRegistry) { - serviceRegistry.Register(factory => - { - Game game = new(factory.GetInstance(), - factory.GetInstance(), - TargetFramesPerSecond) - { - IsMouseVisible = IsMouseVisible, Content = { RootDirectory = AppVariable.ContentRootDirectory, } - }; - - // Hack. Resolving cycle dependency issue (fundamental architecture) - // Implicitly adds itself in the game services container. - new GraphicsDeviceManager(game); - - return game; - }); + serviceRegistry.Register(factory => new Game(factory.GetInstance(), + factory.GetInstance(), + TargetFramesPerSecond)); } } diff --git a/src/Apps/GameDesktop/Content/Content.mgcb b/src/Apps/GameDesktop/Content/Content.mgcb index c2bdd81..668ad1f 100644 --- a/src/Apps/GameDesktop/Content/Content.mgcb +++ b/src/Apps/GameDesktop/Content/Content.mgcb @@ -13,6 +13,9 @@ #---------------------------------- Content ---------------------------------# +#begin Nez/NezDefaultBMFont.xnb +/copy:Nez/NezDefaultBMFont.xnb + #begin SpriteSheets/Player.aseprite /copy:SpriteSheets/Player.aseprite diff --git a/src/Apps/GameDesktop/Content/Nez/NezDefaultBMFont.xnb b/src/Apps/GameDesktop/Content/Nez/NezDefaultBMFont.xnb new file mode 100644 index 0000000..859df51 Binary files /dev/null and b/src/Apps/GameDesktop/Content/Nez/NezDefaultBMFont.xnb differ diff --git a/src/Apps/GameDesktop/Game.cs b/src/Apps/GameDesktop/Game.cs index c1b48b7..b364f04 100644 --- a/src/Apps/GameDesktop/Game.cs +++ b/src/Apps/GameDesktop/Game.cs @@ -1,26 +1,17 @@ -using System; -using Features; -using GameDesktop.CompositionRoots.Features; -using LightInject; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; +using LightInject; +using Nez; using Serilog; namespace GameDesktop; -public class Game : Microsoft.Xna.Framework.Game +public class Game : Core { private readonly float _targetTimeStep; private readonly ILogger _logger; private readonly IServiceContainer _container; - private Entitas.Extended.Feature _rootFeature; - private SpriteBatch _spriteBatch; - private float _accumulatedTime; - - - public Game(ILogger logger, IServiceContainer container, float targetFramesPerSecond) + public Game(ILogger logger, IServiceContainer container, float targetFramesPerSecond) : base() { _logger = logger; _container = container; @@ -28,95 +19,4 @@ public Game(ILogger logger, IServiceContainer container, float targetFramesPerSe _logger.ForContext().Verbose("ctor"); } - - protected override void Initialize() - { - _logger.ForContext().Verbose($"Initialize(): start; available {GraphicsDevice}"); - _logger.ForContext().Verbose("SpriteBatch initialization..."); - - _container.RegisterSingleton(_ => new SpriteBatch(GraphicsDevice)); - _spriteBatch = _container.GetInstance(); - // GraphicsDeviceManager.PreferredBackBufferWidth = 640; - // GraphicsDeviceManager.PreferredBackBufferHeight = 480; - // GraphicsDeviceManager.ApplyChanges(); - - _logger.ForContext().Verbose("SpriteBatch initialized"); - - base.Initialize(); - - _logger.ForContext().Verbose("Initialize(): end"); - } - - protected override void LoadContent() - { - _logger.ForContext().Verbose("LoadContent(): start"); - - _container.RegisterFrom(); - - _rootFeature = _container.GetInstance(); - - // TODO: Logging with game flags (like LOG_MOVEMENT, etc)? - // todo: pass tru logger & log places - // TODO: Error handling - _rootFeature.Initialize(); - _logger.ForContext().Verbose("LoadContent(): end"); - } - - protected override void BeginRun() - { - _logger.ForContext().Verbose("Beginning run..."); - - base.BeginRun(); - - _logger.ForContext().Verbose("Running"); - } - - protected override void EndRun() - { - _logger.ForContext().Verbose("Ending run..."); - - base.EndRun(); - - _logger.ForContext().Verbose("Ended"); - } - - // maybe fixed update is incorrect. needs review in the future - private void FixedUpdate(GameTime gameTime) => _rootFeature.FixedExecute(gameTime); - - protected override void Update(GameTime gameTime) - { - _accumulatedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; - - while (_accumulatedTime >= _targetTimeStep) - { - FixedUpdate(gameTime); - - _accumulatedTime -= _targetTimeStep; - } - - base.Update(gameTime); - _rootFeature.Execute(gameTime); - - LateUpdate(gameTime); - } - - private void LateUpdate(GameTime gameTime) => _rootFeature.LateExecute(gameTime); - - protected override void Draw(GameTime gameTime) - { - GraphicsDevice.Clear(Color.CornflowerBlue); - - _rootFeature.Draw(gameTime, _spriteBatch); - - base.Draw(gameTime); - } - - protected override void Dispose(bool disposing) - { - _logger.ForContext().Verbose("Disposing..."); - - base.Dispose(disposing); - - _logger.ForContext().Verbose("Disposed"); - } } diff --git a/src/Apps/GameDesktop/GameDesktop.csproj b/src/Apps/GameDesktop/GameDesktop.csproj index 6f6d886..9d27070 100644 --- a/src/Apps/GameDesktop/GameDesktop.csproj +++ b/src/Apps/GameDesktop/GameDesktop.csproj @@ -67,6 +67,7 @@ +