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.
Bookmarks