Velaptor Release v1.0.0-preview.35
Hello again!! This release is a good one. ๐
Quick Overviewโ
This release contains changes like a bug fix related to flipping images vertically and horizontally, dependency updates, refactorings, code cleanup, and most importantly, the new stream audio playback feature inherited from CASL.
The Velaptor release v1.0.0-preview.35 also contains breaking changes related to the public API.
These breaking changes are necessary and help solidify the public API before the version v1.0.0
final release.
This release is a good one. ๐ค๐ป
Check out the Velaptor Release Notes!!
If you are interested in seeing some of the features of Velaptor, check out the Demo Video!!
Quick shout out to the following contributors for their support:
- Thanks @AndreBonda for his contribution with issue #868!
- Thanks @thestbar for his contribution with issue #783!
Let's get into the details!!
Bug Fixโ
The bug fix in this release is related to flipping images vertically and horizontally when using
the ImageData
struct. If you were using a variable of type ImageData
, then created the variable
using the default constructor or the default
keyword, and you tried to flip the image using the
FlipHorizontally()
or FlipVertically()
methods, then you would get an exception.
Here is an example of the code that would throw an exception:
// ImageData imgData = default; ๐๐ป or this
// var imgData = new ImageData(); ๐๐ป or this
var imgData = default(ImageData); ๐๐ป or this
imgData.FlipHorizontally(); ๐๐ป Would cause an exception
imgData.FlipVertically(); ๐๐ป Would cause an exception
Dependency Updatesโ
The main dependency update was to the latest version of CASL. We will get into that later.
Check out the CASL Release Notes for more details.
Another dependency update was upgrading Carbonate from version v1.0.0-preview.16 to v1.0.0-preview.18.
Refactorings and Code Cleanupโ
As always, we are continuously looking for ways to improve the codebase. This release contains code cleanup in areas such as the main Velaptor project, the unit tests, spelling and grammar throughout the code docs, and more.
The improvement of the code docs directly impacts the developer experience as well as on the API documentation.
API Changesโ
The breaking changes in this release are related to the public API. The changes are necessary to make the API more consistent, easy to use, and with minimal confusion.
Removal of concrete loader typesโ
This change is about being more opinionated and producing less confusion for the user when loading content.
Currently, the best and easiest way to load content and create content loaders is to use the ContentLoaderFactory
.
Use the desired loader throughout the lifetime of the scene, then use that loader to load specific content.
Let's show you an example:
public override void LoadContent()
{
// Most common way to load content
this.textureLoader = ContentLoaderFactory.CreateTextureLoader();
this.texture = this.textureLoader.Load("my-texture");
}
Before version v1.0.0-preview.35 you could load content manually by creating a loader object:
public override void LoadContent()
{
this.textureLoader = new TextureLoader(); ๐๐ผ // Has been removed
this.texture = this.textureLoader.Load("my-texture");
}
We are getting close but have yet to reach v1.0.0. The NEED for creating content loaders via constructors is not necessary; it is better to have APIs closed and then opened up as needed. This practice helps keep the API more consistent, and reduces breaking changes.
Sound class changesโ
-
We have changed the name of the
Sound
class toAudio
and theISound
interface toIAudio
. This change better reflects the purpose of the class and aligns better with the latest version of the CASL library.// Before v1.0.0-preview.35
var music = new Sound("my-music.ogg");
// After v1.0.0-preview.35
this.audioLoader = ContentLoaderFactory.CreateAudioLoader();
var music = this.audioLoader.Load("my-music.ogg", AudioBuffer.Stream);
// or
var music = this.audioLoader.Load("my-music.ogg", AudioBuffer.Full); -
We have also changed the data type of the
Position
andLength
properties toTimeSpan
. UsingTimeSpan
means using what is provided by dotnet instead of creating and maintaining a type to represent time. The previous type,SoundTime
was a type from CASL and was not intended to be exposed or used in Velaptor. TheTimeSpan
API data type provides more power and flexibility than the oldSoundTime
API. -
We have replaced the
State
property from theISound
interface andSound
class with the following bool properties to represent the state of the audio.IsPlaying
IsPaused
IsStopped
- The
State
property was removed due to the unintentional exposure of the CASL API.
Here is an example of how to check the state of the audio before and after the changes:
// Before v1.0.0-preview.35
var music = new Sound("my-music.ogg");
var isPlaying = music.State == AudioState.Playing;
var isPaused = music.State == AudioState.Paused;
var isStopped = music.State == AudioState.Stopped;
// After v1.0.0-preview.35
this.audioLoader = ContentLoaderFactory.CreateAudioLoader();
var music = this.audioLoader.Load("my-music.ogg", AudioBuffer.Stream);
var isPlaying = music.IsPlaying;
var isPaused = music.IsPaused;
var isStopped = music.IsStopped; -
We removed the
Reset()
method which was a duplication of theStop()
method. Both methods existed when we first brought CASL into Velaptor. In the world of OpenAL, there is a difference between both operation types, and they were brought into the API by mistake. When it comes to user expectations and experience, a single method is the better way to go. -
We removed the
public
constructor from theAudio
class (it used to beSound
), which reduces the number of ways to load content and keeps the API opinionated and consistent.
Naming Changesโ
We went through the entire code base, refactored all types and code docs using the terms Sound
and Sounds
, and replaced them with Audio
.
Here is a list of the naming changes we did on various types and methods:
-
Refactored the name of the
LoadSoundException
toLoadAudioException
. -
Refactored the name of the
SoundLoader
class toAudioLoader
. -
Refactored the name of the
PathResolverFactory.CreateSoundPathResolver()
method toPathResolverFactory.CreateAudioPathResolver()
. -
Refactored the name of the
ContentLoaderFactory.CreateSoundLoader()
method toContentLoaderFactory.CreateAudioLoader()
. -
Refactored the
ILoader<IAudio>.Unload()
method parameter namedsound
toaudio
.