voxelinc/voxellancer — pull request #194 by mrzzzrm (2013-12-18 23:25:48+00:00)
Title: Reference system

This is a proposal on how to fix #139 and #141 and @psieg random remark that we'll get a hell of object pointing to each other withour guarantee that these pointers are still valid.

It introduces:
* Referencor, an object that holds references to Target, for example as a pointer/in a list
* Referenceable, abstract base class for an object that of type Target and can be referenced to by Referencors
* ReferenceHandle, the actual handle to a Target

#Usage:
If an object wants to hold a reference(i.e. pointer) to another it requests a ReferenceHandle by calling object->createHandle(*this). createHandle() is a method of Referenceable, that creates a ReferenceHandle as connection between the Referencor and the Referenceable. Both of them receive a pointer to the handle, but the referencor is the owner of it. When either of them are destroyed, they inform their counterpart, remove the handle from the list, delete the handle and inform the referencor about the loss by calling referenceDestroyed(Target*). The Referencor can then remove the reference from his interiors.

#Example:
This behaviour is implemented for the Ship and its lockedTarget. Look at the code and try it out. Once you destroy the locked target, you will switch to "no lock".

Still in progress. Please tell me if you like the idea asap!