Entitas
Entitas copied to clipboard
Should you always favor reactivity over initialization?
Hi, I want to create a very simple minesweeper game to get started. Currently I'm thinking about creating the board, placing the mines and calculating the mine counter for each field.
When starting the game there are components holding information about
- How many fields to create per row and column (e.g. 60 x 80)
- How many mines to place
Each field has the PrimaryEntityIndex attribute to make sure a field index is unique. What I don't know yet is if I should do it with initialize systems only or make use of reactivity. I thought about four different approaches with increasing complexity but also flexibility.
Approach 1
- Init System: Create a grid with x * y fields
- Init System: Place n mines randomly
- Init System: Calculate the mine counter for each field
Approach 2
- Init System: Create a grid with x * y fields
- Init System: Place n mines randomly
- Reactive System: Since all fields start with a mine counter of 0, you just have to recalculate each field around the field with the new mine
Approach 3
- Init System: Create a grid with x * y fields
- Reactive System: Check the mine counter component, decrease it and place a new mine randomly BUT wait until the grid creation has finished (there are no more fields to create yet)
- Reactive System: Since all fields start with a mine counter of 0, you just have to recalculate each field around the field with the new mine
Approach 4
- Reactive System: Foreach field to create decrease the counter and create a new field
- Reactive System: Check the mine counter component, decrease it and place a new mine randomly BUT wait until the grid creation has finished (there are no more fields to create yet)
- Reactive System: Since all fields start with a mine counter of 0, you just have to recalculate each field around the field with the new mine
Besides your own opinions, are there any technical reasons to favor one over another approach?
I think I will try sticking to approach 4 since its the most flexible one but maybe I should avoid this approach because ... ? ... :)
If I understand 3 and 4 approach - are impossible. You can't wait before all field is inited, because they are all initialized at that time.
You don't need reactive systems here, because there are no activity at all, you don't need make generating algorithm more complex than it should be.
Use one reactive, or one initialize system, or simple method (depends on how you provide settings for field) - that create field and place all mines and do not try break that on ECS, because that not how should you use that.
I trying say that ECS has different task, this is how use hammer instead of spoon.
Just generate field in simple plain method. But instead of generating CellClassObject - you will create entity, that have id, position, isOpen, isMine, isExploded, isFlagged, neighbourMinesAmount components, and on that entities you will create systems that will react.