Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": ".NET Meteor Debugger",
"type": "dotnet-meteor.debugger",
"request": "launch",
"preLaunchTask": "dotnet-meteor: Build"
}
]
}
50 changes: 50 additions & 0 deletions ManagedDoom.Maui/Game/AggregatedUserInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using ManagedDoom.UserInput;

namespace ManagedDoom.Maui.Game;

public class AggregatedUserInput : IUserInput
{
private readonly IReadOnlyList<IUserInput> _userInputs;

public AggregatedUserInput(IReadOnlyList<IUserInput> userInputs)
{
_userInputs = userInputs;
}

public void BuildTicCmd(TicCmd cmd)
{
cmd.Clear();

foreach (var userInput in _userInputs)
{
userInput.BuildTicCmd(cmd);
}
}

public void Reset()
{
foreach (var userInput in _userInputs)
{
userInput.Reset();
}
}

public void GrabMouse()
{
foreach (var userInput in _userInputs)
{
userInput.GrabMouse();
}
}

public void ReleaseMouse()
{
foreach (var userInput in _userInputs)
{
userInput.ReleaseMouse();
}
}

public int MaxMouseSensitivity { get; }
public int MouseSensitivity { get; set; }
}
76 changes: 76 additions & 0 deletions ManagedDoom.Maui/Game/GameControllerUserInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using ManagedDoom.UserInput;
using Orbit.Input;

namespace ManagedDoom.Maui.Game;

public class GameControllerUserInput : IUserInput
{
private Orbit.Input.GameController? _gameController;
private int _currentIndex;

public GameControllerUserInput()
{
GameControllerManager.Current.GameControllerConnected += OnGameControllerConnected;
_ = GameControllerManager.Current.StartDiscovery();
}

private void OnGameControllerConnected(object? sender, GameControllerConnectedEventArgs args)
{
_gameController = args.GameController;

_gameController.ButtonChanged += (o, eventArgs) =>
{
if (eventArgs.ButtonName == _gameController.North.Name &&
eventArgs.IsPressed)
{
_currentIndex = (_currentIndex + TicCmdButtons.WeaponShift) % (7 * TicCmdButtons.WeaponShift);
}
};
}

public void BuildTicCmd(TicCmd cmd)
{
if (_gameController is null)
{
return;
}

if (_gameController.RightShoulder.Trigger.Value > 0)
{
cmd.Buttons |= TicCmdButtons.Attack;
}

if (_gameController.South.Value)
{
cmd.Buttons |= TicCmdButtons.Use;
}

if (_gameController.North.Value)
{
cmd.Buttons |= TicCmdButtons.Change;
cmd.Buttons |= (byte)_currentIndex;
}

cmd.AngleTurn -= (short)(_gameController.RightStick.XAxis.Value * 0x150);
cmd.ForwardMove += (sbyte)(_gameController.LeftStick.YAxis.Value * 0x8);
cmd.SideMove += (sbyte)(_gameController.LeftStick.XAxis.Value * 0x8);
}

public void Reset()
{

}

public void GrabMouse()
{

}

public void ReleaseMouse()
{

}

public int MaxMouseSensitivity { get; }
public int MouseSensitivity { get; set; }
}
16 changes: 11 additions & 5 deletions ManagedDoom.Maui/Game/MauiDoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class MauiDoom : MauiGame
private MauiSound _sound;
private MauiVideo _video;
private MauiUserInput _input;
private GameControllerUserInput _gameController;

private CommandLineArgs args;
private Config _config;
Expand Down Expand Up @@ -89,8 +90,6 @@ bool OnUiCommand(UiCommand command)
/// </summary>
protected override void Paint(DrawingContext ctx)
{
// base.Paint(ctx); - will not draw background color/gradient in this case

frameCount++;

//we draw the game every frame but sending the frameFrac 0 or 1 to interpolate updates
Expand Down Expand Up @@ -120,7 +119,6 @@ protected override void Paint(DrawingContext ctx)
}



/// <summary>
/// Setup everything
/// </summary>
Expand Down Expand Up @@ -157,8 +155,16 @@ void Init(DrawingContext context)
}

_input = new MauiUserInput(_config, !args.nomouse.Present, OnUiCommand);

_doom = new Doom(args, _config, _content, _video, _sound, _music, _input);
_gameController = new GameControllerUserInput();

_doom = new Doom(
args,
_config,
_content,
_video,
_sound,
_music,
new AggregatedUserInput([_input, _gameController]));

_input.Attach(_doom);

Expand Down
27 changes: 12 additions & 15 deletions ManagedDoom.Maui/Game/MauiGame.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using DrawnUi.Maui.Draw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Orbit.Input;
using KeyboardManager = Orbit.Input.KeyboardManager;

namespace DrawnUi.Maui.Game
{
Expand All @@ -30,14 +27,14 @@ public class MauiGame : SkiaLayout, IMauiGame

public MauiGame()
{
KeyboardManager.KeyDown += OnKeyboardDownEvent;
KeyboardManager.KeyUp += OnKeyboardUpEvent;
KeyboardManager.Current.KeyDown += OnKeyboardDownEvent;
KeyboardManager.Current.KeyUp += OnKeyboardUpEvent;
}

public override void OnDisposing()
{
KeyboardManager.KeyUp -= OnKeyboardUpEvent;
KeyboardManager.KeyDown -= OnKeyboardDownEvent;
KeyboardManager.Current.KeyDown -= OnKeyboardUpEvent;
KeyboardManager.Current.KeyUp -= OnKeyboardDownEvent;

base.OnDisposing();
}
Expand Down Expand Up @@ -149,20 +146,20 @@ public virtual void OnKeyUp(MauiKey key)
/// Do not use directly. It's public to be able to send keys to game manually if needed.
/// </summary>
/// <param name="sender"></param>
/// <param name="key"></param>
public void OnKeyboardDownEvent(object sender, MauiKey key)
/// <param name="eventArgs"></param>
public void OnKeyboardDownEvent(object sender, KeyboardKeyChangeEventArgs eventArgs)
{
OnKeyDown(key);
OnKeyDown((MauiKey)eventArgs.Key); // TODO: We don't need both?
}

/// <summary>
/// Do not use directly. It's public to be able to send keys to game manually if needed.
/// </summary>
/// <param name="sender"></param>
/// <param name="key"></param>
public void OnKeyboardUpEvent(object sender, MauiKey key)
/// <param name="eventArgs"></param>
public void OnKeyboardUpEvent(object sender, KeyboardKeyChangeEventArgs eventArgs)
{
OnKeyUp(key);
OnKeyUp((MauiKey)eventArgs.Key);// TODO: We don't need both?
}


Expand Down
2 changes: 0 additions & 2 deletions ManagedDoom.Maui/Game/MauiUserInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ public void BuildTicCmd(TicCmd cmd)
weaponKeys[5] = IsPressed(DoomKey.Num6);
weaponKeys[6] = IsPressed(DoomKey.Num7);

cmd.Clear();

var strafe = keyStrafe;
var speed = keyRun ? 1 : 0;
var forward = 0;
Expand Down
1 change: 1 addition & 0 deletions ManagedDoom.Maui/Game/MauiVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public MauiVideo(

public void Render(SKCanvas canvas, SKRect destination, Doom doom, Fixed frameFrac)
{
//if you have problems with System.Threadig.Tasks.Parellel
if (DeviceInfo.Platform == DevicePlatform.iOS && DeviceInfo.DeviceType == DeviceType.Physical)
{
DrawScreen.Optimize = false;
Expand Down
3 changes: 1 addition & 2 deletions ManagedDoom.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ public MainPage()
#if IOS
Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.SetPrefersHomeIndicatorAutoHidden(this, true);
#endif

}
catch (Exception e)
{
Super.DisplayException(this, e);
}
}


}
}
5 changes: 3 additions & 2 deletions ManagedDoom.Maui/ManagedDoom.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ApplicationTitle>DOOM</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.mauigame.doom</ApplicationId>
<ApplicationId>com.tinysoft.doom</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
Expand Down Expand Up @@ -65,7 +65,8 @@
<ItemGroup>
<!--can replace this with usual plugin if PR is merged-->
<PackageReference Include="AppoMobi.Preview.Plugin.Maui.Audio" Version="3.0.2.1-pre1" />
<PackageReference Include="AppoMobi.Maui.DrawnUi" Version="1.4.0.1" />
<PackageReference Include="AppoMobi.Maui.DrawnUi" Version="1.4.0.1" />
<PackageReference Include="Bijington.Orbit.Input" Version="0.2.0-preview1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.22" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions ManagedDoom.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//#define DEBUG_MOBILE
using DrawnUi.Maui.Draw;
using Microsoft.Extensions.Logging;
using Orbit.Input;
using Plugin.Maui.Audio;

namespace ManagedDoom.Maui
Expand Down Expand Up @@ -31,10 +32,10 @@ public static MauiApp CreateMauiApp()
builder
.UseMauiApp<App>()
.AddAudio()
.UseOrbitInput()
#if DEBUG_MOBILE //don't need this to compile, it's for development to simulate mobile screen on desktop
.UseDrawnUi(new()
{
UseDesktopKeyboard = true,
DesktopWindow = new()
{
Width = 400,
Expand All @@ -46,7 +47,6 @@ public static MauiApp CreateMauiApp()
#else
.UseDrawnUi(new()
{
UseDesktopKeyboard = true,
MobileIsFullscreen = true,
DesktopWindow = new()
{
Expand Down
30 changes: 29 additions & 1 deletion ManagedDoom.Maui/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
using Foundation;
using System.Diagnostics;
using Foundation;
using Orbit.Input;
using UIKit;

namespace ManagedDoom.Maui
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

public override void PressesBegan(NSSet<UIPress> presses, UIPressesEvent evt)
{
KeyboardManager.Current.PressesBegan(presses, evt);
//base.PressesBegan(presses, evt);
}

public override void PressesCancelled(NSSet<UIPress> presses, UIPressesEvent evt)
{
Trace.WriteLine(@"PressesCancelled");
//KeyboardManager.Current.PressesCancelled(presses, evt);
//base.PressesCancelled(presses, evt);
}

public override void PressesChanged(NSSet<UIPress> presses, UIPressesEvent evt)
{
Trace.WriteLine(@"PressesChanged");
//base.PressesChanged(presses, evt);
}

public override void PressesEnded(NSSet<UIPress> presses, UIPressesEvent evt)
{
KeyboardManager.Current.PressesEnded(presses, evt);
//base.PressesEnded(presses, evt);
}
}
}
2 changes: 1 addition & 1 deletion ManagedDoom.Shared/ManagedDoom.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down