[Commits] [wesnoth/wesnoth] 056d7a: Game Events: refactored event handler storage

GitHub noreply at github.com
Tue Nov 28 21:04:10 UTC 2017


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: 056d7ac8f88ca4614b22d10894235a93c1637eb2
      https://github.com/wesnoth/wesnoth/commit/056d7ac8f88ca4614b22d10894235a93c1637eb2
  Author: Charles Dang <exodia339 at gmail.com>
  Date:   2017-11-29 (Wed, 29 Nov 2017)

  Changed paths:
    M src/game_events/handlers.cpp
    M src/game_events/handlers.hpp
    M src/game_events/manager.cpp
    M src/game_events/manager.hpp
    M src/game_events/manager_impl.cpp
    M src/game_events/manager_impl.hpp
    M src/game_events/pump.cpp
    R src/utils/smart_list.hpp

  Log Message:
  -----------
  Game Events: refactored event handler storage

This throws out the custom smart_list class in favor of a plain std::list. It also greatly simplifies
a few things. First, event handlers no longer remove themselves from the main list in event_handlers.
Now they just flag themselves as disabled (which means they will never execute once marked) and cleaned
up later in a newly added cleanup stage. This means a handler no longer needs to keep its index in the
active handler vector.

This removal of reliance on indices also means I could add the aforementioned cleanup stage. With the
smart_list code, event handlers were never actually removed from the active vector, nor any weak_ptrs
pointing to them removed either. This wasn't exactly a problem, since the handlers were stored via
shared_ptrs which would then simply be null after one deleted itself. Still, it's cleaner to drop any
invalid ones (and unlockable weak_ptrs) from any relevant containers. I've opted to do this in
manager::execute_on_events. Seems a good enough place as any.

The net result of this is the code is much cleaner. We're able to get rid of a bunch of unnecessary
feelers into various classes. This also makes the manager::iteration dereference code a lot easier
to understand. There certainly could be further refactoring, but I think this is a good start.


  Commit: 230dce9fec1fc24fc2bf8e3e5c9943e2d161988c
      https://github.com/wesnoth/wesnoth/commit/230dce9fec1fc24fc2bf8e3e5c9943e2d161988c
  Author: Charles Dang <exodia339 at gmail.com>
  Date:   2017-11-29 (Wed, 29 Nov 2017)

  Changed paths:
    M src/game_events/handlers.cpp

  Log Message:
  -----------
  Minor cleanup to 2045b6739e0f4e544

[ci skip]


Compare: https://github.com/wesnoth/wesnoth/compare/f62b62b7008b...230dce9fec1f


More information about the Commits mailing list