Skip to content

Commit

Permalink
AudioManager separated from base scene
Browse files Browse the repository at this point in the history
  • Loading branch information
Selinux24 committed May 18, 2024
1 parent cf81322 commit ac8a05d
Show file tree
Hide file tree
Showing 17 changed files with 1,664 additions and 1,050 deletions.
32 changes: 12 additions & 20 deletions Engine.ModularScenery/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,31 @@ namespace Engine.Modular
/// <summary>
/// Modular scenery item
/// </summary>
public class Item
/// <remarks>
/// Constructor
/// </remarks>
/// <param name="obj">Object</param>
/// <param name="instance">Scene object</param>
/// <param name="emitters">Particle emitters list</param>
/// <param name="state">Initial state</param>
public class Item(ObjectReference obj, ModelInstance instance, ParticleEmitter[] emitters, string state)
{
/// <summary>
/// Object
/// </summary>
public ObjectReference Object { get; private set; }
public ObjectReference Object { get; private set; } = obj;
/// <summary>
/// Instance
/// </summary>
public ModelInstance Instance { get; private set; }
public ModelInstance Instance { get; private set; } = instance;
/// <summary>
/// Particle emitters
/// </summary>
public ParticleEmitter[] Emitters { get; private set; }
public ParticleEmitter[] Emitters { get; private set; } = emitters;
/// <summary>
/// Current state
/// </summary>
public string CurrentState { get; set; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="obj">Object</param>
/// <param name="instance">Scene object</param>
/// <param name="emitters">Particle emitters list</param>
/// <param name="state">Initial state</param>
public Item(ObjectReference obj, ModelInstance instance, ParticleEmitter[] emitters, string state)
{
Object = obj;
Instance = instance;
Emitters = emitters;
CurrentState = state;
}
public string CurrentState { get; set; } = state;

/// <inheritdoc/>
public override string ToString()
Expand Down
20 changes: 7 additions & 13 deletions Engine/Common/Updatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ namespace Engine.Common
/// <summary>
/// Updatable object
/// </summary>
public abstract class Updatable<T> : BaseSceneObject<T>, IUpdatable where T : SceneObjectDescription
/// <remarks>
/// Constructor
/// </remarks>
/// <param name="scene">Scene</param>
/// <param name="id">Id</param>
/// <param name="name">Name</param>
public abstract class Updatable<T>(Scene scene, string id, string name) : BaseSceneObject<T>(scene, id, name), IUpdatable where T : SceneObjectDescription
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="scene">Scene</param>
/// <param name="id">Id</param>
/// <param name="name">Name</param>
protected Updatable(Scene scene, string id, string name) :
base(scene, id, name)
{

}

/// <inheritdoc/>
public virtual void EarlyUpdate(UpdateContext context)
{
Expand Down
17 changes: 15 additions & 2 deletions Engine/LoadResourcesResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,29 @@ public virtual bool Completed
/// Throw exceptions, if any
/// </summary>
public virtual void ThrowExceptions()
{
var aggregate = Flatten();
if (aggregate == null)
{
return;
}

throw aggregate;
}
/// <summary>
/// Gets the aggregate exception, if any
/// </summary>
public virtual AggregateException Flatten()
{
var exList = GetExceptions();
if (!exList.Any())
{
return;
return null;
}

var aggregate = new AggregateException($"A load resource task list results in error.", exList);

throw aggregate.Flatten();
return aggregate.Flatten();
}
/// <summary>
/// Gets a list of exception results, if any
Expand Down
35 changes: 15 additions & 20 deletions Engine/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Engine
{
using Engine.Audio;
using Engine.Common;

/// <summary>
Expand Down Expand Up @@ -47,10 +46,6 @@ public class Scene : IHasGameState, IDisposable
/// Scene mode
/// </summary>
private SceneModes sceneMode = SceneModes.Unknown;
/// <summary>
/// Audio manager
/// </summary>
private GameAudioManager audioManager = null;

/// <summary>
/// Scene bounding box
Expand All @@ -60,16 +55,6 @@ public class Scene : IHasGameState, IDisposable
/// Scene renderer
/// </summary>
protected ISceneRenderer Renderer = null;
/// <summary>
/// Audio manager
/// </summary>
protected GameAudioManager AudioManager
{
get
{
return audioManager ??= new();
}
}

/// <summary>
/// Game class
Expand Down Expand Up @@ -170,9 +155,6 @@ protected virtual void Dispose(bool disposing)
Renderer?.Dispose();
Renderer = null;

audioManager?.Dispose();
audioManager = null;

Camera?.Dispose();
Camera = null;

Expand Down Expand Up @@ -209,8 +191,6 @@ public virtual void Update(IGameTime gameTime)
// Camera!
Camera?.Update(gameTime);

AudioManager?.Update(gameTime);

// Action!
Renderer?.Update(gameTime);
}
Expand Down Expand Up @@ -393,6 +373,7 @@ private async Task<TObj> AddComponentInternal<TObj, TDescription>(string id, str

return component;
}

/// <summary>
/// Adds an agent component to the scene
/// </summary>
Expand Down Expand Up @@ -510,6 +491,20 @@ public async Task<TObj> AddComponent<TObj, TDescription>(string id, string name,
/// Adds a component to the scene
/// </summary>
/// <typeparam name="TObj">Component type</typeparam>
/// <param name="id">Id</param>
/// <param name="name">Name</param>
/// <param name="usage">Component usage</param>
/// <param name="layer">Processing layer</param>
/// <returns>Returns the created component</returns>
public async Task<TObj> AddComponent<TObj>(string id, string name, SceneObjectUsages usage = SceneObjectUsages.None, int layer = LayerDefault)
where TObj : BaseSceneObject<SceneObjectDescription>
{
return await AddComponentInternal<TObj, SceneObjectDescription>(id, name, new(), usage, layer);
}
/// <summary>
/// Adds a component to the scene
/// </summary>
/// <typeparam name="TObj">Component type</typeparam>
/// <param name="component">Component instance</param>
/// <param name="usage">Component usage</param>
/// <param name="layer">Processing layer</param>
Expand Down
Loading

0 comments on commit ac8a05d

Please sign in to comment.