Esempio n. 1
0
/* if process is true, input will be sent (online play) */
void joynet_update_game(JOYNET_GAME * gp, int process)
{
	ENetPacket * pp;
	char data[1024];
	if(gp->client)
	{
		if(process)
		{
			if(joynet_encode_game_input(gp, data))
			{
				pp = joynet_create_packet(JOYNET_GAME_MESSAGE_INPUT, gp->serial_data);
				enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
			}
		}
	}
	else
	{
		if(joynet_encode_game_input(gp, data))
		{
			memcpy(&(gp->input_buffer->data[gp->input_buffer->write_pos]), data, gp->input_buffer->frame_size);
//			printf("data - %d - %d\n", data[0], data[1]);
			gp->input_buffer->write_pos += gp->input_buffer->frame_size;
			if(gp->input_buffer->write_pos >= gp->input_buffer->frame_size * gp->max_buffer_frames)
			{
				gp->input_buffer->write_pos = 0;
			}
			gp->input_buffer->frames++;
		}
	}
}
Esempio n. 2
0
/* if process is true, input will be sent (online play) */
void joynet_update_game(JOYNET_GAME * gp, int process)
{
	ENetPacket * pp;
	char data[1024];
	if(gp->client)
	{
		if(gp->player[gp->current_player]->local && process)
		{
			if(joynet_encode_game_input(gp, data))
			{
				pp = joynet_create_packet(JOYNET_GAME_MESSAGE_INPUT, gp->serial_data);
				enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
			}
		}
	}
	else
	{
		if(joynet_encode_game_input(gp, data))
		{
            joynet_write_input_buffer_frame(gp->input_buffer, data);
		}
		else
		{
			printf("failed to encode\n");
		}
	}
}