std::function and delegate both require runtime relocations, slowing down startup - just use function pointers; also, most downcast, and get rid of a circular dependency between gamedrv.h and mconfig.h (nw)

This commit is contained in:
Vas Crabb 2018-01-18 18:56:01 +11:00
parent d853daeae3
commit a0dfee78d6
5 changed files with 19 additions and 49 deletions

View File

@ -35,10 +35,6 @@ protected:
// internal state
const char *m_device_name;
public:
// getter (for validation purposes)
const char *device_name() const { return m_device_name; }
};
@ -102,6 +98,9 @@ public:
// perform the binding
void bind_relative_to(device_t &search_root) { if (!basetype::isnull()) basetype::late_bind(bound_object(search_root)); }
// getter (for validation purposes)
const char *device_name() const { return m_device_name; }
};

View File

@ -173,8 +173,7 @@ const tiny_rom_entry *driver_device::device_rom_region() const
void driver_device::device_add_mconfig(machine_config &config)
{
assert(m_system);
machine_config_delegate creator(m_system->machine_creator, *this);
creator(config);
m_system->machine_creator(config, *this);
}
@ -202,7 +201,7 @@ void driver_device::device_start()
throw device_missing_dependencies();
// call the game-specific init
m_system->driver_init(machine());
m_system->driver_init(*this);
// finish image devices init process
machine().image().postdevice_init();

View File

@ -115,7 +115,4 @@ typedef void (*machine_config_constructor)(machine_config &config, device_t *own
// member templates that don't like incomplete types
#include "device.ipp"
template <class DriverClass> void game_driver::driver_init_helper_impl<DriverClass>::invoke(driver_init_helper const &helper, running_machine &machine)
{ (machine.driver_data<DriverClass>()->*static_cast<driver_init_helper_impl<DriverClass> const &>(helper).m_method)(); }
#endif /* __EMU_H__ */

View File

@ -101,31 +101,8 @@ constexpr u64 MACHINE_IS_SKELETON_MECHANICAL = MACHINE_IS_SKELETON | MACHINE_
class game_driver
{
public:
class driver_init_helper
{
public:
void operator()(running_machine &machine) const { m_function(*this, machine); }
protected:
constexpr driver_init_helper(void (*function)(driver_init_helper const &, running_machine &)) : m_function(function) { }
constexpr driver_init_helper(driver_init_helper const &) = default;
private:
void (* const m_function)(driver_init_helper const &, running_machine &);
};
template <class DriverClass> class driver_init_helper_impl : public driver_init_helper
{
public:
constexpr driver_init_helper_impl(void (DriverClass::*method)()) : driver_init_helper(&driver_init_helper_impl<DriverClass>::invoke), m_method(method) { }
constexpr driver_init_helper_impl(driver_init_helper_impl<DriverClass> const &) = default;
private:
static void invoke(driver_init_helper const &helper, running_machine &machine);
void (DriverClass::*const m_method)();
};
template <class DriverClass> static constexpr auto make_driver_init(void (DriverClass::*method)())
{
return driver_init_helper_impl<DriverClass>(method);
}
typedef void (*machine_creator_wrapper)(machine_config &, device_t &);
typedef void (*driver_init_wrapper)(device_t &);
static constexpr device_t::feature_type unemulated_features(u64 flags)
{
@ -152,9 +129,9 @@ public:
const char * parent; // if this is a clone, the name of the parent
const char * year; // year the game was released
const char * manufacturer; // manufacturer of the game
machine_config_delegate machine_creator; // machine driver tokens
machine_creator_wrapper machine_creator; // machine driver tokens
ioport_constructor ipt; // pointer to constructor for input ports
driver_init_helper const & driver_init; // DRIVER_INIT callback
driver_init_wrapper driver_init; // DRIVER_INIT callback
const tiny_rom_entry * rom; // pointer to list of ROMs for the game
const char * compatible_with;
const internal_layout * default_layout; // default internally defined layout
@ -202,9 +179,9 @@ extern game_driver const GAME_NAME(NAME) \
#PARENT, \
#YEAR, \
COMPANY, \
machine_config_delegate(FUNC(CLASS::MACHINE), DEVICE_SELF, (CLASS *)nullptr), \
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
[] (device_t &owner) { downcast<CLASS &>(owner).init_##INIT(); }, \
ROM_NAME(NAME), \
nullptr, \
nullptr, \
@ -221,9 +198,9 @@ extern game_driver const GAME_NAME(NAME) \
#PARENT, \
#YEAR, \
COMPANY, \
machine_config_delegate(FUNC(CLASS::MACHINE), DEVICE_SELF, (CLASS *)nullptr), \
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
[] (device_t &owner) { downcast<CLASS &>(owner).init_##INIT(); }, \
ROM_NAME(NAME), \
nullptr, \
&LAYOUT, \
@ -241,9 +218,9 @@ extern game_driver const GAME_NAME(NAME) \
#PARENT, \
#YEAR, \
COMPANY, \
machine_config_delegate(FUNC(CLASS::MACHINE), DEVICE_SELF, (CLASS *)nullptr), \
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
[] (device_t &owner) { downcast<CLASS &>(owner).init_##INIT(); }, \
ROM_NAME(NAME), \
#COMPAT, \
nullptr, \
@ -260,9 +237,9 @@ extern game_driver const GAME_NAME(NAME) \
#PARENT, \
#YEAR, \
COMPANY, \
machine_config_delegate(FUNC(CLASS::MACHINE), DEVICE_SELF, (CLASS *)nullptr), \
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
[] (device_t &owner) { downcast<CLASS &>(owner).init_##INIT(); }, \
ROM_NAME(NAME), \
#COMPAT, \
nullptr, \
@ -279,9 +256,9 @@ extern game_driver const GAME_NAME(NAME) \
#PARENT, \
#YEAR, \
COMPANY, \
machine_config_delegate(FUNC(CLASS::MACHINE), DEVICE_SELF, (CLASS *)nullptr), \
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
[] (device_t &owner) { downcast<CLASS &>(owner).init_##INIT(); }, \
ROM_NAME(NAME), \
#COMPAT, \
nullptr, \

View File

@ -83,8 +83,6 @@ private:
std::unique_ptr<device_t> m_root_device;
};
typedef device_delegate<void (machine_config &)> machine_config_delegate;
//*************************************************************************/
/** @name Machine config start/end macros */