26 #include "utils/ContactListener.h"
27 #include "utils/DestructionListener.h"
198 Q_INVOKABLE
bool isPaused()
const {
return mPausedRefCount != 0; }
303 const QString& label,
long value);
328 template <
typename T>
329 void forEach(
const std::function<
void(T*)>& func)
const {
333 if (!mValidCacheSet.
contains(&T::staticMetaObject)) {
335 createItemCache(
getRoot(), &sItemCache);
336 mValidCacheSet.
insert(&T::staticMetaObject);
339 for (T* t : sItemCache) {
352 template <
typename T>
376 template <
typename T>
378 T* t = qobject_cast<T*>(root);
496 void levelChanged(
const QString& levelName,
int completionThreshold,
int activationThreshold);
572 void onBeforeSynchronizing();
573 void onBeforeRendering();
574 void onAfterRendering();
575 void onLoadCompleted(
bool success);
590 void setCurrentLevel(
Level* level);
595 void queueWorldForDeletion(b2World* world);
598 void performLevelChange();
599 void setPhase(
Phase phase);
601 template <
typename T>
603 T* t = qobject_cast<T*>(item);
608 createItemCache(child, itemCache);
620 void synchronizeForRendering();
622 bool mIsInitialized =
false;
624 int mPausedRefCount = 1;
625 long long mWorldStepCount = 0;
627 Camera* mCamera =
nullptr;
630 bool mLevelReady =
false;
631 Level* mLevel =
nullptr;
632 bool mHasNextLevel =
false;
633 int mSyncsSinceNextLevelRequest = 0;
636 volatile bool mViewerReady =
false;
637 std::unique_ptr<QQuickView> mViewer;
638 std::unique_ptr<ContactListener> mContactListener;
639 std::unique_ptr<DestructionListener> mDestructionListener;
640 std::unique_ptr<Renderer> mRenderer;
641 std::unique_ptr<RenderList> mRenderList;
642 std::unique_ptr<TextureManager> mTextureManager;
643 std::unique_ptr<TerrainMaterials> mTerrainMaterials;
644 std::unique_ptr<LiquidFunDebugDraw> mDebugDraw;
645 std::unique_ptr<SoundManager> mSoundManager;
647 std::unique_ptr<b2World> mWorldToDelete;
653 Q_DECLARE_METATYPE(
Engine*)
Implementation of b2Draw which renders objects (body fixtures, particles, etc.) using DebugRenderer...
Definition: LiquidFunDebugDraw.h:35
b2World * getWorld() const
Returns the Box2D world object.
void onDevicePause()
Respond to Android onPause().
static const int PARTICLE_ITERATIONS
LiquidFun particle solve iterations, controlling world substepping.
Definition: Engine.h:174
void resume()
Respond to game resume.
ContactListener * getContactListener() const
Returns ContactListener, the Engine's implementation of the b2ContactListener.
Definition: Engine.h:250
Engine is executing the Body::updateBeforePhysics() calls.
Definition: Engine.h:110
static const float TIME_STEP_S
The fixed simulation time step between frames, in seconds.
Definition: Engine.h:154
void deviceStart()
Emitted at end of onDeviceStart().
Class managing GL state switches and draw calls.
Definition: Renderer.h:50
void deviceDestroy()
Signal for when the device has reached the end of its application lifecycle.
void push_back(const T &value)
void cloudDataLoaded(int statusCode, const QString &data)
Emitted when the cloud data is loaded.
Class which loads and caches Textures.
Definition: TextureManager.h:37
Q_INVOKABLE Level * getLevel() const
Returns the current Level being displayed and executed.
Definition: Engine.h:269
Q_INVOKABLE SoundManager * getSoundManager() const
Returns the SoundManager object.
Definition: Engine.h:234
const QObjectList & children() const
static Engine * getInstance(bool createIfNecessary=true)
Returns the global singleton instance of Engine.
Engine is adjusting the camera relative to the state of the world.
Definition: Engine.h:137
Phase getPhase() const
Return the phase of execution.
Definition: Engine.h:257
bool isInitialized() const
Returns true if the Engine has been initialized.
Definition: Engine.h:192
iterator insert(const T &value)
void onDeviceResume()
Respond to Android onResume().
The singleton object responsible for game execution.
Definition: Engine.h:84
void invalidateSceneGraphObjectCaches()
Invalidates the caches of all scene graph objects, regardless of type.
Definition: Engine.h:360
TextureManager * getTextureManager() const
Returns the TextureManager object.
Definition: Engine.h:239
TerrainMaterials * getTerrainMaterials() const
Returns the TerrainMaterials object.
Definition: Engine.h:244
void invalidateSceneGraphObjectCache()
Invalidates the cache of scene graph objects of the specified type.
Definition: Engine.h:353
Metadata for a Level.
Definition: LevelInfo.h:31
void loadLevel(LevelInfo *levelInfo)
Emits the signal to load level/start game.
Controls the sound effects and background music (BGM) audio tracks needed to be played during the gam...
Definition: SoundManager.h:39
long long getWorldStepCount() const
Returns the number of physics steps since last level loaded.
Definition: Engine.h:208
void onDeviceStop()
Respond to Android onStop().
void onSignedIntoCloudChanged(bool signedIntoCloud)
Respond to state of cloud sign-in changed.
void pause()
Respond to game pause.
void onOpeningCinematicCompleted(const QString &menuBGMTrack)
Respond to opening cinematic finishing.
void beforeUpdate()
Emitted at the start of the update() call.
void addChildItem(QQuickItem *item)
Add a child item to the QQuickItem scene graph.
void forEach(QObject *root, const std::function< void(T *)> &func) const
Recursively traverses scene graph and call func on each QObject of type T, starting at the given root...
Definition: Engine.h:377
Camera * getCamera() const
Returns the Camera object.
Definition: Engine.h:224
void signedIntoCloudChanged(bool signedIntoCloud)
Emitted when cloud sign-in has changed.
Q_INVOKABLE void setTrackerScreenName(const QString &screenName, bool sendScreenView=true)
Sets the Google Analytics screen name and optionally sends a screen view hit.
void deviceStop()
Emitted at end of onDeviceStop().
void levelChanged(const QString &levelName, int completionThreshold, int activationThreshold)
Emitted when a new level is finished loading a level.
Representation of an in-game level.
Definition: Level.h:48
QQuickItem * getRoot() const
Returns the root item, as defined in the main QML file.
void onCloudDataLoaded(int statusCode, const QString &data)
Respond to cloud data being loaded.
Engine is rendering.
Definition: Engine.h:143
Q_INVOKABLE void sendTrackerEvent(const QString &category, const QString &action)
Sends an event hit to Google Analytics.
bool contains(const T &value) const
void onQuitRequested()
Respond to quit request.
void onPlayLevelRequested()
Respond to request to play the current level.
Renderer * getRenderer() const
Returns the Renderer object, the game-specific renderer.
Definition: Engine.h:229
bool remove(const T &value)
static const int VELOCITY_ITERATIONS
LiquidFun velocity iterations, controlling world substepping.
Definition: Engine.h:164
Engine is executing the Logic::update() calls.
Definition: Engine.h:101
void deviceResume()
Emitted at end of onDeviceResume().
File containing forward declarations for renderer types and smart pointers.
void onDeviceStart()
Respond to Android onStart().
void init()
Initialize the Engine.
void devicePause()
Emitted at end of onDevicePause().
static const float TIME_STEP_MS
The fixed simulation time step between frames, in milliseconds.
Definition: Engine.h:159
void deviceCreate()
Emitted at end of onDeviceCreate().
Grouping of related LevelInfos together into an logical, ordered list.
Definition: Environment.h:37
QQuickItem which represents the Camera into the game world.
Definition: Camera.h:42
void deleteCurrentLevel()
Mark the current level for deletion and remove it from the scene graph to avoid continuing rendering ...
QQmlEngine * getQmlEngine() const
Returns the QQmlEngine being used by the Engine.
void onDeviceCreate()
Respond to Android onCreate().
Q_INVOKABLE bool isPaused() const
Returns true if engine is paused, e.g. when the in-game menu is open.
Definition: Engine.h:198
Engine is executing the Body::updateAfterPhysics() calls.
Definition: Engine.h:126
Engine is executing the Box2D/LiquidFun physics.
Definition: Engine.h:117
static const float UPDATE_FREQUENCY
The target frame rate.
Definition: Engine.h:149
void forEach(const std::function< void(T *)> &func) const
Recursively traverses scene graph and call func on each QObject of type T.
Definition: Engine.h:329
void onDeviceDestroy()
Respond to Android onDestroy().
Phase
The phases of Engine execution.
Definition: Engine.h:93
static const int POSITION_ITERATIONS
LiquidFun position iterations, controlling world substepping.
Definition: Engine.h:169
Class managing a collection of TerrainMaterialDefs.
Definition: TerrainMaterials.h:31
void afterUpdate()
Emitted at the end of the update() call.