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

Camera Redesign #439

Merged
merged 13 commits into from
Apr 27, 2020
Merged

Camera Redesign #439

merged 13 commits into from
Apr 27, 2020

Conversation

pathunstrom
Copy link
Collaborator

@pathunstrom pathunstrom commented Apr 19, 2020

This is the long awaited fix to all the pain points in the Camera. So far, it's just an init.

This represents a breaking change in the API.

This touches on a number of issues, some solved wholly by this change, some only fixes part of the problem.

Resolves #185: pixel_ratio is now derived from the number of game units you want visible and the screen resolution. You can "zoom" by increasing or decreasing the width or height of the camera.
Resolves #310: Camera isn't added until SceneStarted event, but is fully initialized as soon as it's available.
Regarding #358: Did not deal with this directly. That test is currently nullified until we can go over it and determine what is going on.
Regarding #400: Removes the pixel_ratio argument from BaseScene.

@pathunstrom pathunstrom marked this pull request as ready for review April 26, 2020 22:10
@pathunstrom pathunstrom requested a review from a team as a code owner April 26, 2020 22:10
@pathunstrom pathunstrom marked this pull request as draft April 26, 2020 22:22
@pathunstrom pathunstrom marked this pull request as ready for review April 26, 2020 22:34
Copy link
Member

@AstraLuma AstraLuma left a comment

Choose a reason for hiding this comment

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

This overall looks good, but a few aspects need some polishing.

:attr:`Camera.width`, :attr:`Camera.height`, or the
``target_game_unit_width`` of the :class:`Camera` constructor) will
affect both :attr:`Camera.width` and :attr:`Camera.height`. Their ratio
is determined by the defined window.
Copy link
Member

Choose a reason for hiding this comment

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

I think we might need more prose to discuss camera initialization and when scenes can expect to have the camera.

@@ -111,12 +113,14 @@ def __init__(
resolution=DEFAULT_RESOLUTION,
window_title: str = "PursuedPyBear",
target_frame_rate: int = 30,
target_camera_width=25,
Copy link
Member

Choose a reason for hiding this comment

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

This is the default scene width? This is significantly larger than before, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Flipped a coin between a 32 pixel default sprite and a 64. I'm willing to switch it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(But yes, this is 25 x ~19, previously, we were 10 x ~7.5)

# regions they should render to.
camera = camera_class(self, self.target_camera_width, self.resolution)
scene.main_camera = camera
self.scene_cameras[scene] = [camera]
Copy link
Member

Choose a reason for hiding this comment

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

Why the extra ref?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Primarily to have handles to adjust resolution when we finally start supporting resizeable windows.

values = [width, height]
short_side_index = width > height
target = self.pixel_ratio * game_unit_size
target = pixel_ratio * game_object_size
Copy link
Member

Choose a reason for hiding this comment

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

Not actually a fan of this rename. The old name was more correct and we're not moving away from game units as a concept.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, yeah, sorry, I inlined this because pixel_ratio isn't directly a renderer concern anymore, then realized we had a test around this. Can revert.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please.

assert camera.translate_point_to_game_space(point) == expected


# @pytest.mark.skip(reason="Test for old camera. Will want to restore this functionality in new camera.")
Copy link
Member

Choose a reason for hiding this comment

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

Any reason these tests weren't ported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, this top one is because I didn't rewrite sprite_in_viewport because it's not used by anything in the library. I'll probably do it sometime in the next couple of months and then restore/rewrite the relevant test.

The one below it is because it's doing a lot, would require translation to the new camera tests, and I'm not entirely sure what all of the steps are there to do. As such, I'd rather rewrite it as its own thing and not tied to the giant pile of other changes going on. (And it's commented out because the old camera got killed, I'd have just left it marked skip otherwise.)

Copy link
Member

Choose a reason for hiding this comment

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

I think that's a useful utility, although the name isn't great.

The one below that is supposed to be a simple round-trip test: If we convert a point from game units to pixels and back, do we get the same point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a useful utility! I have no intention of leaving it cut forever. I just wanted to get the new camera working then I'll restore some of the niceties later.

The good news RE: round tripping, the tests for translate_point_to_screen and translate_point_to_game_space use the same values for their tests, just reversing input and output.

Copy link
Member

Choose a reason for hiding this comment

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

Well, doing a roundtrip test means it's generic and we can throw hypothesis at it.

@AstraLuma
Copy link
Member

We can drop sprite_in_viewport() for now, but i'll hold you to rewriting it.

Copy link
Member

@AstraLuma AstraLuma left a comment

Choose a reason for hiding this comment

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

bors r+

@bors bors bot merged commit 8253c00 into ppb:master Apr 27, 2020
@pathunstrom pathunstrom deleted the 185-camera-rework branch October 24, 2020 20:57
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.

Incomplete camera information at scene init Change the various camera relationships.
2 participants