Skip to content

Commit

Permalink
Naming and Documentation Part 1:
Browse files Browse the repository at this point in the history
Breaking Changes:
- Resource.name changed to Resource.Name
- Camera.TopLeft and Camera.BottomRight replace with GetBounds()
- SoundInstance changed to ManagedSound
- Scene.deltaTime changed to Scene.DeltaTime
- Scene.camera changed to Scene.Camera
- Scene.renderManager to Scene.RenderManager
- Scene.audioManager to Scene.audioManager
- Scene.isLoaded to Scene.IsLoaded
- Scene.started to Scene.Started

Adds missing or non existing XML documentation for:
GUIEditor,
AudioManager,
Camera,
FontResource,
GameObject,
Resource,
Scene,
Shader Resource,
ManagedSound

gitignore for internal documentation generation testing
  • Loading branch information
ThatGuy-GEWP committed Jun 16, 2024
1 parent 7eb053f commit ea02300
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 122 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/Documentation
66 changes: 48 additions & 18 deletions SFMLGE Local deps/Engine/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,57 @@

namespace SFML_Game_Engine
{
public class SoundInstance : IDisposable
/// <summary>
/// An instance of a <see cref="Sound"/>
/// </summary>
public class ManagedSound : IDisposable
{
/// <summary>
/// The <see cref="Sound"/> within this instance
/// </summary>
public Sound sound;
/// <summary>
/// The name of this sound
/// </summary>
public string name;
public bool Disposed = false;

/// <summary>
/// false while the sound has yet to be disposed
/// </summary>
public bool Disposed { get; private set; } = false;

/// <summary>
/// If true, this instance will be automatically disposed of.
/// </summary>
public bool allowCleanup = true;

public SoundInstance(string name, Sound sound) { this.name = name; this.sound = sound; }
/// <summary>
/// Creates a ManagedSound from a <paramref name="name"/> and a <see cref="Sound"/>
/// </summary>
public ManagedSound(string name, Sound sound) { this.name = name; this.sound = sound; }

public SoundInstance(string name, SoundResource sound)
/// <summary>
/// Creates a ManagedSound from a <paramref name="name"/> and a <see cref="SoundResource"/>
/// </summary>
public ManagedSound(string name, SoundResource sound)
{
this.name = name;
this.sound = new Sound(sound);
}

/// <summary> Plays the current <see cref="sound"/> </summary>
public void Play()
{
sound.Play();
}

/// <summary> Stops the current <see cref="sound"/> </summary>
public void Stop()
{
sound.Stop();
}

/// <summary> Sets the volume of the current <see cref="sound"/> </summary>
public void SetVolume(float volume)
{
sound.Volume = volume;
Expand All @@ -54,20 +78,23 @@ public void Dispose()
/// </summary>
public class AudioManager
{
List<SoundInstance> activeSounds = new List<SoundInstance>(200);
List<ManagedSound> activeSounds = new List<ManagedSound>(200);
Scene ownerScene;

public AudioManager(Scene owner)
{
ownerScene = owner;
}

/// <summary>
/// Updates the internal state of this <see cref="AudioManager"/>
/// </summary>
public void Update()
{
List<SoundInstance> stillPlayingSounds = new List<SoundInstance>();
List<ManagedSound> stillPlayingSounds = new List<ManagedSound>();
for (int i = 0; i < activeSounds.Count; i++)
{
SoundInstance cur = activeSounds[i];
ManagedSound cur = activeSounds[i];

if (cur.Disposed) { continue; }
if (cur.sound == null) { continue; }
Expand All @@ -82,11 +109,14 @@ public void Update()
activeSounds = stillPlayingSounds;
}

/// <summary>
/// Called when the <see cref="Scene"/> this AudioManager is attached to is unloaded
/// </summary>
public void OnUnload()
{
for (int i = 0; i < activeSounds.Count; i++)
{
SoundInstance cur = activeSounds[i];
ManagedSound cur = activeSounds[i];
cur.Stop();
}
}
Expand All @@ -98,7 +128,7 @@ public void OnUnload()
public void PlaySound(SoundResource sound)
{
if (activeSounds.Count > 200) { return; }
SoundInstance inst = new SoundInstance(sound.name, sound);
ManagedSound inst = new ManagedSound(sound.Name, sound);
inst.sound.Play();
activeSounds.Add(inst);
}
Expand All @@ -110,35 +140,35 @@ public void PlaySound(SoundResource sound)
public void PlaySound(SoundResource sound, float volume)
{
if (activeSounds.Count > 200) { return; }
SoundInstance inst = new SoundInstance(sound.name, sound);
ManagedSound inst = new ManagedSound(sound.Name, sound);
inst.sound.Volume = volume;
inst.sound.Play();
activeSounds.Add(inst);
}

/// <summary>
/// Creates a <see cref="SoundInstance"/> from a given <see cref="SoundResource"/>
/// Creates a <see cref="ManagedSound"/> from a given <see cref="SoundResource"/>
/// </summary>
/// <param name="sound"></param>
/// <returns><see cref="SoundInstance"/>, or null if active sounds is greater then 200</returns>
public SoundInstance? CreateSound(SoundResource sound)
/// <returns><see cref="ManagedSound"/>, or null if active sounds is greater then 200</returns>
public ManagedSound? CreateSound(SoundResource sound)
{
if (activeSounds.Count > 200) { return null; }
SoundInstance inst = new SoundInstance(sound.name, sound);
ManagedSound inst = new ManagedSound(sound.Name, sound);
inst.allowCleanup = false;
activeSounds.Add(inst);
return inst;
}

/// <summary>
/// Creates a <see cref="SoundInstance"/> from a given <see cref="SoundResource"/>
/// Creates a <see cref="ManagedSound"/> from a given <see cref="SoundResource"/>
/// </summary>
/// <param name="sound"></param>
/// <returns><see cref="SoundInstance"/>, or null if active sounds is greater then 200</returns>
public SoundInstance? CreateSound(SoundResource sound, float volume)
/// <returns><see cref="ManagedSound"/>, or null if active sounds is greater then 200</returns>
public ManagedSound? CreateSound(SoundResource sound, float volume)
{
if (activeSounds.Count > 200) { return null; }
SoundInstance inst = new SoundInstance(sound.name, sound);
ManagedSound inst = new ManagedSound(sound.Name, sound);
inst.allowCleanup = false;
inst.sound.Volume = volume;
activeSounds.Add(inst);
Expand Down
63 changes: 42 additions & 21 deletions SFMLGE Local deps/Engine/Camera.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,93 @@
using SFML.Graphics;
using SFML_Game_Engine.GUI;

namespace SFML_Game_Engine
{
/// <summary>
/// A Camera, defines where the current <see cref="Scene"/> is being viewed from.
/// </summary>
public class Camera
{
RenderWindow app;
readonly RenderWindow app;

/// <summary>
/// The <see cref="View"/> of this camera.
/// </summary>
public View cameraView;

/// <summary>
/// The center position of the <see cref="cameraView"/>
/// </summary>
public Vector2 cameraPosition
{
get { return (Vector2)cameraView.Center; }
set { SetPosition(value); }
}

/// <summary>
/// The current rotation of this camera, in degrees
/// </summary>
public float cameraRotation
{
get { return cameraView.Rotation; }
set { cameraView.Rotation = value; }
}


/// <summary>
/// The size of this cameras <see cref="cameraView"/>
/// </summary>
public Vector2 cameraAreaSize
{
get { return cameraView.Size; }
set { cameraView.Size = value; }
}

public Vector2 TopLeft
{
get
{
return new Vector2(
cameraView.Center.X - cameraView.Size.X / 2f,
cameraView.Center.Y - cameraView.Size.Y / 2f
);
}
}

public Vector2 BottomRight
/// <summary>
/// Gets the current bounds of the camera.
/// </summary>
/// <returns></returns>
public BoundBox GetBounds()
{
get
{
return new Vector2(
cameraView.Center.X + cameraView.Size.X / 2f,
cameraView.Center.Y + cameraView.Size.Y / 2f
);
}
return new BoundBox(new FloatRect(cameraPosition, cameraAreaSize));
}

/// <summary>
/// Creates a camera bound to a <see cref="RenderWindow"/>
/// </summary>
/// <param name="app"></param>
public Camera(RenderWindow app)
{
this.app = app;
cameraView = new View(app.DefaultView);
}

/// <summary>
/// Sets center of this cameras <see cref="cameraView"/> to a givent <paramref name="vec"/>
/// </summary>
/// <param name="vec">the position to set the camera center to</param>
public void SetPosition(Vector2 vec)
{
cameraView.Center = vec;
}

/// <summary>
/// Resets then zooms the <see cref="cameraView"/>
/// </summary>
/// <param name="factor"></param>
public void SetZoom(float factor) // bit wasteful but it should be fine
{
Vector2 pos = cameraView.Center;
float rot = cameraView.Rotation;
cameraView.Dispose();
cameraView = app.DefaultView;
cameraView.Rotation = rot;
cameraView.Zoom(factor);
cameraView.Center = pos;
}

/// <summary>
/// Sets the view of the <see cref="RenderWindow"/> this camera is attached to, to <see cref="cameraView"/>
/// </summary>
public void Update()
{
app.SetView(cameraView);
Expand Down
2 changes: 1 addition & 1 deletion SFMLGE Local deps/Engine/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public GameObject gameObject

public float DeltaTime
{
get { return Scene.deltaTime; }
get { return Scene.DeltaTime; }
}

public bool Started
Expand Down
6 changes: 3 additions & 3 deletions SFMLGE Local deps/Engine/Editor/GUIEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void Start()

foreach (Resource res in Project.Resources.resources)
{
GUIListEntry entry = new GUIListEntry(25, res.name + "| uses:" + res.requests + " : " + res.GetType().Name, 0);
GUIListEntry entry = new GUIListEntry(25, res.Name + "| uses:" + res.requests + " : " + res.GetType().Name, 0);
entry.textPosition = new Vector2(0.05f, 0.5f);
entry.textAnchor = new Vector2(0f, 0.5f);

Expand Down Expand Up @@ -93,7 +93,7 @@ public override void Update()

foreach (Resource res in Project.Resources.resources)
{
GUIListEntry entry = new GUIListEntry(25, res.name + " : " + res.GetType().Name, 0);
GUIListEntry entry = new GUIListEntry(25, res.Name + " : " + res.GetType().Name, 0);
entry.textPosition = new Vector2(0.05f, 0.5f);
entry.textAnchor = new Vector2(0f, 0.5f);
entry.val = res;
Expand All @@ -110,7 +110,7 @@ public override void Update()
Resource asRes = (Resource)entry.val!;

ResourceInfo.displayedString =
"Resource name: " + asRes.name + "\n" +
"Resource name: " + asRes.Name + "\n" +
"Resource Type: " + entry.valType!.Name + "\n" + "\n" +
"Get Requests: " + asRes.requests + "\n" +
asRes.Description;
Expand Down
16 changes: 15 additions & 1 deletion SFMLGE Local deps/Engine/FontResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@

namespace SFML_Game_Engine
{
/// <summary>
/// A Resource containing a <see cref="Font"/>
/// </summary>
public class FontResource : Resource
{
/// <summary>
/// The <see cref="Font"/> this resource contains.
/// </summary>
public Font resource;

/// <summary>
/// Creates a new <see cref="FontResource"/> from a given <paramref name="filePath"/> and <paramref name="name"/>
/// </summary>
/// <param name="filePath">the path to the <see cref="Font"/></param>
/// <param name="name">the name of this resource</param>
public FontResource(string filePath, string name)
{
this.resource = new Font(filePath);
this.name = name;
this.Name = name;
}

public override void Dispose()
{
return;
}

/// <summary>
/// Converts a <see cref="FontResource"/> into a <see cref="Font"/> implicitly
/// </summary>
public static implicit operator Font(FontResource resource) { return resource.resource; }
}
}
Loading

0 comments on commit ea02300

Please sign in to comment.