[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Slick Forums • View topic - Component objects/entities prioritization

Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jul 29, 2021 7:48 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Mar 16, 2010 12:07 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 620
Location: Iceland
Just wanted to share something I had been trying to find a solution to for, well, 1 hour, but had been bothering me for a while.

The problem with game objects (or entities) comprised of components, in 2D games, is prioritization. E.g. what gets rendered first.

Simple 2D games solve this by grouping together similar entities, e.g. "ships", "projectiles", "explosions". And if a ship has a healthbar that needs to overlay all ships then different render methods are created, e.g. first render() is called on all ships and then renderOverlay() on all ships.

But in GOCS (GameObject Component System) we don't have this luxury, there is only one render() method. However, we have components and the healthbar can be put into a component Health which renders a healthbar, and the ship's image into a component ImageRenderer.

Now we only need to define rendering order of the components! ImageRenderer component gets rendered first, then Health component.

Problem solved? No. Things can get a bit more complicated than this.


Let me explain by analyzing a little problem:

We have a Cursor gameobject, Selecter gameobject, a Minimap gameobject and a Starship gameobject.

Cursor: Displays appropriate in-game cursor, e.g. highlight cursor, attack cursor, move cursor, and cursor when you are over the minimap.
Selecter: Allows you to drag/click to select all the selectable gameobjects.
Starship: The starship gameobject which you can select with your mouse.
Minimap: No need to explain.

Now, let's imagine the Minimap being translucent, the Starship is occluded by the Minimap and you'd like to click on that area with your Cursor.

What should happen? Should the Starship get selected or should you jump to the correct location on the Minimap?

The natural prioritization is this: Starship, Selecter, Minimap, Cursor.

But, if Selecter is higher in priority than Minimap, then the Starship must get selected?

Somehow, the Minimap needs to have higher priority than the Selecter, but Selecter rendered first!

Solution: We need to prioritize updating and rendering on component level, where object grouping is secondary.

Example 1:
First, the Minimap should check if you've clicked on it, poll that out of the input. (and possibly telling Cursor to show an appropriate minimap-hovering cursor)
Second, when Selecter gets updated, the input has already been cleared by the Minimap polling from it.
Third, Selecter gets rendered (nothing visible though).
Fourth, Minimap gets rendered.


Now, but what if we have two objects "Bullet" and "Starship", whereas both have the ImageRenderer component and we want the "Bullet" to appear above the "Starship"? This is where secondary prioritization kicks in. Components of same priority are tie-breaked using object-grouping prioritiztion. So, first we sort components by update and render priority order, and then tie-break them using group priority order.

In short:
- update components by component-update-priority, tie-break using object-priority.
- render components by component-render-priority, tie-break using object-priority.


This way, we ensure gameobjects and components are updated and rendered in the correct order!


(I have a feeling there is a much simpler solution to this and I'm going to get laughed at :lol: for proposing such a nutcase solution, but heck, at least it's a solution that should work in theory.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group