Compare commits
	
		
			2 Commits
		
	
	
		
			65cfaf1b4a
			...
			ad365dc722
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ad365dc722 | |||
| 200e8ae7da | 
							
								
								
									
										6
									
								
								Engine.Core/Debug/LoggerWrapperExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Engine.Core/Debug/LoggerWrapperExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
namespace Syntriax.Engine.Core.Debug;
 | 
			
		||||
 | 
			
		||||
public static class LoggerWrapperExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ILogger WrapWith(this ILogger thisLogger, ILogger logger) => new LoggerWrapper(thisLogger, logger);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
using Microsoft.Xna.Framework.Content;
 | 
			
		||||
 | 
			
		||||
using Syntriax.Engine.Core;
 | 
			
		||||
 | 
			
		||||
namespace Syntriax.Engine.Integration.MonoGame;
 | 
			
		||||
 | 
			
		||||
public interface ILoadContent : IBehaviour
 | 
			
		||||
{
 | 
			
		||||
    void LoadContent(ContentManager content);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,53 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Syntriax.Engine.Core;
 | 
			
		||||
 | 
			
		||||
namespace Syntriax.Engine.Integration.MonoGame;
 | 
			
		||||
 | 
			
		||||
public class LoadContentManager : Behaviour, IFirstFrameUpdate
 | 
			
		||||
{
 | 
			
		||||
    // We use Ascending order because we are using reverse for loop to call them
 | 
			
		||||
    private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
 | 
			
		||||
 | 
			
		||||
    private readonly ActiveBehaviourCollectorSorted<ILoadContent> loadContents = new() { SortBy = SortByAscendingPriority() };
 | 
			
		||||
    private readonly List<ILoadContent> toCallLoadContents = new(32);
 | 
			
		||||
 | 
			
		||||
    private MonoGameWindowContainer monoGameWindowContainer = null!;
 | 
			
		||||
 | 
			
		||||
    public void FirstActiveFrame()
 | 
			
		||||
    {
 | 
			
		||||
        monoGameWindowContainer = Universe.FindRequiredBehaviour<MonoGameWindowContainer>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnEnteredUniverse(IUniverse universe)
 | 
			
		||||
    {
 | 
			
		||||
        loadContents.Assign(universe);
 | 
			
		||||
 | 
			
		||||
        universe.OnPreUpdate.AddListener(OnPreUpdate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnExitedUniverse(IUniverse universe)
 | 
			
		||||
    {
 | 
			
		||||
        loadContents.Unassign();
 | 
			
		||||
 | 
			
		||||
        universe.OnPreUpdate.RemoveListener(OnPreUpdate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void OnPreUpdate(IUniverse sender, IUniverse.UpdateArguments args)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = toCallLoadContents.Count - 1; i >= 0; i--)
 | 
			
		||||
        {
 | 
			
		||||
            toCallLoadContents[i].LoadContent(monoGameWindowContainer.Window.Content);
 | 
			
		||||
            toCallLoadContents.RemoveAt(i);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void OnFirstFrameCollected(IBehaviourCollector<ILoadContent> sender, IBehaviourCollector<ILoadContent>.BehaviourCollectedArguments args)
 | 
			
		||||
    {
 | 
			
		||||
        toCallLoadContents.Add(args.BehaviourCollected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LoadContentManager()
 | 
			
		||||
    {
 | 
			
		||||
        loadContents.OnCollected.AddListener(OnFirstFrameCollected);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -21,6 +21,9 @@ public class MonoGameWindow : Game
 | 
			
		||||
 | 
			
		||||
        Universe.InstantiateUniverseObject().SetUniverseObject("Window Container")
 | 
			
		||||
            .BehaviourController.AddBehaviour<MonoGameWindowContainer>(this);
 | 
			
		||||
 | 
			
		||||
        Universe.InstantiateUniverseObject().SetUniverseObject("Content Loader")
 | 
			
		||||
            .BehaviourController.AddBehaviour<LoadContentManager>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void Initialize()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user