Don't send input events when nothing has changed
[tennix.git] / network.h
bloba31ed27e5f32c8805b0adda5403edd1712027ef7
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007, 2008, 2009 Thomas Perl <thp@thpinfo.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
22 **/
24 #ifndef __NETWORK_H
25 #define __NETWORK_H
27 #include "game.h"
28 #include "input.h"
30 #include <SDL/SDL_net.h>
32 /* Vanity ports "STNX" and "MTNX" */
33 #define TENNIXNET_PORT_SLAVE 7869
34 #define TENNIXNET_PORT_MASTER 6869
36 typedef struct {
37 Uint32 x;
38 Uint32 y;
39 Uint32 z;
40 Uint32 move_x;
41 Uint32 move_y;
42 Uint32 move_z;
43 bool ground_hit;
44 char last_hit_by;
45 bool inhibit_gravity;
46 } NetworkBall;
48 typedef struct {
49 Uint32 x;
50 Uint32 y;
51 Uint32 power;
52 bool use_power;
53 unsigned char score;
54 unsigned char desire;
55 char game;
56 unsigned char sets[SETS_TO_WIN*2];
57 Uint32 accelerate;
58 } NetworkPlayer;
60 typedef struct {
61 NetworkBall ball;
62 NetworkPlayer players[MAXPLAYERS];
63 unsigned char serving_player;
64 referee_t referee;
65 unsigned char current_set;
66 winner_t winner;
67 soundevent_t sound_events;
68 scoreevent_t score_event;
69 unsigned char score_time;
70 eventcounter_t ec_game;
71 eventcounter_t ec_sets;
72 statusmessage_t status_message;
73 } NetworkGameState;
75 void
76 init_network();
78 void
79 uninit_network();
81 TennixNet*
82 network_connect(const char* host, bool master);
84 void
85 network_disconnect(TennixNet* connection);
87 void
88 network_send_input(TennixNet* connection, NetworkInputData* src);
90 void
91 network_send_state(TennixNet* connection, GameState* src);
93 void
94 network_receive(TennixNet* connection);
96 void
97 network_get_input(TennixNet* connection, NetworkInputData* dest);
99 void
100 network_get_gamestate(TennixNet* connection, GameState* dest);
102 void
103 net_serialize_ball(const Ball* src, NetworkBall* dest);
105 void
106 net_unserialize_ball(const NetworkBall* src, Ball* dest);
108 void
109 net_serialize_player(const Player* src, NetworkPlayer* dest);
111 void
112 net_unserialize_player(const NetworkPlayer* src, Player* dest);
114 void
115 net_serialize_gamestate(const GameState* src, NetworkGameState* dest);
117 void
118 net_unserialize_gamestate(const NetworkGameState* src, GameState* dest);
120 #endif