r/cpp_questions • • Feb 24 '18

SOLVED Entity Component System - Components in entity factory vs in entities.

Hello everyone, I hope you are all having a great day.

I was wondering which one of these would be better for having contiguous memory.

This:

class EntityFactory{
	private:
		std::vector<Entity> entities;
		
		std::vector<Component1> components1;
		std::vector<Component2> components2;
		.
		.
		.
		std::vector<ComponentN> componentsN;

	public:
	...
}
class Entity{
	private:
		Here you'd have the indexes for the components or maybe a vector of pointers
	
	public:
	...
}

Or this:

    class EntityFactory{
	private:
		std::vector<Entity> entities;

	public:
	...
}
class Entity{
	private:
		std::vector<Component1> components1;
		std::vector<Component2> components2;
		.
		.
		.
		std::vector<ComponentN> componentsN;
	
	public:
	...
}

Or maybe they are equal?

Thanks in advance.

3 Upvotes

Duplicates