Add text message stuff (not used yet), simplified some function calls

This commit is contained in:
simon.kagstrom 2009-04-13 06:31:12 +00:00
parent d9171701f8
commit 0680b1d8e0
3 changed files with 40 additions and 21 deletions

View File

@ -608,7 +608,7 @@ void C64::network_vblank()
/* Has the peer sent any data? */
if (remote->ReceiveUpdate() == true)
{
if (remote->DecodeUpdate(remote->GetScreen(),
if (remote->DecodeUpdate(this->TheDisplay,
js, this->TheSID) == false)
{
/* Disconnect or sending crap, remove this guy! */

View File

@ -157,7 +157,7 @@ size_t Network::EncodeSoundRaw(struct NetworkUpdate *dst,
return len;
}
bool Network::DecodeDisplayDiff(Uint8 *screen, struct NetworkUpdate *src,
bool Network::DecodeDisplayDiff(struct NetworkUpdate *src,
int x_start, int y_start)
{
struct NetworkUpdateDisplay *dp = (struct NetworkUpdateDisplay *)src->data;
@ -179,14 +179,14 @@ bool Network::DecodeDisplayDiff(Uint8 *screen, struct NetworkUpdate *src,
x = x_start + x_diff;
y = y + y_diff;
screen[y * DISPLAY_X + x] = color;
this->screen[y * DISPLAY_X + x] = color;
p += 2;
}
return true;
}
bool Network::DecodeDisplayRLE(Uint8 *screen, struct NetworkUpdate *src,
bool Network::DecodeDisplayRLE(struct NetworkUpdate *src,
int x_start, int y_start)
{
struct NetworkUpdateDisplay *dp = (struct NetworkUpdateDisplay *)src->data;
@ -206,7 +206,7 @@ bool Network::DecodeDisplayRLE(Uint8 *screen, struct NetworkUpdate *src,
while (len > 0)
{
screen[y * DISPLAY_X + x] = color;
this->screen[y * DISPLAY_X + x] = color;
len--;
x++;
if ((x - x_start) % SQUARE_W == 0)
@ -221,7 +221,7 @@ bool Network::DecodeDisplayRLE(Uint8 *screen, struct NetworkUpdate *src,
return true;
}
bool Network::DecodeDisplayRaw(Uint8 *screen, struct NetworkUpdate *src,
bool Network::DecodeDisplayRaw(struct NetworkUpdate *src,
int x_start, int y_start)
{
struct NetworkUpdateDisplay *dp = (struct NetworkUpdateDisplay *)src->data;
@ -235,8 +235,8 @@ bool Network::DecodeDisplayRaw(Uint8 *screen, struct NetworkUpdate *src,
Uint8 a = v >> 4;
Uint8 b = v & 0xf;
screen[ y * DISPLAY_X + x ] = a;
screen[ y * DISPLAY_X + x + 1 ] = b;
this->screen[ y * DISPLAY_X + x ] = a;
this->screen[ y * DISPLAY_X + x + 1 ] = b;
}
}
@ -382,8 +382,7 @@ size_t Network::EncodeDisplaySquare(struct NetworkUpdate *dst,
return dst->size;
}
bool Network::DecodeDisplayUpdate(Uint8 *screen,
struct NetworkUpdate *src)
bool Network::DecodeDisplayUpdate(struct NetworkUpdate *src)
{
struct NetworkUpdateDisplay *dp = (struct NetworkUpdateDisplay *)src->data;
int square = dp->square;
@ -391,11 +390,11 @@ bool Network::DecodeDisplayUpdate(Uint8 *screen,
const int square_y = SQUARE_TO_Y(square);
if (src->type == DISPLAY_UPDATE_DIFF)
return this->DecodeDisplayDiff(screen, src, square_x, square_y);
return this->DecodeDisplayDiff(src, square_x, square_y);
else if (src->type == DISPLAY_UPDATE_RAW)
return this->DecodeDisplayRaw(screen, src, square_x, square_y);
return this->DecodeDisplayRaw(src, square_x, square_y);
else if (src->type == DISPLAY_UPDATE_RLE)
return this->DecodeDisplayRLE(screen, src, square_x, square_y);
return this->DecodeDisplayRLE(src, square_x, square_y);
/* Error */
return false;
@ -419,6 +418,21 @@ size_t Network::GetSoundBufferSize()
return Network::sample_head- Network::sample_tail;
}
void Network::EncodeTextMessage(char *str)
{
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
char *p = (char*)dst->data;
size_t len = strlen(str) + 1;
len += (len & 3);
dst = InitNetworkUpdate(dst, TEXT_MESSAGE,
sizeof(NetworkUpdate) + len);
memset(p, 0, len);
strncpy(p, str, len - 1);
this->AddNetworkUpdate(dst);
}
void Network::EncodeSound()
{
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
@ -673,6 +687,7 @@ bool Network::MarshalData(NetworkUpdate *p)
case JOYSTICK_UPDATE:
case DISCONNECT:
case CONNECT_TO_PEER:
case TEXT_MESSAGE:
case STOP:
break;
case PING:
@ -763,6 +778,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
case JOYSTICK_UPDATE:
case DISCONNECT:
case CONNECT_TO_PEER:
case TEXT_MESSAGE:
case STOP:
/* Nothing to do, just bytes */
break;
@ -826,7 +842,7 @@ bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
return this->DeMarshalData(p);
}
bool Network::DecodeUpdate(uint8 *screen, uint8 *js, MOS6581 *dst)
bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
{
NetworkUpdate *p = this->ud;
bool out = true;
@ -849,7 +865,7 @@ bool Network::DecodeUpdate(uint8 *screen, uint8 *js, MOS6581 *dst)
/* No screen updates _to_ the master */
if (Network::is_master)
break;
if (this->DecodeDisplayUpdate(screen, p) == false)
if (this->DecodeDisplayUpdate(p) == false)
out = false;
break;
case JOYSTICK_UPDATE:

View File

@ -9,6 +9,7 @@
#include <SDL.h>
#include "SID.h"
#include "Display.h"
#define FRODO_NETWORK_PROTOCOL_VERSION 2
@ -38,6 +39,7 @@ typedef enum
KEYBOARD_UPDATE = 6,
JOYSTICK_UPDATE = 7,
ENTER_MENU = 8,
TEXT_MESSAGE = 9,
} network_message_type_t;
typedef enum
@ -152,8 +154,10 @@ public:
void EncodeJoystickUpdate(Uint8 v);
void EncodeTextMessage(char *str);
bool DecodeUpdate(uint8 *screen, uint8 *js, MOS6581 *dst);
bool DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst);
void ResetNetworkUpdate(void);
@ -247,10 +251,9 @@ protected:
/**
* Decode a display update message onto @a screen
*
* @param screen the screen to draw to
* @param src the message to decode
*/
bool DecodeDisplayUpdate(Uint8 *screen, struct NetworkUpdate *src);
bool DecodeDisplayUpdate(struct NetworkUpdate *src);
void AddNetworkUpdate(struct NetworkUpdate *update);
@ -269,11 +272,11 @@ protected:
*/
bool CompareSquare(Uint8 *a, Uint8 *b);
bool DecodeDisplayDiff(Uint8 *screen, struct NetworkUpdate *src,
bool DecodeDisplayDiff(struct NetworkUpdate *src,
int x, int y);
bool DecodeDisplayRLE(Uint8 *screen, struct NetworkUpdate *src,
bool DecodeDisplayRLE(struct NetworkUpdate *src,
int x, int y);
bool DecodeDisplayRaw(Uint8 *screen, struct NetworkUpdate *src,
bool DecodeDisplayRaw(struct NetworkUpdate *src,
int x, int y);
void SendPingAck(int seq);