This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
TrueCraft/TrueCraft.API/Configuration.cs
Drew DeVault 6fb8ee7ba5 Many more optimizations and bugfixes
Again, sorry for the huge commit. Just taking on performance issues as I
see them. Changes in this:

- Deadlocks in region code finally fixed
- Chunk packet preparation optimized (saves ~10-20ms per packet, since
  we're sending these like 30 at a time that's pretty important) by
  storing chunks pre-encoded in memory (basically just using a single
  big array for IDs, metadata, and light)
- Move chunk generation and compression to the thread pool
- Move client chunk updates to the scheduler
- Improve profiler coverage
- Add knob to disable scheduling chunk events on chunk load
- Make it possible to disable specific scheduled events in config.yml
2017-05-23 18:17:44 -04:00

40 lines
1.2 KiB
C#

using System.IO;
using YamlDotNet.Serialization;
namespace TrueCraft.API
{
/// <summary>
/// Abstract base class for configurations read from YAML files.
/// </summary>
public abstract class Configuration
{
/// <summary>
/// Creates and returns a new configuration read from a YAML file.
/// </summary>
/// <typeparam name="T">The configuration type.</typeparam>
/// <param name="configFileName">The path to the YAML file.</param>
/// <returns></returns>
public static T LoadConfiguration<T>(string configFileName) where T : new()
{
T config;
if (File.Exists(configFileName))
{
var deserializer = new Deserializer(ignoreUnmatched: true);
using (var file = File.OpenText(configFileName))
config = deserializer.Deserialize<T>(file);
}
else
{
config = new T();
}
var serializer = new Serializer(SerializationOptions.EmitDefaults);
using (var writer = new StreamWriter(configFileName))
serializer.Serialize(writer, config);
return config;
}
}
}