Browse Source

Fix picking block groups...

tags/v1.7.0
NorbiPeti 3 years ago
parent
commit
fad3b5cbf4
7 changed files with 48 additions and 112 deletions
  1. +1
    -4
      GamecraftModdingAPI/Block.cs
  2. +8
    -4
      GamecraftModdingAPI/BlockGroup.cs
  3. +36
    -19
      GamecraftModdingAPI/Blocks/BlueprintEngine.cs
  4. +1
    -1
      GamecraftModdingAPI/Blocks/PlacementEngine.cs
  5. +1
    -1
      GamecraftModdingAPI/GamecraftModdingAPI.csproj
  6. +0
    -82
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
  7. +1
    -1
      doxygen.conf

+ 1
- 4
GamecraftModdingAPI/Block.cs View File

@@ -365,7 +365,7 @@ namespace GamecraftModdingAPI

private BlockGroup blockGroup;
/// <summary>
/// Returns the block group this block is a part of. Block groups can be placed using blueprints.
/// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
/// Returns null if not part of a group.<br />
/// Setting the group after the block has been initialized will not update everything properly,
/// so you can only set this property on blocks newly placed by your code.<br />
@@ -385,9 +385,6 @@ namespace GamecraftModdingAPI
{
if (Exists)
{
/*var copy = Copy<Block>();
copy.BlockGroup = value; //It won't run this on the new instance as it won't 'exist' yet
Remove();*/
Logging.LogWarning("Attempted to set group of existing block. This is not supported."
+ " Copy the block and set the group of the resulting block.");
return;


+ 8
- 4
GamecraftModdingAPI/BlockGroup.cs View File

@@ -55,7 +55,7 @@ namespace GamecraftModdingAPI
}

/// <summary>
/// The position of the block group (center). Recalculated if blocks have been added/removed since the last query.
/// The position of the block group (center). Can only be used after initialization is complete.
/// </summary>
public float3 Position
{
@@ -78,7 +78,7 @@ namespace GamecraftModdingAPI
}

/// <summary>
/// The rotation of the block group. Recalculated if blocks have been added/removed since the last query.
/// The rotation of the block group. Can only be used after initialization is complete.
/// </summary>
public float3 Rotation
{
@@ -121,7 +121,7 @@ namespace GamecraftModdingAPI
/// <returns>A new block group containing the given block</returns>
public static BlockGroup Create(Block block)
{
var bg = new BlockGroup(_engine.CreateBlockGroup(default, default), block);
var bg = new BlockGroup(_engine.CreateBlockGroup(block.Position, Quaternion.Euler(block.Rotation)), block);
block.BlockGroup = bg;
return bg;
}
@@ -166,7 +166,11 @@ namespace GamecraftModdingAPI
item.BlockGroup = this; //Calls AddInternal
}

internal void AddInternal(Block item) => blocks.Add(item);
internal void AddInternal(Block item)
{
blocks.Add(item);
_engine.AddBlockToGroup(item.Id, Id);
}

/// <summary>
/// Removes all blocks from this group.


+ 36
- 19
GamecraftModdingAPI/Blocks/BlueprintEngine.cs View File

@@ -29,7 +29,8 @@ namespace GamecraftModdingAPI.Blocks

private NativeDynamicArray selectedBlocksInGroup;
private NativeHashSet<ulong> removedConnections = new NativeHashSet<ulong>();
private int addingToBlockGroup = -1;

private static readonly Type PlaceBlueprintUtilityType =
AccessTools.TypeByName("RobocraftX.CR.MachineEditing.PlaceBlueprintUtility");
private static readonly FieldInfo LocalBlockMap =
@@ -50,13 +51,14 @@ namespace GamecraftModdingAPI.Blocks
private static FasterList<EGID> globalBlockMap;
private static object SerializeGhostBlueprintInstance;
private static GhostChildEntityFactory BuildGhostBlueprintFactory;
public void Ready()
{
selectedBlocksInGroup = NativeDynamicArray.Alloc<EGID>(Allocator.Persistent);
}

public EntitiesDB entitiesDB { get; set; }

public void Dispose()
{
selectedBlocksInGroup.Dispose();
@@ -96,6 +98,20 @@ namespace GamecraftModdingAPI.Blocks
return nextFilterId;
}

public void AddBlockToGroup(EGID blockID, int groupID)
{
if (globalBlockMap == null)
globalBlockMap = FullGameFields._deserialisedBlockMap;
if (groupID != addingToBlockGroup)
{
Logging.MetaDebugLog("Changing current block group from " + addingToBlockGroup + " to " + groupID);
addingToBlockGroup = groupID;
globalBlockMap.Clear();
}

globalBlockMap.Add(blockID);
}

public void SelectBlueprint(uint resourceID)
{
if (resourceID == uint.MaxValue)
@@ -109,7 +125,7 @@ namespace GamecraftModdingAPI.Blocks
uint index = clipboardManager.AllocateSerializationData();
return index;
}
public void ReplaceBlueprint(uint playerID, uint blueprintID, ICollection<Block> selected, float3 pos, quaternion rot)
{
var blockIDs = new EGID[selected.Count];
@@ -131,14 +147,14 @@ namespace GamecraftModdingAPI.Blocks
//float3 bottomOffset = PlaceBlockUtility.GetBottomOffset(collider);
//var rootPosition = math.mul(groupTransform.blockGroupGridRotation, bottomOffset) + groupTransform.blockGroupGridPosition;
//var rootRotation = groupTransform.blockGroupGridRotation;
clipboardManager.SetGhostSerialized(blueprintID, false);
SelectionSerializationUtility.CopySelectionToClipboard(playerID, entitiesDB,
serializationData.blueprintData, entitySerialization, entityFactory, blockIDs,
(uint) blockIDs.Length, pos, rot, -1);
BuildGhostBlueprint(selected, pos, rot, playerID);
SerializeGhostBlueprint.Invoke(SerializeGhostBlueprintInstance, new object[] {playerID, blueprintID});
}

private void BuildGhostBlueprint(ICollection<Block> blocks, float3 pos, quaternion rot, uint playerID)
@@ -173,11 +189,12 @@ namespace GamecraftModdingAPI.Blocks
}
}
int nextFilterId1 = BlockGroupUtility.NextFilterId;
entityFactory.BuildEntity<BlockGroupEntityDescriptor>(new EGID((uint) nextFilterId1, BlockGroupExclusiveGroups.BlockGroupEntityGroup)).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridPosition = selectionPosition.position,
blockGroupGridRotation = selectionRotation.rotation
});
entityFactory.BuildEntity<BlockGroupEntityDescriptor>(new EGID((uint) nextFilterId1,
BlockGroupExclusiveGroups.BlockGroupEntityGroup)).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridPosition = selectionPosition.position,
blockGroupGridRotation = selectionRotation.rotation
});
var frot = Quaternion.Euler(rot);
var grid = new GridRotationStruct {position = pos, rotation = frot};
var poss = new PositionEntityStruct {position = pos};
@@ -284,17 +301,17 @@ namespace GamecraftModdingAPI.Blocks
}

[HarmonyPatch]
private static class BuildGhostBlueprintPatch
private static class BuildGhostBlueprintPatch
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}

public static MethodBase TargetMethod()
{RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
}

public IEntityFactory Factory { get; set; }


+ 1
- 1
GamecraftModdingAPI/Blocks/PlacementEngine.cs View File

@@ -107,7 +107,7 @@ namespace GamecraftModdingAPI.Blocks
belongsTo = 32U,
collidesWith = 239532U
});*/
PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer);
EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup);
ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID);


+ 1
- 1
GamecraftModdingAPI/GamecraftModdingAPI.csproj View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.8.0</Version>
<Version>1.7.0</Version>
<Authors>Exmods</Authors>
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>


+ 0
- 82
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs View File

@@ -410,88 +410,6 @@ namespace GamecraftModdingAPI.Tests
return ((Action) MinimumSpecsCheck.CheckRequirementsMet).Method;
}
}

[HarmonyPatch]
public class BugHuntPatch
{
public static MethodInfo method =
SymbolExtensions.GetMethodInfo<string>(str => Console.WriteLine(str));
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int i = 0;
foreach (var instruction in instructions)
{
i++;
yield return instruction; //Return the instruction first
//stloc, dup, callvirt
if (instruction.opcode.Name.ToLower().StartsWith("stloc")
|| instruction.opcode == OpCodes.Dup
|| instruction.opcode == OpCodes.Callvirt)
{
yield return new CodeInstruction(OpCodes.Ldstr,
"Just ran the " + i + ". instruction ending with " + instruction.opcode.Name);
yield return new CodeInstruction(OpCodes.Call, method);
}
}
}

public static MethodInfo TargetMethod()
{
return AccessTools.Method("RobocraftX.CR.MachineEditing.BoxSelect.CopySelectionEngine:GenerateThumbnail");
}
}

[HarmonyPatch]
public class BugHuntPatch2
{
public static void Prefix(int width, float fieldOfView, Vector3 cameraDirection, Vector3 lightDirection)
{
Console.WriteLine("TakeThumbnail invoked with parameters: " + width + ", " + fieldOfView + ", " +
cameraDirection + ", " + lightDirection);
GPUInstancerManager manager = GPUInstancerAPI.GetActiveManagers().Find(m => m is GPUInstancerPrefabManager);
Bounds instancesBounds = manager.ComputeInstancesBounds(2);
Console.WriteLine("Bounds: " + instancesBounds);
Console.WriteLine("Size: " + instancesBounds.size);
Console.WriteLine("Size.x < 0: " + (instancesBounds.size.x < 0));
}

public static void Postfix(Texture2D __result)
{
Console.WriteLine("TakeThumbnail returned: " + (__result == null ? null : __result.name));
}

private delegate Texture2D TakeThumbnailDel(int width, float fieldOfView, Vector3 cameraDirection,
Vector3 lightDirection);

public static MethodInfo TargetMethod()
{
return ((TakeThumbnailDel) ThumbnailUtility.TakeThumbnail).Method;
}
}

[HarmonyPatch]
public class BugHuntPatch3
{
public static void Prefix(int width, int filterLayerMask, GPUInstancerManager manager,
Vector3 cameraPosition, Quaternion cameraRotation, float cameraFov, Vector3 lightDirection,
int cullingLayer)
{
Console.WriteLine("Inner TakeThumbnail invoked with parameters: " + width + ", " + filterLayerMask +
", " + (manager != null ? manager.name : null) + ", " + cameraPosition + ", " +
cameraRotation + ", " + cameraFov + ", " + lightDirection + ", " + cullingLayer);
}

private delegate Texture2D TakeThumbnailDel(int width, int filterLayerMask, GPUInstancerManager manager,
Vector3 cameraPosition, Quaternion cameraRotation, float cameraFov, Vector3 lightDirection,
int cullingLayer);

public static MethodInfo TargetMethod()
{
return ((TakeThumbnailDel) ThumbnailUtility.TakeThumbnail).Method;
}
}
}
#endif
}

+ 1
- 1
doxygen.conf View File

@@ -38,7 +38,7 @@ PROJECT_NAME = "GamecraftModdingAPI"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "v1.8.0"
PROJECT_NUMBER = "v1.7.0"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a


Loading…
Cancel
Save