Qt 5 port: Fixes to build against "develop" branch

The Qt 5 port was based on the "master" branch. This patch
updates all Qt 5 changes to build correctly with the "develop"
branch. Tested with GCC 4.6 and Qt 5.1.0 on Linux.
This commit is contained in:
Thomas Perl 2013-07-26 08:55:46 +00:00
parent 0557eb9674
commit 2f35353020
16 changed files with 151 additions and 99 deletions

View File

@ -41,7 +41,7 @@ namespace CocosDenshion {
static QString
fullPath(const char *filename)
{
return QString::fromStdString(CCFileUtils::sharedFileUtils()->fullPathForFilename(filename));
return QString::fromStdString(FileUtils::getInstance()->fullPathForFilename(filename));
}
class CocosQt5AudioBackend {
@ -119,7 +119,7 @@ simple_audio_engine = NULL;
@brief Get the shared Engine object,it will new one when first time be called
*/
SimpleAudioEngine *
SimpleAudioEngine::sharedEngine()
SimpleAudioEngine::getInstance()
{
if (simple_audio_engine == NULL) {
simple_audio_engine = new SimpleAudioEngine;
@ -283,8 +283,11 @@ SimpleAudioEngine::setEffectsVolume(float volume)
@bLoop Whether to loop the effect playing, default value is false
*/
unsigned int
SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,
float pitch, float pan, float gain)
{
// TODO: Handle pitch, pan and gain
CocosQt5AudioBackend::gcEffects();
QString filename = fullPath(pszFilePath);

View File

@ -29,7 +29,7 @@
#include <QObject>
AccelerometerListener::AccelerometerListener(CCAccelerometer *accelerometer)
AccelerometerListener::AccelerometerListener(Accelerometer *accelerometer)
: QObject()
, m_accelerometer(accelerometer)
{

View File

@ -38,13 +38,13 @@ class AccelerometerListener : public QObject {
Q_OBJECT
public:
AccelerometerListener(CCAccelerometer *accelerometer);
AccelerometerListener(Accelerometer *accelerometer);
public slots:
void onReadingChanged();
private:
CCAccelerometer *m_accelerometer;
Accelerometer *m_accelerometer;
};
#endif /* COCOS2DX_ACCELEROMETER_LISTENER_QT5_H */

View File

@ -33,29 +33,29 @@
NS_CC_BEGIN
static CCAccelerometer *
static Accelerometer *
shared_accelerometer = NULL;
CCAccelerometer::CCAccelerometer()
Accelerometer::Accelerometer()
: m_accelerometer(new QAccelerometer)
, m_listener(new AccelerometerListener(this))
, m_delegate(NULL)
, m_function(nullptr)
{
QObject::connect(m_accelerometer, SIGNAL(readingChanged()),
m_listener, SLOT(onReadingChanged()));
}
CCAccelerometer::~CCAccelerometer()
Accelerometer::~Accelerometer()
{
delete m_listener;
delete m_accelerometer;
}
CCAccelerometer *
CCAccelerometer::sharedAccelerometer()
Accelerometer *
Accelerometer::sharedAccelerometer()
{
if (shared_accelerometer == NULL) {
shared_accelerometer = new CCAccelerometer;
shared_accelerometer = new Accelerometer;
}
return shared_accelerometer;
@ -63,13 +63,13 @@ CCAccelerometer::sharedAccelerometer()
void
CCAccelerometer::setDelegate(CCAccelerometerDelegate *pDelegate)
Accelerometer::setDelegate(std::function<void(Acceleration*)> function)
{
m_delegate = pDelegate;
m_function = function;
}
void
CCAccelerometer::setAccelerometerInterval(float interval)
Accelerometer::setAccelerometerInterval(float interval)
{
if (interval == 0.0) {
m_accelerometer->setDataRate(0.0);
@ -80,21 +80,21 @@ CCAccelerometer::setAccelerometerInterval(float interval)
}
void
CCAccelerometer::readingChanged()
Accelerometer::readingChanged()
{
if (m_delegate == NULL) {
if (m_function == NULL) {
return;
}
QAccelerometerReading *reading = m_accelerometer->reading();
CCAcceleration accel;
Acceleration accel;
accel.x = reading->x();
accel.y = reading->y();
accel.z = reading->z();
accel.timestamp = reading->timestamp();
m_delegate->didAccelerate(&accel);
m_function(&accel);
}
NS_CC_END

View File

@ -31,20 +31,21 @@
#include "platform/CCCommon.h"
#include "platform/CCAccelerometerDelegate.h"
#include <functional>
class QAccelerometer;
class AccelerometerListener;
NS_CC_BEGIN
class CCAccelerometer {
class Accelerometer {
public:
CCAccelerometer();
~CCAccelerometer();
Accelerometer();
~Accelerometer();
static CCAccelerometer *sharedAccelerometer();
static Accelerometer *sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate *pDelegate);
void setDelegate(std::function<void(Acceleration*)> function);
void setAccelerometerInterval(float interval);
/* Functions to be called from AccelerometerListener */
@ -53,7 +54,7 @@ class CCAccelerometer {
private:
QAccelerometer *m_accelerometer;
AccelerometerListener *m_listener;
CCAccelerometerDelegate *m_delegate;
std::function<void(Acceleration*)> m_function;
};
NS_CC_END

View File

@ -57,7 +57,7 @@ class Cocos2DQt5MainloopIntegration : public QObject {
protected:
virtual void timerEvent(QTimerEvent *event)
{
cocos2d::CCDirector::sharedDirector()->mainLoop();
cocos2d::Director::getInstance()->mainLoop();
}
private:
@ -68,7 +68,7 @@ class Cocos2DQt5MainloopIntegration : public QObject {
NS_CC_BEGIN
// Application singleton
static CCApplication *
static Application *
application = NULL;
static int
@ -77,14 +77,21 @@ global_fake_argc = 1;
static char *
global_fake_argv[1];
CCApplication *
CCApplication::sharedApplication()
// @deprecated Use getInstance() instead
Application *
Application::sharedApplication()
{
return getInstance();
}
Application *
Application::getInstance()
{
CC_ASSERT(application != NULL);
return application;
}
CCApplication::CCApplication()
Application::Application()
: m_application(NULL)
, m_animationInterval(1000 / 60)
, m_resourceRootPath("")
@ -101,7 +108,7 @@ CCApplication::CCApplication()
application = this;
}
CCApplication::~CCApplication()
Application::~Application()
{
delete m_mainloop;
delete m_application;
@ -111,7 +118,7 @@ CCApplication::~CCApplication()
}
int
CCApplication::run()
Application::run()
{
// Initialize instance and cocos2d.
if (!applicationDidFinishLaunching()) {
@ -124,7 +131,7 @@ CCApplication::run()
}
void
CCApplication::setAnimationInterval(double interval)
Application::setAnimationInterval(double interval)
{
// Interval is expressed in seconds
m_animationInterval = interval * 1000;
@ -133,32 +140,32 @@ CCApplication::setAnimationInterval(double interval)
}
void
CCApplication::setResourceRootPath(const std::string &rootResDir)
Application::setResourceRootPath(const std::string &rootResDir)
{
m_resourceRootPath = rootResDir;
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/') {
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
FileUtils* pFileUtils = FileUtils::getInstance();
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPaths(searchPaths);
}
const std::string &
CCApplication::getResourceRootPath()
Application::getResourceRootPath()
{
return m_resourceRootPath;
}
TargetPlatform
CCApplication::getTargetPlatform()
Application::getTargetPlatform()
{
return kTargetLinux;
}
ccLanguageType
CCApplication::getCurrentLanguage()
Application::getCurrentLanguage()
{
QLocale locale;

View File

@ -38,13 +38,13 @@ class Cocos2DQt5MainloopIntegration;
NS_CC_BEGIN
class CCApplication : public CCApplicationProtocol {
class Application : public ApplicationProtocol {
public:
CCApplication();
virtual ~CCApplication();
Application();
virtual ~Application();
/**
@brief Callback by CCDirector for limit FPS.
@brief Callback by Director for limit FPS.
@interval The time, which expressed in second in second, between current frame and next.
*/
void setAnimationInterval(double interval);
@ -55,10 +55,13 @@ class CCApplication : public CCApplicationProtocol {
int run();
/**
@brief Get current applicaiton instance.
@brief Get current application instance.
@return Current application instance pointer.
*/
static CCApplication* sharedApplication();
static Application* getInstance();
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static Application* sharedApplication();
/* override functions */
virtual ccLanguageType getCurrentLanguage();

View File

@ -33,6 +33,7 @@ NS_CC_BEGIN
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
/* @deprecated, use cocos2d::log() instead (see below) */
void CCLog(const char * pszFormat, ...)
{
char szBuf[MAX_LEN];
@ -53,12 +54,32 @@ void CCLog(const char * pszFormat, ...)
fprintf(stderr, "cocos2d-x debug info [%s]\n", szBuf);
}
void CCMessageBox(const char * pszMsg, const char * pszTitle)
void log(const char * pszFormat, ...)
{
CCLog("%s: %s", pszTitle, pszMsg);
char szBuf[MAX_LEN];
va_list ap;
va_start(ap, pszFormat);
vsnprintf(szBuf, MAX_LEN, pszFormat, ap);
va_end(ap);
// Strip any trailing newlines from log message.
size_t len = strlen(szBuf);
while (len && szBuf[len-1] == '\n')
{
szBuf[len-1] = '\0';
len--;
}
fprintf(stderr, "cocos2d-x debug info [%s]\n", szBuf);
}
void CCLuaLog(const char * pszFormat)
void MessageBox(const char * pszMsg, const char * pszTitle)
{
log("%s: %s", pszTitle, pszMsg);
}
void LuaLog(const char * pszFormat)
{
puts(pszFormat);
}

View File

@ -33,7 +33,7 @@
NS_CC_BEGIN
int CCDevice::getDPI()
int Device::getDPI()
{
QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance());
QScreen *screen = app->primaryScreen();

View File

@ -49,7 +49,7 @@ NS_CC_BEGIN
class Cocos2DQt5OpenGLIntegration : public QWindow {
public:
Cocos2DQt5OpenGLIntegration(CCEGLView *view, int width, int height);
Cocos2DQt5OpenGLIntegration(EGLView *view, int width, int height);
~Cocos2DQt5OpenGLIntegration();
virtual void touchEvent(QTouchEvent *event);
@ -58,11 +58,11 @@ class Cocos2DQt5OpenGLIntegration : public QWindow {
void swapBuffers();
private:
CCEGLView *m_egl_view;
EGLView *m_egl_view;
QOpenGLContext *m_context;
};
Cocos2DQt5OpenGLIntegration::Cocos2DQt5OpenGLIntegration(CCEGLView *view, int width, int height)
Cocos2DQt5OpenGLIntegration::Cocos2DQt5OpenGLIntegration(EGLView *view, int width, int height)
: m_egl_view(view)
, m_context(NULL)
{
@ -114,7 +114,7 @@ bool
Cocos2DQt5OpenGLIntegration::event(QEvent *event)
{
if (event->type() == QEvent::Close) {
CCDirector::sharedDirector()->end();
Director::getInstance()->end();
}
return QWindow::event(event);
@ -128,28 +128,35 @@ Cocos2DQt5OpenGLIntegration::swapBuffers()
}
/* Global CCEGLView singleton for this module */
static CCEGLView *
/* Global EGLView singleton for this module */
static EGLView *
egl_view = NULL;
CCEGLView *
CCEGLView::sharedOpenGLView()
/** @deprecated Use getInstance() instead */
EGLView *
EGLView::sharedOpenGLView()
{
return getInstance();
}
EGLView *
EGLView::getInstance()
{
if (egl_view == NULL) {
egl_view = new CCEGLView;
egl_view = new EGLView;
}
return egl_view;
}
CCEGLView::CCEGLView()
EGLView::EGLView()
: m_integration(NULL)
{
}
CCEGLView::~CCEGLView()
EGLView::~EGLView()
{
if (m_integration) {
delete m_integration;
@ -157,7 +164,7 @@ CCEGLView::~CCEGLView()
}
void
CCEGLView::setFrameSize(float width, float height)
EGLView::setFrameSize(float width, float height)
{
if (m_integration == NULL) {
m_integration = new Cocos2DQt5OpenGLIntegration(this,
@ -166,11 +173,11 @@ CCEGLView::setFrameSize(float width, float height)
m_integration->resize(width, height);
}
CCEGLViewProtocol::setFrameSize(width, height);
EGLViewProtocol::setFrameSize(width, height);
}
void
CCEGLView::swapBuffers()
EGLView::swapBuffers()
{
if (m_integration != NULL) {
m_integration->swapBuffers();
@ -178,14 +185,14 @@ CCEGLView::swapBuffers()
}
void
CCEGLView::setIMEKeyboardState(bool bOpen)
EGLView::setIMEKeyboardState(bool bOpen)
{
QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance());
app->inputMethod()->setVisible(bOpen);
}
void
CCEGLView::end()
EGLView::end()
{
QGuiApplication::exit(0);
}

View File

@ -37,12 +37,15 @@ NS_CC_BEGIN
class Cocos2DQt5OpenGLIntegration;
class CCEGLView : public CCEGLViewProtocol {
class EGLView : public EGLViewProtocol {
public:
CCEGLView();
virtual ~CCEGLView();
EGLView();
virtual ~EGLView();
static CCEGLView *sharedOpenGLView();
static EGLView *getInstance();
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static EGLView *sharedOpenGLView();
virtual bool isOpenGLReady() { return (m_integration != NULL); }

View File

@ -44,10 +44,10 @@
NS_CC_BEGIN
class CC_DLL CCFileUtilsQt5 : public CCFileUtils
class CC_DLL FileUtilsQt5 : public FileUtils
{
public:
CCFileUtilsQt5();
FileUtilsQt5();
/* override funtions */
virtual bool init();
@ -55,23 +55,23 @@ class CC_DLL CCFileUtilsQt5 : public CCFileUtils
virtual bool isFileExist(const std::string& strFilePath);
};
CCFileUtils *
CCFileUtils::sharedFileUtils()
FileUtils *
FileUtils::getInstance()
{
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new CCFileUtilsQt5();
s_sharedFileUtils = new FileUtilsQt5();
s_sharedFileUtils->init();
}
return s_sharedFileUtils;
}
CCFileUtilsQt5::CCFileUtilsQt5()
FileUtilsQt5::FileUtilsQt5()
{
}
bool
CCFileUtilsQt5::init()
FileUtilsQt5::init()
{
// Determine directory of the application executable
QDir app_dir = QDir("/proc/self/exe").canonicalPath();
@ -79,13 +79,13 @@ CCFileUtilsQt5::init()
// Resources should be placed alongside the binary (same directory)
QString path = app_dir.path() + "/Resources/";
m_strDefaultResRootPath = path.toStdString();
_defaultResRootPath = path.toStdString();
return CCFileUtils::init();
return FileUtils::init();
}
std::string
CCFileUtilsQt5::getWritablePath()
FileUtilsQt5::getWritablePath()
{
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
@ -97,7 +97,7 @@ CCFileUtilsQt5::getWritablePath()
return dir.path().toStdString();
}
bool CCFileUtilsQt5::isFileExist(const std::string& strFilePath)
bool FileUtilsQt5::isFileExist(const std::string& strFilePath)
{
QString filePath = QString::fromStdString(strFilePath);
@ -106,8 +106,8 @@ bool CCFileUtilsQt5::isFileExist(const std::string& strFilePath)
return true;
}
// If not found, look for file in m_strDefaultResRootPath
QString defaultResRootPath = QString::fromStdString(m_strDefaultResRootPath);
// If not found, look for file in _defaultResRootPath
QString defaultResRootPath = QString::fromStdString(_defaultResRootPath);
return QFile(QDir(defaultResRootPath).filePath(filePath)).exists();
}

View File

@ -31,17 +31,18 @@ SOURCES += ../actions/CCAction.cpp \
../cocoa/CCNS.cpp \
../cocoa/CCObject.cpp \
../cocoa/CCSet.cpp \
../cocoa/CCZone.cpp \
../cocoa/CCArray.cpp \
../cocoa/CCDictionary.cpp \
../cocoa/CCString.cpp \
../cocoa/CCDataVisitor.cpp \
../cocoa/CCData.cpp \
../draw_nodes/CCDrawingPrimitives.cpp \
../draw_nodes/CCDrawNode.cpp \
../effects/CCGrabber.cpp \
../effects/CCGrid.cpp \
../keypad_dispatcher/CCKeypadDelegate.cpp \
../keypad_dispatcher/CCKeypadDispatcher.cpp \
../keyboard_dispatcher/CCKeyboardDispatcher.cpp \
../label_nodes/CCLabelAtlas.cpp \
../label_nodes/CCLabelBMFont.cpp \
../label_nodes/CCLabelTTF.cpp \
@ -62,7 +63,6 @@ SOURCES += ../actions/CCAction.cpp \
../particle_nodes/CCParticleBatchNode.cpp \
../platform/CCSAXParser.cpp \
../platform/CCThread.cpp \
../platform/platform.cpp \
../platform/CCImageCommonWebp.cpp \
../platform/CCEGLViewProtocol.cpp \
../platform/CCFileUtils.cpp \
@ -82,7 +82,6 @@ SOURCES += ../actions/CCAction.cpp \
../sprite_nodes/CCSpriteFrame.cpp \
../sprite_nodes/CCSpriteFrameCache.cpp \
../support/ccUTF8.cpp \
../support/CCPointExtension.cpp \
../support/CCProfiling.cpp \
../support/user_default/CCUserDefault.cpp \
../support/TransformUtils.cpp \
@ -105,6 +104,7 @@ SOURCES += ../actions/CCAction.cpp \
../textures/CCTextureCache.cpp \
../textures/CCTextureETC.cpp \
../textures/CCTexturePVR.cpp \
../textures/etc/etc1.cpp \
../tilemap_parallax_nodes/CCParallaxNode.cpp \
../tilemap_parallax_nodes/CCTMXLayer.cpp \
../tilemap_parallax_nodes/CCTMXObjectGroup.cpp \
@ -136,17 +136,17 @@ SOURCES += ../actions/CCAction.cpp \
../CCDirector.cpp \
../CCScheduler.cpp \
../ccFPSImages.c \
../ccTypes.cpp \
../cocos2d.cpp
# Headers with QObject subclasses (will be processed by moc)
HEADERS += ../platform/qt5/AccelerometerListener.h
# WebP
INCLUDEPATH += ../platform/third_party/marmalade/libwebp/webp
SOURCES += $$files(../platform/third_party/marmalade/libwebp/dec/*.c)
SOURCES += $$files(../platform/third_party/marmalade/libwebp/dsp/*.c)
#SOURCES += $$files(../platform/third_party/marmalade/libwebp/mux/*.c)
SOURCES += $$files(../platform/third_party/marmalade/libwebp/utils/*.c)
INCLUDEPATH += ../../external/libwebp/webp
SOURCES += $$files(../../external/libwebp/dec/*.c)
SOURCES += $$files(../../external/libwebp/dsp/*.c)
SOURCES += $$files(../../external/libwebp/utils/*.c)
# FreeType (FIXME: use pkg-config)
INCLUDEPATH += /usr/include/freetype2

View File

@ -3,8 +3,13 @@ DEFINES += CC_TARGET_QT5
CONFIG += silent
QMAKE_CXXFLAGS += -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-psabi
QMAKE_CFLAGS += -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-psabi
# Disable some warnings to make compiler output easier to read during development
DISABLED_WARNINGS = -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-psabi
QMAKE_CXXFLAGS += $${DISABLED_WARNINGS} -Wno-reorder
QMAKE_CFLAGS += $${DISABLED_WARNINGS}
# C++11 support (GCC 4.6; for newer versions, change to -std=c++11)
QMAKE_CXXFLAGS += -Doverride= -std=c++0x
OS_TYPE = linux

View File

@ -28,7 +28,6 @@ SOURCES += ../CCBReader/CCBFileLoader.cpp \
../CCBReader/CCBSequence.cpp \
../CCBReader/CCBSequenceProperty.cpp \
../CCBReader/CCBValue.cpp \
../CCBReader/CCData.cpp \
../CCBReader/CCNode+CCBRelativePositioning.cpp \
../GUI/CCScrollView/CCScrollView.cpp \
../GUI/CCScrollView/CCSorting.cpp \

View File

@ -64,8 +64,10 @@ SOURCES += ../Classes/AccelerometerTest/AccelerometerTest.cpp \
../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \
../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \
../Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \
../Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \
../Classes/FontTest/FontTest.cpp \
../Classes/IntervalTest/IntervalTest.cpp \
../Classes/KeyboardTest/KeyboardTest.cpp \
../Classes/KeypadTest/KeypadTest.cpp \
../Classes/LabelTest/LabelTest.cpp \
../Classes/LayerTest/LayerTest.cpp \
@ -105,6 +107,7 @@ SOURCES += ../Classes/AccelerometerTest/AccelerometerTest.cpp \
../Classes/controller.cpp \
../Classes/testBasic.cpp \
../Classes/AppDelegate.cpp \
../Classes/BaseTest.cpp \
../Classes/VisibleRect.cpp
LIBS += $${LINK_AGAINST_COCOS2DX}