note description: "GAME_HAPTIC_EFFECT that play at a custom strength." author: "Louis Marchand" date: "Tue, 03 Mar 2015 14:16:22 +0000" revision: "2.0" class GAME_HAPTIC_CUSTOM_EFFECT inherit GAME_HAPTIC_EFFECT_INFINITE_LENGTH redefine make end GAME_HAPTIC_EFFECT_ENVELOPE redefine make end PLATFORM POINTER_REF rename item as null undefine out, is_equal end DISPOSABLE create make feature -- Initialization make -- Initialization of Current do Precursor set_type ({GAME_SDL_EXTERNAL}.sdl_haptic_custom.as_natural_16) set_axes_count (1) ensure then axes_number_valid: axes_count >= 1 type_valid: type.to_natural_32 = {GAME_SDL_EXTERNAL}.sdl_haptic_custom end feature -- Access direction: GAME_HAPTIC_DIRECTION assign set_direction -- The orientation that the force of Current come from require exists: exists do create Result.make_by_pointer ({GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_direction (specific_item)) end set_direction (a_direction: GAME_HAPTIC_DIRECTION) -- assign direction with the values of a_direction require exists: exists do direction.copy (a_direction) ensure is_assign: direction ~ a_direction end length: NATURAL_32 assign set_length -- Duration of Current (in millisecond) do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_length (specific_item) end set_length (a_length: NATURAL_32) -- Assign length with the value of a_length do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_length (specific_item, a_length) end delay: NATURAL_16 assign set_delay -- delay before starting Current (in millisecond) do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_delay (specific_item) end set_delay (a_delay: NATURAL_16) -- Assign delay with the value of a_delay do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_delay (specific_item, a_delay) end interval: NATURAL_16 assign set_interval -- how soon before effect can be triggered again (in millisecond) do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_interval (specific_item) end set_interval (a_interval: NATURAL_16) -- Assign interval with the value of a_interval do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_interval (specific_item, a_interval) end axes_count: NATURAL_8 assign set_axes_number -- The number of axes to use require exists: exists do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_channels (specific_item) end set_axes_count (a_count: NATURAL_8) -- Assign axes_count with the value of a_count -- Note: Callig this routine will clear the samples (to satisfied invariant) require exists: exists number_valid: a_count >= 1 do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_channels (specific_item, a_count) set_samples (create {ARRAYED_LIST [NATURAL_16]}.make (0)) ensure is_assign: axes_count = a_count samples_valid_for_every_axes: samples.count.divisible (axes_count.to_integer_32) end axes_number: NATURAL_8 assign set_axes_number obsolete "Use `axes_count' instead" -- The number of axes to use require exists: exists do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_channels (specific_item) end set_axes_number (a_number: NATURAL_8) obsolete "Use `set_axes_count' instead" -- Assign axes_number with the value of a_number -- Note: Callig this routine will clear the samples (to satisfied invariant) require exists: exists number_valid: a_number >= 1 do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_channels (specific_item, a_number) set_samples (create {ARRAYED_LIST [NATURAL_16]}.make (0)) ensure is_assign: axes_number = a_number samples_valid_for_every_axes: samples.count.divisible (axes_number.to_integer_32) end period: NATURAL_16 assign set_period -- Time (in millisecond) between two samples. require exists: exists do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_period (specific_item) end set_period (a_period: NATURAL_16) -- Assign period with the value of a_period require exists: exists period_valid: a_period <= 32767 do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_period (specific_item, a_period) ensure is_assign: period = a_period end samples: ARRAYED_LIST [NATURAL_16] assign set_samples -- Value sequence to play Current require exists: exists local l_managed_pointer: MANAGED_POINTER l_samples_ptr: POINTER l_count, l_byte_count, i: INTEGER_32 do l_samples_ptr := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_data (specific_item) l_count := axes_count.to_natural_16 * {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_samples (specific_item).to_integer_32 l_byte_count := l_count * Natural_16_bytes create Result.make (l_count) create l_managed_pointer.make_from_pointer (l_samples_ptr, l_byte_count) from i := 0 until i >= l_byte_count loop Result.extend (l_managed_pointer.read_natural_16 (i)) i := i + Natural_16_bytes end end set_samples (a_samples: ARRAYED_LIST [NATURAL_16]) -- Assign samples with the values in a_samples require exists: exists samples_for_all_axes: a_samples.count.divisible (axes_count.to_integer_32) local l_pointer: POINTER l_array: ARRAY [NATURAL_16] l_count, l_byte_count: INTEGER_32 do l_count := axes_count.to_natural_16 * {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_samples (specific_item).to_integer_32 l_byte_count := l_count * Natural_16_bytes l_array := a_samples.to_array l_pointer := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_data (specific_item) if not l_pointer.is_default_pointer then l_pointer.memory_free end l_pointer := l_pointer.memory_alloc (l_byte_count) c_memcpy ($l_array.to_pointer, l_pointer, l_byte_count) {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_data (specific_item, l_pointer) ensure is_assign: samples ~ a_samples samples_valid_for_every_axes: samples.count.divisible (axes_count.to_integer_32) end fade_in_level: NATURAL_16 assign set_fade_in_level -- level at the start of the fade in do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_attack_level (specific_item) end set_fade_in_level (a_fade_in_level: NATURAL_16) -- Assign fade_in_level with the value of a_fade_in_level do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_attack_level (specific_item, a_fade_in_level) end fade_in_length: NATURAL_16 assign set_fade_in_length -- length of the fade in do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_attack_length (specific_item) end set_fade_in_length (a_fade_in_length: NATURAL_16) -- Assign fade_in_length with the value of a_fade_in_length do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_attack_length (specific_item, a_fade_in_length) end fade_out_level: NATURAL_16 assign set_fade_out_level -- level at the start of the fade out do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_fade_level (specific_item) end set_fade_out_level (a_fade_out_level: NATURAL_16) -- Assign fade_out_level with the value of a_fade_out_level do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_fade_level (specific_item, a_fade_out_level) end fade_out_length: NATURAL_16 assign set_fade_out_length -- length of the fade out do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_fade_length (specific_item) end set_fade_out_length (a_fade_out_length: NATURAL_16) -- Assign fade_out_length with the value of a_fade_out_length do {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_fade_length (specific_item, a_fade_out_length) end feature {NONE} -- Implementation specific_item: POINTER -- Internal pointer that is specific to a certain type of Current -- Note that item only point to a C union. do Result := {GAME_SDL_EXTERNAL}.get_sdl_haptic_effect_custom (item) end dispose -- Action to be executed just before garbage collection -- reclaims an object. -- Effect it in descendants to perform specific dispose -- actions. Those actions should only take care of freeing -- external resources; they should not perform remote calls -- on other objects since these may also be dead and reclaimed. local l_samples_pointer: POINTER do l_samples_pointer := {GAME_SDL_EXTERNAL}.get_sdl_haptic_custom_data (specific_item) if not l_samples_pointer.is_default_pointer then l_samples_pointer.memory_free {GAME_SDL_EXTERNAL}.set_sdl_haptic_custom_data (specific_item, null) end end invariant axes_number_valid: axes_count >= 1 samples_valid_for_every_axes: samples.count.divisible (axes_count.to_integer_32) end -- class GAME_HAPTIC_CUSTOM_EFFECT
Generated by ISE EiffelStudio