Referencing custom struct types: Difference between revisions

Jump to navigation Jump to search
m
→‎Public method implementations: Moved LoadReference to be mentioned last since it uses Destroy
m (→‎The user interface: Repositioned LoadReference to be mentioned last.)
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: LoadReference, CreateCopy, and Destroy.
Here we have the implementations of our public methods: Destroy, CreateCopy, and LoadReference.
 
=====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).


=====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====
190

edits

Navigation menu