04-12-2020, 12:51 AM
I guess I wasn't too clear. I think the entity should have its data stored either in the entity class itself, or in the individual subsystem classes (whatever makes more sense for the particular kind of data), but it is each subsystem's responsibility to know how to save and load that data from / to NBT, *when serializing the entity*. So when the entity gets loaded, its subsystems load their internal data from the entity's NBT, and when it's saved, the subsystems save the data. They store the data within themselves, as they see fit. If there is need to share the data between multiple subsystems, that needs individual consideration. In a general case, such a sharing means the subsystems are not designed properly.
From this, you can see that a subsystem cannot be a class with a single operator(), but instead many virtual methods. For example:
From this, you can see that a subsystem cannot be a class with a single operator(), but instead many virtual methods. For example:
/** The interface of the high-level AI subclasses */ class cEntity::IBehavior { /** Called when aAttacker has attacked this entity. */ virtual void OnAttacked(const cEntity & aAttacker) = 0; /** Called when sight of the tracked target was lost (such as when targeting a player, or hunting) */ virtual void OnLostSightOfTarget(const cEntity & aTarget) = 0; /** Called when a new entity comes into the sight range. This doesn't mean the entity can be seen, it is only close enough to actually check the line-of-sight, if desired. */ virtual void OnEntityInSightRange(const cEntity & aEntity) = 0; // ... /** Saves the behavior's data to the NBT */ virtual void SaveToNBT(...) = 0; /** Loads the behavior's data to the NTB. */ virtual void LoadFromNBT(...) = 0; }