indexing description: "[ Sample scene which shows how to use the multiplayer frameworks EM_NET_CLIENT class. ]" date: "$Date$" revision: "$Revision$" class EM_MP_CLIENT_SCENE inherit EM_MP_SAMPLE_SCENE redefine create_widgets, handle_update_event end create make feature -- Initialisation make (a_socket: EM_INET_SOCKET_ADDRESS) is -- Init do -- first make the widget scene make_component_scene -- setup the client: create client.make (35703) client.set_server_address (a_socket) client.subscribe_by_type_id (client.object_types.em_net_status_request, agent on_status_request (?)) client.subscribe_by_type_id (client.object_types.em_net_join_response, agent on_successful_join (?)) client.subscribe_by_type_id (client.object_types.em_net_create_object_response, agent on_object_create (?)) -- setup our sample object the_square := client.object_types.create_square_on_circle drawables.container.extend (the_square) the_square.set_is_master_object (false) client.standard_group.add_object (the_square) client.set_nickname ("sample334") client.join client.enable_auto_transmit end feature {NONE} -- Implementation create_widgets is -- Create additional widgets local a_grey: EM_COLOR a_checkbox: EM_CHECKBOX do Precursor create a_grey.make_with_rgb (200,200,200) create timenudge_slider.make_from_range_horizontal (-1000, 1000) timenudge_slider.set_background_color (a_grey) timenudge_slider.set_current_value (0) timenudge_slider.set_position (590, 90) timenudge_slider.set_dimension (200, 50) timenudge_slider.position_changed_event.subscribe (agent on_timenudge_changed (?)) add_component (timenudge_slider) create timenudge_label.make_from_text ("timenudge: 0") timenudge_label.set_background_color (a_grey) timenudge_label.set_x (590); timenudge_label.set_y (120); timenudge_label.set_width (200) add_component (timenudge_label) create a_checkbox.make_from_text ("movement smoothing") a_checkbox.set_background_color (a_grey) a_checkbox.set_position (590, 150) a_checkbox.checked_event.subscribe (agent set_movement_smoothing(true)) a_checkbox.unchecked_event.subscribe (agent set_movement_smoothing(false)) add_component (a_checkbox) create block_updates_checkbox.make_from_text ("block updates") block_updates_checkbox.set_background_color (a_grey) block_updates_checkbox.set_position (590, 170) block_updates_checkbox.checked_event.subscribe (agent set_block_updates (true)) block_updates_checkbox.unchecked_event.subscribe (agent set_block_updates (false)) block_updates_checkbox.set_checked block_updates_checkbox.disable add_component (block_updates_checkbox) end handle_update_event is -- Handle outside event. do Precursor client.process_timed_procedures_in_same_thread the_square.move_interpolated if time.ticks > next_frame then time_label.set_text ("time: " + client.time.out) next_frame := time.ticks end end on_successful_join (a_join_response: EM_NET_JOIN_RESPONSE) is -- Handle a successful join attempt do if a_join_response.is_accepted then io.put_string("joined...%N") -- Start time synchronisation periode client.add_timed_procedure (agent activate (4), 500) else io.put_string("not accepted...%N") end end activate (times_left: INTEGER) is -- Activate the system do if times_left > 0 then status_message.set_text (status_message.text + times_left.out + "...") client.add_timed_procedure (agent activate (times_left -1), 500) else status_message.set_text ("GO!!") block_updates_checkbox.enable block_updates_checkbox.set_unchecked end end on_status_request (a_request: EM_NET_STATUS_REQUEST) is -- Handle status request. local a_message: EM_NET_STATUS_MESSAGE do a_message := client.object_types.create_em_net_status_message a_message.set_status ("helloo... my time is: " + client.time.out) client.publish (a_message) end on_object_create (a_response: EM_NET_CREATE_OBJECT_RESPONSE) is -- Handle object creation. do end on_timenudge_changed (tn: INTEGER) is -- Handle timenudge changed event. do the_square.set_timenudge (tn) timenudge_label.set_text ("timenudge: " + tn.out) end set_movement_smoothing(a_boolean: BOOLEAN) is -- Enable oder disable movement smoothing do the_square.set_movement_smoothing(a_boolean) -- TODO: if there are more squares (maybe added later), update them too... end set_block_updates(a_boolean: BOOLEAN) is -- Enable oder disable movement smoothing do the_square.set_block_updates(a_boolean) -- TODO: if there are more squares (maybe added later), update them too... end client: EM_NET_CLIENT [MY_OBJECT_TYPES] -- Client timenudge_slider: EM_SLIDER -- Timenudge slider timenudge_label: EM_LABEL -- Timenudge label block_updates_checkbox: EM_CHECKBOX next_frame: INTEGER -- Next frame to draw time end