Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions engine/class_modules/monk/sc_monk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6889,6 +6889,14 @@ bool monk_t::validate_fight_style( fight_style_e style ) const
return true;
}

void monk_t::init()
{
base_t::init();

sim_controller_t::register_sim_controller<min_player_stat_t>( sim, this, STAT_CRIT_RATING, 100.0 );
sim_controller_t::register_sim_controller<tier_set_count_t>( sim, this, TWW2, B2 );
}

// monk_t::init_spells ======================================================
void monk_t::init_spells()
{
Expand Down
2 changes: 2 additions & 0 deletions engine/class_modules/monk/sc_monk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "sc_enums.hpp"
#include "sc_stagger.hpp"
#include "sim/proc.hpp"
#include "sim/sim_controller.hpp"
#include "util/timeline.hpp"

#include <array>
Expand Down Expand Up @@ -1476,6 +1477,7 @@ struct monk_t : public stagger_t<parse_player_effects_t, monk_t>
bool validate_fight_style( fight_style_e style ) const override;

// Init / Reset
void init() override;
void create_pets() override;
void init_spells() override;
void init_background_actions() override;
Expand Down
11 changes: 11 additions & 0 deletions engine/report/json/report_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,11 @@ void profileset_json2( const profileset::profilesets_t& profileset, const sim_t&
}
}

// report source, location, and reason of interrupt for
// all registered profileset sim controllers
// for ( const auto& controller: sim.sim_controllers )
// controller->report_json_profileset( obj );

// Optional override ouput data
if ( !sim.profileset_output_data.empty() )
{
Expand Down Expand Up @@ -1092,6 +1097,12 @@ void profileset_json3( const profileset::profilesets_t& profilesets, const sim_t
obj[ "iterations" ] = as<uint64_t>( result.iterations() );
}

// report source, location, and reason of interrupt for
// all registered profileset sim controllers
// for ( const auto& controller: sim.sim_controllers )
// controller->report_json_profileset( obj );


// Optional override ouput data
if ( !sim.profileset_output_data.empty() )
{
Expand Down
23 changes: 23 additions & 0 deletions engine/report/report_html_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,29 @@ void print_profilesets( std::ostream& out, const profileset::profilesets_t& prof

print_profilesets_chart( out, sim );


if ( sim.sim_controller_data.size() )
{
out << "<h3 class=\"toggle\">Profileset Sim Control</h3>\n";
out << "<div class=\"toggle-content hide\">\n";

out << "<div class=\"note\" style=\"margin:6px 0;\"><strong>Sim Controllers</strong><ul>\n";
for ( const auto& [ key, controller_data ] : sim.sim_controller_data )
controller_data.report_html_options( out );
out << "</ul></div>\n";

// report source, location, and reason of interrupt for
// all registered profileset sim controllers
// TODO: check if any are culled, otherwise omit table
out << "<div class=\"note\" style=\"margin:6px 0;\"><strong>Interrupted Profilesets</strong><ul>\n";
for ( const auto& [ key, controller_data ] : sim.sim_controller_data )
if ( controller_data.exit_reasons.size() )
controller_data.report_html_profileset( out );
out << "</ul></div>\n";
out << "</div>";
}


out << "</div>";
out << "</div>";
}
Expand Down
6 changes: 6 additions & 0 deletions engine/sim/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,8 @@ sim_t::sim_t()
count_overheal_as_heal( false ),
scaling_normalized( 1.0 ),
merge_enemy_priority_dmg( false ),
sim_controllers(),
sim_controller_data(),
// Multi-Threading
threads( 0 ),
thread_index( 0 ),
Expand Down Expand Up @@ -3059,6 +3061,8 @@ bool sim_t::iterate()

progress_bar.init();

sim_controller_t::evaluate( this, sim_controller_t::POST_INIT );

try
{
activate_actors();
Expand All @@ -3076,6 +3080,8 @@ bool sim_t::iterate()
progress_bar.output( false );
}

sim_controller_t::evaluate( this, sim_controller_t::POST_ITER );

do_pause();
auto old_active = current_index;
if ( !canceled )
Expand Down
116 changes: 116 additions & 0 deletions engine/sim/sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "progress_bar.hpp"
#include "sim_ostream.hpp"
#include "sim/option.hpp"
#include "interfaces/sc_js.hpp"
#include "util/concurrency.hpp"
#include "util/rng.hpp"
#include "util/sample_data.hpp"
Expand All @@ -19,6 +20,7 @@

#include <map>
#include <memory>
#include <mutex>

struct actor_target_data_t;
struct buff_t;
Expand Down Expand Up @@ -49,6 +51,114 @@ namespace profileset{
class profilesets_t;
}

struct sim_controller_data_t;
template <typename T>
struct data_wrapper_t
{
T& data;

data_wrapper_t( T& data, std::recursive_mutex& m ) : data( data ), lock( m )
{
}

private:
std::scoped_lock<std::recursive_mutex> lock;
};

struct exit_reason_t;
struct sim_controller_data_wrapper_t
{
std::recursive_mutex mutex;
std::unique_ptr<sim_controller_data_t> data;
std::vector<exit_reason_t> exit_reasons;
std::vector<std::unique_ptr<option_t>> options;

sim_controller_data_wrapper_t();
sim_controller_data_wrapper_t( std::unique_ptr<sim_controller_data_t>&& data );

~sim_controller_data_wrapper_t() = default;

void report_json_profileset( js::JsonOutput& ) const;
void report_json_options( js::JsonOutput& ) const;
void report_html_profileset( std::ostream& ) const;
void report_html_options( std::ostream& ) const;

// disallow copy, as that would introduce additional mutexes for a single controller name
sim_controller_data_wrapper_t( const sim_controller_data_wrapper_t& ) = delete;
};

// local profileset data and methods
struct sim_controller_t
{
using data_t = sim_controller_data_t;

enum call_point_e
{
NONE,
POST_INIT,
POST_ITER
};

static const std::string call_point_string( call_point_e call_point );
static void evaluate( sim_t* sim, call_point_e call_point );
template <typename TBase, typename... Args,
typename = typename std::enable_if_t<std::is_constructible_v<TBase, sim_t*, Args...>, bool>>
static bool register_sim_controller( sim_t* sim, Args&&... args );

sim_t* parent;
sim_t* sim;

sim_controller_t( sim_t* sim );
virtual ~sim_controller_t() = default;

sim_controller_t( sim_controller_t& ) = delete;
sim_controller_t( const sim_controller_t& ) = delete;

const std::string message( call_point_e );
void add_option( std::unique_ptr<option_t> );

virtual const std::string name() const = 0;
virtual const std::string reason() const = 0;
virtual void create_options() {}

virtual bool evaluate_post_init()
{
return true;
}

virtual bool evaluate_post_iter()
{
return true;
}

protected:
template <typename T>
data_wrapper_t<T> get_data();
template <typename T>
void set_data( T&& data );
};

struct exit_reason_t
{
const std::string profileset_name;
const sim_controller_t::call_point_e exit_point;
const std::string exit_reason;

exit_reason_t( const std::string profileset_name, const sim_controller_t::call_point_e exit_point, const std::string exit_reason )
: profileset_name( profileset_name ), exit_point( exit_point ), exit_reason( exit_reason )
{}
};

// global profileset data to be shared across all instantiations of a derived `sim_controller_t`
struct sim_controller_data_t
{
sim_controller_data_t();
sim_controller_data_t( sim_controller_data_t& data );
sim_controller_data_t( const sim_controller_data_t& ) = delete;

virtual ~sim_controller_data_t() = default;
};

struct sim_progress_t
{
int current_iterations;
Expand Down Expand Up @@ -622,6 +732,11 @@ struct sim_t : private sc_thread_t
double scaling_normalized;
bool merge_enemy_priority_dmg;

// sim control
std::vector<std::unique_ptr<sim_controller_t>> sim_controllers;
std::map<std::string, sim_controller_data_wrapper_t> sim_controller_data;

public:
// Multi-Threading
mutex_t merge_mutex;
int threads;
Expand Down Expand Up @@ -796,6 +911,7 @@ struct sim_t : private sc_thread_t
{ return _rng; }
double averaged_range( double min, double max );


// Thread id of this sim_t object
#ifndef SC_NO_THREADING
std::thread::id thread_id() const
Expand Down
Loading
Loading