Re-fix Wii compile

This commit is contained in:
simon.kagstrom 2009-02-21 07:59:45 +00:00
parent 4e90dad903
commit ed13ce7073
5 changed files with 56 additions and 94 deletions

View File

@ -187,6 +187,7 @@ private:
public: public:
CmdPipe *gui; CmdPipe *gui;
#elif defined(GEKKO) #elif defined(GEKKO)
public:
void open_close_joystick(int port, int oldjoy, int newjoy); void open_close_joystick(int port, int oldjoy, int newjoy);
double speed_index; double speed_index;
#endif #endif

View File

@ -395,9 +395,6 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t
void Network::EncodeSound() void Network::EncodeSound()
{ {
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
int cnt = 0;
/* Nothing to encode? */ /* Nothing to encode? */
if (!this->is_master || if (!this->is_master ||
Network::sample_head == Network::sample_tail) Network::sample_head == Network::sample_tail)
@ -561,7 +558,6 @@ bool Network::SendUpdate()
void Network::AddNetworkUpdate(NetworkUpdate *update) void Network::AddNetworkUpdate(NetworkUpdate *update)
{ {
size_t sz = update->size;
Uint8 *next = (Uint8*)this->cur_ud + update->size; Uint8 *next = (Uint8*)this->cur_ud + update->size;
this->cur_ud = (NetworkUpdate*)next; this->cur_ud = (NetworkUpdate*)next;
@ -584,7 +580,7 @@ bool Network::MarshalData(NetworkUpdate *p)
case LIST_PEERS: case LIST_PEERS:
{ {
NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data; NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data;
for (int i = 0; i < lp->n_peers; i++) for (unsigned int i = 0; i < lp->n_peers; i++)
{ {
NetworkUpdatePeerInfo *peer = &lp->peers[i]; NetworkUpdatePeerInfo *peer = &lp->peers[i];
@ -654,7 +650,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data; NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data;
lp->n_peers = ntohl(lp->n_peers); lp->n_peers = ntohl(lp->n_peers);
for (int i = 0; i < lp->n_peers; i++) for (unsigned int i = 0; i < lp->n_peers; i++)
{ {
NetworkUpdatePeerInfo *peer = &lp->peers[i]; NetworkUpdatePeerInfo *peer = &lp->peers[i];
@ -716,8 +712,6 @@ bool Network::DecodeUpdate(uint8 *screen, uint8 *js)
break; break;
case LIST_PEERS: case LIST_PEERS:
{ {
NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data;
} break; } break;
case PING: case PING:
/* Send an ack */ /* Send an ack */
@ -844,7 +838,6 @@ bool Network::WaitForPeerList()
bool Network::WaitForPeerReply() bool Network::WaitForPeerReply()
{ {
struct timeval tv; struct timeval tv;
const char **msgs;
tv.tv_sec = 3; tv.tv_sec = 3;
tv.tv_usec = 0; tv.tv_usec = 0;
@ -966,7 +959,7 @@ uint8 Network::sample_buf[NETWORK_SOUND_BUF_SIZE];
int Network::sample_head; int Network::sample_head;
int Network::sample_tail; int Network::sample_tail;
#if defined(GEKKOd) #if defined(GEKKO)
#include "NetworkWii.h" #include "NetworkWii.h"
#else #else
#include "NetworkUnix.h" #include "NetworkUnix.h"

View File

@ -15,7 +15,7 @@ static int set_sock_opts(int sock)
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int)); return setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int));
} }
/* From glibc docs */ /* From glibc docs */

View File

@ -13,9 +13,7 @@ static int set_sock_opts(int sock)
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
net_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, net_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
net_setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int)); return net_setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int));
return 0;
} }
/* From glibc docs */ /* From glibc docs */
@ -47,7 +45,7 @@ static int make_socket (uint16_t port)
return sock; return sock;
} }
bool init_sockaddr (struct sockaddr_in *name, bool Network::InitSockaddr (struct sockaddr_in *name,
const char *hostname, uint16_t port) const char *hostname, uint16_t port)
{ {
struct hostent *hostinfo; struct hostent *hostinfo;
@ -60,103 +58,57 @@ bool init_sockaddr (struct sockaddr_in *name,
fprintf (stderr, "Unknown host %s.\n", hostname); fprintf (stderr, "Unknown host %s.\n", hostname);
return false; return false;
} }
#warning this need to be fixed
//name->sin_addr = *(struct in_addr *) hostinfo->h_addr; //name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
return true; return true;
} }
bool Network::InitSocket(const char *remote_host, int port)
bool Network::StartListener(int port)
{ {
Network::listen_sock = make_socket(port);
if (Network::listen_sock < 0)
return false;
if (net_listen(Network::listen_sock, MAX_NETWORK_PEERS) < 0)
{
perror("listen");
return false;
}
return true;
}
bool Network::CheckNewConnection()
{
struct timeval tv;
struct sockaddr_in peer_name;
size_t size;
int peer_sock;
fd_set listen_fds;
Network *peer;
/* Not initialized yet */
if (Network::listen_sock <= 0)
return false;
/* No more than that thanks... */
if (Network::n_peers >= MAX_NETWORK_PEERS)
return false;
FD_ZERO(&listen_fds);
FD_SET(Network::listen_sock, &listen_fds);
/* If something connects, create a new client */
memset(&tv, 0, sizeof(tv));
int v = net_select(Network::listen_sock + 1, &listen_fds, NULL, NULL, &tv);
if ( v < 0)
{
perror("select");
exit(1);
}
else if ( v == 0 )
return false;
size = sizeof(peer_name);
peer_sock = net_accept(Network::listen_sock, (struct sockaddr*)&peer_name, &size);
if (peer_sock < 0)
{
fprintf(stderr, "Accepting peer failed\n");
return false;
}
/* And add the new one! */
Network::AddPeer(new Network(peer_sock, true));
return true;
}
bool Network::ConnectTo(const char *hostname, int port)
{
/* Again from glibc docs */
struct sockaddr_in servername;
int sock;
/* Create the socket. */ /* Create the socket. */
sock = net_socket (PF_INET, SOCK_STREAM, 0); this->sock = net_socket (PF_INET, SOCK_DGRAM, 0);
if (sock < 0) if (this->sock < 0)
{ {
perror ("socket (client)"); perror ("socket (client)");
return false; return false;
} }
set_sock_opts(sock); set_sock_opts(this->sock);
/* Connect to the server. */ /* Connect to the server. */
init_sockaddr (&servername, hostname, port); this->InitSockaddr(&this->connection_addr, remote_host, port);
if (net_connect(sock, (struct sockaddr *) &servername,
sizeof (servername)) != 0) if (this->is_master)
{ {
perror ("connect (client)"); if (net_bind(this->sock, (struct sockaddr *)&this->connection_addr,
return false; sizeof (this->connection_addr)) < 0)
{
perror ("bind");
return false;
}
} }
Network::AddPeer( new Network(sock, false) );
return true; return true;
} }
bool Network::ReceiveData(void *dst, int sock, size_t sz)
{
size_t received_sz = 0;
while (received_sz < sz)
{
int v = net_read(sock, dst, sz);
if (v < 0)
return false;
received_sz += v;
}
this->traffic += received_sz;
return sz > 0;
}
ssize_t Network::ReceiveFrom(void *dst, int sock, size_t sz, ssize_t Network::ReceiveFrom(void *dst, int sock, size_t sz,
struct sockaddr_in *from) struct sockaddr_in *from)
{ {
@ -173,6 +125,22 @@ ssize_t Network::SendTo(void *src, int sock, size_t sz, struct sockaddr_in *to)
return net_sendto(sock, src, sz, 0, (struct sockaddr*)to, to_sz); return net_sendto(sock, src, sz, 0, (struct sockaddr*)to, to_sz);
} }
bool Network::SendData(void *src, int sock, size_t sz)
{
size_t sent_sz = 0;
while (sent_sz < sz)
{
int v = net_write(sock, (void*)src, sz);
if (v < 0)
return false;
sent_sz += v;
}
return true;
}
bool Network::Select(int sock, struct timeval *tv) bool Network::Select(int sock, struct timeval *tv)
{ {
fd_set fds; fd_set fds;

View File

@ -117,7 +117,7 @@ void VirtualKeyboard::draw()
(this->shift_on && key.is_shift)) (this->shift_on && key.is_shift))
b = 0; b = 0;
menu_print_font(this->screen, this->font, r, g, b, menu_print_font(this->screen, r, g, b,
x * key_w + border_x, y * key_h + border_y, x * key_w + border_x, y * key_h + border_y,
what); what);
} }
@ -313,7 +313,7 @@ const char *VirtualKeyboard::get_string()
/* SDL_Flip is done in get_key_internal() */ /* SDL_Flip is done in get_key_internal() */
SDL_FillRect(this->screen, 0, SDL_MapRGB(screen->format, 0x00, 0x80, 0x80)); SDL_FillRect(this->screen, 0, SDL_MapRGB(screen->format, 0x00, 0x80, 0x80));
menu_print_font(this->screen, this->font, 255, 255, 0, menu_print_font(this->screen, 255, 255, 0,
40, screen->h - 50, 40, screen->h - 50,
this->buf); this->buf);
} }