Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (791)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ECS confusion  (Read 4314 times)
0 Members and 1 Guest are viewing this topic.
Offline mudlee

Junior Devvie

Medals: 6
Exp: 5 years

« Posted 2018-06-17 13:48:17 »

Hi guys. In the last few weeks, I read a lot about ECS. Also, I started to use artemis-odb in my engine which was previously used a Unity-like game loop, where every GameObject might have onUpdate, onFrameStart, etc.

The confusion is this. Let's say, if I have 3-4 entities, all have a MeshRenderer component, which contains the material and the mesh. In a MeshRendererSystem, I process those entities, add/update all of them into a batch and when all are processed, I do the render passes using the batches. That's pretty mutch clear, I have entities with one component, and one system process them, then a separated logic uses the systems outcome.

But in other cases, I'm not sure, what to do. Eg.:
I have
  • a CursorEntity
  • a CursorScreenPositionComponent
  • a CursorPositionSystem

The component is attached to the entity, the system updates the component's data, which is the cursor position on the screen. But where should I update the cursor (an image) position itself? So after a frame, I have an entity with an up2date component (thanks to the system), but what to do next?

Currently, I solve this that ECS systems run first in the gameloop, and after that, I run updater components that uses the updated entities.
I might miss something very basic stuff, so if you can recommend a great article or explain what did I miss, I would be so happy Smiley
Offline VaTTeRGeR
« Reply #1 - Posted 2018-06-17 17:22:59 »

If you only need the CursorScreenPositionComponent to store a value that is used to calculate another value, why not skip that and set the world position directly in the cursorSystem?

Your cursor could be built like this:
  • positionComponent, generic world position component, also used by other entities
  • spriteComponent, generic sprite component, also used by other entities
  • cursorComponent, marks it as a cursor, contains only exclusively cursor-specific data or maybe even no data at all

There could be a cursorPositionSystem that takes the mouses screen-position from your game engine, calculates the world-position from that and sets the world-position of all entities with a cursorComponent and a positionComponent. That should happen before your sprite-render-system is invoked.

Components need to be as atomic as practically possible. The only difference between your cursor and any other 2d gameobject is that the cursor gets it's position set to where the mouse points. After that it just get's processed (drawn) together with the other 2d entities.
Offline mudlee

Junior Devvie

Medals: 6
Exp: 5 years

« Reply #2 - Posted 2018-06-18 16:28:37 »

thx! Thats make sense. Tried it and looks kinda OK Smiley
Pages: [1]
  ignore  |  Print  

hadezbladez (2845 views)
2018-11-16 13:46:03

hadezbladez (1028 views)
2018-11-16 13:41:33

hadezbladez (2812 views)
2018-11-16 13:35:35

hadezbladez (551 views)
2018-11-16 13:32:03

EgonOlsen (3824 views)
2018-06-10 19:43:48

EgonOlsen (4237 views)
2018-06-10 19:43:44

EgonOlsen (2543 views)
2018-06-10 19:43:20

DesertCoockie (3355 views)
2018-05-13 18:23:11

nelsongames (3469 views)
2018-04-24 18:15:36

nelsongames (4467 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!