Skip to content

Commit

Permalink
Fixed small Audio bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Marin-MK committed Jun 7, 2020
1 parent 2435968 commit 15f5151
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 34 deletions.
16 changes: 5 additions & 11 deletions Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static void Start()
Thread thread = null;
thread = new Thread(delegate ()
{
if (Stopped) thread.Abort();
else Update();
while (!Stopped) Update();
});
thread.Start();
}

public static void Stop()
Expand Down Expand Up @@ -69,10 +69,6 @@ public static void Play(Sound Sound)
Sound.Volume = Sound.__volume__;
Sound.Position = Sound.__position__;
Sound.Pan = Sound.__pan__;
//Sound.__sound__.Volume = Sound.Volume / 100f;
//Sound.__sound__.PlayPosition = Sound.Position;
//Sound.__sound__.Pan = Sound.Pan / -100f;
//Console.WriteLine($"Volume({Sound.__sound__.Volume}) Position({Sound.__sound__.PlayPosition}) Pan({Sound.__sound__.Pan})");
Sound.__sound__.setSoundStopEventReceiver(new InternalStopReceiver(Sound));
Sounds.Add(Sound);
}
Expand All @@ -82,7 +78,7 @@ public static void Update()
for (int i = 0; i < Sounds.Count; i++)
{
Sound Sound = Sounds[i];
if (Sound.__sound__ == null) throw new Exception("Shoulda been removed error");
if (Sound.__sound__ == null || Sound.__sound__.Finished) continue;
if (Sound.Loop && (Sound.LoopTimes == -1 || Sound.TimesLooped < Sound.LoopTimes))
{
if (Sound.__sound__.PlayPosition < Sound.__oldpos__ ||
Expand All @@ -101,7 +97,7 @@ public static void Update()
}
if (Sound.FadeInLength != 0 && Sound.Position < Sound.FadeInLength && Sound.TimesLooped == 0)
{
float fraction = (float)Sound.Position / Sound.FadeInLength;
float fraction = (float) Sound.Position / Sound.FadeInLength;
Sound.__sound__.Volume = Sound.__volume__ / 100f * fraction;
Sound.__fade_in__ = true;
}
Expand All @@ -114,7 +110,7 @@ public static void Update()
if (Sound.FadeOutLength != 0 && Sound.Position >= Sound.__sound__.PlayLength - Sound.FadeOutLength &&
(Sound.LoopTimes != -1 && Sound.TimesLooped == Sound.LoopTimes || Sound.LoopTimes == -1 && !Sound.Loop))
{
float fraction = (float)(Sound.__sound__.PlayLength - Sound.Position) / Sound.FadeOutLength;
float fraction = (float) (Sound.__sound__.PlayLength - Sound.Position) / Sound.FadeOutLength;
Sound.__sound__.Volume = Sound.__volume__ / 100f * fraction;
if (!Sound.__fade_out__)
{
Expand All @@ -139,8 +135,6 @@ public InternalStopReceiver(Sound Sound)
public void OnSoundStopped(ISound sound, StopEventCause reason, object userData)
{
this.Sound.OnStopped?.Invoke(new BaseEventArgs());
//this.Sound.__sound__ = null;
//Sounds.Remove(this.Sound);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ public static void RegisterRenderer(Renderer Renderer)
/// </summary>
public static bool CanUpdate()
{
return Windows.Count(w => w != null && !w.Disposed) > 0;
for (int i = 0; i < Windows.Count; i++)
{
if (Windows[i] != null && !Windows[i].Disposed) return true;
}
return false;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public static void SetCursor(IntPtr Cursor)
/// </summary>
public static void CaptureMouse()
{
SDL2.SDL.SDL_CaptureMouse(SDL2.SDL.SDL_bool.SDL_TRUE);
SDL_CaptureMouse(SDL_bool.SDL_TRUE);
}

/// <summary>
/// Disallows mouse events to fire when the mouse is outside of the window.
/// </summary>
public static void ReleaseMouse()
{
SDL2.SDL.SDL_CaptureMouse(SDL2.SDL.SDL_bool.SDL_FALSE);
SDL_CaptureMouse(SDL_bool.SDL_FALSE);
}
}
}
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
<h1>Object-Oriented DirectMedia Layer (ODL)</h1>
<h1>odl</h1>

This library implements all the major SDL2 components in an Object-Oriented fashion. Surfaces are Bitmaps, Sprites manage Bitmaps, Viewports delimit Sprites, and Windows manage Viewports.
odl, short for <b>Object-Oriented DirectMedia Layer</b>, is first and foremost a cross-platform .NET Core C# library for creating a window and displaying and manipulating the content of that window. It also includes simple input handling and audio playback.

The implementation of all the classes is based on RGSS (Ruby Game Scripting System), but there's quite a few differences.

<h2>Dependencies</h2>

<list>
<li>libfreetype-6
<li>libpng16-16
<li>SDL2 (2.0.7 used)
<li>SDL2_image (2.0.2 used)
<li>SDL2_ttf (2.0.14 used)
<li><a href="https://github.com/flibitijibibo/SDL2-CS">SDL2-CS</a>
<li>zlib (1.2.11 used)
</list>

If using ILMerge to merge your libraries, only odl.dll and SDL2-CS.dll can be merged together.
An extensive introduction, documentation and examples can be found at https://m3rein.gitbook.io/odl/.
6 changes: 3 additions & 3 deletions Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Sound
// General
public string Filename;
public int __volume__ = 100;
public int Volume { get { return __sound__ == null ? __volume__ : (int)Math.Round(__sound__.Volume * 100); } set { if (__sound__ != null) __sound__.Volume = value / 100f; __volume__ = value; } }
public int Volume { get { return __sound__ == null ? __volume__ : (int) Math.Round(__sound__.Volume * 100); } set { if (__sound__ != null) __sound__.Volume = value / 100f; __volume__ = value; } }
public uint __position__ = 0;
public uint Position { get { return __sound__ == null ? __position__ : __sound__.PlayPosition; } set { if (__sound__ != null) __sound__.PlayPosition = value; __position__ = value; __oldpos__ = value; } }
public int __pan__ = 0;
public int Pan { get { return __sound__ == null ? __pan__ : (int)Math.Round(__sound__.Pan * -100); } set { if (__sound__ != null) __sound__.Pan = value / -100f; __pan__ = value; } }
public int Pan { get { return __sound__ == null ? __pan__ : (int) Math.Round(__sound__.Pan * -100); } set { if (__sound__ != null) __sound__.Pan = value / -100f; __pan__ = value; } }
public bool Paused { get { return __sound__ == null ? false : __sound__.Paused; } }
public bool Playing { get { return __sound__ != null && !Paused; } }
public bool Playing { get { return __sound__ != null && !Paused && !__sound__.Finished; } }
public bool Disposed = false;

// Looping
Expand Down
1 change: 1 addition & 0 deletions Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public void Initialize(bool HardwareAcceleration = true, bool VSync = false)

this.Viewport = new Viewport(this, 0, 0, this.Width, this.Height);
this.Viewport.Name = "Main Viewport";
if (Viewport.DefaultWindow == null) Viewport.DefaultWindow = this;
if (Sprite.DefaultViewport == null) Sprite.DefaultViewport = this.Viewport;

BackgroundViewport = new Viewport(this, 0, 0, this.Width, this.Height);
Expand Down

0 comments on commit 15f5151

Please sign in to comment.