indexing description: "[ Singleton representing the Joystick subsystem. Use EM_SHARED_SUBSYSTEMS to access this class. ]" date: "$Date$" revision: "$Revision$" class EM_JOYSTICK_SUBSYSTEM inherit EM_SUBSYSTEM SDL_JOYSTICK_FUNCTIONS_EXTERNAL export {NONE} all end create {EM_SHARED_BASE_SUBSYSTEMS} make feature {NONE} -- Initialization make is do create devices.make ensure not_enabled: not is_enabled end feature -- Status report is_enabled: BOOLEAN is -- Is the joystick subsystem enabled? do Result := 0 /= sdl_was_init_external (Em_init_joystick) end feature -- Subsysten management enable is -- Enable EiffelMedia Joystick subsystem. local i: INTEGER do i := sdl_init_external (Em_init_joystick) if i >= 0 then -- device count count := sdl_num_joysticks_external end end disable is -- Disable EiffelMedia Joystick subsystem. local cur_item: EM_JOYSTICK do -- first close all open device handler from devices.start until devices.after loop cur_item := devices.item devices.forth cur_item.close end sdl_quit_sub_system_external (Em_init_joystick) ensure then no_active_devices: devices.count = 0 end feature {EM_JOYSTICK} -- device administration devices: LINKED_LIST [EM_JOYSTICK] -- list of all active devices register_device (a_device: EM_JOYSTICK) is -- register a new device handler require not_already_registered: not devices.has (a_device) do devices.extend (a_device) ensure registration_success: devices.has (a_device) end unregister_device (a_device: EM_JOYSTICK) is -- unregister a device handler require device_registered: devices.has (a_device) do devices.start devices.prune (a_device) ensure unregistration_success: not devices.has (a_device) end feature -- joystick subsystem name (a_device: INTEGER): STRING is -- return the joystick device identifier of device `a_device' -- this argument is system dependent require subsystem_ebabled: is_enabled local str: EWG_ZERO_TERMINATED_STRING do -- This has to be done shared: SDL collects everything create str.make_shared (sdl_joystick_name_external (a_device)) result := str.string end count: INTEGER -- joystick device count name_list: DS_LINKED_LIST [STRING] is -- return a list of all device names local i: INTEGER do -- create list create result.make -- fill the list with all joystick device names from i := 0 until i = count loop result.put_last (name (i)) i := i + 1 end end end