Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
StrobeAPI integration
Browse files Browse the repository at this point in the history
Strobe through StrobeAPI is now supported.
StrobeAPI added as a git submodule.
  • Loading branch information
fuzun committed Jun 28, 2018
1 parent 771d881 commit a7dbdd8
Show file tree
Hide file tree
Showing 21 changed files with 671 additions and 174 deletions.
18 changes: 16 additions & 2 deletions Flappy-Bird-Qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ SOURCES += \
source/Physics.cpp \
source/Scene.cpp \
source/main.cpp \
source/Sound.cpp
source/Sound.cpp \
source/View.cpp \
source/StrobeDialog.cpp

HEADERS += \
source/MainWindow.h \
Expand All @@ -33,7 +35,19 @@ HEADERS += \
source/Physics.h \
source/Scene.h \
source/common.h \
source/Sound.h
source/Sound.h \
source/View.h \
source/StrobeDialog.h

RESOURCES += \
assets/Resource.qrc

# strobe-api :

SOURCES += \
source/strobe-api/strobe/strobe-api.cpp \
source/strobe-api/strobe/strobe-core.cpp

HEADERS += \
source/strobe-api/strobe/strobe-api.h \
source/strobe-api/strobe/strobe-core.h
69 changes: 60 additions & 9 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,19 +1,70 @@
[General]
Fullscreen = 0
Fullscreen = 0 ; 0: Window mode, 1: Fullscreen mode
; Both OpenGL and software rendering work better in fullscreen mode.

ScreenWidth = 480
ScreenHeight = 800
Sound = 0

Sound = 0 ; 0: Sounds are disabled, 1: Sounds are enabled
; Sounds may cause stuttering.

;ScaleFactor = 1.0 ; Use if you are not satisfied with the default value.
; Used for scaling images.


[Graphic]
OpenGL = 0
Antialiasing = 1
OpenGL = 1 ; Determines what to use for rendering. 0: Qt Raster-Software (CPU), 1: OpenGL (GPU)
; OpenGL support is experimental. Tests show that raster is better performance-wise.
; Swap interval of raster is 0. It might cause tearing.
; Swap interval of OpenGL is 1. V-Sync is enabled.

Antialiasing = 0
SmoothPixmapTransform = 1
HighQualityAntiAliasing = 1
SwapInterval = 1 ; 0 to disable vertical sync
ViewportUpdateMode = 1 ; 0 -> FullViewportUpdate, 1 -> MinimalViewportUpdate, 2 -> SmartViewportUpdate
;ScaleFactor = 1.0
HighQualityAntiAliasing = 0
FPSCap = 1 ; 0: capping disabled, 1: capping enabled
; Only valid in software rendering.
; Viewport update mode determines the dynamically capped fps.

ViewportUpdateMode = 1 ; 0: FullViewportUpdate, 1: MinimalViewportUpdate, 2: SmartViewportUpdate
; Only valid in software rendering.
; Only valid when FPSCap != 0


[Physics]
TickRate = 5 ; in milliseconds
ComplexAnalyse = 1
DisableCollisionDetection = 0
;SpeedFactor = 1.0 ; E.g. 2.0 makes the game 2x faster (except bird's movements).
; OpenGL rendering causes slower pace so this parameter may help for setting up the correct pace.

ComplexAnalyse = 1 ; Complex collision detection analysis enabled or disabled.
; Only valid when DisableCollisionDetection = 0


[Strobe]
Enabled = 1 ; StrobeAPI enabled or disabled
; Strobe mode requires OpenGL renderer.

Dialog = 1 ; StrobeAPI information dialog is shown or not.
; Affects Strobe performance in a bad way.
; Needs StrobeAPI to be enabled.

Method = 1 ; Strobing method.
; 1 : [RENDER - BLACK]
; 2 : [RENDER - BLACK - BLACK]
; -2 : [BLACK - BLACK - RENDER]
; 0 disables strobing

CooldownDelay = 3 ; When deviation of fps becomes too high (instability) , strobing gets temporarily disabled for a time period. This parameter sets the time period in seconds.
; Set 0 to disable cooldown.

SwapInterval = 0 ; Phase swap interval in seconds.
; Set 0 to disable phase swapping.
; Setting 0 may cause image retention in some monitors.

DeviationLimit = 5.0 ; Standard deviation limit of collected FPS values in a period. When deviation becomes higher than the limit, strobing will be temporarily disabled.
; Only valid when CooldownDelay != 0

DialogUpdateInterval = 20 ; Update interval of information dialog in milliseconds.



4 changes: 2 additions & 2 deletions source/Bird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
#include <QPropertyAnimation>

Bird::Bird(const QPointF& pos, const QPixmap& pixmap, const qreal &groundStartPosY, int scrWidth, int scrHeight, qreal scaleF)
: QGraphicsPixmapItem(pixmap), groundYPos(groundStartPosY), screenWidth(scrWidth), screenHeight(scrHeight), scaleFactor(scaleF)
: QGraphicsPixmapItem(pixmap), groundYPos(groundStartPosY), scaleFactor(scaleF), screenWidth(scrWidth), screenHeight(scrHeight)
{
setCacheMode(ItemCoordinateCache);

Expand Down Expand Up @@ -127,7 +127,7 @@ void Bird::gravitation()
{
birdDesigner->setInterval(85);

rotate(90, 625, QEasingCurve::InQuart);
rotate(90, 675, QEasingCurve::InCubic);

qreal endPos = groundYPos;
qreal curPosY = this->y();
Expand Down
20 changes: 12 additions & 8 deletions source/Bird.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Bird : public QObject, public QGraphicsPixmapItem
void fall();

private:

typedef enum{
up,
middle,
Expand All @@ -59,13 +58,17 @@ class Bird : public QObject, public QGraphicsPixmapItem
WingStates wingState;

bool wingDirection;
bool oscillateDirection;

BirdTypes birdType;

qreal currentRotation;
bool oscillateDirection;
QTimer *birdDesigner;
QPropertyAnimation *yAnimator;
QPropertyAnimation *oscillator;
QPropertyAnimation *rotator;

class QTimer *birdDesigner;

class QPropertyAnimation *yAnimator;
class QPropertyAnimation *oscillator;
class QPropertyAnimation *rotator;

private slots:
void gravitation();
Expand All @@ -74,10 +77,11 @@ private slots:

protected:
qreal groundYPos;
void rotate(const qreal &end, const int &duration, const QEasingCurve &curve);
int screenWidth, screenHeight;
qreal scaleFactor;

void rotate(const qreal &end, const int &duration, const QEasingCurve &curve);

int screenWidth, screenHeight;
};

#endif // BIRD_H
59 changes: 10 additions & 49 deletions source/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@ SOFTWARE.
#include "Game.h"

#include <QSound>
#include <QTimer>
#include <QImage>
#include <QPainter>
#include <QSettings>
#include <QGraphicsView>
#include <QEasingCurve>
#include <QTimer>
#include <QtOpenGL>

#include "MainWindow.h"
#include "View.h"
#include "Bird.h"
#include "Button.h"
#include "Scene.h"
#include "Physics.h"
#include "Sound.h"


Game::Game(QGraphicsView *GraphicsView, class QSettings *cfg, class QSettings *settings, int windowWidth, int windowHeight)
Game::Game(View *GraphicsView, class QSettings *cfg, class QSettings *settings, int windowWidth, int windowHeight)
: graphicsView(GraphicsView), screenWidth(windowWidth), screenHeight(windowHeight), config(cfg), registry(settings)
{
scoreRecord = 0;
Expand All @@ -60,7 +59,8 @@ Game::Game(QGraphicsView *GraphicsView, class QSettings *cfg, class QSettings *s

scene = new Scene(this, QRectF(0, 0, screenWidth, screenHeight));

physics = new Physics(this, physicsTickRate, physicsComplexAnalysis, true);
physics = new Physics(this, physicsTickRate, physicsComplexAnalysis, true, physicsSpeedFactor, physicsDisableCollisionDetection);

}

Game::~Game()
Expand All @@ -74,63 +74,24 @@ Game::~Game()
delete sound_swooshing;
delete sound_wing;

if(glWidget)
delete glWidget;
}

void Game::loadConfiguration()
{
scaleFactor = config->value(CONFIG_SCALEFACTOR, scaleFactor).toReal();

soundEnabled = registry->value(CONFIG_SOUNDENABLED, soundEnabled).toBool();
scoreRecord = registry->value(CONFIG_SCORE_RECORD, 0).toInt();

// config->beginGroup(CONFIG_GENERAL);
soundEnabled = config->value(CONFIG_SOUNDENABLED, soundEnabled).toBool();
// config->endGroup();

config->beginGroup(CONFIG_GRAPHICS);
scaleFactor = config->value(CONFIG_SCALEFACTOR, scaleFactor).toReal();
glWidget = nullptr;
if(config->value(CONFIG_OPENGL, GAME_DEFAULT_OPENGL_ENABLED).toBool())
{
glWidget = new QOpenGLWidget();
QTimer::singleShot(2500, [this]() {
graphicsView->setViewport(glWidget);
});
}
int _config_viewportupdate = config->value(CONFIG_VIEWPORTUPDATE, GAME_DEFAULT_VIEWPORTUPDATE).toInt();
if(_config_viewportupdate == 0)
{
graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}
else if(_config_viewportupdate == 1)
{
graphicsView->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
}
else
{
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
}

QSurfaceFormat::defaultFormat().setSwapInterval(config->value(CONFIG_SWAPINTERVAL, GAME_DEFAULT_SWAPINTERVAL).toInt());

if(config->value(CONFIG_ANTIALIASING, GAME_DEFAULT_ANTIALIASING_ENABLED).toBool())
graphicsView->setRenderHint(QPainter::Antialiasing);
else
graphicsView->setRenderHint(QPainter::Antialiasing, 0);
if(config->value(CONFIG_SMOOTHPIXMAPTRANSFORM, GAME_DEFAULT_SMOOTHPIXMAPTRANSFORM_ENABLED).toBool())
graphicsView->setRenderHint(QPainter::SmoothPixmapTransform);
else
graphicsView->setRenderHint(QPainter::SmoothPixmapTransform, 0);
if(config->value(CONFIG_HQANTIALIASING, GAME_DEFAULT_HQANTIALIASING_ENABLED).toBool())
graphicsView->setRenderHint(QPainter::HighQualityAntialiasing);
else
graphicsView->setRenderHint(QPainter::HighQualityAntialiasing, 0);

config->endGroup();

config->beginGroup(CONFIG_PHYSICS);
physicsTickRate = config->value(CONFIG_PHYSICS_TICKRATE, PHYSICS_DEFAULT_TICKRATE).toInt();
physicsComplexAnalysis = config->value(CONFIG_PHYSICS_COMPLEXANALYSIS, PHYSICS_COMPLEXANALYSIS_ENABLED).toBool();
physicsSpeedFactor = config->value(CONFIG_PHYSICS_SPEEDFACTOR, PHYSICS_DEFAULT_SPEEDFACTOR).toReal();
physicsDisableCollisionDetection = config->value(CONFIG_PHYSICS_DISABLECOLLISIONDETECTION, PHYSICS_DEFAULT_DISABLECOLLISIONDETECTION).toBool();
config->endGroup();
}

Expand Down Expand Up @@ -230,7 +191,7 @@ void Game::prepareNewRound()


delete physics;
physics = new Physics(this, physicsTickRate, physicsComplexAnalysis, false);
physics = new Physics(this, physicsTickRate, physicsComplexAnalysis, false, physicsSpeedFactor, physicsDisableCollisionDetection);

score = -1;
updateScore();
Expand Down
9 changes: 5 additions & 4 deletions source/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Sound;
class Game
{
public:
Game(class QGraphicsView *GraphicsView, class QSettings *cfg, class QSettings *registry, int windowWidth, int windowHeight);
Game(class View *GraphicsView, class QSettings *cfg, class QSettings *registry, int windowWidth, int windowHeight);
~Game();

void clickEvent();
Expand Down Expand Up @@ -58,27 +58,28 @@ class Game
Sound *sound_wing;

class Scene *scene;
class QGraphicsView *graphicsView;
class View *graphicsView;

private:
bool soundEnabled;
bool gameFinished, gameStarted;
bool gameActuallyStarted;
bool physicsComplexAnalysis;
bool physicsDisableCollisionDetection;

int score, scoreRecord;
int screenWidth, screenHeight;
int physicsTickRate;

qreal physicsSpeedFactor;
qreal scaleFactor;

class QOpenGLWidget *glWidget;

void loadConfiguration();

protected:
class QSettings *config;
class QSettings *registry;

class Physics *physics;

};
Expand Down
Loading

0 comments on commit a7dbdd8

Please sign in to comment.