qglgameengine.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef QGLGAMEENGINE_H
  2. #define QGLGAMEENGINE_H
  3. #include <QGLWidget>
  4. #include <QMainWindow>
  5. #include <QTimer>
  6. #include <QTime>
  7. #include <QDebug>
  8. #include <QFile>
  9. #include <QMap>
  10. #include <QtDeclarative/QDeclarativeView>
  11. #include <QStackedWidget>
  12. #include "GameApp.h"
  13. #include "GameEngine.h"
  14. #include "gameglwidget.h"
  15. #ifdef USE_PUSH_AUDIO_OUT
  16. #include "pushaudioout.h"
  17. #endif
  18. #ifdef USE_PULL_AUDIO_OUT
  19. #include "pullaudioout.h"
  20. #endif
  21. #if defined(Q_OS_SYMBIAN) || defined(MY_OS_MEEGO)
  22. #include <QAccelerometer>
  23. QTM_USE_NAMESPACE
  24. #endif
  25. class QGlGameEngine : public QStackedWidget, public GF::GameEngine, public GF::IAudioSource
  26. {
  27. Q_OBJECT
  28. public:
  29. explicit QGlGameEngine(QWidget *parent = 0);
  30. ~QGlGameEngine();
  31. bool event(QEvent *);
  32. void keyPressEvent(QKeyEvent *);
  33. #ifdef USE_VKB
  34. void inputMethodEvent(QInputMethodEvent *);
  35. #endif
  36. signals:
  37. virtual void quit();
  38. public slots:
  39. #ifdef USE_PUSH_AUDIO_OUT
  40. virtual void audioTick();
  41. #endif
  42. void renderTick();
  43. #ifdef USE_QML
  44. void qmlQuit();
  45. #endif
  46. protected:
  47. void startGame();
  48. void pauseGame();
  49. GF::GameApp *game;
  50. QTimer timer;
  51. #ifdef USE_PUSH_AUDIO_OUT
  52. QTimer audioTimer;
  53. GE::PushAudioOut *m_aout;
  54. #endif
  55. #ifdef USE_PULL_AUDIO_OUT
  56. GE::PullAudioOut *m_aout;
  57. #endif
  58. public: // engine
  59. virtual void exit();
  60. virtual bool startAudio( int frequency, int channels );
  61. virtual void stopAudio();
  62. virtual bool queryTextInput( const char *prompt, char *target, int targetLength );
  63. virtual int loadGLTexture( const char *fileName );
  64. virtual void releaseTexture(int textureHandle);
  65. virtual void* loadBinaryResource( const char *fileName, int &sizeTarget );
  66. virtual void releaseBinaryResource( void *resource );
  67. virtual void sendEvent(GF::ENGINE_EVENT_TYPE type, int flags);
  68. virtual int openUrlInBrowser(const char *path8);
  69. virtual bool startSensors() {qDebug("TODO: startSensors"); }
  70. virtual void stopSensors() {qDebug("TODO: stopSensors"); }
  71. virtual const char *adjustPath(const char *inputPath, char *outputPath, int outputPathLength, bool *isOk = 0);
  72. virtual void setUpdateAndPauseState(bool updatesDisabled, bool pauseResumeDisabled) {qDebug("TODO: setUpdateAndPauseState"); }
  73. virtual int pullAudio( AUDIO_SAMPLE_TYPE *target, int sampleCount );
  74. #if defined(Q_OS_SYMBIAN) || defined(MY_OS_MEEGO)
  75. QAccelerometer sensor;
  76. #endif
  77. QMap<uchar*, QFile*> resourceMap;
  78. QDeclarativeView *view;
  79. GameGLWidget *gl;
  80. QStackedWidget stacked;
  81. bool gameRunning;
  82. int audioFrequency;
  83. int audioChannels;
  84. QTime previousRenderTick;
  85. bool splashScreen;
  86. #ifdef USE_VKB
  87. int lastStringLength;
  88. #endif
  89. };
  90. #endif // QGLGAMEENGINE_H