im facing a fork in the road in development of effecient server code.
lets say a client is gonna shoot a fireball, and only the people in his view is gonna see this (its a 2d tile based game, so no trouble finding those people). Ok, now i could send that to the server, and the server could update the clients in his view. BUT! we would be using a for loop. This for loop would keep looping until its sent the data to each client that needs to be updated. Here is the problem, the server has to update in a loop (well at least mine does), and that for loop could be vital time missed.
So im figureing im gonna need some type of loop-based solution. One loop goes, it sends to the first client, another loop goes, it sends to the next client, another loop goes, it sends to the next client, and so on. As opposed to one loop goes, it sends to all the clients in the for loop, then continues on through the loop.
myloop
update the server
client sent a fireball
for each client in client''s view
send fireball
thats the BAD way to do it, but im looking for a BETTER way to do it
my loop
update the server
client sent a fireball
send to next client in client''s view
send fireball
//loop returns
my loop
update the server
already sent fireball, still sending
send to next client in client''s view
send fireball
//loop returns
something like that. But the thing is i dont know how to actually implement this with code. I guess you could call this non-blocking server sorting or something. Where a for loop is gonna block, but i need another method that wont block.
i guess the cop-out method would be this
my loop
update the server
client sent fireball
for each client in client''s view
update the server
send fireball
note: update server checks for incoming messages (and handles them), incoming connections, disconnecting players, and socket errors on clients(disconnects them).
so anyone?
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios