mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-19 02:46:35 -05:00
Started work on session manager. Fixed mouse rendering logic.
This commit is contained in:
parent
6907d8e507
commit
0a3eb44248
21
OpenDiablo2.Common/Enums/eSessionType.cs
Normal file
21
OpenDiablo2.Common/Enums/eSessionType.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenDiablo2.Common.Enums
|
||||||
|
{
|
||||||
|
/// <summary>Defines the type of gameplay session we are running.</summary>
|
||||||
|
public enum eSessionType
|
||||||
|
{
|
||||||
|
/// <summary>This session is an offline single player game.</summary>
|
||||||
|
Local,
|
||||||
|
|
||||||
|
/// <summary>This session is a multiplayer game, and this instance is the server.</summary>
|
||||||
|
Server,
|
||||||
|
|
||||||
|
/// <summary>This session is a multiplayer game, and this instance is a client connected to an external server.</summary>
|
||||||
|
Remote
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ namespace OpenDiablo2.Common.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IRenderWindow : IDisposable
|
public interface IRenderWindow : IDisposable
|
||||||
{
|
{
|
||||||
|
IMouseCursor MouseCursor { get; set; }
|
||||||
|
|
||||||
bool IsRunning { get; }
|
bool IsRunning { get; }
|
||||||
void Update();
|
void Update();
|
||||||
void Clear();
|
void Clear();
|
||||||
@ -24,7 +26,6 @@ namespace OpenDiablo2.Common.Interfaces
|
|||||||
void Draw(ISprite sprite, int frame);
|
void Draw(ISprite sprite, int frame);
|
||||||
void Draw(ISprite sprite, int xSegments, int ySegments, int offset);
|
void Draw(ISprite sprite, int xSegments, int ySegments, int offset);
|
||||||
IMouseCursor LoadCursor(ISprite sprite, int frame, Point hotspot);
|
IMouseCursor LoadCursor(ISprite sprite, int frame, Point hotspot);
|
||||||
void SetCursor(IMouseCursor mouseCursor);
|
|
||||||
void Draw(ILabel label);
|
void Draw(ILabel label);
|
||||||
MapCellInfo CacheMapCell(MPQDT1Tile mapCell);
|
MapCellInfo CacheMapCell(MPQDT1Tile mapCell);
|
||||||
void DrawMapCell(MapCellInfo mapCellInfo, int xPixel, int yPixel);
|
void DrawMapCell(MapCellInfo mapCellInfo, int xPixel, int yPixel);
|
||||||
|
@ -18,7 +18,7 @@ namespace OpenDiablo2.Common.Interfaces
|
|||||||
bool ToggleShowCharacterPanel();
|
bool ToggleShowCharacterPanel();
|
||||||
bool ShowCharacterPanel { get; set; }
|
bool ShowCharacterPanel { get; set; }
|
||||||
|
|
||||||
void Initialize(string text, eHero value);
|
void Initialize(string text, eHero value, eSessionType sessionType);
|
||||||
void Update(long ms);
|
void Update(long ms);
|
||||||
IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType);
|
IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType);
|
||||||
void UpdateMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType, IEnumerable<MapCellInfo> mapCellInfo);
|
void UpdateMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType, IEnumerable<MapCellInfo> mapCellInfo);
|
||||||
|
14
OpenDiablo2.Common/Interfaces/ISessionManager.cs
Normal file
14
OpenDiablo2.Common/Interfaces/ISessionManager.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenDiablo2.Common.Interfaces
|
||||||
|
{
|
||||||
|
public interface ISessionManager : IDisposable
|
||||||
|
{
|
||||||
|
void Initialize();
|
||||||
|
void Stop();
|
||||||
|
}
|
||||||
|
}
|
12
OpenDiablo2.Common/Interfaces/ISessionServer.cs
Normal file
12
OpenDiablo2.Common/Interfaces/ISessionServer.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenDiablo2.Common.Interfaces
|
||||||
|
{
|
||||||
|
public interface ISessionServer : IDisposable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -61,11 +61,14 @@
|
|||||||
<Compile Include="Enums\eLevelSubType.cs" />
|
<Compile Include="Enums\eLevelSubType.cs" />
|
||||||
<Compile Include="Enums\eMPQFormatVersion.cs" />
|
<Compile Include="Enums\eMPQFormatVersion.cs" />
|
||||||
<Compile Include="Enums\eRenderCellType.cs" />
|
<Compile Include="Enums\eRenderCellType.cs" />
|
||||||
|
<Compile Include="Enums\eSessionType.cs" />
|
||||||
<Compile Include="Enums\eTextAlign.cs" />
|
<Compile Include="Enums\eTextAlign.cs" />
|
||||||
<Compile Include="Enums\eWildBorder.cs" />
|
<Compile Include="Enums\eWildBorder.cs" />
|
||||||
<Compile Include="Enums\Mobs\eDamageTypes.cs" />
|
<Compile Include="Enums\Mobs\eDamageTypes.cs" />
|
||||||
<Compile Include="Enums\Mobs\eMobFlags.cs" />
|
<Compile Include="Enums\Mobs\eMobFlags.cs" />
|
||||||
<Compile Include="Enums\Mobs\eStatModifierType.cs" />
|
<Compile Include="Enums\Mobs\eStatModifierType.cs" />
|
||||||
|
<Compile Include="Interfaces\ISessionManager.cs" />
|
||||||
|
<Compile Include="Interfaces\ISessionServer.cs" />
|
||||||
<Compile Include="Interfaces\UI\IButton.cs" />
|
<Compile Include="Interfaces\UI\IButton.cs" />
|
||||||
<Compile Include="Interfaces\UI\IPanelFrame.cs" />
|
<Compile Include="Interfaces\UI\IPanelFrame.cs" />
|
||||||
<Compile Include="Interfaces\UI\IInventoryPanel.cs" />
|
<Compile Include="Interfaces\UI\IInventoryPanel.cs" />
|
||||||
@ -134,6 +137,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<Folder Include="Message Frames\Requests\" />
|
||||||
|
<Folder Include="Message Frames\Responses\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -27,6 +27,7 @@ namespace OpenDiablo2.Core
|
|||||||
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
|
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
|
||||||
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();
|
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();
|
||||||
builder.RegisterType<TextBox>().As<ITextBox>().InstancePerDependency();
|
builder.RegisterType<TextBox>().As<ITextBox>().InstancePerDependency();
|
||||||
|
builder.RegisterType<SessionServer>().As<ISessionServer>().InstancePerLifetimeScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ namespace OpenDiablo2.Core
|
|||||||
private readonly GlobalConfiguration globalConfig;
|
private readonly GlobalConfiguration globalConfig;
|
||||||
private readonly IMPQProvider mpqProvider;
|
private readonly IMPQProvider mpqProvider;
|
||||||
private readonly Func<IRenderWindow> getRenderWindow;
|
private readonly Func<IRenderWindow> getRenderWindow;
|
||||||
private readonly Func<IMouseInfoProvider> getMouseInfoProvider;
|
|
||||||
private readonly Func<string, IScene> getScene;
|
private readonly Func<string, IScene> getScene;
|
||||||
private readonly Func<IResourceManager> getResourceManager;
|
private readonly Func<IResourceManager> getResourceManager;
|
||||||
private readonly Func<IGameState> getGameState;
|
private readonly Func<IGameState> getGameState;
|
||||||
@ -36,7 +35,6 @@ namespace OpenDiablo2.Core
|
|||||||
GlobalConfiguration globalConfig,
|
GlobalConfiguration globalConfig,
|
||||||
IMPQProvider mpqProvider,
|
IMPQProvider mpqProvider,
|
||||||
Func<IRenderWindow> getRenderWindow,
|
Func<IRenderWindow> getRenderWindow,
|
||||||
Func<IMouseInfoProvider> getMouseInfoProvider,
|
|
||||||
Func<string, IScene> getScene,
|
Func<string, IScene> getScene,
|
||||||
Func<IResourceManager> getResourceManager,
|
Func<IResourceManager> getResourceManager,
|
||||||
Func<IGameState> getGameState
|
Func<IGameState> getGameState
|
||||||
@ -45,7 +43,6 @@ namespace OpenDiablo2.Core
|
|||||||
this.globalConfig = globalConfig;
|
this.globalConfig = globalConfig;
|
||||||
this.mpqProvider = mpqProvider;
|
this.mpqProvider = mpqProvider;
|
||||||
this.getRenderWindow = getRenderWindow;
|
this.getRenderWindow = getRenderWindow;
|
||||||
this.getMouseInfoProvider = getMouseInfoProvider;
|
|
||||||
this.getScene = getScene;
|
this.getScene = getScene;
|
||||||
this.getResourceManager = getResourceManager;
|
this.getResourceManager = getResourceManager;
|
||||||
this.getGameState = getGameState;
|
this.getGameState = getGameState;
|
||||||
@ -81,18 +78,13 @@ namespace OpenDiablo2.Core
|
|||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
var renderWindow = getRenderWindow();
|
var renderWindow = getRenderWindow();
|
||||||
var mouseInfoProvider = getMouseInfoProvider();
|
|
||||||
|
|
||||||
LoadPalettes();
|
LoadPalettes();
|
||||||
LoadSoundData();
|
LoadSoundData();
|
||||||
|
|
||||||
mouseSprite = renderWindow.LoadSprite(ResourcePaths.CursorDefault, Palettes.Units);
|
mouseSprite = renderWindow.LoadSprite(ResourcePaths.CursorDefault, Palettes.Units);
|
||||||
IMouseCursor cursor;
|
var cursor = renderWindow.LoadCursor(mouseSprite, 0, new Point(0, 3));
|
||||||
if (globalConfig.MouseMode == eMouseMode.Hardware)
|
renderWindow.MouseCursor = cursor;
|
||||||
{
|
|
||||||
cursor = renderWindow.LoadCursor(mouseSprite, 0, new Point(0, 0));
|
|
||||||
renderWindow.SetCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentScene = getScene("Main Menu");
|
currentScene = getScene("Main Menu");
|
||||||
var lastTicks = renderWindow.GetTicks();
|
var lastTicks = renderWindow.GetTicks();
|
||||||
@ -132,9 +124,6 @@ namespace OpenDiablo2.Core
|
|||||||
renderWindow.Clear();
|
renderWindow.Clear();
|
||||||
currentScene.Render();
|
currentScene.Render();
|
||||||
|
|
||||||
if (globalConfig.MouseMode == eMouseMode.Software)
|
|
||||||
renderWindow.Draw(mouseSprite, new Point(mouseInfoProvider.MouseX, mouseInfoProvider.MouseY + 3));
|
|
||||||
|
|
||||||
renderWindow.Sync();
|
renderWindow.Sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,12 @@ namespace OpenDiablo2.Core.GameState_
|
|||||||
private readonly IEngineDataManager engineDataManager;
|
private readonly IEngineDataManager engineDataManager;
|
||||||
private readonly IRenderWindow renderWindow;
|
private readonly IRenderWindow renderWindow;
|
||||||
private readonly Func<IMapEngine> getMapEngine;
|
private readonly Func<IMapEngine> getMapEngine;
|
||||||
|
private readonly Func<eSessionType, ISessionManager> getSessionManager;
|
||||||
|
|
||||||
private float animationTime = 0f;
|
private float animationTime = 0f;
|
||||||
private List<MapInfo> mapInfo;
|
private List<MapInfo> mapInfo;
|
||||||
private List<MapCellInfo> mapDataLookup = new List<MapCellInfo>();
|
private List<MapCellInfo> mapDataLookup = new List<MapCellInfo>();
|
||||||
|
private ISessionManager sessionManager;
|
||||||
// TODO: Break this out further so we can support multiple maps---------------------------------------------
|
|
||||||
//private MPQDS1 _mapDataTemp, _mapDataTemp2;
|
|
||||||
//private Dictionary<Guid, List<MapCellInfo>> mapDataLookup = new Dictionary<Guid, List<MapCellInfo>>();
|
|
||||||
//private Dictionary<Guid, List<MapCellInfo>> mapDataLookup2 = new Dictionary<Guid, List<MapCellInfo>>();
|
|
||||||
// ---------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
public int Act { get; private set; }
|
public int Act { get; private set; }
|
||||||
public string MapName { get; private set; }
|
public string MapName { get; private set; }
|
||||||
@ -45,57 +41,31 @@ namespace OpenDiablo2.Core.GameState_
|
|||||||
IPaletteProvider paletteProvider,
|
IPaletteProvider paletteProvider,
|
||||||
IEngineDataManager engineDataManager,
|
IEngineDataManager engineDataManager,
|
||||||
IRenderWindow renderWindow,
|
IRenderWindow renderWindow,
|
||||||
Func<IMapEngine> getMapEngine
|
Func<IMapEngine> getMapEngine,
|
||||||
|
Func<eSessionType, ISessionManager> getSessionManager
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.sceneManager = sceneManager;
|
this.sceneManager = sceneManager;
|
||||||
this.resourceManager = resourceManager;
|
this.resourceManager = resourceManager;
|
||||||
this.paletteProvider = paletteProvider;
|
this.paletteProvider = paletteProvider;
|
||||||
this.getMapEngine = getMapEngine;
|
this.getMapEngine = getMapEngine;
|
||||||
|
this.getSessionManager = getSessionManager;
|
||||||
this.engineDataManager = engineDataManager;
|
this.engineDataManager = engineDataManager;
|
||||||
this.renderWindow = renderWindow;
|
this.renderWindow = renderWindow;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize(string characterName, eHero hero)
|
public void Initialize(string characterName, eHero hero, eSessionType sessionType)
|
||||||
{
|
{
|
||||||
|
sessionManager = getSessionManager(sessionType);
|
||||||
|
sessionManager.Initialize();
|
||||||
|
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
Seed = random.Next();
|
Seed = random.Next(); // TODO: Seed does not go here ;-(
|
||||||
|
|
||||||
sceneManager.ChangeScene("Game");
|
sceneManager.ChangeScene("Game");
|
||||||
|
|
||||||
// Initialize our first village
|
|
||||||
// TODO: Loading may make this 'fun'..
|
|
||||||
mapInfo = new List<MapInfo>();
|
mapInfo = new List<MapInfo>();
|
||||||
|
|
||||||
(new MapGenerator(this)).Generate();
|
(new MapGenerator(this)).Generate();
|
||||||
|
|
||||||
// TODO: We need a map generator here...
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
// TODO: TEMP CODE AHEAD!
|
|
||||||
var transId = nw ? 3 : 2;
|
|
||||||
var level = engineDataManager.LevelPresets.First(x => x.Def == (int)transId);
|
|
||||||
var levelDetails = engineDataManager.LevelDetails.First(x => x.Id == level.LevelId);
|
|
||||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelDetails.LevelType);
|
|
||||||
|
|
||||||
// Some maps have variations, so lets pick a random one
|
|
||||||
var mapNames = new List<string>();
|
|
||||||
if (level.File1 != "0") mapNames.Add(level.File1);
|
|
||||||
if (level.File2 != "0") mapNames.Add(level.File2);
|
|
||||||
if (level.File3 != "0") mapNames.Add(level.File3);
|
|
||||||
if (level.File4 != "0") mapNames.Add(level.File4);
|
|
||||||
if (level.File5 != "0") mapNames.Add(level.File5);
|
|
||||||
if (level.File6 != "0") mapNames.Add(level.File6);
|
|
||||||
|
|
||||||
|
|
||||||
var random = new Random(Seed);
|
|
||||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
|
||||||
_mapDataTemp2 = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
<Compile Include="MPQProvider.cs" />
|
<Compile Include="MPQProvider.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ResourceManager.cs" />
|
<Compile Include="ResourceManager.cs" />
|
||||||
|
<Compile Include="SessionServer.cs" />
|
||||||
<Compile Include="TextDictionary.cs" />
|
<Compile Include="TextDictionary.cs" />
|
||||||
<Compile Include="UI\Button.cs" />
|
<Compile Include="UI\Button.cs" />
|
||||||
<Compile Include="UI\PanelFrame.cs" />
|
<Compile Include="UI\PanelFrame.cs" />
|
||||||
|
18
OpenDiablo2.Core/SessionServer.cs
Normal file
18
OpenDiablo2.Core/SessionServer.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using OpenDiablo2.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace OpenDiablo2.Core
|
||||||
|
{
|
||||||
|
public sealed class SessionServer : ISessionServer
|
||||||
|
{
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using OpenDiablo2.Common.Interfaces;
|
using OpenDiablo2.Common.Interfaces;
|
||||||
|
using SDL2;
|
||||||
|
|
||||||
namespace OpenDiablo2.SDL2_
|
namespace OpenDiablo2.SDL2_
|
||||||
{
|
{
|
||||||
public sealed class SDL2MouseCursor : IMouseCursor
|
public sealed class SDL2MouseCursor : IMouseCursor
|
||||||
{
|
{
|
||||||
public IntPtr Surface { get; set; }
|
public IntPtr HWSurface { get; set; }
|
||||||
|
public IntPtr SWTexture { get; set; }
|
||||||
|
public Size ImageSize { get; set; }
|
||||||
|
public Point Hotspot { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,19 @@ namespace OpenDiablo2.SDL2_
|
|||||||
|
|
||||||
public OnKeyPressed KeyPressCallback { get; set; }
|
public OnKeyPressed KeyPressCallback { get; set; }
|
||||||
|
|
||||||
|
private IMouseCursor mouseCursor = null;
|
||||||
|
public IMouseCursor MouseCursor
|
||||||
|
{
|
||||||
|
get => mouseCursor;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (mouseCursor == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetCursor(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IMPQProvider mpqProvider;
|
private readonly IMPQProvider mpqProvider;
|
||||||
private readonly IPaletteProvider paletteProvider;
|
private readonly IPaletteProvider paletteProvider;
|
||||||
private readonly IResourceManager resourceManager;
|
private readonly IResourceManager resourceManager;
|
||||||
@ -96,8 +109,33 @@ namespace OpenDiablo2.SDL2_
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Sync()
|
public unsafe void Sync()
|
||||||
{
|
{
|
||||||
|
if (globalConfig.MouseMode == eMouseMode.Software)
|
||||||
|
{
|
||||||
|
var cursor = mouseCursor as SDL2MouseCursor;
|
||||||
|
var texture = cursor.SWTexture;
|
||||||
|
|
||||||
|
var srcRect = new SDL.SDL_Rect
|
||||||
|
{
|
||||||
|
x = 0,
|
||||||
|
y = 0,
|
||||||
|
w = cursor.ImageSize.Width,
|
||||||
|
h = cursor.ImageSize.Height
|
||||||
|
};
|
||||||
|
|
||||||
|
var destRect = new SDL.SDL_Rect
|
||||||
|
{
|
||||||
|
x = MouseX - cursor.Hotspot.X,
|
||||||
|
y = MouseY - cursor.Hotspot.Y,
|
||||||
|
w = cursor.ImageSize.Width,
|
||||||
|
h = cursor.ImageSize.Height
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL.SDL_RenderCopy(renderer, texture, ref srcRect, ref destRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SDL.SDL_RenderPresent(renderer);
|
SDL.SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +183,8 @@ namespace OpenDiablo2.SDL2_
|
|||||||
fullscreen = !fullscreen;
|
fullscreen = !fullscreen;
|
||||||
SDL.SDL_SetWindowFullscreen(window, (uint)(fullscreen ? SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0));
|
SDL.SDL_SetWindowFullscreen(window, (uint)(fullscreen ? SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0));
|
||||||
}
|
}
|
||||||
else*/ if (evt.key.keysym.sym == SDL.SDL_Keycode.SDLK_BACKSPACE && KeyPressCallback != null)
|
else*/
|
||||||
|
if (evt.key.keysym.sym == SDL.SDL_Keycode.SDLK_BACKSPACE && KeyPressCallback != null)
|
||||||
KeyPressCallback('\b');
|
KeyPressCallback('\b');
|
||||||
}
|
}
|
||||||
else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT)
|
else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT)
|
||||||
@ -287,8 +326,6 @@ namespace OpenDiablo2.SDL2_
|
|||||||
|
|
||||||
public unsafe MapCellInfo CacheMapCell(MPQDT1Tile mapCell)
|
public unsafe MapCellInfo CacheMapCell(MPQDT1Tile mapCell)
|
||||||
{
|
{
|
||||||
log.Debug($"Caching map cell {mapCell.Id}");
|
|
||||||
|
|
||||||
var minX = mapCell.Blocks.Min(x => x.PositionX);
|
var minX = mapCell.Blocks.Min(x => x.PositionX);
|
||||||
var minY = mapCell.Blocks.Min(x => x.PositionY);
|
var minY = mapCell.Blocks.Min(x => x.PositionY);
|
||||||
var maxX = mapCell.Blocks.Max(x => x.PositionX + 32);
|
var maxX = mapCell.Blocks.Max(x => x.PositionX + 32);
|
||||||
@ -379,34 +416,55 @@ namespace OpenDiablo2.SDL2_
|
|||||||
|
|
||||||
public unsafe IMouseCursor LoadCursor(ISprite sprite, int frame, Point hotspot)
|
public unsafe IMouseCursor LoadCursor(ISprite sprite, int frame, Point hotspot)
|
||||||
{
|
{
|
||||||
if (globalConfig.MouseMode != eMouseMode.Hardware)
|
if (globalConfig.MouseMode == eMouseMode.Software)
|
||||||
throw new ApplicationException("Tried to set a hardware cursor, but we are using software cursors!");
|
{
|
||||||
|
sprite.Frame = frame;
|
||||||
|
|
||||||
|
var texId = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888,
|
||||||
|
(int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, sprite.LocalFrameSize.Width, sprite.LocalFrameSize.Height);
|
||||||
|
SDL.SDL_SetTextureBlendMode(texId, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
SDL.SDL_SetRenderTarget(renderer, texId);
|
||||||
|
SDL.SDL_RenderCopy(renderer, (sprite as SDL2Sprite).texture, IntPtr.Zero, IntPtr.Zero);
|
||||||
|
SDL.SDL_SetRenderTarget(renderer, IntPtr.Zero);
|
||||||
|
|
||||||
|
return new SDL2MouseCursor
|
||||||
|
{
|
||||||
|
Hotspot = hotspot,
|
||||||
|
ImageSize = sprite.LocalFrameSize,
|
||||||
|
SWTexture = texId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var multiple = globalConfig.HardwareMouseScale;
|
var multiple = globalConfig.HardwareMouseScale;
|
||||||
var spr = sprite as SDL2Sprite;
|
var spr = sprite as SDL2Sprite;
|
||||||
var surface = SDL.SDL_CreateRGBSurface(0, spr.FrameSize.Width * multiple, spr.FrameSize.Height * multiple, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
|
var surface = SDL.SDL_CreateRGBSurface(0, spr.LocalFrameSize.Width * multiple, spr.LocalFrameSize.Height * multiple, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
|
||||||
|
var yOffset = (spr.FrameSize.Height - spr.LocalFrameSize.Height);
|
||||||
|
var XOffset = (spr.FrameSize.Width - spr.LocalFrameSize.Width);
|
||||||
var pixels = (UInt32*)((SDL.SDL_Surface*)surface)->pixels;
|
var pixels = (UInt32*)((SDL.SDL_Surface*)surface)->pixels;
|
||||||
for (var y = 0; y < (spr.FrameSize.Height * multiple) - 1; y++)
|
for (var y = 0; y < (spr.LocalFrameSize.Height * multiple) - 1; y++)
|
||||||
for (var x = 0; x < (spr.FrameSize.Width * multiple) - 1; x++)
|
for (var x = 0; x < (spr.LocalFrameSize.Width * multiple) - 1; x++)
|
||||||
{
|
{
|
||||||
pixels[x + (y * spr.FrameSize.Width * multiple)] = spr.source.Frames[frame].GetColor(x / multiple, y / multiple, sprite.CurrentPalette);
|
pixels[x + XOffset + ((y + yOffset) * spr.LocalFrameSize.Width * multiple)] = spr.source.Frames[frame].GetColor(x / multiple, y / multiple, sprite.CurrentPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cursor = SDL.SDL_CreateColorCursor(surface, hotspot.X, hotspot.Y);
|
var cursor = SDL.SDL_CreateColorCursor(surface, hotspot.X * multiple, hotspot.Y * multiple);
|
||||||
if (cursor == IntPtr.Zero)
|
if (cursor == IntPtr.Zero)
|
||||||
throw new ApplicationException($"Unable to set the cursor cursor: {SDL.SDL_GetError()}"); // TODO: Is this supported everywhere? May need to still support software cursors.
|
throw new ApplicationException($"Unable to set the cursor cursor: {SDL.SDL_GetError()}"); // TODO: Is this supported everywhere? May need to still support software cursors.
|
||||||
return new SDL2MouseCursor { Surface = cursor };
|
return new SDL2MouseCursor { HWSurface = cursor };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCursor(IMouseCursor mouseCursor)
|
private void SetCursor(IMouseCursor mouseCursor)
|
||||||
{
|
{
|
||||||
if (globalConfig.MouseMode != eMouseMode.Hardware)
|
this.mouseCursor = mouseCursor;
|
||||||
throw new ApplicationException("Tried to set a hardware cursor, but we are using software cursors!");
|
|
||||||
|
|
||||||
SDL.SDL_SetCursor((mouseCursor as SDL2MouseCursor).Surface);
|
if (globalConfig.MouseMode != eMouseMode.Hardware)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SDL.SDL_SetCursor((mouseCursor as SDL2MouseCursor).HWSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint GetTicks() => SDL.SDL_GetTicks();
|
public uint GetTicks() => SDL.SDL_GetTicks();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,8 @@ namespace OpenDiablo2.Scenes
|
|||||||
|
|
||||||
private void OnOkclicked()
|
private void OnOkclicked()
|
||||||
{
|
{
|
||||||
gameState.Initialize(characterNameTextBox.Text, selectedHero.Value);
|
// TODO: Support other session types
|
||||||
|
gameState.Initialize(characterNameTextBox.Text, selectedHero.Value, eSessionType.Local);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExitClicked()
|
private void OnExitClicked()
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using Autofac;
|
using System;
|
||||||
|
using Autofac;
|
||||||
|
using OpenDiablo2.Common.Enums;
|
||||||
|
using OpenDiablo2.Common.Interfaces;
|
||||||
|
|
||||||
namespace OpenDiablo2.ServiceBus
|
namespace OpenDiablo2.ServiceBus
|
||||||
{
|
{
|
||||||
@ -6,7 +9,24 @@ namespace OpenDiablo2.ServiceBus
|
|||||||
{
|
{
|
||||||
protected override void Load(ContainerBuilder builder)
|
protected override void Load(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
|
builder.RegisterType<LocalSessionManager>().AsSelf().InstancePerLifetimeScope();
|
||||||
|
|
||||||
|
builder.Register<Func<eSessionType, ISessionManager>>(c =>
|
||||||
|
{
|
||||||
|
var componentContext = c.Resolve<IComponentContext>();
|
||||||
|
return (sessionType) =>
|
||||||
|
{
|
||||||
|
switch (sessionType)
|
||||||
|
{
|
||||||
|
case eSessionType.Local:
|
||||||
|
return componentContext.Resolve<LocalSessionManager>();
|
||||||
|
case eSessionType.Server:
|
||||||
|
case eSessionType.Remote:
|
||||||
|
default:
|
||||||
|
throw new ApplicationException("Unsupported session type.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
OpenDiablo2.ServiceBus/LocalSessionManager.cs
Normal file
47
OpenDiablo2.ServiceBus/LocalSessionManager.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using OpenDiablo2.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace OpenDiablo2.ServiceBus
|
||||||
|
{
|
||||||
|
public sealed class LocalSessionManager : ISessionManager
|
||||||
|
{
|
||||||
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private readonly ISessionServer sessionServer;
|
||||||
|
volatile bool running = false;
|
||||||
|
|
||||||
|
public LocalSessionManager(ISessionServer sessionServer)
|
||||||
|
{
|
||||||
|
this.sessionServer = sessionServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
log.Info("Initializing a local multiplayer session.");
|
||||||
|
running = true;
|
||||||
|
Task.Run(() => Listen());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Listen()
|
||||||
|
{
|
||||||
|
log.Info("Local session manager is starting.");
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Local session manager has stopped.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop() => running = false;
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AutofacModule.cs" />
|
<Compile Include="AutofacModule.cs" />
|
||||||
|
<Compile Include="LocalSessionManager.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user