Added WRL frontend for Win8 and WP8

Merged Qt, SDL and WRL frontend on the same corewrapper
Moved OpenGL code out of SDL and Qt frontends to OpenGl backend
(JGfx.cpp)
Updated file system and network code to be compatible with WRL
This commit is contained in:
xawotihs
2013-11-17 16:46:44 +01:00
parent 9ac28d35a2
commit a6ba983650
31 changed files with 1660 additions and 1326 deletions

View File

@@ -156,6 +156,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Dependencies\SDL\src\main\windows\SDL_windows_main.c" /> <ClCompile Include="Dependencies\SDL\src\main\windows\SDL_windows_main.c" />
<ClCompile Include="src\corewrapper.cpp" />
<ClCompile Include="src\Encoding.cpp" /> <ClCompile Include="src\Encoding.cpp" />
<ClCompile Include="src\JAnimator.cpp" /> <ClCompile Include="src\JAnimator.cpp" />
<ClCompile Include="src\JApp.cpp"> <ClCompile Include="src\JApp.cpp">
@@ -298,6 +299,7 @@
<ClCompile Include="src\zipFS\zstream.cpp" /> <ClCompile Include="src\zipFS\zstream.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="include\corewrapper.h" />
<ClInclude Include="include\DebugRoutines.h" /> <ClInclude Include="include\DebugRoutines.h" />
<ClInclude Include="include\decoder_prx.h" /> <ClInclude Include="include\decoder_prx.h" />
<ClInclude Include="include\Encoding.h" /> <ClInclude Include="include\Encoding.h" />

View File

@@ -32,7 +32,7 @@ std::string ToHex(T* pointer)
#define DebugTrace(inString) \ #define DebugTrace(inString) \
{ \ { \
std::ostringstream stream; \ std::ostringstream stream; \
stream << inString; \ stream << inString << std::endl; \
qDebug("%s", stream.str().c_str()); \ qDebug("%s", stream.str().c_str()); \
} }
#elif defined (ANDROID) #elif defined (ANDROID)
@@ -48,7 +48,7 @@ std::string ToHex(T* pointer)
{ \ { \
std::ostringstream stream; \ std::ostringstream stream; \
stream << inString << std::endl; \ stream << inString << std::endl; \
OutputDebugString(stream.str().c_str()); \ OutputDebugStringA(stream.str().c_str()); \
} }
#endif // QT_CONFIG #endif // QT_CONFIG
#endif // Win32, Linux #endif // Win32, Linux

View File

@@ -16,7 +16,7 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#if (!defined IOS) && (!defined ANDROID) && (!defined QT_CONFIG) #if (!defined IOS) && (!defined ANDROID) && (!defined QT_CONFIG) && (!defined WP8)
#include <gif_lib.h> #include <gif_lib.h>
#endif //IOS ANDROID #endif //IOS ANDROID
@@ -24,9 +24,7 @@
#if defined (WIN32) #if defined (WIN32)
#include <windows.h> #include <windows.h>
#elif defined (PSP) #elif defined (PSP)
#include <pspgu.h> #include <pspgu.h>
@@ -53,7 +51,7 @@
#define COSF(x) cosf(x*DEG2RAD) #define COSF(x) cosf(x*DEG2RAD)
#endif #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 typedef struct
{ {
GLfloat m[4][4]; GLfloat m[4][4];
@@ -68,18 +66,23 @@ class JRenderer
{ {
protected: protected:
JRenderer(); JRenderer();
~JRenderer(); ~JRenderer();
void InitRenderer(); void InitRenderer();
void DestroyRenderer(); void DestroyRenderer();
float mActualWidth; float mWindowWidth;
float mActualHeight; float mWindowHeight;
float mLeft;
float mTop;
float mRight;
float mBottom;
public: public:
#if defined (PSP) #if defined (PSP)
int PixelSize(int textureMode); int PixelSize(int textureMode);
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@@ -529,28 +532,44 @@ public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void SetImageFilter(JImageFilter* imageFilter); 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. ** Set/Get methods for the actual display screen size.
*/ */
inline void SetActualWidth(float inWidth) inline void SetViewPort(float inLeft, float inTop, float inRight, float inBottom)
{ {
mActualWidth = inWidth; mLeft = inLeft;
} mTop = inTop;
mRight = inRight;
mBottom = inBottom;
}
inline void SetActualHeight(float inHeight) inline void GetViewPort(float& outLeft, float& outTop, float& outRight, float& outBottom)
{ {
mActualHeight = inHeight; outLeft = mLeft;
} outTop = mTop;
outRight = mRight;
outBottom = mBottom;
}
inline float GetActualWidth() inline float GetActualWidth()
{ {
return mActualWidth; return (mRight - mLeft);
} }
inline float GetActualHeight() inline float GetActualHeight()
{ {
return mActualHeight; return (mBottom - mTop);
} }
private: private:
@@ -564,10 +583,10 @@ private:
bool mVRAM; 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); 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); 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); 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); 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 ? #endif // (ANDROID) How can we get gif support for android ?
@@ -575,41 +594,52 @@ private:
static JRenderer* mInstance; static JRenderer* mInstance;
#if (!defined PSP) #ifdef WP8
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
D3D_FEATURE_LEVEL m_featureLevel;
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
Microsoft::WRL::ComPtr<IUnknown> m_Window;
ID3D11Buffer* m_vertexBuffer;
ID3D11Buffer* m_indexBuffer;
#elif (!defined PSP) && (!defined WP8) && (!defined CONSOLE_CONFIG)
GLuint mCurrentTex; GLuint mCurrentTex;
#if ((defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32)) && (!defined CONSOLE_CONFIG) #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32)
// MVP matrix // MVP matrix
ESMatrix theMvpMatrix; ESMatrix theMvpMatrix;
// Handle to a program object // Handle to a program object
GLuint prog1; GLuint prog1;
// Attribute locations // Attribute locations
GLint prog1_positionLoc; GLint prog1_positionLoc;
GLint prog1_colorLoc; GLint prog1_colorLoc;
// Uniform locations // Uniform locations
GLint prog1_mvpLoc; GLint prog1_mvpLoc;
// Handle to a program object // Handle to a program object
GLuint prog2; GLuint prog2;
// Sampler location // Sampler location
GLint prog2_samplerLoc; GLint prog2_samplerLoc;
// Attribute locations // Attribute locations
GLint prog2_positionLoc; GLint prog2_positionLoc;
GLint prog2_texCoordLoc; GLint prog2_texCoordLoc;
GLint prog2_colorLoc; GLint prog2_colorLoc;
// MVP matrix // MVP matrix
ESMatrix prog2_mvpMatrix; ESMatrix prog2_mvpMatrix;
// Uniform locations // Uniform locations
GLint prog2_mvpLoc; GLint prog2_mvpLoc;
#endif // (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #endif // (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
#else #elif (defined PSP)
void *fbp0, *fbp1, *zbp; void *fbp0, *fbp1, *zbp;
PIXEL_TYPE* mVRAM; PIXEL_TYPE* mVRAM;
int mCurrentTex; int mCurrentTex;
int mCurrentBlend; int mCurrentBlend;
int mCurrentTextureFormat; int mCurrentTextureFormat;
#endif #endif
bool mVsync; bool mVsync;

View File

@@ -1,8 +1,6 @@
#ifndef _JSOCKET_H_ #ifndef _JSOCKET_H_
#define _JSOCKET_H_ #define _JSOCKET_H_
#include <queue>
#include "Threading.h"
using namespace std; using namespace std;
#define SERVER_PORT 5001 #define SERVER_PORT 5001

View File

@@ -31,6 +31,13 @@
#endif #endif
#ifdef WP8
#define _XM_NO_INTRINSICS_
#include <wrl/client.h>
#include <d3d11_1.h>
#include <DirectXMath.h>
#endif
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(arg) #define __attribute__(arg)
#endif #endif
@@ -39,10 +46,10 @@
#define MAX_CHANNEL 128 #define MAX_CHANNEL 128
enum { enum {
JGE_ERR_CANT_OPEN_FILE = -1, JGE_ERR_CANT_OPEN_FILE = -1,
JGE_ERR_PNG = -2, JGE_ERR_PNG = -2,
JGE_ERR_MALLOC_FAILED = -4, JGE_ERR_MALLOC_FAILED = -4,
JGE_ERR_GENERIC = -5, JGE_ERR_GENERIC = -5,
}; };
#ifdef PSP #ifdef PSP
@@ -74,44 +81,43 @@ enum {
#define SCREEN_WIDTH_F 480.0f #define SCREEN_WIDTH_F 480.0f
#define SCREEN_HEIGHT_F 272.0f #define SCREEN_HEIGHT_F 272.0f
#ifdef CONSOLE_CONFIG #ifdef CONSOLE_CONFIG
#define DEFAULT_BLEND 0 #define DEFAULT_BLEND 0
#define BLEND_OPTION_ADD 0 #define BLEND_OPTION_ADD 0
#define BLEND_OPTION_BLEND 0 #define BLEND_OPTION_BLEND 0
#define BLEND_ZERO 0 #define BLEND_ZERO 0
#define BLEND_ONE 0 #define BLEND_ONE 0
#define BLEND_SRC_COLOR 0 #define BLEND_SRC_COLOR 0
#define BLEND_ONE_MINUS_SRC_COLOR 0 #define BLEND_ONE_MINUS_SRC_COLOR 0
#define BLEND_SRC_ALPHA 0 #define BLEND_SRC_ALPHA 0
#define BLEND_ONE_MINUS_SRC_ALPHA 0 #define BLEND_ONE_MINUS_SRC_ALPHA 0
#define BLEND_DST_ALPHA 0 #define BLEND_DST_ALPHA 0
#define BLEND_ONE_MINUS_DST_ALPHA 0 #define BLEND_ONE_MINUS_DST_ALPHA 0
#define BLEND_DST_COLOR 0 #define BLEND_DST_COLOR 0
#define BLEND_ONE_MINUS_DST_COLOR 0 #define BLEND_ONE_MINUS_DST_COLOR 0
#define BLEND_SRC_ALPHA_SATURATE 0 #define BLEND_SRC_ALPHA_SATURATE 0
#define GU_PSM_5551 0 #define GU_PSM_5551 0
#else #else
#ifdef WIN32 #ifdef WIN32
// #define DEFAULT_BLEND BLEND_DEFAULT // #define DEFAULT_BLEND BLEND_DEFAULT
// #define BLEND_OPTION_ADD BLEND_COLORADD // #define BLEND_OPTION_ADD BLEND_COLORADD
// #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE) // #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
#else #else
#define DEFAULT_BLEND GU_TFX_MODULATE #define DEFAULT_BLEND GU_TFX_MODULATE
#define BLEND_OPTION_ADD GU_TFX_ADD #define BLEND_OPTION_ADD GU_TFX_ADD
#define BLEND_OPTION_BLEND GU_TFX_BLEND #define BLEND_OPTION_BLEND GU_TFX_BLEND
#endif #endif
#endif // CONSOLE_CONFIG #endif // CONSOLE_CONFIG
#if (defined WIN32) && (!defined LINUX) #if ((defined WIN32) || (defined WP8)) && (!defined LINUX)
#include <windows.h> #include <windows.h>
#endif #endif
#if defined(LINUX) && (!defined WIN32) || defined(IOS) || defined (ANDROID) #if defined(LINUX) && (!defined WIN32) || defined(IOS) || defined (ANDROID)
typedef uint8_t byte; typedef uint8_t byte;
typedef uint32_t DWORD; typedef uint32_t DWORD;
typedef uint8_t BYTE; typedef uint8_t BYTE;
#ifndef IOS #ifndef IOS
typedef bool BOOL; typedef bool BOOL;
#endif #endif
#endif #endif
@@ -122,25 +128,26 @@ typedef uint8_t u8;
typedef uint16_t u16; typedef uint16_t u16;
typedef uint32_t u32; typedef uint32_t u32;
#define PIXEL_TYPE DWORD #define PIXEL_TYPE DWORD
#define ARGB(a, r, g, b) ((PIXEL_TYPE)((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #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 RGBA(r, g, b, a) ((PIXEL_TYPE)((a) << 24) | ((b) << 16) | ((g) << 8) | (r))
#define TEXTURE_FORMAT 0 #ifndef PSP
#define TEXTURE_FORMAT 0
#endif //PSP
#ifndef CONSOLE_CONFIG #ifndef CONSOLE_CONFIG
#ifndef QT_CONFIG #ifndef QT_CONFIG
#if defined (IOS) #if defined (IOS)
#import <OpenGLES/ES2/gl.h> #import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h> #import <OpenGLES/ES2/glext.h>
#import <OpenGLES/ES1/gl.h> #import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h> # import <OpenGLES/ES1/glext.h>
#elif defined (ANDROID) #elif defined (ANDROID)
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
#elif defined (WIN32) || defined (LINUX) #elif (defined (WIN32) && !defined (WP8)) || defined (LINUX)
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#endif #endif
#else #else
# include <QtOpenGL> # include <QtOpenGL>
@@ -158,117 +165,159 @@ typedef uint32_t u32;
#if defined (PSP) #if defined (PSP)
#ifndef ABGR8888 #ifndef ABGR8888
#define ABGR8888 #define ABGR8888
#endif #endif
#if defined (ABGR8888) #if defined (ABGR8888)
#define PIXEL_TYPE u32 #define PIXEL_TYPE u32
#ifndef ARGB #ifndef ARGB
#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format #define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format
#endif #endif
#define MAKE_COLOR(a, c) (a << 24 | c) #define MAKE_COLOR(a, c) (a << 24 | c)
#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels #define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels
#define MASK_BLUE 0x00FF0000 #define MASK_BLUE 0x00FF0000
#define MASK_GREEN 0x0000FF00 #define MASK_GREEN 0x0000FF00
#define MASK_RED 0x000000FF #define MASK_RED 0x000000FF
#define PIXEL_SIZE 4 #define PIXEL_SIZE 4
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888 #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
#define BUFFER_FORMAT GU_PSM_8888 #define BUFFER_FORMAT GU_PSM_8888
#define TEXTURE_FORMAT GU_PSM_8888 #define TEXTURE_FORMAT GU_PSM_8888
#define TEXTURE_COLOR_FORMAT GU_COLOR_8888 #define TEXTURE_COLOR_FORMAT GU_COLOR_8888
#elif defined (ABGR5551) #elif defined (ABGR5551)
#ifndef ARGB #ifndef ARGB
#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15)) #define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15))
#endif #endif
#define MAKE_COLOR(a, c) (((a>>7)<<15) | c) #define MAKE_COLOR(a, c) (((a>>7)<<15) | c)
#define MASK_ALPHA 0x8000 #define MASK_ALPHA 0x8000
#define MASK_BLUE 0x7C00 #define MASK_BLUE 0x7C00
#define MASK_GREEN 0x03E0 #define MASK_GREEN 0x03E0
#define MASK_RED 0x001F #define MASK_RED 0x001F
#define PIXEL_TYPE u16 #define PIXEL_TYPE u16
#define PIXEL_SIZE 2 #define PIXEL_SIZE 2
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551 #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
#define BUFFER_FORMAT GU_PSM_8888 #define BUFFER_FORMAT GU_PSM_8888
#define TEXTURE_FORMAT GU_PSM_5551 #define TEXTURE_FORMAT GU_PSM_5551
#define TEXTURE_COLOR_FORMAT GU_COLOR_5551 #define TEXTURE_COLOR_FORMAT GU_COLOR_5551
#elif defined (ABGR4444) #elif defined (ABGR4444)
#ifndef ARGB #ifndef ARGB
#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12)) #define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12))
#endif #endif
#define MAKE_COLOR(a, c) (((a>>4)<<12) | c) #define MAKE_COLOR(a, c) (((a>>4)<<12) | c)
#define MASK_ALPHA 0xF000 #define MASK_ALPHA 0xF000
#define MASK_BLUE 0x0F00 #define MASK_BLUE 0x0F00
#define MASK_GREEN 0x00F0 #define MASK_GREEN 0x00F0
#define MASK_RED 0x000F #define MASK_RED 0x000F
#define PIXEL_TYPE u16 #define PIXEL_TYPE u16
#define PIXEL_SIZE 2 #define PIXEL_SIZE 2
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444 #define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
#define BUFFER_FORMAT GU_PSM_4444 #define BUFFER_FORMAT GU_PSM_4444
#define TEXTURE_FORMAT GU_PSM_4444 #define TEXTURE_FORMAT GU_PSM_4444
#define TEXTURE_COLOR_FORMAT GU_COLOR_4444 #define TEXTURE_COLOR_FORMAT GU_COLOR_4444
#endif #endif
#define FRAME_BUFFER_WIDTH 512 #define FRAME_BUFFER_WIDTH 512
#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE #define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE
#define SLICE_SIZE_F 64.0f #define SLICE_SIZE_F 64.0f
typedef unsigned int DWORD; typedef unsigned int DWORD;
#define BLEND_ZERO 0x1000 #define BLEND_ZERO 0x1000
#define BLEND_ONE 0x1002 #define BLEND_ONE 0x1002
#define BLEND_SRC_COLOR GU_SRC_COLOR #define BLEND_SRC_COLOR GU_SRC_COLOR
#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR #define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR
#define BLEND_SRC_ALPHA GU_SRC_ALPHA #define BLEND_SRC_ALPHA GU_SRC_ALPHA
#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA #define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA
#define BLEND_DST_ALPHA GU_DST_ALPHA #define BLEND_DST_ALPHA GU_DST_ALPHA
#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA #define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA
#define BLEND_DST_COLOR GU_DST_COLOR #define BLEND_DST_COLOR GU_DST_COLOR
#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR #define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR
#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE #define BLEND_SRC_ALPHA_SATURATE BLEND_ONE
typedef struct typedef struct
{ {
ScePspFVector2 texture; ScePspFVector2 texture;
ScePspFVector3 pos; ScePspFVector3 pos;
} PSPVertex3D; } PSPVertex3D;
#else //non PSP #elif !defined(WP8) //non PSP
#define BLEND_ZERO GL_ZERO
#define BLEND_ZERO GL_ZERO #define BLEND_ONE GL_ONE
#define BLEND_ONE GL_ONE #define BLEND_SRC_COLOR GL_SRC_COLOR
#define BLEND_SRC_COLOR GL_SRC_COLOR #define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR
#define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR #define BLEND_SRC_ALPHA GL_SRC_ALPHA
#define BLEND_SRC_ALPHA GL_SRC_ALPHA #define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
#define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA #define BLEND_DST_ALPHA GL_DST_ALPHA
#define BLEND_DST_ALPHA GL_DST_ALPHA #define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA
#define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA #define BLEND_DST_COLOR GL_DST_COLOR
#define BLEND_DST_COLOR GL_DST_COLOR #define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR
#define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR #define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE
#define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE
#define GU_PSM_8888 0 #define GU_PSM_8888 0
#define GU_PSM_5551 0 #define GU_PSM_5551 0
#define GU_PSM_4444 0 #define GU_PSM_4444 0
#define GU_PSM_5650 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 #endif
#else #else
typedef uint32_t GLuint; typedef uint32_t GLuint;
typedef float GLfloat; typedef float GLfloat;
#endif //CONSOLE_CONFIG #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 struct Vertex
{ {
@@ -352,11 +401,14 @@ public:
int mFilter; int mFilter;
#if defined (PSP) #if defined (PSP)
int mTextureFormat; int mTextureFormat;
int mTexId; int mTexId;
bool mInVideoRAM; bool mInVideoRAM;
PIXEL_TYPE* mBits; PIXEL_TYPE* mBits;
#elif defined (WP8)
ID3D11Texture2D* mTexId;
u8* mBuffer;
#else #else
GLuint mTexId; GLuint mTexId;
u8* mBuffer; 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 #endif

View File

@@ -1,7 +1,7 @@
#ifndef THREADING_H #ifndef THREADING_H
#define THREADING_H #define THREADING_H
#if !defined(PSP) && !defined(QT_CONFIG) #if !defined(PSP) && !defined(QT_CONFIG) && !defined(WP8)
#include <boost/date_time.hpp> #include <boost/date_time.hpp>
#ifdef WIN32 #ifdef WIN32
@@ -14,7 +14,7 @@
#endif #endif
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#elif !defined(QT_CONFIG) #elif defined(PSP)
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@@ -538,6 +538,80 @@ namespace boost
} }
} }
#elif defined(WP8)
#include <thread>
#include <mutex>
namespace boost
{
typedef std::thread thread;
template <class Mutex>
struct unique_lock
{
unique_lock(Mutex& inMutex) : mMutex(&inMutex)
{
mMutex->lock();
}
~unique_lock()
{
mMutex->unlock();
}
Mutex* mMutex;
};
class mutex
{
public:
typedef unique_lock<mutex> 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
#endif // THREADING_H #endif // THREADING_H

88
JGE/include/corewrapper.h Normal file
View File

@@ -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<JButton> m_buttonQueue;
bool m_active;
};
#endif // COREWRAPPER_H

View File

@@ -1,5 +1,7 @@
#ifndef COREWRAPPER_H #ifndef QTCOREWRAPPER_H
#define COREWRAPPER_H #define QTCOREWRAPPER_H
#include "../include/corewrapper.h"
#include <QObject> #include <QObject>
#include <QElapsedTimer> #include <QElapsedTimer>
@@ -7,12 +9,6 @@
#include <QtDeclarative> #include <QtDeclarative>
#include <QGraphicsItem> #include <QGraphicsItem>
#endif //QT_WIDGET #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) #if (defined Q_WS_MAEMO_5)
// For screen on/off events support // For screen on/off events support
@@ -23,23 +19,11 @@
#include <QDBusInterface> #include <QDBusInterface>
#endif //Q_WS_MAEMO_5 #endif //Q_WS_MAEMO_5
class WagicWrapper
{
public:
WagicWrapper();
virtual ~WagicWrapper();
private:
JGE* m_engine;
JApp* m_app;
JGameLauncher* m_launcher;
};
#ifdef QT_WIDGET #ifdef QT_WIDGET
class WagicCore : public QGLWidget class QtWagicCore : public QGLWidget
#else #else
class WagicCore : public QDeclarativeItem class QtWagicCore : public QDeclarativeItem
#endif #endif
{ {
private: private:
@@ -48,7 +32,6 @@ private:
#else #else
typedef QDeclarativeItem super; typedef QDeclarativeItem super;
#endif //QT_WIDGET #endif //QT_WIDGET
void initApp();
public: public:
Q_OBJECT Q_OBJECT
@@ -59,36 +42,30 @@ public:
public: public:
explicit WagicCore(super *parent = 0); explicit QtWagicCore(super *parent = 0);
virtual ~WagicCore(); virtual ~QtWagicCore();
static int runTestSuite();
Q_INVOKABLE void doOK() { Q_INVOKABLE void doOK() {
doAndEnqueue(JGE_BTN_OK); m_Wagic.doOK();
}; };
Q_INVOKABLE void doNext() { Q_INVOKABLE void doNext() {
doAndEnqueue(JGE_BTN_PREV); m_Wagic.doNext();
}; };
Q_INVOKABLE void doCancel() { Q_INVOKABLE void doCancel() {
doAndEnqueue(JGE_BTN_SEC); m_Wagic.doCancel();
}; };
Q_INVOKABLE void doMenu() { Q_INVOKABLE void doMenu() {
doAndEnqueue(JGE_BTN_MENU); m_Wagic.doMenu();
}; };
Q_INVOKABLE void done() { Q_INVOKABLE void done() {
while(m_buttonQueue.size()) m_Wagic.done();
{
m_engine->ReleaseKey(m_buttonQueue.front());
m_buttonQueue.pop();
}
m_engine->ResetInput();
}; };
Q_INVOKABLE void pixelInput(int x, int y); Q_INVOKABLE void pixelInput(int x, int y);
Q_INVOKABLE qint64 getTick() { Q_INVOKABLE qint64 getTick() {
return g_startTimer.elapsed(); return g_startTimer.elapsed();
}; };
Q_INVOKABLE void doScroll(int x, int y, int) { 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 getNominalHeight(){ return SCREEN_HEIGHT;};
int getNominalWidth(){ return SCREEN_WIDTH;}; int getNominalWidth(){ return SCREEN_WIDTH;};
@@ -137,20 +114,14 @@ private slots:
private: private:
void timerEvent( QTimerEvent* ); void timerEvent( QTimerEvent* );
void doAndEnqueue(JButton action) {
m_engine->HoldKey_NoRepeat(action);
m_buttonQueue.push(action);
}
public: public:
// used mainly to mesure the delta between 2 updates // used mainly to mesure the delta between 2 updates
static QElapsedTimer g_startTimer; static QElapsedTimer g_startTimer;
private: private:
JGE* m_engine; WagicCore m_Wagic;
JApp* m_app;
JGameLauncher* m_launcher;
qint64 m_lastTickCount; qint64 m_lastTickCount;
std::queue<JButton> m_buttonQueue;
int m_timerId; int m_timerId;
bool m_active; bool m_active;
QRect m_viewPort; QRect m_viewPort;
@@ -171,4 +142,4 @@ private:
QML_DECLARE_TYPE(WagicCore) QML_DECLARE_TYPE(WagicCore)
#endif //QT_WIDGET #endif //QT_WIDGET
#endif // COREWRAPPER_H #endif // QTCOREWRAPPER_H

View File

@@ -135,6 +135,15 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
DebugTrace("User path " << userPath); DebugTrace("User path " << userPath);
DebugTrace("System path " << systemPath); DebugTrace("System path " << systemPath);
DebugTrace("Current path " << QDir::currentPath().toStdString()); 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 #else
//Find the Res.txt file and matching Res folders for backwards compatibility //Find the Res.txt file and matching Res folders for backwards compatibility
ifstream mfile("Res.txt"); ifstream mfile("Res.txt");

View File

@@ -10,7 +10,7 @@
// Should we add PrecompiledHeader.h to more platforms here? PSP Doesn't support it in JGE (erwan 2011/12/11) // 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" #include "PrecompiledHeader.h"
#endif #endif

View File

@@ -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; mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA;
// mLineWidth = 1.0f; // mLineWidth = 1.0f;
mCurrentTex = -1;
mFOV = 75.0f; mFOV = 75.0f;
#ifdef USING_MATH_TABLE #ifdef USING_MATH_TABLE
@@ -173,8 +176,6 @@ void JRenderer::EnableTextureFilter(bool flag)
mCurrentTextureFilter = TEX_FILTER_LINEAR; mCurrentTextureFilter = TEX_FILTER_LINEAR;
else else
mCurrentTextureFilter = TEX_FILTER_NEAREST; mCurrentTextureFilter = TEX_FILTER_NEAREST;
mCurrentTex = -1;
} }
void Swap(float *a, float *b) void Swap(float *a, float *b)

View File

@@ -8,7 +8,9 @@
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#if defined (IOS) || defined (ANDROID) || defined (WP8)
#include "PrecompiledHeader.h"
#endif
#include "../include/JLBFont.h" #include "../include/JLBFont.h"
#include "../include/JFileSystem.h" #include "../include/JFileSystem.h"

View File

@@ -4,13 +4,12 @@
*/ */
#include "../include/DebugRoutines.h" #if (defined WIN32) && (!defined QT_CONFIG)
#include "../include/JNetwork.h" #pragma comment(lib,"ws2_32.lib")
#include <winsock2.h>
#if defined (WIN32) || defined (LINUX) #elif defined (LINUX)
#else #elif defined (PSP)
#ifdef NETWORK_SUPPORT #ifdef NETWORK_SUPPORT
#include <pspkernel.h> #include <pspkernel.h>
#include <pspdebug.h> #include <pspdebug.h>
#include <pspsdk.h> #include <pspsdk.h>
@@ -29,9 +28,11 @@
#endif #endif
#endif #endif
#include "../include/JNetwork.h"
#include <sstream> #include <sstream>
#include "../include/JSocket.h" #include "../include/JSocket.h"
#include "../include/DebugRoutines.h"
map<string, JNetwork::CommandStruc> JNetwork::sCommandMap; map<string, JNetwork::CommandStruc> JNetwork::sCommandMap;

View File

@@ -19,7 +19,6 @@
#include <errno.h> #include <errno.h>
#endif #endif
#include "../include/JGE.h"
#include "../include/JSocket.h" #include "../include/JSocket.h"
JSocket::JSocket(){ JSocket::JSocket(){

View File

@@ -11,35 +11,11 @@
#endif //QT_WIDGET #endif //QT_WIDGET
#include "filedownloader.h" #include "filedownloader.h"
#include "GameApp.h" #include "GameApp.h"
#include "corewrapper.h" #include "qtcorewrapper.h"
QWidget* g_glwidget = NULL; 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() bool JGEToggleFullscreen()
{ {
@@ -54,11 +30,6 @@ bool JGEToggleFullscreen()
return true; return true;
} }
int JGEGetTime()
{
return (int)WagicCore::g_startTimer.elapsed();
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
QScopedPointer<QApplication> app QScopedPointer<QApplication> app
@@ -69,17 +40,10 @@ int main(int argc, char* argv[])
#endif //QT_WIDGET #endif //QT_WIDGET
if(argc >= 2 && strcmp(argv[1], "testsuite")==0) app->setApplicationName(QtWagicCore::getApplicationName());
{
int result = 0;
result += WagicCore::runTestSuite();
return result;
}
app->setApplicationName(WagicCore::getApplicationName());
FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME); FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME);
#ifdef QT_WIDGET #ifdef QT_WIDGET
g_glwidget = new WagicCore(); g_glwidget = new QtWagicCore();
g_glwidget->connect(&fileDownloader, SIGNAL(finished(int)), SLOT(start(int))); g_glwidget->connect(&fileDownloader, SIGNAL(finished(int)), SLOT(start(int)));
#else #else
qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore"); qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore");

View File

@@ -15,6 +15,7 @@
#include "../include/JRenderer.h" #include "../include/JRenderer.h"
#include "../include/JGameLauncher.h" #include "../include/JGameLauncher.h"
#include "DebugRoutines.h" #include "DebugRoutines.h"
#include "corewrapper.h"
#include <stdexcept> #include <stdexcept>
#include <iostream> #include <iostream>
#include <math.h> #include <math.h>
@@ -47,9 +48,7 @@ const int kTapEventTimeout = 250;
uint64_t lastTickCount; uint64_t lastTickCount;
JGE* g_engine = NULL;
JApp* g_app = NULL;
JGameLauncher* g_launcher = NULL;
#ifdef ANDROID #ifdef ANDROID
JNIEnv * mJNIEnv = NULL; JNIEnv * mJNIEnv = NULL;
jclass * mJNIClass = NULL; jclass * mJNIClass = NULL;
@@ -66,19 +65,15 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativePause(
JNIEnv* env, jclass cls) JNIEnv* env, jclass cls)
{ {
DebugTrace("Attempt pause"); DebugTrace("Attempt pause");
if (!g_engine) WagicCore::getInstance()->setActive(false);
return; DebugTrace("Pause done");
g_engine->Pause();
DebugTrace("Pause done");
} }
// Resume // Resume
extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume( extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume(
JNIEnv* env, jclass cls) JNIEnv* env, jclass cls)
{ {
if (!g_engine) WagicCore::getInstance()->setActive(true);
return;
g_engine->Resume();
} }
#endif #endif
@@ -89,7 +84,7 @@ public: /* For easy interfacing with JGE static functions */
bool Running; bool Running;
SDL_Window* window; SDL_Window* window;
SDL_Surface* Surf_Display; SDL_Surface* Surf_Display;
SDL_Rect viewPort; // SDL_Rect viewPort;
Uint32 lastMouseUpTime; Uint32 lastMouseUpTime;
Uint32 lastFingerDownTime; Uint32 lastFingerDownTime;
int windowed_w; int windowed_w;
@@ -99,6 +94,7 @@ public: /* For easy interfacing with JGE static functions */
int mMouseDownX; int mMouseDownX;
int mMouseDownY; int mMouseDownY;
WagicCore m_Wagic;
public: public:
SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), lastFingerDownTime(0), Running(true), mMouseDownX(0), mMouseDownY(0) SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), lastFingerDownTime(0), Running(true), mMouseDownX(0), mMouseDownY(0)
@@ -116,16 +112,13 @@ public:
while(Running) 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(m_Wagic.getActive())
{ OnEvent(&Event);
if(!g_engine->IsPaused())
OnEvent(&Event);
}
if(!g_engine->IsPaused())
OnUpdate();
} }
if(m_Wagic.getActive())
OnUpdate();
} }
OnCleanup(); OnCleanup();
@@ -138,44 +131,7 @@ public:
void OnResize(int width, int height) void OnResize(int width, int height)
{ {
DebugTrace("OnResize Width " << width << " height " << height); m_Wagic.onWindowResize((void*)0, (float)width, (float)height);
if ((GLfloat)width / (GLfloat)height <= ACTUAL_RATIO)
{
viewPort.x = 0;
viewPort.y = -(static_cast<int>(width / ACTUAL_RATIO) - height) / 2;
viewPort.w = width;
viewPort.h = static_cast<int>(width / ACTUAL_RATIO);
}
else
{
viewPort.x = -(static_cast<int>(height * ACTUAL_RATIO) - width) / 2;
viewPort.y = 0;
viewPort.w = static_cast<int>(height * ACTUAL_RATIO);
viewPort.h = height;
}
glViewport(viewPort.x, viewPort.y, viewPort.w, viewPort.h);
JRenderer::GetInstance()->SetActualWidth(static_cast<float>(viewPort.w));
JRenderer::GetInstance()->SetActualHeight(static_cast<float>(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
} }
void OnKeyPressed(const SDL_KeyboardEvent& event); void OnKeyPressed(const SDL_KeyboardEvent& event);
@@ -254,7 +210,7 @@ public:
case SDL_JOYBALLMOTION: case SDL_JOYBALLMOTION:
DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel); 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; 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() bool JGEToggleFullscreen()
{ {
//cycle between the display modes //cycle between the display modes
@@ -365,70 +271,11 @@ bool JGEToggleFullscreen()
return true; 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() void SdlApp::OnUpdate()
{ {
static int tickCount = 0; Running = m_Wagic.onUpdate();
tickCount = JGEGetTime(); if(Running)
int64_t dt = (tickCount - lastTickCount); m_Wagic.onRender();
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();
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
} }
@@ -437,28 +284,17 @@ void SdlApp::OnKeyPressed(const SDL_KeyboardEvent& event)
{ {
if (event.type == SDL_KEYDOWN) 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) 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) void SdlApp::OnMouseMoved(const SDL_MouseMotionEvent& event)
{ {
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); m_Wagic.onPointerMoved(WagicCore::LEFT, event.x, event.y);
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);
}
} }
void SdlApp::OnMouseDoubleClicked(const SDL_MouseButtonEvent& event) 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) void SdlApp::OnMouseWheel(int x, int y)
{ {
m_Wagic.onWheelChanged(x, y);
/*
if(!x && y) if(!x && y)
{ // Vertical wheel { // Vertical wheel
if(y > 0) if(y > 0)
@@ -491,7 +330,7 @@ void SdlApp::OnMouseWheel(int x, int y)
else else
{ {
g_engine->HoldKey_NoRepeat(JGE_BTN_RIGHT); g_engine->HoldKey_NoRepeat(JGE_BTN_RIGHT);
} }*/
} }
void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event) 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 */ if (event.button == SDL_BUTTON_LEFT) /* Left button */
{ {
// this is intended to convert window coordinate into game coordinate. m_Wagic.onPointerPressed(WagicCore::LEFT, event.x, event.y);
// 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);
}
} }
else if(event.button == SDL_BUTTON_RIGHT) /* Right button */ 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 */ 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) else if (event.type == SDL_MOUSEBUTTONUP)
{ {
if(event.button == SDL_BUTTON_LEFT) if(event.button == SDL_BUTTON_LEFT)
{ {
if (event.y >= viewPort.y && m_Wagic.onPointerReleased(WagicCore::LEFT, event.x, event.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);
}
} }
else if(event.button == SDL_BUTTON_RIGHT) 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) 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 // should be ignored, and will come through instead as a multigesture event
if (event.fingerId == 0) if (event.fingerId == 0)
{ {
if (event.y >= viewPort.y && if (event.type == SDL_FINGERDOWN)
event.y <= viewPort.y + viewPort.h &&
event.x >= viewPort.x &&
event.x <= viewPort.x + viewPort.w)
{ {
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); m_Wagic.onPointerPressed(WagicCore::LEFT, event.x, event.y);
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); }
else if (event.type == SDL_FINGERUP)
Uint32 eventTime = SDL_GetTicks(); {
if (event.type == SDL_FINGERDOWN) m_Wagic.onPointerReleased(WagicCore::LEFT, event.x, event.y);
{ }
mMouseDownX = event.x; else
mMouseDownY = event.y; {
m_Wagic.onPointerMoved(WagicCore::LEFT, event.x, 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);
}
} }
} }
@@ -664,52 +437,9 @@ bool SdlApp::OnInit()
#endif #endif
return false; return false;
} }
SDL_WM_SetCaption(g_launcher->GetName(), ""); SDL_WM_SetCaption(m_Wagic.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;
}
m_Wagic.initApp();
OnResize(window_w, window_h); OnResize(window_w, window_h);
return true; return true;
@@ -732,27 +462,12 @@ int main(int argc, char* argv[])
DebugTrace("I R in da native"); 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(); g_SdlApp = new SdlApp();
int result = g_SdlApp->OnExecute(); int result = g_SdlApp->OnExecute();
if (g_launcher)
delete g_launcher;
if(g_SdlApp) if(g_SdlApp)
delete g_SdlApp; delete g_SdlApp;
// Shutdown
DestroyGame();
return result; return result;
} }

309
JGE/src/WRLmain.cpp Normal file
View File

@@ -0,0 +1,309 @@
#include <wrl/client.h>
#include <memory>
#include <agile.h>
#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<float>(
static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) /
static_cast<double>(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<float>(
static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) /
static_cast<double>(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<CoreApplicationView^, IActivatedEventArgs^>(this, &WagicApp::OnActivated);
CoreApplication::Suspending +=
ref new EventHandler<SuspendingEventArgs^>(this, &WagicApp::OnSuspending);
CoreApplication::Resuming +=
ref new EventHandler<Platform::Object^>(this, &WagicApp::OnResuming);
}
void WagicApp::SetWindow(CoreWindow^ window)
{
window->SizeChanged +=
ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &WagicApp::OnWindowSizeChanged);
window->VisibilityChanged +=
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &WagicApp::OnVisibilityChanged);
window->Closed +=
ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &WagicApp::OnWindowClosed);
window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
window->PointerPressed +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &WagicApp::OnPointerPressed);
window->PointerMoved +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &WagicApp::OnPointerMoved);
window->KeyDown +=
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &WagicApp::OnKeyDown);
window->KeyDown +=
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &WagicApp::OnKeyUp);
window->PointerWheelChanged +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(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<Platform::String^>^)
{
auto wagicAppSource = ref new WagicAppSource();
CoreApplication::Run(wagicAppSource);
return 0;
}
bool JGEToggleFullscreen()
{
return true;
}

374
JGE/src/corewrapper.cpp Normal file
View File

@@ -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(y<top) {
m_engine->HoldKey_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
}

View File

@@ -9,6 +9,24 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#define GL_GLEXT_PROTOTYPES #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) #if (!defined IOS) && (!defined QT_CONFIG)
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
@@ -310,13 +328,10 @@ void JQuad::SetTextureRect(float x, float y, float w, float h)
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
if(mTex) mTX0 = x/mTex->mTexWidth;
{ mTY0 = y/mTex->mTexHeight;
mTX0 = x/mTex->mTexWidth; mTX1 = (x+w)/mTex->mTexWidth;
mTY0 = y/mTex->mTexHeight; mTY1 = (y+h)/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) #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
void esMatrixLoadIdentity(ESMatrix *result) void esMatrixLoadIdentity(ESMatrix *result)
{ {
@@ -710,6 +748,43 @@ GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
void JRenderer::InitRenderer() void JRenderer::InitRenderer()
{ {
checkGlError(); 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; mCurrentTextureFilter = TEX_FILTER_NONE;
mImageFilter = NULL; mImageFilter = NULL;
@@ -819,16 +894,16 @@ void JRenderer::BeginScene()
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer 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) #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
glLoadIdentity (); // Reset The Modelview Matrix 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 #else
esMatrixLoadIdentity(&theMvpMatrix); esMatrixLoadIdentity(&theMvpMatrix);
esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f); 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) #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(); checkGlError();
} }
@@ -843,7 +918,7 @@ void JRenderer::EndScene()
void JRenderer::BindTexture(JTexture *tex) void JRenderer::BindTexture(JTexture *tex)
{ {
checkGlError(); checkGlError();
if (tex && mCurrentTex != tex->mTexId) if (mCurrentTex != tex->mTexId)
{ {
mCurrentTex = tex->mTexId; mCurrentTex = tex->mTexId;

View File

@@ -1,11 +1,15 @@
#include <errno.h>
#ifdef WIN32 #ifdef WIN32
#ifdef QT_CONFIG
#pragma comment(lib,"WSOCK32.LIB") #pragma comment(lib,"WSOCK32.LIB")
#include <stdio.h> #include <stdio.h>
#include <conio.h> #include <conio.h>
#include <winsock.h> #include <winsock.h>
#include <winsock.h> #include <winsock.h>
#include <fcntl.h> #include <fcntl.h>
#else
#pragma comment(lib,"ws2_32.lib")
#include <winsock2.h>
#endif
#elif LINUX #elif LINUX
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -13,7 +17,9 @@
#include <netdb.h> #include <netdb.h>
#include <fcntl.h> #include <fcntl.h>
#endif //WINDOWS #endif //WINDOWS
#include <errno.h>
#include <string>
#include "../../include/JSocket.h" #include "../../include/JSocket.h"
#include "../../include/DebugRoutines.h" #include "../../include/DebugRoutines.h"

View File

@@ -1,596 +0,0 @@
#include <qplatformdefs.h>
#include <QtOpenGL>
#include "corewrapper.h"
#include <QElapsedTimer>
#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()<m_viewPort.top()) {
m_engine->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<QGestureEvent*>(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<QTapAndHoldGesture *>(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

View File

@@ -0,0 +1,309 @@
#include <qplatformdefs.h>
#include <QtOpenGL>
#include "qtcorewrapper.h"
#include <QElapsedTimer>
#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<QGestureEvent*>(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<QTapAndHoldGesture *>(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

View File

@@ -47,9 +47,8 @@
#if defined WIN32 #if defined WIN32 || defined WP8
#include <io.h> // Windows I/O facilities (Directories) #include <PrecompiledHeader.h>
#else
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
#endif #endif
@@ -86,14 +85,9 @@ public:
protected: protected:
bool m_Valid; bool m_Valid;
#if defined WIN32
intptr_t m_hFiles;
_finddata_t m_FindData;
#else
DIR * m_Directory; DIR * m_Directory;
std::string m_Extension; std::string m_Extension;
struct dirent * m_DirectoryEntry; 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() inline search_iterator::search_iterator()
: m_Valid(false), : m_Valid(false),
#if defined WIN32
m_hFiles(-1)
#else
m_Directory(NULL) m_Directory(NULL)
#endif
{ } { }
inline search_iterator::search_iterator(const char * FileSpec) inline search_iterator::search_iterator(const char * FileSpec)
: m_Valid(false), : m_Valid(false),
#if defined WIN32
m_hFiles(-1)
#else
m_Directory(NULL) m_Directory(NULL)
#endif
{ {
begin(FileSpec); begin(FileSpec);
} }
inline search_iterator::~search_iterator() { inline search_iterator::~search_iterator() {
#if defined WIN32
if (m_hFiles != -1) _findclose(m_hFiles);
#else
if (m_Directory != NULL) closedir(m_Directory); if (m_Directory != NULL) closedir(m_Directory);
#endif
} }
inline search_iterator::operator bool () const { 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) { 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; std::string DirectoryName;
if (m_Directory != NULL) closedir(m_Directory); if (m_Directory != NULL) closedir(m_Directory);
int i; int i;
for (i = strlen(FileSpec); i >= 0; --i) for (i = strlen(FileSpec); i >= 0; --i)
if (FileSpec[i] == '/') break; if (FileSpec[i] == '/' || FileSpec[i] == '\\') break;
if (i < 0) if (i < 0)
DirectoryName = "."; DirectoryName = ".";
@@ -204,7 +182,6 @@ inline search_iterator & search_iterator::begin(const char * FileSpec) {
return (* this); return (* this);
next(); next();
#endif
return (* this); return (* this);
} }
@@ -214,9 +191,6 @@ inline bool search_iterator::end() const {
} }
inline search_iterator & search_iterator::next() { inline search_iterator & search_iterator::next() {
#if defined WIN32
m_Valid = (_findnext(m_hFiles, &m_FindData) != -1);
#else
bool Found = false; bool Found = false;
while (! Found) { while (! Found) {
m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL); m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL);
@@ -235,17 +209,12 @@ inline search_iterator & search_iterator::next() {
else else
break; break;
} }
#endif
return (* this); return (* this);
} }
inline std::string search_iterator::Name() const { inline std::string search_iterator::Name() const {
#if defined WIN32
return (m_FindData.name);
#else
return (m_DirectoryEntry->d_name); return (m_DirectoryEntry->d_name);
#endif
} }

View File

@@ -503,7 +503,7 @@ bool filesystem::PreloadZip(const char * Filename, map<string, limited_file_info
continue; continue;
target[Name] = limited_file_info( target[Name] = limited_file_info(
realBeginOfFile + FileHdr.m_RelOffset, // "Local File" header offset position (size_t)realBeginOfFile + FileHdr.m_RelOffset, // "Local File" header offset position
FileHdr.m_UncompSize // File Size FileHdr.m_UncompSize // File Size
); );
} }

View File

@@ -60,13 +60,12 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
typedef struct dirent { typedef struct dirent {
/* name of current directory entry (a multi-byte character string) */ /* name of current directory entry (a multi-byte character string) */
char d_name[MAX_PATH + 1]; char d_name[MAX_PATH + 1];
/* file attributes */ /* file attributes */
WIN32_FIND_DATAA data; WIN32_FIND_DATAW data;
} dirent; } dirent;
@@ -81,7 +80,7 @@ typedef struct DIR {
HANDLE search_handle; HANDLE search_handle;
/* search pattern (3 = zero terminator + pattern "\\*") */ /* search pattern (3 = zero terminator + pattern "\\*") */
char patt[MAX_PATH + 3]; wchar_t patt[MAX_PATH + 3];
} DIR; } DIR;
@@ -91,12 +90,7 @@ static int closedir (DIR *dirp);
/* use the new safe string functions introduced in Visual Studio 2005 */ /* use the new safe string functions introduced in Visual Studio 2005 */
#if defined(_MSC_VER) && _MSC_VER >= 1400 # define STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
# define STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
#else
# define STRNCPY(dest,src,size) strncpy((dest),(src),(size))
#endif
/* /*
* Open directory stream DIRNAME for read and return a pointer to the * Open directory stream DIRNAME for read and return a pointer to the
@@ -114,23 +108,29 @@ opendir(
/* construct new DIR structure */ /* construct new DIR structure */
dirp = (DIR*) malloc (sizeof (struct DIR)); dirp = (DIR*) malloc (sizeof (struct DIR));
if (dirp != NULL) { if (dirp != NULL) {
char *p; wchar_t *p;
/* take directory name... */ /* take directory name... */
STRNCPY (dirp->patt, dirname, sizeof(dirp->patt)); MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, dirname, -1,dirp->patt, strlen(dirname)+1 );
dirp->patt[MAX_PATH] = '\0'; dirp->patt[MAX_PATH] = L'\0';
/* ... and append search pattern to it */ /* ... and append search pattern to it */
p = strchr (dirp->patt, '\0'); p = wcschr (dirp->patt, L'\0');
if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') { if (dirp->patt < p && *(p-1) != L'\\' && *(p-1) != L':') {
*p++ = '\\'; *p++ = L'\\';
} }
*p++ = '*'; *p++ = L'*';
*p = '\0'; *p = L'\0';
/* open stream and retrieve first file */ /* open stream and retrieve first file */
dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data); dirp->search_handle = FindFirstFileExW( dirp->patt,
if (dirp->search_handle == INVALID_HANDLE_VALUE) { FindExInfoStandard,
&dirp->current.data,
FindExSearchNameMatch,
NULL,
0 );;
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* invalid search pattern? */ /* invalid search pattern? */
free (dirp); free (dirp);
return NULL; return NULL;
@@ -168,7 +168,7 @@ readdir(
dirp->cached = 0; dirp->cached = 0;
} else { } else {
/* read next directory entry from disk */ /* 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 */ /* the very last file has been processed or an error occured */
FindClose (dirp->search_handle); FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
@@ -177,7 +177,7 @@ readdir(
} }
/* copy as a multibyte character string */ /* 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'; dirp->current.d_name[MAX_PATH] = '\0';
return &dirp->current; return &dirp->current;

View File

@@ -15,16 +15,19 @@
#include <assert.h> #include <assert.h>
#ifdef WP8
#include <wrl.h>
#include <wrl/client.h>
#else
#include <boost/shared_ptr.hpp>
#endif
#include "JGE.h" #include "JGE.h"
#include "JFileSystem.h" #include "JFileSystem.h"
#include "JLogger.h" #include "JLogger.h"
#include "GameOptions.h" #include "GameOptions.h"
#ifndef WP8
#include <boost/shared_ptr.hpp>
#endif
#if defined (WP8) || defined (IOS) || defined (ANDROID) || defined (QT_CONFIG) || defined (SDL_CONFIG) #if defined (WP8) || defined (IOS) || defined (ANDROID) || defined (QT_CONFIG) || defined (SDL_CONFIG)
#define TOUCH_ENABLED #define TOUCH_ENABLED
#endif #endif

View File

@@ -7,7 +7,7 @@
#include "Player.h" #include "Player.h"
#include "Counters.h" #include "Counters.h"
#include "AllAbilities.h" #include "AllAbilities.h"
#include <boost/scoped_ptr.hpp> #include <memory>
SUPPORT_OBJECT_ANALYTICS(ExtraCost) SUPPORT_OBJECT_ANALYTICS(ExtraCost)
@@ -171,7 +171,7 @@ LifeorManaCost::LifeorManaCost(TargetChooser *_tc, string manaType)
string buildType ="{"; string buildType ="{";
buildType.append(manaType); buildType.append(manaType);
buildType.append("}"); buildType.append("}");
boost::scoped_ptr<ManaCost> cost(ManaCost::parseManaCost(buildType)); std::unique_ptr<ManaCost> cost(ManaCost::parseManaCost(buildType));
manaCost.copy(cost.get()); manaCost.copy(cost.get());
} }

View File

@@ -12,7 +12,7 @@ using std::map;
static map<const LocalKeySym, KeyRep> fattable; static map<const LocalKeySym, KeyRep> fattable;
static map<const JButton, KeyRep> slimtable; static map<const JButton, KeyRep> 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) const KeyRep& translateKey(LocalKeySym key)
{ {
{ {
@@ -23,7 +23,7 @@ const KeyRep& translateKey(LocalKeySym key)
char* str = NULL; 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); str = XKeysymToString(key);
#elif defined (SDL_CONFIG) #elif defined (SDL_CONFIG)
str = (char*)SDL_GetKeyName(key); str = (char*)SDL_GetKeyName(key);
@@ -31,7 +31,7 @@ const KeyRep& translateKey(LocalKeySym key)
if (!str) if (!str)
{ {
str = NEW char[11]; 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<JQuad*>(NULL)); const KeyRep k = make_pair(str, static_cast<JQuad*>(NULL));
fattable[key] = k; fattable[key] = k;
@@ -184,9 +184,9 @@ const KeyRep& translateKey(JButton key) {
} }
else else
{ {
char* str = NEW char[11]; char* str = NEW char[11];
sprintf(str, "%d", key); snprintf(str, 11, "%d", key);
slimtable[key] = make_pair(str, static_cast<JQuad*> (static_cast<JQuad*> (NULL))); slimtable[key] = make_pair(str, static_cast<JQuad*> (static_cast<JQuad*> (NULL)));
} }
res = slimtable.find(key); res = slimtable.find(key);
} }

View File

@@ -306,6 +306,7 @@ HEADERS += \
# JGE, could probably be moved outside # JGE, could probably be moved outside
SOURCES += \ SOURCES += \
../../JGE/src/corewrapper.cpp\
../../JGE/src/Encoding.cpp\ ../../JGE/src/Encoding.cpp\
../../JGE/src/JAnimator.cpp\ ../../JGE/src/JAnimator.cpp\
../../JGE/src/JApp.cpp\ ../../JGE/src/JApp.cpp\
@@ -323,9 +324,9 @@ SOURCES += \
../../JGE/src/JParticleSystem.cpp\ ../../JGE/src/JParticleSystem.cpp\
../../JGE/src/JResourceManager.cpp\ ../../JGE/src/JResourceManager.cpp\
../../JGE/src/JSpline.cpp\ ../../JGE/src/JSpline.cpp\
../../JGE/src/JNetwork.cpp\
../../JGE/src/pc/JSocket.cpp\ ../../JGE/src/pc/JSocket.cpp\
../../JGE/src/pc/JSfx.cpp\ ../../JGE/src/pc/JSfx.cpp\
../../JGE/src/JNetwork.cpp\
../../JGE/src/JSprite.cpp\ ../../JGE/src/JSprite.cpp\
../../JGE/src/Vector2D.cpp\ ../../JGE/src/Vector2D.cpp\
../../JGE/src/tinyxml/tinystr.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\
@@ -345,14 +346,14 @@ SOURCES += \
CONFIG(graphics, graphics|console){ CONFIG(graphics, graphics|console){
SOURCES += \ SOURCES += \
../../JGE/src/qt/filedownloader.cpp\ ../../JGE/src/qt/filedownloader.cpp\
../../JGE/src/qt/corewrapper.cpp\ ../../JGE/src/qt/qtcorewrapper.cpp\
../../JGE/src/Qtmain.cpp\ ../../JGE/src/Qtmain.cpp\
../../JGE/src/JMD2Model.cpp\ ../../JGE/src/JMD2Model.cpp\
../../JGE/src/pc/JGfx.cpp ../../JGE/src/pc/JGfx.cpp
HEADERS += \ HEADERS += \
../../JGE/include/qt/filedownloader.h\ ../../JGE/include/qt/filedownloader.h\
../../JGE/include/qt/corewrapper.h ../../JGE/include/qt/qtcorewrapper.h
} }
else:CONFIG(console, graphics|console){ else:CONFIG(console, graphics|console){
SOURCES += \ SOURCES += \
@@ -363,6 +364,7 @@ else:CONFIG(console, graphics|console){
HEADERS += \ HEADERS += \
../../JGE/include/Threading.h\ ../../JGE/include/Threading.h\
../../JGE/include/corewrapper.h\
../../JGE/include/decoder_prx.h\ ../../JGE/include/decoder_prx.h\
../../JGE/include/DebugRoutines.h\ ../../JGE/include/DebugRoutines.h\
../../JGE/include/Encoding.h\ ../../JGE/include/Encoding.h\