Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i233 Deep Migration Warning #237

Merged
merged 4 commits into from
May 2, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Anvil.CSharp.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using Unity.Jobs;
using UnityEngine;
using Debug = UnityEngine.Debug;

namespace Anvil.Unity.DOTS.Entities
{
Expand Down Expand Up @@ -175,6 +178,8 @@ public static void RegisterForEntityPatching(Type type)
{
throw new InvalidOperationException($"Type {type.GetReadableName()} must be a value type in order to register for Entity Patching.");
}

ScanForCollections(string.Empty, type);

long typeHash = BurstRuntime.GetHashCode64(type);
//We've already added this type, no need to do so again
Expand Down Expand Up @@ -210,6 +215,29 @@ public static void RegisterForEntityPatching(Type type)
//our shared statics
UpdateSharedStatics();
}

//TODO: #233 - This likely won't be a safety function when fully implemented as we'll need to store the type offsets for patching
[Conditional("ANVIL_DEBUG_SAFETY")]
private static void ScanForCollections(string parentPathString, Type type)
{
//One of these fields might be a collection or contain a collection, best way to tell is to scan it and see if it has a pointer
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo field in fields)
{
Type fieldType = field.FieldType;
if (fieldType.IsPrimitive)
{
continue;
}
if (fieldType.IsPointer)
{
//TODO: #233 - Update instructions when implemented.
Debug.LogWarning($"{parentPathString}/{type.GetReadableName()} has a field named {field.Name} which is a pointer. This is probably a collection. As a result, we cannot automatically patch any entity references inside this collection.");
continue;
}
ScanForCollections($"{parentPathString}/{type.GetReadableName()}", fieldType);
}
}

//*************************************************************************************************************
// HELPER TYPES
Expand Down