示例#1
0
/* server functions */
JOYNET_SERVER * joynet_create_server(void)
{
	JOYNET_SERVER * sp;
	int i;
	
	sp = malloc(sizeof(JOYNET_SERVER));
	if(!sp)
	{
		return NULL;
	}
	sp->serial_data = joynet_create_serial_data();
	if(!sp->serial_data)
	{
		return NULL;
	}
	strcpy(sp->id, "");
	sp->client = NULL;
	sp->global_callback = NULL;
	sp->internal_callback = NULL;
	for(i = 0; i < JOYNET_MAX_CHANNELS; i++)
	{
		sp->channel_callback[i] = NULL;
	}
	return sp;
}
示例#2
0
/* client functions */
JOYNET_CLIENT * joynet_create_client(void)
{
	JOYNET_CLIENT * cp;
	int i;
	
	cp = malloc(sizeof(JOYNET_CLIENT));
	if(!cp)
	{
		return NULL;
	}
	cp->serial_data = joynet_create_serial_data();
	if(!cp->serial_data)
	{
		return NULL;
	}
	cp->host = NULL;
	cp->peer = NULL;
	strcpy(cp->screen_name, "");
	cp->user = -1; // -1 means not connected
	cp->group = 0;
	cp->master = 0;
	cp->playing = 0;
	cp->spectating = 0;
	cp->global_callback = NULL;
	for(i = 0; i < JOYNET_MAX_CHANNELS; i++)
	{
		cp->channel_callback[i] = NULL;
	}
	return cp;
}
示例#3
0
文件: game.c 项目: showkoba/JoyNet
/* don't pass a client if you want local play */
JOYNET_GAME * joynet_create_game(char * name, int type, int max_players, int max_controllers, int(*callback)(JOYNET_MESSAGE * mp))
{
	JOYNET_GAME * gp;
	int i;
	
	gp = malloc(sizeof(JOYNET_GAME));
	if(!gp)
	{
		return NULL;
	}
	memset(gp, 0, sizeof(JOYNET_GAME));
	gp->type = type;
	strcpy(gp->name, name);
	gp->state = JOYNET_GAME_STATE_OFF;
	gp->callback = callback;
	for(i = 0; i < max_players; i++)
	{
		gp->player[i] = malloc(sizeof(JOYNET_PLAYER));
		if(!gp->player[i])
		{
			return NULL;
		}
		memset(gp->player[i], 0, sizeof(JOYNET_PLAYER));
		gp->player[i]->controller = NULL; // allocated at connect
		gp->player[i]->options = 0;
		strcpy(gp->player[i]->name, "");
		memset(gp->player[i]->selected_content, 0, sizeof(unsigned long) * JOYNET_GAME_MAX_CONTENT_LISTS);
		memset(gp->player[i]->selected_content_index, 0, sizeof(int) * JOYNET_GAME_MAX_CONTENT_LISTS);
	}
	gp->players = max_players;
	for(i = 0; i < max_controllers; i++)
	{
		gp->controller[i] = malloc(sizeof(JOYNET_CONTROLLER));
		if(!gp->controller[i])
		{
			return NULL;
		}
		gp->controller[i]->port = -1; // not connected yet
	}
	gp->serial_data = joynet_create_serial_data();
	if(!gp->serial_data)
	{
		return NULL;
	}
	gp->controllers = max_controllers;
	gp->options = 0;
	gp->client = NULL;
	gp->input_buffer = NULL;
	gp->player_count = 0;
	return gp;
}