The use of the proper sensor in Shiva is critical to obtaining optimal frame-rate. In the past, you may have hap-hazardly populated onSensorCollision without a second thought. This could cause serious performance issues down the road.
The largest difference in the 3 sensor handlers are the circumstances under which they are fired. I’m sure you are familiar with these differences already, but if you aren’t here is a quick recap.
I devised the following benchmark to measure this minimum performance impact. This benchmark can easily be reproduced by anyone, the steps to do so are as easy as 1-2-9:
Because objects spawn in the center of the scene, all sensors will overlap. This results in the sensor handlers being called (if applicable). Below are the resulting data sets from these tests.
I compared box vs spherical sensors, sensor quantity and onSensorCollision vs onSensorCollisionBegin/End. I ran these tests inside the editor with the preview mode set to Runtime (no debug objects being shown). This was ran on my 1.2 GHz netbook.
First I wanted to establish a baseline for sensor performance. This test was ran without any sensor handlers attached to the object. The performance can’t get any better than this.
The baseline indicated that box sensors were less performant than spherical sensors (head scratch).
I then added an onSensorCollision handler and repeated the tests while varying the sensor count. Keep in mind that my onSensorCollision is doing *absolutely nothing*, it literally doesn’t have any code in it. The extreme performance difference here is due to the overhead involved in the sensors.
I then switched collision handlers to onSensorCollisionBegin and ran the same tests as above.
Whoah! Huge difference! Clearly the reason why is that the sensor collision only hits the CPU a single time (when the sensors first collide) vs every single frame. These numbers are very close to the baseline, on average being ~15 objects off. There is still a bit of overhead, but clearly far better performance than the frame-by-frame situation.
The main items to take away from this data are: