Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

c++ - ECS-实体可以具有给定类型的多个组件吗(ECS-can an entity have more than one component of given type)

I've been recently assigned to code a Entity-component-system based framework.

(最近,我被分配去编写一个基于实体组件系统的框架的代码。)

As I'm not experienced in that matter, I have a simple question: Can I assume, that an entity can have maximum of one component of each type?

(因为我没有这方面的经验,所以我有一个简单的问题:我可以假设一个实体最多可以具有每种类型的一个组件吗?)

I mean like:

(我的意思是:)

int COMPONENT_COUNT; //number of different components available

class Entity
{
    COMPONENT* component_list[COMPONENT_COUNT];
}

then adding a component would be like

(然后添加一个组件就像)

component_list[component.id]=&component; //can't add more components of this type

Is that a correct assumption?

(这是正确的假设吗?)

I can't think of any situation when an entity would need two or more components of the same type.

(当一个实体需要两个或多个相同类型的组件时,我想不出任何情况。)

  ask by Oti translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well, there isn't a holy bible of entity component systems.

(嗯,没有实体组件系统的圣经。)

But many implementations I'm aware of don't make any provision for this, they allow entities to have or not have some kind of component but don't support multiplicity.

(但是我知道许多实现对此都未作任何规定,它们允许实体具有或不具有某种组件,但不支持多重性。)

Likewise, from a design perspective it seems like a rather bad idea (lots of complexity for naught).

(同样,从设计角度看,这似乎是一个坏主意(很多复杂性无济于事)。)

You could make it work, but neither you nor I can come up with a use case.

(您可以使其工作,但您和我都无法提出用例。)

KISS and YAGNI apply, this is a reasonable assumption.

(KISS和YAGNI适用,这是一个合理的假设。)

And if you do later need to add a component twice or thrice, it's easy to emulate by having two or three different kinds of components.

(而且,如果以后需要将组件添加两次或三次,则可以通过具有两种或三种不同类型的组件来进行仿真。)

Only with variable arity you need to change the innards of the system, but that seems even more outlandish.

(只有在可变可变性的情况下,您才需要更改系统的内部,但这似乎更加奇怪。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...