Dumb rotation refactor#512
Conversation
… with the rest of the model code
…a subfunction) in modelread.cpp, and add some descriptive commenting
…del instances are created. This might be sufficient to get dumb rotations working for ships.
…ove below look_at and dumb_rotate
|
Here's the mod I use for testing. It includes the standard Faustus, a Faustus X using dumb-rotation instead of standard rotation, and the Praetor ship, which uses look-at. (Ignore the Praetor for now; look-at will be re-implemented after dumb-rotation is finished.) Sorry for the triple-post; github was derping out with attachments. I've uploaded it instead. |
|
The changes look good. I haven't tested it but I'll do that as soon as possible.
|
…function contract is being followed, and fix an incipient bug by adding a necessary is_ship flag
|
I tested the changes. Dumb rotations still work like before but there is no collision detection (but that's also the case in master). |
|
I concur; if collision detection doesn't work right with it currently, then it not working with this PR isn't a regression. |
|
Ok, fair enough. As for the There are a couple additional cases I want to add or test before this is merged:
I plan to look at those this evening. |
|
Depending on the argument for |
|
The two code paths are handling exactly the same functionality, just in slightly different ways for slightly different circumstances. They belong in the same function. If they were separated into two different functions, the tight coupling would be de-emphasized and the risk for confusion and code drift would be increased. |
|
...Except the two code paths aren't sharing any code in |
…finally, proper collision detection!
|
They aren't sharing any code, but they are certainly sharing functionality. As the comment preceding the function explains, the dumb-rotation is being applied in two slightly different ways depending on the requirements of whether the thing is a ship or not a ship. And the actual angle updating already was split out into In other news, I figured out why collision detection wasn't working and added a commit to fix that (975e108). Along with adding the model_instance code for non-ship models (1651242) and making a few other fixes, that finishes up all the changes for dumb-rotation. Pending approval, this PR is ready to be merged. |
|
Would moving the check (or saving the result in a |
|
Which check do you propose to move into the for-loop? |
|
|
|
I don't think so. I tried hacking the code around a bit just now and it isn't as good of a solution. It would interleave the two code paths too much; the distinction between the two circumstances would be muddled. It actually makes it less readable because you have to puzzle out the two different execution flows. |
|
If it doesn't work then I'd say the code can stay as it is. It's a minor style issue that doesn't cause any issues. With that out of the way, I'd say this is ready to be merged. |
There was a problem hiding this comment.
As noted earlier in the look_at PR, checking for both "$gun_rotation:" and "$gun_rotation" is redundant; might as well get rid of the former while we're at it.
|
Good point. Done, and I've removed colons from a couple other places as well. |
|
@MageKing17 signed off on merging this, woot! Next stop, fixing |
"Dumb rotation" is rotation of a submodel without having an associated subsystem. The original implementation by Bobboau was quite hackish, involving a redundant traversal of the submodel hierarchy independent of all the rest of the submodel code.
This PR merges dumb-rotation into the rest of the code, so that neither the traversal nor the rotation calculations are duplicated. It also introduces separate dumb-rotation data structures to hold the rotation information (which fills in for the absent subystems) so that the rotation doesn't have to be brute-forced each frame. Finally, it uses Swifty's model_instance code so that it is not necessary to call ship_model_start and ship_model_stop whenever the game wants to interact with the submodels.
(Note that, since dumb-rotation doesn't require a subsystem, it can be used for submodel rotation on models that are not ships.)
This PR incorporates some of the tweaked model_read code from #358. It is also a prerequisite for finally merging the look_at feature into the codebase in a non-hackish way, as look_at will use some of the helper functions in this PR. (The previously proposed look_at feature used a redundant brute-force traversal just like dumb_rotation did, making for two redundant traversals, each with their own redundant calculations.)
I've tested dumb-rotation in-game using this patch, and the rotating submodels render as you would expect. Curiously, collision detection doesn't seem to work. Even more curiously, collision detection didn't work on pre-refactor dumb-rotation either! I want to get collision detection working before this PR is merged, but I thought I'd create it anyway just to get additional eyes on it in the meantime.