Remove game_events::wml_event_pump::wml_tracking()

The variable **always** changed when event handlers were run, and thus the
optimizations to avoid updating some status after WML/Lua has run weren't
doing anything. In addition, commit 62ec3b3951 removed the most
important optimization that relied on wml_tracking().

Resolves #2578.

(cherry-picked from commit f0896bdf8c)
This commit is contained in:
Jyrki Vesterinen 2018-06-09 19:26:08 +03:00
parent 5b412030f4
commit a5739073ea
3 changed files with 6 additions and 49 deletions

View file

@ -838,14 +838,8 @@ namespace { // Private helpers for move_unit()
*/
void unit_mover::pump_sighted(const route_iterator & from)
{
const std::size_t track = resources::game_events->pump().wml_tracking();
auto pump_res = clearer_.fire_events();
if (track != resources::game_events->pump().wml_tracking()) {
// Some WML fired, so update our status.
post_wml(pump_res, from);
}
game_events::pump_result_t pump_res = clearer_.fire_events();
post_wml(pump_res, from);
}

View file

@ -87,9 +87,6 @@ struct pump_impl
{
std::vector<queued_event> events_queue;
/// The value returned by wml_tracking();
std::size_t internal_wml_tracking;
std::stringstream wml_messages_stream;
std::stack<context::state> contexts_;
@ -100,7 +97,6 @@ struct pump_impl
pump_impl(manager& man)
: events_queue()
, internal_wml_tracking(0)
, wml_messages_stream()
, contexts_()
, instance_count(0)
@ -298,7 +294,6 @@ void wml_event_pump::process_event(handler_ptr& handler_p, const queued_event& e
}
// The event hasn't been filtered out, so execute the handler.
++impl_->internal_wml_tracking;
context::scoped evc(impl_->contexts_);
assert(resources::lua_kernel != nullptr);
handler_p->handle_event(ev, *resources::lua_kernel);
@ -547,8 +542,6 @@ pump_result_t wml_event_pump::operator()()
DBG_EH << "processing queued events: " << ss.str() << "\n";
}
const std::size_t old_wml_track = impl_->internal_wml_tracking;
// Ensure the whiteboard doesn't attempt to build its future unit map
// while events are being processed.
wb::real_map real_unit_map;
@ -572,12 +565,7 @@ pump_result_t wml_event_pump::operator()()
{ // Block for context::scoped
context::scoped inner_evc(impl_->contexts_, false);
if(resources::lua_kernel->run_event(ev)) {
// TODO: since feeding was moved to lua we _always_ have a lua on_event handler so
// lua_kernel->run_event always returns true. So maybe we should remove this
// internal_wml_tracking thing (in particular the 'optimisation' in the movement code)?
++impl_->internal_wml_tracking;
}
resources::lua_kernel->run_event(ev);
}
assert(impl_->my_manager);
@ -609,11 +597,9 @@ pump_result_t wml_event_pump::operator()()
flush_messages();
}
if(old_wml_track != impl_->internal_wml_tracking) {
// Notify the whiteboard of any event.
// This is used to track when moves, recruits, etc. happen.
resources::whiteboard->on_gamestate_change();
}
// Notify the whiteboard of any event.
// This is used to track when moves, recruits, etc. happen.
resources::whiteboard->on_gamestate_change();
return std::make_tuple(undo_disabled(), action_canceled());
}
@ -627,26 +613,6 @@ void wml_event_pump::flush_messages()
}
}
/**
* This function can be used to detect when no WML/Lua has been executed.
*
* If two calls to this function return the same value, then one can
* assume that the usual game mechanics have been followed, and code does
* not have to account for all the things WML/Lua can do. If the return
* values are different, then something unusual might have happened between
* those calls.
*
* This is not intended as a precise metric. Rather, it is motivated by
* how large the number of fired WML events is, compared to the (typical)
* number of WML event handlers. It is intended for code that can benefit
* from caching some aspect of the game state and that cannot rely on
* [allow_undo] not being used when that state changes.
*/
std::size_t wml_event_pump::wml_tracking()
{
return impl_->internal_wml_tracking;
}
wml_event_pump::wml_event_pump(manager& man)
: impl_(new pump_impl(man))
{

View file

@ -141,9 +141,6 @@ public:
/** Flushes WML messages and errors. */
void flush_messages();
/** This function can be used to detect when no WML/Lua has been executed. */
std::size_t wml_tracking();
private:
bool filter_event(const event_handler& handler, const queued_event& ev);