Beispiel #1
0
/* execute the task callback function. */
static int task_func(void *argv) {
	struct kqueuemgr *mgr = (struct kqueuemgr *)argv;
	struct kevent *ev;
	struct socketer *sock;
	for (;;) {
		if (mgr->need_exit)
			return -1;
		ev = pop_event(mgr);
		if (!ev)
			return 0;
		assert(ev->udata != NULL);
		sock = (struct socketer *)ev->udata;

		/* error event. */
		if (ev->flags & EV_EOF || ev->flags & EV_ERROR) {
			socketer_close(sock);
			continue;
		}

		if (ev->filter == EVFILT_READ) {
			/* can read event. */
			if (catomic_compare_set(&sock->recvlock, 0, 1)) {
				catomic_inc(&sock->ref);
			}
			socketer_on_recv(sock, 0);
		} else 	if (ev->filter == EVFILT_WRITE) {
			/* can write event. */
			if (catomic_compare_set(&sock->sendlock, 0, 1)) {
				catomic_inc(&sock->ref);
			}
			socketer_on_send(sock, 0);
		}
	}
}
Beispiel #2
0
unsigned int
event_process() {
	Event *event;
	Subscribers *subscribers;
	int events_processed = 0;
	
	// deal with all events currently on the queue
	// TODO: may want to consider sticking a threshold on the number of
	//		events we handle in each batch if there are noticable performance
	//		issues.
	while (peek_events() > 0) {
		
		event = (Event *)pop_event();
		
		subscribers = get_subscribers(event->id);
		if (subscribers != NULL) {
			LOG_DEBUG("Subscribers found to handle event ID %d", event->id);
		}
		
		// The event should now be at the end of it's lifecycle and as such,
		// it's resources can be freed
		free(event);
		events_processed++;
	}
	
	return events_processed;
}
Beispiel #3
0
static void free_flight_cancel_quit_campaign (event *ev)
{
	set_ui_object_drawable (free_flight_dialog_area, FALSE);

	set_ui_object_drawable (free_flight_quit_campaign_area, FALSE);

	pop_event (quit_free_flight_set_events);
}
void* outputwriter_thread(void* arg) {
	for(;;) {
		char * e = pop_event();
		printf("%s\n", e);
		free(e);
	}
	return NULL;
}
jstring  Java_spade_reporter_AuditAndroid_readAuditStream (JNIEnv * env, jclass j_class) {
	jstring ret;
	char* str_ptr = pop_event();
	ret = (*env)->NewStringUTF(env, str_ptr);
	free(str_ptr);

	return ret;
}
Beispiel #6
0
void process_event(){
    /* debug_printf("process_event_s"); */
    /* printf("\n>>>>>>>>>>>>>><<process event "); */
    event_t *e = top_event();
    /* printf("event-->%.3f ", e->x);//print_point(&e->p); */
    /* printf("valid? %d\n", e->valid); */
    pop_event();

    if(e->valid!=FALSE){
        seg_t * new_seg = dispatch_seg();
        new_seg->start = e->p;

         /* printf("\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n"); */

         //   print_arc_list();


        arc_t *a = e->a;
        if(a->prev!=NULL){
            a->prev->next = a->next;
            a->prev->s1 = new_seg;

        }

        if(a->next!=NULL){
            a->next->prev = a->prev;
            a->next->s0 = new_seg;
        }

        //  print_arc_list();
        if(a->s0!=NULL){
            if(a->s0->done == FALSE){
                 a->s0->end = e->p;
                 a->s0->done = TRUE;
            }
        }
        if(a->s1!=NULL){
            if(a->s1->done == FALSE){
                a->s1->end = e->p;
                a->s1->done = TRUE;
            }

        }
        if(a->prev!=NULL) check_circle_event(a->prev, e->x);

        if(a->next!=NULL) check_circle_event(a->next, e->x);
    }

    /* debug_printf("process_event_e"); */


}
void USkookumScriptListener::deinitialize()
  {
  // Kill any events that are still around
  while (has_event())
    {
    free_event(pop_event(), true);
    }

  // Forget the coroutine we keep track of
  m_coro_p.null();

  // Unregister from delegate list if any
  if (m_unregister_callback_p && m_obj_p.IsValid())
    {
    (*m_unregister_callback_p)(m_obj_p.Get(), this);
    }
  }
Beispiel #8
0
int			execute_event(void *data)
{
  t_event		*event;
  struct itimerspec	new_value;

  if (event = pop_event(((t_evq*)data)->eventq))
    do_event(event, ((t_evq*)data)->p_id, ((t_evq*)data)->p_fd);
  else
    {
      debug("Timer set but no events registered");
      new_value.it_value.tv_sec = 0;
      new_value.it_value.tv_nsec = 0;
      new_value.it_interval.tv_sec = 0;
      new_value.it_interval.tv_nsec = 0;
      timerfd_settime(((t_evq*)data)->eventq->timerfd,
		      TFD_TIMER_ABSTIME, &new_value, NULL);
    }
  debug("Event executed");
  return (EXIT_SUCCESS);
}
Beispiel #9
0
void abort_alpha_entry (event *ev)
{

	void
		((*old_abort_alpha_entry_function) (int key));

	old_abort_alpha_entry_function = abort_alpha_entry_function;

	pop_event (NULL);

	end_alpha_entry_function = NULL;

	abort_alpha_entry_function = NULL;

	alpha_entry_function = NULL;

	if (old_abort_alpha_entry_function)
	{

		old_abort_alpha_entry_function (((event *) ev)->key);
	}
}
Beispiel #10
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  stim_mainloop
 *  Description:  checkout mark_list,and execute callback funtion if mark be setted.
 *                this function must be execute by while loop in main.c
 * =====================================================================================
 */
void stim_mainloop ( void )
{
  uint8_t i;
  
  for(i = 0; i < STIM_EVENT_MAX_SIZE; i++){
    if((mark_list[i] != STIM_INVALID) && (mark_list[i] > 0)){
      if(callback_list[i] != NULL){
        callback_list[i]();
      }
      mark_list[i] -= 1;
    }
  }

  if(recycle_count > 0){
    for(i = 0; i < STIM_EVENT_MAX_SIZE; i++){
      if(recycle_list[i] != NULL){
        pop_event(recycle_list[i]);
        recycle_count--;
        break;
      }
    }
  }

}		/* -----  end of function stim_loop  ----- */
Beispiel #11
0
void comms_process_data (void)
{

	session_list_data_type
		*current_session;

	connection_list_type
		*this_connection,
		*connection;

	char
		*received_data;

	int
		planner_event,
		frame_id,
		packet_id,
		receive_flag,
		received_size;

	GUID
		received_id = 0;

	entity
		*member;

	send_types
		send_type;

	packet_types
		type;

	// receive all packets in queue

	current_session = get_current_game_session ();

	received_size = MAX_RECEIVE_SIZE;

	connection = get_connection_list_head ();

	while (connection)
	{

		this_connection = connection;

		connection = connection->next;

		send_type = SEND_TYPE_GROUP;

		while (send_type >= SEND_TYPE_PERSONAL)
		{

			receive_flag = TRUE;

			while (receive_flag)
			{

				type = process_packet_list (send_type, this_connection, &received_id, &received_data, &received_size);

				switch (type)
				{

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// System packets, used internally
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_INVALID:
					{

						receive_flag = FALSE;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							if (this_connection->packet_rerequested > command_line_comms_packet_rerequest_limit)
							{

								debug_log ("COMM_MAN: REJECTING CONNECTION. CONNECTION TOO BAD (re-request limit %d reached)", command_line_comms_packet_rerequest_limit);

								send_packet (this_connection->connection_id, PACKET_TYPE_SERVER_REJECTED, NULL, 0, SEND_TYPE_PERSONAL);
							}
						}

						break;
					}

					case PACKET_TYPE_RESEND_PACKET:
					{

						send_types
							resend_send_type;

						frame_id = get_list_item (received_data, int);

						packet_id = get_list_item (received_data, int);

						resend_send_type = get_list_item (received_data, send_types);

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received RESEND PACKET for frame %d packet %d from %s (dpid %d)",
											frame_id, packet_id,
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: received RESEND PACKET by unknown (pdid %d)",
											received_id);
						}

						#endif

						resend_packet (received_id, frame_id, packet_id, resend_send_type);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// Packets for initialisation and joining
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_SESSION_QUERY:
					{

						char
							*ptr;

						int
							server_version_number,
							player_count,
							size;

						connection_list_type
							*new_connection;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %d", received_id);
							}

							#endif

							new_connection = get_connection_list_item (received_id);

							if (!new_connection->already_sent_query_data)
							{

								new_connection->already_sent_query_data = TRUE;

								while (TRUE)
								{

									ptr = new_connection->connection_receive_buffer;

									size = 0;

									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									//
									// Check both client and server are running same campaign data
									//
									server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

									quick_set_list_item (ptr, int, server_version_number);

									size += sizeof (int);
									//
									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

									// map details

									quick_set_list_item (ptr, int, NUM_MAP_X_SECTORS);

									quick_set_list_item (ptr, int, NUM_MAP_Z_SECTORS);

									quick_set_list_item (ptr, int, SECTOR_SIDE_LENGTH);

									size += sizeof (int) * 3;

									// data path

									strcpy (ptr, current_session->data_path);

									ptr += strlen (current_session->data_path) + 1;

									size += strlen (current_session->data_path) + 1;

									// population_placement filename

									if (population_placement_filename)
									{

										strcpy (ptr, population_placement_filename);

										ptr += strlen (population_placement_filename) + 1;

										size += strlen (population_placement_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//

									// side_data filename

									if (side_data_filename)
									{

										strcpy (ptr, side_data_filename);

										ptr += strlen (side_data_filename) + 1;

										size += strlen (side_data_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									// campaign_population filename

									if (campaign_population_filename)
									{

										strcpy (ptr, campaign_population_filename);

										ptr += strlen (campaign_population_filename) + 1;

										size += strlen (campaign_population_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//
									// planner position and zoom
									//

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_x);

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_z);

//									size += sizeof (float) * 2;

//									quick_set_list_item (ptr, int, planner_map_data.map_zoom);

//									size += sizeof (int);

									//
									// Pilots
									//

									player_count = get_number_of_connected_players ();

									quick_set_list_item (ptr, int, player_count);

									size += sizeof (int);

									//
									//
									//

									#if DEBUG_MODULE

									debug_log ("COMM_MAN: sending data path %s, population placement %s, side data %s, campaign_pop file %s",
													current_session->data_path, population_placement_filename, side_data_filename, campaign_population_filename);

									#endif

									new_connection->connection_receive_buffer_size -= size;

									if (!pack_session (ptr, &new_connection->connection_receive_buffer_size, PACK_MODE_BROWSE_SESSION))
									{

										break;
									}

									new_connection->connection_receive_buffer_size *= 2;

									#if DEBUG_MODULE

									debug_log ("COMMS MAN: Browse: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

									#endif

									free_mem (new_connection->connection_receive_buffer);

									new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);
								}

								//
								//
								//

								send_packet (received_id, PACKET_TYPE_SESSION_INFO, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size + size, SEND_TYPE_PERSONAL);

								/*
								{

									FILE
										*test_ptr;

									test_ptr = fopen ("out.txt", "wb");

									fwrite (new_connection->connection_receive_buffer, 1, new_connection->connection_receive_buffer_size + size, test_ptr);

									fclose (test_ptr);
								}
								*/
							}
							else
							{

								debug_log ("COMM_MAN: not resending query data");
							}
						}

						break;
					}

					case PACKET_TYPE_CONNECTION_VALIDATION:
					{

						debug_log ("COMM_MAN: received CONNECTION_VALIDATION, sending RESPONSE");

						send_packet (received_id, PACKET_TYPE_CONNECTION_RESPONSE, NULL, 0, SEND_TYPE_PERSONAL);

						break;
					}

					case PACKET_TYPE_CONNECTION_RESPONSE:
					{

						connection_list_type
							*connection;

						connection = get_connection_list_item (received_id);

						connection->validation_count = 0;

						debug_log ("COMM_MAN: received CONNECTION_RESPONSE, connection still alive");

						break;
					}

					case PACKET_TYPE_SESSION_INFO:
					{

						entity
							*force,
							*pilot;

						int
							client_version_number,
							server_version_number;

						int
							size,
							x_size,
							z_size,
							sector_size,
							player_count,
							loop;

						char
							*ptr,
							warzone_ffp_filename [256],
							temp_campaign_population_filename [256],
							temp_population_placement_filename [256],
							temp_side_data_filename [256],
							buffer [128];

						session_data = FALSE;

						reinitialise_entity_system ();

						ptr = received_data;

						size = 0;

						set_ui_object_redraw (gunships_screen, TRUE);

						ui_force_update ();

						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
						//
						// Check both client and server are running same campaign data
						//
						client_version_number = get_global_version_number ();

						server_version_number = get_list_item (ptr, int);

						size += sizeof (int);

						if (client_version_number != server_version_number)
						{

							debug_fatal ("COMM_MAN: Incorrect version. Server Version No. %d, Client Version No. %d", server_version_number, client_version_number);
						}
						//
						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

						// map details

						x_size = get_list_item (ptr, int);

						z_size = get_list_item (ptr, int);

						sector_size = get_list_item (ptr, int);

						size += (sizeof (int) * 3);

						set_entity_world_map_size (x_size, z_size, sector_size);

						// data path

						strncpy (current_session->data_path, ptr, sizeof (current_session->data_path));

						ptr += strlen (current_session->data_path) + 1;

						size += strlen (current_session->data_path) + 1;

						// population_placement_filename

						strncpy (temp_population_placement_filename, ptr, sizeof (temp_population_placement_filename));

						ptr += strlen (temp_population_placement_filename) + 1;

						size += strlen (temp_population_placement_filename) + 1;

						if (population_placement_filename)
						{

							free_mem (population_placement_filename);
						}

						if (strlen (temp_population_placement_filename) > 0)
						{

							population_placement_filename = (char *) malloc_heap_mem (strlen (temp_population_placement_filename) + 1);

							sprintf (population_placement_filename, "%s", temp_population_placement_filename);
						}
						else
						{

							population_placement_filename = NULL;
						}

						// side_data filename

						strncpy (temp_side_data_filename, ptr, sizeof (temp_side_data_filename));

						ptr += strlen (temp_side_data_filename) + 1;

						size += strlen (temp_side_data_filename) + 1;

						if (side_data_filename)
						{

							free_mem (side_data_filename);
						}

						if (strlen (temp_side_data_filename) > 0)
						{

							side_data_filename = (char *) malloc_heap_mem (strlen (temp_side_data_filename) + 1);

							sprintf (side_data_filename, "%s", temp_side_data_filename);
						}
						else
						{

							side_data_filename = NULL;
						}

						// campaign_population_filename

						strncpy (temp_campaign_population_filename, ptr, sizeof (temp_campaign_population_filename));

						ptr += strlen (temp_campaign_population_filename) + 1;

						size += strlen (temp_campaign_population_filename) + 1;

						if (campaign_population_filename)
						{

							free_mem (campaign_population_filename);
						}

						if (strlen (temp_campaign_population_filename) > 0)
						{

							campaign_population_filename = (char *) malloc_heap_mem (strlen (temp_campaign_population_filename) + 1);

							sprintf (campaign_population_filename, "%s", temp_campaign_population_filename);
						}
						else
						{

							campaign_population_filename = NULL;
						}

						//
						//
						//

						player_count = get_list_item (ptr, int);

						size += sizeof (int);

						//
						//
						//

						received_size -= size;

						#if DEBUG_MODULE

						debug_log ("COMM_MAN: data path %s population placement filename %s, side data filename %s", current_session->data_path, population_placement_filename, side_data_filename);

						debug_log ("COMM_MAN: campaign data path = %s", current_session->data_path);

						#endif

						//
						// check we have the correct warzone locally
						//

						sprintf (warzone_ffp_filename, "%s\\terrain\\terrain.ffp", current_session->data_path);

						if (!file_exist (warzone_ffp_filename))
						{

							add_to_pop_up_list_with_word_wrap (get_trans ("UNRECOGNISED_WARZONE"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);
							//add_to_pop_up_list (get_trans ("Server using unrecognised warzone"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

							break;
						}

						//
						//
						//

						create_local_only_entities (PACK_MODE_BROWSE_SESSION);

						if (unpack_session (ptr, received_size, PACK_MODE_BROWSE_SESSION))
						{

							debug_fatal ("COMMS MAN: browse: received size overflow");
						}

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received SESSION INFO from %s (dpid %d) (setting server id)",
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: RECEIVED SESSION INFO from %d", received_id);
						}

						debug_log ("COMMS MAN: session info: time of day = %f",
										get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_TIME_OF_DAY));

						debug_log ("COMMS MAN: map dimensions %d, %d, sector size %d", x_size, z_size, sector_size);

						#endif

						set_ui_object_drawable (session_screen_next_button, TRUE);

						//
						// Display game info
						//

						ui_object_destroy_list_items (session_info_list);

						if (get_local_entity_int_value (get_session_entity (), INT_TYPE_CAMPAIGN_REQUIRES_APACHE_HAVOC))
						{

							// campaign requires apache havoc to be installed
							// check it is...

							if (!get_global_apache_havoc_installed ())
							{

								add_to_pop_up_list_with_word_wrap (get_trans ("REQUIRES_APACHE_HAVOC"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

								set_ui_object_drawable (session_screen_next_button, FALSE);

								break;
							}
						}

						loop = 3;

						sprintf (buffer, "%s : %d", get_trans ("Players"), player_count);

						add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							pilot = get_local_entity_first_child (force, LIST_TYPE_PILOT);

							while (pilot)
							{
								{
									rgb_colour
										col;

									sprintf (buffer, "%2d  ", loop - 2);

									strncat (buffer, get_local_entity_string (pilot, STRING_TYPE_PILOTS_NAME), 64);

									switch (get_local_entity_int_value (pilot, INT_TYPE_SIDE))
									{
										case ENTITY_SIDE_BLUE_FORCE:
										{
											col.r = 120;
											col.g = 158;
											col.b = 255;
											col.a = 255;

											break;
										}
										case ENTITY_SIDE_RED_FORCE:
										{
											col.r = 255;
											col.g = 120;
											col.b = 80;
											col.a = 255;

											break;
										}
										default:
										{
									      col = ui_colour_white;

											break;
										}
									}

									add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, col);

									loop ++;
								}

								pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
							}

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

						set_server_id (received_id);

						//
						// destroy all entities created by browse info
						//

						reinitialise_entity_system ();

						break;
					}

					case PACKET_TYPE_CLIENT_PILOT_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_pilot_request_data
							pilot_data;

						entity
							*new_pilot;

						int
							index;

						ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: RECEIVED PILOT REQUEST from %d", received_id);

//						#endif

						//
						// unpack name
						//

						memcpy (&pilot_data, (client_pilot_request_data *) received_data, sizeof (client_pilot_request_data));

						new_pilot = create_new_pilot_entity
										(
											pilot_data.name,
											pilot_data.side,
											pilot_data.rank,
											pilot_data.sub_type,
											pilot_data.unique_id,
											pilot_data.difficulty
										);

						ASSERT (new_pilot);

						index = get_local_entity_safe_index (new_pilot);

						new_connection = get_connection_list_item (received_id);

						transmit_entity_comms_message (ENTITY_COMMS_PILOT_REQUEST_ACCEPTED, NULL, received_id, index);

						new_connection->pilot_entity = new_pilot;

						break;
					}

					case PACKET_TYPE_CLIENT_GUNSHIP_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_gunship_request_data
							pilot_data;

						int
							index_number,
							buffer [2];

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

//							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %d", received_id);
							}

//							#endif

							memcpy (&pilot_data, (client_gunship_request_data *) received_data, sizeof (client_gunship_request_data));

							index_number = pilot_data.gunship_index;

							ASSERT (index_number != ENTITY_INDEX_DONT_CARE);

							member = get_local_entity_safe_ptr (index_number);

							if (!member)
							{
//								#if DEBUG_MODULE

								if (this_connection->pilot_entity)
								{

									debug_log ("COMMS MAN: REFUSING GUNSHIP FOR PLAYER %s (dpid %d) for helicopter %d",
													get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
													received_id, pilot_data.gunship_index);
								}
								else
								{

									debug_log ("COMMS MAN: Refusing gunship for player %d to helicopter %d", received_id, pilot_data.gunship_index);
								}

//								#endif

								send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_REFUSED, NULL, 0, SEND_TYPE_PERSONAL);

								break;
							}

							new_connection = get_connection_list_item (received_id);

							//
							// send acceptance
							//

							buffer [0] = index_number;

//							#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending gunship request accepted for gunship %d pilot id %d", index_number, received_id);

//							#endif

							send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED, (void *) &buffer, 4, SEND_TYPE_PERSONAL);

							new_connection->gunship_number = pilot_data.gunship_index;

							new_connection->gunship_entity = member;
						}

						break;
					}

					case PACKET_TYPE_CLIENT_CAMPAIGN_DATA_REQUEST:
					{

						connection_list_type
							*new_connection;

						int
							index_number;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED JOIN REQUEST by %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: received JOIN REQUEST by %d", received_id);
							}

							#endif

							//
							// flush group send buffer
							//

							send_comms_data ();

							//
							// pack mission data into packet
							//

							new_connection = get_connection_list_item (received_id);

							//
							// Store entity data
							//

							while (pack_session (new_connection->connection_receive_buffer, &new_connection->connection_receive_buffer_size, PACK_MODE_CLIENT_SESSION))
							{

								new_connection->connection_receive_buffer_size *= 2;

								#if DEBUG_MODULE

								debug_log ("COMMS MAN: Mission data: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

								#endif

								free_mem (new_connection->connection_receive_buffer);

								new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);

								memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);
							}

							// add frame id
							index_number = get_group_frame_id ();
							memcpy (&new_connection->connection_receive_buffer [new_connection->connection_receive_buffer_size], (void *) &index_number, sizeof (int));
							new_connection->connection_receive_buffer_size += sizeof (int);

							send_packet (received_id, PACKET_TYPE_MISSION_DATA, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size, SEND_TYPE_PERSONAL);

							memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);

							//
							// send group frame id
							//

							SDL_Delay (100);

							index_number = get_group_frame_id ();

							//send_packet (received_id, PACKET_TYPE_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

							zero_average_pack_size ();
						}

						break;
					}

					case PACKET_TYPE_CLIENT_FRAME_ID:
					{

						int
							loop1,
							loop2,
							index_number;

						stub_packet_type
							*stub_packet;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						new_connection = get_connection_list_item (received_id);

						//#if DEBUG_MODULE

						if (new_connection)
						{

							debug_log ("COMMS MAN: received CLIENT FRAME ID (%d) by %d %s", index_number, received_id, direct_play_get_player_name (received_id));
						}

						//#endif

						//
						// send all packets between when the client started to join and when it actually joined.
						//

						for (loop1 = index_number; loop1 < get_group_frame_id () - 1; loop1 ++)
						{

							//#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, 0);

							//#endif

							stub_packet = resend_packet (received_id, loop1, 1, SEND_TYPE_GROUP);

							ASSERT (stub_packet);

							for (loop2 = 2; loop2 <= stub_packet->packet->number_of_packets; loop2 ++)
							{

								//#if DEBUG_MODULE

								debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, loop2);

								//#endif

								stub_packet = resend_packet (received_id, loop1, loop2, SEND_TYPE_GROUP);
							}
						}

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_REFUSED:
					{

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: Gunship refused");

//						#endif

						set_server_response (SERVER_RESPONSE_REFUSE);

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED:
					{

						entity
							*gunship;

						int
							index_number;

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received GUNSHIP ACCEPTED by %d", received_id);

//						#endif

						//
						// set gunship
						//

						index_number = get_list_item (received_data, int);

						ASSERT (get_pilot_entity ());

						gunship = get_local_entity_safe_ptr (index_number);

						debug_filtered_log ("COMM_MAN: setting gunship");

						planner_event = FALSE;

						if (get_event_stack_head_function() == ingame_screen_set_events)
						{

							pop_event (ingame_screen_set_events);

							planner_event = TRUE;
						}

						assign_entity_to_user (gunship);

						if (planner_event)
						{

							push_event (ingame_screen_set_events, "ingame screen events");
						}

						debug_filtered_log ("COMM_MAN: gunship set");

						////////////////////////////////////////////////////////////////////////

						break;
					}

					case PACKET_TYPE_PILOT_REQUEST_ACCEPTED:
					{

						int
							index_number;

						ASSERT (get_comms_model () == COMMS_MODEL_CLIENT);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received PILOT ACCEPTED by %d", received_id);

//						#endif

						index_number = get_list_item (received_data, int);

						set_pilot_entity (get_local_entity_safe_ptr (index_number));

						break;
					}

					case PACKET_TYPE_MISSION_DATA:
					{

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received MISSION DATA by %d", received_id);

						#endif

						set_mouse_graphic_off ();

						//
						// LOAD TERRAIN DATA
						//

						load_3d_terrain_game_data ();

						initialise_population_name_database ();

						load_route_data (); // might need to send what route filename to load...

						//
						// Initialise stuff
						//

						create_local_only_entities (PACK_MODE_CLIENT_SESSION);

						/////////////////////////////////////////////////////////////////
						if (strstr ((char*) stoupper (side_data_filename), "SID"))
						{

							read_sector_side_file (side_data_filename);
						}
						else if (strstr ((char*) stoupper (side_data_filename), "DAT"))
						{

							load_ai_sector_data (side_data_filename);
						}
						/////////////////////////////////////////////////////////////////

						deinitialise_formation_database ();

						initialise_formation_database ();

						deinitialise_formation_component_database ();

						initialise_formation_component_database ();

						if (unpack_session (received_data, received_size - 4, PACK_MODE_CLIENT_SESSION))
						{

							debug_fatal ("COMMS MAN: received size overflow");
						}
/*
						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							create_frontline (force);

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

*/
						{
							int
								index_number;

							connection_list_type
								*new_connection;

							received_data += received_size - 4;
							index_number = get_list_item (received_data, int);

							new_connection = get_connection_list_item (received_id);

							new_connection->receive_group_frame_id = index_number;

							send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);
						}

						session_data = TRUE;

						//direct_play_join_group ();

						set_gunship_waiting_for_connection ( FALSE );

						zero_average_pack_size ();

						set_mouse_graphic_on ();

						break;
					}

					case PACKET_TYPE_FRAME_ID:
					{

						int
							index_number;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received FRAME ID (%d) by %d", index_number, received_id);

						#endif

						new_connection = get_connection_list_item (received_id);

						new_connection->receive_group_frame_id = index_number;

						send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// In game packets
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_AI_DATA:
					{

						int
							//padding,
							data_size;

						#if DEBUG_MODULE >= 2

						debug_log ("COMMS MAN: received AI DATA by %d", received_id);

						#endif

						if (get_comms_model () == COMMS_MODEL_CLIENT)
						{

							ASSERT (session_data);
						}

						data_size = get_list_item (received_data, int);

						//debug
						//padding = get_list_item (received_data, int);
						//end

						open_unpack_buffer (received_data, received_size);

						process_received_entity_comms_messages ();

						ASSERT (!get_unpack_buffer_overflow ());

						close_unpack_buffer ();

						//debug
						//padding = get_list_item (received_data, int);
						//end

						memset (received_data, 0, this_connection->connection_receive_buffer_size);

						break;
					}

					case PACKET_TYPE_END_GAME:
					{

						debug_log ("COMMS MAN: received END GAME from %d", received_id);

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{
							if (this_connection->gunship_entity)
							{

								set_client_server_entity_int_value (this_connection->gunship_entity, INT_TYPE_PLAYER, ENTITY_PLAYER_AI);
							}

							if (this_connection->pilot_entity)
							{

								debug_log ("	from %s ", get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME));
							}

							unregister_connection (received_id);
						}
						else
						{

							if (received_id == get_server_id ())
							{

								//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_STALEMATE);

								start_game_exit (GAME_EXIT_KICKOUT, FALSE);
							}
						}

						receive_flag = FALSE;

						break;
					}

					case PACKET_TYPE_SERVER_REJECTED:
					{

						debug_log ("COMMS MAN: received SERVER REJECTED (server id %d)", received_id);

						//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_SERVER_REJECTED);

						start_game_exit (GAME_EXIT_KICKOUT, FALSE);

						break;
					}

					default:
					{

						debug_fatal ("ERROR: Data Exchange, unknown packet type %d", type);

						break;
					}
				}
			}

			send_type --;
		}
	}
}
void mm_one_queue_simulator_for_batch_means(long nr_customer, double average_interarrival_time, double average_service_time, long *next_seed_interarrival, long *next_seed_service, long nr_batch, long batch_size, long initial_bias, double correlation_bound, double half_alpha, double eps_relative, struct batch_means_output *result) {
  struct event *event_list = NULL;
  struct queue system_queue;
  enum server_state server_state = IDLE;
  double system_clock = 0.0;
  struct event *event;

  enum event_type event_type;
  int customer_number = 0;
  double clock_time;
  double arrival_time;
  double interarrival_time;
  double departure_time;
  double service_time;

  struct customer *customer;

  double lamda_interarrival_rate = 1.0 / average_interarrival_time; /* interarrival rate: lamda = 1 / average_time */
  double mu_service_rate = 1.0 / average_service_time; /* service_rate: mu = 1 / arverage_service_time */

  double total_customer_in_system_time = 0.0; 

  /* for batch means */
  double *batch_mean;
  batch_mean = malloc(nr_batch * sizeof(double));
  memset(batch_mean, 0, nr_batch * sizeof(double));
  double *batch_sum;
  batch_sum = malloc(nr_batch * sizeof(double));
  memset(batch_sum, 0, nr_batch * sizeof(double));

  double lag_1_corr;
  double t; /* student t distribution */
  double dev;
  double avg;
  double ci_hw;
  double ci_hb;
  long batch_index;
  int i;

  /* initial system */
  init_queue(&system_queue);

  /* step 0: initial first event and add into event list */
#ifdef DEBUG
  printf("Info: simulation starts.\n");
#endif
  if (customer_number < nr_customer) {
    event_type = ARRIVAL;
    clock_time = 1.0;
    customer = init_customer(customer_number);
    customer->arrival_time = clock_time;
    customer_number++;
    add_event(&event_list, event_type, clock_time, (void *) customer);
  }
  /* step 1: pop event from event list */
  event = get_event(event_list);
  while (event) {
    /* step 2: addvance clock */
    system_clock = event->clock_time;
    pop_event(&event_list);
    /* get customer */
    customer = (struct customer *) event->content;
    event->content = NULL;
    switch (event->event_type) {
      case ARRIVAL:
#ifdef DEBUG
        /* print info */
        printf("Info: [time: %12f] [customer: %8d] event: ARRIVAL\n", system_clock, customer->no);
#endif
        /* generate service time */
        service_time = exponential_random_generator(mu_service_rate, next_seed_service);
        add_service_time_to_customer(customer, service_time);
        /* step 3: update state */
        if (server_state == IDLE) {
          server_state = BUSY;
          /* set service time and departure time */
          service_time = customer->service_time;
          departure_time = system_clock + service_time;
          event_type = DEPARTURE;
          customer->departure_time = departure_time;
          add_event(&event_list, event_type, departure_time, (void *) customer);
        } else if (server_state == BUSY) {
          /* add customer into queue */
          enqueue(&system_queue, (void *) customer);
        }
        /* step 4: generate future event into event list */
        /* if customer_number < nr_customer, generate next arrival event */
        if (customer_number < nr_customer) {
          interarrival_time = exponential_random_generator(lamda_interarrival_rate, next_seed_interarrival);
          arrival_time = system_clock + interarrival_time;
          event_type = ARRIVAL;
          customer = init_customer(customer_number);
          customer->arrival_time = arrival_time;
          customer_number++;
          add_event(&event_list, event_type, arrival_time, (void *) customer);
        }
     
        break;
      case DEPARTURE:
#ifdef DEBUG
        /* print info */
        printf("Info: [time: %12f] --------------------------------------- [customer: %8d] event: DEPARTURE\n", system_clock, customer->no);
#endif
        if (customer->no >= (initial_bias + nr_batch * batch_size)) {
          for (i = 0; i < nr_batch; i++) {
            batch_mean[i] = batch_sum[i] / batch_size;
          }
          /* check correlation */
          lag_1_corr = sample_lag1_corr_sequence(batch_mean, nr_batch);
          if (fabs(lag_1_corr) < correlation_bound) {
            /* check confidence interval */
            t = gsl_cdf_tdist_Pinv(1.0-half_alpha, nr_batch - 1); 
            avg = avg_sequence(batch_mean, nr_batch);
            dev = dev_sequence(batch_mean, nr_batch);
            ci_hw = t * dev / sqrt((double) nr_batch);
            ci_hb = avg * eps_relative;
            if (ci_hw < ci_hb) {
              if (result) {
                result->avg = avg;
                result->ci_hw = ci_hw;
                result->lag_1 = lag_1_corr;
              }
              return;
            }
          }
          /* not satisfy constraint, double batch_size */
          batch_size *= 2;
          for (i = 0; i < nr_batch / 2; i++) {
            batch_sum[i] = batch_sum[i*2] + batch_sum[i*2+1];
          }
          for (i = nr_batch / 2; i < nr_batch; i++) {
            batch_sum[i] = 0.0;
          }
        }
        if (customer->no >= initial_bias) {
          batch_index = (customer->no - initial_bias) / batch_size;
          batch_sum[batch_index] += customer->departure_time - customer->arrival_time;
          total_customer_in_system_time += customer->departure_time - customer->arrival_time;
        }
        free(customer);
        customer = NULL;
        /* step 3: update state */
        if (system_queue.count > 0) {
          customer = (struct customer *) dequeue(&system_queue);
          /* set service time and departure time */
          service_time = get_service_time_from_customer(customer);
          departure_time = system_clock + service_time;
          event_type = DEPARTURE;
          customer->departure_time = departure_time;
          add_event(&event_list, event_type, departure_time, (void *) customer);
        } else if (system_queue.count == 0) {
          server_state = IDLE;
        }

        /* step 4: generate future event into event list */
        break;
      default:
        fprintf(stderr, "Error: unkown event type.\n");
        exit(EXIT_FAILURE);
    }
    free(event);
    event = NULL;

    /* get next event */
    event = get_event(event_list);
  }
#ifdef DEBUG
  printf("Info: event list is empty.\n");
  printf("Info: simulation ends.\n");
#endif
}
void mm_one_queue_simulator_with_initail_bias(long nr_customer, double average_interarrival_time, double average_service_time, long *next_seed_interarrival, long *next_seed_service, struct mm_one_simulation_result *result, long initial_bias) {
  struct event *event_list = NULL;
  struct queue system_queue;
  enum server_state server_state = IDLE;
  double system_clock = 0.0;
  struct event *event;

  enum event_type event_type;
  int customer_number = 0;
  double clock_time;
  double arrival_time;
  double interarrival_time;
  double departure_time;
  double service_time;

  struct customer *customer;

  double lamda_interarrival_rate = 1.0 / average_interarrival_time; /* interarrival rate: lamda = 1 / average_time */
  double mu_service_rate = 1.0 / average_service_time; /* service_rate: mu = 1 / arverage_service_time */

  double total_customer_in_system_time = 0.0; 
  /* initial system */
  init_queue(&system_queue);

  /* step 0: initial first event and add into event list */
#ifdef DEBUG
  printf("Info: simulation starts.\n");
#endif
  if (customer_number < nr_customer) {
    event_type = ARRIVAL;
    clock_time = 1.0;
    customer = init_customer(customer_number);
    customer->arrival_time = clock_time;
    customer_number++;
    add_event(&event_list, event_type, clock_time, (void *) customer);
  }
  /* step 1: pop event from event list */
  event = get_event(event_list);
  while (event) {
    /* step 2: addvance clock */
    system_clock = event->clock_time;
    pop_event(&event_list);
    /* get customer */
    customer = (struct customer *) event->content;
    event->content = NULL;
    switch (event->event_type) {
      case ARRIVAL:
#ifdef DEBUG
        /* print info */
        printf("Info: [time: %12f] [customer: %8d] event: ARRIVAL\n", system_clock, customer->no);
#endif
        /* generate service time */
        service_time = exponential_random_generator(mu_service_rate, next_seed_service);
        add_service_time_to_customer(customer, service_time);
        /* step 3: update state */
        if (server_state == IDLE) {
          server_state = BUSY;
          /* set service time and departure time */
          service_time = customer->service_time;
          departure_time = system_clock + service_time;
          event_type = DEPARTURE;
          customer->departure_time = departure_time;
          add_event(&event_list, event_type, departure_time, (void *) customer);
        } else if (server_state == BUSY) {
          /* add customer into queue */
          enqueue(&system_queue, (void *) customer);
        }
        /* step 4: generate future event into event list */
        /* if customer_number < nr_customer, generate next arrival event */
        if (customer_number < nr_customer) {
          interarrival_time = exponential_random_generator(lamda_interarrival_rate, next_seed_interarrival);
          arrival_time = system_clock + interarrival_time;
          event_type = ARRIVAL;
          customer = init_customer(customer_number);
          customer->arrival_time = arrival_time;
          customer_number++;
          add_event(&event_list, event_type, arrival_time, (void *) customer);
        }
     
        break;
      case DEPARTURE:
#ifdef DEBUG
        /* print info */
        printf("Info: [time: %12f] --------------------------------------- [customer: %8d] event: DEPARTURE\n", system_clock, customer->no);
#endif
        /* store each customer's system time in result */
        if (result && result->customer_in_system_time) {
          result->customer_in_system_time[customer->no] = customer->departure_time - customer->arrival_time;
        }

        /* initial bias */
        if (customer->no >= initial_bias) {
          total_customer_in_system_time += customer->departure_time - customer->arrival_time;
        }

        free(customer);
        customer = NULL;
        /* step 3: update state */
        if (system_queue.count > 0) {
          customer = (struct customer *) dequeue(&system_queue);
          /* set service time and departure time */
          service_time = get_service_time_from_customer(customer);
          departure_time = system_clock + service_time;
          event_type = DEPARTURE;
          customer->departure_time = departure_time;
          add_event(&event_list, event_type, departure_time, (void *) customer);
        } else if (system_queue.count == 0) {
          server_state = IDLE;
        }

        /* step 4: generate future event into event list */
        break;
      default:
        fprintf(stderr, "Error: unkown event type.\n");
        exit(EXIT_FAILURE);
    }
    free(event);
    event = NULL;

    /* get next event */
    event = get_event(event_list);
  }
  if (result) {
    result->average_customer_in_system_time = total_customer_in_system_time / (nr_customer - initial_bias);
#ifdef DEBUG
    printf("Info: average time of a customer in system: %12f\n", result->average_customer_in_system_time);
#endif
  }
#ifdef DEBUG
  printf("Info: event list is empty.\n");
  printf("Info: simulation ends.\n");
#endif
}
//-----------------------------------------------------------------------------
void InputManager::frame(uint64_t current_frame)
{
	OsEvent event;

	m_keyboard.m_current_frame = current_frame;
	while (1)
	{
		event = pop_event();

		switch (event.type)
		{
			case OSET_NONE:
			{
				return;
			}
			case OSET_BUTTON_PRESS:
			case OSET_BUTTON_RELEASE:
			{
				MouseEvent mouse_event;
				mouse_event.x = event.data_a.int_value;
				mouse_event.y = event.data_b.int_value;
				mouse_event.button = event.data_c.int_value == 0 ? MB_LEFT : event.data_c.int_value == 1 ? MB_MIDDLE : MB_RIGHT;
				mouse_event.wheel = 0.0f;

				if (event.type == OSET_BUTTON_PRESS)
				{
					m_mouse.m_buttons[mouse_event.button] = true;
					m_event_dispatcher.button_pressed(mouse_event);
				}
				else
				{
					m_mouse.m_buttons[mouse_event.button] = false;
					m_event_dispatcher.button_released(mouse_event);
				}

				break;
			}
			case OSET_KEY_PRESS:
			case OSET_KEY_RELEASE:
			{
				KeyboardEvent keyboard_event;
				keyboard_event.key = event.data_a.int_value;
				keyboard_event.modifier = (uint8_t)event.data_b.int_value;

				m_keyboard.m_modifier = keyboard_event.modifier;

				if (event.type == OSET_KEY_PRESS)
				{
					m_keyboard.m_states[keyboard_event.key] = true;
					m_keyboard.m_keys[keyboard_event.key] = current_frame;
					m_event_dispatcher.key_pressed(keyboard_event);
				}
				else
				{
					m_keyboard.m_states[keyboard_event.key] = false;
					m_keyboard.m_keys[keyboard_event.key] = current_frame;
					m_event_dispatcher.key_released(keyboard_event);
				}

				break;
			}
			case OSET_TOUCH_DOWN:
			case OSET_TOUCH_UP:
			{
				TouchEvent touch_event;
				touch_event.pointer_id = event.data_a.int_value;
				touch_event.x = event.data_b.int_value;
				touch_event.y = event.data_c.int_value;

				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;

				// FIXME
				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;

				if (event.type == OSET_TOUCH_DOWN)
				{
					m_touch.m_pointers[touch_event.pointer_id].up = false;
					m_event_dispatcher.touch_down(touch_event);
				}
				else
				{
					m_touch.m_pointers[touch_event.pointer_id].up = true;
					m_event_dispatcher.touch_up(touch_event);
				}

				break;
			}
			case OSET_TOUCH_MOVE:
			{
				TouchEvent touch_event;
				touch_event.pointer_id = event.data_a.int_value;
				touch_event.x = event.data_b.int_value;
				touch_event.y = event.data_c.int_value;

				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;

				// FIXME
				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;

				m_event_dispatcher.touch_move(touch_event);

				break;
			}
			case OSET_ACCELEROMETER:
			{
				AccelerometerEvent sensor_event;
				sensor_event.x = event.data_a.float_value;
				sensor_event.y = event.data_b.float_value;
				sensor_event.z = event.data_c.float_value;

				m_accelerometer.m_orientation.x = sensor_event.x;
				m_accelerometer.m_orientation.y = sensor_event.y;
				m_accelerometer.m_orientation.z = sensor_event.z;

				m_event_dispatcher.accelerometer_changed(sensor_event);
				break;
			}
			default:
			{
				break;
			}
		}
	}
}