mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e00170f45 | ||
|
|
261ee96cad | ||
|
|
2c851885db | ||
|
|
849be86455 | ||
|
|
ffd5c120be | ||
|
|
76b15dda70 | ||
|
|
0bf7f519ad | ||
|
|
f97f325a36 | ||
|
|
24315fa787 | ||
|
|
792179657b | ||
|
|
9b92bcf911 | ||
|
|
86e34ea27b | ||
|
|
62cf778958 | ||
|
|
5d667e44c3 | ||
|
|
6d84b8741c | ||
|
|
d08ca59b75 | ||
|
|
f06b046c1c | ||
|
|
bb412a6906 | ||
|
|
1baee3004c | ||
|
|
f18068c13a | ||
|
|
0ba00a1845 | ||
|
|
28caf0d74c | ||
|
|
ecbb32b70b | ||
|
|
8e2a9cc597 | ||
|
|
a7eb8201c9 | ||
|
|
1f95fe6782 | ||
|
|
07c1f9e1af | ||
|
|
826dce6659 | ||
|
|
cdf714f3ba | ||
|
|
671ca7959c | ||
|
|
b7a1345d3a | ||
|
|
835b6ebdba | ||
|
|
0ecabd6553 | ||
|
|
feaa69f825 | ||
|
|
857904a3d9 | ||
|
|
0b37418477 |
@@ -1,24 +1,63 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<PropertyGroup>
|
||||
<RobustUseExternalMSBuild>true</RobustUseExternalMSBuild>
|
||||
<_RobustUseExternalMSBuild>$(RobustUseExternalMSBuild)</_RobustUseExternalMSBuild>
|
||||
<_RobustUseExternalMSBuild Condition="'$(_RobustForceInternalMSBuild)' == 'true'">false</_RobustUseExternalMSBuild>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="**\*.xaml.cs">
|
||||
<DependentUpon>%(Filename)</DependentUpon>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="**\*.xaml" />
|
||||
<AdditionalFiles Include="**\*.xaml" />
|
||||
<EmbeddedResource Include="**\*.xaml"/>
|
||||
<AdditionalFiles Include="**\*.xaml"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\Robust.Client.NameGenerator\Robust.Client.NameGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\Robust.Client.Injectors\Robust.Client.Injectors.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\Robust.Client.NameGenerator\Robust.Client.NameGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\Robust.Client.Injectors\Robust.Client.Injectors.csproj" ReferenceOutputAssembly="false"/>
|
||||
</ItemGroup>
|
||||
|
||||
<UsingTask TaskName="CompileRobustXamlTask" AssemblyFile="$(MSBuildThisFileDirectory)\..\Robust.Client.Injectors\bin\$(Configuration)\net5.0\Robust.Client.Injectors.dll" />
|
||||
<Target Name="CompileRobustXaml" AfterTargets="AfterCompile">
|
||||
<UsingTask
|
||||
Condition="'$(_RobustUseExternalMSBuild)' != 'true' And $(DesignTimeBuild) != true"
|
||||
TaskName="CompileRobustXamlTask"
|
||||
AssemblyFile="$(MSBuildThisFileDirectory)\..\Robust.Client.Injectors\bin\$(Configuration)\netstandard2.0\Robust.Client.Injectors.dll"/>
|
||||
<Target
|
||||
Name="CompileRobustXaml"
|
||||
Condition="Exists('@(IntermediateAssembly)')"
|
||||
AfterTargets="AfterCompile"
|
||||
Inputs="@(IntermediateAssembly);@(ReferencePathWithRefAssemblies)"
|
||||
Outputs="$(IntermediateOutputPath)XAML/doot">
|
||||
<PropertyGroup>
|
||||
<RobustXamlReferencesTemporaryFilePath Condition="'$(RobustXamlReferencesTemporaryFilePath)' == ''">$(IntermediateOutputPath)XAML/references</RobustXamlReferencesTemporaryFilePath>
|
||||
<RobustXamlOriginalCopyFilePath Condition="'$(RobustXamlOriginalCopyFilePath)' == ''">$(IntermediateOutputPath)XAML/original.dll</RobustXamlOriginalCopyFilePath>
|
||||
</PropertyGroup>
|
||||
<WriteLinesToFile File="$(RobustXamlReferencesTemporaryFilePath)" Lines="@(ReferencePathWithRefAssemblies)" Overwrite="true" />
|
||||
<CompileRobustXamlTask AssemblyFile="@(IntermediateAssembly)" ReferencesFilePath="$(RobustXamlReferencesTemporaryFilePath)" OriginalCopyPath="$(RobustXamlOriginalCopyFilePath)" ProjectDirectory="$(MSBuildProjectDirectory)" AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)" SignAssembly="$(SignAssembly)" DelaySign="$(DelaySign)" />
|
||||
<WriteLinesToFile
|
||||
Condition="'$(_RobustForceInternalMSBuild)' != 'true'"
|
||||
File="$(RobustXamlReferencesTemporaryFilePath)"
|
||||
Lines="@(ReferencePathWithRefAssemblies)"
|
||||
Overwrite="true"/>
|
||||
|
||||
<!--
|
||||
UpdateBuildIndicator is done so that we can use MSBuild Inputs and Outputs on the target
|
||||
to avoid unecessary execution of this target
|
||||
Saves compile time if e.g. ONLY Robust.Client changes (Content.Client doesn't have to re-xaml).
|
||||
-->
|
||||
<CompileRobustXamlTask
|
||||
Condition="'$(_RobustUseExternalMSBuild)' != 'true'"
|
||||
AssemblyFile="@(IntermediateAssembly)"
|
||||
ReferencesFilePath="$(RobustXamlReferencesTemporaryFilePath)"
|
||||
OriginalCopyPath="$(RobustXamlOriginalCopyFilePath)"
|
||||
ProjectDirectory="$(MSBuildProjectDirectory)"
|
||||
AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)"
|
||||
SignAssembly="$(SignAssembly)"
|
||||
DelaySign="$(DelaySign)"
|
||||
UpdateBuildIndicator="$(IntermediateOutputPath)XAML/doot"/>
|
||||
|
||||
<PropertyGroup>
|
||||
<DOTNET_HOST_PATH Condition="'$(DOTNET_HOST_PATH)' == ''">dotnet</DOTNET_HOST_PATH>
|
||||
</PropertyGroup>
|
||||
<Exec
|
||||
Condition="'$(_RobustUseExternalMSBuild)' == 'true'"
|
||||
Command=""$(DOTNET_HOST_PATH)" msbuild /nodereuse:false $(MSBuildProjectFile) /t:CompileRobustXaml /p:_RobustForceInternalMSBuild=true /p:Configuration=$(Configuration) /p:RuntimeIdentifier=$(RuntimeIdentifier) /p:TargetFramework=$(TargetFramework) /p:BuildProjectReferences=false"/>
|
||||
</Target>
|
||||
</Project>
|
||||
|
||||
Submodule NetSerializer updated: 60d23c01f9...1e103e8e29
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
@@ -48,6 +49,19 @@ namespace Robust.Build.Tasks
|
||||
if(File.Exists(inputPdb))
|
||||
File.Copy(inputPdb, outputPdb, true);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(UpdateBuildIndicator))
|
||||
{
|
||||
if (!File.Exists(UpdateBuildIndicator))
|
||||
{
|
||||
File.Create(UpdateBuildIndicator).Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
File.SetLastWriteTime(UpdateBuildIndicator, DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -64,6 +78,7 @@ namespace Robust.Build.Tasks
|
||||
public string OriginalCopyPath { get; set; }
|
||||
|
||||
public string OutputPath { get; set; }
|
||||
public string UpdateBuildIndicator { get; set; }
|
||||
|
||||
public string AssemblyOriginatorKeyFile { get; set; }
|
||||
public bool SignAssembly { get; set; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -31,6 +31,16 @@ namespace Robust.Build.Tasks
|
||||
|
||||
var asm = typeSystem.TargetAssemblyDefinition;
|
||||
|
||||
if (asm.MainModule.GetType("CompiledRobustXaml", "XamlIlContext") != null)
|
||||
{
|
||||
// If this type exists, the assembly has already been processed by us.
|
||||
// Do not run again, it would corrupt the file.
|
||||
// This *shouldn't* be possible due to Inputs/Outputs dependencies in the build system,
|
||||
// but better safe than sorry eh?
|
||||
engine.LogWarningEvent(new BuildWarningEventArgs("XAMLIL", "", "", 0, 0, 0, 0, "Ran twice on same assembly file; ignoring.", "", ""));
|
||||
return (true, false);
|
||||
}
|
||||
|
||||
var compileRes = CompileCore(engine, typeSystem);
|
||||
if (compileRes == null)
|
||||
return (true, false);
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-3.final" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Robust.Client.Audio.Midi
|
||||
private const string OsxSoundfont =
|
||||
"/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls";
|
||||
|
||||
private const string FallbackSoundfont = "/Resources/Midi/fallback.sf2";
|
||||
private const string FallbackSoundfont = "/Midi/fallback.sf2";
|
||||
|
||||
private readonly ResourceLoaderCallbacks _soundfontLoaderCallbacks = new();
|
||||
|
||||
@@ -207,13 +207,10 @@ namespace Robust.Client.Audio.Midi
|
||||
|
||||
var renderer = new MidiRenderer(_settings!, soundfontLoader);
|
||||
|
||||
foreach (var file in _resourceManager.ContentFindFiles(new ResourcePath("/Audio/MidiCustom/")))
|
||||
foreach (var file in _resourceManager.ContentFindFiles(("/Audio/MidiCustom/")))
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls") continue;
|
||||
if (_resourceManager.TryGetDiskFilePath(file, out var path))
|
||||
{
|
||||
renderer.LoadSoundfont(path);
|
||||
}
|
||||
renderer.LoadSoundfont(file.ToString());
|
||||
}
|
||||
|
||||
// Since the last loaded soundfont takes priority, we load the fallback soundfont before the soundfont.
|
||||
@@ -382,10 +379,18 @@ namespace Robust.Client.Audio.Midi
|
||||
|
||||
public override IntPtr Open(string filename)
|
||||
{
|
||||
Stream? stream;
|
||||
if (filename.StartsWith("/Resources/"))
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
if (!IoCManager.Resolve<IResourceCache>().TryContentFileRead(filename.Substring(10), out stream))
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
Stream? stream;
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
var resourcePath = new ResourcePath(filename);
|
||||
|
||||
if (resourcePath.IsRooted && resourceCache.ContentFileExists(filename))
|
||||
{
|
||||
if (!resourceCache.TryContentFileRead(filename, out stream))
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
else if (File.Exists(filename))
|
||||
|
||||
72
Robust.Client/Console/Commands/AddCompCommand.cs
Normal file
72
Robust.Client/Console/Commands/AddCompCommand.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Interfaces.Console;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class AddCompCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "addcompc";
|
||||
public string Description => "Adds a component to an entity on the client";
|
||||
public string Help => "addcompc <uid> <componentName>";
|
||||
|
||||
public bool Execute(IDebugConsole shell, params string[] args)
|
||||
{
|
||||
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.AddLine("Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
var entityUid = EntityUid.Parse(args[0]);
|
||||
var componentName = args[1];
|
||||
|
||||
var compManager = IoCManager.Resolve<IComponentManager>();
|
||||
var compFactory = IoCManager.Resolve<IComponentFactory>();
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var entity = entityManager.GetEntity(entityUid);
|
||||
var component = (Component) compFactory.GetComponent(componentName);
|
||||
|
||||
component.Owner = entity;
|
||||
|
||||
compManager.AddComponent(entity, component);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
internal sealed class RemoveCompCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "rmcompc";
|
||||
public string Description => "Removes a component from an entity.";
|
||||
public string Help => "rmcompc <uid> <componentName>";
|
||||
|
||||
public bool Execute(IDebugConsole shell, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.AddLine("Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
var entityUid = EntityUid.Parse(args[0]);
|
||||
var componentName = args[1];
|
||||
|
||||
var compManager = IoCManager.Resolve<IComponentManager>();
|
||||
var compFactory = IoCManager.Resolve<IComponentFactory>();
|
||||
|
||||
var registration = compFactory.GetRegistration(componentName);
|
||||
|
||||
compManager.RemoveComponent(entityUid, registration.Type);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -781,6 +781,21 @@ namespace Robust.Client.Console.Commands
|
||||
}
|
||||
}
|
||||
|
||||
internal class GcFullCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "gcf";
|
||||
public string Description => "Run the GC, fully, compacting LOH and everything.";
|
||||
public string Help => "gcf";
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
|
||||
GC.Collect(2, GCCollectionMode.Forced, true, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal class GcModeCommand : IConsoleCommand
|
||||
{
|
||||
|
||||
|
||||
69
Robust.Client/Console/Commands/LauncherAuthCommand.cs
Normal file
69
Robust.Client/Console/Commands/LauncherAuthCommand.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
#if !FULL_RELEASE
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Robust.Client.Interfaces.Console;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
internal sealed class LauncherAuthCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "launchauth";
|
||||
public string Description => "Load authentication tokens from launcher data to aid in testing of live servers";
|
||||
public string Help => "launchauth [account name]";
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
var wantName = args.Length > 0 ? args[0] : null;
|
||||
|
||||
var basePath = Path.GetDirectoryName(UserDataDir.GetUserDataDir())!;
|
||||
var cfgPath = Path.Combine(basePath, "launcher", "launcher_config.json");
|
||||
|
||||
var data = JsonSerializer.Deserialize<LauncherConfig>(File.ReadAllText(cfgPath))!;
|
||||
|
||||
var login = wantName != null
|
||||
? data.Logins.FirstOrDefault(p => p.Username == wantName)
|
||||
: data.Logins.FirstOrDefault();
|
||||
|
||||
if (login == null)
|
||||
{
|
||||
console.AddLine("Unable to find a matching login");
|
||||
return false;
|
||||
}
|
||||
|
||||
var token = login.Token.Token;
|
||||
var userId = login.UserId;
|
||||
|
||||
var cfg = IoCManager.Resolve<IConfigurationManagerInternal>();
|
||||
cfg.SetSecureCVar(CVars.AuthUserId, userId);
|
||||
cfg.SetSecureCVar(CVars.AuthToken, token);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private sealed class LauncherConfig
|
||||
{
|
||||
[JsonInclude] [JsonPropertyName("logins")]
|
||||
public LauncherLogin[] Logins = default!;
|
||||
}
|
||||
|
||||
private sealed class LauncherLogin
|
||||
{
|
||||
[JsonInclude] public string Username = default!;
|
||||
[JsonInclude] public string UserId = default!;
|
||||
[JsonInclude] public LauncherToken Token = default!;
|
||||
}
|
||||
|
||||
private sealed class LauncherToken
|
||||
{
|
||||
[JsonInclude] public string Token = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
35
Robust.Client/Console/Commands/SetInputContextCommand.cs
Normal file
35
Robust.Client/Console/Commands/SetInputContextCommand.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Interfaces.Console;
|
||||
using Robust.Client.Interfaces.Input;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SetInputContextCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "setinputcontext";
|
||||
public string Description => "Sets the active input context.";
|
||||
public string Help => "setinputcontext <context>";
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
console.AddLine("Invalid number of arguments!");
|
||||
return false;
|
||||
}
|
||||
|
||||
var inputMan = IoCManager.Resolve<IInputManager>();
|
||||
|
||||
if (!inputMan.Contexts.Exists(args[0]))
|
||||
{
|
||||
console.AddLine("Context not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
inputMan.Contexts.SetActiveContext(args[0]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,11 +48,21 @@ namespace Robust.Client.GameObjects.Components.Animations
|
||||
return;
|
||||
}
|
||||
|
||||
List<string>? toRemove = null;
|
||||
// TODO: Get rid of this ToArray() allocation.
|
||||
foreach (var (key, playback) in _playingAnimations.ToArray())
|
||||
{
|
||||
var keep = UpdatePlayback(Owner, playback, frameTime);
|
||||
if (!keep)
|
||||
{
|
||||
toRemove ??= new List<string>();
|
||||
toRemove.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove != null)
|
||||
{
|
||||
foreach (var key in toRemove)
|
||||
{
|
||||
_playingAnimations.Remove(key);
|
||||
AnimationCompleted?.Invoke(key);
|
||||
|
||||
@@ -54,17 +54,17 @@ namespace Robust.Client.GameObjects
|
||||
return (T) data[key];
|
||||
}
|
||||
|
||||
public override bool TryGetData<T>(Enum key, [MaybeNullWhen(false)] out T data)
|
||||
public override bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
return TryGetData(key, out data);
|
||||
}
|
||||
|
||||
public override bool TryGetData<T>(string key, [MaybeNullWhen(false)] out T data)
|
||||
public override bool TryGetData<T>(string key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
return TryGetData(key, out data);
|
||||
}
|
||||
|
||||
internal bool TryGetData<T>(object key, [MaybeNullWhen(false)] out T data)
|
||||
internal bool TryGetData<T>(object key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
if (this.data.TryGetValue(key, out var dat))
|
||||
{
|
||||
@@ -72,7 +72,7 @@ namespace Robust.Client.GameObjects
|
||||
return true;
|
||||
}
|
||||
|
||||
data = default;
|
||||
data = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -991,6 +991,9 @@ namespace Robust.Client.GameObjects
|
||||
var mRotation = Matrix3.CreateRotation(angle);
|
||||
Matrix3.Multiply(ref mRotation, ref mOffset, out var transform);
|
||||
|
||||
// Only apply scale if needed.
|
||||
if(!Scale.EqualsApprox(Vector2.One)) transform.Multiply(Matrix3.CreateScale(Scale));
|
||||
|
||||
transform.Multiply(worldTransform);
|
||||
|
||||
RenderInternal(drawingHandle, worldRotation, overrideDirection, transform);
|
||||
|
||||
@@ -128,7 +128,8 @@ namespace Robust.Client.GameObjects.EntitySystems
|
||||
|
||||
if (!entity.TryGetComponent(out InputComponent? inputComp))
|
||||
{
|
||||
Logger.DebugS("input.context", $"AttachedEnt has no InputComponent: entId={entity.Uid}, entProto={entity.Prototype}");
|
||||
Logger.DebugS("input.context", $"AttachedEnt has no InputComponent: entId={entity.Uid}, entProto={entity.Prototype}. Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +139,8 @@ namespace Robust.Client.GameObjects.EntitySystems
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS("input.context", $"Unknown context: entId={entity.Uid}, entProto={entity.Prototype}, context={inputComp.ContextName}");
|
||||
Logger.ErrorS("input.context", $"Unknown context: entId={entity.Uid}, entProto={entity.Prototype}, context={inputComp.ContextName}. . Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
while (readSamples < totalSamples)
|
||||
{
|
||||
var read = vorbis.ReadSamples(buffer, readSamples * channels, (int)totalSamples - readSamples);
|
||||
var read = vorbis.ReadSamples(buffer, readSamples * channels, buffer.Length - readSamples);
|
||||
if (read == 0)
|
||||
{
|
||||
break;
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
CheckGlError();
|
||||
|
||||
// Check on original format is NOT a bug, this is so srgb emulation works
|
||||
textureObject = GenTexture(texture, size, format.ColorFormat == RTCF.Rgba8Srgb, name == null ? null : $"{name}-color");
|
||||
textureObject = GenTexture(texture, size, format.ColorFormat == RTCF.Rgba8Srgb, name == null ? null : $"{name}-color", TexturePixelType.RenderTarget);
|
||||
}
|
||||
|
||||
// Depth/stencil buffers.
|
||||
|
||||
@@ -11,6 +11,9 @@ using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using OGLTextureWrapMode = OpenToolkit.Graphics.OpenGL.TextureWrapMode;
|
||||
using PIF = OpenToolkit.Graphics.OpenGL4.PixelInternalFormat;
|
||||
using PF = OpenToolkit.Graphics.OpenGL4.PixelFormat;
|
||||
using PT = OpenToolkit.Graphics.OpenGL4.PixelType;
|
||||
|
||||
namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
@@ -20,8 +23,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
private ClydeTexture _stockTextureBlack = default!;
|
||||
private ClydeTexture _stockTextureTransparent = default!;
|
||||
|
||||
private readonly Dictionary<ClydeHandle, LoadedTexture> _loadedTextures =
|
||||
new();
|
||||
private readonly Dictionary<ClydeHandle, LoadedTexture> _loadedTextures = new();
|
||||
|
||||
private readonly ConcurrentQueue<ClydeHandle> _textureDisposeQueue = new();
|
||||
|
||||
@@ -69,85 +71,129 @@ namespace Robust.Client.Graphics.Clyde
|
||||
// Flip image because OpenGL reads images upside down.
|
||||
var copy = FlipClone(image);
|
||||
|
||||
var texture = new GLHandle((uint) GL.GenTexture());
|
||||
CheckGlError();
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
|
||||
CheckGlError();
|
||||
ApplySampleParameters(actualParams.SampleParameters);
|
||||
|
||||
PixelInternalFormat internalFormat;
|
||||
PixelFormat pixelDataFormat;
|
||||
PixelType pixelDataType;
|
||||
bool isActuallySrgb = false;
|
||||
|
||||
if (pixelType == typeof(Rgba32))
|
||||
{
|
||||
// Note that if _hasGLSrgb is off, we import an sRGB texture as non-sRGB.
|
||||
// Shaders are expected to compensate for this
|
||||
internalFormat = (actualParams.Srgb && _hasGLSrgb) ? PixelInternalFormat.Srgb8Alpha8 : PixelInternalFormat.Rgba8;
|
||||
isActuallySrgb = actualParams.Srgb;
|
||||
pixelDataFormat = PixelFormat.Rgba;
|
||||
pixelDataType = PixelType.UnsignedByte;
|
||||
}
|
||||
else if (pixelType == typeof(A8))
|
||||
{
|
||||
if (image.Width % 4 != 0 || image.Height % 4 != 0)
|
||||
{
|
||||
throw new ArgumentException("Alpha8 images must have multiple of 4 sizes.");
|
||||
}
|
||||
|
||||
internalFormat = PixelInternalFormat.R8;
|
||||
pixelDataFormat = PixelFormat.Red;
|
||||
pixelDataType = PixelType.UnsignedByte;
|
||||
|
||||
unsafe
|
||||
{
|
||||
// TODO: Does it make sense to default to 1 for RGB parameters?
|
||||
// It might make more sense to pass some options to change swizzling.
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int) All.One);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int) All.One);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int) All.One);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int) All.Red);
|
||||
}
|
||||
}
|
||||
else if (pixelType == typeof(L8) && !actualParams.Srgb)
|
||||
{
|
||||
// Can only use R8 for L8 if sRGB is OFF.
|
||||
// Because OpenGL doesn't provide sRGB single/dual channel image formats.
|
||||
// Vulkan when?
|
||||
if (copy.Width % 4 != 0 || copy.Height % 4 != 0)
|
||||
{
|
||||
throw new ArgumentException("L8 non-sRGB images must have multiple of 4 sizes.");
|
||||
}
|
||||
|
||||
internalFormat = PixelInternalFormat.R8;
|
||||
pixelDataFormat = PixelFormat.Red;
|
||||
pixelDataType = PixelType.UnsignedByte;
|
||||
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int) All.Red);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int) All.Red);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int) All.Red);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int) All.One);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException($"Unable to handle pixel type '{pixelType.Name}'");
|
||||
}
|
||||
var texture = CreateBaseTextureInternal<T>(image.Width, image.Height, actualParams, name);
|
||||
|
||||
unsafe
|
||||
{
|
||||
var span = copy.GetPixelSpan();
|
||||
fixed (T* ptr = span)
|
||||
{
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, copy.Width, copy.Height, 0,
|
||||
pixelDataFormat, pixelDataType, (IntPtr) ptr);
|
||||
CheckGlError();
|
||||
// Still bound.
|
||||
DoTexUpload(copy.Width, copy.Height, actualParams.Srgb, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
var pressureEst = EstPixelSize(internalFormat) * copy.Width * copy.Height;
|
||||
return texture;
|
||||
}
|
||||
|
||||
return GenTexture(texture, (copy.Width, copy.Height), isActuallySrgb, name, pressureEst);
|
||||
public unsafe OwnedTexture CreateBlankTexture<T>(
|
||||
Vector2i size,
|
||||
string? name = null,
|
||||
in TextureLoadParameters? loadParams = null)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
var actualParams = loadParams ?? TextureLoadParameters.Default;
|
||||
if (!_hasGLTextureSwizzle)
|
||||
{
|
||||
// Actually create RGBA32 texture if missing texture swizzle.
|
||||
// This is fine (TexturePixelType that's stored) because all other APIs do the same.
|
||||
if (typeof(T) == typeof(A8) || typeof(T) == typeof(L8))
|
||||
{
|
||||
return CreateBlankTexture<Rgba32>(size, name, loadParams);
|
||||
}
|
||||
}
|
||||
|
||||
var texture = CreateBaseTextureInternal<T>(
|
||||
size.X, size.Y,
|
||||
actualParams,
|
||||
name);
|
||||
|
||||
// Texture still bound, run glTexImage2D with null data param to specify bounds.
|
||||
DoTexUpload<T>(size.X, size.Y, actualParams.Srgb, null);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
private unsafe void DoTexUpload<T>(int width, int height, bool srgb, T* ptr) where T : unmanaged, IPixel<T>
|
||||
{
|
||||
if (sizeof(T) < 4)
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
var (pif, pf, pt) = PixelEnums<T>(srgb);
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, pif, width, height, 0, pf, pt, (IntPtr) ptr);
|
||||
CheckGlError();
|
||||
|
||||
if (sizeof(T) < 4)
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
|
||||
CheckGlError();
|
||||
}
|
||||
}
|
||||
|
||||
private ClydeTexture CreateBaseTextureInternal<T>(
|
||||
int width, int height,
|
||||
in TextureLoadParameters loadParams,
|
||||
string? name = null)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
var texture = new GLHandle((uint) GL.GenTexture());
|
||||
CheckGlError();
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
|
||||
CheckGlError();
|
||||
ApplySampleParameters(loadParams.SampleParameters);
|
||||
|
||||
var (pif, _, _) = PixelEnums<T>(loadParams.Srgb);
|
||||
var pixelType = typeof(T);
|
||||
var texPixType = GetTexturePixelType<T>();
|
||||
var isActuallySrgb = false;
|
||||
|
||||
if (pixelType == typeof(Rgba32))
|
||||
{
|
||||
isActuallySrgb = loadParams.Srgb;
|
||||
}
|
||||
else if (pixelType == typeof(A8))
|
||||
{
|
||||
DebugTools.Assert(_hasGLTextureSwizzle);
|
||||
|
||||
// TODO: Does it make sense to default to 1 for RGB parameters?
|
||||
// It might make more sense to pass some options to change swizzling.
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int) All.One);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int) All.One);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int) All.One);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int) All.Red);
|
||||
CheckGlError();
|
||||
}
|
||||
else if (pixelType == typeof(L8) && !loadParams.Srgb)
|
||||
{
|
||||
DebugTools.Assert(_hasGLTextureSwizzle);
|
||||
|
||||
// Can only use R8 for L8 if sRGB is OFF.
|
||||
// Because OpenGL doesn't provide sRGB single/dual channel image formats.
|
||||
// Vulkan when?
|
||||
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int) All.Red);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int) All.Red);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int) All.Red);
|
||||
CheckGlError();
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int) All.One);
|
||||
CheckGlError();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"Unable to handle pixel type '{pixelType.Name}'");
|
||||
}
|
||||
|
||||
var pressureEst = EstPixelSize(pif) * width * height;
|
||||
|
||||
return GenTexture(texture, (width, height), isActuallySrgb, name, texPixType, pressureEst);
|
||||
}
|
||||
|
||||
private void ApplySampleParameters(TextureSampleParameters? sampleParameters)
|
||||
@@ -201,10 +247,30 @@ namespace Robust.Client.Graphics.Clyde
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
private ClydeTexture GenTexture(GLHandle glHandle, Vector2i size, bool srgb, string? name, long memoryPressure=0)
|
||||
private (PIF pif, PF pf, PT pt) PixelEnums<T>(bool srgb)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
return default(T) switch
|
||||
{
|
||||
// Note that if _hasGLSrgb is off, we import an sRGB texture as non-sRGB.
|
||||
// Shaders are expected to compensate for this
|
||||
Rgba32 => (srgb && _hasGLSrgb ? PIF.Srgb8Alpha8 : PIF.Rgba8, PF.Rgba, PT.UnsignedByte),
|
||||
A8 or L8 => (PIF.R8, PF.Red, PT.UnsignedByte),
|
||||
_ => throw new NotSupportedException("Unsupported pixel type."),
|
||||
};
|
||||
}
|
||||
|
||||
private ClydeTexture GenTexture(
|
||||
GLHandle glHandle,
|
||||
Vector2i size,
|
||||
bool srgb,
|
||||
string? name,
|
||||
TexturePixelType pixType,
|
||||
long memoryPressure = 0)
|
||||
{
|
||||
if (name != null)
|
||||
{
|
||||
@@ -222,7 +288,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
Height = height,
|
||||
IsSrgb = srgb,
|
||||
Name = name,
|
||||
MemoryPressure = memoryPressure
|
||||
MemoryPressure = memoryPressure,
|
||||
TexturePixelType = pixType
|
||||
// TextureInstance = new WeakReference<ClydeTexture>(instance)
|
||||
};
|
||||
|
||||
@@ -246,6 +313,97 @@ namespace Robust.Client.Graphics.Clyde
|
||||
//GC.RemoveMemoryPressure(loadedTexture.MemoryPressure);
|
||||
}
|
||||
|
||||
private unsafe void SetSubImage<T>(
|
||||
ClydeTexture texture,
|
||||
Vector2i dstTl,
|
||||
Image<T> srcImage,
|
||||
in UIBox2i srcBox)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
if (!_hasGLTextureSwizzle)
|
||||
{
|
||||
if (typeof(T) == typeof(A8))
|
||||
{
|
||||
SetSubImage(texture, dstTl, ApplyA8Swizzle((Image<A8>) (object) srcImage), srcBox);
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(L8))
|
||||
{
|
||||
SetSubImage(texture, dstTl, ApplyL8Swizzle((Image<L8>) (object) srcImage), srcBox);
|
||||
}
|
||||
}
|
||||
|
||||
var loaded = _loadedTextures[texture.TextureId];
|
||||
|
||||
var pixType = GetTexturePixelType<T>();
|
||||
|
||||
if (pixType != loaded.TexturePixelType)
|
||||
{
|
||||
if (loaded.TexturePixelType == TexturePixelType.RenderTarget)
|
||||
throw new InvalidOperationException("Cannot modify texture for render target directly.");
|
||||
|
||||
throw new InvalidOperationException("Mismatching pixel type for texture.");
|
||||
}
|
||||
|
||||
if (loaded.Width < dstTl.X + srcBox.Width || loaded.Height < dstTl.Y + srcBox.Height)
|
||||
throw new ArgumentOutOfRangeException(nameof(srcBox), "Destination rectangle out of bounds.");
|
||||
|
||||
if (srcBox.Left < 0 || srcBox.Top < 0 || srcBox.Right > srcImage.Width || srcBox.Bottom > srcImage.Height)
|
||||
throw new ArgumentOutOfRangeException(nameof(srcBox), "Source rectangle out of bounds.");
|
||||
|
||||
if (sizeof(T) != 4)
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
// sRGB doesn't matter since that only changes the internalFormat, which we don't need here.
|
||||
var (_, pf, pt) = PixelEnums<T>(srgb: false);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, loaded.OpenGLObject.Handle);
|
||||
CheckGlError();
|
||||
|
||||
var size = srcBox.Width * srcBox.Height;
|
||||
|
||||
var copyBuffer = size < 16 * 16 ? stackalloc T[size] : new T[size];
|
||||
|
||||
for (var y = 0; y < srcBox.Height; y++)
|
||||
for (var x = 0; x < srcBox.Width; x++)
|
||||
{
|
||||
copyBuffer[(srcBox.Height - y - 1) * srcBox.Width + x] = srcImage[x + srcBox.Left, srcBox.Top + y];
|
||||
}
|
||||
|
||||
fixed (T* aPtr = copyBuffer)
|
||||
{
|
||||
var dstY = loaded.Height - dstTl.Y - srcBox.Height;
|
||||
GL.TexSubImage2D(
|
||||
TextureTarget.Texture2D,
|
||||
0,
|
||||
dstTl.X, dstY,
|
||||
srcBox.Width, srcBox.Height,
|
||||
pf, pt,
|
||||
(IntPtr) aPtr);
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
if (sizeof(T) != 4)
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
|
||||
CheckGlError();
|
||||
}
|
||||
}
|
||||
|
||||
private static TexturePixelType GetTexturePixelType<T>() where T : unmanaged, IPixel<T>
|
||||
{
|
||||
return default(T) switch
|
||||
{
|
||||
Rgba32 => TexturePixelType.Rgba32,
|
||||
L8 => TexturePixelType.L8,
|
||||
A8 => TexturePixelType.A8,
|
||||
_ => throw new NotSupportedException("Unsupported pixel type."),
|
||||
};
|
||||
}
|
||||
|
||||
private void LoadStockTextures()
|
||||
{
|
||||
var white = new Image<Rgba32>(1, 1);
|
||||
@@ -350,10 +508,20 @@ namespace Robust.Client.Graphics.Clyde
|
||||
public bool IsSrgb;
|
||||
public string? Name;
|
||||
public long MemoryPressure;
|
||||
public TexturePixelType TexturePixelType;
|
||||
|
||||
public Vector2i Size => (Width, Height);
|
||||
// public WeakReference<ClydeTexture> TextureInstance;
|
||||
}
|
||||
|
||||
private enum TexturePixelType : byte
|
||||
{
|
||||
RenderTarget = 0,
|
||||
Rgba32,
|
||||
A8,
|
||||
L8,
|
||||
}
|
||||
|
||||
private void FlushTextureDispose()
|
||||
{
|
||||
while (_textureDisposeQueue.TryDequeue(out var handle))
|
||||
@@ -369,6 +537,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
internal ClydeHandle TextureId { get; }
|
||||
|
||||
public override void SetSubImage<T>(Vector2i topLeft, Image<T> sourceImage, in UIBox2i sourceRegion)
|
||||
{
|
||||
_clyde.SetSubImage(this, topLeft, sourceImage, sourceRegion);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
public string GetKeyName(Keyboard.Key key) => string.Empty;
|
||||
public string GetKeyNameScanCode(int scanCode) => string.Empty;
|
||||
public int GetKeyScanCode(Keyboard.Key key) => default;
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
// Nada.
|
||||
@@ -77,8 +78,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
public override event Action<WindowResizedEventArgs> OnWindowResized
|
||||
{
|
||||
add {}
|
||||
remove {}
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public void Render()
|
||||
@@ -111,6 +112,15 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return new DummyTexture((image.Width, image.Height));
|
||||
}
|
||||
|
||||
public OwnedTexture CreateBlankTexture<T>(
|
||||
Vector2i size,
|
||||
string? name = null,
|
||||
in TextureLoadParameters? loadParams = null)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
return new DummyTexture(size);
|
||||
}
|
||||
|
||||
public IRenderTexture CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format,
|
||||
TextureSampleParameters? sampleParameters = null, string? name = null)
|
||||
{
|
||||
@@ -174,7 +184,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return DummyAudioSource.Instance;
|
||||
}
|
||||
|
||||
public IClydeBufferedAudioSource CreateBufferedAudioSource(int buffers, bool floatAudio=false)
|
||||
public IClydeBufferedAudioSource CreateBufferedAudioSource(int buffers, bool floatAudio = false)
|
||||
{
|
||||
return DummyBufferedAudioSource.Instance;
|
||||
}
|
||||
@@ -296,6 +306,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
public DummyTexture(Vector2i size) : base(size)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetSubImage<T>(Vector2i topLeft, Image<T> sourceImage, in UIBox2i sourceRegion)
|
||||
{
|
||||
// Just do nothing on mutate.
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DummyShaderInstance : ShaderInstance
|
||||
@@ -434,7 +449,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
}
|
||||
|
||||
public IRenderTexture RenderTarget { get; } = new DummyRenderTexture(Vector2i.One, new DummyTexture(Vector2i.One));
|
||||
public IRenderTexture RenderTarget { get; } =
|
||||
new DummyRenderTexture(Vector2i.One, new DummyTexture(Vector2i.One));
|
||||
|
||||
public IEye? Eye { get; set; }
|
||||
public Vector2i Size { get; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Interfaces.Graphics;
|
||||
using Robust.Client.Utility;
|
||||
@@ -17,7 +18,11 @@ namespace Robust.Client.Graphics
|
||||
{
|
||||
internal sealed class FontManager : IFontManagerInternal
|
||||
{
|
||||
private const int SheetWidth = 256;
|
||||
private const int SheetHeight = 256;
|
||||
|
||||
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
|
||||
private uint BaseFontDPI;
|
||||
|
||||
@@ -51,8 +56,7 @@ namespace Robust.Client.Graphics
|
||||
return instance;
|
||||
}
|
||||
|
||||
var glyphMap = _generateGlyphMap(fontFaceHandle.Face);
|
||||
instance = new FontInstanceHandle(this, size, glyphMap, fontFaceHandle);
|
||||
instance = new FontInstanceHandle(this, size, fontFaceHandle);
|
||||
|
||||
_loadedInstances.Add((fontFaceHandle, size), instance);
|
||||
return instance;
|
||||
@@ -67,135 +71,128 @@ namespace Robust.Client.Graphics
|
||||
var descent = -ftFace.Size.Metrics.Descender.ToInt32();
|
||||
var lineHeight = ftFace.Size.Metrics.Height.ToInt32();
|
||||
|
||||
var (atlas, metricsMap) = _generateAtlas(instance, scale);
|
||||
var data = new ScaledFontData(ascent, descent, ascent + descent, lineHeight);
|
||||
|
||||
return new ScaledFontData(metricsMap, ascent, descent, ascent + descent, lineHeight, atlas);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private (FontTextureAtlas, Dictionary<uint, CharMetrics> metricsMap)
|
||||
_generateAtlas(FontInstanceHandle instance, float scale)
|
||||
private void CacheGlyph(FontInstanceHandle instance, ScaledFontData scaled, float scale, uint glyph)
|
||||
{
|
||||
// TODO: This could use a better box packing algorithm.
|
||||
// Right now we treat each glyph bitmap as having the max size among all glyphs.
|
||||
// So we can divide the atlas into equal-size rectangles.
|
||||
// This wastes a lot of space though because there's a lot of tiny glyphs.
|
||||
// Check if already cached.
|
||||
if (scaled.AtlasData.ContainsKey(glyph))
|
||||
return;
|
||||
|
||||
var face = instance.FaceHandle.Face;
|
||||
face.SetCharSize(0, instance.Size, 0, (uint) (BaseFontDPI * scale));
|
||||
face.LoadGlyph(glyph, LoadFlags.Default, LoadTarget.Normal);
|
||||
face.Glyph.RenderGlyph(RenderMode.Normal);
|
||||
|
||||
var maxGlyphSize = Vector2i.Zero;
|
||||
var count = 0;
|
||||
var glyphMetrics = face.Glyph.Metrics;
|
||||
var metrics = new CharMetrics(glyphMetrics.HorizontalBearingX.ToInt32(),
|
||||
glyphMetrics.HorizontalBearingY.ToInt32(),
|
||||
glyphMetrics.HorizontalAdvance.ToInt32(),
|
||||
glyphMetrics.Width.ToInt32(),
|
||||
glyphMetrics.Height.ToInt32());
|
||||
|
||||
var metricsMap = new Dictionary<uint, CharMetrics>();
|
||||
|
||||
foreach (var glyph in instance.GlyphMap.Values)
|
||||
using var bitmap = face.Glyph.Bitmap;
|
||||
if (bitmap.Pitch < 0)
|
||||
{
|
||||
if (metricsMap.ContainsKey(glyph))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
face.LoadGlyph(glyph, LoadFlags.Default, LoadTarget.Normal);
|
||||
face.Glyph.RenderGlyph(RenderMode.Normal);
|
||||
|
||||
var glyphMetrics = face.Glyph.Metrics;
|
||||
var metrics = new CharMetrics(glyphMetrics.HorizontalBearingX.ToInt32(),
|
||||
glyphMetrics.HorizontalBearingY.ToInt32(),
|
||||
glyphMetrics.HorizontalAdvance.ToInt32(),
|
||||
glyphMetrics.Width.ToInt32(),
|
||||
glyphMetrics.Height.ToInt32());
|
||||
metricsMap.Add(glyph, metrics);
|
||||
|
||||
maxGlyphSize = Vector2i.ComponentMax(maxGlyphSize,
|
||||
new Vector2i(face.Glyph.Bitmap.Width, face.Glyph.Bitmap.Rows));
|
||||
|
||||
count += 1;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Make atlas.
|
||||
// This is the same algorithm used for RSIs. Tries to keep width and height as close as possible,
|
||||
// but preferring to increase width if necessary.
|
||||
var atlasEntriesHorizontal = (int) Math.Ceiling(Math.Sqrt(count));
|
||||
var atlasEntriesVertical =
|
||||
(int) Math.Ceiling(count / (float) atlasEntriesHorizontal);
|
||||
var atlasDimX =
|
||||
(int) Math.Ceiling(atlasEntriesHorizontal * maxGlyphSize.X / 4f) * 4;
|
||||
var atlasDimY =
|
||||
(int) Math.Ceiling(atlasEntriesVertical * maxGlyphSize.Y / 4f) * 4;
|
||||
|
||||
using (var atlas = new Image<A8>(atlasDimX, atlasDimY))
|
||||
if (bitmap.Pitch != 0)
|
||||
{
|
||||
var atlasRegions = new Dictionary<uint, UIBox2>();
|
||||
count = 0;
|
||||
foreach (var glyph in metricsMap.Keys)
|
||||
Image<A8> img;
|
||||
switch (bitmap.PixelMode)
|
||||
{
|
||||
face.LoadGlyph(glyph, LoadFlags.Default, LoadTarget.Normal);
|
||||
face.Glyph.RenderGlyph(RenderMode.Normal);
|
||||
|
||||
var bitmap = face.Glyph.Bitmap;
|
||||
if (bitmap.Pitch == 0)
|
||||
case PixelMode.Mono:
|
||||
{
|
||||
count += 1;
|
||||
continue;
|
||||
img = MonoBitMapToImage(bitmap);
|
||||
break;
|
||||
}
|
||||
|
||||
if (bitmap.Pitch < 0)
|
||||
case PixelMode.Gray:
|
||||
{
|
||||
ReadOnlySpan<A8> span;
|
||||
unsafe
|
||||
{
|
||||
span = new ReadOnlySpan<A8>((void*) bitmap.Buffer, bitmap.Pitch * bitmap.Rows);
|
||||
}
|
||||
|
||||
img = new Image<A8>(bitmap.Width, bitmap.Rows);
|
||||
|
||||
span.Blit(
|
||||
bitmap.Pitch,
|
||||
UIBox2i.FromDimensions(0, 0, bitmap.Pitch, bitmap.Rows),
|
||||
img,
|
||||
(0, 0));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelMode.Gray2:
|
||||
case PixelMode.Gray4:
|
||||
case PixelMode.Lcd:
|
||||
case PixelMode.VerticalLcd:
|
||||
case PixelMode.Bgra:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
var column = count % atlasEntriesHorizontal;
|
||||
var row = count / atlasEntriesVertical;
|
||||
var offsetX = column * maxGlyphSize.X;
|
||||
var offsetY = row * maxGlyphSize.Y;
|
||||
count += 1;
|
||||
atlasRegions.Add(glyph, UIBox2i.FromDimensions(offsetX, offsetY, bitmap.Width, bitmap.Rows));
|
||||
|
||||
switch (bitmap.PixelMode)
|
||||
{
|
||||
case PixelMode.Mono:
|
||||
{
|
||||
using (var bitmapImage = MonoBitMapToImage(bitmap))
|
||||
{
|
||||
bitmapImage.Blit(new UIBox2i(0, 0, bitmapImage.Width, bitmapImage.Height), atlas,
|
||||
(offsetX, offsetY));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelMode.Gray:
|
||||
{
|
||||
ReadOnlySpan<A8> span;
|
||||
unsafe
|
||||
{
|
||||
span = new ReadOnlySpan<A8>((void*) bitmap.Buffer, bitmap.Pitch * bitmap.Rows);
|
||||
}
|
||||
|
||||
span.Blit(bitmap.Pitch, UIBox2i.FromDimensions(0, 0, bitmap.Pitch, bitmap.Rows), atlas,
|
||||
(offsetX, offsetY));
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelMode.Gray2:
|
||||
case PixelMode.Gray4:
|
||||
case PixelMode.Lcd:
|
||||
case PixelMode.VerticalLcd:
|
||||
case PixelMode.Bgra:
|
||||
throw new NotImplementedException();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var atlasDictionary = new Dictionary<uint, AtlasTexture>();
|
||||
var texture = Texture.LoadFromImage(atlas, $"font-{face.FamilyName}-{instance.Size}-{(uint) (BaseFontDPI * scale)}");
|
||||
OwnedTexture sheet;
|
||||
if (scaled.AtlasTextures.Count == 0)
|
||||
sheet = GenSheet();
|
||||
else
|
||||
sheet = scaled.AtlasTextures[^1];
|
||||
|
||||
foreach (var (glyph, region) in atlasRegions)
|
||||
var (sheetW, sheetH) = sheet.Size;
|
||||
|
||||
if (sheetW - scaled.CurSheetX < img.Width)
|
||||
{
|
||||
atlasDictionary.Add(glyph, new AtlasTexture(texture, region));
|
||||
scaled.CurSheetX = 0;
|
||||
scaled.CurSheetY = scaled.CurSheetMaxY;
|
||||
}
|
||||
|
||||
return (new FontTextureAtlas(texture, atlasDictionary), metricsMap);
|
||||
if (sheetH - scaled.CurSheetY < img.Height)
|
||||
{
|
||||
// Make new sheet.
|
||||
scaled.CurSheetY = 0;
|
||||
scaled.CurSheetX = 0;
|
||||
scaled.CurSheetMaxY = 0;
|
||||
|
||||
sheet = GenSheet();
|
||||
}
|
||||
|
||||
sheet.SetSubImage((scaled.CurSheetX, scaled.CurSheetY), img);
|
||||
|
||||
var atlasTexture = new AtlasTexture(
|
||||
sheet,
|
||||
UIBox2.FromDimensions(
|
||||
scaled.CurSheetX,
|
||||
scaled.CurSheetY,
|
||||
bitmap.Width,
|
||||
bitmap.Rows));
|
||||
|
||||
scaled.AtlasData.Add(glyph, atlasTexture);
|
||||
|
||||
scaled.CurSheetMaxY = Math.Max(scaled.CurSheetMaxY, scaled.CurSheetY + bitmap.Rows);
|
||||
scaled.CurSheetX += bitmap.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
scaled.AtlasData.Add(glyph, null);
|
||||
}
|
||||
|
||||
scaled.MetricsMap.Add(glyph, metrics);
|
||||
|
||||
OwnedTexture GenSheet()
|
||||
{
|
||||
var sheet = _clyde.CreateBlankTexture<A8>((SheetWidth, SheetHeight),
|
||||
$"font-{face.FamilyName}-{instance.Size}-{(uint) (BaseFontDPI * scale)}-sheet{scaled.AtlasTextures.Count}");
|
||||
scaled.AtlasTextures.Add(sheet);
|
||||
return sheet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,46 +223,6 @@ namespace Robust.Client.Graphics
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
private Dictionary<char, uint> _generateGlyphMap(Face face)
|
||||
{
|
||||
var map = new Dictionary<char, uint>();
|
||||
|
||||
// TODO: Render more than extended ASCII, Cyrillic and Greek. somehow.
|
||||
// Does it make sense to just render every glyph in the font?
|
||||
|
||||
// Render all the extended ASCII characters.
|
||||
// Yeah I know "extended ASCII" isn't a real thing get off my back.
|
||||
for (var i = 32u; i <= 255; i++)
|
||||
{
|
||||
_addGlyph(i, face, map);
|
||||
}
|
||||
|
||||
// Render basic cyrillic.
|
||||
for (var i = 0x0410u; i <= 0x044F; i++)
|
||||
{
|
||||
_addGlyph(i, face, map);
|
||||
}
|
||||
|
||||
// Render greek.
|
||||
for (var i = 0x03B1u; i <= 0x03C9; i++)
|
||||
{
|
||||
_addGlyph(i, face, map);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void _addGlyph(uint codePoint, Face face, Dictionary<char, uint> map)
|
||||
{
|
||||
var glyphIndex = face.GetCharIndex(codePoint);
|
||||
if (glyphIndex == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
map.Add((char) codePoint, glyphIndex);
|
||||
}
|
||||
|
||||
private class FontFaceHandle : IFontFaceHandle
|
||||
{
|
||||
public Face Face { get; }
|
||||
@@ -282,78 +239,84 @@ namespace Robust.Client.Graphics
|
||||
public FontFaceHandle FaceHandle { get; }
|
||||
public int Size { get; }
|
||||
private readonly Dictionary<float, ScaledFontData> _scaledData = new();
|
||||
public readonly IReadOnlyDictionary<char, uint> GlyphMap;
|
||||
private readonly FontManager _fontManager;
|
||||
public readonly Dictionary<Rune, uint> GlyphMap;
|
||||
|
||||
public FontInstanceHandle(FontManager fontManager, int size, IReadOnlyDictionary<char, uint> glyphMap,
|
||||
FontFaceHandle faceHandle)
|
||||
public FontInstanceHandle(FontManager fontManager, int size, FontFaceHandle faceHandle)
|
||||
{
|
||||
GlyphMap = new Dictionary<Rune, uint>();
|
||||
_fontManager = fontManager;
|
||||
Size = size;
|
||||
GlyphMap = glyphMap;
|
||||
FaceHandle = faceHandle;
|
||||
}
|
||||
|
||||
public Texture? GetCharTexture(char chr, float scale)
|
||||
public Texture? GetCharTexture(Rune codePoint, float scale)
|
||||
{
|
||||
var glyph = _getGlyph(chr);
|
||||
var glyph = GetGlyph(codePoint);
|
||||
if (glyph == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var scaled = _getScaleDatum(scale);
|
||||
scaled.Atlas.AtlasData.TryGetValue(glyph, out var texture);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
_fontManager.CacheGlyph(this, scaled, scale, glyph);
|
||||
|
||||
scaled.AtlasData.TryGetValue(glyph, out var texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
public CharMetrics? GetCharMetrics(char chr, float scale)
|
||||
public CharMetrics? GetCharMetrics(Rune codePoint, float scale)
|
||||
{
|
||||
var glyph = _getGlyph(chr);
|
||||
var glyph = GetGlyph(codePoint);
|
||||
if (glyph == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var scaled = _getScaleDatum(scale);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
_fontManager.CacheGlyph(this, scaled, scale, glyph);
|
||||
|
||||
return scaled.MetricsMap[glyph];
|
||||
}
|
||||
|
||||
public int GetAscent(float scale)
|
||||
{
|
||||
var scaled = _getScaleDatum(scale);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
return scaled.Ascent;
|
||||
}
|
||||
|
||||
public int GetDescent(float scale)
|
||||
{
|
||||
var scaled = _getScaleDatum(scale);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
return scaled.Descent;
|
||||
}
|
||||
|
||||
public int GetHeight(float scale)
|
||||
{
|
||||
var scaled = _getScaleDatum(scale);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
return scaled.Height;
|
||||
}
|
||||
|
||||
public int GetLineHeight(float scale)
|
||||
{
|
||||
var scaled = _getScaleDatum(scale);
|
||||
var scaled = GetScaleDatum(scale);
|
||||
return scaled.LineHeight;
|
||||
}
|
||||
|
||||
private uint _getGlyph(char chr)
|
||||
private uint GetGlyph(Rune chr)
|
||||
{
|
||||
if (GlyphMap.TryGetValue(chr, out var glyph))
|
||||
{
|
||||
return glyph;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Check FreeType to see if it exists.
|
||||
var index = FaceHandle.Face.GetCharIndex((uint) chr.Value);
|
||||
|
||||
GlyphMap.Add(chr, index);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private ScaledFontData _getScaleDatum(float scale)
|
||||
private ScaledFontData GetScaleDatum(float scale)
|
||||
{
|
||||
if (_scaledData.TryGetValue(scale, out var datum))
|
||||
{
|
||||
@@ -368,37 +331,25 @@ namespace Robust.Client.Graphics
|
||||
|
||||
private class ScaledFontData
|
||||
{
|
||||
public ScaledFontData(IReadOnlyDictionary<uint, CharMetrics> metricsMap, int ascent, int descent,
|
||||
int height, int lineHeight, FontTextureAtlas atlas)
|
||||
public ScaledFontData(int ascent, int descent, int height, int lineHeight)
|
||||
{
|
||||
MetricsMap = metricsMap;
|
||||
Ascent = ascent;
|
||||
Descent = descent;
|
||||
Height = height;
|
||||
LineHeight = lineHeight;
|
||||
Atlas = atlas;
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<uint, CharMetrics> MetricsMap { get; }
|
||||
public int Ascent { get; }
|
||||
public int Descent { get; }
|
||||
public int Height { get; }
|
||||
public int LineHeight { get; }
|
||||
public FontTextureAtlas Atlas { get; }
|
||||
}
|
||||
public readonly List<OwnedTexture> AtlasTextures = new();
|
||||
public readonly Dictionary<uint, AtlasTexture?> AtlasData = new();
|
||||
public readonly Dictionary<uint, CharMetrics> MetricsMap = new();
|
||||
public readonly int Ascent;
|
||||
public readonly int Descent;
|
||||
public readonly int Height;
|
||||
public readonly int LineHeight;
|
||||
|
||||
private class FontTextureAtlas
|
||||
{
|
||||
public FontTextureAtlas(Texture mainTexture, Dictionary<uint, AtlasTexture> atlasData)
|
||||
{
|
||||
MainTexture = mainTexture;
|
||||
AtlasData = atlasData;
|
||||
}
|
||||
|
||||
public Texture MainTexture { get; }
|
||||
|
||||
// Maps glyph index to atlas.
|
||||
public Dictionary<uint, AtlasTexture> AtlasData { get; }
|
||||
public int CurSheetX;
|
||||
public int CurSheetY;
|
||||
public int CurSheetMaxY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
@@ -12,21 +14,42 @@ namespace Robust.Client.Graphics
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifies a sub area of the texture with new data.
|
||||
/// </summary>
|
||||
/// <param name="topLeft">The top left corner of the area to modify.</param>
|
||||
/// <param name="sourceImage">The image from which to copy pixel data.</param>
|
||||
/// <param name="sourceRegion">The rectangle inside <paramref name="sourceImage"/> from which to copy.</param>
|
||||
/// <typeparam name="T">
|
||||
/// The type of pixels being used.
|
||||
/// This must match the type used when creating the texture.
|
||||
/// </typeparam>
|
||||
public abstract void SetSubImage<T>(Vector2i topLeft, Image<T> sourceImage, in UIBox2i sourceRegion)
|
||||
where T : unmanaged, IPixel<T>;
|
||||
|
||||
/// <summary>
|
||||
/// Modifies a sub area of the texture with new data.
|
||||
/// </summary>
|
||||
/// <param name="topLeft">The top left corner of the area to modify.</param>
|
||||
/// <param name="sourceImage">The image to paste onto the texture.</param>
|
||||
/// <typeparam name="T">
|
||||
/// The type of pixels being used.
|
||||
/// This must match the type used when creating the texture.
|
||||
/// </typeparam>
|
||||
public void SetSubImage<T>(Vector2i topLeft, Image<T> sourceImage)
|
||||
where T : unmanaged, IPixel<T>
|
||||
{
|
||||
SetSubImage(topLeft, sourceImage, UIBox2i.FromDimensions(0, 0, sourceImage.Width, sourceImage.Height));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[Obsolete("Use Dispose() instead")]
|
||||
public void Delete()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~OwnedTexture()
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name","directions"] //'delays' is marked as optional in the spec
|
||||
"required": ["name"] //'delays' is marked as optional in the spec
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -134,7 +134,8 @@ namespace Robust.Client.Input
|
||||
Priority = p.Priority,
|
||||
Type = p.BindingType,
|
||||
CanFocus = p.CanFocus,
|
||||
CanRepeat = p.CanRepeat
|
||||
CanRepeat = p.CanRepeat,
|
||||
AllowSubCombs = p.AllowSubCombs
|
||||
}).ToArray();
|
||||
|
||||
var leaveEmpty = _modifiedKeyFunctions
|
||||
@@ -203,6 +204,7 @@ namespace Robust.Client.Input
|
||||
|
||||
var bindsDown = new List<KeyBinding>();
|
||||
var hasCanFocus = false;
|
||||
var hasAllowSubCombs = false;
|
||||
|
||||
// bindings are ordered with larger combos before single key bindings so combos have priority.
|
||||
foreach (var binding in _bindings)
|
||||
@@ -221,12 +223,22 @@ namespace Robust.Client.Input
|
||||
matchedCombo = binding.PackedKeyCombo;
|
||||
|
||||
bindsDown.Add(binding);
|
||||
|
||||
hasCanFocus |= binding.CanFocus;
|
||||
hasAllowSubCombs |= binding.AllowSubCombs;
|
||||
|
||||
}
|
||||
else if (PackedIsSubPattern(matchedCombo, binding.PackedKeyCombo))
|
||||
{
|
||||
// kill any lower level matches
|
||||
UpBind(binding);
|
||||
if (hasAllowSubCombs)
|
||||
{
|
||||
bindsDown.Add(binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
// kill any lower level matches
|
||||
UpBind(binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,8 +390,8 @@ namespace Robust.Client.Input
|
||||
{
|
||||
for (var i = 0; i < 32; i += 8)
|
||||
{
|
||||
var key = (Key) (subPackedCombo.Packed >> i);
|
||||
if (!PackedContainsKey(packedCombo, key))
|
||||
var key = (Key) ((subPackedCombo.Packed >> i) & 0b_1111_1111);
|
||||
if (key != Key.Unknown && !PackedContainsKey(packedCombo, key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -453,7 +465,7 @@ namespace Robust.Client.Input
|
||||
public IKeyBinding RegisterBinding(BoundKeyFunction function, KeyBindingType bindingType,
|
||||
Key baseKey, Key? mod1, Key? mod2, Key? mod3)
|
||||
{
|
||||
var binding = new KeyBinding(this, function, bindingType, baseKey, false, false,
|
||||
var binding = new KeyBinding(this, function, bindingType, baseKey, false, false, false,
|
||||
0, mod1 ?? Key.Unknown, mod2 ?? Key.Unknown, mod3 ?? Key.Unknown);
|
||||
|
||||
RegisterBinding(binding);
|
||||
@@ -464,7 +476,7 @@ namespace Robust.Client.Input
|
||||
public IKeyBinding RegisterBinding(in KeyBindingRegistration reg, bool markModified = true)
|
||||
{
|
||||
var binding = new KeyBinding(this, reg.Function, reg.Type, reg.BaseKey, reg.CanFocus, reg.CanRepeat,
|
||||
reg.Priority, reg.Mod1, reg.Mod2, reg.Mod3);
|
||||
reg.AllowSubCombs, reg.Priority, reg.Mod1, reg.Mod2, reg.Mod3);
|
||||
|
||||
RegisterBinding(binding, markModified);
|
||||
|
||||
@@ -619,12 +631,18 @@ namespace Robust.Client.Input
|
||||
[ViewVariables]
|
||||
public bool CanRepeat { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the Bound Key Combination allows Sub Combinations of it to trigger.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool AllowSubCombs { get; internal set; }
|
||||
|
||||
[ViewVariables] public int Priority { get; internal set; }
|
||||
|
||||
public KeyBinding(InputManager inputManager, BoundKeyFunction function,
|
||||
KeyBindingType bindingType,
|
||||
Key baseKey,
|
||||
bool canFocus, bool canRepeat, int priority, Key mod1 = Key.Unknown,
|
||||
bool canFocus, bool canRepeat, bool allowSubCombs, int priority, Key mod1 = Key.Unknown,
|
||||
Key mod2 = Key.Unknown,
|
||||
Key mod3 = Key.Unknown)
|
||||
{
|
||||
@@ -632,6 +650,7 @@ namespace Robust.Client.Input
|
||||
BindingType = bindingType;
|
||||
CanFocus = canFocus;
|
||||
CanRepeat = canRepeat;
|
||||
AllowSubCombs = allowSubCombs;
|
||||
Priority = priority;
|
||||
_inputManager = inputManager;
|
||||
|
||||
|
||||
@@ -34,6 +34,29 @@ namespace Robust.Client.Interfaces.Graphics
|
||||
Texture LoadTextureFromImage<T>(Image<T> image, string? name = null,
|
||||
TextureLoadParameters? loadParams = null) where T : unmanaged, IPixel<T>;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a blank texture of the specified parameters.
|
||||
/// This texture can later be modified using <see cref="OwnedTexture.SetSubImage{T}"/>
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the new texture, in pixels.</param>
|
||||
/// <param name="name">A name for the texture that can show up in debugging tools like renderdoc.</param>
|
||||
/// <param name="loadParams">
|
||||
/// Load parameters for the texture describing stuff such as sample mode.
|
||||
/// </param>
|
||||
/// <typeparam name="T">
|
||||
/// The type of pixels to "store" in the texture.
|
||||
/// This is the same type you should pass to <see cref="OwnedTexture.SetSubImage{T}"/>,
|
||||
/// and also determines how the texture is stored internally.
|
||||
/// </typeparam>
|
||||
/// <returns>
|
||||
/// An owned, mutable texture object.
|
||||
/// </returns>
|
||||
OwnedTexture CreateBlankTexture<T>(
|
||||
Vector2i size,
|
||||
string? name = null,
|
||||
in TextureLoadParameters? loadParams = null)
|
||||
where T : unmanaged, IPixel<T>;
|
||||
|
||||
IRenderTexture CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format,
|
||||
TextureSampleParameters? sampleParameters = null, string? name = null);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Robust.Client.Interfaces.Graphics
|
||||
@@ -22,8 +23,13 @@ namespace Robust.Client.Interfaces.Graphics
|
||||
|
||||
internal interface IFontInstanceHandle
|
||||
{
|
||||
Texture? GetCharTexture(char chr, float scale);
|
||||
CharMetrics? GetCharMetrics(char chr, float scale);
|
||||
|
||||
|
||||
Texture? GetCharTexture(Rune codePoint, float scale);
|
||||
Texture? GetCharTexture(char chr, float scale) => GetCharTexture((Rune) chr, scale);
|
||||
CharMetrics? GetCharMetrics(Rune codePoint, float scale);
|
||||
CharMetrics? GetCharMetrics(char chr, float scale) => GetCharMetrics((Rune) chr, scale);
|
||||
|
||||
int GetAscent(float scale);
|
||||
int GetDescent(float scale);
|
||||
int GetHeight(float scale);
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Robust.Client.Interfaces.Input
|
||||
|
||||
bool CanFocus { get; }
|
||||
bool CanRepeat { get; }
|
||||
bool AllowSubCombs { get; }
|
||||
int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -16,6 +16,7 @@ namespace Robust.Client.Interfaces.Input
|
||||
public int Priority;
|
||||
public bool CanFocus;
|
||||
public bool CanRepeat;
|
||||
public bool AllowSubCombs;
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
@@ -28,6 +29,7 @@ namespace Robust.Client.Interfaces.Input
|
||||
serializer.DataField(ref Priority, "priority", 0);
|
||||
serializer.DataField(ref CanFocus, "canFocus", false);
|
||||
serializer.DataField(ref CanRepeat, "canRepeat", false);
|
||||
serializer.DataField(ref AllowSubCombs, "allowSubCombs", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@ namespace Robust.Client.ResourceManagement
|
||||
|
||||
public override void Load(IResourceCache cache, ResourcePath path)
|
||||
{
|
||||
if (!cache.ContentFileExists(path))
|
||||
if (!cache.TryContentFileRead(path, out var stream))
|
||||
{
|
||||
throw new FileNotFoundException("Content file does not exist for font");
|
||||
}
|
||||
|
||||
FontFaceHandle = IoCManager.Resolve<IFontManagerInternal>().Load(cache.ContentFileRead(path));
|
||||
using (stream)
|
||||
{
|
||||
FontFaceHandle = IoCManager.Resolve<IFontManagerInternal>().Load(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public VectorFont MakeDefault()
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.Utility;
|
||||
@@ -83,7 +82,12 @@ namespace Robust.Client.ResourceManagement
|
||||
{
|
||||
// Load image from disk.
|
||||
var texPath = path / (stateObject.StateId + ".png");
|
||||
var image = Image.Load<Rgba32>(cache.ContentFileRead(texPath));
|
||||
var stream = cache.ContentFileRead(texPath);
|
||||
Image<Rgba32> image;
|
||||
using (stream)
|
||||
{
|
||||
image = Image.Load<Rgba32>(stream);
|
||||
}
|
||||
var sheetSize = new Vector2i(image.Width, image.Height);
|
||||
|
||||
if (sheetSize.X % frameSize.X != 0 || sheetSize.Y % frameSize.Y != 0)
|
||||
@@ -341,15 +345,25 @@ namespace Robust.Client.ResourceManagement
|
||||
foreach (var stateObject in manifestJson["states"]!.Cast<JObject>())
|
||||
{
|
||||
var stateName = stateObject["name"]!.ToObject<string>()!;
|
||||
var dirValue = stateObject["directions"]!.ToObject<int>();
|
||||
RSI.State.DirectionType directions;
|
||||
int dirValue;
|
||||
|
||||
var directions = dirValue switch
|
||||
if (stateObject.TryGetValue("directions", out var dirJToken))
|
||||
{
|
||||
1 => RSI.State.DirectionType.Dir1,
|
||||
4 => RSI.State.DirectionType.Dir4,
|
||||
8 => RSI.State.DirectionType.Dir8,
|
||||
_ => throw new RSILoadException($"Invalid direction: {dirValue}")
|
||||
};
|
||||
dirValue= dirJToken.ToObject<int>();
|
||||
directions = dirValue switch
|
||||
{
|
||||
1 => RSI.State.DirectionType.Dir1,
|
||||
4 => RSI.State.DirectionType.Dir4,
|
||||
8 => RSI.State.DirectionType.Dir8,
|
||||
_ => throw new RSILoadException($"Invalid direction: {dirValue} expected 1, 4 or 8")
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
dirValue = 1;
|
||||
directions = RSI.State.DirectionType.Dir1;
|
||||
}
|
||||
|
||||
// We can ignore selectors and flags for now,
|
||||
// because they're not used yet!
|
||||
|
||||
@@ -26,20 +26,23 @@ namespace Robust.Client.ResourceManagement
|
||||
throw new FileNotFoundException("Content file does not exist for texture");
|
||||
}
|
||||
|
||||
// Primarily for tracking down iCCP sRGB errors in the image files.
|
||||
Logger.DebugS("res.tex", $"Loading texture {path}.");
|
||||
|
||||
var loadParameters = _tryLoadTextureParameters(cache, path) ?? TextureLoadParameters.Default;
|
||||
|
||||
var manager = IoCManager.Resolve<IClyde>();
|
||||
|
||||
using var image = Image.Load<Rgba32>(stream);
|
||||
|
||||
Texture = manager.LoadTextureFromImage(image, path.ToString(), loadParameters);
|
||||
|
||||
if (cache is IResourceCacheInternal cacheInternal)
|
||||
using (stream)
|
||||
{
|
||||
cacheInternal.TextureLoaded(new TextureLoadedEventArgs(path, image, this));
|
||||
// Primarily for tracking down iCCP sRGB errors in the image files.
|
||||
Logger.DebugS("res.tex", $"Loading texture {path}.");
|
||||
|
||||
var loadParameters = _tryLoadTextureParameters(cache, path) ?? TextureLoadParameters.Default;
|
||||
|
||||
var manager = IoCManager.Resolve<IClyde>();
|
||||
|
||||
using var image = Image.Load<Rgba32>(stream);
|
||||
|
||||
Texture = manager.LoadTextureFromImage(image, path.ToString(), loadParameters);
|
||||
|
||||
if (cache is IResourceCacheInternal cacheInternal)
|
||||
{
|
||||
cacheInternal.TextureLoaded(new TextureLoadedEventArgs(path, image, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,21 +51,25 @@ namespace Robust.Client.ResourceManagement
|
||||
var metaPath = path.WithName(path.Filename + ".yml");
|
||||
if (cache.TryContentFileRead(metaPath, out var stream))
|
||||
{
|
||||
YamlDocument yamlData;
|
||||
using (var reader = new StreamReader(stream, EncodingHelpers.UTF8))
|
||||
using (stream)
|
||||
{
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(reader);
|
||||
if (yamlStream.Documents.Count == 0)
|
||||
YamlDocument yamlData;
|
||||
using (var reader = new StreamReader(stream, EncodingHelpers.UTF8))
|
||||
{
|
||||
return null;
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(reader);
|
||||
if (yamlStream.Documents.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
yamlData = yamlStream.Documents[0];
|
||||
}
|
||||
|
||||
yamlData = yamlStream.Documents[0];
|
||||
return TextureLoadParameters.FromYaml((YamlMappingNode) yamlData.RootNode);
|
||||
}
|
||||
|
||||
return TextureLoadParameters.FromYaml((YamlMappingNode)yamlData.RootNode);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ namespace Robust.Client.UserInterface
|
||||
{
|
||||
DebugTools.Assert(!Disposed, "Control has been disposed.");
|
||||
|
||||
foreach (var child in Children.ToList())
|
||||
foreach (var child in Children.ToArray())
|
||||
{
|
||||
RemoveChild(child);
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
if (item.Region == null)
|
||||
continue;
|
||||
|
||||
if (!item.Region.Value.Contains(args.RelativePosition))
|
||||
if (!item.Region.Value.Contains(args.RelativePixelPosition))
|
||||
continue;
|
||||
|
||||
if (item.Selectable && !item.Disabled)
|
||||
|
||||
@@ -31,6 +31,11 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (!VisibleInTree)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_label.Text = string.Join("\n", _inputManager.DownKeyFunctions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,11 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
return;
|
||||
}
|
||||
|
||||
if (!VisibleInTree)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetManager.IsConnected)
|
||||
{
|
||||
contents.Text = "Not connected to server.";
|
||||
|
||||
@@ -4,6 +4,7 @@ using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -172,8 +173,29 @@ namespace Robust.Client.UserInterface
|
||||
// This needs to happen because word wrapping doesn't get checked for the last word.
|
||||
if (posX > maxSizeX)
|
||||
{
|
||||
DebugTools.Assert(wordStartBreakIndex.HasValue,
|
||||
"wordStartBreakIndex can only be null if the word begins at a new line, in which case this branch shouldn't be reached as the word would be split due to being longer than a single line.");
|
||||
if (!wordStartBreakIndex.HasValue)
|
||||
{
|
||||
Logger.Error(
|
||||
"Assert fail inside RichTextEntry.Update, " +
|
||||
"wordStartBreakIndex is null on method end w/ word wrap required. " +
|
||||
"Dumping relevant stuff. Send this to PJB.");
|
||||
Logger.Error($"Message: {Message}");
|
||||
Logger.Error($"maxSizeX: {maxSizeX}");
|
||||
Logger.Error($"maxUsedWidth: {maxUsedWidth}");
|
||||
Logger.Error($"breakIndexCounter: {breakIndexCounter}");
|
||||
Logger.Error("wordStartBreakIndex: null (duh)");
|
||||
Logger.Error($"wordSizePixels: {wordSizePixels}");
|
||||
Logger.Error($"posX: {posX}");
|
||||
Logger.Error($"lastChar: {lastChar}");
|
||||
Logger.Error($"forceSplitData: {forceSplitData}");
|
||||
Logger.Error($"LineBreaks: {string.Join(", ", LineBreaks)}");
|
||||
|
||||
throw new Exception(
|
||||
"wordStartBreakIndex can only be null if the word begins at a new line," +
|
||||
"in which case this branch shouldn't be reached as" +
|
||||
"the word would be split due to being longer than a single line.");
|
||||
}
|
||||
|
||||
LineBreaks.Add(wordStartBreakIndex!.Value.index);
|
||||
Height += font.GetLineHeight(uiScale);
|
||||
maxUsedWidth = Math.Max(maxUsedWidth, wordStartBreakIndex.Value.lineSize);
|
||||
|
||||
@@ -4,7 +4,7 @@ using JetBrains.Annotations;
|
||||
|
||||
namespace Robust.Client.Utility
|
||||
{
|
||||
public static class UserDataDir
|
||||
internal static class UserDataDir
|
||||
{
|
||||
[Pure]
|
||||
public static string GetUserDataDir()
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Robust.Server.Console.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
internal sealed class RemoveCompCommand : IClientCommand
|
||||
{
|
||||
public string Command => "rmcomp";
|
||||
|
||||
@@ -40,17 +40,17 @@ namespace Robust.Server.GameObjects
|
||||
return (T)data[key];
|
||||
}
|
||||
|
||||
public override bool TryGetData<T>(Enum key, [MaybeNullWhen(false)] out T data)
|
||||
public override bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
return TryGetData(key, out data);
|
||||
}
|
||||
|
||||
public override bool TryGetData<T>(string key, [MaybeNullWhen(false)] out T data)
|
||||
public override bool TryGetData<T>(string key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
return TryGetData(key, out data);
|
||||
}
|
||||
|
||||
bool TryGetData<T>(object key, [MaybeNullWhen(false)] out T data)
|
||||
private bool TryGetData<T>(object key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
if (this.data.TryGetValue(key, out var dat))
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Mime;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
@@ -234,12 +235,12 @@ namespace Robust.Server.ServerStatus
|
||||
return serializer.Deserialize<T>(jsonReader);
|
||||
}
|
||||
|
||||
public void Respond(string text, HttpStatusCode code = HttpStatusCode.OK, string contentType = "text/plain")
|
||||
public void Respond(string text, HttpStatusCode code = HttpStatusCode.OK, string contentType = MediaTypeNames.Text.Plain)
|
||||
{
|
||||
Respond(text, (int) code, contentType);
|
||||
}
|
||||
|
||||
public void Respond(string text, int code = 200, string contentType = "text/plain")
|
||||
public void Respond(string text, int code = 200, string contentType = MediaTypeNames.Text.Plain)
|
||||
{
|
||||
_context.Response.StatusCode = code;
|
||||
_context.Response.ContentType = contentType;
|
||||
@@ -263,6 +264,8 @@ namespace Robust.Server.ServerStatus
|
||||
{
|
||||
using var streamWriter = new StreamWriter(_context.Response.OutputStream, EncodingHelpers.UTF8);
|
||||
|
||||
_context.Response.ContentType = MediaTypeNames.Application.Json;
|
||||
|
||||
using var jsonWriter = new JsonTextWriter(streamWriter);
|
||||
|
||||
JsonSerializer.Serialize(jsonWriter, jsonData);
|
||||
|
||||
@@ -306,9 +306,14 @@ namespace Robust.Shared.Configuration
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetCVar(string name, object value)
|
||||
{
|
||||
SetCVarInternal(name, value);
|
||||
}
|
||||
|
||||
private void SetCVarInternal(string name, object value, bool allowSecure = false)
|
||||
{
|
||||
//TODO: Make flags work, required non-derpy net system.
|
||||
if (_configVars.TryGetValue(name, out var cVar) && cVar.Registered && (cVar.Flags & CVar.SECURE) == 0)
|
||||
if (_configVars.TryGetValue(name, out var cVar) && cVar.Registered && (allowSecure || (cVar.Flags & CVar.SECURE) == 0))
|
||||
{
|
||||
if (!Equals(cVar.OverrideValueParsed ?? cVar.Value, value))
|
||||
{
|
||||
@@ -348,6 +353,18 @@ namespace Robust.Shared.Configuration
|
||||
throw new InvalidConfigurationException($"Trying to get unregistered variable '{name}'");
|
||||
}
|
||||
|
||||
public void SetSecureCVar(string name, object value)
|
||||
{
|
||||
SetCVarInternal(name, value, allowSecure: true);
|
||||
}
|
||||
|
||||
|
||||
public void SetSecureCVar<T>(CVarDef<T> def, T value) where T : notnull
|
||||
{
|
||||
SetSecureCVar(def.Name, value);
|
||||
}
|
||||
|
||||
|
||||
public T GetCVar<T>(CVarDef<T> def) where T : notnull
|
||||
{
|
||||
return GetCVar<T>(def.Name);
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Robust.Shared.ContentPack
|
||||
var fullPath = mountPath / filePath;
|
||||
Logger.DebugS("res.mod", $"Found module '{fullPath}'");
|
||||
|
||||
var asmFile = _res.ContentFileRead(fullPath);
|
||||
using var asmFile = _res.ContentFileRead(fullPath);
|
||||
var (asmRefs, asmName) = GetAssemblyReferenceData(asmFile);
|
||||
|
||||
if (!files.TryAdd(asmName, (fullPath, asmRefs)))
|
||||
@@ -118,8 +118,8 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
else
|
||||
{
|
||||
var assemblyStream = _res.ContentFileRead(path);
|
||||
var symbolsStream = _res.ContentFileReadOrNull(path.WithExtension("pdb"));
|
||||
using var assemblyStream = _res.ContentFileRead(path);
|
||||
using var symbolsStream = _res.ContentFileReadOrNull(path.WithExtension("pdb"));
|
||||
LoadGameAssembly(assemblyStream, symbolsStream, skipVerify: true);
|
||||
}
|
||||
}
|
||||
@@ -241,16 +241,34 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
if (_res.TryContentFileRead(dllPath, out var gameDll))
|
||||
{
|
||||
Logger.DebugS("srv", $"Loading {assemblyName} DLL");
|
||||
|
||||
// see if debug info is present
|
||||
if (_res.TryContentFileRead(new ResourcePath($@"/Assemblies/{assemblyName}.pdb"),
|
||||
out var gamePdb))
|
||||
using (gameDll)
|
||||
{
|
||||
Logger.DebugS("srv", $"Loading {assemblyName} DLL");
|
||||
|
||||
// see if debug info is present
|
||||
if (_res.TryContentFileRead(new ResourcePath($@"/Assemblies/{assemblyName}.pdb"),
|
||||
out var gamePdb))
|
||||
{
|
||||
using (gamePdb)
|
||||
{
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
LoadGameAssembly(gameDll, gamePdb);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("srv", $"Exception loading DLL {assemblyName}.dll: {e.ToStringBetter()}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
LoadGameAssembly(gameDll, gamePdb);
|
||||
LoadGameAssembly(gameDll);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -259,18 +277,6 @@ namespace Robust.Shared.ContentPack
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
LoadGameAssembly(gameDll);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("srv", $"Exception loading DLL {assemblyName}.dll: {e.ToStringBetter()}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.WarningS("eng", $"Could not load {assemblyName} DLL: {dllPath} does not exist in the VFS.");
|
||||
|
||||
@@ -216,7 +216,13 @@ namespace Robust.Shared.ContentPack
|
||||
/// <inheritdoc />
|
||||
public bool ContentFileExists(ResourcePath path)
|
||||
{
|
||||
return TryContentFileRead(path, out var _);
|
||||
if (TryContentFileRead(path, out var stream))
|
||||
{
|
||||
stream.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -442,6 +442,7 @@ Types:
|
||||
IsExternalInit: { All: True }
|
||||
IsReadOnlyAttribute: { All: True }
|
||||
IteratorStateMachineAttribute: { All: True }
|
||||
PreserveBaseOverridesAttribute: { All: True }
|
||||
RuntimeCompatibilityAttribute: { All: True }
|
||||
RuntimeHelpers: { All: True }
|
||||
TaskAwaiter: { All: True }
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace Robust.Shared.GameObjects.Components.Appearance
|
||||
public abstract T GetData<T>(string key);
|
||||
public abstract T GetData<T>(Enum key);
|
||||
|
||||
public abstract bool TryGetData<T>(string key, [MaybeNullWhen(false)] out T data);
|
||||
public abstract bool TryGetData<T>(Enum key, [MaybeNullWhen(false)] out T data);
|
||||
public abstract bool TryGetData<T>(string key, [NotNullWhen(true)] out T data);
|
||||
public abstract bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected class AppearanceComponentState : ComponentState
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
@@ -41,6 +41,7 @@ namespace Robust.Shared.GameObjects.Components
|
||||
/// </summary>
|
||||
bool Anchored { get; set; }
|
||||
|
||||
[Obsolete("Use AnchoredChangedMessage instead")]
|
||||
event Action? AnchoredChanged;
|
||||
|
||||
bool Predict { get; set; }
|
||||
@@ -344,11 +345,15 @@ namespace Robust.Shared.GameObjects.Components
|
||||
return;
|
||||
|
||||
_anchored = value;
|
||||
#pragma warning disable 618
|
||||
AnchoredChanged?.Invoke();
|
||||
#pragma warning restore 618
|
||||
SendMessage(new AnchoredChangedMessage(Anchored));
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use AnchoredChangedMessage instead")]
|
||||
public event Action? AnchoredChanged;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -518,4 +523,14 @@ namespace Robust.Shared.GameObjects.Components
|
||||
return !Anchored && Mass > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class AnchoredChangedMessage : ComponentMessage
|
||||
{
|
||||
public readonly bool Anchored;
|
||||
|
||||
public AnchoredChangedMessage(bool anchored)
|
||||
{
|
||||
Anchored = anchored;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ namespace Robust.Shared.GameObjects.Components.Timers
|
||||
/// <param name="cancellationToken"></param>
|
||||
public static void SpawnTimer(this IEntity entity, int milliseconds, Action onFired, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (entity.Deleted)
|
||||
return;
|
||||
|
||||
entity
|
||||
.EnsureComponent<TimerComponent>()
|
||||
.Spawn(milliseconds, onFired, cancellationToken);
|
||||
|
||||
@@ -583,7 +583,11 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
|
||||
internal void ChangeMapId(MapId newMapId)
|
||||
{
|
||||
if (newMapId == MapID)
|
||||
return;
|
||||
|
||||
var oldMapId = MapID;
|
||||
|
||||
MapID = newMapId;
|
||||
MapIdChanged(oldMapId);
|
||||
UpdateChildMapIdsRecursive(MapID, Owner.EntityManager.ComponentManager);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Robust.Shared.Interfaces.Configuration
|
||||
{
|
||||
@@ -9,6 +10,10 @@ namespace Robust.Shared.Interfaces.Configuration
|
||||
void LoadCVarsFromAssembly(Assembly assembly);
|
||||
|
||||
T GetSecureCVar<T>(string name);
|
||||
|
||||
void SetSecureCVar(string name, object value);
|
||||
void SetSecureCVar<T>(CVarDef<T> def, T value) where T : notnull;
|
||||
|
||||
void Initialize(bool isServer);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -663,7 +663,6 @@ namespace Robust.Shared.Network
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
await _serializer.Handshake(channel);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Robust.Shared.Reflection
|
||||
|
||||
private readonly Dictionary<string, Type> _looseTypeCache = new();
|
||||
|
||||
private readonly Dictionary<string, Enum> _enumCache = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<Type> GetAllChildren<T>(bool inclusive = false)
|
||||
{
|
||||
@@ -179,8 +181,13 @@ namespace Robust.Shared.Reflection
|
||||
}
|
||||
|
||||
reference = reference.Substring(5);
|
||||
|
||||
if (_enumCache.TryGetValue(reference, out @enum))
|
||||
return true;
|
||||
|
||||
var dotIndex = reference.LastIndexOf('.');
|
||||
var typeName = reference.Substring(0, dotIndex);
|
||||
|
||||
var value = reference.Substring(dotIndex + 1);
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
@@ -193,6 +200,7 @@ namespace Robust.Shared.Reflection
|
||||
}
|
||||
|
||||
@enum = (Enum) Enum.Parse(type, value);
|
||||
_enumCache[reference] = @enum;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +52,26 @@ namespace Robust.UnitTesting
|
||||
assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared"));
|
||||
assemblies.Add(Assembly.GetExecutingAssembly());
|
||||
|
||||
var configurationManager = IoCManager.Resolve<IConfigurationManagerInternal>();
|
||||
|
||||
configurationManager.Initialize(Project == UnitTestProject.Server);
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
IoCManager.Resolve<IConfigurationManagerInternal>().LoadCVarsFromAssembly(assembly);
|
||||
configurationManager.LoadCVarsFromAssembly(assembly);
|
||||
}
|
||||
|
||||
var contentAssemblies = GetContentAssemblies();
|
||||
|
||||
foreach (var assembly in contentAssemblies)
|
||||
{
|
||||
configurationManager.LoadCVarsFromAssembly(assembly);
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IReflectionManager>().LoadAssemblies(assemblies);
|
||||
|
||||
var modLoader = IoCManager.Resolve<TestingModLoader>();
|
||||
modLoader.Assemblies = GetContentAssemblies();
|
||||
modLoader.Assemblies = contentAssemblies;
|
||||
modLoader.TryLoadModulesFrom(ResourcePath.Root, "");
|
||||
|
||||
// Required components for the engine to work
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
|
||||
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user