Change folder structure, add solution to the root.
This commit is contained in:
9
DaggerFramework/Source/Resources/Loaders/FontLoader.cs
Normal file
9
DaggerFramework/Source/Resources/Loaders/FontLoader.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DaggerFramework;
|
||||
|
||||
public class FontLoader : ResourceLoader<Font>
|
||||
{
|
||||
public override Font Load(string path)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
8
DaggerFramework/Source/Resources/Loaders/ResourceLoader.cs
Executable file
8
DaggerFramework/Source/Resources/Loaders/ResourceLoader.cs
Executable file
@@ -0,0 +1,8 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public abstract class ResourceLoader<T> : IDisposable where T : Resource
|
||||
{
|
||||
public void Dispose() { }
|
||||
public abstract T Load(string path);
|
||||
}
|
||||
}
|
||||
47
DaggerFramework/Source/Resources/Loaders/SoundLoader.cs
Normal file
47
DaggerFramework/Source/Resources/Loaders/SoundLoader.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using StbVorbisSharp;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class SoundLoader : ResourceLoader<Sound>
|
||||
{
|
||||
public override Sound Load(string path)
|
||||
{
|
||||
Vorbis vorbis;
|
||||
Sound result;
|
||||
|
||||
var fileBuffer = File.ReadAllBytes(path);
|
||||
vorbis = Vorbis.FromMemory(fileBuffer);
|
||||
|
||||
vorbis.SubmitBuffer();
|
||||
|
||||
if (vorbis.Decoded == 0)
|
||||
{
|
||||
vorbis.Restart();
|
||||
vorbis.SubmitBuffer();
|
||||
}
|
||||
|
||||
var audioShort = vorbis.SongBuffer;
|
||||
int length = vorbis.Decoded * vorbis.Channels;
|
||||
byte[] audioData = new byte[length * 2];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (i * 2 >= audioData.Length) break;
|
||||
|
||||
var b1 = (byte)(audioShort[i] >> 8);
|
||||
var b2 = (byte)(audioShort[i] & 256);
|
||||
|
||||
audioData[i * 2] = b2;
|
||||
audioData[i * 2 + 1] = b1;
|
||||
}
|
||||
|
||||
result = new Sound(path, audioData);
|
||||
result.Format = (SoundFormat)vorbis.Channels - 1;
|
||||
result.SampleRate = vorbis.SampleRate;
|
||||
result.BufferSize = length;
|
||||
|
||||
vorbis.Dispose();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
DaggerFramework/Source/Resources/Loaders/Texture2dLoader.cs
Executable file
22
DaggerFramework/Source/Resources/Loaders/Texture2dLoader.cs
Executable file
@@ -0,0 +1,22 @@
|
||||
using StbImageSharp;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class Texture2dLoader : ResourceLoader<Texture2d>
|
||||
{
|
||||
public override Texture2d Load(string path)
|
||||
{
|
||||
ImageResult image;
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
|
||||
}
|
||||
|
||||
Texture2d result = new Texture2d(path, image.Data);
|
||||
result.Width = image.Width;
|
||||
result.Height = image.Height;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user