Processing multiple units.
I have created a Vehicle Object from The Nature of Code tutorials, and I have made the vehicle create a thread in itself to update the direction that it should take to reach the target point, the thread is called every 2 seconds.
When I create too many objects (1), the computer lagged so much, so I created another object called container_object
, the container job is to have multiple vehicles and to use only one thread to update the direction for all child vehicles that the container has, and I removed the thread initialization from the vehicle object and add it to the container.
But when I created multiple containers (2), the program lagged even more than the first time. in the first program (1) the system.threads.length
was 248 threads and the average fps was 15-20, and in the second program (2) the system.threads.length
was 7 threads and the average fps was 5-9.
- Why did this happen?
- Can you tell me how to improve the code?