CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Application.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Engine.hpp"
11
13
16
17#include <lyra/lyra.hpp>
18
19namespace CeresEngine {
20
21 using CommandLineInterface = lyra::cli;
22 using CommandLineArguments = lyra::args;
23 using CommandLineOption = lyra::opt;
24
27 class Application : public Engine {
28 public:
31
32 private:
35 bool mShouldExitProgram [[maybe_unused]] = false;
36
40
41 public:
45 explicit Application(const Vector<StringView>& arguments = {});
46
50 explicit Application(const char* argv[], int argc);
51
53 ~Application() override;
54
55 public:
57 virtual bool prepareStartUp();
58
60 virtual void startUp();
61
63 virtual void shutDown();
64
66 virtual void update();
67
71
72 protected:
77
78 public:
83 [[nodiscard]] CE_SCRIPT_EXPORT()
84 int run();
85
86 public:
88 [[nodiscard]] CE_SCRIPT_EXPORT(property = "getter", name = "shared")
89 static Application& shared() noexcept;
90 };
91
93 template<typename T> class TApplication {
94 private:
97
98 public:
100 template<typename... Args> explicit TApplication(Args&&... args) : mApplication(std::forward<Args>(args)...) {}
101
103 ~TApplication() { mApplication.shutDown(); }
104
105 public:
108 int run() {
109 if(!mApplication.prepareStartUp()) {
110 return 0;
111 }
112 mApplication.startUp();
113 return mApplication.run();
114 }
115 };
116
119
120} // namespace CeresEngine
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A base class to be used by all engine applications.
Definition Application.hpp:27
int run()
Runs the engine main loop.
virtual void startUp()
A method called to perform the application for start-up.
virtual bool prepareStartUp()
A method called to prepare the application for start-up.
virtual void update()
A method called by the application on every update loop.
SteadyClockDate mLastRenderTime
The last time a frame was rendered by the engine.
Definition Application.hpp:39
static Application & shared() noexcept
virtual void shutDown()
A method called to perform the application for shutdown.
const Vector< StringView > arguments
The argument given to the application command line.
Definition Application.hpp:30
~Application() override
Destroys the application instance.
bool mShouldExitProgram
A flag set by Window::didClose to indicate that the engine's main loop should exit when the window ge...
Definition Application.hpp:35
virtual void createCommandLineParser(CommandLineInterface &cli)
A method called by the engine whenever it is creating the command line parser.
void updateFromPlatform()
A temporary function that must be invoked by the platform on every update tick.
Application(const char *argv[], int argc)
Creates a new application instance.
Definition Engine.hpp:38
A template class that helps initializing an application.
Definition Application.hpp:93
int run()
A method called to perform the application for start-up.
Definition Application.hpp:108
T mApplication
The application instance.
Definition Application.hpp:96
~TApplication()
A method called to perform the application for shutdown.
Definition Application.hpp:103
TApplication(Args &&... args)
Creates a new application instance.
Definition Application.hpp:100
Definition Application.hpp:19
TDate< SteadyClock, TimeInterval > SteadyClockDate
Represents a point in time.
Definition Chrono.hpp:86
lyra::args CommandLineArguments
Definition Application.hpp:22
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
Application & gApplication() noexcept
lyra::opt CommandLineOption
Definition Application.hpp:23
lyra::cli CommandLineInterface
Definition Application.hpp:21
Definition Span.hpp:668