Browse Source

Remove AsyncUtils, fix FlyCam and GetThingLookedAt()

tags/v2.0.0
NorbiPeti 3 years ago
parent
commit
aea3ef3623
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
6 changed files with 9 additions and 109 deletions
  1. +0
    -2
      TechbloxModdingAPI/Events/GameActivatedComposePatch.cs
  2. +1
    -1
      TechbloxModdingAPI/Main.cs
  3. +4
    -4
      TechbloxModdingAPI/Player.cs
  4. +4
    -4
      TechbloxModdingAPI/Players/PlayerEngine.cs
  5. +0
    -35
      TechbloxModdingAPI/Utility/AsyncUtils.cs
  6. +0
    -63
      TechbloxModdingAPI/Utility/AsyncUtilsEngine.cs

+ 0
- 2
TechbloxModdingAPI/Events/GameActivatedComposePatch.cs View File

@@ -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);


+ 1
- 1
TechbloxModdingAPI/Main.cs View File

@@ -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();


+ 4
- 4
TechbloxModdingAPI/Player.cs View File

@@ -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;
}



+ 4
- 4
TechbloxModdingAPI/Players/PlayerEngine.cs View File

@@ -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<CharacterCameraRayCastEntityStruct>(
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)


+ 0
- 35
TechbloxModdingAPI/Utility/AsyncUtils.cs View File

@@ -1,35 +0,0 @@
using System.Threading.Tasks;

using Svelto.ECS;

namespace TechbloxModdingAPI.Utility
{
public static class AsyncUtils
{
private static AsyncUtilsEngine gameEngine = new AsyncUtilsEngine();

/// <summary>
/// Waits for entity submission asynchronously.
/// Use after placing a block or otherwise creating things in the game to access their properties.
/// </summary>
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);
}
}
}

+ 0
- 63
TechbloxModdingAPI/Utility/AsyncUtilsEngine.cs View File

@@ -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<object> task)
{
/*var waitEnumerator = new WaitForSubmissionEnumerator(efu, efa, entitiesDB);
while (waitEnumerator.MoveNext())
yield return null;
task.SetResult(null);*/
yield break; //TODO
}

private IEnumerator WaitForNextFrameInternal(TaskCompletionSource<object> task)
{
yield return null;
task.SetResult(null);
}

public Task WaitForSubmission()
{
var task = new TaskCompletionSource<object>();
WaitForSubmissionInternal(_efu, _efa, entitiesDB, task).RunOn(ExtraLean.EveryFrameStepRunner_TimeStopped);
return task.Task;
}

public Task WaitForNextFrame()
{
var task = new TaskCompletionSource<object>();
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;
}
}

Loading…
Cancel
Save