Yeah, and any idiot can keep firing at docking port with random large ship and lag the server to oblivion in repetetive calculations. And it will be funny to see people's raging when someone places their ship on docking port for smaller ships obstructing stuff.
You do make a good point here. This could potentially be an issue. By the same token though, I don't think the potential for abuse is a good enough reason by itself to just dismiss an idea completely. For example, if the dock really was intended for smaller ships, you could still use a dock with a fixed size, so that ships larger than that would not be able to dock there.
The lag spikes are really the killer issue here... While I think it's a solvable issue, if it could not be handled, then my idea doesn't work. However, I don't think this operation would actually be all that expensive. I'm not sure how Schema is currently handling collisions, but if it were me, I would probably approach it like this:
- Determine dock points and orientation
- Take max dimensions of both dock targets, corrected for new position and orientation.
- Get a list of the chunks each would occupy, based on max dimensions
- Remove any chunks with no data in them from the list.
- Intersect the lists to find chunks where intersection is possible
- Iterate through the remaining chunks to find any instances where both ships occupy the same space. The first instance of this that is found stops the process and cancels the dock.
Based on what I understand of the Schine engine, steps 1-4 are all basically free because this information is already tracked. For step 5, if there is no collision then the intersection is fast and produces an empty result, the ships don't intersect, and the dock is successful.
If the ships do intersect, the intersection list contains the smallest number of chunks where intersection would possibly occur. The iteration would be the most expensive part, but there are algorithms out there to make the search faster. Even so, I don't think it would be all that expensive, but it's an open question.
Worst case scenario is an oddly shaped ship with an equally oddly shaped dock (like intersecting loops, or figure-8s or something) that require checking a large number of chunks. Even so, performing an intersection check between the chunks themselves should be decently quick.
It's important to note that most of the lag we currently see from collisions comes not from the actual collision calculation, but from the result of that calculation. Namely because:
- Collision results (I.e. applied forces, motion etc) are currently 100% elastic. This means that there's no loss of inertia during collision between the two bodies, which results in lots of 'bouncing' and secondary collisions. These increase the number of calculations and thus lag, especially at high speed.
- The collision calculation is probably being redone at least every frame, and if a collision is detected again, the whole frame basically gets trashed, and needs to be re-rendered, which leads to...
- Ship collisions must also be rendered, in real time. Rendering is almost always the most expensive operation in any graphical application, especially a game like this.
Since docking calculations wouldn't need to care about most of those last three items, I think we would be in the clear.