PlayerViewport class
#include <Jazz2/Rendering/PlayerViewport.h>
Player viewport.
Owns the on-screen region rendered for a single player together with its full render pipeline: the scene viewport and camera that follows a target actor, the LightingRenderer, the chain of BlurRenderPass passes, and the CombineRenderer. Also drives per-frame camera movement, shake, overrides and ambient light.
Public types
- struct WaterView
- What the water needs, in the pixels of the view, shared by the combine pass and the water in the middle of the scene.
Public static functions
- static auto GetAmbientLightChannels(float ambientLevel) -> Vector2f
- Returns the ambient light level split into the channels of the lighting buffer.
Constructors, destructors, conversion operators
-
PlayerViewport(LevelHandler* levelHandler,
Actors::
ActorBase* targetActor) - Creates a new instance.
Public functions
- auto Initialize(SceneNode* sceneNode, SceneNode* outputNode, Recti bounds, bool useHalfRes) -> bool
- Initializes the viewport.
- void Register()
- Registers the viewport and its render passes into the viewport chain.
- auto GetBounds() const -> Rectf
- Returns bounds of the viewport, empty until it's initialized.
- auto GetViewportSize() const -> Vector2i
- Returns size of the viewport.
- auto GetBlurredTarget() const -> Texture*
- Returns the most blurred level of the blur chain, or
nullptrif blur effects are disabled. -
auto GetTargetActor() const -> Actors::
ActorBase* - Returns the actor the camera follows.
- auto GetWaterView() const -> WaterView
- Returns what the water needs in the current frame.
- auto IsWaterInScene() const -> bool
- Returns
trueif the water is drawn in the middle of the scene in the current frame, see DrawWater(). - auto HasWaterPasses() const -> bool
- Returns
trueif the viewport has what the water in the middle of the scene needs, or there's nothing to have. - void DrawWater(RenderQueue& renderQueue)
- Adds the water to the scene, while it's visited.
- void OnEndFrame()
- Called at the end of each frame.
- void UpdateCamera(float timeMult)
- Updates the camera position.
- void ShakeCameraView(float duration)
- Shakes the camera view for a given duration.
- void OverrideCamera(CameraOverride modeX, float x, CameraOverride modeY, float y, bool centered, bool instant)
- Fixes the camera at a position of the level, or lets it follow the target actor again, on each axis, see ILevelHandler::
OverrideCameraView(). - void WarpCameraToTarget(bool fast)
- Instantly moves the camera to the target actor.
- void ResetLookAhead()
- Places the look-ahead where it rests for the target actor as it stands now, instead of easing into it.
- void SetFreeCamera(Vector2f center, float scale)
- Makes the camera a free one, centered at a given position of the level and zoomed by a given scale.
- void SetFollowCamera()
- Makes the camera follow the target actor again, at the scale of the game.
- auto IsFreeCamera() const -> bool
- Returns
trueif the camera is a free one, see SetFreeCamera(). - auto GetCameraCenter() const -> Vector2f
- Returns the center of the view in the level.
- auto GetCameraScale() const -> float
- Returns how many view pixels a world pixel takes, 1 in the game.
- auto GetWorldViewSize() const -> Vector2f
- Returns the size of the part of the level the view shows.
- auto WorldToView(Vector2f worldPos) const -> Vector2f
- Converts a position in the level to a position in the view, in pixels from its top left corner.
- auto ViewToWorld(Vector2f viewPos) const -> Vector2f
- Converts a position in the view, in pixels from its top left corner, to a position in the level.
Function documentation
static Vector2f Jazz2:: Rendering:: PlayerViewport:: GetAmbientLightChannels(float ambientLevel)
Returns the ambient light level split into the channels of the lighting buffer.
The intensity (up to 1) in X and the brightness in Y - light above full brightens the view and lifts dark colors as JJ2+ does with lighting above 100, by the brightness the lights add (see Combine.shader).
Jazz2:: Rendering:: PlayerViewport:: PlayerViewport(LevelHandler* levelHandler,
Actors:: ActorBase* targetActor)
Creates a new instance.
| Parameters | |
|---|---|
| levelHandler | Level handler that owns the viewport |
| targetActor | Actor the camera follows |
bool Jazz2:: Rendering:: PlayerViewport:: Initialize(SceneNode* sceneNode,
SceneNode* outputNode,
Recti bounds,
bool useHalfRes)
Initializes the viewport.
| Parameters | |
|---|---|
| sceneNode | Root node of the rendered scene |
| outputNode | Node the resulting image is attached to |
| bounds | Bounds of the viewport |
| useHalfRes | Whether to render at half resolution |
void Jazz2:: Rendering:: PlayerViewport:: DrawWater(RenderQueue& renderQueue)
Adds the water to the scene, while it's visited.
The water in front of a layer behind the others is drawn at its depth (see LevelHandler::
void Jazz2:: Rendering:: PlayerViewport:: SetFreeCamera(Vector2f center,
float scale)
Makes the camera a free one, centered at a given position of the level and zoomed by a given scale.
The camera then stays where it's put, not limited by the level bounds, and doesn't need a target actor. A scale above 1 zooms in, one view pixel is 1 / scale world pixels. The level editor moves its camera this way.