Added fake loading screen. Added music support.

This commit is contained in:
Tim Sarbin 2018-11-22 02:24:55 -05:00
parent c852d3b172
commit 9b721e4cce
7 changed files with 121 additions and 1 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.Common.Interfaces
{
public interface IMusicProvider : IDisposable
{
void LoadSong(Stream data);
void PlaySong();
void StopSong();
}
}

View File

@ -70,6 +70,7 @@
<Compile Include="Enums\eMPQFormatVersion.cs" />
<Compile Include="Interfaces\IGameEngine.cs" />
<Compile Include="Interfaces\IMPQProvider.cs" />
<Compile Include="Interfaces\IMusicProvider.cs" />
<Compile Include="Interfaces\IPaletteProvider.cs" />
<Compile Include="Interfaces\IRenderTarget.cs" />
<Compile Include="Interfaces\IRenderWindow.cs" />

View File

@ -12,6 +12,7 @@ namespace OpenDiablo2.SDL2_
log.Info("Configuring OpenDiablo2.Core service implementations.");
builder.RegisterType<SDL2RenderWindow>().AsImplementedInterfaces().SingleInstance();
builder.RegisterType<SDL2MusicPlayer>().AsImplementedInterfaces().SingleInstance();
}
}

View File

@ -75,6 +75,7 @@
<Compile Include="SDL2-CS\SDL2_image.cs" />
<Compile Include="SDL2-CS\SDL2_mixer.cs" />
<Compile Include="SDL2-CS\SDL2_ttf.cs" />
<Compile Include="SDL2MusicPlayer.cs" />
<Compile Include="SDL2RenderWindow.cs" />
<Compile Include="SDL2Sprite.cs" />
</ItemGroup>
@ -91,6 +92,9 @@
<Content Include="SDL2.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SDL2_mixer.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,72 @@
using OpenDiablo2.Common.Interfaces;
using SDL2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.SDL2_
{
public sealed class SDL2MusicPlayer : IMusicProvider
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private IntPtr music = IntPtr.Zero;
public SDL2MusicPlayer()
{
if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
log.Error($"SDL_mixer could not initialize! SDL_mixer Error: {SDL.SDL_GetError()}");
return;
}
}
public void PlaySong()
{
SDL_mixer.Mix_PlayChannel(-1, music, 1);
}
public void LoadSong(Stream data)
{
if (music != IntPtr.Zero)
StopSong();
var br = new BinaryReader(data);
var bytes = br.ReadBytes((int)(data.Length - data.Position));
music = SDL_mixer.Mix_QuickLoad_WAV(bytes);
}
public void StopSong()
{
if (music == IntPtr.Zero)
return;
SDL_mixer.Mix_FreeChunk(music);
}
public void Dispose()
{
StopSong();
SDL_mixer.Mix_CloseAudio();
}
/*
musicStream = data;
SDL.SDL_AudioSpec want = new SDL.SDL_AudioSpec
{
freq = 22050,
format = SDL.AUDIO_S16LSB,
channels = 2,
samples = 4096,
callback = AudioCallback
};
SDL.SDL_OpenAudio(ref want, out audioSpec);
SDL.SDL_PauseAudio(0);
*/
}
}

Binary file not shown.

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OpenDiablo2.Scenes
@ -19,6 +20,7 @@ namespace OpenDiablo2.Scenes
private readonly IPaletteProvider paletteProvider;
private readonly IMPQProvider mpqProvider;
private readonly IMouseInfoProvider mouseInfoProvider;
private readonly IMusicProvider musicProvider;
private float logoFrame;
private ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack, mouseSprite;
@ -27,7 +29,8 @@ namespace OpenDiablo2.Scenes
IRenderWindow renderWindow,
IPaletteProvider paletteProvider,
IMPQProvider mpqProvider,
IMouseInfoProvider mouseInfoProvider
IMouseInfoProvider mouseInfoProvider,
IMusicProvider musicProvider
)
{
this.renderWindow = renderWindow;
@ -61,6 +64,29 @@ namespace OpenDiablo2.Scenes
diabloLogoLeftBlack.Location = new Point(400, 120);
diabloLogoRightBlack.Location = new Point(400, 120);
var loadingSprite = renderWindow.LoadSprite(ImageSet.LoadFromStream(mpqProvider.GetStream("data\\global\\ui\\Loading\\loadingscreen.dc6")));
loadingSprite.CurrentPalette = paletteProvider.PaletteTable["loading"];
loadingSprite.Location = new Point(300, 400);
renderWindow.Clear();
renderWindow.Draw(loadingSprite);
renderWindow.Sync();
musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav"));
// TODO: Fake loading for now, this should be in its own scene as we start loading real stuff
var r = new Random();
for(int i = 1; i < 10; i++)
{
renderWindow.Clear();
loadingSprite.Frame = i;
renderWindow.Draw(loadingSprite);
renderWindow.Sync();
Thread.Sleep(r.Next(150));
}
musicProvider.PlaySong();
}
public void Render()