00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GLUON_ENGINE_GAME_H
00022 #define GLUON_ENGINE_GAME_H
00023
00024 #include "gameproject.h"
00025
00026 #include "gluon_engine_export.h"
00027
00028 #include <core/singleton.h>
00029
00030 #include <QtCore/QObject>
00031 #include <QtCore/QSharedData>
00032 #include <QtCore/QThread>
00033
00034 namespace GluonEngine
00035 {
00036 class GameObject;
00037 class Scene;
00038 class GamePrivate;
00039
00040 class I : public QThread
00041 {
00042 public:
00043 static void sleep( unsigned long secs )
00044 {
00045 QThread::sleep( secs );
00046 }
00047 static void msleep( unsigned long msecs )
00048 {
00049 QThread::msleep( msecs );
00050 }
00051 static void usleep( unsigned long usecs )
00052 {
00053 QThread::usleep( usecs );
00054 }
00055 };
00056
00057 class GLUON_ENGINE_EXPORT Game : public GluonCore::Singleton<Game>
00058 {
00059 Q_OBJECT
00063 Q_PROPERTY( Scene* currentScene READ currentScene WRITE setCurrentScene )
00067 Q_PROPERTY( GluonEngine::GameProject* gameProject READ gameProject WRITE setGameProject )
00068
00069 public:
00070 int getCurrentTick();
00071 Scene* currentScene() const;
00072
00073 GluonEngine::GameProject* gameProject() const;
00074
00075 Q_INVOKABLE bool isRunning() const;
00076 Q_INVOKABLE bool isPaused() const;
00077
00083 Q_INVOKABLE GluonEngine::GameObject* getFromScene( const QString& name );
00084
00085 Q_INVOKABLE GluonEngine::GameObject* clone( GluonEngine::GameObject* obj );
00086
00087
00088
00089
00097 Q_INVOKABLE float random();
00098
00099
00100 public slots:
00101 void setGameProject( GluonEngine::GameProject* newGameProject );
00102
00103 void setCurrentScene( Scene* newCurrentScene );
00104 void setCurrentScene( const QString& sceneName );
00105
00109 void resetCurrentScene();
00110
00111 void runGame()
00112 {
00113 this->runGameFixedUpdate();
00114 }
00120 void runGameFixedUpdate( int updatesPerSecond = 25, int maxFrameSkip = 5 );
00121
00126 void runGameFixedTimestep( int framesPerSecond = 25 );
00127
00128 void stopGame();
00129
00130 void setPause( bool pause );
00131
00135 void initializeAll();
00139 void startAll();
00143 void drawAll( int time = 1 );
00147 void updateAll( int time = 10 );
00151 void stopAll();
00155 void cleanupAll();
00156
00157 signals:
00158 void showDebug( const QString& debugText );
00159 void currentSceneChanged( GluonEngine::Scene* );
00160 void currentProjectChanged( GluonEngine::GameProject* );
00161
00162 void updated( int );
00163 void painted( int );
00164
00165 private:
00166 friend class GluonCore::Singleton<Game>;
00167
00168 Game( QObject* parent = 0 );
00169 ~Game();
00170 Q_DISABLE_COPY( Game )
00171
00172 QSharedDataPointer<GamePrivate> d;
00173 };
00174 }
00175
00176 #endif // GLUON_ENGINE_GAME_H