V-Gears 0
Free Final Fantasy VII engine.
Background2D.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
18#include <OgreHardwareVertexBuffer.h>
19#include <OgreRenderQueueListener.h>
20#include <OgreRoot.h>
23#include "Entity.h"
24#include "ScriptManager.h"
25
29class Background2D : public Ogre::RenderQueueListener{
30
31 public:
32
34
39
44
57 SMOOTH
58 };
59
64
68 virtual ~Background2D();
69
74 void InputDebug(const VGears::Event& event);
75
82 void Hide();
83
89 void Show();
90
96 void Update();
97
101 void UpdateDebug();
102
108 void OnResize();
109
113 void Clear();
114
120 void ScriptAutoScrollToEntity(Entity* entity);
121
129
136 void ScriptScrollToPlayer(const SCROLL_TYPE type, const unsigned int seconds);
137
147 const float x, const float y, const SCROLL_TYPE type, const float seconds
148 );
149
155 int ScriptScrollSync();
156
163 void ScriptOffset(const float x, const float y);
164
168 void UnsetScroll();
169
175 const Ogre::Vector2& GetScrollPositionStart() const;
176
182 const Ogre::Vector2& GetScrollPositionEnd() const;
183
190
196 float GetScrollSeconds() const;
197
205 void SetScrollCurrentSeconds(const float seconds);
206
214 float GetScrollCurrentSeconds() const;
215
221 void SetScreenScroll(const Ogre::Vector2& position);
222
228 const Ogre::Vector2 GetScreenScroll() const;
229
235 void SetScroll(const Ogre::Vector2& position);
236
242 const Ogre::Vector2& GetScroll() const;
243
249 void SetImage( const Ogre::String& image );
250
261 void SetRange(const int min_x, const int min_y, const int max_x, const int max_y);
262
270 void SetRange(const Ogre::Vector4& range);
271
288 void AddTile(
289 const int x, const int y, const int width, const int height, const float depth,
290 const float u1, const float v1, const float u2, const float v2, const Blending blending
291 );
292
305 void AddTile(
306 const Ogre::Vector2& destination, const int width, const int height,
307 const float depth, const Ogre::Vector4& uv, const Blending blending
308 );
309
315 void AddTile(const VGears::Tile& tile);
316
327 void UpdateTileUV(
328 const unsigned int tile_id, const float u1, const float v1, const float u2, const float v2
329 );
330
336 void AddAnimation(Background2DAnimation* animation);
337
344 void PlayAnimation(const Ogre::String& animation, const Background2DAnimation::State state);
345
353 void ScriptPlayAnimationLooped(const char* name);
354
362 void ScriptPlayAnimationOnce(const char* name);
363
372 int ScriptAnimationSync(const char* name);
373
382 void renderQueueEnded(
383 Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation
384 ) override;
385
389 struct Tile{
390
394 int x;
395
399 int y;
400
404 int width;
405
410
415
420 };
421
422 typedef std::vector<Tile> TileList;
423
429 virtual void load(const VGears::Background2DFilePtr &background);
430
431 protected:
432
438 virtual void load(const VGears::Background2DFile::TileList &tiles);
439
446 virtual void load( const size_t tile_index, const VGears::AnimationMap &animations);
447
451 virtual void applyScroll();
452
459 virtual void calculateScreenScale();
460
461
468 virtual void virtualScreenToWorldSpace(Ogre::Vector2 &pos) const;
469
473 enum{
474
481
486 };
487
488 private:
489
493 void CreateVertexBuffers();
494
499
503 Ogre::SceneManager* scene_manager_;
504
508 Ogre::RenderSystem* render_system_;
509
514
518 Ogre::RenderOperation alpha_render_op_;
519
523 Ogre::HardwareVertexBufferSharedPtr alpha_vertex_buffer_;
524
529
533 Ogre::MaterialPtr alpha_material_;
534
538 Ogre::RenderOperation add_render_op_;
539
543 Ogre::HardwareVertexBufferSharedPtr add_vertex_buffer_;
544
549
553 Ogre::MaterialPtr add_material;
554
558 Ogre::RenderOperation subtract_render_op_;
559
563 Ogre::HardwareVertexBufferSharedPtr subtract_vertex_buffer_;
564
569
573 Ogre::MaterialPtr subtract_material_;
574
579
584
588 Ogre::Vector2 scroll_position_end_;
589
594
599
604
608 std::vector<ScriptId> scroll_sync_;
609
613 Ogre::Vector2 position_;
614
618 Ogre::Vector2 offset_;
619
625 Ogre::Vector2 position_real_;
626
630 Ogre::Real screen_scale_;
631
635 Ogre::Vector2 screen_proportion_;
636
640 Ogre::Vector2 virtual_screen_size_;
641
645 Ogre::AxisAlignedBox range_;
646
651
656
660 std::vector<ScriptId> sync;
661
666 };
667
671 std::vector<AnimationPlayed> animation_played_;
672
676 std::vector<Background2DAnimation*> animations_;
677};
float * position
Used to keep track of the skeleton and it's bones positions.
Definition: DrawSkeleton.cpp:33
An animation in the background of a field.
Definition: Background2DAnimation.h:28
State
Repetition status of the animation.
Definition: Background2DAnimation.h:52
A field background.
Definition: Background2D.h:29
Ogre::MaterialPtr add_material
Add blending material.
Definition: Background2D.h:553
Ogre::AxisAlignedBox range_
Definition: Background2D.h:645
void Hide()
Hides the background.
Definition: Background2D.cpp:117
const Ogre::Vector2 & GetScrollPositionEnd() const
Retrieves the final position of the current scroll action.
Definition: Background2D.cpp:332
void DestroyVertexBuffers()
Destroys all vertex buffers.
Definition: Background2D.cpp:737
int ScriptAnimationSync(const char *name)
Plays an animation once, then stops.
Definition: Background2D.cpp:633
void InputDebug(const VGears::Event &event)
Definition: Background2D.cpp:107
SCROLL_TYPE GetScrollType() const
Retrieves the type of the current scroll action.
Definition: Background2D.cpp:334
unsigned int alpha_max_vertex_count_
Alpha blending max vertex count.
Definition: Background2D.h:528
float GetScrollCurrentSeconds() const
Retrieves the time taken by the current scroll action.
Definition: Background2D.cpp:340
Ogre::HardwareVertexBufferSharedPtr alpha_vertex_buffer_
Alpha blending vertex buffer.
Definition: Background2D.h:523
void AddAnimation(Background2DAnimation *animation)
Adds an animation to the background.
Definition: Background2D.cpp:598
float scroll_current_seconds_
Secund the currens scroll action has taken so far.
Definition: Background2D.h:603
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.
Definition: Background2D.cpp:563
void ScriptScrollToPosition(const float x, const float y, const SCROLL_TYPE type, const float seconds)
Scrolls the background to a position.
Definition: Background2D.cpp:282
std::vector< Tile > TileList
Definition: Background2D.h:422
void OnResize()
Called on window resize.
Definition: Background2D.cpp:188
Background2D()
Constructor.
Definition: Background2D.cpp:34
unsigned int add_max_vertex_count_
Add blending max vertex count.
Definition: Background2D.h:548
Entity * GetAutoScrollEntity() const
Retrieves the entity currently being tracked for autoscroll.
Definition: Background2D.cpp:267
Ogre::HardwareVertexBufferSharedPtr subtract_vertex_buffer_
Substract blending vertex buffer.
Definition: Background2D.h:563
void ScriptOffset(const float x, const float y)
Offsets the background to a position.
Definition: Background2D.cpp:312
void ScriptScrollToPlayer(const SCROLL_TYPE type, const unsigned int seconds)
Scrolls the background to the position of the playable character.
Definition: Background2D.cpp:269
const Ogre::Vector2 & GetScrollPositionStart() const
Retrieves the initial position of the current scroll action.
Definition: Background2D.cpp:330
Entity * scroll_entity_
The entity to keep track of with the scroll.
Definition: Background2D.h:578
void Update()
Run each frame.
Definition: Background2D.cpp:121
void Clear()
Removes the background and it's animations.
Definition: Background2D.cpp:243
virtual ~Background2D()
Destructor.
Definition: Background2D.cpp:101
Ogre::SceneManager * scene_manager_
The scene manager.
Definition: Background2D.h:503
Ogre::Vector2 position_
The current scroll position, virtual screen size.
Definition: Background2D.h:613
void SetScrollCurrentSeconds(const float seconds)
Sets the time taken by the current scroll action.
Definition: Background2D.cpp:338
Ogre::MaterialPtr subtract_material_
Substract blending material.
Definition: Background2D.h:573
std::vector< Background2DAnimation * > animations_
List of animations.
Definition: Background2D.h:676
Ogre::RenderOperation subtract_render_op_
Substract blending render operation.
Definition: Background2D.h:558
void SetScreenScroll(const Ogre::Vector2 &position)
Scroll position in screen coordinates.
Definition: Background2D.cpp:342
Ogre::Vector2 scroll_position_end_
Final position of the current scroll action.
Definition: Background2D.h:588
std::vector< AnimationPlayed > animation_played_
Definition: Background2D.h:671
Ogre::Vector2 virtual_screen_size_
The size of the virtual screen.
Definition: Background2D.h:640
const Ogre::Vector2 & GetScroll() const
Retrieves the scroll position in game internal screen coordinates.
Definition: Background2D.cpp:369
void CreateVertexBuffers()
Creates all vertex buffers.
Definition: Background2D.cpp:683
Ogre::RenderSystem * render_system_
The render system.
Definition: Background2D.h:508
void ScriptPlayAnimationOnce(const char *name)
Plays an animation once, then stops.
Definition: Background2D.cpp:629
virtual void calculateScreenScale()
Calculates the screen scale.
Definition: Background2D.cpp:177
void UpdateDebug()
Debug inormation about changes in the background.
Definition: Background2D.cpp:160
int ScriptScrollSync()
Waits for the scroll to complete.
Definition: Background2D.cpp:302
Ogre::Vector2 screen_proportion_
Screen aspect ration.
Definition: Background2D.h:635
SCROLL_TYPE
How to scroll the background.
Definition: Background2D.h:38
@ SMOOTH
Smooth (soft in, soft out) scroll.
Definition: Background2D.h:57
@ LINEAR
Linearly scroll.
Definition: Background2D.h:51
@ NONE
Don't scroll the background.
Definition: Background2D.h:43
SCROLL_TYPE scroll_type_
Type of the current scroll action.
Definition: Background2D.h:593
void PlayAnimation(const Ogre::String &animation, const Background2DAnimation::State state)
Plays an animation.
Definition: Background2D.cpp:600
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.
Definition: Background2D.cpp:438
Ogre::Vector2 offset_
The current background offset, virtual screen size.
Definition: Background2D.h:618
virtual void load(const VGears::Background2DFilePtr &background)
Loads a background.
Definition: Background2D.cpp:752
Ogre::MaterialPtr alpha_material_
Alpha blending material.
Definition: Background2D.h:533
void SetImage(const Ogre::String &image)
Sets the background image.
Definition: Background2D.cpp:373
void Show()
Shows the background.
Definition: Background2D.cpp:119
virtual void applyScroll()
Apply the camera position to match the current scroll.
Definition: Background2D.cpp:360
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation) override
Ends the render queue.
Definition: Background2D.cpp:644
unsigned int subtract_max_vertex_count_
Substract blending max vertex count.
Definition: Background2D.h:568
void ScriptPlayAnimationLooped(const char *name)
Plays an animation in a loop.
Definition: Background2D.cpp:624
@ TILE_VERTEX_INDEX_SIZE
Tile vertex index size.
Definition: Background2D.h:485
@ TILE_VERTEX_COUNT
Tile vertex count.
Definition: Background2D.h:480
virtual void virtualScreenToWorldSpace(Ogre::Vector2 &pos) const
Sets the virtual screen to world space.
Definition: Background2D.cpp:431
Ogre::RenderOperation alpha_render_op_
Alpha blending render operation.
Definition: Background2D.h:518
VGears::Blending Blending
Definition: Background2D.h:33
Ogre::Vector2 position_real_
The current scroll position, viewport size.
Definition: Background2D.h:625
const Ogre::Vector2 GetScreenScroll() const
Retrieves the scroll position in screen coordinates.
Definition: Background2D.cpp:371
void ScriptAutoScrollToEntity(Entity *entity)
Flags the background to automatically scroll to an entity position.
Definition: Background2D.cpp:265
TileList tiles_
The list of tiles in the background.
Definition: Background2D.h:513
std::vector< ScriptId > scroll_sync_
Definition: Background2D.h:608
Ogre::RenderOperation add_render_op_
Add blending render operation.
Definition: Background2D.h:538
Ogre::HardwareVertexBufferSharedPtr add_vertex_buffer_
Add blending vertex buffer.
Definition: Background2D.h:543
float scroll_seconds_
Total duration of the current scroll action, in seconds.
Definition: Background2D.h:598
void SetScroll(const Ogre::Vector2 &position)
Sets the scroll in game internal screen coordinates.
Definition: Background2D.cpp:346
void UnsetScroll()
Stops the current scrolling.
Definition: Background2D.cpp:323
void SetRange(const int min_x, const int min_y, const int max_x, const int max_y)
Set the background scrolling range.
Definition: Background2D.cpp:390
Ogre::Vector2 scroll_position_start_
Starting position of the current scroll action.
Definition: Background2D.h:583
Ogre::Real screen_scale_
The scale of the screen.
Definition: Background2D.h:630
float GetScrollSeconds() const
Retrieves the total duration the current scroll action.
Definition: Background2D.cpp:336
Any entity in a field.
Definition: Entity.h:101
std::vector< Tile > TileList
Definition: VGearsBackground2DFile.h:63
Ogre::SharedPtr< Background2DFile > Background2DFilePtr
Definition: VGearsBackground2DFile.h:217
std::map< String, Animation > AnimationMap
Definition: VGearsTile.h:77
Ogre::String String
Definition: TypeDefine.h:37
Blending
Definition: VGearsTile.h:23
unsigned char uint8
Definition: scummsys.h:431
State of an animation.
Definition: Background2D.h:650
Ogre::String name
Animation name.
Definition: Background2D.h:655
std::vector< ScriptId > sync
Definition: Background2D.h:660
Background2DAnimation::State state
Animation state.
Definition: Background2D.h:665
Represents a tile.
Definition: Background2D.h:389
size_t start_vertex_index
Definition: Background2D.h:414
int height
Tile height.
Definition: Background2D.h:409
int x
Tile X coordinate.
Definition: Background2D.h:394
Blending blending
Tile blending mode.
Definition: Background2D.h:419
int y
Tile Y coordinate.
Definition: Background2D.h:399
int width
Tile width.
Definition: Background2D.h:404
An input event.
Definition: Event.h:84
A tile.
Definition: VGearsTile.h:82