Convert get_multi_endlevel_poll2 to dispatch through a vtable

This commit is contained in:
Kp 2020-12-20 20:39:07 +00:00
parent 407678dfdf
commit 2007257064
5 changed files with 9 additions and 20 deletions

View file

@ -237,6 +237,7 @@ constexpr std::integral_constant<unsigned, 21> MULTI_ALLOW_POWERUP_TEXT_LENGTH{}
#endif
namespace multi {
using endlevel_poll_function_type = int(newmenu *menu,const d_event &event, const unused_newmenu_userdata_t *);
struct dispatch_table
{
constexpr const dispatch_table *operator->() const
@ -247,6 +248,7 @@ struct dispatch_table
virtual void do_protocol_frame(int force, int listen) const = 0;
virtual window_event_result level_sync() const = 0;
virtual void send_endlevel_packet() const = 0;
virtual endlevel_poll_function_type *get_endlevel_poll2() const = 0;
};
}
}
@ -485,9 +487,7 @@ void multi_consistency_error(int reset);
window_event_result multi_level_sync();
int multi_endlevel(int *secret);
#ifdef dsx
using multi_endlevel_poll = int(newmenu *menu,const d_event &event, const unused_newmenu_userdata_t *);
namespace dsx {
multi_endlevel_poll *get_multi_endlevel_poll2();
void multi_send_hostage_door_status(vcwallptridx_t wallnum);
void multi_prep_level_objects(const d_vclip_array &Vclip);
void multi_prep_level_player();

View file

@ -30,6 +30,7 @@ struct dispatch_table final : multi::dispatch_table
virtual void do_protocol_frame(int force, int listen) const override;
virtual window_event_result level_sync() const override;
virtual void send_endlevel_packet() const override;
virtual endlevel_poll_function_type *get_endlevel_poll2() const override;
};
extern const dispatch_table dispatch;

View file

@ -312,7 +312,7 @@ window_event_result kmatrix_window::event_handler(const d_event &event)
nm_item_menu(TXT_YES),
nm_item_menu(TXT_NO),
}};
choice = newmenu_do2(menu_title{nullptr}, menu_subtitle{TXT_ABORT_GAME}, nm_message_items, network != kmatrix_network::offline ? get_multi_endlevel_poll2() : unused_newmenu_subfunction, unused_newmenu_userdata);
choice = newmenu_do2(menu_title{nullptr}, menu_subtitle{TXT_ABORT_GAME}, nm_message_items, network != kmatrix_network::offline ? multi::dispatch->get_endlevel_poll2() : unused_newmenu_subfunction, unused_newmenu_userdata);
}
if (choice==0)

View file

@ -1126,23 +1126,6 @@ int multi_endlevel(int *const secret)
return(result);
}
namespace dsx {
multi_endlevel_poll *get_multi_endlevel_poll2()
{
switch (multi_protocol)
{
#if DXX_USE_UDP
case MULTI_PROTO_UDP:
return multi::udp::kmatrix_poll2;
#endif
default:
throw std::logic_error("Protocol handling missing in multi_endlevel_poll2");
}
}
}
//
// Part 2 : functions that act on network messages and change the
// the state of the game in some way.

View file

@ -2521,6 +2521,11 @@ void dispatch_table::send_endlevel_packet() const
dxx_sendto(Netgame.players[0].protocol.udp.addr, UDP_Socket[0], buf, 0);
}
}
endlevel_poll_function_type *dispatch_table::get_endlevel_poll2() const
{
return kmatrix_poll2;
}
}
}
}