diff --git a/JGE/Dependencies/lib/libjpeg-static-mt-debug.pdb b/JGE/Dependencies/lib/libjpeg-static-mt-debug.pdb deleted file mode 100644 index 5e7dbba29..000000000 Binary files a/JGE/Dependencies/lib/libjpeg-static-mt-debug.pdb and /dev/null differ diff --git a/JGE/Dependencies/lib/libjpeg-static-mt.pdb b/JGE/Dependencies/lib/libjpeg-static-mt.pdb deleted file mode 100644 index 0c108332a..000000000 Binary files a/JGE/Dependencies/lib/libjpeg-static-mt.pdb and /dev/null differ diff --git a/JGE/JGE.vcxproj b/JGE/JGE.vcxproj index 567c398e3..7dfb4c68c 100644 --- a/JGE/JGE.vcxproj +++ b/JGE/JGE.vcxproj @@ -156,6 +156,7 @@ + @@ -298,6 +299,7 @@ + diff --git a/JGE/include/DebugRoutines.h b/JGE/include/DebugRoutines.h index 944d4e7a1..861f24277 100644 --- a/JGE/include/DebugRoutines.h +++ b/JGE/include/DebugRoutines.h @@ -32,7 +32,7 @@ std::string ToHex(T* pointer) #define DebugTrace(inString) \ { \ std::ostringstream stream; \ - stream << inString; \ + stream << inString << std::endl; \ qDebug("%s", stream.str().c_str()); \ } #elif defined (ANDROID) @@ -48,7 +48,7 @@ std::string ToHex(T* pointer) { \ std::ostringstream stream; \ stream << inString << std::endl; \ - OutputDebugString(stream.str().c_str()); \ + OutputDebugStringA(stream.str().c_str()); \ } #endif // QT_CONFIG #endif // Win32, Linux diff --git a/JGE/include/JRenderer.h b/JGE/include/JRenderer.h index 0a7b264e3..d132e9718 100644 --- a/JGE/include/JRenderer.h +++ b/JGE/include/JRenderer.h @@ -16,7 +16,7 @@ #include #include -#if (!defined IOS) && (!defined ANDROID) && (!defined QT_CONFIG) +#if (!defined IOS) && (!defined ANDROID) && (!defined QT_CONFIG) && (!defined WP8) #include #endif //IOS ANDROID @@ -24,9 +24,7 @@ #if defined (WIN32) - #include - #elif defined (PSP) #include @@ -53,7 +51,7 @@ #define COSF(x) cosf(x*DEG2RAD) #endif -#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32) +#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || ((defined WIN32) && !defined(WP8)) typedef struct { GLfloat m[4][4]; @@ -68,18 +66,23 @@ class JRenderer { protected: - JRenderer(); - ~JRenderer(); - void InitRenderer(); - void DestroyRenderer(); + JRenderer(); + ~JRenderer(); + void InitRenderer(); + void DestroyRenderer(); - float mActualWidth; - float mActualHeight; + float mWindowWidth; + float mWindowHeight; + + float mLeft; + float mTop; + float mRight; + float mBottom; public: #if defined (PSP) - int PixelSize(int textureMode); + int PixelSize(int textureMode); #endif ////////////////////////////////////////////////////////////////////////// @@ -529,28 +532,44 @@ public: ////////////////////////////////////////////////////////////////////////// void SetImageFilter(JImageFilter* imageFilter); - /** + ////////////////////////////////////////////////////////////////////////// + /// To be called each time the containing window size changes. + /// + /// @param window - pointer to some platform specific window object. + /// @param inWidth - new width of the window. + /// @param inHeight - new height of the window. + /// + ////////////////////////////////////////////////////////////////////////// + void OnWindowsSizeChanged(void* window, float inWidth, float inHeight); + +/** ** Set/Get methods for the actual display screen size. - */ - inline void SetActualWidth(float inWidth) - { - mActualWidth = inWidth; - } + */ + inline void SetViewPort(float inLeft, float inTop, float inRight, float inBottom) + { + mLeft = inLeft; + mTop = inTop; + mRight = inRight; + mBottom = inBottom; + } - inline void SetActualHeight(float inHeight) - { - mActualHeight = inHeight; - } + inline void GetViewPort(float& outLeft, float& outTop, float& outRight, float& outBottom) + { + outLeft = mLeft; + outTop = mTop; + outRight = mRight; + outBottom = mBottom; + } - inline float GetActualWidth() - { - return mActualWidth; - } + inline float GetActualWidth() + { + return (mRight - mLeft); + } - inline float GetActualHeight() - { - return mActualHeight; - } + inline float GetActualHeight() + { + return (mBottom - mTop); + } private: @@ -564,10 +583,10 @@ private: bool mVRAM; }; -#if (!defined IOS) && (!defined QT_CONFIG) +#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) && (!defined QT_CONFIG) +#if (!defined ANDROID) && (!defined QT_CONFIG) && (!defined WP8) void LoadGIF(TextureInfo &textureInfo, const char *filename, int mode = 0, int TextureFormat = TEXTURE_FORMAT); int image_readgif(void * handle, TextureInfo &textureInfo, DWORD * bgcolor, InputFunc readFunc,int mode = 0, int TextureFormat = TEXTURE_FORMAT); #endif // (ANDROID) How can we get gif support for android ? @@ -575,41 +594,52 @@ private: static JRenderer* mInstance; -#if (!defined PSP) +#ifdef WP8 + Microsoft::WRL::ComPtr m_d3dDevice; + Microsoft::WRL::ComPtr m_d3dContext; + D3D_FEATURE_LEVEL m_featureLevel; + Microsoft::WRL::ComPtr m_swapChain; + Microsoft::WRL::ComPtr m_renderTargetView; + Microsoft::WRL::ComPtr m_depthStencilView; + Microsoft::WRL::ComPtr m_Window; + ID3D11Buffer* m_vertexBuffer; + ID3D11Buffer* m_indexBuffer; + +#elif (!defined PSP) && (!defined WP8) && (!defined CONSOLE_CONFIG) GLuint mCurrentTex; -#if ((defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32)) && (!defined CONSOLE_CONFIG) - // MVP matrix - ESMatrix theMvpMatrix; +#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32) + // MVP matrix + ESMatrix theMvpMatrix; - // Handle to a program object - GLuint prog1; - // Attribute locations - GLint prog1_positionLoc; - GLint prog1_colorLoc; - // Uniform locations - GLint prog1_mvpLoc; + // Handle to a program object + GLuint prog1; + // Attribute locations + GLint prog1_positionLoc; + GLint prog1_colorLoc; + // Uniform locations + GLint prog1_mvpLoc; - // Handle to a program object - GLuint prog2; - // Sampler location - GLint prog2_samplerLoc; - // Attribute locations - GLint prog2_positionLoc; - GLint prog2_texCoordLoc; - GLint prog2_colorLoc; - // MVP matrix - ESMatrix prog2_mvpMatrix; - // Uniform locations - GLint prog2_mvpLoc; + // Handle to a program object + GLuint prog2; + // Sampler location + GLint prog2_samplerLoc; + // Attribute locations + GLint prog2_positionLoc; + GLint prog2_texCoordLoc; + GLint prog2_colorLoc; + // MVP matrix + ESMatrix prog2_mvpMatrix; + // Uniform locations + GLint prog2_mvpLoc; #endif // (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) -#else - void *fbp0, *fbp1, *zbp; - PIXEL_TYPE* mVRAM; - int mCurrentTex; - int mCurrentBlend; - int mCurrentTextureFormat; +#elif (defined PSP) + void *fbp0, *fbp1, *zbp; + PIXEL_TYPE* mVRAM; + int mCurrentTex; + int mCurrentBlend; + int mCurrentTextureFormat; #endif bool mVsync; diff --git a/JGE/include/JSocket.h b/JGE/include/JSocket.h index ab8bb2934..4ef762e41 100644 --- a/JGE/include/JSocket.h +++ b/JGE/include/JSocket.h @@ -1,8 +1,6 @@ #ifndef _JSOCKET_H_ #define _JSOCKET_H_ -#include -#include "Threading.h" using namespace std; #define SERVER_PORT 5001 diff --git a/JGE/include/JTypes.h b/JGE/include/JTypes.h index 9a2c9c594..3f479fb1c 100644 --- a/JGE/include/JTypes.h +++ b/JGE/include/JTypes.h @@ -31,6 +31,13 @@ #endif +#ifdef WP8 +#define _XM_NO_INTRINSICS_ +#include +#include +#include +#endif + #ifndef __GNUC__ #define __attribute__(arg) #endif @@ -39,10 +46,10 @@ #define MAX_CHANNEL 128 enum { - JGE_ERR_CANT_OPEN_FILE = -1, - JGE_ERR_PNG = -2, - JGE_ERR_MALLOC_FAILED = -4, - JGE_ERR_GENERIC = -5, + JGE_ERR_CANT_OPEN_FILE = -1, + JGE_ERR_PNG = -2, + JGE_ERR_MALLOC_FAILED = -4, + JGE_ERR_GENERIC = -5, }; #ifdef PSP @@ -74,44 +81,43 @@ enum { #define SCREEN_WIDTH_F 480.0f #define SCREEN_HEIGHT_F 272.0f - #ifdef CONSOLE_CONFIG -#define DEFAULT_BLEND 0 -#define BLEND_OPTION_ADD 0 -#define BLEND_OPTION_BLEND 0 -#define BLEND_ZERO 0 -#define BLEND_ONE 0 -#define BLEND_SRC_COLOR 0 -#define BLEND_ONE_MINUS_SRC_COLOR 0 -#define BLEND_SRC_ALPHA 0 -#define BLEND_ONE_MINUS_SRC_ALPHA 0 -#define BLEND_DST_ALPHA 0 -#define BLEND_ONE_MINUS_DST_ALPHA 0 -#define BLEND_DST_COLOR 0 -#define BLEND_ONE_MINUS_DST_COLOR 0 -#define BLEND_SRC_ALPHA_SATURATE 0 -#define GU_PSM_5551 0 +#define DEFAULT_BLEND 0 +#define BLEND_OPTION_ADD 0 +#define BLEND_OPTION_BLEND 0 +#define BLEND_ZERO 0 +#define BLEND_ONE 0 +#define BLEND_SRC_COLOR 0 +#define BLEND_ONE_MINUS_SRC_COLOR 0 +#define BLEND_SRC_ALPHA 0 +#define BLEND_ONE_MINUS_SRC_ALPHA 0 +#define BLEND_DST_ALPHA 0 +#define BLEND_ONE_MINUS_DST_ALPHA 0 +#define BLEND_DST_COLOR 0 +#define BLEND_ONE_MINUS_DST_COLOR 0 +#define BLEND_SRC_ALPHA_SATURATE 0 +#define GU_PSM_5551 0 #else #ifdef WIN32 // #define DEFAULT_BLEND BLEND_DEFAULT // #define BLEND_OPTION_ADD BLEND_COLORADD // #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE) #else -#define DEFAULT_BLEND GU_TFX_MODULATE -#define BLEND_OPTION_ADD GU_TFX_ADD -#define BLEND_OPTION_BLEND GU_TFX_BLEND + #define DEFAULT_BLEND GU_TFX_MODULATE + #define BLEND_OPTION_ADD GU_TFX_ADD + #define BLEND_OPTION_BLEND GU_TFX_BLEND #endif #endif // CONSOLE_CONFIG -#if (defined WIN32) && (!defined LINUX) +#if ((defined WIN32) || (defined WP8)) && (!defined LINUX) #include #endif #if defined(LINUX) && (!defined WIN32) || defined(IOS) || defined (ANDROID) -typedef uint8_t byte; -typedef uint32_t DWORD; -typedef uint8_t BYTE; + typedef uint8_t byte; + typedef uint32_t DWORD; + typedef uint8_t BYTE; #ifndef IOS -typedef bool BOOL; + typedef bool BOOL; #endif #endif @@ -122,25 +128,26 @@ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; #define PIXEL_TYPE DWORD -#define ARGB(a, r, g, b) ((PIXEL_TYPE)((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) -#define RGBA(r, g, b, a) ((PIXEL_TYPE)((a) << 24) | ((b) << 16) | ((g) << 8) | (r)) -#define TEXTURE_FORMAT 0 - +#define ARGB(a, r, g, b) ((PIXEL_TYPE)((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) +#define RGBA(r, g, b, a) ((PIXEL_TYPE)((a) << 24) | ((b) << 16) | ((g) << 8) | (r)) +#ifndef PSP +#define TEXTURE_FORMAT 0 +#endif //PSP #ifndef CONSOLE_CONFIG #ifndef QT_CONFIG #if defined (IOS) -#import -#import -#import -#import + #import + #import + #import + # import #elif defined (ANDROID) -#include -#include -#elif defined (WIN32) || defined (LINUX) -#include -#include + #include + #include +#elif (defined (WIN32) && !defined (WP8)) || defined (LINUX) + #include + #include #endif #else # include @@ -158,117 +165,159 @@ typedef uint32_t u32; #if defined (PSP) -#ifndef ABGR8888 -#define ABGR8888 -#endif + #ifndef ABGR8888 + #define ABGR8888 + #endif -#if defined (ABGR8888) -#define PIXEL_TYPE u32 -#ifndef ARGB -#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format -#endif -#define MAKE_COLOR(a, c) (a << 24 | c) -#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels -#define MASK_BLUE 0x00FF0000 -#define MASK_GREEN 0x0000FF00 -#define MASK_RED 0x000000FF + #if defined (ABGR8888) + #define PIXEL_TYPE u32 + #ifndef ARGB + #define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format + #endif + #define MAKE_COLOR(a, c) (a << 24 | c) + #define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels + #define MASK_BLUE 0x00FF0000 + #define MASK_GREEN 0x0000FF00 + #define MASK_RED 0x000000FF -#define PIXEL_SIZE 4 -#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888 + #define PIXEL_SIZE 4 + #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888 -#define BUFFER_FORMAT GU_PSM_8888 -#define TEXTURE_FORMAT GU_PSM_8888 -#define TEXTURE_COLOR_FORMAT GU_COLOR_8888 + #define BUFFER_FORMAT GU_PSM_8888 + #define TEXTURE_FORMAT GU_PSM_8888 + #define TEXTURE_COLOR_FORMAT GU_COLOR_8888 -#elif defined (ABGR5551) + #elif defined (ABGR5551) -#ifndef ARGB -#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15)) -#endif -#define MAKE_COLOR(a, c) (((a>>7)<<15) | c) -#define MASK_ALPHA 0x8000 -#define MASK_BLUE 0x7C00 -#define MASK_GREEN 0x03E0 -#define MASK_RED 0x001F -#define PIXEL_TYPE u16 -#define PIXEL_SIZE 2 -#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551 + #ifndef ARGB + #define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15)) + #endif + #define MAKE_COLOR(a, c) (((a>>7)<<15) | c) + #define MASK_ALPHA 0x8000 + #define MASK_BLUE 0x7C00 + #define MASK_GREEN 0x03E0 + #define MASK_RED 0x001F + #define PIXEL_TYPE u16 + #define PIXEL_SIZE 2 + #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551 -#define BUFFER_FORMAT GU_PSM_8888 -#define TEXTURE_FORMAT GU_PSM_5551 -#define TEXTURE_COLOR_FORMAT GU_COLOR_5551 + #define BUFFER_FORMAT GU_PSM_8888 + #define TEXTURE_FORMAT GU_PSM_5551 + #define TEXTURE_COLOR_FORMAT GU_COLOR_5551 -#elif defined (ABGR4444) -#ifndef ARGB -#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12)) -#endif -#define MAKE_COLOR(a, c) (((a>>4)<<12) | c) -#define MASK_ALPHA 0xF000 -#define MASK_BLUE 0x0F00 -#define MASK_GREEN 0x00F0 -#define MASK_RED 0x000F -#define PIXEL_TYPE u16 -#define PIXEL_SIZE 2 -#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444 + #elif defined (ABGR4444) + #ifndef ARGB + #define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12)) + #endif + #define MAKE_COLOR(a, c) (((a>>4)<<12) | c) + #define MASK_ALPHA 0xF000 + #define MASK_BLUE 0x0F00 + #define MASK_GREEN 0x00F0 + #define MASK_RED 0x000F + #define PIXEL_TYPE u16 + #define PIXEL_SIZE 2 + #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444 -#define BUFFER_FORMAT GU_PSM_4444 -#define TEXTURE_FORMAT GU_PSM_4444 -#define TEXTURE_COLOR_FORMAT GU_COLOR_4444 + #define BUFFER_FORMAT GU_PSM_4444 + #define TEXTURE_FORMAT GU_PSM_4444 + #define TEXTURE_COLOR_FORMAT GU_COLOR_4444 -#endif + #endif -#define FRAME_BUFFER_WIDTH 512 -#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE + #define FRAME_BUFFER_WIDTH 512 + #define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE -#define SLICE_SIZE_F 64.0f -typedef unsigned int DWORD; + #define SLICE_SIZE_F 64.0f + typedef unsigned int DWORD; -#define BLEND_ZERO 0x1000 -#define BLEND_ONE 0x1002 -#define BLEND_SRC_COLOR GU_SRC_COLOR -#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR -#define BLEND_SRC_ALPHA GU_SRC_ALPHA -#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA -#define BLEND_DST_ALPHA GU_DST_ALPHA -#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA -#define BLEND_DST_COLOR GU_DST_COLOR -#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR -#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE + #define BLEND_ZERO 0x1000 + #define BLEND_ONE 0x1002 + #define BLEND_SRC_COLOR GU_SRC_COLOR + #define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR + #define BLEND_SRC_ALPHA GU_SRC_ALPHA + #define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA + #define BLEND_DST_ALPHA GU_DST_ALPHA + #define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA + #define BLEND_DST_COLOR GU_DST_COLOR + #define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR + #define BLEND_SRC_ALPHA_SATURATE BLEND_ONE -typedef struct -{ - ScePspFVector2 texture; - ScePspFVector3 pos; -} PSPVertex3D; + typedef struct + { + ScePspFVector2 texture; + ScePspFVector3 pos; + } PSPVertex3D; -#else //non PSP +#elif !defined(WP8) //non PSP - -#define BLEND_ZERO GL_ZERO -#define BLEND_ONE GL_ONE -#define BLEND_SRC_COLOR GL_SRC_COLOR -#define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR -#define BLEND_SRC_ALPHA GL_SRC_ALPHA -#define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA -#define BLEND_DST_ALPHA GL_DST_ALPHA -#define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA -#define BLEND_DST_COLOR GL_DST_COLOR -#define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR -#define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE + #define BLEND_ZERO GL_ZERO + #define BLEND_ONE GL_ONE + #define BLEND_SRC_COLOR GL_SRC_COLOR + #define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR + #define BLEND_SRC_ALPHA GL_SRC_ALPHA + #define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + #define BLEND_DST_ALPHA GL_DST_ALPHA + #define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA + #define BLEND_DST_COLOR GL_DST_COLOR + #define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR + #define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE #define GU_PSM_8888 0 #define GU_PSM_5551 0 #define GU_PSM_4444 0 #define GU_PSM_5650 0 +#else // WP8 + #define BLEND_ZERO 0 + #define BLEND_ONE 0 + #define BLEND_SRC_COLOR 0 + #define BLEND_ONE_MINUS_SRC_COLOR 0 + #define BLEND_SRC_ALPHA 0 + #define BLEND_ONE_MINUS_SRC_ALPHA 0 + #define BLEND_DST_ALPHA 0 + #define BLEND_ONE_MINUS_DST_ALPHA 0 + #define BLEND_DST_COLOR 0 + #define BLEND_ONE_MINUS_DST_COLOR 0 + #define BLEND_SRC_ALPHA_SATURATE 0 + #define TEXTURE_FORMAT 0 + #define GU_PSM_8888 0 + #define GU_PSM_5551 0 + #define GU_PSM_4444 0 + #define GU_PSM_5650 0 #endif #else typedef uint32_t GLuint; typedef float GLfloat; #endif //CONSOLE_CONFIG + +typedef enum Buttons + { + JGE_BTN_NONE = 0, // No button pressed + JGE_BTN_QUIT, // Home on PSP + JGE_BTN_MENU, // Start on PSP + JGE_BTN_CTRL, // Select + JGE_BTN_POWER, // Hold + JGE_BTN_SOUND, // Music note + JGE_BTN_RIGHT, + JGE_BTN_LEFT, + JGE_BTN_UP, + JGE_BTN_DOWN, + JGE_BTN_OK, // Circle in Japan, Cross in Europe + JGE_BTN_CANCEL, // Triangle + JGE_BTN_PRI, // Square (primary) + JGE_BTN_SEC, // Cross or Circle (secondary) + JGE_BTN_PREV, // Left trigger + JGE_BTN_NEXT, // Right trigger + JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only) + + JGE_BTN_MAX = JGE_BTN_FULLSCREEN + 1 + } JButton; + + + //------------------------------------------------------------------------------------------------ struct Vertex { @@ -352,11 +401,14 @@ public: int mFilter; -#if defined (PSP) +#if defined (PSP) int mTextureFormat; int mTexId; bool mInVideoRAM; PIXEL_TYPE* mBits; +#elif defined (WP8) + ID3D11Texture2D* mTexId; + u8* mBuffer; #else GLuint mTexId; u8* mBuffer; @@ -537,28 +589,5 @@ public: }; -typedef enum Buttons - { - JGE_BTN_NONE = 0, // No button pressed - JGE_BTN_QUIT, // Home on PSP - JGE_BTN_MENU, // Start on PSP - JGE_BTN_CTRL, // Select - JGE_BTN_POWER, // Hold - JGE_BTN_SOUND, // Music note - JGE_BTN_RIGHT, - JGE_BTN_LEFT, - JGE_BTN_UP, - JGE_BTN_DOWN, - JGE_BTN_OK, // Circle in Japan, Cross in Europe - JGE_BTN_CANCEL, // Triangle - JGE_BTN_PRI, // Square (primary) - JGE_BTN_SEC, // Cross or Circle (secondary) - JGE_BTN_PREV, // Left trigger - JGE_BTN_NEXT, // Right trigger - JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only) - - JGE_BTN_MAX = JGE_BTN_FULLSCREEN + 1 - } JButton; - #endif diff --git a/JGE/include/Threading.h b/JGE/include/Threading.h index fe3c79068..916f228d0 100644 --- a/JGE/include/Threading.h +++ b/JGE/include/Threading.h @@ -1,7 +1,7 @@ #ifndef THREADING_H #define THREADING_H -#if !defined(PSP) && !defined(QT_CONFIG) +#if !defined(PSP) && !defined(QT_CONFIG) && !defined(WP8) #include #ifdef WIN32 @@ -14,7 +14,7 @@ #endif #include -#elif !defined(QT_CONFIG) +#elif defined(PSP) #include #include @@ -538,6 +538,80 @@ namespace boost } } +#elif defined(WP8) + +#include +#include + +namespace boost +{ + typedef std::thread thread; + + 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(); + } + + std::mutex mQMutex; + + private: + mutex(mutex const&); + mutex& operator=(mutex const&); + }; + + 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) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time)); + } + } +} + #endif #endif // THREADING_H diff --git a/JGE/include/corewrapper.h b/JGE/include/corewrapper.h new file mode 100644 index 000000000..5cd0c199a --- /dev/null +++ b/JGE/include/corewrapper.h @@ -0,0 +1,88 @@ +#ifndef COREWRAPPER_H +#define COREWRAPPER_H + +#include "../include/JGE.h" +#include "../include/JTypes.h" +#include "../include/JApp.h" +#include "../include/JFileSystem.h" +#include "../include/JRenderer.h" +#include "../include/JGameLauncher.h" + +class WagicCore +{ +private: + +public: + explicit WagicCore(); + virtual ~WagicCore(); + void initApp(); + + void doOK() { + doAndEnqueue(JGE_BTN_OK); + }; + void doNext() { + doAndEnqueue(JGE_BTN_PREV); + }; + void doCancel() { + doAndEnqueue(JGE_BTN_SEC); + }; + void doMenu() { + doAndEnqueue(JGE_BTN_MENU); + }; + void done() { + while(m_buttonQueue.size()) + { + m_engine->ReleaseKey(m_buttonQueue.front()); + m_buttonQueue.pop(); + } + m_engine->ResetInput(); + }; + void doScroll(int x, int y) { + m_engine->Scroll(x, y); + }; + int getNominalHeight(){ return SCREEN_HEIGHT;}; + int getNominalWidth(){ return SCREEN_WIDTH;}; + float getNominalRatio() { return ((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);}; + bool getActive() { return m_active; }; + void setActive(bool active); + void onKeyDown(LocalKeySym); + void onKeyUp(LocalKeySym); + void onWindowResize(void* window, float width, float height); + void onWheelChanged(int deltaX, int deltaY); + static char* getApplicationName() { + return JGameLauncher::GetName(); + }; + + typedef enum { + LEFT, + MIDLE, + RIGHT + } PointerId; + + bool onPointerPressed(PointerId, int, int); + bool onPointerReleased(PointerId, int, int); + bool onPointerMoved(PointerId, int, int); + bool onUpdate(); + bool onRender(); + void registerDefaultBindings(); + static WagicCore* getInstance() { return s_instance; }; + char *GetName(){ return m_launcher->GetName();}; + +private: + void doAndEnqueue(JButton action) { + m_engine->HoldKey_NoRepeat(action); + m_buttonQueue.push(action); + } + +private: + static WagicCore* s_instance; + JGE* m_engine; + JApp* m_app; + JGameLauncher* m_launcher; + int64_t m_lastTickCount; + std::queue m_buttonQueue; + bool m_active; +}; + + +#endif // COREWRAPPER_H diff --git a/JGE/include/qt/corewrapper.h b/JGE/include/qt/qtcorewrapper.h similarity index 72% rename from JGE/include/qt/corewrapper.h rename to JGE/include/qt/qtcorewrapper.h index 962f91bd4..a8c065bd9 100644 --- a/JGE/include/qt/corewrapper.h +++ b/JGE/include/qt/qtcorewrapper.h @@ -1,5 +1,7 @@ -#ifndef COREWRAPPER_H -#define COREWRAPPER_H +#ifndef QTCOREWRAPPER_H +#define QTCOREWRAPPER_H + +#include "../include/corewrapper.h" #include #include @@ -7,12 +9,6 @@ #include #include #endif //QT_WIDGET -#include "../include/JGE.h" -#include "../include/JTypes.h" -#include "../include/JApp.h" -#include "../include/JFileSystem.h" -#include "../include/JRenderer.h" -#include "../include/JGameLauncher.h" #if (defined Q_WS_MAEMO_5) // For screen on/off events support @@ -23,23 +19,11 @@ #include #endif //Q_WS_MAEMO_5 -class WagicWrapper -{ -public: - WagicWrapper(); - virtual ~WagicWrapper(); - -private: - JGE* m_engine; - JApp* m_app; - JGameLauncher* m_launcher; -}; - #ifdef QT_WIDGET -class WagicCore : public QGLWidget +class QtWagicCore : public QGLWidget #else -class WagicCore : public QDeclarativeItem +class QtWagicCore : public QDeclarativeItem #endif { private: @@ -48,7 +32,6 @@ private: #else typedef QDeclarativeItem super; #endif //QT_WIDGET - void initApp(); public: Q_OBJECT @@ -59,36 +42,30 @@ public: public: - explicit WagicCore(super *parent = 0); - virtual ~WagicCore(); - static int runTestSuite(); + explicit QtWagicCore(super *parent = 0); + virtual ~QtWagicCore(); Q_INVOKABLE void doOK() { - doAndEnqueue(JGE_BTN_OK); + m_Wagic.doOK(); }; Q_INVOKABLE void doNext() { - doAndEnqueue(JGE_BTN_PREV); + m_Wagic.doNext(); }; Q_INVOKABLE void doCancel() { - doAndEnqueue(JGE_BTN_SEC); + m_Wagic.doCancel(); }; Q_INVOKABLE void doMenu() { - doAndEnqueue(JGE_BTN_MENU); + m_Wagic.doMenu(); }; Q_INVOKABLE void done() { - while(m_buttonQueue.size()) - { - m_engine->ReleaseKey(m_buttonQueue.front()); - m_buttonQueue.pop(); - } - m_engine->ResetInput(); + m_Wagic.done(); }; Q_INVOKABLE void pixelInput(int x, int y); Q_INVOKABLE qint64 getTick() { return g_startTimer.elapsed(); }; Q_INVOKABLE void doScroll(int x, int y, int) { - m_engine->Scroll(x, y); + m_Wagic.doScroll(x, y); }; int getNominalHeight(){ return SCREEN_HEIGHT;}; int getNominalWidth(){ return SCREEN_WIDTH;}; @@ -137,20 +114,14 @@ private slots: private: void timerEvent( QTimerEvent* ); - void doAndEnqueue(JButton action) { - m_engine->HoldKey_NoRepeat(action); - m_buttonQueue.push(action); - } public: // used mainly to mesure the delta between 2 updates static QElapsedTimer g_startTimer; private: - JGE* m_engine; - JApp* m_app; - JGameLauncher* m_launcher; + WagicCore m_Wagic; + qint64 m_lastTickCount; - std::queue m_buttonQueue; int m_timerId; bool m_active; QRect m_viewPort; @@ -171,4 +142,4 @@ private: QML_DECLARE_TYPE(WagicCore) #endif //QT_WIDGET -#endif // COREWRAPPER_H +#endif // QTCOREWRAPPER_H diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 3948dc4cc..6423b83d4 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -135,6 +135,15 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath) DebugTrace("User path " << userPath); DebugTrace("System path " << systemPath); DebugTrace("Current path " << QDir::currentPath().toStdString()); +#elif defined (WP8) + char buff[500]; + auto appInstallDirectory = Windows::ApplicationModel::Package::Current->InstalledLocation->Path; + WideCharToMultiByte(CP_ACP, 0, appInstallDirectory->Data(), -1, buff, appInstallDirectory->Length()+1, NULL, NULL); + systemPath = buff; + + auto localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path; + WideCharToMultiByte(CP_ACP, 0, localfolder->Data(), -1, buff, localfolder->Length()+1, NULL, NULL); + userPath = buff; #else //Find the Res.txt file and matching Res folders for backwards compatibility ifstream mfile("Res.txt"); diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index eb606f302..348c29db8 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -10,7 +10,7 @@ // Should we add PrecompiledHeader.h to more platforms here? PSP Doesn't support it in JGE (erwan 2011/12/11) -#if defined (IOS) || defined (ANDROID) +#if defined (IOS) || defined (ANDROID) || defined (WP8) #include "PrecompiledHeader.h" #endif diff --git a/JGE/src/JGfx-fake.cpp b/JGE/src/JGfx-fake.cpp index 917d1f7ab..9e02c51c7 100644 --- a/JGE/src/JGfx-fake.cpp +++ b/JGE/src/JGfx-fake.cpp @@ -117,7 +117,11 @@ void JRenderer::Destroy() } } -JRenderer::JRenderer() : mActualWidth(SCREEN_WIDTH_F), mActualHeight(SCREEN_HEIGHT_F) +JRenderer::JRenderer() : +mLeft(0.0f), +mRight(SCREEN_WIDTH_F), +mTop(0.0f), +mBottom(SCREEN_HEIGHT_F) { } @@ -136,7 +140,6 @@ void JRenderer::InitRenderer() mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA; // mLineWidth = 1.0f; - mCurrentTex = -1; mFOV = 75.0f; #ifdef USING_MATH_TABLE @@ -173,8 +176,6 @@ void JRenderer::EnableTextureFilter(bool flag) mCurrentTextureFilter = TEX_FILTER_LINEAR; else mCurrentTextureFilter = TEX_FILTER_NEAREST; - - mCurrentTex = -1; } void Swap(float *a, float *b) diff --git a/JGE/src/JLBFont.cpp b/JGE/src/JLBFont.cpp index 9e7426e96..e7c166d0d 100644 --- a/JGE/src/JLBFont.cpp +++ b/JGE/src/JLBFont.cpp @@ -8,7 +8,9 @@ // //------------------------------------------------------------------------------------- - +#if defined (IOS) || defined (ANDROID) || defined (WP8) +#include "PrecompiledHeader.h" +#endif #include "../include/JLBFont.h" #include "../include/JFileSystem.h" diff --git a/JGE/src/JNetwork.cpp b/JGE/src/JNetwork.cpp index 769764a52..e33320489 100644 --- a/JGE/src/JNetwork.cpp +++ b/JGE/src/JNetwork.cpp @@ -4,13 +4,12 @@ */ -#include "../include/DebugRoutines.h" -#include "../include/JNetwork.h" - -#if defined (WIN32) || defined (LINUX) -#else +#if (defined WIN32) && (!defined QT_CONFIG) +#pragma comment(lib,"ws2_32.lib") +#include +#elif defined (LINUX) +#elif defined (PSP) #ifdef NETWORK_SUPPORT - #include #include #include @@ -29,9 +28,11 @@ #endif #endif +#include "../include/JNetwork.h" #include #include "../include/JSocket.h" +#include "../include/DebugRoutines.h" map JNetwork::sCommandMap; diff --git a/JGE/src/JSocket.cpp b/JGE/src/JSocket.cpp index 9d1e1dbdc..29e329005 100644 --- a/JGE/src/JSocket.cpp +++ b/JGE/src/JSocket.cpp @@ -19,7 +19,6 @@ #include #endif -#include "../include/JGE.h" #include "../include/JSocket.h" JSocket::JSocket(){ diff --git a/JGE/src/Qtmain.cpp b/JGE/src/Qtmain.cpp index 9aa849ead..c9b280600 100644 --- a/JGE/src/Qtmain.cpp +++ b/JGE/src/Qtmain.cpp @@ -11,35 +11,11 @@ #endif //QT_WIDGET #include "filedownloader.h" #include "GameApp.h" -#include "corewrapper.h" +#include "qtcorewrapper.h" QWidget* g_glwidget = NULL; -static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] = -{ - { Qt::Key_Enter, JGE_BTN_MENU }, - { Qt::Key_Return, JGE_BTN_MENU }, - { Qt::Key_Escape, JGE_BTN_MENU }, - { Qt::Key_Backspace, JGE_BTN_CTRL }, - { Qt::Key_Up, JGE_BTN_UP }, - { Qt::Key_Down, JGE_BTN_DOWN }, - { Qt::Key_Left, JGE_BTN_LEFT }, - { Qt::Key_Right, JGE_BTN_RIGHT }, - { Qt::Key_Space, JGE_BTN_OK }, - { Qt::Key_Tab, JGE_BTN_CANCEL }, - { Qt::Key_J, JGE_BTN_PRI }, - { Qt::Key_K, JGE_BTN_SEC }, - { Qt::Key_Q, JGE_BTN_PREV }, - { Qt::Key_A, JGE_BTN_NEXT }, -// fullscreen management seems somehow broken in JGE, it works fine with Qt directly -// { Qt::Key_F, JGE_BTN_FULLSCREEN }, -}; -void JGECreateDefaultBindings() -{ - for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) - JGE::BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode); -} bool JGEToggleFullscreen() { @@ -54,11 +30,6 @@ bool JGEToggleFullscreen() return true; } -int JGEGetTime() -{ - return (int)WagicCore::g_startTimer.elapsed(); -} - int main(int argc, char* argv[]) { QScopedPointer app @@ -69,17 +40,10 @@ int main(int argc, char* argv[]) #endif //QT_WIDGET - if(argc >= 2 && strcmp(argv[1], "testsuite")==0) - { - int result = 0; - result += WagicCore::runTestSuite(); - return result; - } - - app->setApplicationName(WagicCore::getApplicationName()); + app->setApplicationName(QtWagicCore::getApplicationName()); FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME); #ifdef QT_WIDGET - g_glwidget = new WagicCore(); + g_glwidget = new QtWagicCore(); g_glwidget->connect(&fileDownloader, SIGNAL(finished(int)), SLOT(start(int))); #else qmlRegisterType("CustomComponents", 1, 0, "WagicCore"); diff --git a/JGE/src/SDLmain.cpp b/JGE/src/SDLmain.cpp index d3323890d..7b6e1cd71 100644 --- a/JGE/src/SDLmain.cpp +++ b/JGE/src/SDLmain.cpp @@ -15,6 +15,7 @@ #include "../include/JRenderer.h" #include "../include/JGameLauncher.h" #include "DebugRoutines.h" +#include "corewrapper.h" #include #include #include @@ -47,9 +48,7 @@ const int kTapEventTimeout = 250; uint64_t lastTickCount; -JGE* g_engine = NULL; -JApp* g_app = NULL; -JGameLauncher* g_launcher = NULL; + #ifdef ANDROID JNIEnv * mJNIEnv = NULL; jclass * mJNIClass = NULL; @@ -66,19 +65,15 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativePause( JNIEnv* env, jclass cls) { DebugTrace("Attempt pause"); - if (!g_engine) - return; - g_engine->Pause(); - DebugTrace("Pause done"); + WagicCore::getInstance()->setActive(false); + DebugTrace("Pause done"); } // Resume extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume( JNIEnv* env, jclass cls) { - if (!g_engine) - return; - g_engine->Resume(); + WagicCore::getInstance()->setActive(true); } #endif @@ -89,7 +84,7 @@ public: /* For easy interfacing with JGE static functions */ bool Running; SDL_Window* window; SDL_Surface* Surf_Display; - SDL_Rect viewPort; +// SDL_Rect viewPort; Uint32 lastMouseUpTime; Uint32 lastFingerDownTime; int windowed_w; @@ -99,6 +94,7 @@ public: /* For easy interfacing with JGE static functions */ int mMouseDownX; int mMouseDownY; + WagicCore m_Wagic; public: SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), lastFingerDownTime(0), Running(true), mMouseDownX(0), mMouseDownY(0) @@ -116,16 +112,13 @@ public: while(Running) { - if (g_engine) + for (int x = 0; x < 5 && SDL_WaitEventTimeout(&Event, 10); ++x) { - for (int x = 0; x < 5 && SDL_WaitEventTimeout(&Event, 10); ++x) - { - if(!g_engine->IsPaused()) - OnEvent(&Event); - } - if(!g_engine->IsPaused()) - OnUpdate(); + if(m_Wagic.getActive()) + OnEvent(&Event); } + if(m_Wagic.getActive()) + OnUpdate(); } OnCleanup(); @@ -138,44 +131,7 @@ public: void OnResize(int width, int height) { - DebugTrace("OnResize Width " << width << " height " << height); - - if ((GLfloat)width / (GLfloat)height <= ACTUAL_RATIO) - { - viewPort.x = 0; - viewPort.y = -(static_cast(width / ACTUAL_RATIO) - height) / 2; - viewPort.w = width; - viewPort.h = static_cast(width / ACTUAL_RATIO); - } - else - { - viewPort.x = -(static_cast(height * ACTUAL_RATIO) - width) / 2; - viewPort.y = 0; - viewPort.w = static_cast(height * ACTUAL_RATIO); - viewPort.h = height; - } - - glViewport(viewPort.x, viewPort.y, viewPort.w, viewPort.h); - - JRenderer::GetInstance()->SetActualWidth(static_cast(viewPort.w)); - JRenderer::GetInstance()->SetActualHeight(static_cast(viewPort.h)); - glScissor(0, 0, width, height); - -#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - - glMatrixMode (GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity (); // Reset The Projection Matrix - -#if (defined GL_VERSION_ES_CM_1_1) - glOrthof(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f, -1.0f, 1.0f); -#else - gluOrtho2D(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f); -#endif - glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity (); // Reset The Modelview Matrix - - glDisable (GL_DEPTH_TEST); -#endif + m_Wagic.onWindowResize((void*)0, (float)width, (float)height); } void OnKeyPressed(const SDL_KeyboardEvent& event); @@ -254,7 +210,7 @@ public: case SDL_JOYBALLMOTION: DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel); - g_engine->Scroll(Event->jball.xrel, Event->jball.yrel); + m_Wagic.onWheelChanged(Event->jball.xrel, Event->jball.yrel); break; } } @@ -268,56 +224,6 @@ public: } }; -static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] = -{ - /* windows controls */ - { SDLK_LCTRL, JGE_BTN_CTRL }, - { SDLK_RCTRL, JGE_BTN_CTRL }, - { SDLK_RETURN, JGE_BTN_MENU }, - { SDLK_KP_ENTER, JGE_BTN_MENU }, - { SDLK_ESCAPE, JGE_BTN_MENU }, - { SDLK_UP, JGE_BTN_UP }, - { SDLK_DOWN, JGE_BTN_DOWN }, - { SDLK_LEFT, JGE_BTN_LEFT }, - { SDLK_RIGHT, JGE_BTN_RIGHT }, - { SDLK_z, JGE_BTN_UP }, - { SDLK_d, JGE_BTN_RIGHT }, - { SDLK_s, JGE_BTN_DOWN }, - { SDLK_q, JGE_BTN_LEFT }, - { SDLK_a, JGE_BTN_PREV }, - { SDLK_e, JGE_BTN_NEXT }, - { SDLK_i, JGE_BTN_CANCEL }, - { SDLK_l, JGE_BTN_OK }, - { SDLK_SPACE, JGE_BTN_OK }, - { SDLK_k, JGE_BTN_SEC }, - { SDLK_j, JGE_BTN_PRI }, - { SDLK_f, JGE_BTN_FULLSCREEN }, - - /* old Qt ones, basically modified to comply with the N900 keyboard - { SDLK_a, JGE_BTN_NEXT }, - { SDLK_TAB, JGE_BTN_CANCEL }, - { SDLK_q, JGE_BTN_PREV }, - { SDLK_BACKSPACE, JGE_BTN_CTRL }, - */ - - /* Android customs */ - { SDLK_AC_BACK, JGE_BTN_MENU }, - /* Android/maemo volume button mapping */ - { SDLK_VOLUMEUP, JGE_BTN_PREV }, - { SDLK_VOLUMEDOWN, JGE_BTN_SEC}, -}; - -void JGECreateDefaultBindings() -{ - for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) - g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode); -} - -int JGEGetTime() -{ - return (int)SDL_GetTicks(); -} - bool JGEToggleFullscreen() { //cycle between the display modes @@ -365,70 +271,11 @@ bool JGEToggleFullscreen() return true; } -bool InitGame(void) -{ - g_engine = JGE::GetInstance(); - g_app = g_launcher->GetGameApp(); - g_app->Create(); - g_engine->SetApp(g_app); -#ifdef ANDROID - DebugTrace("Can I Set JNI Params ?"); - if (mJNIEnv) - DebugTrace("mJNIEnv is ok"); - if (mJNIEnv && mJNIClass) - { - DebugTrace("Setting JNI Params"); - g_engine->SetJNIEnv(mJNIEnv, *mJNIClass); - } -#endif - - JRenderer::GetInstance()->Enable2D(); - lastTickCount = JGEGetTime(); - - return true; -} - -void DestroyGame(void) -{ - g_engine->SetApp(NULL); - if (g_app) - { - g_app->Destroy(); - delete g_app; - g_app = NULL; - } - - JGE::Destroy(); - - g_engine = NULL; -} - void SdlApp::OnUpdate() { - static int tickCount = 0; - tickCount = JGEGetTime(); - int64_t dt = (tickCount - lastTickCount); - lastTickCount = tickCount; - - if(g_engine->IsDone()) - { - SDL_Event event; - event.user.type = SDL_QUIT; - SDL_PushEvent(&event); - } - - try - { - g_engine->SetDelta((float)dt / 1000.0f); - g_engine->Update((float)dt / 1000.0f); - } - catch(out_of_range& oor) - { - cerr << oor.what(); - } - - if(g_engine) - g_engine->Render(); + Running = m_Wagic.onUpdate(); + if(Running) + m_Wagic.onRender(); SDL_GL_SwapBuffers(); } @@ -437,28 +284,17 @@ void SdlApp::OnKeyPressed(const SDL_KeyboardEvent& event) { if (event.type == SDL_KEYDOWN) { - g_engine->HoldKey_NoRepeat((LocalKeySym)event.keysym.sym); + m_Wagic.onKeyDown((LocalKeySym)event.keysym.sym); } else if(event.type == SDL_KEYUP) { - g_engine->ReleaseKey((LocalKeySym)event.keysym.sym); + m_Wagic.onKeyUp((LocalKeySym)event.keysym.sym); } } void SdlApp::OnMouseMoved(const SDL_MouseMotionEvent& event) { - int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); - int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); - - if (event.y >= viewPort.y && - event.y <= viewPort.y + viewPort.h && - event.x >= viewPort.x && - event.x <= viewPort.x + viewPort.w) - { - g_engine->LeftClicked( - ((event.x-viewPort.x)*SCREEN_WIDTH)/actualWidth, - ((event.y-viewPort.y)*SCREEN_HEIGHT)/actualHeight); - } + m_Wagic.onPointerMoved(WagicCore::LEFT, event.x, event.y); } void SdlApp::OnMouseDoubleClicked(const SDL_MouseButtonEvent& event) @@ -473,6 +309,9 @@ void SdlApp::OnMouseDoubleClicked(const SDL_MouseButtonEvent& event) void SdlApp::OnMouseWheel(int x, int y) { + m_Wagic.onWheelChanged(x, y); + + /* if(!x && y) { // Vertical wheel if(y > 0) @@ -491,7 +330,7 @@ void SdlApp::OnMouseWheel(int x, int y) else { g_engine->HoldKey_NoRepeat(JGE_BTN_RIGHT); - } + }*/ } void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event) @@ -500,70 +339,30 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event) { if (event.button == SDL_BUTTON_LEFT) /* Left button */ { - // this is intended to convert window coordinate into game coordinate. - // this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong - int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); - int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); - - if (event.y >= viewPort.y && - event.y <= viewPort.y + viewPort.h && - event.x >= viewPort.x && - event.x <= viewPort.x + viewPort.w) - { - g_engine->LeftClicked( - ((event.x-viewPort.x)*SCREEN_WIDTH)/actualWidth, - ((event.y-viewPort.y)*SCREEN_HEIGHT)/actualHeight); -#if (!defined ANDROID) && (!defined IOS) - g_engine->HoldKey_NoRepeat(JGE_BTN_OK); -#endif - } - else if(event.y < viewPort.y) - { - g_engine->HoldKey_NoRepeat(JGE_BTN_MENU); - } - else if(event.y > viewPort.y + viewPort.h) - { - g_engine->HoldKey_NoRepeat(JGE_BTN_NEXT); - } + m_Wagic.onPointerPressed(WagicCore::LEFT, event.x, event.y); } else if(event.button == SDL_BUTTON_RIGHT) /* Right button */ - { /* next phase please */ - g_engine->HoldKey_NoRepeat(JGE_BTN_PREV); + { + m_Wagic.onPointerPressed(WagicCore::RIGHT, event.x, event.y); } else if(event.button == SDL_BUTTON_MIDDLE) /* Middle button */ - { /* interrupt please */ - g_engine->HoldKey_NoRepeat(JGE_BTN_SEC); + { + m_Wagic.onPointerPressed(WagicCore::MIDLE, event.x, event.y); } } else if (event.type == SDL_MOUSEBUTTONUP) { if(event.button == SDL_BUTTON_LEFT) { - if (event.y >= viewPort.y && - event.y <= viewPort.y + viewPort.h && - event.x >= viewPort.x && - event.x <= viewPort.x + viewPort.w) - { -#if (!defined ANDROID) && (!defined IOS) - g_engine->ReleaseKey(JGE_BTN_OK); -#endif - } - else if(event.y < viewPort.y) - { - g_engine->ReleaseKey(JGE_BTN_MENU); - } - else if(event.y > viewPort.y + viewPort.h) - { - g_engine->ReleaseKey(JGE_BTN_NEXT); - } + m_Wagic.onPointerReleased(WagicCore::LEFT, event.x, event.y); } else if(event.button == SDL_BUTTON_RIGHT) - { /* next phase please */ - g_engine->ReleaseKey(JGE_BTN_PREV); + { + m_Wagic.onPointerReleased(WagicCore::RIGHT, event.x, event.y); } else if(event.button == SDL_BUTTON_MIDDLE) - { /* interrupt please */ - g_engine->ReleaseKey(JGE_BTN_SEC); + { + m_Wagic.onPointerReleased(WagicCore::MIDLE, event.x, event.y); } } } @@ -574,44 +373,18 @@ void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event) // should be ignored, and will come through instead as a multigesture event if (event.fingerId == 0) { - if (event.y >= viewPort.y && - event.y <= viewPort.y + viewPort.h && - event.x >= viewPort.x && - event.x <= viewPort.x + viewPort.w) + if (event.type == SDL_FINGERDOWN) { - int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); - int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); - - Uint32 eventTime = SDL_GetTicks(); - if (event.type == SDL_FINGERDOWN) - { - mMouseDownX = event.x; - mMouseDownY = event.y; - - lastFingerDownTime = eventTime; - } - - -#if (defined ANDROID) || (defined IOS) - if (event.type == SDL_FINGERUP) - { - if (eventTime - lastFingerDownTime <= kTapEventTimeout) - { - // treat an up finger within 50 pixels of the down finger coords as a double click event - if (abs(mMouseDownX - event.x) < kHitzonePliancy && abs(mMouseDownY - event.y) < kHitzonePliancy) - { - DebugTrace("Pressing OK BUtton"); - g_engine->HoldKey_NoRepeat(JGE_BTN_OK); - } - } - } - else -#endif - g_engine->LeftClicked( - ((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth, - ((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight); - - } + m_Wagic.onPointerPressed(WagicCore::LEFT, event.x, event.y); + } + else if (event.type == SDL_FINGERUP) + { + m_Wagic.onPointerReleased(WagicCore::LEFT, event.x, event.y); + } + else + { + m_Wagic.onPointerMoved(WagicCore::LEFT, event.x, event.y); + } } } @@ -664,52 +437,9 @@ bool SdlApp::OnInit() #endif return false; } - SDL_WM_SetCaption(g_launcher->GetName(), ""); - - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers) -#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) -#if (defined GL_ES_VERSION_2_0) - glClearDepthf(1.0f); // Depth Buffer Setup -#else - glClearDepth(1.0f); // Depth Buffer Setup -#endif// (defined GL_ES_VERSION_2_0) - - 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) - 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 - glShadeModel(GL_SMOOTH); // Select Smooth Shading - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate - - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing - glEnable(GL_LINE_SMOOTH); // Enable it! - glEnable(GL_TEXTURE_2D); - -#endif - - glEnable(GL_CULL_FACE); // do not calculate inside of poly's - glFrontFace(GL_CCW); // counter clock-wise polygons are out - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_SCISSOR_TEST); // Enable Clipping - - JGECreateDefaultBindings(); - - if (!InitGame()) - { - cerr << "Could not init the game\n"; - return false; - } + SDL_WM_SetCaption(m_Wagic.GetName(), ""); + m_Wagic.initApp(); OnResize(window_w, window_h); return true; @@ -732,27 +462,12 @@ int main(int argc, char* argv[]) DebugTrace("I R in da native"); - g_launcher = new JGameLauncher(); - - u32 flags = g_launcher->GetInitFlags(); - - if ((flags&JINIT_FLAG_ENABLE3D)!=0) - { - JRenderer::Set3DFlag(true); - } - g_SdlApp = new SdlApp(); int result = g_SdlApp->OnExecute(); - if (g_launcher) - delete g_launcher; - if(g_SdlApp) delete g_SdlApp; - // Shutdown - DestroyGame(); - return result; } diff --git a/JGE/src/WRLmain.cpp b/JGE/src/WRLmain.cpp new file mode 100644 index 000000000..1155383b4 --- /dev/null +++ b/JGE/src/WRLmain.cpp @@ -0,0 +1,309 @@ +#include +#include +#include + +#include "corewrapper.h" + +using namespace Windows::ApplicationModel; +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::System; +using namespace Windows::Foundation; +using namespace Windows::Graphics::Display; + +// Helper class for basic timing. +ref class BasicTimer sealed +{ +public: + // Initializes internal timer values. + BasicTimer() + { + if (!QueryPerformanceFrequency(&m_frequency)) + { + throw ref new Platform::FailureException(); + } + Reset(); + } + + // Reset the timer to initial values. + void Reset() + { + Update(); + m_startTime = m_currentTime; + m_total = 0.0f; + m_delta = 1.0f / 60.0f; + } + + // Update the timer's internal values. + void Update() + { + if (!QueryPerformanceCounter(&m_currentTime)) + { + throw ref new Platform::FailureException(); + } + + m_total = static_cast( + static_cast(m_currentTime.QuadPart - m_startTime.QuadPart) / + static_cast(m_frequency.QuadPart) + ); + + if (m_lastTime.QuadPart == m_startTime.QuadPart) + { + // If the timer was just reset, report a time delta equivalent to 60Hz frame time. + m_delta = 1.0f / 60.0f; + } + else + { + m_delta = static_cast( + static_cast(m_currentTime.QuadPart - m_lastTime.QuadPart) / + static_cast(m_frequency.QuadPart) + ); + } + + m_lastTime = m_currentTime; + } + + // Duration in seconds between the last call to Reset() and the last call to Update(). + property float Total + { + float get() { return m_total; } + } + + // Duration in seconds between the previous two calls to Update(). + property float Delta + { + float get() { return m_delta; } + } + +private: + LARGE_INTEGER m_frequency; + LARGE_INTEGER m_currentTime; + LARGE_INTEGER m_startTime; + LARGE_INTEGER m_lastTime; + float m_total; + float m_delta; +}; + +ref class WagicApp sealed : public Windows::ApplicationModel::Core::IFrameworkView +{ +public: + WagicApp(); + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); + virtual void Load(Platform::String^ entryPoint); + virtual void Run(); + virtual void Uninitialize(); + +protected: + // Event Handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); + void OnLogicalDpiChanged(Platform::Object^ sender); + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); + void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args); + void OnResuming(Platform::Object^ sender, Platform::Object^ args); + void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + +private: + WagicCore m_Wagic; + bool m_windowClosed; + bool m_windowVisible; +}; + +ref class WagicAppSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView(); +}; + + + +WagicApp::WagicApp() : + m_windowClosed(false), + m_windowVisible(true) +{ +} + +void WagicApp::Initialize(CoreApplicationView^ applicationView) +{ + applicationView->Activated += + ref new TypedEventHandler(this, &WagicApp::OnActivated); + + CoreApplication::Suspending += + ref new EventHandler(this, &WagicApp::OnSuspending); + + CoreApplication::Resuming += + ref new EventHandler(this, &WagicApp::OnResuming); + +} + +void WagicApp::SetWindow(CoreWindow^ window) +{ + window->SizeChanged += + ref new TypedEventHandler(this, &WagicApp::OnWindowSizeChanged); + + window->VisibilityChanged += + ref new TypedEventHandler(this, &WagicApp::OnVisibilityChanged); + + window->Closed += + ref new TypedEventHandler(this, &WagicApp::OnWindowClosed); + + window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); + + window->PointerPressed += + ref new TypedEventHandler(this, &WagicApp::OnPointerPressed); + + window->PointerMoved += + ref new TypedEventHandler(this, &WagicApp::OnPointerMoved); + + window->KeyDown += + ref new TypedEventHandler(this, &WagicApp::OnKeyDown); + + window->KeyDown += + ref new TypedEventHandler(this, &WagicApp::OnKeyUp); + + window->PointerWheelChanged += + ref new TypedEventHandler(this, &WagicApp::OnPointerWheelChanged); + + m_Wagic.initApp(); + m_Wagic.onWindowResize((void*)window, window->Bounds.Width, window->Bounds.Height); +} + +void WagicApp::Load(Platform::String^ entryPoint) +{ +} + +void WagicApp::Run() +{ + BasicTimer^ timer = ref new BasicTimer(); + + while (!m_windowClosed) + { + if (m_windowVisible) + { + timer->Update(); + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + if(m_Wagic.onUpdate()) + m_Wagic.onRender(); + else + m_windowClosed = true; + } + else + { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + } +} + +void WagicApp::Uninitialize() +{ +} + +void WagicApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) +{ + m_Wagic.onWindowResize((void*)sender, args->Size.Width, args->Size.Height); +} + +void WagicApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) +{ + m_windowVisible = args->Visible; +} + +void WagicApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) +{ + m_windowClosed = true; +} + +void WagicApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) +{ + WagicCore::PointerId pointerId = WagicCore::LEFT; + if(args->CurrentPoint->Properties->IsLeftButtonPressed) + { + pointerId = WagicCore::LEFT; + } + else if (args->CurrentPoint->Properties->IsRightButtonPressed) + { + pointerId = WagicCore::RIGHT; + } + else if (args->CurrentPoint->Properties->IsMiddleButtonPressed) + { + pointerId = WagicCore::MIDLE; + } + + m_Wagic.onPointerPressed(pointerId, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y); +} + +void WagicApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) +{ + m_Wagic.onPointerMoved(WagicCore::LEFT, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y); +} + +void WagicApp::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ args) +{ + WPARAM param = (WPARAM) args->VirtualKey; + + m_Wagic.onKeyDown(param); +} + +void WagicApp::OnKeyUp(CoreWindow^ sender, KeyEventArgs^ args) +{ + WPARAM param = (WPARAM) args->VirtualKey; + + m_Wagic.onKeyUp(param); +} + +void WagicApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args) +{ + if(args->CurrentPoint->Properties->IsHorizontalMouseWheel) + m_Wagic.onWheelChanged(0, 3*args->CurrentPoint->Properties->MouseWheelDelta); + else + m_Wagic.onWheelChanged(3*args->CurrentPoint->Properties->MouseWheelDelta, 0); +} + +void WagicApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) +{ + CoreWindow::GetForCurrentThread()->Activate(); +} + +void WagicApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) +{ + // Save app state asynchronously after requesting a deferral. Holding a deferral + // indicates that the application is busy performing suspending operations. Be + // aware that a deferral may not be held indefinitely. After about five seconds, + // the app will be forced to exit. + SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); +} + +void WagicApp::OnResuming(Platform::Object^ sender, Platform::Object^ args) +{ + // Restore any data or state that was unloaded on suspend. By default, data + // and state are persisted when resuming from suspend. Note that this event + // does not occur if the app was previously terminated. +} + +IFrameworkView^ WagicAppSource::CreateView() +{ + return ref new WagicApp(); +} + +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto wagicAppSource = ref new WagicAppSource(); + CoreApplication::Run(wagicAppSource); + return 0; +} + +bool JGEToggleFullscreen() +{ + return true; +} + diff --git a/JGE/src/corewrapper.cpp b/JGE/src/corewrapper.cpp new file mode 100644 index 000000000..38c532e88 --- /dev/null +++ b/JGE/src/corewrapper.cpp @@ -0,0 +1,374 @@ +#include "corewrapper.h" + +#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH) +#define ACTUAL_SCREEN_HEIGHT (SCREEN_HEIGHT) +#define ACTUAL_RATIO ((float)ACTUAL_SCREEN_WIDTH / (float)ACTUAL_SCREEN_HEIGHT) + +// in pixels +#define kHitzonePliancy 50 + +// tick value equates to ms +#define kTapEventTimeout 250 +// swipe duration +#define kSwipeEventMinDuration 250 +// swipe distance in pixel (from top to down) +#define kSwipeMinDistance 200 + +WagicCore* WagicCore::s_instance = 0; + +WagicCore::WagicCore() : + m_engine(0), m_app(0), m_launcher(0), m_active(false) +{ + m_lastTickCount = JGEGetTime(); + s_instance = this; +} + +void WagicCore::initApp() +{ + if(!m_engine) + { + m_launcher = new JGameLauncher(); + u32 flags = m_launcher->GetInitFlags(); + if ((flags&JINIT_FLAG_ENABLE3D)!=0) + { + JRenderer::Set3DFlag(true); + } + + JGECreateDefaultBindings(); + + m_engine = JGE::GetInstance(); + m_app = m_launcher->GetGameApp(); + m_app->Create(); + m_engine->SetApp(m_app); + JRenderer::GetInstance()->Enable2D(); + setActive(true); + } +} + +WagicCore::~WagicCore() +{ + if(m_launcher) + { + delete m_launcher; + m_launcher = NULL; + } + + if(m_engine) + m_engine->SetApp(NULL); + + if (m_app) + { + m_app->Destroy(); + delete m_app; + m_app = NULL; + } + + JGE::Destroy(); + + m_engine = NULL; +} + +bool WagicCore::onUpdate() +{ + bool result = false; + int64_t tickCount; + int64_t dt; + tickCount = JGEGetTime(); + dt = (tickCount - m_lastTickCount); + m_lastTickCount = tickCount; + + if(m_engine && !m_engine->IsDone()) + { + m_engine->SetDelta((float)dt / 1000.0f); + m_engine->Update((float)dt / 1000.0f); + + done(); + result = true; + } + + return result; +} + +void WagicCore::setActive(bool active) +{ + if(!m_engine) return; + + if(!m_active && active) + { + m_engine->Resume(); + m_active = active; + } + else if(m_active && !active) + { + m_engine->Pause(); + m_active = active; + } +} + +bool WagicCore::onRender() +{ + bool result = false; + if(m_engine) + { + m_engine->Render(); + result = true; + } + return result; +} + + +void WagicCore::onWindowResize(void* window, float width, float height) +{ + float left, top, right, bottom; + + if ((float)width / (float)height <= ACTUAL_RATIO) + { + left = 0; + top = (float)(-((width/ACTUAL_RATIO)-height)/2); + right = width; + bottom = (-((width/ACTUAL_RATIO)-height)/2 + width / ACTUAL_RATIO); + } + else + { + left = (-(height*ACTUAL_RATIO-width)/2); + top = (0); + right = (-(height*ACTUAL_RATIO-width)/2 + height * ACTUAL_RATIO); + bottom = height; + } + + JRenderer::GetInstance()->SetViewPort(left, top, right, bottom); + JRenderer::GetInstance()->OnWindowsSizeChanged(window, width, height); +} + +void WagicCore::onKeyDown(LocalKeySym key) +{ + m_engine->HoldKey_NoRepeat(key); +} + +void WagicCore::onKeyUp(LocalKeySym key) +{ + m_engine->ReleaseKey(key); +} + +void WagicCore::onWheelChanged(int deltaX, int deltaY) +{ + m_engine->Scroll(deltaX, deltaY); +} + +bool WagicCore::onPointerPressed(WagicCore::PointerId pointer, int x, int y) +{ + bool result = false; + float left, top, right, bottom; + if(pointer == LEFT) + { + // this is intended to convert window coordinate into game coordinate. + // this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong + int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); + int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); + JRenderer::GetInstance()->GetViewPort(left, top, right, bottom); + + if ( y >= top && + y <= bottom && + x <= right && + x >= left) { + m_engine->LeftClicked( + (int)((x-left)*SCREEN_WIDTH)/actualWidth, + (int)((y-top)*SCREEN_HEIGHT)/actualHeight); +#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN) && (!defined ANDROID) && (!defined IOS) + m_engine->HoldKey_NoRepeat(JGE_BTN_OK); +#else + mMouseDownX = x; + mMouseDownY = y; + mLastFingerDownTime = JGEGetTime(); +#endif + result = true; + } else if(yHoldKey_NoRepeat(JGE_BTN_MENU); + result = true; + } else if(y>bottom) { + m_engine->HoldKey_NoRepeat(JGE_BTN_NEXT); + result = true; + } + } + else if(pointer == RIGHT) + { /* next phase please */ + m_engine->HoldKey_NoRepeat(JGE_BTN_PREV); + result = true; + } + else if(pointer == MIDLE) + { /* interrupt please */ + m_engine->HoldKey_NoRepeat(JGE_BTN_SEC); + result = true; + } + return result; +} + +bool WagicCore::onPointerReleased(WagicCore::PointerId pointer, int x, int y) +{ + bool result = false; + float left, top, right, bottom; + JRenderer::GetInstance()->GetViewPort(left, top, right, bottom); + + if(pointer == LEFT) + { + if (y >= top && + y <= bottom && + x <= right && + x >= left) { +#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined ANDROID) || (defined IOS) + if(JGEGetTime() - mLastFingerDownTime <= kTapEventTimeout ) + { + if(abs(mMouseDownX - lastPos.x()) < kHitzonePliancy && + abs(mMouseDownY - lastPos.y()) < kHitzonePliancy) + { + m_engine->HoldKey_NoRepeat(JGE_BTN_OK); + } + } + else if (JGEGetTime() - mLastFingerDownTime >= kSwipeEventMinDuration) + { // Let's swipe + m_engine->Scroll(lastPos.x()-mMouseDownX, lastPos.y()-mMouseDownY); + } +#else + m_engine->ReleaseKey(JGE_BTN_OK); +#endif + m_engine->ReleaseKey(JGE_BTN_MENU); + } else if(y < top) { + m_engine->ReleaseKey(JGE_BTN_MENU); + } else if(y > bottom) { + m_engine->ReleaseKey(JGE_BTN_NEXT); + } + result = true; + } + else if(pointer == RIGHT) + { /* next phase please */ + m_engine->ReleaseKey(JGE_BTN_PREV); + result = true; + } + else if(pointer == MIDLE) + { /* interrupt please */ + m_engine->ReleaseKey(JGE_BTN_SEC); + result = true; + } + + return result; +} + +bool WagicCore::onPointerMoved(WagicCore::PointerId pointer, int x, int y) +{ + bool result = false; + float left, top, right, bottom; + JRenderer::GetInstance()->GetViewPort(left, top, right, bottom); + + int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); + int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); + + if (y >= top && + y <= bottom && + x <= right && + x >= left) { + m_engine->LeftClicked( + (int)((x-left)*SCREEN_WIDTH)/actualWidth, + (int)((y-top)*SCREEN_HEIGHT)/actualHeight); + result = true; + } + return result; +} + + +static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] = +#ifdef SDL_CONFIG +{ + /* windows controls */ + { SDLK_LCTRL, JGE_BTN_CTRL }, + { SDLK_RCTRL, JGE_BTN_CTRL }, + { SDLK_RETURN, JGE_BTN_MENU }, + { SDLK_KP_ENTER, JGE_BTN_MENU }, + { SDLK_ESCAPE, JGE_BTN_MENU }, + { SDLK_UP, JGE_BTN_UP }, + { SDLK_DOWN, JGE_BTN_DOWN }, + { SDLK_LEFT, JGE_BTN_LEFT }, + { SDLK_RIGHT, JGE_BTN_RIGHT }, + { SDLK_z, JGE_BTN_UP }, + { SDLK_d, JGE_BTN_RIGHT }, + { SDLK_s, JGE_BTN_DOWN }, + { SDLK_q, JGE_BTN_LEFT }, + { SDLK_a, JGE_BTN_PREV }, + { SDLK_e, JGE_BTN_NEXT }, + { SDLK_i, JGE_BTN_CANCEL }, + { SDLK_l, JGE_BTN_OK }, + { SDLK_SPACE, JGE_BTN_OK }, + { SDLK_k, JGE_BTN_SEC }, + { SDLK_j, JGE_BTN_PRI }, + { SDLK_f, JGE_BTN_FULLSCREEN }, + + /* Android customs */ + { SDLK_AC_BACK, JGE_BTN_MENU }, + /* Android/maemo volume button mapping */ + { SDLK_VOLUMEUP, JGE_BTN_PREV }, + { SDLK_VOLUMEDOWN, JGE_BTN_SEC}, +}; +#elif define QT_CONFIG +{ + { Qt::Key_Enter, JGE_BTN_MENU }, + { Qt::Key_Return, JGE_BTN_MENU }, + { Qt::Key_Escape, JGE_BTN_MENU }, + { Qt::Key_Backspace, JGE_BTN_CTRL }, + { Qt::Key_Up, JGE_BTN_UP }, + { Qt::Key_Down, JGE_BTN_DOWN }, + { Qt::Key_Left, JGE_BTN_LEFT }, + { Qt::Key_Right, JGE_BTN_RIGHT }, + { Qt::Key_Space, JGE_BTN_OK }, + { Qt::Key_Tab, JGE_BTN_CANCEL }, + { Qt::Key_J, JGE_BTN_PRI }, + { Qt::Key_K, JGE_BTN_SEC }, + { Qt::Key_Q, JGE_BTN_PREV }, + { Qt::Key_A, JGE_BTN_NEXT }, +// fullscreen management seems somehow broken in JGE, it works fine with Qt directly +// { Qt::Key_F, JGE_BTN_FULLSCREEN }, +}; +#else +{ + { VK_CONTROL, JGE_BTN_CTRL }, + { VK_RETURN, JGE_BTN_MENU }, + { VK_ESCAPE, JGE_BTN_MENU }, + { VK_UP, JGE_BTN_UP }, + { VK_RIGHT, JGE_BTN_RIGHT }, + { VK_DOWN, JGE_BTN_DOWN }, + { VK_LEFT, JGE_BTN_LEFT }, + { 'Z', JGE_BTN_UP }, + { 'D', JGE_BTN_RIGHT }, + { 'S', JGE_BTN_DOWN }, + { 'Q', JGE_BTN_LEFT }, + { 'A', JGE_BTN_PREV }, + { 'E', JGE_BTN_NEXT }, + { 'I', JGE_BTN_CANCEL }, + { 'L', JGE_BTN_OK }, + { VK_SPACE, JGE_BTN_OK }, + { 'K', JGE_BTN_SEC }, + { 'J', JGE_BTN_PRI }, + { 'F', JGE_BTN_FULLSCREEN }, +}; +#endif + +void WagicCore::registerDefaultBindings() +{ + for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) + m_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode); + +} + +void JGECreateDefaultBindings() +{ + WagicCore::getInstance()->registerDefaultBindings(); +} + +int JGEGetTime() +{ +#ifdef SDL_CONFIG + return (int)SDL_GetTicks(); +#elif defined QT_CONFIG + return QTime::currentTime().elapsed(); +#elif defined WP8 + return (int)GetTickCount64(); +#endif +} diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index 6050eeeab..beeb9eb04 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -9,6 +9,24 @@ //------------------------------------------------------------------------------------- #define GL_GLEXT_PROTOTYPES +#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 + +#if (defined FORCE_GLES) +#undef GL_ES_VERSION_2_0 +#undef GL_VERSION_2_0 +#define GL_VERSION_ES_CM_1_1 1 +#define glOrthof glOrtho +#define glClearDepthf glClearDepth +#endif + #if (!defined IOS) && (!defined QT_CONFIG) #ifdef WIN32 #pragma warning(disable : 4786) @@ -310,13 +328,10 @@ void JQuad::SetTextureRect(float x, float y, float w, float h) mWidth = w; mHeight = h; - if(mTex) - { - mTX0 = x/mTex->mTexWidth; - mTY0 = y/mTex->mTexHeight; - mTX1 = (x+w)/mTex->mTexWidth; - mTY1 = (y+h)/mTex->mTexHeight; - } + mTX0 = x/mTex->mTexWidth; + mTY0 = y/mTex->mTexHeight; + mTX1 = (x+w)/mTex->mTexWidth; + mTY1 = (y+h)/mTex->mTexHeight; } @@ -403,7 +418,11 @@ void JRenderer::Destroy() } } -JRenderer::JRenderer() : mActualWidth(SCREEN_WIDTH_F), mActualHeight(SCREEN_HEIGHT_F) +JRenderer::JRenderer() : + mLeft(0.0f), + mRight(SCREEN_WIDTH_F), + mTop(0.0f), + mBottom(SCREEN_HEIGHT_F) { } @@ -413,6 +432,25 @@ JRenderer::~JRenderer() } +void JRenderer::OnWindowsSizeChanged(void* window, float inWidth, float inHeight) +{ + glViewport(mLeft, mTop, mRight, mBottom); + glScissor(0, 0, inWidth, inHeight); + +#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) + 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) (mRight)-1.0f, 0.0f, (float) (mBottom)-1.0f, -1.0f, 1.0f); +#else + gluOrtho2D(0.0f, (float) (mRight)-1.0f, 0.0f, (float) (mBottom)-1.0f); +#endif + glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity (); // Reset The Modelview Matrix + glDisable (GL_DEPTH_TEST); +#endif +} + #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) void esMatrixLoadIdentity(ESMatrix *result) { @@ -710,6 +748,43 @@ GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc ) void JRenderer::InitRenderer() { checkGlError(); + + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers) +#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) +#if (defined GL_ES_VERSION_2_0) + glClearDepthf(1.0f); // Depth Buffer Setup +#else + glClearDepth(1.0f); // Depth Buffer Setup +#endif// (defined GL_ES_VERSION_2_0) + + 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) + 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 + glShadeModel(GL_SMOOTH); // Select Smooth Shading + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate + + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing + glEnable(GL_LINE_SMOOTH); // Enable it! + glEnable(GL_TEXTURE_2D); + +#endif + + glEnable(GL_CULL_FACE); // do not calculate inside of poly's + glFrontFace(GL_CCW); // counter clock-wise polygons are out + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_SCISSOR_TEST); // Enable Clipping + mCurrentTextureFilter = TEX_FILTER_NONE; mImageFilter = NULL; @@ -819,16 +894,16 @@ void JRenderer::BeginScene() glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) glLoadIdentity (); // Reset The Modelview Matrix +#if (defined WIN32) || ((defined GL_VERSION_ES_CM_1_1) && (!defined IOS)) + float scaleH = GetActualHeight()/SCREEN_HEIGHT_F; + float scaleW = GetActualWidth()/SCREEN_WIDTH_F; + if (scaleH != 1.0f || scaleW != 1.0f) + glScalef(scaleW,scaleH,1.f); +#endif #else esMatrixLoadIdentity(&theMvpMatrix); esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f); #endif //(!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) -#if (defined WIN32 && !defined GL_ES_VERSION_2_0) || ((defined GL_VERSION_ES_CM_1_1) && (!defined IOS)) - float scaleH = mActualHeight/SCREEN_HEIGHT_F; - float scaleW = mActualWidth/SCREEN_WIDTH_F; - if (scaleH != 1.0f || scaleW != 1.0f) - glScalef(scaleW,scaleH,1.f); -#endif checkGlError(); } @@ -843,7 +918,7 @@ void JRenderer::EndScene() void JRenderer::BindTexture(JTexture *tex) { checkGlError(); - if (tex && mCurrentTex != tex->mTexId) + if (mCurrentTex != tex->mTexId) { mCurrentTex = tex->mTexId; diff --git a/JGE/src/pc/JSocket.cpp b/JGE/src/pc/JSocket.cpp index 49eb7165a..696ec0094 100644 --- a/JGE/src/pc/JSocket.cpp +++ b/JGE/src/pc/JSocket.cpp @@ -1,11 +1,15 @@ -#include #ifdef WIN32 +#ifdef QT_CONFIG #pragma comment(lib,"WSOCK32.LIB") #include #include #include #include #include +#else +#pragma comment(lib,"ws2_32.lib") +#include +#endif #elif LINUX #include #include @@ -13,7 +17,9 @@ #include #include #endif //WINDOWS +#include +#include #include "../../include/JSocket.h" #include "../../include/DebugRoutines.h" diff --git a/JGE/src/qt/corewrapper.cpp b/JGE/src/qt/corewrapper.cpp deleted file mode 100644 index 656a35132..000000000 --- a/JGE/src/qt/corewrapper.cpp +++ /dev/null @@ -1,596 +0,0 @@ -#include -#include -#include "corewrapper.h" -#include - -#ifdef TESTSUITE -#include "TestSuiteAI.h" -#include "GameOptions.h" -#include "MTGDeck.h" -#endif -#include "DebugRoutines.h" - -#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 - -#if (defined FORCE_GLES) -#undef GL_ES_VERSION_2_0 -#undef GL_VERSION_2_0 -#define GL_VERSION_ES_CM_1_1 1 -#define glOrthof glOrtho -#define glClearDepthf glClearDepth -#endif - -#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH) -#define ACTUAL_SCREEN_HEIGHT (SCREEN_HEIGHT) -#define ACTUAL_RATIO ((GLfloat)ACTUAL_SCREEN_WIDTH / (GLfloat)ACTUAL_SCREEN_HEIGHT) - -// in pixels -#define kHitzonePliancy 50 - -// tick value equates to ms -#define kTapEventTimeout 250 - -// swipe duration -#define kSwipeEventMinDuration 250 -// swipe distance in pixel (from top to down) -#define kSwipeMinDistance 200 - - -QElapsedTimer WagicCore::g_startTimer; - -WagicCore::WagicCore(super *parent) : - super(parent), m_engine(0), m_app(0), m_launcher(0), m_active(false) -#ifdef Q_WS_MAEMO_5 - , dBusConnection(QDBusConnection::systemBus()), dBusInterface(0) -#endif //Q_WS_MAEMO_5 -{ -#ifdef QT_WIDGET -#if (defined Q_WS_MAEMO_5) - setAttribute(Qt::WA_Maemo5AutoOrientation); - setAttribute(Qt::WA_Maemo5NonComposited); -#endif //Q_WS_MAEMO_5 - setAttribute(Qt::WA_AcceptTouchEvents); - // setAttribute(Qt::WA_InputMethodEnabled); - setMouseTracking(true); - grabGesture(Qt::TapAndHoldGesture); - resize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT); -#else - setWidth(480); - setHeight(272); - setFlag(QGraphicsItem::ItemHasNoContents, false); -#endif //QT_WIDGET - g_startTimer.restart(); - m_lastTickCount = g_startTimer.elapsed(); - -#ifdef Q_WS_MAEMO_5 - dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH, - MCE_REQUEST_IF, dBusConnection); - - // Handle screen state on / off - dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &))); -#endif -} - - -WagicWrapper::WagicWrapper() -{ - m_launcher = new JGameLauncher(); - u32 flags = m_launcher->GetInitFlags(); - if ((flags&JINIT_FLAG_ENABLE3D)!=0) - { - JRenderer::Set3DFlag(true); - } - - JGECreateDefaultBindings(); - - m_engine = JGE::GetInstance(); - m_app = m_launcher->GetGameApp(); - m_app->Create(); - m_engine->SetApp(m_app); - JRenderer::GetInstance()->Enable2D(); -} - -WagicWrapper::~WagicWrapper() -{ - if(m_launcher) - { - delete m_launcher; - m_launcher = NULL; - } - - if(m_engine) - m_engine->SetApp(NULL); - - if (m_app) - { - m_app->Destroy(); - delete m_app; - m_app = NULL; - } - - JGE::Destroy(); - m_engine = NULL; -} - - -int WagicCore::runTestSuite() -{ - int result = 0; -#ifdef TESTSUITE - WagicWrapper* wagicCore = new WagicWrapper(); - MTGCollection()->loadFolder("sets/primitives/"); - MTGCollection()->loadFolder("sets/", "_cards.dat"); - options.reloadProfile(); - TestSuite testSuite("test/_tests.txt"); - result = testSuite.run(); - delete wagicCore; -#endif - DebugTrace("TestSuite done: failed test: " << result); - return result; -} - -void WagicCore::initApp() -{ - if(!m_engine) - { - m_launcher = new JGameLauncher(); - u32 flags = m_launcher->GetInitFlags(); - if ((flags&JINIT_FLAG_ENABLE3D)!=0) - { - JRenderer::Set3DFlag(true); - } - - JGECreateDefaultBindings(); - - m_engine = JGE::GetInstance(); - m_app = m_launcher->GetGameApp(); - m_app->Create(); - m_engine->SetApp(m_app); - JRenderer::GetInstance()->Enable2D(); - setActive(true); - } -} - -WagicCore::~WagicCore() -{ -#ifdef Q_WS_MAEMO_5 - if(dBusInterface) - delete dBusInterface; -#endif //Q_WS_MAEMO_5 - - if(m_launcher) - { - delete m_launcher; - m_launcher = NULL; - } - - if(m_engine) - m_engine->SetApp(NULL); - - if (m_app) - { - m_app->Destroy(); - delete m_app; - m_app = NULL; - } - - JGE::Destroy(); - - m_engine = NULL; -} - -void WagicCore::pixelInput(int x, int y) -{ - if(m_engine) - m_engine->LeftClicked(x, y); -} - -void WagicCore::timerEvent( QTimerEvent* ) -{ - qint64 tickCount; - quint32 dt; - tickCount = g_startTimer.elapsed(); - dt = (tickCount - m_lastTickCount); - m_lastTickCount = tickCount; - - if(!m_engine) - return; - if(m_engine->IsDone()) - QApplication::instance()->quit(); - - m_engine->SetDelta((float)dt / 1000.0f); - m_engine->Update((float)dt / 1000.0f); - - done(); - update(); -} - -void WagicCore::setActive(bool active) -{ - if(!m_engine) return; - - if(!m_active && active) - { - m_engine->Resume(); - #if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) - // 30 fps max on mobile - m_timerId = startTimer(33); - #else - // 200 fps max on desktop - m_timerId = startTimer(5); - #endif //Q_WS_MAEMO_5 - m_active = active; - emit activeChanged(); - } - else if(m_active && !active) - { - m_engine->Pause(); - #if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) - killTimer(m_timerId); - #endif - m_active = active; - emit activeChanged(); - } -} - -void WagicCore::initializeGL() -{ - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers) - #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - #if (defined GL_ES_VERSION_2_0) - glClearDepthf(1.0f); // Depth Buffer Setup - #else - glClearDepth(1.0f); // Depth Buffer Setup - #endif// (defined GL_ES_VERSION_2_0) - - 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 - glShadeModel(GL_SMOOTH); // Select Smooth Shading - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate - - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing - glEnable(GL_LINE_SMOOTH); // Enable it! - glEnable(GL_TEXTURE_2D); - #endif - - glEnable(GL_CULL_FACE); // do not calculate inside of poly's - glFrontFace(GL_CCW); // counter clock-wise polygons are out - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_SCISSOR_TEST); // Enable Clipping -} - -#ifndef QT_WIDGET -void WagicCore::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - painter->beginNativePainting(); - - initApp(); - - resizeGL ( boundingRect().size().width(), boundingRect().size().height()); - - initializeGL(); - - paintGL(); - - painter->endNativePainting(); -} -#endif //QT_WIDGET - -void WagicCore::paintGL() -{ - if(m_engine) - m_engine->Render(); -} - - -void WagicCore::resizeGL(int width, int height) -{ - if ((GLfloat)width / (GLfloat)height <= ACTUAL_RATIO) - { - m_viewPort.setLeft(0); - m_viewPort.setTop(-((width/ACTUAL_RATIO)-height)/2); - m_viewPort.setRight(width); - m_viewPort.setBottom(-((width/ACTUAL_RATIO)-height)/2 + width / ACTUAL_RATIO); - } - else - { - m_viewPort.setLeft(-(height*ACTUAL_RATIO-width)/2); - m_viewPort.setTop(0); - m_viewPort.setRight(-(height*ACTUAL_RATIO-width)/2 + height * ACTUAL_RATIO); - m_viewPort.setBottom(height); - } - - glViewport(m_viewPort.left(), m_viewPort.top(), m_viewPort.right()-m_viewPort.left(), m_viewPort.bottom()-m_viewPort.top()); - - JRenderer::GetInstance()->SetActualWidth(m_viewPort.right()-m_viewPort.left()); - JRenderer::GetInstance()->SetActualHeight(m_viewPort.bottom()-m_viewPort.top()); - glScissor(0, 0, width, height); - -#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - - 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) (m_viewPort.right()-m_viewPort.left())-1.0f, 0.0f, (float) (m_viewPort.bottom()-m_viewPort.top())-1.0f, -1.0f, 1.0f); -#else - gluOrtho2D(0.0f, (float) (m_viewPort.right()-m_viewPort.left())-1.0f, 0.0f, (float) (m_viewPort.bottom()-m_viewPort.top())-1.0f); -#endif - - glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity (); // Reset The Modelview Matrix - - glDisable (GL_DEPTH_TEST); -#endif -} - -void WagicCore::keyPressEvent(QKeyEvent *event) -{ - switch(event->key()) - { -#if (defined Q_WS_MAEMO_5) - case Qt::Key_F7: - /* interrupt please */ - m_engine->HoldKey_NoRepeat(JGE_BTN_SEC); - break; - case Qt::Key_F8: - /* next phase please */ - m_engine->HoldKey_NoRepeat(JGE_BTN_PREV); - break; -#endif // Q_WS_MAEMO_5 - case Qt::Key_F: - JGEToggleFullscreen(); - break; - default: - m_engine->HoldKey_NoRepeat((LocalKeySym)event->key()); - } - event->accept(); - super::keyPressEvent(event); -} - -void WagicCore::keyReleaseEvent(QKeyEvent *event) -{ - switch(event->key()) - { -#if (defined Q_WS_MAEMO_5) - case Qt::Key_F7: - /* interrupt please */ - m_engine->ReleaseKey(JGE_BTN_SEC); - break; - case Qt::Key_F8: - /* next phase please */ - m_engine->ReleaseKey(JGE_BTN_PREV); - break; - #endif // Q_WS_MAEMO_5 - default: - m_engine->ReleaseKey((LocalKeySym)event->key()); - } - - event->accept(); - super::keyReleaseEvent(event); -} - -#ifdef QT_WIDGET -void WagicCore::wheelEvent(QWheelEvent *event) -#else -void WagicCore::wheelEvent ( QGraphicsSceneWheelEvent * event) -#endif -{ - if(event->orientation() == Qt::Vertical) - m_engine->Scroll(0, 3*event->delta()); - else - - m_engine->Scroll(3*event->delta(), 0); - - event->accept(); -} - -#ifdef QT_WIDGET -void WagicCore::tapAndHoldTriggered(QTapAndHoldGesture* gesture) -{ - if (gesture->state() == Qt::GestureFinished) { - m_engine->HoldKey_NoRepeat(JGE_BTN_MENU); - } -} - -void WagicCore::mousePressEvent(QMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - QPoint lastPos = event->pos(); - // this is intended to convert window coordinate into game coordinate. - // this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong - int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); - int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); - - if (lastPos.y() >= m_viewPort.top() && - lastPos.y() <= m_viewPort.bottom() && - lastPos.x() <= m_viewPort.right() && - lastPos.x() >= m_viewPort.left()) { - m_engine->LeftClicked( - ((lastPos.x()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth, - ((lastPos.y()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight); -#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN) && (!defined Q_WS_ANDROID) - m_engine->HoldKey_NoRepeat(JGE_BTN_OK); -#else - mMouseDownX = lastPos.x(); - mMouseDownY = lastPos.y(); - mLastFingerDownTime = g_startTimer.elapsed(); -#endif - } else if(lastPos.y()HoldKey_NoRepeat(JGE_BTN_MENU); - } else if(lastPos.y()>m_viewPort.bottom()) { - m_engine->HoldKey_NoRepeat(JGE_BTN_NEXT); - } - event->accept(); - } - else if(event->button() == Qt::RightButton) - { /* next phase please */ - m_engine->HoldKey_NoRepeat(JGE_BTN_PREV); - event->accept(); - } - else if(event->button() == Qt::MidButton) - { /* interrupt please */ - m_engine->HoldKey_NoRepeat(JGE_BTN_SEC); - event->accept(); - } - else - { - super::mousePressEvent(event); - } -} - -void WagicCore::mouseReleaseEvent(QMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - QPoint lastPos = event->pos(); - - if (lastPos.y() >= m_viewPort.top() && - lastPos.y() <= m_viewPort.bottom() && - lastPos.x() <= m_viewPort.right() && - lastPos.x() >= m_viewPort.left()) { -#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) - if(g_startTimer.elapsed() - mLastFingerDownTime <= kTapEventTimeout ) - { - if(abs(mMouseDownX - lastPos.x()) < kHitzonePliancy && - abs(mMouseDownY - lastPos.y()) < kHitzonePliancy) - { - m_engine->HoldKey_NoRepeat(JGE_BTN_OK); - } - } - else if (g_startTimer.elapsed() - mLastFingerDownTime >= kSwipeEventMinDuration) - { // Let's swipe - m_engine->Scroll(lastPos.x()-mMouseDownX, lastPos.y()-mMouseDownY); - } -#else -//#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN) - m_engine->ReleaseKey(JGE_BTN_OK); -#endif - m_engine->ReleaseKey(JGE_BTN_MENU); - } else if(lastPos.y() < m_viewPort.top()) { - m_engine->ReleaseKey(JGE_BTN_MENU); - } else if(lastPos.y() > m_viewPort.bottom()) { - m_engine->ReleaseKey(JGE_BTN_NEXT); - } - event->accept(); - } - else if(event->button() == Qt::RightButton) - { /* next phase please */ - m_engine->ReleaseKey(JGE_BTN_PREV); - event->accept(); - } - else if(event->button() == Qt::MidButton) - { /* interrupt please */ - m_engine->ReleaseKey(JGE_BTN_SEC); - event->accept(); - } - else - { - super::mouseReleaseEvent(event); - } -} - -void WagicCore::mouseMoveEvent(QMouseEvent *event) -{ - int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); - int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); - - QPoint lastPos = event->pos(); - - if (lastPos.y() >= m_viewPort.top() && - lastPos.y() <= m_viewPort.bottom() && - lastPos.x() <= m_viewPort.right() && - lastPos.x() >= m_viewPort.left()) { - m_engine->LeftClicked( - ((lastPos.x()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth, - ((lastPos.y()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight); - event->accept(); - } else { - super::mouseMoveEvent(event); - } -} - -void WagicCore::showEvent ( QShowEvent * ) -{ - setActive(true); -} - -void WagicCore::hideEvent ( QHideEvent * ) -{ - setActive(false); -} - -bool WagicCore::event(QEvent *event) -{ - if (event->type() == QEvent::Gesture) - return gestureEvent(static_cast(event)); -#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) - else if (event->type() == QEvent::WindowActivate) - { - showEvent(NULL); - } - else if (event->type() == QEvent::WindowDeactivate) - { - hideEvent(NULL); - } -#endif - - return QGLWidget::event(event); -} - -bool WagicCore::gestureEvent(QGestureEvent* event) -{ - if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) - tapAndHoldTriggered(static_cast(tapAndHold)); - - return true; -} - -void WagicCore::start(int) -{ -#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) - showFullScreen(); -#else - show(); -#endif - initApp(); -} - -#endif //QT_WIDGET - -#ifdef Q_WS_MAEMO_5 -void WagicCore::displayStateChanged(const QDBusMessage &message) -{ - QString state = message.arguments().at(0).toString(); - if (!state.isEmpty()) { - if (state == MCE_DISPLAY_ON_STRING && isActiveWindow()) { - setActive(true); - } - else if (state == MCE_DISPLAY_OFF_STRING) { - setActive(false); - } - } -} -#endif diff --git a/JGE/src/qt/qtcorewrapper.cpp b/JGE/src/qt/qtcorewrapper.cpp new file mode 100644 index 000000000..ec022fd35 --- /dev/null +++ b/JGE/src/qt/qtcorewrapper.cpp @@ -0,0 +1,309 @@ +#include +#include +#include "qtcorewrapper.h" +#include + +#ifdef TESTSUITE +#include "TestSuiteAI.h" +#include "GameOptions.h" +#include "MTGDeck.h" +#endif +#include "DebugRoutines.h" + +QElapsedTimer QtWagicCore::g_startTimer; + +QtWagicCore::QtWagicCore(super *parent) : + super(parent), m_active(false) +#ifdef Q_WS_MAEMO_5 + , dBusConnection(QDBusConnection::systemBus()), dBusInterface(0) +#endif //Q_WS_MAEMO_5 +{ +#ifdef QT_WIDGET +#if (defined Q_WS_MAEMO_5) + setAttribute(Qt::WA_Maemo5AutoOrientation); + setAttribute(Qt::WA_Maemo5NonComposited); +#endif //Q_WS_MAEMO_5 + setAttribute(Qt::WA_AcceptTouchEvents); + // setAttribute(Qt::WA_InputMethodEnabled); + setMouseTracking(true); + grabGesture(Qt::TapAndHoldGesture); + resize(SCREEN_WIDTH, SCREEN_HEIGHT); +#else + setWidth(ACTUAL_SCREEN_WIDTH); + setHeight(SCREEN_HEIGHT); + setFlag(QGraphicsItem::ItemHasNoContents, false); +#endif //QT_WIDGET + g_startTimer.restart(); + m_lastTickCount = g_startTimer.elapsed(); + +#ifdef Q_WS_MAEMO_5 + dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, dBusConnection); + + // Handle screen state on / off + dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &))); +#endif +} + +QtWagicCore::~QtWagicCore() +{ +#ifdef Q_WS_MAEMO_5 + if(dBusInterface) + delete dBusInterface; +#endif //Q_WS_MAEMO_5 +} + +void QtWagicCore::pixelInput(int x, int y) +{ + m_Wagic.onPointerPressed(WagicCore::LEFT, x, y); +} + +void QtWagicCore::timerEvent( QTimerEvent* ) +{ + bool result = m_Wagic.onUpdate(); + if(!result) + QApplication::instance()->quit(); + + update(); +} + +void QtWagicCore::setActive(bool active) +{ + if(!m_active && active) + { + m_Wagic.setActive(true); + #if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) + // 30 fps max on mobile + m_timerId = startTimer(33); + #else + // 200 fps max on desktop + m_timerId = startTimer(5); + #endif //Q_WS_MAEMO_5 + m_active = active; + emit activeChanged(); + } + else if(m_active && !active) + { + m_Wagic.setActive(false); + #if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) + killTimer(m_timerId); + #endif + m_active = active; + emit activeChanged(); + } +} + +void QtWagicCore::initializeGL() +{ + m_Wagic.initApp(); +} + +#ifndef QT_WIDGET +void QtWagicCore::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + painter->beginNativePainting(); + + initApp(); + + resizeGL ( boundingRect().size().width(), boundingRect().size().height()); + + initializeGL(); + + paintGL(); + + painter->endNativePainting(); +} +#endif //QT_WIDGET + +void QtWagicCore::paintGL() +{ + m_Wagic.onRender(); +} + +void QtWagicCore::resizeGL(int width, int height) +{ + m_Wagic.onWindowResize(this, width, height); +} + +void QtWagicCore::keyPressEvent(QKeyEvent *event) +{ + switch(event->key()) + { +#if (defined Q_WS_MAEMO_5) + case Qt::Key_F7: + /* interrupt please */ + m_engine->HoldKey_NoRepeat(JGE_BTN_SEC); + break; + case Qt::Key_F8: + /* next phase please */ + m_engine->HoldKey_NoRepeat(JGE_BTN_PREV); + break; +#endif // Q_WS_MAEMO_5 + case Qt::Key_F: + JGEToggleFullscreen(); + break; + default: + m_Wagic.onKeyDown((LocalKeySym)event->key()); + } + event->accept(); + super::keyPressEvent(event); +} + +void QtWagicCore::keyReleaseEvent(QKeyEvent *event) +{ + switch(event->key()) + { +#if (defined Q_WS_MAEMO_5) + case Qt::Key_F7: + /* interrupt please */ + m_engine->ReleaseKey(JGE_BTN_SEC); + break; + case Qt::Key_F8: + /* next phase please */ + m_engine->ReleaseKey(JGE_BTN_PREV); + break; + #endif // Q_WS_MAEMO_5 + default: + m_Wagic.onKeyUp((LocalKeySym)event->key()); + } + + event->accept(); + super::keyReleaseEvent(event); +} + +#ifdef QT_WIDGET +void QtWagicCore::wheelEvent(QWheelEvent *event) +#else +void QtWagicCore::wheelEvent ( QGraphicsSceneWheelEvent * event) +#endif +{ + if(event->orientation() == Qt::Vertical) + m_Wagic.onWheelChanged(0, 3*event->delta()); + else + m_Wagic.onWheelChanged(3*event->delta(), 0); + + event->accept(); +} + +#ifdef QT_WIDGET +void QtWagicCore::tapAndHoldTriggered(QTapAndHoldGesture* gesture) +{ + if (gesture->state() == Qt::GestureFinished) { + m_Wagic.doMenu(); + } +} + +void QtWagicCore::mousePressEvent(QMouseEvent *event) +{ + WagicCore::PointerId pointer; + if(event->button() == Qt::LeftButton) { + pointer = WagicCore::LEFT; + m_Wagic.onPointerPressed(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else if (event->button() == Qt::RightButton) { + pointer = WagicCore::RIGHT; + m_Wagic.onPointerPressed(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else if (event->button() == Qt::MidButton) { + pointer = WagicCore::MIDLE; + m_Wagic.onPointerPressed(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else { + super::mousePressEvent(event); + } +} + +void QtWagicCore::mouseReleaseEvent(QMouseEvent *event) +{ + WagicCore::PointerId pointer; + if(event->button() == Qt::LeftButton) { + pointer = WagicCore::LEFT; + m_Wagic.onPointerReleased(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else if (event->button() == Qt::RightButton) { + pointer = WagicCore::RIGHT; + m_Wagic.onPointerReleased(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else if (event->button() == Qt::MidButton) { + pointer = WagicCore::MIDLE; + m_Wagic.onPointerReleased(pointer, event->pos().x(), event->pos().y()); + event->accept(); + } else { + super::mouseReleaseEvent(event); + } +} + +void QtWagicCore::mouseMoveEvent(QMouseEvent *event) +{ + bool result = + m_Wagic.onPointerMoved(WagicCore::LEFT, event->pos().x(), event->pos().y()); + + if (result) { + event->accept(); + } else { + super::mouseMoveEvent(event); + } +} + +void QtWagicCore::showEvent ( QShowEvent * ) +{ + setActive(true); +} + +void QtWagicCore::hideEvent ( QHideEvent * ) +{ + setActive(false); +} + +bool QtWagicCore::event(QEvent *event) +{ + if (event->type() == QEvent::Gesture) + return gestureEvent(static_cast(event)); +#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) + else if (event->type() == QEvent::WindowActivate) + { + showEvent(NULL); + } + else if (event->type() == QEvent::WindowDeactivate) + { + hideEvent(NULL); + } +#endif + + return QGLWidget::event(event); +} + +bool QtWagicCore::gestureEvent(QGestureEvent* event) +{ + if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) + tapAndHoldTriggered(static_cast(tapAndHold)); + + return true; +} + +void QtWagicCore::start(int) +{ +#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID) + showFullScreen(); +#else + show(); +#endif + m_Wagic.initApp(); +} + +#endif //QT_WIDGET + +#ifdef Q_WS_MAEMO_5 +void QtWagicCore::displayStateChanged(const QDBusMessage &message) +{ + QString state = message.arguments().at(0).toString(); + if (!state.isEmpty()) { + if (state == MCE_DISPLAY_ON_STRING && isActiveWindow()) { + setActive(true); + } + else if (state == MCE_DISPLAY_OFF_STRING) { + setActive(false); + } + } +} +#endif diff --git a/JGE/src/zipFS/fileio.h b/JGE/src/zipFS/fileio.h index 1594c9317..9b4609a7a 100644 --- a/JGE/src/zipFS/fileio.h +++ b/JGE/src/zipFS/fileio.h @@ -47,9 +47,8 @@ -#if defined WIN32 -#include // Windows I/O facilities (Directories) -#else +#if defined WIN32 || defined WP8 +#include #include #include #endif @@ -86,14 +85,9 @@ public: protected: bool m_Valid; -#if defined WIN32 - intptr_t m_hFiles; - _finddata_t m_FindData; -#else DIR * m_Directory; std::string m_Extension; struct dirent * m_DirectoryEntry; -#endif }; @@ -144,30 +138,18 @@ inline std::ostream & writevar(std::ostream & File, const T & Var, const std::st inline search_iterator::search_iterator() : m_Valid(false), -#if defined WIN32 - m_hFiles(-1) -#else m_Directory(NULL) -#endif { } inline search_iterator::search_iterator(const char * FileSpec) : m_Valid(false), -#if defined WIN32 - m_hFiles(-1) -#else m_Directory(NULL) -#endif { begin(FileSpec); } inline search_iterator::~search_iterator() { -#if defined WIN32 - if (m_hFiles != -1) _findclose(m_hFiles); -#else if (m_Directory != NULL) closedir(m_Directory); -#endif } inline search_iterator::operator bool () const { @@ -179,17 +161,13 @@ inline search_iterator & search_iterator::operator ++ () { } inline search_iterator & search_iterator::begin(const char * FileSpec) { -#if defined WIN32 - if (m_hFiles != -1) _findclose(m_hFiles); - m_Valid = ((m_hFiles = _findfirst(FileSpec, &m_FindData)) != -1); -#else std::string DirectoryName; if (m_Directory != NULL) closedir(m_Directory); int i; for (i = strlen(FileSpec); i >= 0; --i) - if (FileSpec[i] == '/') break; + if (FileSpec[i] == '/' || FileSpec[i] == '\\') break; if (i < 0) DirectoryName = "."; @@ -204,7 +182,6 @@ inline search_iterator & search_iterator::begin(const char * FileSpec) { return (* this); next(); -#endif return (* this); } @@ -214,9 +191,6 @@ inline bool search_iterator::end() const { } inline search_iterator & search_iterator::next() { -#if defined WIN32 - m_Valid = (_findnext(m_hFiles, &m_FindData) != -1); -#else bool Found = false; while (! Found) { m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL); @@ -235,17 +209,12 @@ inline search_iterator & search_iterator::next() { else break; } -#endif return (* this); } inline std::string search_iterator::Name() const { -#if defined WIN32 - return (m_FindData.name); -#else return (m_DirectoryEntry->d_name); -#endif } diff --git a/JGE/src/zipFS/zfsystem.cpp b/JGE/src/zipFS/zfsystem.cpp index 34699d080..566f0b7d6 100644 --- a/JGE/src/zipFS/zfsystem.cpp +++ b/JGE/src/zipFS/zfsystem.cpp @@ -503,7 +503,7 @@ bool filesystem::PreloadZip(const char * Filename, map #include - typedef struct dirent { /* name of current directory entry (a multi-byte character string) */ char d_name[MAX_PATH + 1]; /* file attributes */ - WIN32_FIND_DATAA data; + WIN32_FIND_DATAW data; } dirent; @@ -81,7 +80,7 @@ typedef struct DIR { HANDLE search_handle; /* search pattern (3 = zero terminator + pattern "\\*") */ - char patt[MAX_PATH + 3]; + wchar_t patt[MAX_PATH + 3]; } DIR; @@ -91,12 +90,7 @@ static int closedir (DIR *dirp); /* use the new safe string functions introduced in Visual Studio 2005 */ -#if defined(_MSC_VER) && _MSC_VER >= 1400 -# define STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE) -#else -# define STRNCPY(dest,src,size) strncpy((dest),(src),(size)) -#endif - +# define STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE) /* * Open directory stream DIRNAME for read and return a pointer to the @@ -114,23 +108,29 @@ opendir( /* construct new DIR structure */ dirp = (DIR*) malloc (sizeof (struct DIR)); if (dirp != NULL) { - char *p; + wchar_t *p; /* take directory name... */ - STRNCPY (dirp->patt, dirname, sizeof(dirp->patt)); - dirp->patt[MAX_PATH] = '\0'; + MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, dirname, -1,dirp->patt, strlen(dirname)+1 ); + dirp->patt[MAX_PATH] = L'\0'; /* ... and append search pattern to it */ - p = strchr (dirp->patt, '\0'); - if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') { - *p++ = '\\'; + p = wcschr (dirp->patt, L'\0'); + if (dirp->patt < p && *(p-1) != L'\\' && *(p-1) != L':') { + *p++ = L'\\'; } - *p++ = '*'; - *p = '\0'; + *p++ = L'*'; + *p = L'\0'; /* open stream and retrieve first file */ - dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data); - if (dirp->search_handle == INVALID_HANDLE_VALUE) { + dirp->search_handle = FindFirstFileExW( dirp->patt, + FindExInfoStandard, + &dirp->current.data, + FindExSearchNameMatch, + NULL, + 0 );; + + if (dirp->search_handle == INVALID_HANDLE_VALUE) { /* invalid search pattern? */ free (dirp); return NULL; @@ -168,7 +168,7 @@ readdir( dirp->cached = 0; } else { /* read next directory entry from disk */ - if (FindNextFileA (dirp->search_handle, &dirp->current.data) == FALSE) { + if (FindNextFileW (dirp->search_handle, &dirp->current.data) == FALSE) { /* the very last file has been processed or an error occured */ FindClose (dirp->search_handle); dirp->search_handle = INVALID_HANDLE_VALUE; @@ -177,7 +177,7 @@ readdir( } /* copy as a multibyte character string */ - STRNCPY (dirp->current.d_name, dirp->current.data.cFileName, sizeof(dirp->current.d_name)); + WideCharToMultiByte(CP_ACP, 0, dirp->current.data.cFileName, -1, dirp->current.d_name, wcslen(dirp->current.data.cFileName)+1, NULL, NULL); dirp->current.d_name[MAX_PATH] = '\0'; return &dirp->current; diff --git a/projects/mtg/include/PrecompiledHeader.h b/projects/mtg/include/PrecompiledHeader.h index 3b7cc0ffa..5e6d0b458 100644 --- a/projects/mtg/include/PrecompiledHeader.h +++ b/projects/mtg/include/PrecompiledHeader.h @@ -15,16 +15,19 @@ #include +#ifdef WP8 +#include +#include +#else +#include +#endif + #include "JGE.h" #include "JFileSystem.h" #include "JLogger.h" #include "GameOptions.h" -#ifndef WP8 -#include -#endif - #if defined (WP8) || defined (IOS) || defined (ANDROID) || defined (QT_CONFIG) || defined (SDL_CONFIG) #define TOUCH_ENABLED #endif diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 9abe359a1..441122af6 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -7,7 +7,7 @@ #include "Player.h" #include "Counters.h" #include "AllAbilities.h" -#include +#include SUPPORT_OBJECT_ANALYTICS(ExtraCost) @@ -171,7 +171,7 @@ LifeorManaCost::LifeorManaCost(TargetChooser *_tc, string manaType) string buildType ="{"; buildType.append(manaType); buildType.append("}"); - boost::scoped_ptr cost(ManaCost::parseManaCost(buildType)); + std::unique_ptr cost(ManaCost::parseManaCost(buildType)); manaCost.copy(cost.get()); } diff --git a/projects/mtg/src/TranslateKeys.cpp b/projects/mtg/src/TranslateKeys.cpp index 829da2640..77f55b766 100644 --- a/projects/mtg/src/TranslateKeys.cpp +++ b/projects/mtg/src/TranslateKeys.cpp @@ -12,7 +12,7 @@ using std::map; static map fattable; static map slimtable; -#if defined(LINUX) || defined (IOS) || defined (ANDROID) || defined (SDL_CONFIG) || defined (QT_CONFIG) +#if defined(LINUX) || defined (IOS) || defined (ANDROID) || defined (SDL_CONFIG) || defined (QT_CONFIG) || defined (WP8) const KeyRep& translateKey(LocalKeySym key) { { @@ -23,7 +23,7 @@ const KeyRep& translateKey(LocalKeySym key) char* str = NULL; -#if !defined(QT_CONFIG) && !defined(IOS) && !defined (SDL_CONFIG) +#if !defined(QT_CONFIG) && !defined(IOS) && !defined (SDL_CONFIG) && !defined(WP8) str = XKeysymToString(key); #elif defined (SDL_CONFIG) str = (char*)SDL_GetKeyName(key); @@ -31,7 +31,7 @@ const KeyRep& translateKey(LocalKeySym key) if (!str) { str = NEW char[11]; - sprintf(str, "%lu", (long unsigned int)key); //TODO: Wagic is not supposed to know that a key actually is an unsingned long, so this part should probably be platform specific (move to JGE ?) + snprintf(str, 11, "%lu", (long unsigned int)key); //TODO: Wagic is not supposed to know that a key actually is an unsingned long, so this part should probably be platform specific (move to JGE ?) } const KeyRep k = make_pair(str, static_cast(NULL)); fattable[key] = k; @@ -184,9 +184,9 @@ const KeyRep& translateKey(JButton key) { } else { - char* str = NEW char[11]; - sprintf(str, "%d", key); - slimtable[key] = make_pair(str, static_cast (static_cast (NULL))); + char* str = NEW char[11]; + snprintf(str, 11, "%d", key); + slimtable[key] = make_pair(str, static_cast (static_cast (NULL))); } res = slimtable.find(key); } diff --git a/projects/mtg/wagic-qt.pro b/projects/mtg/wagic-qt.pro index 5f9544b9b..dca2e04e0 100644 --- a/projects/mtg/wagic-qt.pro +++ b/projects/mtg/wagic-qt.pro @@ -306,6 +306,7 @@ HEADERS += \ # JGE, could probably be moved outside SOURCES += \ + ../../JGE/src/corewrapper.cpp\ ../../JGE/src/Encoding.cpp\ ../../JGE/src/JAnimator.cpp\ ../../JGE/src/JApp.cpp\ @@ -323,9 +324,9 @@ SOURCES += \ ../../JGE/src/JParticleSystem.cpp\ ../../JGE/src/JResourceManager.cpp\ ../../JGE/src/JSpline.cpp\ - ../../JGE/src/JNetwork.cpp\ ../../JGE/src/pc/JSocket.cpp\ ../../JGE/src/pc/JSfx.cpp\ + ../../JGE/src/JNetwork.cpp\ ../../JGE/src/JSprite.cpp\ ../../JGE/src/Vector2D.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\ @@ -345,14 +346,14 @@ SOURCES += \ CONFIG(graphics, graphics|console){ SOURCES += \ ../../JGE/src/qt/filedownloader.cpp\ - ../../JGE/src/qt/corewrapper.cpp\ + ../../JGE/src/qt/qtcorewrapper.cpp\ ../../JGE/src/Qtmain.cpp\ ../../JGE/src/JMD2Model.cpp\ ../../JGE/src/pc/JGfx.cpp HEADERS += \ ../../JGE/include/qt/filedownloader.h\ - ../../JGE/include/qt/corewrapper.h + ../../JGE/include/qt/qtcorewrapper.h } else:CONFIG(console, graphics|console){ SOURCES += \ @@ -363,6 +364,7 @@ else:CONFIG(console, graphics|console){ HEADERS += \ ../../JGE/include/Threading.h\ + ../../JGE/include/corewrapper.h\ ../../JGE/include/decoder_prx.h\ ../../JGE/include/DebugRoutines.h\ ../../JGE/include/Encoding.h\