190
edits
Monkey'05'06 (talk | contribs) m (→The user interface: Repositioned LoadReference to be mentioned last.) |
Monkey'05'06 (talk | contribs) m (→Public method implementations: Moved LoadReference to be mentioned last since it uses Destroy) |
||
Line 242: | Line 242: | ||
====Public method implementations==== | ====Public method implementations==== | ||
Here we have the implementations of our public methods: | Here we have the implementations of our public methods: Destroy, CreateCopy, and LoadReference. | ||
=====CreateCopy implementation===== | =====CreateCopy implementation===== | ||
Line 279: | Line 267: | ||
This simply frees up an entry in the cache so it can be reused. The user instance can still be used after calling this method, in which case a new entry would be created and assigned. | This simply frees up an entry in the cache so it can be reused. The user instance can still be used after calling this method, in which case a new entry would be created and assigned. | ||
=====LoadReference implementation===== | |||
void Weapon::LoadReference(WeaponReference ref, bool destroyCurrentInstance) | |||
{ | |||
if (destroyCurrentInstance) this.Destroy(); | |||
// loading a different reference, no need to validate this instance | |||
int ID = GetWeaponReferenceID(ref); | |||
if (ID == -1) AbortGame("Error! Attempted to load non-existent or invalid weapon."); | |||
this.Reference = ref; | |||
} | |||
Since all we're doing is assigning the Reference property, this method is extremely efficient (as opposed to implementations using serialization techniques). | |||
====Attribute accessor methods==== | ====Attribute accessor methods==== |
edits