[ANet] Sending only an element of an array struct

Posted By: alibaba

[ANet] Sending only an element of an array struct - 08/27/14 12:10

lets say i have a struct like this:
typedef struct {
var health;
var points;
...
}PLAYERSTRUCT;

And i declare and initialize it like this:
PLAYERSTRUCT Players[12];

Now i only want to send the health value of all 12 Players.
Do i need to do it in a for loop?

Or can i do something like this:
enet_sendto(Players.health,sizeof(var)*12,BROADCAST);
Posted By: WretchedSid

Re: [ANet] Sending only an element of an array struct - 08/27/14 12:19

Copy it into temporary buffer and send that buffer.
Posted By: alibaba

Re: [ANet] Sending only an element of an array struct - 08/27/14 12:29

The Problem is iŽm using the Memory Registration Mode, this means i have to register all datatypes at the beginning so i donŽt think i could register that temporary buffer at runtime.
Posted By: Ch40zzC0d3r

Re: [ANet] Sending only an element of an array struct - 08/27/14 13:45

Code:
for(int i = 0; i < 12; i++)
{
     pPlayer[i].points += 1;
     enet_sendto(&(pPlayer[i].points), sizeof(var), BROADCAST);
}



As simple as that laugh
Posted By: alibaba

Re: [ANet] Sending only an element of an array struct - 08/27/14 14:06

This is what i tried to avoid, because with every send call youŽll send 7 bytes of unnecessary data.
This is why i asked for a solution with only one send call.
Posted By: Ch40zzC0d3r

Re: [ANet] Sending only an element of an array struct - 08/27/14 16:33

I guess if you dont want any unneeded overhead you need to write your own plugin :S
So if you really want to avoid that, you have to write an array for every element, such like:
Code:
int iScore[32];



Then your could will work for sure.
It cant work with a struct because the data is allocated in the same order, so you'd send the whole player array to achieve it.
Posted By: EpsiloN

Re: [ANet] Sending only an element of an array struct - 04/09/15 22:52

Don't get caught in the optimization trap.
If you're sending 7 unneeded bytes for 12 vars 15 times per second to 12 clients, you get unneeded 14 kbps. Is that really too much? And, if you update 5 times per second, which is enough for me, you get 4,5kbps...
My advice is, first, make your mechanics and features. Think about the optimization after that. laugh

My laptop uploads with 5 to 15 mbps to my country and at least 256kbps worldwide (Its usually in the 512kbps-2mbps range)...
© 2024 lite-C Forums