diff --git a/TechbloxModdingAPI/Events/GameActivatedComposePatch.cs b/TechbloxModdingAPI/Events/GameActivatedComposePatch.cs index 8a32f37..3ee1143 100644 --- a/TechbloxModdingAPI/Events/GameActivatedComposePatch.cs +++ b/TechbloxModdingAPI/Events/GameActivatedComposePatch.cs @@ -28,8 +28,6 @@ namespace TechbloxModdingAPI.Events { // register custom game engines GameEngineManager.RegisterEngines(enginesRoot); - // initialize AsyncUtils - AsyncUtils.Setup(enginesRoot); // A new EnginesRoot is always created when ActivateGame is called // so all event emitters and handlers must be re-registered. EventManager.RegisterEngines(enginesRoot); diff --git a/TechbloxModdingAPI/Main.cs b/TechbloxModdingAPI/Main.cs index da66884..d6d6d3e 100644 --- a/TechbloxModdingAPI/Main.cs +++ b/TechbloxModdingAPI/Main.cs @@ -84,11 +84,11 @@ namespace TechbloxModdingAPI Input.FakeInput.Init(); // init object-oriented classes Player.Init(); + FlyCam.Init(); Block.Init(); BlockGroup.Init(); Wire.Init(); GameClient.Init(); - AsyncUtils.Init(); Client.Init(); Game.Init(); //CustomBlock.Init(); diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs index 2c6b122..01b5c24 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -386,8 +386,8 @@ namespace TechbloxModdingAPI public Block GetBlockLookedAt(float maxDistance = -1f) { var egid = playerEngine.GetThingLookedAt(Id, maxDistance); - return egid.HasValue && egid.Value.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP - ? new Block(egid.Value) + return egid != EGID.Empty && egid.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP + ? new Block(egid) : null; } @@ -399,8 +399,8 @@ namespace TechbloxModdingAPI public SimBody GetSimBodyLookedAt(float maxDistance = -1f) { var egid = playerEngine.GetThingLookedAt(Id, maxDistance); - return egid.HasValue && egid.Value.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP - ? new SimBody(egid.Value) + return egid != EGID.Empty && egid.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP + ? new SimBody(egid) : null; } diff --git a/TechbloxModdingAPI/Players/PlayerEngine.cs b/TechbloxModdingAPI/Players/PlayerEngine.cs index d71c3ee..f0c8a11 100644 --- a/TechbloxModdingAPI/Players/PlayerEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEngine.cs @@ -438,20 +438,20 @@ namespace TechbloxModdingAPI.Players return false; } - public EGID? GetThingLookedAt(uint playerId, float maxDistance = -1f) + public EGID GetThingLookedAt(uint playerId, float maxDistance = -1f) { if (!entitiesDB.TryQueryMappedEntities( CameraExclusiveGroups.CameraGroup, out var mapper)) - return null; + return EGID.Empty; mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast); float distance = maxDistance < 0 ? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast, GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize) : maxDistance; if (rayCast.hit && rayCast.distance <= distance) - return rayCast.hitEgid; + return rayCast.hitEgid; //May be EGID.Empty - return null; + return EGID.Empty; } public unsafe Block[] GetSelectedBlocks(uint playerid) diff --git a/TechbloxModdingAPI/Utility/AsyncUtils.cs b/TechbloxModdingAPI/Utility/AsyncUtils.cs deleted file mode 100644 index 4894515..0000000 --- a/TechbloxModdingAPI/Utility/AsyncUtils.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Threading.Tasks; - -using Svelto.ECS; - -namespace TechbloxModdingAPI.Utility -{ - public static class AsyncUtils - { - private static AsyncUtilsEngine gameEngine = new AsyncUtilsEngine(); - - /// - /// Waits for entity submission asynchronously. - /// Use after placing a block or otherwise creating things in the game to access their properties. - /// - public static async Task WaitForSubmission() - { - await gameEngine.WaitForSubmission(); - } - - public static async Task WaitForNextFrame() - { - await gameEngine.WaitForNextFrame(); - } - - public static void Setup(EnginesRoot enginesRoot) - { - gameEngine.Setup(enginesRoot.GenerateEntityFunctions(), enginesRoot.GenerateEntityFactory()); - } - - public static void Init() - { - GameEngineManager.AddGameEngine(gameEngine); - } - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Utility/AsyncUtilsEngine.cs b/TechbloxModdingAPI/Utility/AsyncUtilsEngine.cs deleted file mode 100644 index ee18ced..0000000 --- a/TechbloxModdingAPI/Utility/AsyncUtilsEngine.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections; -using System.Threading.Tasks; - -using RobocraftX.Schedulers; -using Svelto.ECS; -using Svelto.Tasks.ExtraLean; -using TechbloxModdingAPI.Engines; - -namespace TechbloxModdingAPI.Utility -{ - public class AsyncUtilsEngine : IApiEngine - { - private IEntityFunctions _efu; - private IEntityFactory _efa; - private IEnumerator WaitForSubmissionInternal(IEntityFunctions efu, IEntityFactory efa, - EntitiesDB entitiesDB, TaskCompletionSource task) - { - /*var waitEnumerator = new WaitForSubmissionEnumerator(efu, efa, entitiesDB); - while (waitEnumerator.MoveNext()) - yield return null; - task.SetResult(null);*/ - yield break; //TODO - } - - private IEnumerator WaitForNextFrameInternal(TaskCompletionSource task) - { - yield return null; - task.SetResult(null); - } - - public Task WaitForSubmission() - { - var task = new TaskCompletionSource(); - WaitForSubmissionInternal(_efu, _efa, entitiesDB, task).RunOn(ExtraLean.EveryFrameStepRunner_TimeStopped); - return task.Task; - } - - public Task WaitForNextFrame() - { - var task = new TaskCompletionSource(); - WaitForNextFrameInternal(task).RunOn(ExtraLean.EveryFrameStepRunner_TimeStopped); - return task.Task; - } - - public void Setup(IEntityFunctions efu, IEntityFactory efa) - { - _efu = efu; - _efa = efa; - } - - public void Ready() - { - } - - public EntitiesDB entitiesDB { get; set; } - public void Dispose() - { - } - - public string Name { get; } = "TechbloxModdingAPIAsyncUtilsGameEngine"; - public bool isRemovable { get; } = false; - } -} \ No newline at end of file