Browse Source

Convert more things to use EcsObjectBase

Though the major benefit is only for blocks right now (using initializers)
tags/v2.0.0
NorbiPeti 3 years ago
parent
commit
b6b9a29a3c
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
4 changed files with 32 additions and 32 deletions
  1. +1
    -1
      TechbloxModdingAPI/Block.cs
  2. +5
    -4
      TechbloxModdingAPI/BlockGroup.cs
  3. +24
    -23
      TechbloxModdingAPI/FlyCam.cs
  4. +2
    -4
      TechbloxModdingAPI/Players/FlyCamEngine.cs

+ 1
- 1
TechbloxModdingAPI/Block.cs View File

@@ -431,7 +431,7 @@ namespace TechbloxModdingAPI
return;
}
blockGroup?.RemoveInternal(this);
BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this).currentBlockGroup = value?.Id ?? -1;
BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this).currentBlockGroup = (int?) value?.Id.entityID ?? -1;
value?.AddInternal(this);
blockGroup = value;
}


+ 5
- 4
TechbloxModdingAPI/BlockGroup.cs View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;

using Gamecraft.Blocks.BlockGroups;
using Svelto.ECS;
using Unity.Mathematics;
using UnityEngine;
using TechbloxModdingAPI.Blocks;
@@ -13,10 +14,10 @@ namespace TechbloxModdingAPI
/// <summary>
/// A group of blocks that can be selected together. The placed version of blueprints. Dispose after usage.
/// </summary>
public class BlockGroup : ICollection<Block>, IDisposable
public class BlockGroup : EcsObjectBase, ICollection<Block>, IDisposable
{
internal static BlueprintEngine _engine = new BlueprintEngine();
public int Id { get; }
public override EGID Id { get; }
private readonly Block sourceBlock;
private readonly List<Block> blocks;
private float3 position, rotation;
@@ -26,7 +27,7 @@ namespace TechbloxModdingAPI
{
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
throw new BlockException("Cannot create a block group for blocks without a group!");
Id = id;
Id = new EGID((uint) id, BlockGroupExclusiveGroups.BlockGroupEntityGroup);
sourceBlock = block;
blocks = new List<Block>(GetBlocks());
Block.Removed += OnBlockRemoved;
@@ -168,7 +169,7 @@ namespace TechbloxModdingAPI
internal void AddInternal(Block item)
{
blocks.Add(item);
_engine.AddBlockToGroup(item.Id, Id);
_engine.AddBlockToGroup(item.Id, (int) Id.entityID);
}

/// <summary>


+ 24
- 23
TechbloxModdingAPI/FlyCam.cs View File

@@ -1,4 +1,5 @@
using RobocraftX.Physics;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Techblox.FlyCam;
using TechbloxModdingAPI.Players;
@@ -8,13 +9,13 @@ using UnityEngine;

namespace TechbloxModdingAPI
{
public class FlyCam
public class FlyCam : EcsObjectBase
{
private static FlyCamEngine Engine = new FlyCamEngine();
public uint Id { get; }
public override EGID Id { get; }

public FlyCam(uint id) => Id = id;
public FlyCam(uint id) => Id = new EGID(id, Techblox.FlyCam.FlyCam.Group);

/// <summary>
/// The local player's camera.
@@ -26,11 +27,11 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 Position
{
get => Engine.GetComponent<PositionEntityStruct>(Id).Get().position;
get => Engine.GetComponent<PositionEntityStruct>(this).position;
set
{
Engine.GetComponent<PositionEntityStruct>(Id).Get().position = value;
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().position = value;
Engine.GetComponent<PositionEntityStruct>(this).position = value;
Engine.GetComponent<RigidBodyEntityStruct>(this).position = value;
}
}

@@ -39,11 +40,11 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 Rotation
{
get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation).eulerAngles;
get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(this).rotation).eulerAngles;
set
{
Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
Engine.GetComponent<RotationEntityStruct>(this).rotation = Quaternion.Euler(value);
Engine.GetComponent<RigidBodyEntityStruct>(this).rotation = Quaternion.Euler(value);
}
}

@@ -52,8 +53,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 MovementDirection
{
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection;
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection = value;
get => Engine.GetComponent<FlyCamMovementComponent>(this).movementDirection;
set => Engine.GetComponent<FlyCamMovementComponent>(this).movementDirection = value;
}

/// <summary>
@@ -61,8 +62,8 @@ namespace TechbloxModdingAPI
/// </summary>
public bool Sprinting
{
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting;
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting = value;
get => Engine.GetComponent<FlyCamMovementComponent>(this).sprinting;
set => Engine.GetComponent<FlyCamMovementComponent>(this).sprinting = value;
}
/// <summary>
@@ -70,8 +71,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float Speed
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed = value;
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speed;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speed = value;
}
/// <summary>
@@ -79,8 +80,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float SpeedSprintMultiplier
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier = value;
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speedSprintMultiplier;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speedSprintMultiplier = value;
}
/// <summary>
@@ -88,8 +89,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float Acceleration
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration = value;
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).acceleration;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).acceleration = value;
}
/// <summary>
@@ -97,8 +98,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 Velocity
{
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity = value;
get => Engine.GetComponent<RigidBodyEntityStruct>(this).velocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(this).velocity = value;
}
/// <summary>
@@ -106,8 +107,8 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 AngularVelocity
{
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
get => Engine.GetComponent<RigidBodyEntityStruct>(this).angularVelocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(this).angularVelocity = value;
}

public static void Init()


+ 2
- 4
TechbloxModdingAPI/Players/FlyCamEngine.cs View File

@@ -19,11 +19,9 @@ namespace TechbloxModdingAPI.Players
public string Name => "TechbloxModdingAPIFlyCamEngine";
public bool isRemovable => false;

public OptionalRef<T> GetComponent<T>(uint id) where T : unmanaged, IEntityComponent
public ref T GetComponent<T>(FlyCam cam) where T : unmanaged, IEntityComponent
{
if (entitiesDB.TryQueryEntitiesAndIndex<T>(id, Techblox.FlyCam.FlyCam.Group, out uint index, out var array))
return new OptionalRef<T>(array, index);
return new OptionalRef<T>();
return ref entitiesDB.QueryEntityOrDefault<T>(cam);
}
}
}

Loading…
Cancel
Save