Live data from Hacker News

Flecs – A fast entity component system for C and C++

flecs.dev

1–10 of 90 posts

Re: Flecs – A fast entity component system for C and C++

#3
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

I wrote a game engine that did that, because it was for a very simple, largely static scene.

You would implement it almost the same as a standard Windows GUI -- using an event handler loop that marks the screen as "dirty" and needing a refresh if it has changed.

Where it would immediately break down is ongoing animations. If you stopped moving your mouse, then animations would stop. Of course, you can set up the event loop to continue triggering if there are animations going on, but then you basically have a standard game engine loop running most of the time.

Personally, I'd be happy if games simply paused rendering when minimised. Some games do this, some don't.

Re: Flecs – A fast entity component system for C and C++

#4
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

I wrote a game engine that did that, because it was for a very simple, largely static scene. You would implement it almost the same as a standard Windows GUI -- using an event handler loop that marks the screen as "dirty" and needing a refresh if it has changed. Where it would immediately break down is ongoing animations. If you stopped moving your mouse, then animations would stop. Of course, you can set up the even…

Well, if those animations are things such as camera smoothing, it won't have such an impact. But I see your point.

Thanks for entertaining the idea!

Re: Flecs – A fast entity component system for C and C++

#5
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

I've implemented exactly this at $WORK. We literally just set a global variable, "should render next frame", from input handlers and other important events. It's not pretty but it gets the job done. There are occasional bugs where someone forgets to set the render flag after some significant event. But the bug goes away as soon as the mouse is moved, so it's usually not a big deal. If we wanted we could also schedule a "render once per second" to bound the amount of time that visual issues would persist for.

I'm not sure how this translates to ECS architecture - probably depends on your library, but if you're in charge of the main loop it shouldn't be a problem.

Re: Flecs – A fast entity component system for C and C++

#6
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

I've implemented exactly this at $WORK. We literally just set a global variable, "should render next frame", from input handlers and other important events. It's not pretty but it gets the job done. There are occasional bugs where someone forgets to set the render flag after some significant event. But the bug goes away as soon as the mouse is moved, so it's usually not a big deal. If we wanted we could also schedule…

One trick I found is to gate mutable access to state behind a "transaction object" which sets a flag for each object mutated, then once the transaction object's destructor is called, recomputes all derived state based on which flags were set. Using a destructor might not be the best idea since I ended up not marking it noexcept, it may be better to add an explicit "recompute" function called at the end, but this breaks the convenience of `state().cursor_mut() = new_cursor;` automatically recomputing derived state once the state() object is destroyed.

Re: Flecs – A fast entity component system for C and C++

#7
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

The bevy engine (ECS based) has an `UpdateMode` that specifies "Continuous" vs "Reactive" https://docs.rs/bevy/0.10.1/bevy/winit/enum.UpdateMode.html.

Here's an example using it, it's well suited for "desktop applications", the shorthand to use it is `desktop_app()` https://github.com/bevyengine/bevy/blob/1c5c94715cb17cda5ae2....

https://github.com/bevyengine/bevy/

Re: Flecs – A fast entity component system for C and C++

#8
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

I've implemented exactly this at $WORK. We literally just set a global variable, "should render next frame", from input handlers and other important events. It's not pretty but it gets the job done. There are occasional bugs where someone forgets to set the render flag after some significant event. But the bug goes away as soon as the mouse is moved, so it's usually not a big deal. If we wanted we could also schedule…

> “the bug goes away as soon as the mouse is moved, so it's usually not a big deal”

This reminds me of:

https://thedailywtf.com/articles/Hidden-Tax-Moves

"Wait, let me try," Bruce said, grabbing the mouse.

"Whoa, what just happened?" a teammate exclaimed. "What did you do? A ton of traffic just came through!"

Re: Flecs – A fast entity component system for C and C++

#10
post #2

Any idea what a game loop would look like for an ECS engine that only renders a new frame when some animation is running or when the user is manipulating the camera, but not otherwise? Let's not argue "why". Most obvious would be saving battery.

ECS isn't really relevant to the question

game loops usually call into simulate() and render() entrypoints.

There's state potentially mutated by simulate().. render() looks at that state and potentially produces a new output to present on-screen.

Typically the render() entrypoint returns a status indicating whether a new output was produced or not to put on-screen. If no output was produced you don't flip pages. So in a quiescent situation with nothing changing, render() returns "don't flip" and you just leave the existing page displayed til the next iteration.

How you track the internal game state / dirty vs. clean state is implementation detail behind those simulate() and render() entrypoints and depends greatly on the type of game.

Post reply on HN