Remove AsyncUtils, fix FlyCam and GetThingLookedAt()

This commit is contained in:
Norbi Peti 2021-05-03 01:25:26 +02:00
parent 62afd3b780
commit aea3ef3623
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 9 additions and 109 deletions

View file

@ -28,8 +28,6 @@ namespace TechbloxModdingAPI.Events
{ {
// register custom game engines // register custom game engines
GameEngineManager.RegisterEngines(enginesRoot); GameEngineManager.RegisterEngines(enginesRoot);
// initialize AsyncUtils
AsyncUtils.Setup(enginesRoot);
// A new EnginesRoot is always created when ActivateGame is called // A new EnginesRoot is always created when ActivateGame is called
// so all event emitters and handlers must be re-registered. // so all event emitters and handlers must be re-registered.
EventManager.RegisterEngines(enginesRoot); EventManager.RegisterEngines(enginesRoot);

View file

@ -84,11 +84,11 @@ namespace TechbloxModdingAPI
Input.FakeInput.Init(); Input.FakeInput.Init();
// init object-oriented classes // init object-oriented classes
Player.Init(); Player.Init();
FlyCam.Init();
Block.Init(); Block.Init();
BlockGroup.Init(); BlockGroup.Init();
Wire.Init(); Wire.Init();
GameClient.Init(); GameClient.Init();
AsyncUtils.Init();
Client.Init(); Client.Init();
Game.Init(); Game.Init();
//CustomBlock.Init(); //CustomBlock.Init();

View file

@ -386,8 +386,8 @@ namespace TechbloxModdingAPI
public Block GetBlockLookedAt(float maxDistance = -1f) public Block GetBlockLookedAt(float maxDistance = -1f)
{ {
var egid = playerEngine.GetThingLookedAt(Id, maxDistance); var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid.HasValue && egid.Value.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP return egid != EGID.Empty && egid.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP
? new Block(egid.Value) ? new Block(egid)
: null; : null;
} }
@ -399,8 +399,8 @@ namespace TechbloxModdingAPI
public SimBody GetSimBodyLookedAt(float maxDistance = -1f) public SimBody GetSimBodyLookedAt(float maxDistance = -1f)
{ {
var egid = playerEngine.GetThingLookedAt(Id, maxDistance); var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid.HasValue && egid.Value.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP return egid != EGID.Empty && egid.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP
? new SimBody(egid.Value) ? new SimBody(egid)
: null; : null;
} }

View file

@ -438,20 +438,20 @@ namespace TechbloxModdingAPI.Players
return false; return false;
} }
public EGID? GetThingLookedAt(uint playerId, float maxDistance = -1f) public EGID GetThingLookedAt(uint playerId, float maxDistance = -1f)
{ {
if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>( if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>(
CameraExclusiveGroups.CameraGroup, out var mapper)) CameraExclusiveGroups.CameraGroup, out var mapper))
return null; return EGID.Empty;
mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast); mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
float distance = maxDistance < 0 float distance = maxDistance < 0
? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast, ? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast,
GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize) GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize)
: maxDistance; : maxDistance;
if (rayCast.hit && rayCast.distance <= distance) 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) public unsafe Block[] GetSelectedBlocks(uint playerid)

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

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