static void RecurseAdd(List <PhysicsConfigurationProcessed> list, PhysicsConfiguration sourceConfig, List <PropertyInfo> multipleProps, int level, Type physicsConfigurationType) { if (level < multipleProps.Count) { PropertyInfo readProp = multipleProps[level]; PropertyInfo writeProp = physicsConfigurationType.GetProperty(readProp.Name); string[] vals = (readProp.GetValue(sourceConfig) as string).Split(',').Select(n => n.Trim()).ToArray(); int numberSame = list.Count / vals.Length; for (int valueIndex = 0; valueIndex < vals.Length; valueIndex++) { int startIndex = valueIndex * numberSame; int value = int.Parse(vals[valueIndex]); List <PhysicsConfigurationProcessed> toSendDown = new List <PhysicsConfigurationProcessed>(numberSame); for (int i = startIndex; i < numberSame + startIndex; i++) { PhysicsConfigurationProcessed settingNow = list[i]; writeProp.SetValue(settingNow, value); toSendDown.Add(settingNow); } RecurseAdd(toSendDown, sourceConfig, multipleProps, level + 1, physicsConfigurationType); } } }
/// <summary> /// Loads configuration from specified file. /// </summary> /// <param name="path">Path to configuration file.</param> /// <returns>New instance of <see cref="Configuration" /> class with data loaded from file or defaults if data was missing.</returns> public static Configuration LoadFromFile(string path) { var jsonSerializerOptions = new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip }; var rawFileContent = File.ReadAllText(path); var fileContent = JsonSerializer.Deserialize <FileContent>(rawFileContent, jsonSerializerOptions); if (fileContent is null) { throw new InvalidOperationException($"Cannot load configuration from file: {path}."); } var coreConfigurationBuilder = CoreConfiguration.CreateBuilder(); if (fileContent.Core?.AssetsRootDirectoryPath != null) { coreConfigurationBuilder.WithAssetsRootDirectoryPath(fileContent.Core.AssetsRootDirectoryPath); } if (fileContent.Core?.CustomSystemsExecutionOrder != null) { coreConfigurationBuilder.WithCustomSystemsExecutionOrder(fileContent.Core.CustomSystemsExecutionOrder); } if (fileContent.Core?.FixedUpdatesPerFrameLimit != null) { coreConfigurationBuilder.WithFixedUpdatesPerFrameLimit(fileContent.Core.FixedUpdatesPerFrameLimit.Value); } if (fileContent.Core?.FixedUpdatesPerSecond != null) { coreConfigurationBuilder.WithFixedUpdatesPerSecond(fileContent.Core.FixedUpdatesPerSecond.Value); } if (fileContent.Core?.ShowAllEntitiesCount != null) { coreConfigurationBuilder.WithShowAllEntitiesCount(fileContent.Core.ShowAllEntitiesCount.Value); } if (fileContent.Core?.ShowRootEntitiesCount != null) { coreConfigurationBuilder.WithShowRootEntitiesCount(fileContent.Core.ShowRootEntitiesCount.Value); } if (fileContent.Core?.ShowFps != null) { coreConfigurationBuilder.WithShowFps(fileContent.Core.ShowFps.Value); } if (fileContent.Core?.ShowFrameTime != null) { coreConfigurationBuilder.WithShowFrameTime(fileContent.Core.ShowFrameTime.Value); } if (fileContent.Core?.ShowTotalFrames != null) { coreConfigurationBuilder.WithShowTotalFrames(fileContent.Core.ShowTotalFrames.Value); } if (fileContent.Core?.ShowTotalTime != null) { coreConfigurationBuilder.WithShowTotalTime(fileContent.Core.ShowTotalTime.Value); } if (fileContent.Core?.ShowSystemsExecutionTimes != null) { coreConfigurationBuilder.WithShowSystemsExecutionTimes(fileContent.Core.ShowSystemsExecutionTimes.Value); } if (fileContent.Core?.StartUpScene != null) { coreConfigurationBuilder.WithStartUpScene(fileContent.Core.StartUpScene); } if (fileContent.Core?.StartUpSceneBehavior != null) { coreConfigurationBuilder.WithStartUpSceneBehavior(fileContent.Core.StartUpSceneBehavior); } var physicsConfigurationBuilder = PhysicsConfiguration.CreateBuilder(); if (fileContent.Physics?.RenderCollisionGeometry != null) { physicsConfigurationBuilder.WithRenderCollisionGeometry(fileContent.Physics.RenderCollisionGeometry.Value); } var renderingConfigurationBuilder = RenderingConfiguration.CreateBuilder(); if (fileContent.Rendering?.EnableVSync != null) { renderingConfigurationBuilder.WithEnableVSync(fileContent.Rendering.EnableVSync.Value); } if (fileContent.Rendering?.ScreenHeight != null) { renderingConfigurationBuilder.WithScreenHeight(fileContent.Rendering.ScreenHeight.Value); } if (fileContent.Rendering?.ScreenWidth != null) { renderingConfigurationBuilder.WithScreenWidth(fileContent.Rendering.ScreenWidth.Value); } if (fileContent.Rendering?.SortingLayersOrder != null) { renderingConfigurationBuilder.WithSortingLayersOrder(fileContent.Rendering.SortingLayersOrder); } return(new Configuration( coreConfigurationBuilder.Build(), physicsConfigurationBuilder.Build(), renderingConfigurationBuilder.Build() )); }
public PhysicsSystem(PhysicsConfiguration physicsConfiguration, IDebugRenderer debugRenderer) { _physicsConfiguration = physicsConfiguration; _debugRenderer = debugRenderer; }
private Configuration(CoreConfiguration coreConfiguration, PhysicsConfiguration physics, RenderingConfiguration renderingConfiguration) { Core = coreConfiguration; Physics = physics; Rendering = renderingConfiguration; }