PDA

View Full Version : Please Help ARGHHHHH! Main Loop & TIdTCPServer



Gadget
25-01-2004, 02:28 PM
OK, this problem has been bugging me for months and finally I think I sort of know what part of the problem is.

I have a server exe that processes creatures and players.

The server in simple terms is:-

while not bStop do
begin
ProcessCreatures;
Application.ProcessMessages;
end;


On the TIdTCPServer I have an event command for client movement.

When the client moves, it send the packet to this server, which takes 15 ticks to process at worst (not a lot). But... The packet isn't getting processed until as long as a second later. How can I force these damn packets to process?

I have tried loads of application.process messages everywhere. I have put an extra check in the main loop that states 'if time taken for loop run is less than 1 second, then just do application.processmessages for remaider, and even following the suggestions on other forums I tried Sleep(remainder);

Suggestions please!!

My personal theory is that its the Threading used by the Indy components, but how can I up the priority of the indy threads?

Gadget
25-01-2004, 06:46 PM
It has to be the TIdTCPServer components.

I changed the code to do one process of the loop, then stop the loop until a timer restarts it again after 1 second, Thats adequate amount of time for the CPU to finish processing 3 or 4 packets that take 10ns each, yet I still get a sort of lag effect. The creatures attack the spot where the player was 3 or 4 seconds prior, and because they are attacking the instance which changes instantly when the move packet is processed, its just confusing the hell out of me.

Its almost like my move packets are sat in a queue or buffer somewhere for a few seconds before they hit the events on the exe.

Gadget
28-01-2004, 06:09 PM
It's OK, you can lock this. I now know exactly what the problem is :)

Useless Hacker
28-01-2004, 10:12 PM
This thread seems to be a bit of a monologue. :D

BlueCat
29-01-2004, 10:04 AM
:shock: :lol: :lol: :lol:

Gadget
29-01-2004, 02:33 PM
Just to explain what the solution was (well, I still have to implement it yet...)

The main loop was only taking say 100ms to process all the creatures. But... In that 100ms loop the packets sent out to various players seems to halt the ability of the Indy threaded server sockets to actually recieved. ie. the events associated with the incoming packets do not fire. I think its due to the sockets being threaded and output seems to get priority over input. The CPU of the PC is no where near utilized and other exes that run server sockets respond perfectly. This lead me to 2 changes:-

1) Make outgoing packets even smaller.
2) Have a seperate high priority thread running that 'hosts' incoming server sockets. When packets are received, store the data in a buffer. (buffer contained in the original exe).
3) Change main exe to accept NO incoming packets at all, and to run through the input buffer every so often.

This should allow better control and syncronization, and hopefully stop the psuedo lag problem.