Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 945 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[ANet] Sending only an element of an array struct #445067
08/27/14 12:10
08/27/14 12:10
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
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);


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: [ANet] Sending only an element of an array struct [Re: alibaba] #445068
08/27/14 12:19
08/27/14 12:19
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Copy it into temporary buffer and send that buffer.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: [ANet] Sending only an element of an array struct [Re: WretchedSid] #445069
08/27/14 12:29
08/27/14 12:29
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
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.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: [ANet] Sending only an element of an array struct [Re: alibaba] #445076
08/27/14 13:45
08/27/14 13:45
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
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

Last edited by Ch40zzC0d3r; 08/27/14 13:46.
Re: [ANet] Sending only an element of an array struct [Re: Ch40zzC0d3r] #445077
08/27/14 14:06
08/27/14 14:06
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
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.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: [ANet] Sending only an element of an array struct [Re: alibaba] #445084
08/27/14 16:33
08/27/14 16:33
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
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.

Last edited by Ch40zzC0d3r; 08/27/14 16:39.
Re: [ANet] Sending only an element of an array struct [Re: Ch40zzC0d3r] #450225
04/09/15 22:52
04/09/15 22:52
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
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)...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1