在我的游戏中,我有一个具有不同 GameEntityType
的枚举(大约 200 个条目长)。
保存游戏时,仅将 GameEntityType
数组写入保存文件。
重建游戏世界,并显示有关 GameEntityTypes
的各种信息
我需要一个包含更多额外细节(常量值)的列表。
这意味着每个 GameEntityType 都有与其关联的其他值。
这些值每帧都会被频繁访问。
我的目标是有一种简单的方法来从 GameEntityTypeID (枚举)中获取所有额外信息。
例如,当我从保存文件中读取 0x1 时,我可以简单地访问名称和所有其他
数组中的数字/枚举隐含的信息如下:“Constants.TextureList[GameEntityType
]”,将返回字符串 “Stone_Texture.DDS”
附加示例/第一个枚举条目的关联信息:
类型:
字符串
,字符串,Flag-Enum:“视觉分类”
,布尔
,布尔
价值观:
"StoneBlock"
、"Stone_Texture.DDS"
、0x0102
、false
、true
我的第一个方法是创建一个静态 GameEntityTypeInfo 类
对于每个附加信息类型都有一个如下所示的成员:
public static const string[] = {"StoneBlock", ...[more Entrys]
};
当然,这是一个糟糕的解决方案,因为我不能只添加 GameEntityType
任何我想要的地方,而不必也更新所有其他列表。
我还必须将逻辑单元分离为数据类型单元(这是一个问题!因为当我决定不再需要特定的 EntityType 时,我必须遍历 6 个以上的列表!)
接下来,我尝试解决这个问题通过从这些数据集中创建一个结构
并将它们添加到静态数组中。
但是在构造函数时(游戏开始时)创建一个包含附加信息的列表
似乎仍然不是最好的解决方案。
问题:如何创建对这些常量值的快速(名称/分类查找将在每帧中至少使用 5000 次)并轻松访问(最好使用索引器)?
与此类似的查找最好是“Constants.TextureList[GameEntityType
]”
In my game I have a enum (about 200 entrys long) with different GameEntityType
s.
When the game is saved, only an array of GameEntityType
is written to the savefile.
To reconstruct the gameworld, and to display various information about the GameEntityTypes
I need to have a list of quite a few more extra details (constant values).
This means that each GameEntityType
has other values associated with it.
These values are accessed very often every frame.
My goal is to have a simple way to get all the extra information out of the GameEntityTypeID (the enum).
For example, when I read a 0x1 out of the savefile, I can simply access the Name and all other
information that is implied with the number/enum from an array like this: "Constants.TextureList[GameEntityType
]", Would return the string "Stone_Texture.DDS"
Example for additional/associated information of the first enum entry:
Types:
string
, string, Flag-Enum: "Visual-Classification"
, bool
, bool
Values:
"StoneBlock"
, "Stone_Texture.DDS"
, 0x0102
, false
, true
My first approach to this was to create a static GameEntityTypeInfo class that
had a member like the following for every additional info type:
public static const string[] = {"StoneBlock", ...[more entrys]
};
Of course this is a terrible solution, because I can't just add GameEntityType's
wherever I want without having to update all other lists too.
I also have to separate logical units into datatype units (which is a problem! because when I decide that I don't need an specific EntityType anymore, I have to go trough more than 6 lists!)
Next, I tried to tackle this problem by making a struct out of these datasets
and adding them to a static array.
But creating a List with the additional info while the constructor (while the game is starting)
still doesn't seem like the best solution.
Question: How can I create a fast(Name/Classification lookups will be used every frame at least 5000 times in total) and easy access (preferably with indexers) to these constant values?
A lookup similar to this would be best "Constants.TextureList[GameEntityType
]"
发布评论
评论(2)
通过子类化:
这里有一篇文章: http:// www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx
By subclassing:
An article here: http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx
不确定我是否完全理解您想要了解的内容,但如果您需要快速查找,那么听起来您正在寻找的是
Dictionary>
。Not sure if I understand exactly what you're trying to get at but it sounds like what you're looking for is a
Dictionary<string, List<string>>
if you're after fast lookups.