Initial commit

This commit is contained in:
Meta Vens 2026-04-18 06:04:39 +01:00
commit 137cb2ce13
215 changed files with 659023 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,69 @@
using System;
namespace GameCult.Caching
{
/// <summary>
/// Interface for database entries that have a human-readable name.
/// </summary>
public interface INamedEntry
{
/// <summary>
/// Human-readable name of the entry.
/// </summary>
string EntryName { get; set; }
}
/// <summary>
/// Base abstract class for all database entries in the cache.
/// For optional MessagePack integration, define concrete subclasses with [MessagePackObject] and [Key(n)] on fields.
/// The ID field can be serialized via a custom formatter in MessagePack stores.
/// </summary>
public abstract class DatabaseEntry
{
/// <summary>
/// Unique identifier for the entry. Handled by custom formatters in MessagePack integration.
/// </summary>
public Guid ID = Guid.NewGuid();
/// <inheritdoc/>
public override int GetHashCode()
{
return ID.GetHashCode();
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj is DatabaseEntry entry) return entry.ID == ID;
return false;
}
}
/// <summary>
/// Generic link to a <see cref="DatabaseEntry"/> in the cache.
/// Value is computed from the cache; serializes only LinkID.
/// </summary>
public class DatabaseLink<T> : DatabaseLinkBase where T : DatabaseEntry
{
/// <summary>
/// Computed value from the cache (not serialized; regenerated post-deserialize).
/// </summary>
public T? Value => Cache?.Get<T>(LinkID);
}
/// <summary>
/// Base for database links. LinkID is serialized directly; Value is computed in subclasses.
/// </summary>
public class DatabaseLinkBase
{
/// <summary>
/// ID of the linked entry.
/// </summary>
public Guid LinkID;
/// <summary>
/// Static reference to the cache (not serialized).
/// </summary>
public static CultCache? Cache;
}
}

View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>CultCache: Concurrent polymorphic cache with modular backing stores for .NET</Description>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GameCult.Logging\GameCult.Logging.csproj" />
<PackageReference Include="R3" Version="1.3.0" />
<PackageReference Include="ConcurrentHashSet " Version="1.3.0" />
</ItemGroup>
</Project>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace GameCult.Caching
{
public static class ReflectionExtensions
{
private static Dictionary<Type, Type[]> ParentTypes = new Dictionary<Type, Type[]>();
public static Type[] GetParentTypes(this Type type)
{
if (ParentTypes.ContainsKey(type))
return ParentTypes[type];
return ParentTypes[type] = type.GetParents().ToArray();
}
private static IEnumerable<Type> GetParents(this Type type)
{
// is there any base type?
if (type == null)
{
yield break;
}
// return all inherited types
var currentBaseType = type.BaseType;
while (currentBaseType != null)
{
yield return currentBaseType;
currentBaseType = currentBaseType.BaseType;
}
}
private static Dictionary<Type, Type[]> ChildClasses = new Dictionary<Type, Type[]>();
public static Type[] GetAllChildClasses(this Type type)
{
if (ChildClasses.ContainsKey(type))
return ChildClasses[type];
return ChildClasses[type] = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(ass => ass.GetTypes()).Where(type.IsAssignableFrom).ToArray();
}
}
}