Add Mac OS X support for networking; better network code
[tennix.git] / network.h
blob298187c7989e4ca4e70e60b864e138265a15fc53
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 #define TENNIXNET_STATE_PORT 1448
33 #define TENNIXNET_INPUT_PORT 1449
35 typedef struct {
36 Uint32 x;
37 Uint32 y;
38 Uint32 z;
39 Uint32 move_x;
40 Uint32 move_y;
41 Uint32 move_z;
42 bool ground_hit;
43 char last_hit_by;
44 bool inhibit_gravity;
45 } NetworkBall;
47 typedef struct {
48 Uint32 x;
49 Uint32 y;
50 Uint32 power;
51 bool use_power;
52 unsigned char score;
53 unsigned char desire;
54 char game;
55 unsigned char sets[SETS_TO_WIN*2];
56 Uint32 accelerate;
57 } NetworkPlayer;
59 typedef struct {
60 NetworkBall ball;
61 NetworkPlayer players[MAXPLAYERS];
62 unsigned char serving_player;
63 referee_t referee;
64 unsigned char current_set;
65 winner_t winner;
66 soundevent_t sound_events;
67 scoreevent_t score_event;
68 unsigned char score_time;
69 eventcounter_t ec_game;
70 eventcounter_t ec_sets;
71 statusmessage_t status_message;
72 } NetworkGameState;
74 void
75 init_network();
77 void
78 uninit_network();
80 TennixNet*
81 network_connect(const char* host, Uint16 local_port, Uint16 remote_port);
83 void
84 network_disconnect(TennixNet* connection);
86 void
87 network_set_master(TennixNet* connection, bool master);
89 void
90 network_send_input(TennixNet* connection, NetworkInputData* src);
92 void
93 network_send_state(TennixNet* connection, GameState* src);
95 void
96 network_receive(TennixNet* connection);
98 void
99 network_get_input(TennixNet* connection, NetworkInputData* dest);
101 void
102 network_get_gamestate(TennixNet* connection, GameState* dest);
104 void
105 net_serialize_ball(const Ball* src, NetworkBall* dest);
107 void
108 net_unserialize_ball(const NetworkBall* src, Ball* dest);
110 void
111 net_serialize_player(const Player* src, NetworkPlayer* dest);
113 void
114 net_unserialize_player(const NetworkPlayer* src, Player* dest);
116 void
117 net_serialize_gamestate(const GameState* src, NetworkGameState* dest);
119 void
120 net_unserialize_gamestate(const NetworkGameState* src, GameState* dest);
122 #endif