RetroArch/netplay.h

150 lines
4.9 KiB
C
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
2011-02-13 15:40:24 +00:00
*
2012-04-21 21:13:50 +00:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2011-02-13 15:40:24 +00:00
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2012-04-21 21:13:50 +00:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2011-02-13 15:40:24 +00:00
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 21:31:57 +00:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2011-02-13 15:40:24 +00:00
* If not, see <http://www.gnu.org/licenses/>.
*/
2012-04-21 21:25:32 +00:00
#ifndef __RARCH_NETPLAY_H
#define __RARCH_NETPLAY_H
2011-02-13 15:40:24 +00:00
#include <stdint.h>
2012-04-05 09:47:43 +00:00
#include <stddef.h>
#include <boolean.h>
2012-04-05 09:47:43 +00:00
#include "libretro.h"
2015-01-13 01:29:08 +00:00
#include "libretro_version_1.h"
2011-02-13 15:40:24 +00:00
2015-01-09 17:34:00 +00:00
typedef struct netplay netplay_t;
/* TODO: most of this, actually */
/* /!\ WARNING: A command identifier cannot exceed 16 bytes in length. */
enum netplay_cmd
{
2015-11-17 23:18:04 +00:00
/* misc. commands */
NETPLAY_CMD_ACK = 0x0000, /**< Acknowlegement response */
NETPLAY_CMD_NAK = 0x0001, /**< Failed acknowlegement response */
NETPLAY_CMD_FLIP_PLAYERS = 0x0002, /**< Swap inputs between p1 and p2. */
NETPLAY_CMD_SPECTATE = 0x0003, /**< Toggle spectate/join mode */
NETPLAY_CMD_DISCONNECT = 0x0004, /**< Gracefully disconnects from host. */
NETPLAY_CMD_CFG = 0x0005, /**< Sends multiple config requests over, See
enum netplay_cmd_cfg. */
NETPLAY_CMD_CFG_ACK = 0x0006, /**< CMD_CFG streamlines sending multiple
configurations. This acknowledges
each one individually. */
2015-11-17 23:18:04 +00:00
/* loading and synchronization */
NETPLAY_CMD_LOAD_SAVESTATE = 0x0012, /** Send a savestate for the client to load */
NETPLAY_CMD_CHEATS = 0x0013, /** Sends over cheats enabled on client. */
2015-11-17 23:18:04 +00:00
/* controlling game playback */
NETPLAY_CMD_PAUSE = 0x0030, /**< Pauses the game, takes no args. */
2015-11-19 11:30:00 +00:00
NETPLAY_CMD_RESUME = 0x0031 /**< Resumes the game, takes no args. */
};
/* These are the configurations sent by NETPLAY_CMD_CFG. */
enum netplay_cmd_cfg
{
NETPLAY_CFG_NICK = 0x0001, /**< nickname */
NETPLAY_CFG_SWAP_INPUT = 0x0002, /**< input.netplay_client_swap_input */
NETPLAY_CFG_DELAY_FRAMES = 0x0004, /**< netplay.sync_frames */
2015-11-19 11:30:00 +00:00
NETPLAY_CFG_PLAYER_SLOT = 0x0008 /**< For more than 2 players. */
};
2011-02-13 15:40:24 +00:00
void input_poll_net(void);
2014-09-07 03:47:18 +00:00
int16_t input_state_net(unsigned port, unsigned device,
2014-10-20 17:29:49 +00:00
unsigned idx, unsigned id);
2014-09-07 03:47:18 +00:00
void video_frame_net(const void *data, unsigned width,
unsigned height, size_t pitch);
2012-04-05 09:47:43 +00:00
void audio_sample_net(int16_t left, int16_t right);
2014-09-07 03:47:18 +00:00
2012-04-07 09:55:37 +00:00
size_t audio_sample_batch_net(const int16_t *data, size_t frames);
2011-02-13 15:40:24 +00:00
2014-09-07 03:47:18 +00:00
int16_t input_state_spectate(unsigned port, unsigned device,
2014-10-20 17:29:49 +00:00
unsigned idx, unsigned id);
2014-09-07 03:47:18 +00:00
int16_t input_state_spectate_client(unsigned port, unsigned device,
2014-10-20 17:29:49 +00:00
unsigned idx, unsigned id);
2012-01-11 18:22:18 +00:00
2015-01-09 17:34:00 +00:00
/**
* netplay_new:
* @server : IP address of server.
* @port : Port of server.
* @frames : Amount of lag frames.
* @cb : Libretro callbacks.
* @spectate : If true, enable spectator mode.
* @nick : Nickname of user.
*
* Creates a new netplay handle. A NULL host means we're
* hosting (user 1).
*
* Returns: new netplay handle.
**/
2012-01-21 13:00:11 +00:00
netplay_t *netplay_new(const char *server,
uint16_t port, unsigned frames,
2012-04-05 09:47:43 +00:00
const struct retro_callbacks *cb, bool spectate,
2012-01-21 17:12:42 +00:00
const char *nick);
2014-09-07 03:47:18 +00:00
2015-01-09 17:34:00 +00:00
/**
* netplay_free:
* @netplay : pointer to netplay object
*
* Frees netplay handle.
**/
2011-02-13 15:40:24 +00:00
void netplay_free(netplay_t *handle);
2015-01-09 17:34:00 +00:00
/**
* netplay_flip_users:
* @netplay : pointer to netplay object
*
* On regular netplay, flip who controls user 1 and 2.
**/
2014-12-05 12:48:54 +00:00
void netplay_flip_users(netplay_t *handle);
2012-01-21 13:00:11 +00:00
2015-01-09 17:34:00 +00:00
/**
* netplay_pre_frame:
* @netplay : pointer to netplay object
*
* Pre-frame for Netplay.
* Call this before running retro_run().
**/
void netplay_pre_frame(netplay_t *handle);
2014-09-07 03:47:18 +00:00
2015-01-09 17:34:00 +00:00
/**
* netplay_post_frame:
* @netplay : pointer to netplay object
*
* Post-frame for Netplay.
* We check if we have new input and replay from recorded input.
* Call this after running retro_run().
**/
void netplay_post_frame(netplay_t *handle);
2015-04-11 11:29:40 +00:00
/**
* init_netplay:
*
* Initializes netplay.
*
* If netplay is already initialized, will return false (0).
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool init_netplay(void);
2015-04-11 11:31:33 +00:00
void deinit_netplay(void);
2015-11-17 23:19:22 +00:00
#endif