From 83427b806e60f7a544af85432a83eff2fb6ce784 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 28 Apr 2020 15:55:08 +0200 Subject: [PATCH] Update to Gamecraft 2020.04.27.14.21 --- GamecraftModdingAPI/Blocks/PlacementEngine.cs | 2 +- GamecraftModdingAPI/Blocks/SignalEngine.cs | 74 +++++++++++-------- .../Events/ModEventEntityStruct.cs | 2 +- .../GamecraftModdingAPI.csproj | 4 +- GamecraftModdingAPI/Utility/FullGameFields.cs | 8 +- 5 files changed, 51 insertions(+), 39 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index 0b9293c..879141c 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -92,7 +92,7 @@ namespace GamecraftModdingAPI.Blocks break; } - EntityStructInitializer + EntityComponentInitializer structInitializer = _blockEntityFactory.Build(newBlockID, dbid); //The ghost block index is only used for triggers if (colour.indexInPalette != byte.MaxValue) diff --git a/GamecraftModdingAPI/Blocks/SignalEngine.cs b/GamecraftModdingAPI/Blocks/SignalEngine.cs index 3b732ba..b40b0bb 100644 --- a/GamecraftModdingAPI/Blocks/SignalEngine.cs +++ b/GamecraftModdingAPI/Blocks/SignalEngine.cs @@ -56,12 +56,8 @@ namespace GamecraftModdingAPI.Blocks public bool SetSignal(uint signalID, float signal, bool input = true) { - ExclusiveGroup group = input ? NamedExclusiveGroup.Group : NamedExclusiveGroup.Group; - if (entitiesDB.Exists(signalID, group)) - { - entitiesDB.QueryEntity(signalID, group).anyChannel.valueAsFloat = signal; - return true; - } + var array = GetSignalStruct(signalID, out uint index, input); + if (array != null) array[index].valueAsFloat = signal; return false; } @@ -73,25 +69,27 @@ namespace GamecraftModdingAPI.Blocks public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true) { - ExclusiveGroup group = input ? NamedExclusiveGroup.Group : NamedExclusiveGroup.Group; - if (entitiesDB.Exists(signalID, group)) - { - ref PortEntityStruct pes = ref entitiesDB.QueryEntity(signalID, group); - pes.anyChannel.valueAsFloat += signal; - if (clamp) - { - if (pes.anyChannel.valueAsFloat > Signals.POSITIVE_HIGH) - { - pes.anyChannel.valueAsFloat = Signals.POSITIVE_HIGH; - } - else if (pes.anyChannel.valueAsFloat < Signals.NEGATIVE_HIGH) - { - pes.anyChannel.valueAsFloat = Signals.NEGATIVE_HIGH; - } - return pes.anyChannel.valueAsFloat; - } - } - return signal; + var array = GetSignalStruct(signalID, out uint index, input); + if (array != null) + { + ref var channelData = ref array[index]; + channelData.valueAsFloat += signal; + if (clamp) + { + if (channelData.valueAsFloat > Signals.POSITIVE_HIGH) + { + channelData.valueAsFloat = Signals.POSITIVE_HIGH; + } + else if (channelData.valueAsFloat < Signals.NEGATIVE_HIGH) + { + channelData.valueAsFloat = Signals.NEGATIVE_HIGH; + } + + return channelData.valueAsFloat; + } + } + + return signal; } public float GetSignal(EGID blockID, out uint signalID, bool input = true) @@ -102,12 +100,8 @@ namespace GamecraftModdingAPI.Blocks public float GetSignal(uint signalID, bool input = true) { - ExclusiveGroup group = input ? NamedExclusiveGroup.Group : NamedExclusiveGroup.Group; - if (entitiesDB.Exists(signalID, group)) - { - return entitiesDB.QueryEntity(signalID, group).anyChannel.valueAsFloat; - } - return 0f; + var array = GetSignalStruct(signalID, out uint index, input); + return array?[index].valueAsFloat ?? 0f; } public uint[] GetSignalIDs(EGID blockID, bool input = true) @@ -147,5 +141,23 @@ namespace GamecraftModdingAPI.Blocks } return res; } + + private ChannelDataStruct[] GetSignalStruct(uint signalID, out uint index, bool input = true) + { + ExclusiveGroup group = input + ? NamedExclusiveGroup.Group + : NamedExclusiveGroup.Group; + if (entitiesDB.Exists(signalID, group)) + { + index = entitiesDB.QueryEntity(signalID, group).anyChannelIndex; + ChannelDataStruct[] channelData = entitiesDB + .QueryEntities(NamedExclusiveGroup.Group) + .ToFastAccess(out uint _); + return channelData; + } + + index = 0; + return null; + } } } diff --git a/GamecraftModdingAPI/Events/ModEventEntityStruct.cs b/GamecraftModdingAPI/Events/ModEventEntityStruct.cs index 03bd65f..cc945ec 100644 --- a/GamecraftModdingAPI/Events/ModEventEntityStruct.cs +++ b/GamecraftModdingAPI/Events/ModEventEntityStruct.cs @@ -11,7 +11,7 @@ namespace GamecraftModdingAPI.Events /// /// The event entity struct /// - public struct ModEventEntityStruct : IEntityStruct, INeedEGID + public struct ModEventEntityStruct : IEntityComponent, INeedEGID { /// /// The type of event that has been emitted diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index 4371236..e6bec2b 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -232,8 +232,8 @@ ..\ref\Gamecraft_Data\Managed\StringFormatter.dll - - ..\ref\Gamecraft_Data\Managed\Svelto.Common.dll + + ..\ref\Gamecraft_Data\Managed\Svelto.Common_3.dll ..\ref\Gamecraft_Data\Managed\Svelto.ECS.Debugger.dll diff --git a/GamecraftModdingAPI/Utility/FullGameFields.cs b/GamecraftModdingAPI/Utility/FullGameFields.cs index d90ef44..377f451 100644 --- a/GamecraftModdingAPI/Utility/FullGameFields.cs +++ b/GamecraftModdingAPI/Utility/FullGameFields.cs @@ -64,11 +64,11 @@ namespace GamecraftModdingAPI.Utility } } - public static SimpleSubmissionEntityViewScheduler _mainGameSubmissionScheduler + public static SimpleEntitiesSubmissionScheduler _mainGameSubmissionScheduler { get { - return (SimpleSubmissionEntityViewScheduler)fgcr?.Field("_mainGameSubmissionScheduler").GetValue(); + return (SimpleEntitiesSubmissionScheduler)fgcr?.Field("_sub").Field("_mainGameSubmissionScheduler").GetValue(); } } @@ -112,13 +112,13 @@ namespace GamecraftModdingAPI.Utility } } - public static UnityEntitySubmissionScheduler _frontEndSubmissionScheduler + /*public static UnityEntitySubmissionScheduler _frontEndSubmissionScheduler { get { return (UnityEntitySubmissionScheduler)fgcr?.Field("_frontEndSubmissionScheduler").GetValue(); } - } + }*/ public static LoadingScreenImplementer _loadingScreen {