From 9dccc885d64281b064520f23f4c58e90f8c4b14a Mon Sep 17 00:00:00 2001 From: Xawotihs Date: Sun, 17 Jul 2011 18:18:17 +0000 Subject: [PATCH] Updated the Qt project to work on Desktop/Maemo/Meego/Symbian. Removed all dependencies except Qt and OpenGl. --- JGE/include/JRenderer.h | 4 +- JGE/include/JSoundSystem.h | 2 +- JGE/include/JTypes.h | 3 +- JGE/include/Threading.h | 237 ++++++++++++++++++++++- JGE/src/Qtmain.cpp | 18 ++ JGE/src/pc/JGfx.cpp | 4 +- projects/mtg/src/CardSelector.cpp | 2 +- projects/mtg/src/GuiMana.cpp | 2 +- projects/mtg/{wagic.pro => wagic-Qt.pro} | 27 +-- projects/mtg/wagic-SDL.pro | 11 +- 10 files changed, 285 insertions(+), 25 deletions(-) rename projects/mtg/{wagic.pro => wagic-Qt.pro} (96%) diff --git a/JGE/include/JRenderer.h b/JGE/include/JRenderer.h index 70c9da261..76ad3c395 100644 --- a/JGE/include/JRenderer.h +++ b/JGE/include/JRenderer.h @@ -16,7 +16,7 @@ #include #include -#if (!defined IOS) && (!defined ANDROID) +#if (!defined IOS) && (!defined ANDROID) && (!defined QT_CONFIG) #include #endif //IOS ANDROID @@ -569,7 +569,7 @@ private: bool mVRAM; }; -#if (!defined IOS) +#if (!defined IOS) && (!defined QT_CONFIG) void LoadJPG(TextureInfo &textureInfo, const char *filename, int mode = 0, int TextureFormat = TEXTURE_FORMAT); int LoadPNG(TextureInfo &textureInfo, const char *filename, int mode = 0, int TextureFormat = TEXTURE_FORMAT); #if (!defined ANDROID) diff --git a/JGE/include/JSoundSystem.h b/JGE/include/JSoundSystem.h index 6a14b0f0b..7358e5d55 100644 --- a/JGE/include/JSoundSystem.h +++ b/JGE/include/JSoundSystem.h @@ -58,7 +58,7 @@ class JMusic #endif public: JMusic(); - ~JMusic(); + ~JMusic(); void Update(); int getPlayTime(); diff --git a/JGE/include/JTypes.h b/JGE/include/JTypes.h index 7d4b8253e..1a7f86d71 100644 --- a/JGE/include/JTypes.h +++ b/JGE/include/JTypes.h @@ -120,10 +120,11 @@ enum { #undef GL_ES_VERSION_2_0 #undef GL_VERSION_2_0 #define GL_VERSION_ES_CM_1_1 1 +#ifndef GL_OES_VERSION_1_1 #define glOrthof glOrtho #define glClearDepthf glClearDepth #endif - +#endif #if defined (PSP) diff --git a/JGE/include/Threading.h b/JGE/include/Threading.h index 2d45952d2..532467515 100644 --- a/JGE/include/Threading.h +++ b/JGE/include/Threading.h @@ -1,7 +1,7 @@ #ifndef THREADING_H #define THREADING_H -#if !defined(PSP) +#if !defined(PSP) && !defined(QT_CONFIG) #include #ifdef WIN32 @@ -14,7 +14,7 @@ #endif #include -#else +#elif !defined(QT_CONFIG) #include #include @@ -307,6 +307,239 @@ namespace boost } } +#elif defined(QT_CONFIG) + +#include +#include + +#include +#include + +#include "../include/DebugRoutines.h" +#include "../include/JLogger.h" + +namespace boost +{ + template + struct unique_lock + { + unique_lock(Mutex& inMutex) : mMutex(&inMutex) + { + mMutex->lock(); + } + + ~unique_lock() + { + mMutex->unlock(); + } + + Mutex* mMutex; + }; + + class mutex + { + public: + + typedef unique_lock scoped_lock; + + mutex() + : mQMutex() + { + } + + ~mutex() + { + } + + void lock() + { + mQMutex.lock(); + } + + void unlock() + { + mQMutex.unlock(); + } + + QMutex mQMutex; + + private: + mutex(mutex const&); + mutex& operator=(mutex const&); + }; + + + + class recursive_mutex + { + public: + + typedef unique_lock scoped_lock; + + recursive_mutex() : mQMutex(QMutex::Recursive) + { + } + + ~recursive_mutex() + { + } + + void lock() + { + mQMutex.lock(); + } + + void unlock() + { + mQMutex.unlock(); + } + + QMutex mQMutex; + + private: + recursive_mutex(recursive_mutex const&); + recursive_mutex& operator=(recursive_mutex const&); + }; + + + /** + ** Emulating boost::thread configuration glue, with some shortcuts + ** This detail namespace is a distillation of boost's thread.hpp, thread_data.hpp. + */ + namespace detail + { + struct thread_data_base + { + thread_data_base() + { + } + + virtual ~thread_data_base() + { + } + + virtual void run() = 0; + }; + + typedef boost::shared_ptr thread_data_ptr; + + template + class thread_data : public detail::thread_data_base + { + public: + thread_data(F f_) : f(f_) + { + } + + void run() + { + f(); + } + + private: + F f; + + void operator=(thread_data&); + thread_data(thread_data&); + }; + + } //namespace detail + + class threadImpl : public QThread + { + detail::thread_data_ptr mThreadInfo; + public: + static threadImpl* spThreadImpl; + threadImpl(detail::thread_data_ptr threadInfo) : mThreadInfo(threadInfo) + { + setTerminationEnabled(); + spThreadImpl = this; + }; + static void mymsleep(unsigned long msecs) + { + spThreadImpl->msleep(msecs); + } + protected: + void run() + { + LOG("Entering thread::run"); + mThreadInfo->run(); + } + }; + + threadImpl* threadImpl::spThreadImpl = 0; + + /** + ** A simplistic implementation of boost::thread, using QThread. + ** + */ + class thread + { + /* + ** Helper class for sceKernelStartThread, which passes args by value, not by reference + ** We use this struct to wrap any pointers that we want to pass to the worker thread. + */ + struct CallbackData + { + CallbackData(detail::thread_data_ptr inThreadInfo) + : mThreadInfo(inThreadInfo) + { + } + + detail::thread_data_ptr mThreadInfo; + }; + + public: + + thread() + { + } + + template + thread(F f, A1 a1) : mThreadInfo(make_thread_info(boost::bind(boost::type(), f, a1))) + { + mpThread = new threadImpl(mThreadInfo); + LOG("Calling start func"); + mpThread->start(QThread::LowPriority); + } + + ~thread() + { + } + + void join() + { + mpThread->terminate(); + } + + private: + template + static inline detail::thread_data_ptr make_thread_info(F f) + { + return detail::thread_data_ptr(new detail::thread_data(f)); + } + + detail::thread_data_ptr mThreadInfo; + threadImpl* mpThread; + }; + + namespace posix_time + { + typedef unsigned int milliseconds; + } + + /** + ** boost's platform neutral sleep call. + */ + namespace this_thread + { + inline void sleep(boost::posix_time::milliseconds const& time) + { + threadImpl::mymsleep(time); + } + } +} + #endif #endif // THREADING_H diff --git a/JGE/src/Qtmain.cpp b/JGE/src/Qtmain.cpp index aa6573fb1..6384b9cf4 100644 --- a/JGE/src/Qtmain.cpp +++ b/JGE/src/Qtmain.cpp @@ -2,6 +2,16 @@ #include #include +#if (defined FORCE_GLES) +#undef GL_ES_VERSION_2_0 +#undef GL_VERSION_2_0 +#define GL_VERSION_ES_CM_1_1 1 +#ifndef GL_OES_VERSION_1_1 +#define glOrthof glOrtho +#define glClearDepthf glClearDepth +#endif +#endif + #ifdef Q_WS_MAEMO_5 // For volume buttons support #include @@ -267,8 +277,12 @@ void JGEQtRenderer::initializeGL() glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal) glEnable(GL_DEPTH_TEST); // Enable Depth Testing +#else +#if (defined GL_VERSION_ES_CM_1_1 || defined GL_OES_VERSION_1_1) + glClearDepthf(1.0f); // Depth Buffer Setup #else glClearDepth(1.0f); // Depth Buffer Setup +#endif glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal) glEnable(GL_DEPTH_TEST); // Enable Depth Testing @@ -317,7 +331,11 @@ void JGEQtRenderer::resizeGL(int width, int height) glMatrixMode (GL_PROJECTION); // Select The Projection Matrix glLoadIdentity (); // Reset The Projection Matrix +#if (defined GL_VERSION_ES_CM_1_1 || defined GL_OES_VERSION_1_1) + glOrthof(0.0f, (float) (viewPort.right()-viewPort.left())-1.0f, 0.0f, (float) (viewPort.bottom()-viewPort.top())-1.0f, -1.0f, 1.0f); +#else gluOrtho2D(0.0f, (float) (viewPort.right()-viewPort.left())-1.0f, 0.0f, (float) (viewPort.bottom()-viewPort.top())-1.0f); +#endif glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity (); // Reset The Modelview Matrix diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index 57a696ff2..1d1da4723 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------------- #define GL_GLEXT_PROTOTYPES -#if (!defined IOS) +#if (!defined IOS) && (!defined QT_CONFIG) #ifdef WIN32 #pragma warning(disable : 4786) #pragma comment( lib, "giflib.lib" ) @@ -1630,7 +1630,7 @@ static int getNextPower2(int width) } -#if (!defined IOS) +#if (!defined IOS) && (!defined QT_CONFIG) static void jpg_null(j_decompress_ptr cinfo __attribute__((unused))) { } diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index 6ee11ede9..b8cde1a34 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -7,7 +7,7 @@ #include "Closest.cpp" #include "GameObserver.h" -using std::cout; +//using std::cout; // The X lib annoyingly defines True to be 1, leading to // hard to understand syntax errors. Not using it, so it's diff --git a/projects/mtg/src/GuiMana.cpp b/projects/mtg/src/GuiMana.cpp index 3f1fbaac2..a67b7013d 100644 --- a/projects/mtg/src/GuiMana.cpp +++ b/projects/mtg/src/GuiMana.cpp @@ -4,7 +4,7 @@ #include "OptionItem.h" #include "Player.h" -using std::cout; +//using std::cout; using std::endl; ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) : diff --git a/projects/mtg/wagic.pro b/projects/mtg/wagic-Qt.pro similarity index 96% rename from projects/mtg/wagic.pro rename to projects/mtg/wagic-Qt.pro index 8f826436f..a48e303c5 100644 --- a/projects/mtg/wagic.pro +++ b/projects/mtg/wagic-Qt.pro @@ -4,10 +4,9 @@ # #------------------------------------------------- -QT += core gui opengl -macx:QT += phonon +QT += core gui opengl phonon #CONFIG += warn_off precompile_header // causes some massives errors on mac. -VERSION = 0.14.1 +VERSION = 0.16.0 TARGET = wagic TEMPLATE = app unix|macx:QMAKE_CXXFLAGS += -Wno-unused-parameter @@ -16,14 +15,13 @@ windows:DEFINES += _CRT_SECURE_NO_WARNINGS unix|macx:DEFINES += LINUX CONFIG(debug, debug|release):DEFINES += _DEBUG DEFINES += QT_CONFIG -macx:DEFINES += USE_PHONON -maemo5 { DEFINES += USE_PHONON -QT += phonon dbus +maemo5 { +QT += dbus } windows:INCLUDEPATH += ../../JGE/Dependencies/include windows:INCLUDEPATH += extra -unix:INCLUDEPATH += /usr/include/GL +unix:!symbian:INCLUDEPATH += /usr/include/GL macx:INCLUDEPATH += /opt/include INCLUDEPATH += ../../JGE/include INCLUDEPATH += ../../Boost @@ -31,10 +29,8 @@ INCLUDEPATH += include OBJECTS_DIR = objs MOC_DIR = objs DESTDIR = bin - -unix:LIBS += -ljpeg -lgif -lpng12 -lboost_thread-mt -windows:LIBS += -L../../JGE/Dependencies/lib -L../../Boost/lib -llibjpeg-static-mt-debug -lgiflib -llibpng -lfmodvc -llibboost_date_time-vc100-mt-1_44 -macx|unix:LIBS += -lz +symbian:DEFINES += FORCE_GLES +symbian:DEFINES += QT_OPENGL_ES_1 PRECOMPILED_HEADER = include/PrecompiledHeader.h @@ -198,7 +194,7 @@ HEADERS += \ include/ThisDescriptor.h\ include/CardGui.h\ include/GameStateTransitions.h\ - include/IconButton.h\ + include/IconButton.h\ include/OptionItem.h\ include/Token.h\ include/CardPrimitive.h\ @@ -329,6 +325,7 @@ HEADERS += \ ../../JGE/src/tinyxml/tinyxml.h\ ../../JGE/include/vram.h +# maemo 5 packaging maemo5: { # Variables BINDIR = /opt/wagic @@ -361,3 +358,9 @@ maemo5: { launcher.path = $$BINDIR launcher.files += debian/launcher } + +# Meego/maemo 6 packaging (incomplete) +unix:!symbian:!maemo5 { + target.path = /opt/wagic/bin + INSTALLS += target +} diff --git a/projects/mtg/wagic-SDL.pro b/projects/mtg/wagic-SDL.pro index 6a559d0cb..4377b80bc 100644 --- a/projects/mtg/wagic-SDL.pro +++ b/projects/mtg/wagic-SDL.pro @@ -24,6 +24,7 @@ DEFINES += USE_PHONON QT += phonon dbus } windows:INCLUDEPATH += ../../JGE/Dependencies/include +windows:INCLUDEPATH += ../../JGE/Dependencies/SDL/include windows:INCLUDEPATH += extra unix:INCLUDEPATH += /usr/include/GL unix:INCLUDEPATH += /usr/local/include/SDL @@ -47,6 +48,7 @@ SOURCES += \ src/ActionElement.cpp\ src/ActionLayer.cpp\ src/ActionStack.cpp\ + src/AIHints.cpp\ src/AIMomirPlayer.cpp\ src/AIPlayer.cpp\ src/AIStats.cpp\ @@ -97,10 +99,11 @@ SOURCES += \ src/GuiPhaseBar.cpp\ src/GuiPlay.cpp\ src/GuiStatic.cpp\ - src/IconButton.cpp\ + src/IconButton.cpp\ src/ManaCost.cpp\ src/ManaCostHybrid.cpp\ src/MenuItem.cpp\ + src/ModRules.cpp\ src/MTGAbility.cpp\ src/MTGCard.cpp\ src/MTGCardInstance.cpp\ @@ -201,7 +204,7 @@ HEADERS += \ include/ThisDescriptor.h\ include/CardGui.h\ include/GameStateTransitions.h\ - include/IconButton.h\ + include/IconButton.h\ include/OptionItem.h\ include/Token.h\ include/CardPrimitive.h\ @@ -257,7 +260,9 @@ HEADERS += \ include/Navigator.h\ include/DeckEditorMenu.h\ include/PlayRestrictions.h\ - include/NetworkPlayer.h + include/NetworkPlayer.h\ + include/ModRules.h\ + include/AIHints.h\ # JGE, could probably be moved outside SOURCES += \