21 #include "hx3d/window/game.hpp" 23 #include "hx3d/core/core.hpp" 24 #include "hx3d/window/application.hpp" 26 #include "hx3d/utils/log.hpp" 27 #include "hx3d/utils/timer_manager.hpp" 28 #include "hx3d/tweens/tween_manager.hpp" 29 #include "hx3d/window/event_manager.hpp" 35 _running(true), _screen(nullptr), _showStats(false)
38 _deltaText.transform.position.y = 100;
39 _deltaText.transform.position.z = 0.95f;
40 _deltaText.setCharacterSize(20);
43 _fpsText.transform.position.y = _deltaText.transform.position.y + _deltaText.getCharacterSize();
44 _fpsText.transform.position.z = 0.95f;
45 _fpsText.setCharacterSize(20);
47 _batch.setCamera(_camera);
68 _currentTransition = transition;
73 auto world_size = viewport->getWorldSize();
74 _currentFB.resize(world_size.x, world_size.y);
75 _nextFB.resize(world_size.x, world_size.y);
78 _currentViewport = viewport;
79 _currentViewport->apply(_camera);
85 return _currentViewport;
90 return _currentViewport->getWorldSize();
95 void Game::updateStats() {
96 _deltaText.transform.position.x = this->getSize().x / 2;
97 _deltaText.transform.position.y = 100;
98 _deltaText.transform.position.z = 0.95f;
99 _deltaText.setCharacterSize(20);
101 _fpsText.transform.position.x = this->getSize().x / 2;
102 _fpsText.transform.position.y = _deltaText.transform.position.y + _deltaText.getCharacterSize();
103 _fpsText.transform.position.z = 0.95f;
104 _fpsText.setCharacterSize(20);
116 if (_currentTransition) {
117 if (_currentTransition->isFinished()) {
120 _screen = _nextScreen;
122 _currentTransition->reset();
123 _nextScreen =
nullptr;
135 _nextScreen->render();
138 if (_currentViewport) _currentViewport->apply(_camera);
139 _currentTransition->render(_batch, _currentFB, _nextFB);
145 _screen = _nextScreen;
147 _nextScreen =
nullptr;
155 _batch.draw(_deltaText);
156 _batch.draw(_fpsText);
168 _screen->update(delta);
172 if (_currentTransition) {
173 if (_currentTransition->isRunning()) {
174 _currentTransition->update(delta);
180 _deltaText.setContent(
format(
"D: %2.0f", delta * 1000.f));
181 _fpsText.setContent(
format(
"FPS: %2.0f", 1/delta));
187 _screen->resize(width, height);
206 screen->resize(size.x, size.y);
211 _nextScreen = screen;
213 _nextScreen->pause();
215 if (_currentTransition) {
216 _currentTransition->start();
223 _showStats = enabled;
virtual void resume()
Resume the current screen.
virtual void update(float delta)
Update the current screen.
std::string format(const std::string fmt,...)
Format a string using printf notation.
virtual void render()
Render the current scren.
static window::Application * App()
Get the application instance.
virtual void dispose()
Clean the current screen.
glm::vec2 getSize()
Get the current game size.
virtual void stop()
Stop the game.
glm::ivec2 getSize()
Get the window size (ivec2)
bool isRunning()
Test if the game is running.
Map of whatever you want. Useful for user data.
virtual void pause()
Pause the current screen.
void setScreen(Ptr< Screen > screen)
Set the current screen.
void setTransition(const Ptr< graphics::Transition > &transition)
Set the current transition.
const Ptr< graphics::viewports::Viewport > & getViewport()
Get the current viewport.
void setInputHandler(InputHandler *handler)
Define an input handler.
virtual void create()
Initialize the game.
void setViewport(const Ptr< graphics::viewports::Viewport > &viewport)
Set the current viewport.
static Color Black
Black color.
static window::EventManager * Events()
Get the event manager.
virtual void resize(int width, int height)
Resize the current screen.
void activateStats(bool enabled)
Activate the stats.
static void useDefault()
Use the default framebuffer.
ObjectMap & getSession()
Get the session.
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
static void use(Framebuffer &buf)
Use the framebuffer as current framebuffer.
static void clear(Color color)
Clear the framebuffer.
int getWidth()
Get the window width.