add msg handling (#1737)

This commit is contained in:
David Markowitz
2025-01-19 22:42:15 -08:00
committed by GitHub
parent 1b3cdc6d9c
commit e4c2eecbc7
10 changed files with 163 additions and 13 deletions

View File

@@ -2216,3 +2216,17 @@ int32_t Entity::GetCollisionGroup() const {
return 0;
}
bool Entity::HandleMsg(GameMessages::GameMsg& msg) const {
bool handled = false;
const auto [beg, end] = m_MsgHandlers.equal_range(msg.msgId);
for (auto it = beg; it != end; ++it) {
if (it->second) handled |= it->second(msg);
}
return handled;
}
void Entity::RegisterMsg(const MessageType::Game msgId, std::function<bool(GameMessages::GameMsg&)> handler) {
m_MsgHandlers.emplace(msgId, handler);
}