Entity Component Systems

Like a phoenix, it will always rise again.
Post Reply
xegnma
Posts: 49
Joined: Tue Jun 08, 2021 6:05 pm

Entity Component Systems

Post by xegnma »

Any fans of Entity Component System architecture lurking about?
User avatar
Gered
Posts: 51
Joined: Tue Feb 16, 2021 4:38 pm
Location: Toronto, Canada
Contact:

Re: Entity Component Systems

Post by Gered »

*Raises hand*

Although, I guess I'm about 7-8 years behind the times on it ... not really sure that the present-day methods are and if they're too different from what I used to do. I used it in a couple projects that were never finished (plus one more that I never put up on github or anywhere else because I used some paid art assets...).

Anyway, big fan of ECS stuff. Although, I do think my attempts at using it always left the project feeling like spaghetti. :D
User avatar
Sirocco
Site Admin
Posts: 806
Joined: Fri Feb 12, 2021 10:25 pm
Location: Outer Demoscenia
Contact:

Re: Entity Component Systems

Post by Sirocco »

Yeah, I'm a huge fan (or at least as I understand it, I am). I've been using that since the seconds FB demo, way back in 2001. Although I suppose my approach doesn't try to separate the entity and component parts.

For my first compo entry, I used a simple struct like this:

Code: Select all

struct actor_struct
{
 Vector3 pos;           // Position
 Vector2 path;          // Path of travel
 float blend;           // Blend strength (0-1)    < only applies if not solid >
 float angle;           // Angle of rotation (0-360)
 float rotation;        // amount to rotate each frame
 int mode;              // 0 = solid. 1 = alpha
 int state;             // 0 = inactive. 1-12 = doing stuff
 int effect;            // 0 = none.  1 = zap-glow
 int home;              // Spawner that brought them into this hellish nightmare
 int timer;             // Internal timer for animation purposes.
 int stamina;           // Walking and being attacked drain stamina. When <= 0 the actor dies or fades out
 int cel_x;             // X cel within sprite sheet
 int cel_y;             // Y cel within sprite sheet
 int thought;           // emoji they have in their head
 int locked_to;         // Actor this player is locked to (thug is beating someone)
 bool enabled;          // TRUE if this actor is active
};
For a larger project, I'd use something with more data, and various behaviors that would affect each actor's data. For example, you wouldn't have a rotation variable, but a rotation behavior, and it would have its own parameters. The compo entry was dirt-simple, so I just used the state variable, and a big switch statement to manage what they are doing :P

So far it has worked out well, but you do have to take care and init your data structures, and make sure the game data is in the proper state before you begin executing the system, or else unfortunate things can happen :]
User avatar
carra
Posts: 163
Joined: Thu May 13, 2021 10:39 am

Re: Entity Component Systems

Post by carra »

Sirocco wrote: Sat Jun 12, 2021 2:32 pmI've been using that since the seconds FB demo, way back in 2001
Oh man, that Fenix Blade demo. I liked it so much. I wish it would be finished one day (what? I can dream...).
User avatar
Sirocco
Site Admin
Posts: 806
Joined: Fri Feb 12, 2021 10:25 pm
Location: Outer Demoscenia
Contact:

Re: Entity Component Systems

Post by Sirocco »

I've been thinking a lot about early retirement. If I can manage it, I'd definitely have enough time on my hands to revisit some old projects. All big ifs, but I too have a dream. Also, a Dreamcast ;)
User avatar
deleter
Posts: 60
Joined: Mon Feb 15, 2021 5:40 pm

Re: Entity Component Systems

Post by deleter »

I used flecs for the last compo, it was interesting, can be used in C99. Though it does a ton of memory allocations which is not my preferred style of development these days. Prefer to allocate one big block and then do some smart handling to avoid the complexity of alloc/realloc/free soup.
xegnma
Posts: 49
Joined: Tue Jun 08, 2021 6:05 pm

Re: Entity Component Systems

Post by xegnma »

Sirocco wrote: Sat Jun 12, 2021 4:14 pm I've been thinking a lot about early retirement. If I can manage it, I'd definitely have enough time on my hands to revisit some old projects. All big ifs, but I too have a dream. Also, a Dreamcast ;)
Here's a crazy idea. How about porting Cry Havoc to run inside the browser...

Maybe even do a ground up re-write of the engine to leverage all the fancy ECS techniques that's all the rage these days...I'll help if you're willing (code+pixelart)...
User avatar
Sirocco
Site Admin
Posts: 806
Joined: Fri Feb 12, 2021 10:25 pm
Location: Outer Demoscenia
Contact:

Re: Entity Component Systems

Post by Sirocco »

xegnma wrote: Wed Jun 16, 2021 2:15 pm
Sirocco wrote: Sat Jun 12, 2021 4:14 pm I've been thinking a lot about early retirement. If I can manage it, I'd definitely have enough time on my hands to revisit some old projects. All big ifs, but I too have a dream. Also, a Dreamcast ;)
Here's a crazy idea. How about porting Cry Havoc to run inside the browser...

Maybe even do a ground up re-write of the engine to leverage all the fancy ECS techniques that's all the rage these days...I'll help if you're willing (code+pixelart)...
Sorry, I meant to come back to this post, and totally forgot. Getting old, I guess :D

Interesting thing about Raylib, is that you can target the browser with little code change. I believe there's some trickery on the build side, and you have to do some special stuff with your external resources (textures, sfx, etc). 0xDB said it was a pain in the ass, but he got it working. And given how quickly my little 3D isometric experiment came together, I had given some thought to starting from scratch and rebooting that project. I had to do a fucking ton of code to get the 2D build running quickly and efficiently, and there was a ton of manual ray casting and z-buffer stuff to keep track of what occluded what without redrawing the entire scene. And drawing textures was a pain because they weren't really textures, but diagonal sprites that would be tiles to the top and sides of the "blocks". It was fucking nuts, like all my projects. I'm stupid like that.

Going full 3D for backgrounds eliminates a bunch of that bullshit, and I can do smooth rotation of the playfield, zooming in/out, etc for free.

Once I've finished Far Afield and FML I'll make a decision on that.
Post Reply