Объектные карты/альфа-карты имеют размер 5125123 = 786432 . Более полумиллиона точек данных с плавающей запятой.
Когда я вызываю SerializeObjects в своей структуре, сериализация 16 занимает 50 секунд. splatmap/альфа-карты. Общий размер файла 246 Мб. Поскольку я впервые делаю что-то подобное, я не уверен, что затраченное время на порядок меньше или находится в пределах разумных ожиданий относительно времени, которое потребуется для выполнения этой операции.Можете ли вы помочь мне выяснить, есть ли проблема с методологией?
Я использую Newtonsoft и специальные конвертеры.
Мне трудно понять, что такое общие критерии и как узнать, есть проблема с самим кодом. Я проверил вывод, и он кажется в порядке.
Фрагмент кода, в котором происходит сериализация
Код: Выделить всё
private void SaveTerrainCellData(string SaveName)
{
string saveName = $"{SaveName} - TerrainCellData";
string filePath = (Application.persistentDataPath + "/" + saveName + ".json");
string lines = null;
//Debug.Log(Application.persistentDataPath);
// Use custom converters
var settings = new JsonSerializerSettings
{
Converters = new JsonConverter[] { new Vector3Converter(), new StringEnumConverter() },
Formatting = Formatting.Indented
};
foreach (TerrainCellData data in this.terrainCellsData)
{
lines += JsonConvert.SerializeObject(data, settings);
}
File.WriteAllText(filePath, lines);
//await Task.Yield();
}
Код: Выделить всё
public struct TerrainCellData
{
[SerializeField] public string TerrainName;
[Header("--- Weather ---")]
public Weather Weather;
public float MinutesSinceWeatherChange;
[Header("--- Simulation ---")]
public Biome Biome;
public float WaterLevel;
public float SunLevel;
public int DirtPatchCount;
public int GrassPatchCount;
public List DirtAlphaMapGridID;
public List GrassAlphaMapGridID;
public Vector3 TrailingGrassPatch;
public Vector3 TrailingDirtPatch;
public Dictionary TrailingPlants;
public int TrailingGrassPlantIndex;
public float[,,] OriginalSplatmapData;
public Dictionary AlphaMapGrid;
public float[,,] AlphaMap;
public void WriteData(string TerrainName,
Weather Weather,
float MinutesSinceWeatherChange,
Biome Biome,
float WaterLevel,
float SunLevel,
int DirtPatchCount,
int GrassPatchCount,
List DirtAlphaMapGridID,
List GrassAlphaMapGridID,
Vector3 TrailingGrassPatch,
Vector3 TrailingDirtPatch,
Dictionary TrailingPlants,
int TrailingGrassPlantIndex,
float[,,] OriginalSplatmapData,
Dictionary AlphaMapGrid,
float[,,] AlphaMap)
{
this.TerrainName = TerrainName;
this.Weather = Weather;
this.MinutesSinceWeatherChange = MinutesSinceWeatherChange;
this.Biome = Biome;
this.WaterLevel = WaterLevel;
this.SunLevel = SunLevel;
this.DirtPatchCount = DirtPatchCount;
this.GrassPatchCount = GrassPatchCount;
this.DirtAlphaMapGridID = DirtAlphaMapGridID;
this.GrassAlphaMapGridID = GrassAlphaMapGridID;
this.TrailingGrassPatch = TrailingGrassPatch;
this.TrailingDirtPatch = TrailingDirtPatch;
this.TrailingPlants = TrailingPlants;
this.TrailingGrassPlantIndex = TrailingGrassPlantIndex;
this.OriginalSplatmapData = OriginalSplatmapData;
this.AlphaMapGrid = AlphaMapGrid;
this.AlphaMap = AlphaMap;
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... json-speed
Мобильная версия