WIP: implementation of the Observer pattern [incomplete] #347
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Observer pattern is a possible replacement for the StateRefMap + StateRef.
I.e. ObservableLinkedMap contains agents:
ObservableLinkedMap<Agent> agents;
The Lab is Observer for the agents map.
class Lab : ObserverLinkedMap<Agent>
If agent died (during battle or even if the agents map destroyed during the game's quitting) the lab will receive the event "removed" and remove the agent from its own list.
The vehicles horizontal list could be observer for the vehicles map.
If the player sold or buy a vehicle then the list updates automatically after receive an event. If a vehicle change its state (i.e. enter to building) then the list receives the "changed" event and changes picture of the vehicle accordingly.
The same for agents horizontal list (in battle mode too) and for the organisations list.
Main idea is forget about dereference hell of the StateRef and use the event-driven programming.
So, at this stage it is just an idea and the code is not ready for merging.
The observer.h contains the Observer and the Observable base classes.
The ObserverLinkedMap is a template of abstract class derived from the Observer.
The ObservableLinkedMap is a template class derived from the Observable.
The map is linked because the class contains hashmap and linked list to keep order of inserting.