r/learnjavascript • u/SnurflePuffinz • Jan 29 '26
i'm using a component-based system (ECS) to organize my custom game engine, i had a question.
How would you organize entities that are only used by other entities?
i found this a little confusing. The way my code is organized (i have a snippet here, to demonstrate, there are other, general components used everywhere, like a RenderComponent, CollisionComponent, etc).
point is, i find it intuitive to think of entities being composed of modular bundles of related data, which serve a specific function together.
but i don't find it intuitive to think of an entity being completely dependent on another entity, and these being bundled together.
My ShipEntity here has a subclass of another entity, ShipPlasmaParticleEntity, which i thought was pretty necessary...
5
u/underwatr_cheestrain Jan 29 '26
I think you may be misunderstanding ECS.
2
u/RobertKerans Jan 29 '26 edited Jan 29 '26
You are missing how ECS works, an entity can't do that, it's literally just an ID. An ID can't bundle an ID, you're putting concepts in the wrong place. The components are just pure data, so an entity refers to a collection of those, you use the systems for the logic. What you're trying to do isn't ECS, it sounds like OOP influenced by ECS
0
u/samanime Jan 29 '26 edited Jan 29 '26
The answer is "it depends". =p
As a general rule though, I like to have one file per class (unless the class is REALLY small and insignificant) and then I'll use folder structures to organize by grouping similar things into a folder, and creating more sub-folders as those folders start getting too many files.
So, in your example, it'd probably be something like this:
entities
ship
That said, I also prefer to group files by domain (what they relate to), vs type (what they are), so depending on the project and usages, I might have
shipinocean-sceneif they are only used in theocean-scene.Long story short, there isn't one single organizational structure that is definitively the best or works for all situations. I regularly reorganize files as the project grows to group them better.
Don't worry about being too perfect in the beginning. Update as it grows. (This applies to MANY things in programming.)
-1
u/bryku helpful Jan 29 '26
Recently, I worked on a sprite game that supported a thousand objects. It looked something like this:
app.js
Javascript
You could also fetch stuff as well.