the slowest connection is likely to be only a 56kbit modem, thats 7kb/s
max, so lets say they average 4kb/s, you have 4096bytes that you can
send with in that one second, and your structure is like this
typedef struct {
float flFuel; // 4 bytes(DWORD)
vec3_t vecNewVector; // 3 DWORDs = 12 bytes
} user_variables_t; // Total = 16bytes
You are sending 16bytes for the message contence, leaving 4080bytes of
his 4kb/s for that second, which isn't going to worry that person one
little bit..you can do some encoding, and compression if you wanted to
get it done better... :D
#define MIN_PERSENT_TO_SEND_FULL 0.75
void SendCheckMemory(char *curr, char *old, int size)
{
int changes=0;
int changesize=0;
int totalchangesize=0;
int *sizes;
int *offsets;
int tmp2;
bool tmp;
for(register int i=0;i<size;i++)
{
if(curr[i] != old[i])
{
changesize++;
if(!tmp)
{
changes++;
tmp=true;
tmp2=i;
}
}
else
{
if(tmp)
{
totalchangesize += changesize;
tmp = false;
sizes=realloc(sizes, changes*4);
offsets=realoc(offsets, changes*4);
sizes[changes-1] = changesize;
offsets[changes-1] = tmp2;
tmp2=0;
changesize=0;
}
}
}
if((totalchangesize >= (size*MIN_PERSENT_TO_SEND_FULL)) ||
((totalchangesize+(changes*8)) => size)
{
WRITE_BYTE(0x00);
for(i=0;i<size;i++)
WRITE_BYTE(curr[i]);
}
else
{
WRITE_BYTE(0x01);
WRITE_LONG(changes);
for(i=0;i<changes;i++)
{
WRITE_LONG(offsets[i]);
WRITE_LONG(sizes[i]);
for(register int x=offsets[i];x<sizes[i];x++)
WRITE_BYTE(curr[x]);
}
}
}
void ReadCheckMemory(char *mem, int size)
{
if(READ_BYTE() == 0x00)
{
for(register int i=0;i<size;i++)
mem[i] = READ_BYTE();
}
else
{
for(register int i=0;i<READ_LONG();i++)
{
int offset=READ_LONG();
int size=READ_LONG();
for(register int x=offset;x<size;x++)
mem[x] = READ_BYTE();
}
}
}
Have i confused you yet? hehe Now you can put massive ones in there, Its
midnite here, so time for me to get some sleep, if you don't understand
what i just posted, just ask, its not unusual with me never commenting..
:D
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Jim Hunter
Sent: Tuesday, 11 June 2002 11:06 PM
To: [EMAIL PROTECTED]
Subject: Re: RE: [hlcoders] A method for creating new user variables
> Nice one, just thought I'd add my 2c Maybe a better way of sending
> some stuff would be something like the following
>
> void SendMemory(const char *mem, const int size)
> {
> for(int i=0;i<size;i++)
> WRITE_BYTE(mem[i]);
> }
>
> That would send the structure if you called it like this
> MESSAGE_BEGIN(MSG_ONE, gmsgUserData, NULL, (struct edict_s *)ent);
> SendMemory(pPlayer->UserData, sizeof(user_variables_t));
> MESSAGE_END();
>
> Personally I think its a lot easier..Then to receive it you do the
> following..
>
> char * ReadMemory(int size)
> {
> char *mem=(char*)malloc(size);
> for(int i=0;i<size;i++)
> mem[i] = READ_BYTE();
> return mem;
> }
That way is certainly easier. I just wanted to conserve bandwidth by
only sending the parts that had changed rather than sending the entire
structure with each update. (Of course, not much is gained if every
member of the structure is likely to have changed since the last
update).
Thanks for the feedback.
Jim
Jim Hunter
[EMAIL PROTECTED]
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders