Quote Originally Posted by User137 View Post
Also the mainloop's part for threads is like:
Code:
    i2:=count div 4;
    i3:=i2*2;
    i4:=i2*3;
    TPhysicsThread.Create(self, 0, i2-1);
    TPhysicsThread.Create(self, i2, i3-1);
    TPhysicsThread.Create(self, i3, i4-1);
    TPhysicsThread.Create(self, i4, count-2);
    while threads>0 do begin
      sleep(1); // It takes usually over 140ms, so sleep here is not unnecessary
      Application.ProcessMessages;
    end;
...
constructor TPhysicsThread.Create(parent: TGame; const first, last: cardinal);
...
Thread execute:
...
    for i:=FFirst to FLast do
      with star[i] do
        for j:=i+1 to count-1 do begin
So it will not stop responding. I know it could be done better though, even so that fps wouldn't be affected. I also realize now that all the threads aren't getting equal workload at all. Especially the first thread gets biggest work, and 4th one the smallest.
First of all get that Application.ProcessMessages out of that loop. It is not good to call Application.Process messages to often. And the reason why your main thread has so much load is becouse of Application.ProcessMessavges. It is quite resource consuming call. And all that processing time that is used by Application.ProcessMessages is taken away from one of your other threads making everything slower. And since you sad that you only have dual core the impact on overal speed can be quite big.
Wanna see how much Application.ProcessMessages affect your application. Start the simulation with setting sthat will cause low FPS, rotate the view and then pause the simulation. You will se that after you pause the simulation the overal view will quickly rotate to proper position while when being at low FPS it can be falling beind a litle.