Change folder structure, add solution to the root.

This commit is contained in:
2023-06-18 17:19:03 +02:00
parent d5f5fb5614
commit 15747d7e9b
51 changed files with 33 additions and 6 deletions

View File

@@ -0,0 +1,9 @@
namespace DaggerFramework;
public class Font : Resource
{
public int Size = 16;
public Font(string path, byte[] buffer) : base(path, buffer)
{
}
}

View File

@@ -0,0 +1,9 @@
namespace DaggerFramework;
public class FontLoader : ResourceLoader<Font>
{
public override Font Load(string path)
{
return default;
}
}

View 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);
}
}

View 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;
}
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,23 @@
namespace DaggerFramework
{
public abstract class Resource : IDisposable
{
public string? Path { get => _path; set => _path = value; }
public byte[]? Buffer { get => _buffer; set => _buffer = value; }
public Resource(string path, byte[] buffer)
{
_path = path;
_buffer = buffer;
}
public void Dispose()
{
Buffer = null;
Path = null;
}
private string? _path;
private byte[]? _buffer;
}
}

View File

@@ -0,0 +1,19 @@
namespace DaggerFramework
{
public class Sound : Resource
{
public SoundFormat Format { get; set; }
public int SampleRate { get; set; }
public int BufferSize { get; set; }
public Sound(string path, byte[] buffer) : base(path, buffer)
{
}
}
public enum SoundFormat
{
Mono,
Stereo
}
}

View File

@@ -0,0 +1,11 @@
namespace DaggerFramework
{
public class Texture2d : Resource
{
public int Width { get; set; }
public int Height { get; set; }
public Texture2d(string path, byte[] buffer) : base(path, buffer)
{
}
}
}