V-Gears 0
Free Final Fantasy VII engine.
Background2D Class Reference

A field background. More...

#include <Background2D.h>

Inheritance diagram for Background2D:
Collaboration diagram for Background2D:

Classes

struct  AnimationPlayed
 State of an animation. More...
 
struct  Tile
 Represents a tile. More...
 

Public Types

enum  SCROLL_TYPE { NONE , LINEAR , SMOOTH }
 How to scroll the background. More...
 
typedef VGears::Blending Blending
 
typedef std::vector< TileTileList
 

Public Member Functions

 Background2D ()
 Constructor. More...
 
virtual ~Background2D ()
 Destructor. More...
 
void InputDebug (const VGears::Event &event)
 
void Hide ()
 Hides the background. More...
 
void Show ()
 Shows the background. More...
 
void Update ()
 Run each frame. More...
 
void UpdateDebug ()
 Debug inormation about changes in the background. More...
 
void OnResize ()
 Called on window resize. More...
 
void Clear ()
 Removes the background and it's animations. More...
 
void ScriptAutoScrollToEntity (Entity *entity)
 Flags the background to automatically scroll to an entity position. More...
 
EntityGetAutoScrollEntity () const
 Retrieves the entity currently being tracked for autoscroll. More...
 
void ScriptScrollToPlayer (const SCROLL_TYPE type, const unsigned int seconds)
 Scrolls the background to the position of the playable character. More...
 
void ScriptScrollToPosition (const float x, const float y, const SCROLL_TYPE type, const float seconds)
 Scrolls the background to a position. More...
 
int ScriptScrollSync ()
 Waits for the scroll to complete. More...
 
void ScriptOffset (const float x, const float y)
 Offsets the background to a position. More...
 
void UnsetScroll ()
 Stops the current scrolling. More...
 
const Ogre::Vector2 & GetScrollPositionStart () const
 Retrieves the initial position of the current scroll action. More...
 
const Ogre::Vector2 & GetScrollPositionEnd () const
 Retrieves the final position of the current scroll action. More...
 
SCROLL_TYPE GetScrollType () const
 Retrieves the type of the current scroll action. More...
 
float GetScrollSeconds () const
 Retrieves the total duration the current scroll action. More...
 
void SetScrollCurrentSeconds (const float seconds)
 Sets the time taken by the current scroll action. More...
 
float GetScrollCurrentSeconds () const
 Retrieves the time taken by the current scroll action. More...
 
void SetScreenScroll (const Ogre::Vector2 &position)
 Scroll position in screen coordinates. More...
 
const Ogre::Vector2 GetScreenScroll () const
 Retrieves the scroll position in screen coordinates. More...
 
void SetScroll (const Ogre::Vector2 &position)
 Sets the scroll in game internal screen coordinates. More...
 
const Ogre::Vector2 & GetScroll () const
 Retrieves the scroll position in game internal screen coordinates. More...
 
void SetImage (const Ogre::String &image)
 Sets the background image. More...
 
void SetRange (const int min_x, const int min_y, const int max_x, const int max_y)
 Set the background scrolling range. More...
 
void SetRange (const Ogre::Vector4 &range)
 Set the background scrolling range. More...
 
void AddTile (const int x, const int y, const int width, const int height, const float depth, const float u1, const float v1, const float u2, const float v2, const Blending blending)
 Adds a tile to the background. More...
 
void AddTile (const Ogre::Vector2 &destination, const int width, const int height, const float depth, const Ogre::Vector4 &uv, const Blending blending)
 Adds a tile to the background. More...
 
void AddTile (const VGears::Tile &tile)
 Adds a tile to the background. More...
 
void UpdateTileUV (const unsigned int tile_id, const float u1, const float v1, const float u2, const float v2)
 Updates the UV vector of a tile. More...
 
void AddAnimation (Background2DAnimation *animation)
 Adds an animation to the background. More...
 
void PlayAnimation (const Ogre::String &animation, const Background2DAnimation::State state)
 Plays an animation. More...
 
void ScriptPlayAnimationLooped (const char *name)
 Plays an animation in a loop. More...
 
void ScriptPlayAnimationOnce (const char *name)
 Plays an animation once, then stops. More...
 
int ScriptAnimationSync (const char *name)
 Plays an animation once, then stops. More...
 
void renderQueueEnded (Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation) override
 Ends the render queue. More...
 
virtual void load (const VGears::Background2DFilePtr &background)
 Loads a background. More...
 

Protected Types

enum  { TILE_VERTEX_COUNT = 6 , TILE_VERTEX_INDEX_SIZE = TILE_VERTEX_COUNT + 3 }
 Tile vertex properties. More...
 

Protected Member Functions

virtual void load (const VGears::Background2DFile::TileList &tiles)
 Loads a tile list to the background. More...
 
virtual void load (const size_t tile_index, const VGears::AnimationMap &animations)
 Loads an animation list to the background. More...
 
virtual void applyScroll ()
 Apply the camera position to match the current scroll. More...
 
virtual void calculateScreenScale ()
 Calculates the screen scale. More...
 
virtual void virtualScreenToWorldSpace (Ogre::Vector2 &pos) const
 Sets the virtual screen to world space. More...
 

Private Member Functions

void CreateVertexBuffers ()
 Creates all vertex buffers. More...
 
void DestroyVertexBuffers ()
 Destroys all vertex buffers. More...
 

Private Attributes

Ogre::SceneManager * scene_manager_
 The scene manager. More...
 
Ogre::RenderSystem * render_system_
 The render system. More...
 
TileList tiles_
 The list of tiles in the background. More...
 
Ogre::RenderOperation alpha_render_op_
 Alpha blending render operation. More...
 
Ogre::HardwareVertexBufferSharedPtr alpha_vertex_buffer_
 Alpha blending vertex buffer. More...
 
unsigned int alpha_max_vertex_count_
 Alpha blending max vertex count. More...
 
Ogre::MaterialPtr alpha_material_
 Alpha blending material. More...
 
Ogre::RenderOperation add_render_op_
 Add blending render operation. More...
 
Ogre::HardwareVertexBufferSharedPtr add_vertex_buffer_
 Add blending vertex buffer. More...
 
unsigned int add_max_vertex_count_
 Add blending max vertex count. More...
 
Ogre::MaterialPtr add_material
 Add blending material. More...
 
Ogre::RenderOperation subtract_render_op_
 Substract blending render operation. More...
 
Ogre::HardwareVertexBufferSharedPtr subtract_vertex_buffer_
 Substract blending vertex buffer. More...
 
unsigned int subtract_max_vertex_count_
 Substract blending max vertex count. More...
 
Ogre::MaterialPtr subtract_material_
 Substract blending material. More...
 
Entityscroll_entity_
 The entity to keep track of with the scroll. More...
 
Ogre::Vector2 scroll_position_start_
 Starting position of the current scroll action. More...
 
Ogre::Vector2 scroll_position_end_
 Final position of the current scroll action. More...
 
SCROLL_TYPE scroll_type_
 Type of the current scroll action. More...
 
float scroll_seconds_
 Total duration of the current scroll action, in seconds. More...
 
float scroll_current_seconds_
 Secund the currens scroll action has taken so far. More...
 
std::vector< ScriptIdscroll_sync_
 
Ogre::Vector2 position_
 The current scroll position, virtual screen size. More...
 
Ogre::Vector2 offset_
 The current background offset, virtual screen size. More...
 
Ogre::Vector2 position_real_
 The current scroll position, viewport size. More...
 
Ogre::Real screen_scale_
 The scale of the screen. More...
 
Ogre::Vector2 screen_proportion_
 Screen aspect ration. More...
 
Ogre::Vector2 virtual_screen_size_
 The size of the virtual screen. More...
 
Ogre::AxisAlignedBox range_
 
std::vector< AnimationPlayedanimation_played_
 
std::vector< Background2DAnimation * > animations_
 List of animations. More...
 

Detailed Description

A field background.

Member Typedef Documentation

◆ Blending

◆ TileList

typedef std::vector<Tile> Background2D::TileList

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Tile vertex properties.

Enumerator
TILE_VERTEX_COUNT 

Tile vertex count.

Todo:
Understand and document.
TILE_VERTEX_INDEX_SIZE 

Tile vertex index size.

◆ SCROLL_TYPE

How to scroll the background.

Enumerator
NONE 

Don't scroll the background.

LINEAR 

Linearly scroll.

May seem unnatural in scripted sequences, but it's OK for character tracking.

SMOOTH 

Smooth (soft in, soft out) scroll.

Best for scripted sequences.

Constructor & Destructor Documentation

◆ Background2D()

Background2D::Background2D ( )

Constructor.

◆ ~Background2D()

Background2D::~Background2D ( )
virtual

Destructor.

Member Function Documentation

◆ AddAnimation()

void Background2D::AddAnimation ( Background2DAnimation animation)

Adds an animation to the background.

Parameters
[in]animationAnimation to add.

◆ AddTile() [1/3]

void Background2D::AddTile ( const int  x,
const int  y,
const int  width,
const int  height,
const float  depth,
const float  u1,
const float  v1,
const float  u2,
const float  v2,
const Blending  blending 
)

Adds a tile to the background.

Parameters
[in]xX coordinate for the tile.
[in]yY coordinate for the tile.
[in]widthTile width.
[in]heightTile height.
[in]depthDepth of the tile.
[in]u1
[in]v1
[in]u2
[in]v2
[in]blendingBlending mode for the tile
Todo:

Depth is z-index??

What are v1, v2, u1 and u2?

◆ AddTile() [2/3]

void Background2D::AddTile ( const Ogre::Vector2 &  destination,
const int  width,
const int  height,
const float  depth,
const Ogre::Vector4 &  uv,
const Blending  blending 
)

Adds a tile to the background.

Parameters
[in]destinationCoordinates for the tile.
[in]widthTile width.
[in]heightTile height.
[in]depthDepth of the tile.
[in]uv
[in]blendingBlending mode for the tile
Todo:

Depth is z-index??

What is uv?

◆ AddTile() [3/3]

void Background2D::AddTile ( const VGears::Tile tile)

Adds a tile to the background.

Parameters
[in]tileThe tile to add.

◆ applyScroll()

void Background2D::applyScroll ( )
protectedvirtual

Apply the camera position to match the current scroll.

◆ calculateScreenScale()

void Background2D::calculateScreenScale ( )
protectedvirtual

Calculates the screen scale.

The scale is calculated as the proportion between the viewport and the virtual screen.

◆ Clear()

void Background2D::Clear ( )

Removes the background and it's animations.

◆ CreateVertexBuffers()

void Background2D::CreateVertexBuffers ( )
private

Creates all vertex buffers.

◆ DestroyVertexBuffers()

void Background2D::DestroyVertexBuffers ( )
private

Destroys all vertex buffers.

◆ GetAutoScrollEntity()

Entity * Background2D::GetAutoScrollEntity ( ) const

Retrieves the entity currently being tracked for autoscroll.

Returns
The entity currently being tracked, or nullptr if the background is not currently scrolling to any entity.

◆ GetScreenScroll()

const Ogre::Vector2 Background2D::GetScreenScroll ( ) const

Retrieves the scroll position in screen coordinates.

Returns
Screen coordinates of the scroll.

◆ GetScroll()

const Ogre::Vector2 & Background2D::GetScroll ( ) const

Retrieves the scroll position in game internal screen coordinates.

Returns
Screen coordinates of the scroll.

◆ GetScrollCurrentSeconds()

float Background2D::GetScrollCurrentSeconds ( ) const

Retrieves the time taken by the current scroll action.

It represents the time the current scroll action has been going on for.

Returns
Time taken by the current scroll action.

◆ GetScrollPositionEnd()

const Ogre::Vector2 & Background2D::GetScrollPositionEnd ( ) const

Retrieves the final position of the current scroll action.

Returns
The final position of the current scroll action.

◆ GetScrollPositionStart()

const Ogre::Vector2 & Background2D::GetScrollPositionStart ( ) const

Retrieves the initial position of the current scroll action.

Returns
The initial position of the current scroll action.

◆ GetScrollSeconds()

float Background2D::GetScrollSeconds ( ) const

Retrieves the total duration the current scroll action.

Returns
Duration of the current scroll action.

◆ GetScrollType()

Background2D::SCROLL_TYPE Background2D::GetScrollType ( ) const

Retrieves the type of the current scroll action.

Returns
The type of the current scroll action.

◆ Hide()

void Background2D::Hide ( )

Hides the background.

Once called, the background will not be rendered until {

See also
Show()} is called. If the background is already hidden, it will do nothing.

◆ InputDebug()

void Background2D::InputDebug ( const VGears::Event event)
Todo:
Understand and document.
Parameters
[in]eventEvent.

◆ load() [1/3]

void Background2D::load ( const size_t  tile_index,
const VGears::AnimationMap animations 
)
protectedvirtual

Loads an animation list to the background.

Parameters
[in]tile_indexThe index of the tile.
[in]animationsList of animations to load.

◆ load() [2/3]

void Background2D::load ( const VGears::Background2DFile::TileList tiles)
protectedvirtual

Loads a tile list to the background.

Parameters
[in]tilesThe list of tiles to load.

◆ load() [3/3]

void Background2D::load ( const VGears::Background2DFilePtr background)
virtual

Loads a background.

Parameters
[in]backgroundThe background to load.

◆ OnResize()

void Background2D::OnResize ( )

Called on window resize.

Resizes the background, keeping the ratio.

◆ PlayAnimation()

void Background2D::PlayAnimation ( const Ogre::String &  animation,
const Background2DAnimation::State  state 
)

Plays an animation.

Parameters
[in]animationThe animation to play.
[in]stateAnimation state.

◆ renderQueueEnded()

void Background2D::renderQueueEnded ( Ogre::uint8  queueGroupId,
const Ogre::String &  invocation,
bool &  repeatThisInvocation 
)
override

Ends the render queue.

Parameters
[in]queueGroupIdThe group id of the queue to end.
[in]invocation
[in]repeatThisInvocationIndicates if the invocation must be repeated.
Todo:
Understand and document.

◆ ScriptAnimationSync()

int Background2D::ScriptAnimationSync ( const char *  name)

Plays an animation once, then stops.

The animation is played synchronously, and the thread is locked until it ends.

Parameters
[in]nameAnimation name.

◆ ScriptAutoScrollToEntity()

void Background2D::ScriptAutoScrollToEntity ( Entity entity)

Flags the background to automatically scroll to an entity position.

Parameters
[in]entityThe entity to track.

◆ ScriptOffset()

void Background2D::ScriptOffset ( const float  x,
const float  y 
)

Offsets the background to a position.

Parameters
[in]xX coordinate to scroll to.
[in]yY coordinate to scroll to.

◆ ScriptPlayAnimationLooped()

void Background2D::ScriptPlayAnimationLooped ( const char *  name)

Plays an animation in a loop.

The animation is played asynchronously.

Parameters
[in]nameAnimation name.

◆ ScriptPlayAnimationOnce()

void Background2D::ScriptPlayAnimationOnce ( const char *  name)

Plays an animation once, then stops.

The animation is played asynchronously.

Parameters
[in]nameAnimation name.

◆ ScriptScrollSync()

int Background2D::ScriptScrollSync ( )

Waits for the scroll to complete.

Returns
-1.

◆ ScriptScrollToPlayer()

void Background2D::ScriptScrollToPlayer ( const SCROLL_TYPE  type,
const unsigned int  seconds 
)

Scrolls the background to the position of the playable character.

Parameters
[in]typeScroll type.
[in]secondsScroll duration.

◆ ScriptScrollToPosition()

void Background2D::ScriptScrollToPosition ( const float  x,
const float  y,
const SCROLL_TYPE  type,
const float  seconds 
)

Scrolls the background to a position.

Parameters
[in]xX coordinate to scroll to.
[in]yY coordinate to scroll to.
[in]typeScroll type.
[in]secondsDuration of the scroll.

◆ SetImage()

void Background2D::SetImage ( const Ogre::String &  image)

Sets the background image.

Parameters
[in]imageImage name.

◆ SetRange() [1/2]

void Background2D::SetRange ( const int  min_x,
const int  min_y,
const int  max_x,
const int  max_y 
)

Set the background scrolling range.

The range is applied in game internal screen coordinates.

Parameters
[in]min_xMin scrollabe x coordinate.
[in]min_yMin scrollabe y coordinate.
[in]max_xMax scrollabe x coordinate.
[in]max_yMax scrollabe y coordinate.

◆ SetRange() [2/2]

void Background2D::SetRange ( const Ogre::Vector4 &  range)

Set the background scrolling range.

The range is applied in game internal screen coordinates.

Parameters
[in]rangeRange bounds vector.

◆ SetScreenScroll()

void Background2D::SetScreenScroll ( const Ogre::Vector2 &  position)

Scroll position in screen coordinates.

Parameters
[in]positionPosition to set the scroll.

◆ SetScroll()

void Background2D::SetScroll ( const Ogre::Vector2 &  position)

Sets the scroll in game internal screen coordinates.

Parameters
[in]positionPosition to set the scroll.

◆ SetScrollCurrentSeconds()

void Background2D::SetScrollCurrentSeconds ( const float  seconds)

Sets the time taken by the current scroll action.

It represents the time the current scroll action has been going on for.

Parameters
[in]secondsTime taken by the current scroll action.

◆ Show()

void Background2D::Show ( )

Shows the background.

Once called, the background will start rendered until {

See also
Hide()} is called.

◆ UnsetScroll()

void Background2D::UnsetScroll ( )

Stops the current scrolling.

◆ Update()

void Background2D::Update ( )

Run each frame.

Updates animations and changes in the background.

◆ UpdateDebug()

void Background2D::UpdateDebug ( )

Debug inormation about changes in the background.

◆ UpdateTileUV()

void Background2D::UpdateTileUV ( const unsigned int  tile_id,
const float  u1,
const float  v1,
const float  u2,
const float  v2 
)

Updates the UV vector of a tile.

Parameters
[in]tile_idID of the tile to update.
[in]u1
[in]v1
[in]u2
[in]v2
Todo:
What are v1, v2, u1 and u2?

◆ virtualScreenToWorldSpace()

void Background2D::virtualScreenToWorldSpace ( Ogre::Vector2 &  pos) const
protectedvirtual

Sets the virtual screen to world space.

Parameters
[in]pos
Todo:
Understand and document.

Member Data Documentation

◆ add_material

Ogre::MaterialPtr Background2D::add_material
private

Add blending material.

◆ add_max_vertex_count_

unsigned int Background2D::add_max_vertex_count_
private

Add blending max vertex count.

◆ add_render_op_

Ogre::RenderOperation Background2D::add_render_op_
private

Add blending render operation.

◆ add_vertex_buffer_

Ogre::HardwareVertexBufferSharedPtr Background2D::add_vertex_buffer_
private

Add blending vertex buffer.

◆ alpha_material_

Ogre::MaterialPtr Background2D::alpha_material_
private

Alpha blending material.

◆ alpha_max_vertex_count_

unsigned int Background2D::alpha_max_vertex_count_
private

Alpha blending max vertex count.

◆ alpha_render_op_

Ogre::RenderOperation Background2D::alpha_render_op_
private

Alpha blending render operation.

◆ alpha_vertex_buffer_

Ogre::HardwareVertexBufferSharedPtr Background2D::alpha_vertex_buffer_
private

Alpha blending vertex buffer.

◆ animation_played_

std::vector<AnimationPlayed> Background2D::animation_played_
private
Todo:
Document.

◆ animations_

std::vector<Background2DAnimation*> Background2D::animations_
private

List of animations.

◆ offset_

Ogre::Vector2 Background2D::offset_
private

The current background offset, virtual screen size.

◆ position_

Ogre::Vector2 Background2D::position_
private

The current scroll position, virtual screen size.

◆ position_real_

Ogre::Vector2 Background2D::position_real_
private

The current scroll position, viewport size.

Includes the offset.

◆ range_

Ogre::AxisAlignedBox Background2D::range_
private
Todo:
Document.

◆ render_system_

Ogre::RenderSystem* Background2D::render_system_
private

The render system.

◆ scene_manager_

Ogre::SceneManager* Background2D::scene_manager_
private

The scene manager.

◆ screen_proportion_

Ogre::Vector2 Background2D::screen_proportion_
private

Screen aspect ration.

◆ screen_scale_

Ogre::Real Background2D::screen_scale_
private

The scale of the screen.

◆ scroll_current_seconds_

float Background2D::scroll_current_seconds_
private

Secund the currens scroll action has taken so far.

◆ scroll_entity_

Entity* Background2D::scroll_entity_
private

The entity to keep track of with the scroll.

◆ scroll_position_end_

Ogre::Vector2 Background2D::scroll_position_end_
private

Final position of the current scroll action.

◆ scroll_position_start_

Ogre::Vector2 Background2D::scroll_position_start_
private

Starting position of the current scroll action.

◆ scroll_seconds_

float Background2D::scroll_seconds_
private

Total duration of the current scroll action, in seconds.

◆ scroll_sync_

std::vector<ScriptId> Background2D::scroll_sync_
private
Todo:
Document.

◆ scroll_type_

SCROLL_TYPE Background2D::scroll_type_
private

Type of the current scroll action.

◆ subtract_material_

Ogre::MaterialPtr Background2D::subtract_material_
private

Substract blending material.

◆ subtract_max_vertex_count_

unsigned int Background2D::subtract_max_vertex_count_
private

Substract blending max vertex count.

◆ subtract_render_op_

Ogre::RenderOperation Background2D::subtract_render_op_
private

Substract blending render operation.

◆ subtract_vertex_buffer_

Ogre::HardwareVertexBufferSharedPtr Background2D::subtract_vertex_buffer_
private

Substract blending vertex buffer.

◆ tiles_

TileList Background2D::tiles_
private

The list of tiles in the background.

◆ virtual_screen_size_

Ogre::Vector2 Background2D::virtual_screen_size_
private

The size of the virtual screen.


The documentation for this class was generated from the following files: