Browse Source

Chunk and cluster fixes and improvements & bump version

Added Cluster.GetSimBodies() and SimBody.GetBlocks()
Fixed some issues with IDs and bad handling of them
tags/v1.6.0
NorbiPeti 4 years ago
parent
commit
abbb83da26
5 changed files with 69 additions and 12 deletions
  1. +4
    -2
      GamecraftModdingAPI/Block.cs
  2. +19
    -3
      GamecraftModdingAPI/Blocks/BlockEngine.cs
  3. +33
    -0
      GamecraftModdingAPI/Cluster.cs
  4. +1
    -5
      GamecraftModdingAPI/GamecraftModdingAPI.csproj
  5. +12
    -2
      GamecraftModdingAPI/SimBody.cs

+ 4
- 2
GamecraftModdingAPI/Block.cs View File

@@ -372,11 +372,13 @@ namespace GamecraftModdingAPI
/// Returns the rigid body of the chunk of blocks this one belongs to during simulation.
/// Can be used to apply forces or move the block around while the simulation is running.
/// </summary>
/// <returns>The SimBody of the chunk or null if the block doesn't exist.</returns>
/// <returns>The SimBody of the chunk or null if the block doesn't exist or not in simulation mode.</returns>
public SimBody GetSimBody()
{
return BlockEngine.GetBlockInfo(this,
(GridConnectionsEntityStruct st) => new SimBody(st.machineRigidBodyId, st.clusterId));
(GridConnectionsEntityStruct st) => st.machineRigidBodyId != uint.MaxValue
? new SimBody(st.machineRigidBodyId, st.clusterId)
: null);
}

private void OnPlacedInit(object sender, BlockPlacedRemovedEventArgs e)


+ 19
- 3
GamecraftModdingAPI/Blocks/BlockEngine.cs View File

@@ -218,7 +218,7 @@ namespace GamecraftModdingAPI.Blocks
}
}

return bodies.Select(id => new SimBody(id)).ToArray();
return bodies.Select(id => new SimBody(id, cid)).ToArray();
}

public EGID? FindBlockEGID(uint id)
@@ -239,8 +239,8 @@ namespace GamecraftModdingAPI.Blocks
foreach (var (coll, _) in groups)
{
foreach (var conn in coll)
{
if (conn.machineRigidBodyId == sbid)
{ //Static blocks don't have a cluster ID but the cluster destruction manager should have one
if (conn.machineRigidBodyId == sbid && conn.clusterId != uint.MaxValue)
return new Cluster(conn.clusterId);
}
}
@@ -248,6 +248,22 @@ namespace GamecraftModdingAPI.Blocks
return null;
}

public Block[] GetBodyBlocks(uint sbid)
{
var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
var set = new HashSet<Block>();
foreach (var (coll, _) in groups)
{
foreach (var conn in coll)
{
if (conn.machineRigidBodyId == sbid)
set.Add(new Block(conn.ID));
}
}

return set.ToArray();
}

#if DEBUG
public EntitiesDB GetEntitiesDB()
{


+ 33
- 0
GamecraftModdingAPI/Cluster.cs View File

@@ -6,6 +6,7 @@ namespace GamecraftModdingAPI
{
/// <summary>
/// Represnts a cluster of blocks in time running mode, meaning blocks that are connected either directly or via joints.
/// Only exists if a cluster destruction manager is present. Static blocks like grass and dirt aren't part of a cluster.
/// </summary>
public class Cluster
{
@@ -37,5 +38,37 @@ namespace GamecraftModdingAPI
get => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(Id).healthMultiplier;
set => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(Id).healthMultiplier = value;
}

/// <summary>
/// Returns the simulation-time rigid bodies for the chunks in this cluster.
/// </summary>
/// <returns>An array of sim-bodies</returns>
public SimBody[] GetSimBodies()
{
return Block.BlockEngine.GetClusterBodies(Id.entityID);
}

public override string ToString()
{
return $"{nameof(Id)}: {Id}";
}

protected bool Equals(Cluster other)
{
return Id.Equals(other.Id);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Cluster) obj);
}

public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}

+ 1
- 5
GamecraftModdingAPI/GamecraftModdingAPI.csproj View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.5.0</Version>
<Version>1.6.0</Version>
<Authors>Exmods</Authors>
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>
@@ -445,10 +445,6 @@
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX_TextBlock.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX_TextBlock.dll</HintPath>
</Reference>
<Reference Include="RobocratX.SimulationCompositionRoot">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll</HintPath>
</Reference>
<Reference Include="SpawningPointCompositionRoot">
<HintPath>..\ref\Gamecraft_Data\Managed\SpawningPointCompositionRoot.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\SpawningPointCompositionRoot.dll</HintPath>


+ 12
- 2
GamecraftModdingAPI/SimBody.cs View File

@@ -17,12 +17,13 @@ namespace GamecraftModdingAPI
public EGID Id { get; }

/// <summary>
/// The cluster this chunk belongs to, or null if the chunk doesn't exist. Get the SimBody from a Block if possible for good performance here.
/// The cluster this chunk belongs to, or null if no cluster destruction manager present or the chunk doesn't exist.
/// Get the SimBody from a Block if possible for good performance here.
/// </summary>
public Cluster Cluster => cluster ?? (cluster = clusterId == uint.MaxValue ? Block.BlockEngine.GetCluster(Id.entityID) : new Cluster(clusterId));

private Cluster cluster;
private uint clusterId;
private readonly uint clusterId = uint.MaxValue;

public SimBody(EGID id)
{
@@ -120,6 +121,15 @@ namespace GamecraftModdingAPI
return Block.BlockEngine.GetConnectedSimBodies(Id.entityID);
}

/// <summary>
/// The blocks that form this rigid body.
/// </summary>
/// <returns></returns>
public Block[] GetBlocks()
{
return Block.BlockEngine.GetBodyBlocks(Id.entityID);
}

private ref RigidBodyEntityStruct GetStruct()
{
return ref Block.BlockEngine.GetBlockInfo<RigidBodyEntityStruct>(Id);


Loading…
Cancel
Save