generated from max/template-unity-project
ulong and grid list wrapper test
- wrapped lists in serialized dicts do work, maybe wrap anything. - note: maybe convert long fields to string fields to support ulong?
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VertexColor.ScenePartition
|
||||
@ -14,16 +13,18 @@ namespace VertexColor.ScenePartition
|
||||
|
||||
public SceneGridDictionary Grid => grid;
|
||||
|
||||
public void Insert(long scenePartitionId, Vector3 point)
|
||||
public void Insert(ulong scenePartitionId, Vector3 point)
|
||||
{
|
||||
int gridId = CalculateGridPosition(point, cellSize);
|
||||
if (grid.TryGetValue(gridId, out List<long> ids))
|
||||
if (grid.TryGetValue(gridId, out GridList ids))
|
||||
{
|
||||
ids.Add(scenePartitionId);
|
||||
ids.list.Add(scenePartitionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
grid.Add(gridId, new List<long> { scenePartitionId });
|
||||
var l = new GridList();
|
||||
l.list.Add(scenePartitionId);
|
||||
grid.Add(gridId, l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,5 +65,20 @@ namespace VertexColor.ScenePartition
|
||||
|
||||
return (x, y);
|
||||
}
|
||||
|
||||
public static ulong ULongPairToULong(ulong x, ulong y)
|
||||
{
|
||||
// Combine x and y components into a single ulong
|
||||
return (x << 32) | (uint)y;
|
||||
}
|
||||
|
||||
public static (ulong, ulong) ULongToULongPair(ulong value)
|
||||
{
|
||||
// Extract x and y components from the combined ulong
|
||||
ulong x = value >> 32;
|
||||
ulong y = (uint)value;
|
||||
|
||||
return (x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ namespace VertexColor.ScenePartition
|
||||
[System.Serializable]
|
||||
public class ScenePartition
|
||||
{
|
||||
public long id = 0;
|
||||
//public long classId = 0;
|
||||
public string filePath = null;
|
||||
public ulong id = 0;
|
||||
//public ulong classId = 0;
|
||||
public string filePath = null; // TODO: Only store relative path.
|
||||
//public string[] data = null;
|
||||
public LongSortedSet references = new LongSortedSet();
|
||||
|
||||
@ -45,7 +45,7 @@ namespace VertexColor.ScenePartition
|
||||
Match match = Regex.Match(data[0], pattern);
|
||||
|
||||
if (!match.Success) return;
|
||||
if (!long.TryParse(match.Groups[1].Value, out id)) return;
|
||||
if (!ulong.TryParse(match.Groups[1].Value, out id)) return;
|
||||
}
|
||||
|
||||
//{ // Get class id.
|
||||
@ -68,7 +68,7 @@ namespace VertexColor.ScenePartition
|
||||
|
||||
if (!match.Success) continue;
|
||||
|
||||
if (long.TryParse(match.Groups[1].Value, out long fileNumber))
|
||||
if (ulong.TryParse(match.Groups[1].Value, out ulong fileNumber))
|
||||
{
|
||||
if (fileNumber == 0) continue; // 0 == nothing.
|
||||
|
||||
|
@ -3,11 +3,17 @@ using System.Collections.Generic;
|
||||
namespace VertexColor.ScenePartition
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ScenePartitionSortedList : SerializableSortedList<long, ScenePartition> { }
|
||||
public class ScenePartitionSortedList : SerializableSortedList<ulong, ScenePartition> { }
|
||||
|
||||
[System.Serializable]
|
||||
public class LongSortedSet : SerializableSortedSet<long> { }
|
||||
public class LongSortedSet : SerializableSortedSet<ulong> { }
|
||||
|
||||
[System.Serializable]
|
||||
public class SceneGridDictionary : SerializableDictionary<int, List<long>> { }
|
||||
public class SceneGridDictionary : SerializableDictionary<int, GridList> { }
|
||||
|
||||
[System.Serializable]
|
||||
public class GridList
|
||||
{
|
||||
public List<ulong> list = new List<ulong>();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user