I took a look at the block selection code today.
What we currently had in engine was very specialized: based on the local player activating an item and always rendered, and only one selection could ever be in effect.
I separated it out into two new base systems and reworked the current functionality to use those two base systems in a way that should be completely backwards compatible, although I suspect a more optimized approach might be possible.
synopia did most of the hard word. All I've done is reorganize it.
The base BlockSelectionSystem simply tracks block selections for BlockSelectionComponents. A LocationComponent sends a BlockStartSelectionEvent with a reference to a BlockSelectionComponent. The BlockSelectionComponent is updated with that location as a starting point and the selected region as that single point. Another (or the same) LocationComponent sends a BlockEndSelectionEvent to set a second selection point which resets the selected region. BlockSelectionCompletedEvents and BlockSelectionStartedEvents are sent out as appropriate.
A BlockSelectionRenderSystem will draw any block selections which have been registered for rendering. Currently they all use separate instances of the original block selection renderer class, but there's no reason why that instance cannot be customized or replaced with an alternate renderer. Register block selections with RegisterBlockSelectionForRenderingEvents and UnregisterBlockSelectionForRenderingEvents.
LocalPlayerBlockSelectionByItemSystem imitates the original functionality by working with the base BlockSelectionSystem events.
Here's a good branch for merging these changes.
https://github.com/mkienenb/Terasology/tree/component-based-block-selection
What we currently had in engine was very specialized: based on the local player activating an item and always rendered, and only one selection could ever be in effect.
I separated it out into two new base systems and reworked the current functionality to use those two base systems in a way that should be completely backwards compatible, although I suspect a more optimized approach might be possible.
synopia did most of the hard word. All I've done is reorganize it.
The base BlockSelectionSystem simply tracks block selections for BlockSelectionComponents. A LocationComponent sends a BlockStartSelectionEvent with a reference to a BlockSelectionComponent. The BlockSelectionComponent is updated with that location as a starting point and the selected region as that single point. Another (or the same) LocationComponent sends a BlockEndSelectionEvent to set a second selection point which resets the selected region. BlockSelectionCompletedEvents and BlockSelectionStartedEvents are sent out as appropriate.
A BlockSelectionRenderSystem will draw any block selections which have been registered for rendering. Currently they all use separate instances of the original block selection renderer class, but there's no reason why that instance cannot be customized or replaced with an alternate renderer. Register block selections with RegisterBlockSelectionForRenderingEvents and UnregisterBlockSelectionForRenderingEvents.
LocalPlayerBlockSelectionByItemSystem imitates the original functionality by working with the base BlockSelectionSystem events.
Here's a good branch for merging these changes.
https://github.com/mkienenb/Terasology/tree/component-based-block-selection