Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with all units' voxels flipped relative to Y axis #1423

Merged
merged 2 commits into from
Sep 9, 2023

Conversation

narical
Copy link
Contributor

@narical narical commented Aug 9, 2023

Sometimes TileEngine::calculateLineVoxel() successfully creates the trajectory to voxel inside a unit, but returns V_EMPTY instead of V_UNIT. As it turned out, LOFTemps data is stored in memory in "right" direction, with positive X axis from left to right, but (1 << x) in code counts X axis in negative direction, from right to left. LOFTemp becomes effectively inverted from left to right, which moves unit slightly to the left. For terrain code, this effect negated by inverting X axis beforehand, just like that:

int x = 15 - voxel.x%16;
int y = voxel.y%16;

but the unit check does:

int x = voxel.x%16;
int y = voxel.y%16;

Also, in original X-Com it was 0x8000 >> x - just shifting X in positive direction, without double inverting it

Current 2x2 units loftemps loading logic is inverted too, so I've added workaround to not break anything (switching left/right parts).

Inverted units have new center at (7,8) - Volutar has deducted that empirically somehow and "fixed" in
757d674 so I reverted those too.

Images before and after a patch.

Center of inverted unit become (7,8) and Volutar deducted that empirically and made dirty fix in commit#757d674 which (fix, not the whole commit) can now be reverted. Big units loftemps loading logic was inverted too, and I've added quick workaround to not break anything
@MeridianOXC
Copy link
Member

Thank you for the report.
We will look at this and review carefully.
It will probably take a few weeks, please be patient.

@Yankes
Copy link
Contributor

Yankes commented Aug 13, 2023

As I see, part of problem is loftempsSet. I talked with Warboy about it and he said that reorder it to fix First Person Voxel View.
Probably best solution will need bit more changes to clean up whole situation.

@narical
Copy link
Contributor Author

narical commented Aug 13, 2023

As I see, part of problem is loftempsSet. I talked with Warboy about it and he said that reorder it to fix First Person Voxel View. Probably best solution will need bit more changes to clean up whole situation.

"reorder" means "flip it too"? Now it's in right direction. 1 << X increments X from rigth to left, to counter that we flip terrain, and apply inverted X axis to inverted terrain. My proposal is to change units' in similar manner, don't touch (1<<x) code but keep solution uniform with older terrain code.

The right solution, in my opinion, should be:

  • removing X axis invertion altogether both for units and terrain, turning 15 - voxel.x%16 to plain (and intuitive) voxel.x%16
  • removing X axis invertion in bits checking, turning (1 << x) to (0x8000 >> x) as was in the original game
  • don't touch loftempSet as bits are stored in right (and intuitive) way

@Yankes
Copy link
Contributor

Yankes commented Aug 13, 2023

As I see, part of problem is loftempsSet. I talked with Warboy about it and he said that reorder it to fix First Person Voxel View. Probably best solution will need bit more changes to clean up whole situation.

"reorder" means "flip it too"? Now it's in right direction. 1 << X increments X from rigth to left, to counter that we flip terrain, and apply inverted X axis to inverted terrain. My proposal is to change units' in similar manner, don't touch (1<<x) code but keep solution uniform with older terrain code.

I ask SupSuper what version he prefer, he answer that your "hack" is preferred, this will have side effect that
how loftempsSet will work will broken as order with it take templates for body parts will be very unexpected for modder.

Probably for all this 6y everybody copy paste [ 92, 89, 90, 91 ] and call it a day, even its do not had any sense.

The right solution, in my opinion, should be:

* removing X axis invertion altogether both for units and terrain, turning `15 - voxel.x%16` to plain (and intuitive) `voxel.x%16`

* removing X axis invertion in bits checking, turning (1 << x) to (0x8000 >> x) as was in the original game

* don't touch loftempSet as bits are stored in right (and intuitive) way

@narical
Copy link
Contributor Author

narical commented Aug 14, 2023

As for parts[] = {1,0,3,2} - I didn't come to a wiser solution, with just a single formula as it was before. But I was tired and sleepy, maybe you guys can do it in a smarter way

upd: and by "the right solution" I mean "pure, but maybe not affordable". That's why my PR is what it is )

@Yankes
Copy link
Contributor

Yankes commented Aug 25, 2023

@narical Have you example of case where center (7,8) need to be corrected?
example
I locally flip only X axes and result look not shifted.

@narical
Copy link
Contributor Author

narical commented Aug 26, 2023

@narical Have you example of case where center (7,8) need to be corrected? example I locally flip only X axes and result look not shifted.

Shifting occurs in case of 1-tile units, due to flipping them along X axis. In that case, their center point (8,8) shifts to (7,8). For big 2x2 units, loftemps loading was initially made to make correct cylinder with respect to X inversion. So fixing inversion means getting big units "inverted", and moves all 1-tile units 1 voxels to the right where they intended to be.

@Yankes
Copy link
Contributor

Yankes commented Aug 30, 2023

fpslook039
fpslook040
toggling between int x = 15 - voxel.x%16; and int x = voxel.x%16; move units voxels around (this one belongs to Secioid).

I think this commit is fine aside of constexpr that is not available before C++11.

Copy link
Contributor

@Yankes Yankes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside C++02 incomparability change look fine

src/Battlescape/TileEngine.cpp Outdated Show resolved Hide resolved
@narical
Copy link
Contributor Author

narical commented Aug 31, 2023

I changed constexpr to const, commited to my branch, and pressed "resolve conversation" here

@SupSuper SupSuper merged commit 1c188b9 into OpenXcom:master Sep 9, 2023
4 checks passed
@MeridianOXC
Copy link
Member

This PR was now merged into OXCE too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants