c# - 将组件存储在静态类中可行吗?
问题描述
我正在为 C# 中 ECS 的自定义实现而苦苦挣扎。
我将组件存储在静态类中,如下所示:
internal static class ComponentStorage<T> where T : struct, IComponent
{
private static readonly T[] components = new T[capacity];
public static ref T Get(int index)
{
return ref components[index];
}
public static void Add(T component, int index)
{
components[index] = component;
}
}
我这样做有两个主要原因:
- 它允许我将我的组件(原样)存储在连续的结构数组中
- 我无需装箱/拆箱即可轻松获得组件
我用表格等管理管理器类中的组件。
到目前为止,我的实现运行良好,但基于这种方法我很紧张。
- 由于通用静力学,我是否缺少任何东西,例如隐藏拳击?性能测试按预期进行,但我还没有实现任何 SystemManager 类型的东西,因为这样做非常棘手,所以如果我一直都错了,我不想从那开始。
我找不到静态通用装箱问题的正确答案,而且我还没有看到任何 ecs 使用它。
解决方案
推荐阅读
- c++ - 如何在 Windows Cmake 中将 Dlib 设置为静态安装的共享库
- docker - Vagrant 和 Docker 之间的 Redis 连接被拒绝
- javascript - Chrome 扩展程序“接收端不存在。” 错误
- python - 在python中为可滚动图像添加复选框
- ruby - 用 Ruby 打印矩形
- java - 如何使用 JPA/Hibernate 从 MySQL 数据库中检索其描述或名称包含某些给定单词的产品列表?
- ember.js - 如何强制 ember.js 在渲染索引路由之前完全加载所有路由?
- javascript - 键值配对数组元素在给定索引javascript中分配值时返回“未定义”错误
- python - 如何过滤收件箱并仅下载带有附件的电子邮件
- azure - terraform azurerm 函数应用程序设置 host.json 文档丢失