mirror of https://github.com/axmolengine/axmol.git
Merge pull request #695 from GermanMtz/master
fixed #963: Member variable added to keep the current window active status
This commit is contained in:
commit
5c65af137b
|
@ -1,104 +1,104 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "CCAccelerometer_qnx.h"
|
#include "CCAccelerometer_qnx.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <bps/accelerometer.h>
|
#include <bps/accelerometer.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#define BUFFER_SIZE 30
|
#define BUFFER_SIZE 30
|
||||||
|
|
||||||
namespace cocos2d
|
namespace cocos2d
|
||||||
{
|
{
|
||||||
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
|
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
|
||||||
int CCAccelerometer::m_initialOrientationAngle = 0;
|
int CCAccelerometer::m_initialOrientationAngle = 0;
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer()
|
CCAccelerometer::CCAccelerometer()
|
||||||
{
|
{
|
||||||
m_pAccelDelegate = NULL;
|
m_pAccelDelegate = NULL;
|
||||||
m_initialOrientationAngle = atoi(getenv("ORIENTATION"));
|
m_initialOrientationAngle = atoi(getenv("ORIENTATION"));
|
||||||
|
|
||||||
accelerometer_set_update_frequency(FREQ_40_HZ);
|
accelerometer_set_update_frequency(FREQ_40_HZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAccelerometer::~CCAccelerometer()
|
CCAccelerometer::~CCAccelerometer()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
||||||
{
|
{
|
||||||
if (m_spCCAccelerometer == NULL)
|
if (m_spCCAccelerometer == NULL)
|
||||||
m_spCCAccelerometer = new CCAccelerometer();
|
m_spCCAccelerometer = new CCAccelerometer();
|
||||||
|
|
||||||
return m_spCCAccelerometer;
|
return m_spCCAccelerometer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
||||||
{
|
{
|
||||||
m_pAccelDelegate = pDelegate;
|
m_pAccelDelegate = pDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::update(long timeStamp)
|
void CCAccelerometer::update(long timeStamp)
|
||||||
{
|
{
|
||||||
if ( m_pAccelDelegate != NULL)
|
if ( m_pAccelDelegate != NULL)
|
||||||
{
|
{
|
||||||
int angle = atoi(getenv("ORIENTATION"));
|
int angle = atoi(getenv("ORIENTATION"));
|
||||||
|
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
|
|
||||||
accelerometer_read_forces(&x, &y, &z);
|
accelerometer_read_forces(&x, &y, &z);
|
||||||
|
|
||||||
if (m_initialOrientationAngle == 270)
|
if (m_initialOrientationAngle == 270)
|
||||||
{
|
{
|
||||||
m_accelerationValue.x = y;
|
m_accelerationValue.x = y;
|
||||||
m_accelerationValue.y = -x;
|
m_accelerationValue.y = -x;
|
||||||
}
|
}
|
||||||
else if (m_initialOrientationAngle == 90)
|
else if (m_initialOrientationAngle == 90)
|
||||||
{
|
{
|
||||||
m_accelerationValue.x = -y;
|
m_accelerationValue.x = -y;
|
||||||
m_accelerationValue.y = x;
|
m_accelerationValue.y = x;
|
||||||
}
|
}
|
||||||
else if (m_initialOrientationAngle == 0)
|
else if (m_initialOrientationAngle == 0)
|
||||||
{
|
{
|
||||||
m_accelerationValue.x = x;
|
m_accelerationValue.x = x;
|
||||||
m_accelerationValue.y = y;
|
m_accelerationValue.y = y;
|
||||||
}
|
}
|
||||||
else if (m_initialOrientationAngle == 180)
|
else if (m_initialOrientationAngle == 180)
|
||||||
{
|
{
|
||||||
m_accelerationValue.x = -x;
|
m_accelerationValue.x = -x;
|
||||||
m_accelerationValue.y = -y;
|
m_accelerationValue.y = -y;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_accelerationValue.z = z;
|
m_accelerationValue.z = z;
|
||||||
m_accelerationValue.timestamp = (double)timeStamp;
|
m_accelerationValue.timestamp = (double)timeStamp;
|
||||||
|
|
||||||
m_pAccelDelegate->didAccelerate(&m_accelerationValue);
|
m_pAccelDelegate->didAccelerate(&m_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace cococs2d
|
} // end of namespace cococs2d
|
||||||
|
|
||||||
|
|
|
@ -1,55 +1,55 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __PLATFORM_QNX_CCACCELEROMETER_H__
|
#ifndef __PLATFORM_QNX_CCACCELEROMETER_H__
|
||||||
#define __PLATFORM_QNX_CCACCELEROMETER_H__
|
#define __PLATFORM_QNX_CCACCELEROMETER_H__
|
||||||
|
|
||||||
#include "CCCommon.h"
|
#include "CCCommon.h"
|
||||||
#include "CCAccelerometerDelegate.h"
|
#include "CCAccelerometerDelegate.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
class CC_DLL CCAccelerometer
|
class CC_DLL CCAccelerometer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
static CCAccelerometer* sharedAccelerometer();
|
static CCAccelerometer* sharedAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
||||||
void update(long sensorTimeStamp);
|
void update(long sensorTimeStamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static CCAccelerometer* m_spCCAccelerometer;
|
static CCAccelerometer* m_spCCAccelerometer;
|
||||||
CCAccelerometerDelegate* m_pAccelDelegate;
|
CCAccelerometerDelegate* m_pAccelDelegate;
|
||||||
CCAcceleration m_accelerationValue;
|
CCAcceleration m_accelerationValue;
|
||||||
static int m_initialOrientationAngle;
|
static int m_initialOrientationAngle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,146 +1,146 @@
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
|
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCAccelerometer.h"
|
#include "CCAccelerometer.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <bps/locale.h>
|
#include <bps/locale.h>
|
||||||
|
|
||||||
#define LOGD(...) fprintf(stderr, __VA_ARGS__)
|
#define LOGD(...) fprintf(stderr, __VA_ARGS__)
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
// sharedApplication pointer
|
// sharedApplication pointer
|
||||||
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
||||||
long CCApplication::m_animationInterval = 1000;
|
long CCApplication::m_animationInterval = 1000;
|
||||||
|
|
||||||
// convert the timespec into milliseconds
|
// convert the timespec into milliseconds
|
||||||
static long time2millis(struct timespec *times)
|
static long time2millis(struct timespec *times)
|
||||||
{
|
{
|
||||||
return times->tv_sec*1000 + times->tv_nsec/1000000;
|
return times->tv_sec*1000 + times->tv_nsec/1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCApplication::CCApplication()
|
CCApplication::CCApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(! sm_pSharedApplication);
|
CC_ASSERT(! sm_pSharedApplication);
|
||||||
sm_pSharedApplication = this;
|
sm_pSharedApplication = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCApplication::~CCApplication()
|
CCApplication::~CCApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(this == sm_pSharedApplication);
|
CC_ASSERT(this == sm_pSharedApplication);
|
||||||
sm_pSharedApplication = NULL;
|
sm_pSharedApplication = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCApplication::run()
|
int CCApplication::run()
|
||||||
{
|
{
|
||||||
struct timespec time_struct;
|
struct timespec time_struct;
|
||||||
long current_time, update_time;
|
long current_time, update_time;
|
||||||
|
|
||||||
// Initialize instance and cocos2d.
|
// Initialize instance and cocos2d.
|
||||||
if (!initInstance() || !applicationDidFinishLaunching())
|
if (!initInstance() || !applicationDidFinishLaunching())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &time_struct);
|
clock_gettime(CLOCK_REALTIME, &time_struct);
|
||||||
update_time = time2millis(&time_struct);
|
update_time = time2millis(&time_struct);
|
||||||
|
|
||||||
|
|
||||||
while (1) // or device wants to quit
|
while (1) // or device wants to quit
|
||||||
{
|
{
|
||||||
CCEGLView::sharedOpenGLView().HandleEvents();
|
CCEGLView::sharedOpenGLView().HandleEvents();
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &time_struct);
|
clock_gettime(CLOCK_REALTIME, &time_struct);
|
||||||
current_time = time2millis(&time_struct);
|
current_time = time2millis(&time_struct);
|
||||||
|
|
||||||
if ((current_time - update_time) > m_animationInterval)
|
if ((current_time - update_time) > m_animationInterval)
|
||||||
{
|
{
|
||||||
update_time = current_time;
|
update_time = current_time;
|
||||||
|
|
||||||
CCAccelerometer::sharedAccelerometer()->update(current_time);
|
CCAccelerometer::sharedAccelerometer()->update(current_time);
|
||||||
CCDirector::sharedDirector()->mainLoop();
|
CCDirector::sharedDirector()->mainLoop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// sleep(0);
|
// sleep(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCApplication::setAnimationInterval(double interval)
|
void CCApplication::setAnimationInterval(double interval)
|
||||||
{
|
{
|
||||||
// interval in milliseconds
|
// interval in milliseconds
|
||||||
m_animationInterval = (long)(interval * 1000);
|
m_animationInterval = (long)(interval * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
|
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
|
||||||
{
|
{
|
||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCApplication::statusBarFrame(CCRect * rect)
|
void CCApplication::statusBarFrame(CCRect * rect)
|
||||||
{
|
{
|
||||||
if (rect)
|
if (rect)
|
||||||
{
|
{
|
||||||
// qnx doesn't have a status bar
|
// qnx doesn't have a status bar
|
||||||
*rect = CCRectMake(0, 0, 0, 0);
|
*rect = CCRectMake(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// static member function
|
// static member function
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
CCApplication& CCApplication::sharedApplication()
|
CCApplication& CCApplication::sharedApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(sm_pSharedApplication);
|
CC_ASSERT(sm_pSharedApplication);
|
||||||
return *sm_pSharedApplication;
|
return *sm_pSharedApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccLanguageType CCApplication::getCurrentLanguage()
|
ccLanguageType CCApplication::getCurrentLanguage()
|
||||||
{
|
{
|
||||||
ccLanguageType ret_language = kLanguageEnglish;
|
ccLanguageType ret_language = kLanguageEnglish;
|
||||||
char *language, *country;
|
char *language, *country;
|
||||||
|
|
||||||
locale_get(&language, &country);
|
locale_get(&language, &country);
|
||||||
|
|
||||||
if (strcmp(language, "en") == 0)
|
if (strcmp(language, "en") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageEnglish;
|
ret_language = kLanguageEnglish;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "fr") == 0)
|
else if (strcmp(language, "fr") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageFrench;
|
ret_language = kLanguageFrench;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "de") == 0)
|
else if (strcmp(language, "de") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageGerman;
|
ret_language = kLanguageGerman;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "it") == 0)
|
else if (strcmp(language, "it") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageItalian;
|
ret_language = kLanguageItalian;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "es") == 0)
|
else if (strcmp(language, "es") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageSpanish;
|
ret_language = kLanguageSpanish;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "ch") == 0)
|
else if (strcmp(language, "ch") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageChinese;
|
ret_language = kLanguageChinese;
|
||||||
}
|
}
|
||||||
else if (strcmp(language, "ru") == 0)
|
else if (strcmp(language, "ru") == 0)
|
||||||
{
|
{
|
||||||
ret_language = kLanguageRussian;
|
ret_language = kLanguageRussian;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(language);
|
free(language);
|
||||||
free(country);
|
free(country);
|
||||||
|
|
||||||
return ret_language;
|
return ret_language;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,121 +1,123 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __CC_EGLVIEW_QNX_H__
|
#ifndef __CC_EGLVIEW_QNX_H__
|
||||||
#define __CC_EGLVIEW_QNX_H__
|
#define __CC_EGLVIEW_QNX_H__
|
||||||
|
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <screen/screen.h>
|
#include <screen/screen.h>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class CCSet;
|
class CCSet;
|
||||||
class CCTouch;
|
class CCTouch;
|
||||||
class EGLTouchDelegate;
|
class EGLTouchDelegate;
|
||||||
|
|
||||||
class CC_DLL CCEGLView
|
class CC_DLL CCEGLView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCEGLView();
|
CCEGLView();
|
||||||
virtual ~CCEGLView();
|
virtual ~CCEGLView();
|
||||||
|
|
||||||
CCSize getSize();
|
CCSize getSize();
|
||||||
bool isOpenGLReady();
|
bool isOpenGLReady();
|
||||||
/**
|
/**
|
||||||
* the width and height is the real size of phone
|
* the width and height is the real size of phone
|
||||||
*/
|
*/
|
||||||
void setFrameWidthAndHeight(int width, int height);
|
void setFrameWidthAndHeight(int width, int height);
|
||||||
/**
|
/**
|
||||||
* create a drawing rect,
|
* create a drawing rect,
|
||||||
* the width and heiht is the resource size match best
|
* the width and heiht is the resource size match best
|
||||||
*/
|
*/
|
||||||
bool Create(int width, int height);
|
bool Create(int width, int height);
|
||||||
EGLTouchDelegate* getDelegate(void);
|
EGLTouchDelegate* getDelegate(void);
|
||||||
|
|
||||||
// keep compatible
|
// keep compatible
|
||||||
void release();
|
void release();
|
||||||
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
bool canSetContentScaleFactor();
|
bool canSetContentScaleFactor();
|
||||||
void setContentScaleFactor(float contentScaleFactor);
|
void setContentScaleFactor(float contentScaleFactor);
|
||||||
void setViewPortInPoints(float x, float y, float w, float h);
|
void setViewPortInPoints(float x, float y, float w, float h);
|
||||||
void setScissorInPoints(float x, float y, float w, float h);
|
void setScissorInPoints(float x, float y, float w, float h);
|
||||||
CCRect getViewPort();
|
CCRect getViewPort();
|
||||||
float getScreenScaleFactor();
|
float getScreenScaleFactor();
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
bool HandleEvents();
|
bool HandleEvents();
|
||||||
|
|
||||||
// static function
|
// static function
|
||||||
/**
|
/**
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
*/
|
*/
|
||||||
static CCEGLView& sharedOpenGLView();
|
static CCEGLView& sharedOpenGLView();
|
||||||
|
|
||||||
// pointer to OES methods from EGL
|
// pointer to OES methods from EGL
|
||||||
static PFNGLGENERATEMIPMAPOESPROC glGenerateMipmapOES;
|
static PFNGLGENERATEMIPMAPOESPROC glGenerateMipmapOES;
|
||||||
static PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOES;
|
static PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOES;
|
||||||
static PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
|
static PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
|
||||||
static PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
|
static PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
|
||||||
static PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOES;
|
static PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOES;
|
||||||
static PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOES;
|
static PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOES;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool initGL();
|
bool initGL();
|
||||||
void initEGLFunctions();
|
void initEGLFunctions();
|
||||||
bool isGLExtension(const char *searchName) const;
|
bool isGLExtension(const char *searchName) const;
|
||||||
bool initDriver();
|
bool initDriver();
|
||||||
void printEGLInfo(const EGLConfig &config) const;
|
void printEGLInfo(const EGLConfig &config) const;
|
||||||
EGLConfig chooseConfig(const EGLDisplay &eglDisplay, const char* str);
|
EGLConfig chooseConfig(const EGLDisplay &eglDisplay, const char* str);
|
||||||
int chooseFormat(const EGLDisplay &eglDisplay, const EGLConfig &config);
|
int chooseFormat(const EGLDisplay &eglDisplay, const EGLConfig &config);
|
||||||
bool createNativeWindow(const EGLConfig &config);
|
bool createNativeWindow(const EGLConfig &config);
|
||||||
void showKeyboard();
|
void showKeyboard();
|
||||||
void hideKeyboard();
|
void hideKeyboard();
|
||||||
|
|
||||||
CCSize m_sSizeInPixel;
|
CCSize m_sSizeInPixel;
|
||||||
CCSize m_sSizeInPoint;
|
CCSize m_sSizeInPoint;
|
||||||
CCRect m_rcViewPort;
|
CCRect m_rcViewPort;
|
||||||
bool m_bNotHVGA;
|
bool m_bNotHVGA;
|
||||||
bool m_isGLInitialized;
|
bool m_isGLInitialized;
|
||||||
|
|
||||||
EGLTouchDelegate *m_pDelegate;
|
EGLTouchDelegate *m_pDelegate;
|
||||||
float m_fScreenScaleFactor;
|
float m_fScreenScaleFactor;
|
||||||
|
|
||||||
static bool m_initializedFunctions;
|
bool m_isWindowActive;
|
||||||
static const GLubyte *m_extensions;
|
|
||||||
|
static bool m_initializedFunctions;
|
||||||
EGLDisplay m_eglDisplay;
|
static const GLubyte *m_extensions;
|
||||||
EGLContext m_eglContext;
|
|
||||||
EGLSurface m_eglSurface;
|
EGLDisplay m_eglDisplay;
|
||||||
screen_event_t m_screenEvent;
|
EGLContext m_eglContext;
|
||||||
screen_window_t m_screenWindow;
|
EGLSurface m_eglSurface;
|
||||||
screen_context_t m_screenContext;
|
screen_event_t m_screenEvent;
|
||||||
};
|
screen_window_t m_screenWindow;
|
||||||
|
screen_context_t m_screenContext;
|
||||||
} // end of namespace cocos2d
|
};
|
||||||
|
|
||||||
#endif // end of __CC_EGLVIEW_QNX_H__
|
} // end of namespace cocos2d
|
||||||
|
|
||||||
|
#endif // end of __CC_EGLVIEW_QNX_H__
|
||||||
|
|
|
@ -1,161 +1,161 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "CCCommon.h"
|
#include "CCCommon.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
#define MAX_PATH 256
|
#define MAX_PATH 256
|
||||||
|
|
||||||
// record the resource path
|
// record the resource path
|
||||||
static std::string s_strResourcePath = "";
|
static std::string s_strResourcePath = "";
|
||||||
static std::string s_pszZipFilePath = "";
|
static std::string s_pszZipFilePath = "";
|
||||||
|
|
||||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||||
{
|
{
|
||||||
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||||
CCAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
CCAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||||
|
|
||||||
if (!pszResourcePath)
|
if (!pszResourcePath)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s_strResourcePath = pszResourcePath;
|
s_strResourcePath = pszResourcePath;
|
||||||
|
|
||||||
// if the path is not ended with '/', append it
|
// if the path is not ended with '/', append it
|
||||||
if (s_strResourcePath.find("/") != (strlen(s_strResourcePath.c_str()) - 1))
|
if (s_strResourcePath.find("/") != (strlen(s_strResourcePath.c_str()) - 1))
|
||||||
{
|
{
|
||||||
s_strResourcePath += "/";
|
s_strResourcePath += "/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
{
|
{
|
||||||
// It works like this: if the relative path already includes the resource path
|
// It works like this: if the relative path already includes the resource path
|
||||||
// it will be returned as it is
|
// it will be returned as it is
|
||||||
const std::string relPath = pszRelativePath;
|
const std::string relPath = pszRelativePath;
|
||||||
if (relPath.find(s_strResourcePath) == std::string::npos)
|
if (relPath.find(s_strResourcePath) == std::string::npos)
|
||||||
{
|
{
|
||||||
CCString *pRet = new CCString();
|
CCString *pRet = new CCString();
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
pRet->m_sString = s_strResourcePath + pszRelativePath;
|
pRet->m_sString = s_strResourcePath + pszRelativePath;
|
||||||
return pRet->m_sString.c_str();
|
return pRet->m_sString.c_str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return pszRelativePath;
|
return pszRelativePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||||
{
|
{
|
||||||
std::string relativeFile = pszRelativeFile;
|
std::string relativeFile = pszRelativeFile;
|
||||||
CCString *pRet = new CCString();
|
CCString *pRet = new CCString();
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
||||||
pRet->m_sString += pszFilename;
|
pRet->m_sString += pszFilename;
|
||||||
return pRet->m_sString.c_str();
|
return pRet->m_sString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * buffer = NULL;
|
unsigned char * buffer = NULL;
|
||||||
|
|
||||||
std::string full_path = pszFileName;
|
std::string full_path = pszFileName;
|
||||||
|
|
||||||
// If it is not inside resource path
|
// If it is not inside resource path
|
||||||
if (full_path.find(s_strResourcePath) == std::string::npos)
|
if (full_path.find(s_strResourcePath) == std::string::npos)
|
||||||
{
|
{
|
||||||
full_path = s_strResourcePath + pszFileName;
|
full_path = s_strResourcePath + pszFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if specify the zip file,load from it first
|
// if specify the zip file,load from it first
|
||||||
if (s_pszZipFilePath[0] != 0)
|
if (s_pszZipFilePath[0] != 0)
|
||||||
{
|
{
|
||||||
buffer = getFileDataFromZip(s_pszZipFilePath.c_str(), full_path.c_str(), pSize);
|
buffer = getFileDataFromZip(s_pszZipFilePath.c_str(), full_path.c_str(), pSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if that failed then let's try and load the file ourselves
|
// if that failed then let's try and load the file ourselves
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
// read the file from hardware
|
// read the file from hardware
|
||||||
FILE *fp = fopen(full_path.c_str(), pszMode);
|
FILE *fp = fopen(full_path.c_str(), pszMode);
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
*pSize = ftell(fp);
|
*pSize = ftell(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
buffer = new unsigned char[*pSize];
|
buffer = new unsigned char[*pSize];
|
||||||
*pSize = fread(buffer, sizeof(unsigned char), *pSize, fp);
|
*pSize = fread(buffer, sizeof(unsigned char), *pSize, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we couldn't find the file
|
// we couldn't find the file
|
||||||
if (!buffer && getIsPopupNotify())
|
if (!buffer && getIsPopupNotify())
|
||||||
{
|
{
|
||||||
std::string title = "Notification";
|
std::string title = "Notification";
|
||||||
std::string msg = "Get data from file(";
|
std::string msg = "Get data from file(";
|
||||||
msg.append(full_path);
|
msg.append(full_path);
|
||||||
if (s_pszZipFilePath[0] != 0)
|
if (s_pszZipFilePath[0] != 0)
|
||||||
{
|
{
|
||||||
msg.append(") in zip archive(").append(s_pszZipFilePath);
|
msg.append(") in zip archive(").append(s_pszZipFilePath);
|
||||||
}
|
}
|
||||||
msg.append(") failed!");
|
msg.append(") failed!");
|
||||||
|
|
||||||
CCMessageBox(msg.c_str(), title.c_str());
|
CCMessageBox(msg.c_str(), title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||||
{
|
{
|
||||||
s_pszZipFilePath = pszZipFileName;
|
s_pszZipFilePath = pszZipFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||||
{
|
{
|
||||||
CCAssert(0, "Have not implemented!");
|
CCAssert(0, "Have not implemented!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CCFileUtils::getWriteablePath()
|
std::string CCFileUtils::getWriteablePath()
|
||||||
{
|
{
|
||||||
// Let's write it in the current working directory's data folder
|
// Let's write it in the current working directory's data folder
|
||||||
char cwd[FILENAME_MAX];
|
char cwd[FILENAME_MAX];
|
||||||
|
|
||||||
getcwd(cwd, FILENAME_MAX - 1);
|
getcwd(cwd, FILENAME_MAX - 1);
|
||||||
cwd[FILENAME_MAX] = '\0';
|
cwd[FILENAME_MAX] = '\0';
|
||||||
|
|
||||||
std::string path = cwd;
|
std::string path = cwd;
|
||||||
path += "/data/";
|
path += "/data/";
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
Loading…
Reference in New Issue