SimulationCraft
SimulationCraft is a tool to explore combat mechanics in the popular MMO RPG World of Warcraft (tm).
|
A wrapper object to enable dynamic pet spawns in simulationcraft. More...
#include <pet_spawner.hpp>
Public Types | |
using | create_fn_t = std::function< T *(O *)> |
using | apply_fn_t = std::function< void(T *)> |
using | check_arg_fn_t = std::function< bool(const T *)> |
using | check_fn_t = std::function< bool(void)> |
using | expr_fn_t = std::function< std::unique_ptr< expr_t >(util::span< const util::string_view >)> |
Public Member Functions | |
pet_spawner_t (util::string_view id, O *p, pet_spawn_type st=PET_SPAWN_DYNAMIC) | |
pet_spawner_t (util::string_view id, O *p, unsigned max_pets, pet_spawn_type st=PET_SPAWN_DYNAMIC) | |
pet_spawner_t (util::string_view id, O *p, unsigned max_pets, const create_fn_t &creator, pet_spawn_type st=PET_SPAWN_DYNAMIC) | |
pet_spawner_t (util::string_view id, O *p, const create_fn_t &creator, pet_spawn_type st=PET_SPAWN_DYNAMIC) | |
std::vector< T * > | spawn (timespan_t duration=timespan_t::min(), unsigned n=0) |
Spawn n new pets (defaults, 1 for dynamic, max_pets for persistent), return spawned pets as a vector of pointers. | |
std::vector< T * > | spawn (unsigned n) |
Spawns n pets using the default summon duration. | |
size_t | despawn () |
Despawn all active pets, return number of pets despawned. | |
bool | despawn (T *obj) |
Despawn a specific active pet, return true if pet was despawned. | |
size_t | despawn (const std::vector< T *> &obj) |
Despawn a set of active pets, return number of pets despawned. | |
size_t | despawn (const check_arg_fn_t &fn) |
Despawn a set of active pets based on a functor, return number of pets despawned. | |
void | extend_expiration (timespan_t adjustment) |
Adjust the expiration time of active pets of type T. | |
size_t | n_active_pets () const |
Number of active pets of type T. | |
size_t | n_active_pets (const check_arg_fn_t &fn) |
Number of active pets of type T satisfying fn check. | |
size_t | n_inactive_pets () const |
Number of inactive pets of type T. | |
size_t | n_pets () const |
Total number of active and inactive pets of type T. | |
size_t | max_pets () const |
Maximum number of active pets. | |
timespan_t | duration () const |
Default spawning duration. | |
std::vector< T * >::iterator | begin () |
std::vector< T * >::iterator | end () |
std::vector< T * >::const_iterator | cbegin () |
std::vector< T * >::const_iterator | cend () |
pet_spawner_t< T, O > & | set_max_pets (unsigned v) |
Sets the maximum number of active pets. | |
pet_spawner_t< T, O > & | set_creation_callback (const create_fn_t &fn) |
Sets the creation callback for the pet. | |
pet_spawner_t< T, O > & | set_creation_check_callback (const check_fn_t &fn) |
Set creation check callback for persistent pets. Dynamic spawns will always be created. | |
pet_spawner_t< T, O > & | set_creation_event_callback (const apply_fn_t &fn) |
Set (add) creation callback. Creation callbacks will be invoked for every new pet. | |
pet_spawner_t< T, O > & | set_default_duration (const spell_data_t *spell) |
Set default duration based on a spell. | |
pet_spawner_t< T, O > & | set_default_duration (const spell_data_t &spell) |
Set default duration based on a spell. | |
pet_spawner_t< T, O > & | set_default_duration (timespan_t duration) |
Set default duration based on a timespan object. | |
pet_spawner_t< T, O > & | add_expression (const std::string &name, const expr_fn_t &fn) |
Registers custom expressions for the pet type. | |
pet_spawner_t< T, O > & | set_replacement_strategy (pet_replacement_strategy new_) |
Sets the replacement strategy of spawned pets if maximum is reached. | |
std::vector< T * > | pets () |
All pets. | |
std::vector< const T * > | pets () const |
All pets (read only) | |
std::vector< T * > | active_pets () |
All currently active pets. | |
T * | pet (size_t index=0) const |
Access the zero-indexth created pet, nullptr if no pets are created. | |
T * | active_pet (size_t index=0) |
Access the zero-indexth active pet, nullptr if no pet of index active. | |
T * | active_pet (const check_arg_fn_t &fn) |
Access the first active pet based on an unary check function, nullptr if no pet found. | |
T * | active_pet_max_remains (const check_arg_fn_t &fn=check_arg_fn_t()) |
Acccess the active pet with highest remaining time left using an optional unary constraint. | |
T * | active_pet_min_remains (const check_arg_fn_t &fn=check_arg_fn_t()) |
Acccess the active pet with lowest remaining time left using an optional unary constraint. | |
void | merge (base_actor_spawner_t *other) override |
Merge dynamic pet information. | |
void | create_persistent_actors () override |
Creates persistent pet objects during pet creation. | |
std::unique_ptr< expr_t > | create_expression (util::span< const util::string_view > expr, util::string_view full_expression_str) override |
Returns a pet-related expression. | |
timespan_t | iteration_uptime () const override |
Returns total uptime of the spawned pet type. | |
void | reset () override |
Reset internal state. | |
void | datacollection_end () override |
Collect statistical data. | |
Public Member Functions inherited from spawner::base_actor_spawner_t | |
base_actor_spawner_t (util::string_view id, player_t *o) | |
const std::string & | name () const |
Additional Inherited Members | |
Protected Attributes inherited from spawner::base_actor_spawner_t | |
std::string | m_name |
player_t * | m_owner |
A wrapper object to enable dynamic pet spawns in simulationcraft.
Normally, all pets must be fully initialized at the beginning of the simulation run (i.e., init phase). This wrapper class allows for the creation of pets during simulation run time.
Primary use is for dynamically spawned pets as a result of a proc or such.
The class uses two template parameters, T which is the type of the pet to be dynamically spawned (e.g., a pet class type in a class module), and O which is the type of the owner who performs the spawning (e.g., warlock_t). The owner type can be omitted, in which case it defaults to player_t.
Each pet spawner object is associated with an unique case insensitive textual id, which should correlate with the tokenized name of the pet (e.g., wild_imp). The id is used in various places to find a spawner context for a pet (for example expressions, or data analysis).
Note that since this wrapper object breaks the strict rule where each simulation thread has an identical actor end state (in terms of actor objects created), the merging operation of pets spawned by this wrapper object is no longer guaranteed to be deterministic (except under deterministic simulations of the same user input).
This means that the spawning order, or the number of dynamic pets across different threads is no longer identical. As such, if during the merge process the main thread does not have enough dynamic pets controlled by this object, it will create new ones until the requirement is satisfied.