Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Text and ECS (Entity Component System) architecture questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Finalspace   Members   -  Reputation: 298

Like
0Likes
Like

Posted 13 August 2014 - 01:40 AM

Hi there,

 

i have successfully implemented signed distance fields font creation and rendering and now i am in the planing process for my HUD/UI rendering right now. Normally i would just add a renderHUD() method after all the other rendering stuff and call it and use orthographic projection. Thats how i have done it in the past, but now i have a Entity Component Based Game Engine and i want to do this the "Entity->Component" way if possible.

 

What i want to achieve is:

 

- Rendering a bit of text based on triggers (which are components as well) in the 3D scene (Created and destroyed on the fly)

- Rendering simple game Menu UI (Start, Load, Save, Options, Credits, etc.)

- Rendering HUD for the player/game and scene stats

- Rendering tons of debug informations - if required

 

Do you guys have some tips for a good component based solution?

 

Thanks in advance,

Finalspace



Sponsor:

#2 AvengerDr   Members   -  Reputation: 750

Like
5Likes
Like

Posted 13 August 2014 - 06:51 AM

I faced a similar problem so here's my perspective, though you might not like it.

Not everything has to be framed in the context of an ECS. It's the same problem I see with developers using the MVVM pattern. I myself have at times become so obsessive that everything had to follow that pattern, to the point that things that would have taken 10 seconds to implement in the codebehind required complex XAML-only solutions.

 

I am building this UI library, which I am using together with my ECS framework. The solution I adopted was to treat the whole HUD as an entity. Therefore the UI system has the only responsibilities of polling input devices and rendering the whole HUD (though I might split those eventually). I assume that you wanted an approach in which every UI element was a different entity? Or something along the lines of having different UI-components, such as a "ButtonComponent", "PanelComponent", "LabelComponent" and so on?

 

The only advantage I can see is that you would then be able to attach UI elements to 3D objects. The downside is that you'll have to find someway to have different UI-components communicate with each other.


Edited by AvengerDr, 13 August 2014 - 09:20 AM.

--Avengers UTD Chronicles - My game development blog

#3 Strewya   Members   -  Reputation: 1492

Like
1Likes
Like

Posted 13 August 2014 - 07:25 AM

I agree with AvengerDr. Think really hard if you want to shove the UI rendering block into an ECS shaped hole. The ECS concept relates well to game objects, and afaik, the HUD is not a game object. You might try hard to represent it as one, but it really would end up like trying to push a cube through a round hole. ECS is just another tool in your toolbox, so use it where appropriate.

 

Do things the easy way. Do things the way it makes sense.


devstropo.blogspot.com - Random stuff about my gamedev hobby


#4 Finalspace   Members   -  Reputation: 298

Like
0Likes
Like

Posted 13 August 2014 - 01:41 PM

I agree that not everything must be done in a ECS-way, but i really like the way how clean it is with all the systems, entities and components.

You have the update systems (like input, behavior, camera, physics engine - in that order) first and then you have the draw systems and every system encapsulates the logic or drawing which are really clean in my opinion. Currently i havent found anything yet which does not fit in the ECS - but these will come definitly i think.

 

But i will give it more though, to get a simple but good solution - for now i need to fix the damn letter advancement -.-



#5 CRYP7IK   Members   -  Reputation: 986

Like
0Likes
Like

Posted 13 August 2014 - 05:26 PM


The downside is that you'll have to find someway to have different UI-components communicate with each other.

 

Components should already be able to communicate with other components.

 

I actually think the HUD can easily be made with ECS and even fit with your old way of doing things, you should already have an image component and image render component a UI is just behaviors with those so: a clickable component and system that sends a message to all components in the entity when  entered, exited, mouse up, mouse down then a uicomponent with it's system that ties together multiple components in the same group (Like radio buttons).


To accomplish great things we must first dream, then visualize, then plan...believe... act! - Alfred A. Montapert
Gold Coast Studio Manager, Lead Programmer and IT Admin at Valhalla Studios Bifrost.

#6 BedderDanu   Members   -  Reputation: 283

Like
0Likes
Like

Posted 13 August 2014 - 06:42 PM

I'm still teaching myself all this stuff, but can't you do it with 2 different drawing systems?

 

System 1 iterates through all entities and draws them if they have 3D components

System 2 iterates through all entities and draws them if they have HUD components

 

That essentially gives you your renderHUD() method.

 

So you wind up doing something like

 

Systems.input.update()

Systems.AI.update()

Systems.physics.update()

Systems.WorldPainter.draw()

Systems.HudPainter.draw()



#7 AvengerDr   Members   -  Reputation: 750

Like
0Likes
Like

Posted 14 August 2014 - 03:44 AM

Components should already be able to communicate with other components.

 

I actually think the HUD can easily be made with ECS and even fit with your old way of doing things, you should already have an image component and image render component a UI is just behaviors with those so: a clickable component and system that sends a message to all components in the entity when  entered, exited, mouse up, mouse down then a uicomponent with it's system that ties together multiple components in the same group (Like radio buttons).

 

Yes sure, but it would be more time-consuming to have them behave the way you want compared to using an explicit approach. You can't throw a ButtonComponent, a PanelComponent and LabelComponents in an Entity and expect a DropDownBox to appear and work like it should unless you coordinate the logic between all of them. I believe that's easier to do if you have a DropDownBox object where you can do everything you need. After all none of the major UI frameworks use anything even remotely similar to an ECS.

 

In my approach, I only have a UIComponent for the whole HUD. So it gives me the flexibility to switch HUDs at runtime and that's enough I guess. Further, in my approach I am using Direct2D to render controls from scratch. So they aren't simple textures and thus require a different rendering method than if they were billboards.


Edited by AvengerDr, 14 August 2014 - 03:44 AM.

--Avengers UTD Chronicles - My game development blog

#8 Finalspace   Members   -  Reputation: 298

Like
0Likes
Like

Posted 15 August 2014 - 03:29 AM

For the HUD i think i will just create a HUD system and a HUD component which are rendered in orthographic mode and the component just have a list of labels/ui-elements without interaction for now.
For the ingame text stuff, i think a TextComponent and a text render system should work also.

Thanks guys for all the tips ;-)

#9 haegarr   Crossbones+   -  Reputation: 4425

Like
0Likes
Like

Posted 15 August 2014 - 04:49 AM


I actually think the HUD can easily be made with ECS and even fit with your old way of doing things ...

Not to be offending, but: This kind of thinking has led to the omni-potent scene graph, hasn't it? It is not principally wrong to think so, but only if side-effects and longtime effects are considered, and that is not so easy as the history shows us.

 

If one uses OOP as the programming paradigm, two principle ways are given: Inheritance and composition (or in practice a mix of those). ECS is in fact object composition made available to the designer. Because composition by itself is so low level, nearly all problems can be solved that way. However, does that mean that all problems are related to ECS?

 

ECS is a framework made to deal with game objects. At Gas Powered Games, which made the technique popular, the entities were called so, abbreviated as GOs. Text output of a debugger is hardly a game object. The graphics of a game menu belongs to the menu game state, which is in parallel with the gameplay state, of which the ECS is part of; so having the game menu inside the ECS is also strange. Judging the HUD itself is not as easy though, and having a dialog item floating above an avatar shifts things even more towards a game object understanding.

 

The argument that all those is text, and the wanted achievement of unified text rendering hence requires all examples to end in the ECS because some of them look like components, is the wrong way. Having the game loop being split into sub-systems is a solution independently of using ECS. The graphics sub-system is usually the very last one called in a game loop. Ideally it should not know what the ECS is, because the ECS is a tool to model the world, and graphics rendering just needs a snapshot (in time) slice (spatially) of the world to do its job (keyword: decoupling by queuing rendering jobs). Hence graphics rendering is not interested in which other sub-system(s) sent jobs, only that jobs are waiting to be processed.

 

What's with the other sub-systems? Input has an impact, for sure. Animation may be used. AI, collision detection, physics, ... usually not. But all these are part of the game loop and work onto ECS. So, when using an ICS ("interface component system" ;) ) it would be wise to clearly separate ECS and ICS, so that belonging sub-systems can be invoked for one set without being disturbed by the other set. For example, something like the Spaces approach may be used (see an introduction by Sean here).

 

Just my 2 Cents, of course.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS