mirror of https://github.com/axmolengine/axmol.git
Merge pull request #589 from dumganhar/master_base
fix some bugs on bada
This commit is contained in:
commit
d07f9a792d
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCAudioOut.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -104,7 +128,7 @@ int CCAudioOut::DecodeOgg(const char *infile)
|
|||
if(ov_seekable(&vf)) {
|
||||
seekable = 1;
|
||||
length = ov_pcm_total(&vf, 0);
|
||||
size = bits/8 * ov_info(&vf, 0)->channels;
|
||||
size = 16/8 * ov_info(&vf, 0)->channels;
|
||||
}
|
||||
//AppLog("enter");
|
||||
if (ov_info(&vf,0)->channels == 2)
|
||||
|
@ -120,13 +144,13 @@ int CCAudioOut::DecodeOgg(const char *infile)
|
|||
__sampleBitdepth = AUDIO_TYPE_PCM_S16_LE;
|
||||
|
||||
//AppLog("enter");
|
||||
while((ret = ov_read(&vf, buf, buflen, endian, bits/8, sign, &bs)) != 0) {
|
||||
while((ret = ov_read(&vf, buf, buflen, 0, 16/8, 1, &bs)) != 0) {
|
||||
if(bs != 0) {
|
||||
//AppLog("Only one logical bitstream currently supported\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(ret < 0 && !quiet) {
|
||||
if(ret < 0) {
|
||||
//AppLog("Warning: hole in data\n");
|
||||
continue;
|
||||
}
|
||||
|
@ -143,7 +167,7 @@ int CCAudioOut::DecodeOgg(const char *infile)
|
|||
memcpy(__pAllPcmBuffer+written, buf, ret);
|
||||
|
||||
written += ret;
|
||||
if(!quiet && seekable) {
|
||||
if(seekable) {
|
||||
done += ret/size;
|
||||
if((double)done/(double)length * 200. > (double)percent) {
|
||||
percent = (double)done/(double)length *200;
|
||||
|
@ -178,17 +202,14 @@ CCAudioOut::CCAudioOut()
|
|||
__iAllPcmBufferSize = 0;
|
||||
__iAllPcmPos = 0;
|
||||
__pAudioOut = null;
|
||||
quiet = 0;
|
||||
bits = 16;
|
||||
endian = 0;
|
||||
raw = 0;
|
||||
sign = 1;
|
||||
__iFileType = 0;
|
||||
__pFile = null;
|
||||
__bShortPcmBuffer = false;
|
||||
__bBufferConstruted = false;
|
||||
__checkInitFiniPair = false;
|
||||
__iUsedBufferCount = 0;
|
||||
__bLoop = false;
|
||||
__bPause = false;
|
||||
}
|
||||
|
||||
CCAudioOut::~CCAudioOut()
|
||||
|
@ -516,20 +537,18 @@ void CCAudioOut::ReFeedBuffer(void)
|
|||
}
|
||||
}
|
||||
|
||||
result CCAudioOut::Play(void)
|
||||
result CCAudioOut::Play(bool bLoop/* = false*/)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
|
||||
result ret = E_FAILURE;
|
||||
AudioOutState state = __pAudioOut->GetState();
|
||||
|
||||
if(state == AUDIOOUT_STATE_PREPARED || state == AUDIOOUT_STATE_STOPPED)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
__bLoop = bLoop;
|
||||
ret = __pAudioOut->Start();
|
||||
if (IsFailed(ret))
|
||||
{
|
||||
//AppLog("[Error] m_AudioOut.Start failed : %d\n", ret);
|
||||
AppLog("[Error] m_AudioOut.Start failed : %d\n", ret);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -537,39 +556,55 @@ result CCAudioOut::Play(void)
|
|||
|
||||
result CCAudioOut::Stop(void)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
AudioOutState state = __pAudioOut->GetState();
|
||||
result r = E_SUCCESS;
|
||||
|
||||
__bPause = false;
|
||||
if(state == AUDIOOUT_STATE_PLAYING)
|
||||
{
|
||||
r = __pAudioOut->Reset();
|
||||
if(IsFailed(r))
|
||||
{
|
||||
AppLog("[Error] AudioOut Reset is failed");
|
||||
}
|
||||
ReWriteBuffer();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
result CCAudioOut::Pause(void)
|
||||
{
|
||||
result ret = E_FAILURE;
|
||||
|
||||
if( __pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING )
|
||||
{
|
||||
__bPause = true;
|
||||
ret = __pAudioOut->Stop();
|
||||
if (IsFailed(ret))
|
||||
{
|
||||
//AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
|
||||
AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
result CCAudioOut::Reset(void)
|
||||
result CCAudioOut::Resume(void)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
AudioOutState state = __pAudioOut->GetState();
|
||||
result r = E_SUCCESS;
|
||||
result ret = E_FAILURE;
|
||||
|
||||
if(state == AUDIOOUT_STATE_PLAYING)
|
||||
if(__bPause && __pAudioOut->GetState() == AUDIOOUT_STATE_STOPPED )
|
||||
{
|
||||
//AppLog("reset ...");
|
||||
r = __pAudioOut->Reset();
|
||||
if(IsFailed(r))
|
||||
__bPause = false;
|
||||
ret = __pAudioOut->Start();
|
||||
if (IsFailed(ret))
|
||||
{
|
||||
//AppLog("[Error] AudioOut Reset is failed");
|
||||
AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
|
||||
}
|
||||
ReWriteBuffer();
|
||||
}
|
||||
|
||||
return r;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
|
||||
|
@ -579,13 +614,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
|
|||
__iUsedBufferCount--;
|
||||
if (__iUsedBufferCount <= 0)
|
||||
{
|
||||
Reset();
|
||||
//AppLog("Reset...");
|
||||
Stop();
|
||||
if (__bLoop)
|
||||
{
|
||||
Play(__bLoop);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
// //AppLog("thread name is %S", Thread::GetCurrentThread()->GetName().GetPointer());
|
||||
//AppLog("__buffReadCnt = %d", __buffReadCnt);
|
||||
__byteBuffer[__buffReadCnt++].Clear ();
|
||||
|
@ -607,11 +645,14 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
|
|||
__finishChecker--;
|
||||
if(__finishChecker == 0)
|
||||
{
|
||||
//AppLog("Reset...");
|
||||
Reset();
|
||||
Stop();
|
||||
__bufWrittenCnt = PRE_BUFFERING_NUM;
|
||||
__buffReadCnt = 0;
|
||||
__buffWriteCnt = 0;
|
||||
if (__bLoop)
|
||||
{
|
||||
Play(__bLoop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,19 +661,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
|
|||
|
||||
void CCAudioOut::OnAudioOutInterrupted(Osp::Media::AudioOut& src)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
Reset();
|
||||
Pause();
|
||||
}
|
||||
|
||||
void CCAudioOut::OnAudioOutReleased(Osp::Media::AudioOut& src)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
Resume();
|
||||
}
|
||||
|
||||
void CCAudioOut::Finalize(void)
|
||||
{
|
||||
//AppLog("Enter");
|
||||
|
||||
if(__checkInitFiniPair)
|
||||
{
|
||||
|
||||
|
@ -650,7 +688,7 @@ void CCAudioOut::Finalize(void)
|
|||
r = __pAudioOut->Reset();
|
||||
if(IsFailed(r))
|
||||
{
|
||||
//AppLog("[Error] AudioOut Reset is failed");
|
||||
AppLog("[Error] AudioOut Reset is failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -662,7 +700,7 @@ void CCAudioOut::Finalize(void)
|
|||
r = __pAudioOut->Unprepare();
|
||||
if(IsFailed(r))
|
||||
{
|
||||
//AppLog("[Error] AudioOut UnPrepare is failed");
|
||||
AppLog("[Error] AudioOut UnPrepare is failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -675,7 +713,7 @@ void CCAudioOut::Finalize(void)
|
|||
|
||||
__checkInitFiniPair = false;
|
||||
}else{
|
||||
//AppLog("[WANRNING] This application state is not proper");
|
||||
AppLog("[WANRNING] This application state is not proper");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCAUDIOOUT_H__
|
||||
#define __CCAUDIOOUT_H__
|
||||
|
||||
|
@ -26,9 +50,11 @@ public:
|
|||
void ReFeedBuffer(void);
|
||||
void Finalize(void);
|
||||
|
||||
result Play(void);
|
||||
result Play(bool bLoop = false);
|
||||
result Stop(void);
|
||||
result Reset(void);
|
||||
result Pause(void);
|
||||
result Resume(void);
|
||||
|
||||
void SetVolume(int volume);
|
||||
int GetVolume(void) const;
|
||||
Osp::Media::AudioOutState GetState(void) const;
|
||||
|
@ -54,11 +80,8 @@ private:
|
|||
char* __pAllPcmBuffer;
|
||||
int __iAllPcmBufferSize;
|
||||
int __iAllPcmPos;
|
||||
int quiet;
|
||||
int bits;
|
||||
int endian;
|
||||
int raw;
|
||||
int sign;
|
||||
bool __bLoop;
|
||||
bool __bPause;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "CCAudioOut.h"
|
||||
#include <FBase.h>
|
||||
|
@ -32,6 +56,7 @@ static EffectList s_List;
|
|||
static float s_fBackgroundMusicVolume = 1.0f;
|
||||
static float s_fEffectsVolume = 1.0f;
|
||||
static bool s_bWillPlayBackgroundMusic = false;
|
||||
static bool s_bBackgroundMusicPaused = false;
|
||||
static string s_strResourcePath = "/Res/";
|
||||
|
||||
static unsigned int _Hash(const char *key)
|
||||
|
@ -53,7 +78,9 @@ static string fullPathFromRelativePath(const char *pszRelativePath)
|
|||
string strRet="";
|
||||
int len = strlen(pszRelativePath);
|
||||
if (pszRelativePath == NULL || len <= 0)
|
||||
return NULL;
|
||||
{
|
||||
return strRet;
|
||||
}
|
||||
|
||||
if (len > 1 && pszRelativePath[0] == '/')
|
||||
{
|
||||
|
@ -87,7 +114,7 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerOpened( result r )
|
||||
{
|
||||
//AppLog("OnPlayerOpened");
|
||||
AppLog("OnPlayerOpened result = %d", r);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +123,7 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerEndOfClip(void)
|
||||
{
|
||||
//AppLog("OnPlayerEndOfClip");
|
||||
AppLog("OnPlayerEndOfClip");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +136,7 @@ public:
|
|||
|
||||
virtual void OnPlayerSeekCompleted( result r )
|
||||
{
|
||||
//AppLog("OnPlayerSeekCompleted");
|
||||
AppLog("OnPlayerSeekCompleted result = %d", r);
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,7 +148,7 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerBuffering(int percent)
|
||||
{
|
||||
//AppLog("OnPlayerBuffering");
|
||||
AppLog("OnPlayerBuffering percent = %d%", percent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,7 +162,7 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerErrorOccurred( PlayerErrorReason r )
|
||||
{
|
||||
//AppLog("OnPlayerErrorOccurred");
|
||||
AppLog("OnPlayerErrorOccurred PlayerErrorReason = %d", r);
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,8 +172,8 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerInterrupted(void)
|
||||
{
|
||||
AppLog("OnPlayerInterrupted");
|
||||
//Insert your code here
|
||||
//AppLog("OnPlayerInterrupted");
|
||||
if (s_pBackPlayer->GetState() == PLAYER_STATE_PLAYING)
|
||||
s_pBackPlayer->Pause();
|
||||
}
|
||||
|
@ -157,8 +184,8 @@ public:
|
|||
*/
|
||||
virtual void OnPlayerReleased(void)
|
||||
{
|
||||
AppLog("OnPlayerReleased");
|
||||
//Insert your code here
|
||||
//AppLog("OnPlayerReleased");
|
||||
if (s_pBackPlayer->GetState() != PLAYER_STATE_PLAYING)
|
||||
s_pBackPlayer->Play();
|
||||
}
|
||||
|
@ -176,17 +203,15 @@ static void closeMediaPlayer(Player*& pPlayer)
|
|||
{
|
||||
pPlayer->Stop();
|
||||
pPlayer->Close();
|
||||
//AppLog("audio player closed");
|
||||
}
|
||||
else if(nowState == PLAYER_STATE_OPENED || nowState == PLAYER_STATE_ENDOFCLIP || nowState == PLAYER_STATE_STOPPED )
|
||||
{
|
||||
pPlayer->Close();
|
||||
//AppLog("audio player closed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoop)
|
||||
static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath)
|
||||
{
|
||||
bool bRet = false;
|
||||
result r = E_FAILURE;
|
||||
|
@ -201,7 +226,7 @@ static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoo
|
|||
r = pPlayer->Construct(s_playerListener, null);
|
||||
if (IsFailed(r))
|
||||
{
|
||||
//AppLog("player construct fails, pszFilePath = %s", pszFilePath);
|
||||
AppLog("player construct fails, pszFilePath = %s", pszFilePath);
|
||||
delete pPlayer;
|
||||
pPlayer = NULL;
|
||||
break;
|
||||
|
@ -213,19 +238,20 @@ static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoo
|
|||
r = pPlayer->OpenFile(strFilePath.c_str(), false);
|
||||
if (IsFailed(r))
|
||||
{
|
||||
//AppLog("Open (%s) fails\n", strFilePath.c_str());
|
||||
AppLog("Open (%s) fails\n", strFilePath.c_str());
|
||||
delete pPlayer;
|
||||
pPlayer = NULL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlayer->SetLooping(bLoop);
|
||||
bRet = true;
|
||||
}
|
||||
}
|
||||
while (0);
|
||||
|
||||
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(s_fBackgroundMusicVolume);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
@ -236,11 +262,9 @@ SimpleAudioEngine::SimpleAudioEngine()
|
|||
|
||||
SimpleAudioEngine::~SimpleAudioEngine()
|
||||
{
|
||||
//AppLog("destroy SimpleAudioEngine");
|
||||
|
||||
for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it)
|
||||
{
|
||||
it->second->Reset();
|
||||
it->second->Stop();
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
|
@ -277,25 +301,25 @@ void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
|||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
|
||||
openMediaPlayer(s_pBackPlayer, pszFilePath);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
result r = E_FAILURE;
|
||||
bool bRet = false;
|
||||
bRet = openMediaPlayer(s_pBackPlayer, pszFilePath, bLoop);
|
||||
|
||||
setBackgroundMusicVolume(s_fBackgroundMusicVolume);
|
||||
bRet = openMediaPlayer(s_pBackPlayer, pszFilePath);
|
||||
|
||||
if (bRet)
|
||||
{
|
||||
s_pBackPlayer->SetLooping(bLoop);
|
||||
r = s_pBackPlayer->Play();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
|
||||
{
|
||||
s_bBackgroundMusicPaused = false;
|
||||
if (s_pBackPlayer && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState())
|
||||
{
|
||||
s_pBackPlayer->Stop();
|
||||
|
@ -306,26 +330,32 @@ void SimpleAudioEngine::pauseBackgroundMusic()
|
|||
{
|
||||
if (s_pBackPlayer && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState())
|
||||
{
|
||||
s_bBackgroundMusicPaused = true;
|
||||
s_pBackPlayer->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeBackgroundMusic()
|
||||
{
|
||||
if (s_pBackPlayer && PLAYER_STATE_PLAYING != s_pBackPlayer->GetState())
|
||||
if (s_pBackPlayer && s_bBackgroundMusicPaused && PLAYER_STATE_PLAYING != s_pBackPlayer->GetState())
|
||||
{
|
||||
s_bBackgroundMusicPaused = false;
|
||||
s_pBackPlayer->Play();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::rewindBackgroundMusic()
|
||||
{
|
||||
stopBackgroundMusic();
|
||||
if (s_pBackPlayer)
|
||||
{
|
||||
s_pBackPlayer->SeekTo(0);
|
||||
if (PLAYER_STATE_PLAYING != s_pBackPlayer->GetState())
|
||||
{
|
||||
s_pBackPlayer->Play();
|
||||
result r = s_pBackPlayer->Play();
|
||||
if (IsFailed(r))
|
||||
{
|
||||
AppLog("ERROR: %s", GetErrorMessage(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -372,11 +402,9 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
|
|||
s_pBackPlayer->SetVolume((int) (volume * 99));
|
||||
if (volume > 0.0f && s_pBackPlayer->GetVolume() == 0)
|
||||
{
|
||||
//AppLog("volume is lowest");
|
||||
s_pBackPlayer->SetVolume(1);
|
||||
}
|
||||
}
|
||||
//AppLog("volume = %f", volume);
|
||||
s_fBackgroundMusicVolume = volume;
|
||||
}
|
||||
|
||||
|
@ -402,12 +430,10 @@ void SimpleAudioEngine::setEffectsVolume(float volume)
|
|||
// for sound effects
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/)
|
||||
{
|
||||
long long curTick, oldTick;
|
||||
SystemTime::GetTicks(oldTick);
|
||||
result r = E_FAILURE;
|
||||
string strFilePath = fullPathFromRelativePath(pszFilePath);
|
||||
unsigned int nRet = _Hash(strFilePath.c_str());
|
||||
//AppLog("play effect (%s)", pszFilePath);
|
||||
|
||||
preloadEffect(pszFilePath);
|
||||
|
||||
EffectList::iterator p = s_List.find(nRet);
|
||||
|
@ -415,34 +441,28 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/*
|
|||
{
|
||||
p->second->SetVolume((int) (s_fEffectsVolume * 99));
|
||||
int volume = p->second->GetVolume();
|
||||
//AppLog("volume = %d, s_fEffectsVolume = %f", volume, s_fEffectsVolume);
|
||||
|
||||
if (s_fEffectsVolume > 0.0f && volume == 0)
|
||||
{
|
||||
//AppLog("effect volume is lowest");
|
||||
p->second->SetVolume(1);
|
||||
}
|
||||
|
||||
if (AUDIOOUT_STATE_PLAYING == p->second->GetState())
|
||||
{
|
||||
return nRet; // reset waste a lot of time, so just return.
|
||||
//AppLog("Reset effect...");
|
||||
r = p->second->Reset();
|
||||
return nRet; // Stop waste a lot of time, so just return.
|
||||
//r = p->second->Stop();
|
||||
}
|
||||
|
||||
//AppLog("play...");
|
||||
|
||||
if (s_fEffectsVolume > 0.0f)
|
||||
{
|
||||
r = p->second->Play();
|
||||
r = p->second->Play(bLoop);
|
||||
}
|
||||
|
||||
if (IsFailed(r))
|
||||
{
|
||||
//AppLog("play effect fails, error code = %d", r);
|
||||
AppLog("play effect fails, error code = %d", r);
|
||||
}
|
||||
}
|
||||
SystemTime::GetTicks(curTick);
|
||||
//AppLog("play effect waste %ld ms...", (long)(curTick-oldTick));
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
@ -451,7 +471,41 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
|||
CCAudioOut*& pPlayer = s_List[nSoundId];
|
||||
if (pPlayer != NULL)
|
||||
{
|
||||
pPlayer->Reset();
|
||||
pPlayer->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
|
||||
{
|
||||
CCAudioOut*& pPlayer = s_List[nSoundId];
|
||||
if (pPlayer != NULL)
|
||||
{
|
||||
pPlayer->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseAllEffects()
|
||||
{
|
||||
for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it)
|
||||
{
|
||||
it->second->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
|
||||
{
|
||||
CCAudioOut*& pPlayer = s_List[nSoundId];
|
||||
if (pPlayer != NULL)
|
||||
{
|
||||
pPlayer->Resume();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeAllEffects()
|
||||
{
|
||||
for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it)
|
||||
{
|
||||
it->second->Resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +513,7 @@ void SimpleAudioEngine::stopAllEffects()
|
|||
{
|
||||
for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it)
|
||||
{
|
||||
it->second->Reset();
|
||||
it->second->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,23 +532,19 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
|||
BREAK_IF(s_List.end() != s_List.find(nRet));
|
||||
|
||||
//AppLog("not find effect, create it...");
|
||||
// bada only support 10 player instance, we use one for background music, other for effect music.
|
||||
if (s_List.size() >= 64)
|
||||
{
|
||||
// get the first effect, and remove it form list
|
||||
//AppLog("effect preload more than 9, delete the first effect");
|
||||
//AppLog("effect preload more than 64, delete the first effect");
|
||||
pEffectPlayer = s_List.begin()->second;
|
||||
// closeMediaPlayer(pEffectPlayer);
|
||||
pEffectPlayer->Finalize();
|
||||
s_List.erase(s_List.begin()->first);
|
||||
}
|
||||
if (pEffectPlayer == NULL)
|
||||
pEffectPlayer = new CCAudioOut;
|
||||
pEffectPlayer->Initialize(strFilePath.c_str());
|
||||
// if (openMediaPlayer(pEffectPlayer, pszFilePath, false))
|
||||
{
|
||||
s_List.insert(Effect(nRet, pEffectPlayer));
|
||||
}
|
||||
|
||||
s_List.insert(Effect(nRet, pEffectPlayer));
|
||||
|
||||
} while (0);
|
||||
}
|
||||
|
@ -504,8 +554,7 @@ void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
|
|||
string strFilePath = fullPathFromRelativePath(pszFilePath);
|
||||
unsigned int nSoundId = _Hash(strFilePath.c_str());
|
||||
CCAudioOut*& pPlayer = s_List[nSoundId];
|
||||
pPlayer->Reset();
|
||||
//closeMediaPlayer(pPlayer);
|
||||
pPlayer->Stop();
|
||||
}
|
||||
|
||||
} // end of namespace CocosDenshion
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
<name>HelloWorld</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>Box2D</project>
|
||||
<project>chipmunk</project>
|
||||
<project>cocos2dx</project>
|
||||
<project>CocosDenshion</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FOsp.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsOpengl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsEgl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/pthread.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/StubDynCast.so""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.osp.gnu.cpp.linker.input.1537454940" superClass="cdt.managedbuild.tool.osp.gnu.cpp.linker.input">
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
<name>HelloWorld</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>Box2D</project>
|
||||
<project>chipmunk</project>
|
||||
<project>cocos2dx</project>
|
||||
<project>CocosDenshion</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
@ -95,7 +99,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace cocos2d{
|
|||
bool CCMenu::init()
|
||||
{
|
||||
va_list args;
|
||||
return initWithItems(0, args);
|
||||
return initWithItems(NULL, args);
|
||||
}
|
||||
|
||||
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
|
||||
|
|
|
@ -272,7 +272,7 @@ void CCLog(const char * pszFormat, ...)
|
|||
va_start(args, pszFormat);
|
||||
vsnprintf(buf, MAX_LEN, pszFormat, args);
|
||||
va_end(args);
|
||||
AppLog(buf);
|
||||
__App_info(__PRETTY_FUNCTION__ , __LINE__, buf);
|
||||
}
|
||||
|
||||
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN;
|
||||
|
||||
/// The max length of CCLog message.
|
||||
static const int kMaxLogLen = 255;
|
||||
static const int kMaxLogLen = 16*1024;
|
||||
|
||||
/**
|
||||
@brief Output Debug message.
|
||||
|
|
|
@ -154,7 +154,7 @@ public: inline void set##funName(const varType& var){ varName = var; }
|
|||
#endif // COCOS2D_DEBUG
|
||||
|
||||
// shared library declartor
|
||||
#define CC_DLL
|
||||
#define CC_DLL
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
||||
// assertion
|
||||
|
@ -162,6 +162,7 @@ public: inline void set##funName(const varType& var){ varName = var; }
|
|||
#define CC_ASSERT(cond) assert(cond)
|
||||
#else
|
||||
// bada platform
|
||||
|
||||
#include <FBaseConfig.h>
|
||||
#include <FBaseSys.h>
|
||||
|
||||
|
@ -171,9 +172,9 @@ public: inline void set##funName(const varType& var){ varName = var; }
|
|||
#include "CCPlatformFunc_bada.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define CC_ASSERT(cond) if (!(cond)) badaAssert(__PRETTY_FUNCTION__ , __LINE__ , #cond)
|
||||
#define CC_ASSERT(cond) (void)( (!!(cond)) || (badaAssert(__PRETTY_FUNCTION__ , __LINE__ , #cond),0) )
|
||||
#else
|
||||
#define CC_ASSERT(cond)
|
||||
#define CC_ASSERT(cond) void(0)
|
||||
#endif /* _DEBUG */
|
||||
#endif
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@ int CC_DLL gettimeofday(struct timeval * val, struct timezone *)
|
|||
}
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
|
||||
|
||||
using namespace Osp::System;
|
||||
|
||||
int CC_DLL gettimeofday(struct timeval * val, struct timezone *)
|
||||
{
|
||||
if (val)
|
||||
|
|
|
@ -129,7 +129,6 @@ int CC_DLL gettimeofday(struct timeval *, struct timezone *);
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
|
||||
|
||||
#include <FSysSystemTime.h>
|
||||
using namespace Osp::System;
|
||||
|
||||
struct timeval
|
||||
{
|
||||
|
@ -143,6 +142,7 @@ struct timezone
|
|||
int tz_dsttime;
|
||||
};
|
||||
|
||||
|
||||
int CC_DLL gettimeofday(struct timeval *, struct timezone *);
|
||||
|
||||
#ifndef MIN
|
||||
|
|
|
@ -31,28 +31,24 @@ using namespace Osp::Uix;
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
|
||||
|
||||
CCAccelerometer::CCAccelerometer() :
|
||||
m_pAccelDelegate(NULL)
|
||||
CCAccelerometer::CCAccelerometer()
|
||||
: m_pAccelDelegate(NULL)
|
||||
, m_pSensor(NULL)
|
||||
, m_bEnabled(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCAccelerometer::~CCAccelerometer()
|
||||
{
|
||||
m_spCCAccelerometer = NULL;
|
||||
CC_SAFE_DELETE(m_pSensor);
|
||||
}
|
||||
|
||||
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
||||
{
|
||||
if (m_spCCAccelerometer == NULL)
|
||||
{
|
||||
m_spCCAccelerometer = new CCAccelerometer();
|
||||
}
|
||||
return m_spCCAccelerometer;
|
||||
static CCAccelerometer s_CCAccelerometer;
|
||||
return &s_CCAccelerometer;
|
||||
}
|
||||
|
||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
||||
|
@ -106,39 +102,52 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa
|
|||
void CCAccelerometer::setEnable(bool bEnable)
|
||||
{
|
||||
result r = E_INVALID_STATE;
|
||||
static long interval = 50;
|
||||
if (m_pSensor == NULL)
|
||||
if (m_bEnabled == bEnable)
|
||||
{
|
||||
bool available = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_bEnabled = bEnable;
|
||||
|
||||
if (m_bEnabled)
|
||||
{
|
||||
bool available = false;
|
||||
long interval = 50;
|
||||
|
||||
CC_SAFE_DELETE(m_pSensor);
|
||||
m_pSensor = new SensorManager();
|
||||
m_pSensor->Construct();
|
||||
|
||||
available = m_pSensor->IsAvailable(SENSOR_TYPE_ACCELERATION);
|
||||
if (available)
|
||||
{
|
||||
long intervalTemp = 0;
|
||||
long intervalTemp = 0;
|
||||
m_pSensor->GetMaxInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
|
||||
if (interval > intervalTemp)
|
||||
{
|
||||
interval = intervalTemp;
|
||||
}
|
||||
m_pSensor->GetMinInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
|
||||
if (interval < intervalTemp)
|
||||
{
|
||||
interval = intervalTemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_pSensor;
|
||||
m_pSensor = NULL;
|
||||
}
|
||||
}
|
||||
if (m_pSensor != NULL)
|
||||
{
|
||||
if (bEnable)
|
||||
{
|
||||
}
|
||||
r = m_pSensor->AddSensorListener(*this, SENSOR_TYPE_ACCELERATION, interval, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("Accelerometer Sensor unavailable!");
|
||||
delete m_pSensor;
|
||||
m_pSensor = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pSensor != NULL)
|
||||
{
|
||||
r = m_pSensor->RemoveSensorListener(*this);
|
||||
delete m_pSensor;
|
||||
m_pSensor = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ public:
|
|||
private:
|
||||
void setEnable(bool bEnable);
|
||||
|
||||
static CCAccelerometer* m_spCCAccelerometer;
|
||||
CCAccelerometerDelegate* m_pAccelDelegate;
|
||||
Osp::Uix::SensorManager* m_pSensor;
|
||||
bool m_bEnabled;
|
||||
};
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCApplication_bada.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
|
@ -15,9 +39,7 @@ static long long s_nAnimationInterval = 1000/60;
|
|||
CCApplication::CCApplication() :
|
||||
m_pTimer(null)
|
||||
{
|
||||
CCLog("CCApplication constructor...");
|
||||
s_pApplication = this;
|
||||
|
||||
}
|
||||
|
||||
CCApplication::~CCApplication()
|
||||
|
|
|
@ -347,7 +347,7 @@ void CCEGLView::resize(int width, int height)
|
|||
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
|
||||
m_rcViewPort.size.width = viewPortW;
|
||||
m_rcViewPort.size.height = viewPortH;
|
||||
//AppLog("m_rcViewPort.origin.x = %f, y = %f, width = %f, height = %f", \
|
||||
//CCLOG("m_rcViewPort.origin.x = %f, y = %f, width = %f, height = %f", \
|
||||
m_rcViewPort.origin.x, m_rcViewPort.origin.y, m_rcViewPort.size.width, m_rcViewPort.size.height);
|
||||
}
|
||||
|
||||
|
@ -381,7 +381,7 @@ result CCEGLView::OnInitializing(void)
|
|||
// calculate the factor and the rect of viewport
|
||||
m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
|
||||
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
|
||||
//AppLog("rc.width = %d, rc.height = %d, m_fScreenScaleFactor = %f", rc.width, rc.height, m_fScreenScaleFactor);
|
||||
//CCLOG("rc.width = %d, rc.height = %d, m_fScreenScaleFactor = %f", rc.width, rc.height, m_fScreenScaleFactor);
|
||||
resize(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
||||
|
||||
return r;
|
||||
|
@ -398,7 +398,7 @@ result CCEGLView::OnTerminating(void)
|
|||
|
||||
//void CCEGLView::onPenDown(int nIndex, float x, float y)
|
||||
//{
|
||||
// AppLog("onPenDown nIndex = %d,x = %f, y=%f", nIndex, x, y);
|
||||
// CCLOG("onPenDown nIndex = %d,x = %f, y=%f", nIndex, x, y);
|
||||
// if (m_pDelegate && nIndex < MAX_TOUCHES)
|
||||
// {
|
||||
// CCTouch* pTouch = s_pTouches[nIndex];
|
||||
|
@ -433,7 +433,7 @@ void CCEGLView::onTouchesBegin(int id[], float x[], float y[], int pointerNumber
|
|||
}
|
||||
else
|
||||
{
|
||||
AppLog("Beginnig touches with id: %d error", id[i]);
|
||||
CCLOG("Beginnig touches with id: %d error", id[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ void CCEGLView::onTouchesMove(int id[], float x[], float y[], int pointerNumber)
|
|||
result r = E_SUCCESS;
|
||||
CCSet set;
|
||||
for(int i = 0 ; i < pointerNumber ; i++ ) {
|
||||
AppLog("Moving touches with id: %d, x=%f, y=%f", id[i], x[i], y[i]);
|
||||
CCLOG("Moving touches with id: %d, x=%f, y=%f", id[i], x[i], y[i]);
|
||||
CCTouch *pTouch = NULL;
|
||||
r = s_mapTouches.GetValue(id[i], pTouch);
|
||||
|
||||
|
@ -456,7 +456,7 @@ void CCEGLView::onTouchesMove(int id[], float x[], float y[], int pointerNumber)
|
|||
else
|
||||
{
|
||||
// It is error, should return.
|
||||
AppLog("Moving touches with id: %d error", id[i]);
|
||||
CCLOG("Moving touches with id: %d error", id[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ void CCEGLView::onTouchesEnd(int id[], float x[], float y[], int pointerNumber)
|
|||
set.addObject(pTouch);
|
||||
s_mapTouches.Remove(id[i]);
|
||||
pTouch->release();
|
||||
AppLog("Ending touches with id: %d, x=%f, y=%f, retain count = %d", id[i], x[i], y[i], pTouch->retainCount());
|
||||
CCLOG("Ending touches with id: %d, x=%f, y=%f, retain count = %d", id[i], x[i], y[i], pTouch->retainCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,7 +556,7 @@ void CCEGLView::OnTouchPressed(const Control& source,
|
|||
int id = (int)touchInfo.GetPointId();
|
||||
float x = (float)touchInfo.GetCurrentPosition().x;
|
||||
float y = (float)touchInfo.GetCurrentPosition().y;
|
||||
AppLog("OnTouchPressed id = %d,x = %f,y = %f, count = %d", id, x, y, s_mapTouches.GetCount());
|
||||
CCLOG("OnTouchPressed id = %d,x = %f,y = %f, count = %d", id, x, y, s_mapTouches.GetCount());
|
||||
if (!m_bNotHVGA)
|
||||
{
|
||||
x = x * 2 / 3;
|
||||
|
@ -586,7 +586,7 @@ void CCEGLView::OnTouchReleased(const Control& source,
|
|||
}
|
||||
|
||||
onTouchesEnd(&id, &x, &y, 1);
|
||||
AppLog("OnTouchReleased id = %d,x = %f,y = %f", id, x, y);
|
||||
CCLOG("OnTouchReleased id = %d,x = %f,y = %f", id, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ void CCFileUtils::setResourcePath(const char* pszResourcePath)
|
|||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
int len = strlen(pszRelativePath);
|
||||
if (pszRelativePath == NULL || len <= 0)
|
||||
int len = 0;
|
||||
if (pszRelativePath == NULL || (len = strlen(pszRelativePath)) <= 0)
|
||||
return NULL;
|
||||
CCString * pRet = new CCString();
|
||||
pRet->autorelease();
|
||||
|
@ -69,31 +69,52 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
|
|||
|
||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||
{
|
||||
unsigned char * pBuffer = NULL;
|
||||
CC_ASSERT(pszFileName != NULL && pszMode != NULL);
|
||||
unsigned char * pData = 0;
|
||||
int len = 0;
|
||||
string fullPath;
|
||||
|
||||
do
|
||||
{
|
||||
// read the file from hardware
|
||||
FILE *fp = fopen(pszFileName, pszMode);
|
||||
CC_BREAK_IF(!fp);
|
||||
len = strlen(pszFileName);
|
||||
|
||||
fseek(fp,0,SEEK_END);
|
||||
*pSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pBuffer = new unsigned char[*pSize];
|
||||
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||
fclose(fp);
|
||||
} while (0);
|
||||
if (len > 1 && pszFileName[0] == '/')
|
||||
{
|
||||
fullPath = pszFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
fullPath = s_strResourcePath;
|
||||
fullPath += pszFileName;
|
||||
}
|
||||
|
||||
if (! pBuffer && getIsPopupNotify())
|
||||
{
|
||||
std::string title = "Notification";
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(pszFileName).append(") failed!");
|
||||
do
|
||||
{
|
||||
// read rrom other path than user set it
|
||||
FILE *fp = fopen(fullPath.c_str(), pszMode);
|
||||
CC_BREAK_IF(!fp);
|
||||
|
||||
CCMessageBox(msg.c_str(), title.c_str());
|
||||
}
|
||||
return pBuffer;
|
||||
unsigned long size;
|
||||
fseek(fp,0,SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pData = new unsigned char[size];
|
||||
size = fread(pData,sizeof(unsigned char), size,fp);
|
||||
fclose(fp);
|
||||
|
||||
if (pSize)
|
||||
{
|
||||
*pSize = size;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (! pData && getIsPopupNotify())
|
||||
{
|
||||
std::string title = "Notification";
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(fullPath.c_str()).append(") failed!");
|
||||
CCMessageBox(msg.c_str(), title.c_str());
|
||||
}
|
||||
|
||||
return pData;
|
||||
}
|
||||
|
||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||
|
|
|
@ -21,41 +21,87 @@ 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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include <FGraphics.h>
|
||||
using namespace Osp::Graphics;
|
||||
#include <FBase.h>
|
||||
#include <FGraphics.h>
|
||||
|
||||
using namespace Osp::Base;
|
||||
using namespace Osp::Base::Collection;
|
||||
using namespace Osp::Graphics;
|
||||
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
/**
|
||||
@brief A memory DC which uses to draw text on bitmap.
|
||||
*/
|
||||
class BitmapDC
|
||||
{
|
||||
public:
|
||||
BitmapDC()
|
||||
{
|
||||
/**
|
||||
@brief A memory DC which uses to draw text on bitmap.
|
||||
*/
|
||||
class BitmapDC
|
||||
{
|
||||
public:
|
||||
BitmapDC()
|
||||
{
|
||||
m_pCanvas = NULL;
|
||||
m_pEnrichedText = NULL;
|
||||
}
|
||||
|
||||
~BitmapDC()
|
||||
{
|
||||
CC_SAFE_DELETE(m_pCanvas);
|
||||
}
|
||||
|
||||
bool drawText(const char * pszText, CCSize& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0)
|
||||
{
|
||||
bool nRet = false;
|
||||
m_pEnrichedText = NULL;
|
||||
}
|
||||
|
||||
~BitmapDC()
|
||||
{
|
||||
CC_SAFE_DELETE(m_pCanvas);
|
||||
}
|
||||
|
||||
bool drawText(const char * pszText, Dimension& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0)
|
||||
{
|
||||
bool nRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(pszText == NULL || strlen(pszText) <= 0);
|
||||
// text
|
||||
Osp::Base::String strText(pszText);
|
||||
// Set a font to the TextElement
|
||||
Font font;
|
||||
font.Construct(FONT_STYLE_PLAIN, fontSize);
|
||||
bool bUseDefaultFont = true;
|
||||
if (fontName != NULL && strlen(fontName) > 0)
|
||||
{
|
||||
String strFonName(fontName);
|
||||
if (strFonName.EndsWith(".ttf") || strFonName.EndsWith(".TTF"))
|
||||
{
|
||||
bUseDefaultFont = false;
|
||||
const char* pFullFontPath = CCFileUtils::fullPathFromRelativePath(fontName);
|
||||
font.Construct(pFullFontPath, FONT_STYLE_PLAIN, fontSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
IList* pSystemFontList = Font::GetSystemFontListN();
|
||||
if (pSystemFontList != NULL)
|
||||
{
|
||||
IEnumerator* pEnum = pSystemFontList->GetEnumeratorN();
|
||||
Object* pObj = null;
|
||||
while (pEnum->MoveNext() == E_SUCCESS)
|
||||
{
|
||||
pObj = pEnum->GetCurrent();
|
||||
String* pStrName = static_cast<String*>(pObj);
|
||||
if (pStrName->Equals(strFonName, false))
|
||||
{
|
||||
bUseDefaultFont = false;
|
||||
font.Construct(*pStrName, FONT_STYLE_PLAIN, fontSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete pEnum;
|
||||
|
||||
pSystemFontList->RemoveAll(true);
|
||||
delete pSystemFontList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bUseDefaultFont)
|
||||
{
|
||||
font.Construct(FONT_STYLE_PLAIN, fontSize);
|
||||
}
|
||||
|
||||
// calculate text size
|
||||
if (CCSize::CCSizeEqualToSize(dimensions, CCSizeZero))
|
||||
if (dimensions.width <= 0)
|
||||
{
|
||||
Dimension dim;
|
||||
font.GetTextExtent(strText, strText.GetLength(), dim);
|
||||
|
@ -63,16 +109,11 @@ public:
|
|||
dimensions.height = dim.height;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(m_pCanvas);
|
||||
|
||||
CC_BREAK_IF(dimensions.width <= 0 || dimensions.height <= 0);
|
||||
|
||||
m_pCanvas = new Canvas();
|
||||
m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
|
||||
CC_BREAK_IF(dimensions.width <= 0);
|
||||
|
||||
// Create an EnrichedText
|
||||
m_pEnrichedText = new EnrichedText();
|
||||
m_pEnrichedText->Construct(Dimension(dimensions.width, dimensions.height));
|
||||
m_pEnrichedText->Construct(Dimension(dimensions.width, 10));
|
||||
|
||||
switch (alignment)
|
||||
{
|
||||
|
@ -130,26 +171,33 @@ public:
|
|||
// Add the TextElement to the EnrichedText
|
||||
m_pEnrichedText->Add(*pTextElement);
|
||||
|
||||
m_pEnrichedText->Refresh();
|
||||
dimensions.height = m_pEnrichedText->GetTotalLineHeight();
|
||||
m_pEnrichedText->SetSize(dimensions.width, dimensions.height);
|
||||
|
||||
CC_SAFE_DELETE(m_pCanvas);
|
||||
m_pCanvas = new Canvas();
|
||||
m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
|
||||
m_pCanvas->DrawText(Point(0, 0), *m_pEnrichedText);
|
||||
|
||||
m_pEnrichedText->RemoveAllTextElements(true);
|
||||
CC_SAFE_DELETE(m_pEnrichedText);
|
||||
|
||||
nRet = true;
|
||||
} while (0);
|
||||
return nRet;
|
||||
}
|
||||
private:
|
||||
friend class CCImage;
|
||||
Canvas* m_pCanvas;
|
||||
EnrichedText* m_pEnrichedText;
|
||||
std::string m_curFontPath;
|
||||
};
|
||||
|
||||
static BitmapDC& sharedBitmapDC()
|
||||
{
|
||||
static BitmapDC s_BmpDC;
|
||||
return s_BmpDC;
|
||||
} while (0);
|
||||
return nRet;
|
||||
}
|
||||
private:
|
||||
friend class CCImage;
|
||||
Canvas* m_pCanvas;
|
||||
EnrichedText* m_pEnrichedText;
|
||||
std::string m_curFontPath;
|
||||
};
|
||||
|
||||
static BitmapDC& sharedBitmapDC()
|
||||
{
|
||||
static BitmapDC s_BmpDC;
|
||||
return s_BmpDC;
|
||||
}
|
||||
|
||||
bool CCImage::initWithString(
|
||||
|
@ -165,11 +213,11 @@ bool CCImage::initWithString(
|
|||
do
|
||||
{
|
||||
int nLen = 0;
|
||||
CC_BREAK_IF(! pText);
|
||||
|
||||
BitmapDC& dc = sharedBitmapDC();
|
||||
CC_BREAK_IF(! pText);
|
||||
|
||||
CCSize size(nWidth, nHeight);
|
||||
BitmapDC& dc = sharedBitmapDC();
|
||||
|
||||
Dimension size(nWidth, nHeight);
|
||||
|
||||
bRet = dc.drawText(pText, size, eAlignMask, pFontName, nSize);
|
||||
|
||||
|
@ -186,23 +234,13 @@ bool CCImage::initWithString(
|
|||
CC_BREAK_IF(!m_pData);
|
||||
memcpy(m_pData, bufferInfo.pPixels, nLen);
|
||||
|
||||
if (bufferInfo.bitsPerPixel == 32)
|
||||
{
|
||||
if (bufferInfo.width * 4 != bufferInfo.pitch)
|
||||
{
|
||||
m_nWidth = bufferInfo.pitch / 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nWidth = bufferInfo.width;
|
||||
}
|
||||
}
|
||||
|
||||
m_nHeight = bufferInfo.height;
|
||||
int iBytesPerPixel = bufferInfo.bitsPerPixel/8;
|
||||
|
||||
m_nWidth = bufferInfo.pitch / iBytesPerPixel;
|
||||
m_nHeight = bufferInfo.height;
|
||||
m_bHasAlpha = true;
|
||||
m_bPreMulti = false;
|
||||
m_nBitsPerComponent = bufferInfo.bitsPerPixel / 4;
|
||||
m_nBitsPerComponent = 8;
|
||||
dc.m_pCanvas->Unlock();
|
||||
|
||||
bRet = true;
|
||||
|
|
|
@ -1,4 +1,28 @@
|
|||
#include "CCPlatformFunc_bada.h"
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCCommon.h"
|
||||
#include <FApp.h>
|
||||
#include <FBase.h>
|
||||
#include <FUi.h>
|
||||
|
@ -81,15 +105,26 @@ static char _ctype_b[128 + 256] = {
|
|||
//char *__ctype_ptr__ = (char *) _ctype_b + 127;
|
||||
|
||||
|
||||
int printf(const char* format, ...)
|
||||
{
|
||||
char szBuf[cocos2d::kMaxLogLen] = {0};
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int n = vsnprintf(szBuf, cocos2d::kMaxLogLen, format, args);
|
||||
va_end(args);
|
||||
AppLog(szBuf);
|
||||
return n;
|
||||
}
|
||||
|
||||
int sprintf(char* buf, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
char szBuf[256] = {0};
|
||||
char szBuf[cocos2d::kMaxLogLen] = {0};
|
||||
|
||||
int n = vsnprintf(szBuf, 256, format, ap);
|
||||
int n = vsnprintf(szBuf, cocos2d::kMaxLogLen, format, ap);
|
||||
va_end(ap) ;
|
||||
|
||||
strcpy(buf, szBuf);
|
||||
|
|
|
@ -1,22 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PLATFORMFUNC_BADA_H__
|
||||
#define __CC_PLATFORMFUNC_BADA_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef CC_BADA_2_0
|
||||
|
||||
#define printf(...) AppLog(__VA_ARGS__)
|
||||
|
||||
extern int CC_DLL sprintf(char* buf, const char *format, ...);
|
||||
extern int CC_DLL sscanf (const char *s,const char *format, ...);
|
||||
int CC_DLL printf(const char* format, ...);
|
||||
int CC_DLL sprintf(char* buf, const char *format, ...);
|
||||
int CC_DLL sscanf (const char *s,const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
||||
extern void CC_DLL badaAssert(const char* pFunction, int lineNumber, const char* pszContent);
|
||||
void CC_DLL badaAssert(const char* pFunction, int lineNumber, const char* pszContent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,387 @@
|
|||
/*
|
||||
Bada pthread
|
||||
Copyright (c) 2010 Markovtsev Vadim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CC_BADA_2_0
|
||||
|
||||
#include "pthread.h"
|
||||
#include <FApp.h>
|
||||
#include <FBaseRtThread.h>
|
||||
|
||||
using namespace Osp::Base;
|
||||
using namespace Osp::Base::Runtime;
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef void*(*pthread_func)(void *);
|
||||
|
||||
//struct _pthread_fastlock
|
||||
//{
|
||||
// int __spinlock;
|
||||
//};
|
||||
|
||||
//typedef struct _pthread_descr_struct*_pthread_descr;
|
||||
/* Mutexes */
|
||||
struct pthread_mutex{
|
||||
Osp::Base::Runtime::Mutex *lock;
|
||||
// _pthread_descr owner;
|
||||
int kind;
|
||||
unsigned int count;
|
||||
bool acquired;
|
||||
};
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority; /* Process execution scheduling priority */
|
||||
|
||||
#if defined(_POSIX_SPORADIC_SERVER)
|
||||
int ss_low_priority; /* Low scheduling priority for sporadic */
|
||||
/* server */
|
||||
struct timespec ss_replenish_period;
|
||||
/* Replenishment period for sporadic server */
|
||||
struct timespec ss_initial_budget; /* Initial budget for sporadic server */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Attributes for threads. */
|
||||
struct pthread_attr{
|
||||
int __detachstate;
|
||||
int __schedpolicy;
|
||||
struct sched_param __schedparam;
|
||||
int __inheritsched;
|
||||
int __scope;
|
||||
void * __stackaddr;
|
||||
unsigned long __stacksize;
|
||||
};
|
||||
|
||||
struct pthread_mutexattr{
|
||||
int __mutexkind;
|
||||
};
|
||||
|
||||
struct pthread_cond{
|
||||
Osp::Base::Runtime::Monitor *lock;
|
||||
// _pthread_descr wait_chain;
|
||||
};
|
||||
|
||||
class RunnableProxy :
|
||||
public Object,
|
||||
public virtual IRunnable
|
||||
{
|
||||
private:
|
||||
pthread_func _func;
|
||||
void * _parameter;
|
||||
|
||||
public:
|
||||
void SetFunc(pthread_func func)
|
||||
{
|
||||
_func = func;
|
||||
}
|
||||
|
||||
pthread_func GetFunc()
|
||||
{
|
||||
return _func;
|
||||
}
|
||||
|
||||
void SetParameter(void *parameter)
|
||||
{
|
||||
_parameter = parameter;
|
||||
}
|
||||
|
||||
void *GetParameter()
|
||||
{
|
||||
return _parameter;
|
||||
}
|
||||
|
||||
Object* Run(void)
|
||||
{
|
||||
void *result = _func(_parameter);
|
||||
return (Object *)result;
|
||||
}
|
||||
};
|
||||
|
||||
pthread_t pthread_self(void)
|
||||
{
|
||||
return Thread::GetCurrentThread();
|
||||
}
|
||||
|
||||
int pthread_create(pthread_t*__threadarg,
|
||||
const pthread_attr_t*__attr,
|
||||
void*(*__start_routine)(void *),
|
||||
void*__arg)
|
||||
{
|
||||
if (NULL == __threadarg)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Thread *thread = new Thread();
|
||||
RunnableProxy *proxy = new RunnableProxy();
|
||||
proxy->SetFunc(__start_routine);
|
||||
proxy->SetParameter(__arg);
|
||||
thread->Construct(*proxy);
|
||||
*__threadarg = thread;
|
||||
return (int)thread->Start();
|
||||
}
|
||||
|
||||
void pthread_exit(void*__retval)
|
||||
{
|
||||
Thread::Exit(-1);
|
||||
}
|
||||
|
||||
int pthread_join(pthread_t __th,void**__thread_return)
|
||||
{
|
||||
if (!__th)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return ((Thread*)__th)->Join();
|
||||
}
|
||||
|
||||
int pthread_cancel(pthread_t thread)
|
||||
{
|
||||
if (!thread)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return ((Thread*)thread)->Exit();
|
||||
}
|
||||
|
||||
int pthread_detach(pthread_t __th)
|
||||
{
|
||||
if (__th)
|
||||
{
|
||||
((Thread*)__th)->Exit();
|
||||
delete __th;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_equal(pthread_t __thread1,pthread_t __thread2)
|
||||
{
|
||||
if (!__thread1 || !__thread2)
|
||||
{
|
||||
return (void *)__thread1 == (void *)__thread2;
|
||||
}
|
||||
return ((Thread*)__thread1)->Equals(*((Thread*)__thread2));
|
||||
}
|
||||
|
||||
int pthread_kill(pthread_t thread,int sig)
|
||||
{
|
||||
if (!thread)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return ((Thread*)thread)->Exit(sig);
|
||||
}
|
||||
|
||||
int pthread_attr_init(pthread_attr_t*attr)
|
||||
{
|
||||
*attr = new pthread_attr();
|
||||
(*attr)->__stacksize = Thread::DEFAULT_STACK_SIZE;
|
||||
struct sched_param param;
|
||||
param.sched_priority = THREAD_PRIORITY_MID;
|
||||
(*attr)->__schedparam = param;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_attr_destroy(pthread_attr_t*attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_attr_setdetachstate(pthread_attr_t*attr,const int detachstate)
|
||||
{
|
||||
(*attr)->__detachstate = detachstate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_attr_getdetachstate(const pthread_attr_t*attr,int*detachstate)
|
||||
{
|
||||
*detachstate = (*attr)->__detachstate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t*attr)
|
||||
{
|
||||
*attr = new pthread_mutexattr();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t*attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutex_init(pthread_mutex_t*mutex,
|
||||
const pthread_mutexattr_t*mutexattr)
|
||||
{
|
||||
if (!mutex)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*mutex = new pthread_mutex();
|
||||
(*mutex)->lock = new Mutex();
|
||||
(*mutex)->acquired = false;
|
||||
return (*mutex)->lock->Create();
|
||||
}
|
||||
|
||||
int pthread_mutex_lock(pthread_mutex_t*mutex)
|
||||
{
|
||||
if (!mutex || !(*mutex)->lock)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int res = (*mutex)->lock->Acquire();
|
||||
if (res == E_SUCCESS)
|
||||
{
|
||||
(*mutex)->acquired = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int pthread_mutex_unlock(pthread_mutex_t*mutex)
|
||||
{
|
||||
if (!mutex || !(*mutex)->lock)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int res = (*mutex)->lock->Release();
|
||||
if (res == E_SUCCESS)
|
||||
{
|
||||
(*mutex)->acquired = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int pthread_mutex_trylock(pthread_mutex_t*mutex)
|
||||
{
|
||||
if (!mutex || !(*mutex)->lock)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (!(*mutex)->acquired)
|
||||
{
|
||||
int res = (*mutex)->lock->Acquire();
|
||||
if (res == E_SUCCESS)
|
||||
{
|
||||
(*mutex)->acquired = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pthread_mutex_destroy(pthread_mutex_t*mutex)
|
||||
{
|
||||
delete (*mutex)->lock;
|
||||
(*mutex)->acquired = false;
|
||||
delete (*mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_cond_init(pthread_cond_t*cond,pthread_condattr_t*cond_attr)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*cond = new pthread_cond();
|
||||
(*cond)->lock = new Monitor();
|
||||
(*cond)->lock->Construct();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_cond_destroy(pthread_cond_t*cond)
|
||||
{
|
||||
if (cond != NULL)
|
||||
{
|
||||
delete (*cond)->lock;
|
||||
delete (*cond);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_cond_signal(pthread_cond_t*cond)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (*cond)->lock->Notify();
|
||||
}
|
||||
|
||||
int pthread_cond_broadcast(pthread_cond_t*cond)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (*cond)->lock->NotifyAll();
|
||||
}
|
||||
|
||||
int pthread_cond_timedwait(pthread_cond_t*cond,pthread_mutex_t*mutex,
|
||||
const struct timespec*abstime)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
(*cond)->lock->Enter();
|
||||
(*cond)->lock->Wait();
|
||||
(*cond)->lock->Exit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pthread_cond_wait(pthread_cond_t*cond,pthread_mutex_t*mutex)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
(*cond)->lock->Enter();
|
||||
(*cond)->lock->Wait();
|
||||
(*cond)->lock->Exit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pthread_condattr_init(pthread_condattr_t*attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_condattr_destroy(pthread_condattr_t*attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_condattr_getpshared(const pthread_condattr_t*attr,int*pshared)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_condattr_setpshared(pthread_condattr_t*attr,int pshared)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
Bada pthread
|
||||
Copyright (c) 2010 Markovtsev Vadim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __BADA_PTHREAD_H__
|
||||
#define __BADA_PTHREAD_H__
|
||||
|
||||
#ifdef CC_BADA_2_0
|
||||
#include <libxml/../pthread.h>
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PTHREAD_STACK_SIZE (64*1024)
|
||||
#define PTHREAD_STACK_MINSIZE 16384
|
||||
#define PTHREAD_THREADS_MAX 1024
|
||||
|
||||
#define MAX_SPIN_COUNT 50
|
||||
#define SPIN_SLEEP_DURATION 2000001
|
||||
#define PTHREAD_DESTRUCTOR_ITERATIONS 1
|
||||
|
||||
#define PTHREAD_KEYS_MAX 32
|
||||
|
||||
|
||||
typedef void* pthread_t;
|
||||
struct pthread_mutex;
|
||||
typedef struct pthread_mutex* pthread_mutex_t;
|
||||
struct pthread_attr;
|
||||
typedef struct pthread_attr* pthread_attr_t;
|
||||
struct pthread_mutexattr;
|
||||
typedef struct pthread_mutexattr* pthread_mutexattr_t;
|
||||
struct pthread_cond;
|
||||
typedef struct pthread_cond* pthread_cond_t;
|
||||
|
||||
#define PTHREAD_SPIN_LOCKED 1
|
||||
#define PTHREAD_SPIN_UNLOCKED 0
|
||||
|
||||
|
||||
enum {
|
||||
PTHREAD_MUTEX_FAST_NP,
|
||||
#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
|
||||
PTHREAD_MUTEX_RECURSIVE_NP,
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
|
||||
PTHREAD_MUTEX_ERRORCHECK_NP,
|
||||
#define PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
|
||||
};
|
||||
|
||||
enum {
|
||||
PTHREAD_PROCESS_PRIVATE,
|
||||
#define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
|
||||
PTHREAD_PROCESS_SHARED
|
||||
#define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
|
||||
};
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER \
|
||||
{{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_FAST_NP,0}
|
||||
|
||||
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
|
||||
{{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_RECURSIVE_NP,0}
|
||||
|
||||
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
|
||||
{{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_ERRORCHECK_NP,0}
|
||||
|
||||
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t*attr);
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t*attr);
|
||||
|
||||
//int pthread_mutexattr_getkind_np(const pthread_mutexattr_t*attr,int*kind);
|
||||
//int pthread_mutexattr_setkind_np(pthread_mutexattr_t*attr,int kind);
|
||||
|
||||
int pthread_mutex_init(pthread_mutex_t*mutex,
|
||||
const pthread_mutexattr_t*mutexattr);
|
||||
int pthread_mutex_lock(pthread_mutex_t*mutex);
|
||||
int pthread_mutex_unlock(pthread_mutex_t*mutex);
|
||||
int pthread_mutex_trylock(pthread_mutex_t*mutex);
|
||||
int pthread_mutex_destroy(pthread_mutex_t*mutex);
|
||||
|
||||
/* Conditions */
|
||||
typedef void* pthread_condattr_t;
|
||||
|
||||
|
||||
#define PTHREAD_COND_INITIALIZER \
|
||||
{{PTHREAD_SPIN_UNLOCKED},0}
|
||||
|
||||
int pthread_cond_init(pthread_cond_t*cond,pthread_condattr_t*cond_attr);
|
||||
int pthread_cond_destroy(pthread_cond_t*cond);
|
||||
int pthread_cond_signal(pthread_cond_t*cond);
|
||||
int pthread_cond_broadcast(pthread_cond_t*cond);
|
||||
int pthread_cond_timedwait(pthread_cond_t*cond,pthread_mutex_t*mutex,
|
||||
const struct timespec*abstime);
|
||||
int pthread_cond_wait(pthread_cond_t*cond,pthread_mutex_t*mutex);
|
||||
|
||||
// These two functions are not described in the standard. Use them as follows:
|
||||
// [thread #1]
|
||||
// pthread_cond_enter(cond);
|
||||
// pthread_cond_wait(cond, null);
|
||||
// pthread_cond_exit(cond);
|
||||
//
|
||||
// [thread #2]
|
||||
// pthread_cond_enter(cond);
|
||||
// pthread_cond_broadcast(cond);
|
||||
// pthread_cond_exit(cond);
|
||||
//
|
||||
// The mutex style locking will result in a dead lock.
|
||||
int pthread_cond_enter(pthread_cond_t*cond);
|
||||
int pthread_cond_exit(pthread_cond_t*cond);
|
||||
|
||||
/* only for completeness (always return NULL) */
|
||||
int pthread_condattr_init(pthread_condattr_t*attr);
|
||||
int pthread_condattr_destroy(pthread_condattr_t*attr);
|
||||
int pthread_condattr_getpshared(const pthread_condattr_t*attr,int*pshared);
|
||||
int pthread_condattr_setpshared(pthread_condattr_t*attr,int pshared);
|
||||
|
||||
/* thread specific variables */
|
||||
typedef unsigned int pthread_key_t;
|
||||
/*
|
||||
int pthread_key_create(pthread_key_t*key,void(*destructor)(const void*));
|
||||
int pthread_key_delete(pthread_key_t key);
|
||||
int pthread_setspecific(pthread_key_t key,const void*value);
|
||||
const void*pthread_getspecific(pthread_key_t key);
|
||||
*/
|
||||
|
||||
enum {
|
||||
PTHREAD_CREATE_JOINABLE,
|
||||
#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
|
||||
PTHREAD_CREATE_DETACHED
|
||||
#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
|
||||
};
|
||||
|
||||
enum {
|
||||
PTHREAD_EXPLICIT_SCHED,
|
||||
#define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
|
||||
PTHREAD_INHERIT_SCHED
|
||||
#define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
|
||||
};
|
||||
|
||||
enum { /* for completeness */
|
||||
PTHREAD_SCOPE_SYSTEM,
|
||||
#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
|
||||
PTHREAD_SCOPE_PROCESS
|
||||
#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
|
||||
};
|
||||
|
||||
int pthread_attr_init(pthread_attr_t*attr);
|
||||
int pthread_attr_destroy(pthread_attr_t*attr);
|
||||
|
||||
int pthread_attr_setdetachstate(pthread_attr_t*attr,const int detachstate);
|
||||
int pthread_attr_getdetachstate(const pthread_attr_t*attr,int*detachstate);
|
||||
/*
|
||||
int pthread_attr_setschedpolicy(pthread_attr_t*attr,const int policy);
|
||||
int pthread_attr_getschedpolicy(const pthread_attr_t*attr,int*policy);
|
||||
|
||||
int pthread_attr_setschedparam(pthread_attr_t*attr,
|
||||
const struct sched_param*param);
|
||||
int pthread_attr_getschedparam(const pthread_attr_t*attr,
|
||||
struct sched_param*param);
|
||||
|
||||
int pthread_attr_setinheritsched(pthread_attr_t*attr,const int inherit);
|
||||
int pthread_attr_getinheritsched(const pthread_attr_t*attr,int*inherit);
|
||||
|
||||
int pthread_attr_setscope(pthread_attr_t*attr,const int scope);
|
||||
int pthread_attr_getscope(const pthread_attr_t*attr,int*scope);
|
||||
|
||||
int pthread_attr_setstackaddr(pthread_attr_t*attr,void*stack);
|
||||
int pthread_attr_getstackaddr(const pthread_attr_t*attr,void**stack);
|
||||
|
||||
int pthread_attr_setstacksize(pthread_attr_t*attr,const size_t stacksize);
|
||||
int pthread_attr_getstacksize(const pthread_attr_t*attr,size_t*stacksize);
|
||||
|
||||
int pthread_setschedparam(const pthread_t target_thread,const int policy,
|
||||
const struct sched_param*param);
|
||||
int pthread_getschedparam(const pthread_t target_thread,int*policy,
|
||||
struct sched_param*param);
|
||||
*/
|
||||
/* ONCE */
|
||||
typedef int pthread_once_t;
|
||||
#define PTHREAD_ONCE_INIT PTHREAD_SPIN_UNLOCKED
|
||||
|
||||
//int pthread_once(pthread_once_t*once_control,void(*init_routine)(void));
|
||||
|
||||
/* CANCEL */
|
||||
|
||||
enum {
|
||||
PTHREAD_CANCEL_ENABLE,
|
||||
#define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
|
||||
PTHREAD_CANCEL_DISABLE,
|
||||
#define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
|
||||
};
|
||||
|
||||
enum {
|
||||
PTHREAD_CANCEL_DEFERRED,
|
||||
#define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS,
|
||||
#define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
|
||||
};
|
||||
|
||||
#define PTHREAD_CANCELED ((void *) -1)
|
||||
|
||||
int pthread_kill(pthread_t thread,int sig);
|
||||
int pthread_cancel(pthread_t thread);
|
||||
/*int pthread_setcancelstate(int state,int*oldstate);
|
||||
|
||||
int pthread_setcanceltype(int type,int*oldtype);
|
||||
|
||||
void pthread_testcancel(void);
|
||||
*/
|
||||
/* CLEANUP */
|
||||
/*
|
||||
void pthread_cleanup_push(void(*routine)(void*),void*arg);
|
||||
void pthread_cleanup_pop(int execute);
|
||||
|
||||
void pthread_cleanup_push_defer_np(void(*routine)(void*),void*arg);
|
||||
void pthread_cleanup_pop_restore_np(int execute);
|
||||
*/
|
||||
/* FORK */
|
||||
/*
|
||||
pid_t pthread_atfork(void(*prepare)(void),void(*parent)(void),
|
||||
void(*child)(void));
|
||||
*/
|
||||
/* THREADS */
|
||||
pthread_t pthread_self(void);
|
||||
|
||||
int pthread_create(pthread_t*__threadarg,
|
||||
const pthread_attr_t*__attr,
|
||||
void*(*__start_routine)(void *),
|
||||
void*__arg);
|
||||
|
||||
void pthread_exit(void*__retval);
|
||||
|
||||
int pthread_join(pthread_t __th,void**__thread_return);
|
||||
|
||||
int pthread_detach(pthread_t __th);
|
||||
int pthread_equal(pthread_t __thread1,pthread_t __thread2);
|
||||
|
||||
//int pthread_sigmask(int how,const sigset_t*newset,sigset_t*oldset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CC_BADA_2_0 */
|
||||
|
||||
#endif /* __BADA_PTHREAD_H__ */
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
Bada pthread
|
||||
Copyright (c) 2010 Markovtsev Vadim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "semaphore.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
static std::map<std::string, sem_t *> _semaphores;
|
||||
|
||||
int sem_destroy(sem_t*sem)
|
||||
{
|
||||
if (sem)
|
||||
{
|
||||
if (sem->id)
|
||||
{
|
||||
delete sem->id;
|
||||
sem->id = null;
|
||||
}
|
||||
if (sem->mutex)
|
||||
{
|
||||
delete sem->mutex;
|
||||
sem->mutex = null;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atomic_add(int *number, int value, Osp::Base::Runtime::Mutex *mutex)
|
||||
{
|
||||
if (!mutex || !number)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
mutex->Acquire();
|
||||
*number += value;
|
||||
mutex->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_getvalue(sem_t*sem,int*sval)
|
||||
{
|
||||
if (!sem || !sval || sem->mutex)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sem->mutex->Acquire();
|
||||
*sval = sem->value;
|
||||
sem->mutex->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_init(sem_t*sem,int pshared,unsigned int value)
|
||||
{
|
||||
if (!sem)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sem->id = new Osp::Base::Runtime::Semaphore();
|
||||
sem->mutex = new Osp::Base::Runtime::Mutex();
|
||||
sem->id->Create(value);
|
||||
sem->mutex->Create();
|
||||
sem->value = value;
|
||||
return 0;
|
||||
}
|
||||
int sem_post(sem_t*sem)
|
||||
{
|
||||
if (!sem || !sem->id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
atomic_add(&sem->value, 1, sem->mutex);
|
||||
sem->id->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_trywait(sem_t*sem)
|
||||
{
|
||||
if (!sem || !sem->id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sem->mutex->Acquire();
|
||||
int sval = sem->value;
|
||||
sem->mutex->Release();
|
||||
if (sval > 0)
|
||||
{
|
||||
atomic_add(&sem->value, -1, sem->mutex);
|
||||
sem->id->Acquire();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sem_wait(sem_t*sem)
|
||||
{
|
||||
if (!sem || !sem->id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
atomic_add(&sem->value, -1, sem->mutex);
|
||||
sem->id->Acquire();
|
||||
return 0;
|
||||
}
|
||||
|
||||
sem_t*sem_open(const char*name,int oflag,...)
|
||||
{
|
||||
sem_t *sem = new sem_t();
|
||||
sem->id = new Osp::Base::Runtime::Semaphore();
|
||||
sem->mutex = new Osp::Base::Runtime::Mutex();
|
||||
sem->id->Create(name);
|
||||
sem->mutex->Create();
|
||||
sem->value = 1;
|
||||
_semaphores.insert(std::pair<std::string, sem_t *>(name, sem));
|
||||
return sem;
|
||||
}
|
||||
|
||||
int sem_close(sem_t*sem)
|
||||
{
|
||||
return sem_destroy(sem);
|
||||
}
|
||||
|
||||
int sem_unlink(const char*name)
|
||||
{
|
||||
std::map<std::string, sem_t *>::iterator I = _semaphores.find(name);
|
||||
if (I == _semaphores.end())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sem_destroy(I->second);
|
||||
_semaphores.erase(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_timedwait(sem_t*sem,const struct timespec*abstime)
|
||||
{
|
||||
if (!sem || !sem->id || !abstime)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sem->id->Acquire(abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Bada pthread
|
||||
Copyright (c) 2010 Markovtsev Vadim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SEMAPHORE_H_
|
||||
#define SEMAPHORE_H_
|
||||
|
||||
#include <FBaseRtThread.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef struct sem{
|
||||
Osp::Base::Runtime::Semaphore *id;
|
||||
int value;
|
||||
Osp::Base::Runtime::Mutex *mutex;
|
||||
}sem_t;
|
||||
|
||||
#define SEM_FAILED ((sem_t*)0)
|
||||
#define SEM_VALUE_MAX ((int)((~0u)>>1))
|
||||
#define SEM_MAGIC 0x35d108f2
|
||||
|
||||
int sem_destroy(sem_t*sem);
|
||||
int sem_getvalue(sem_t*sem,int*sval);
|
||||
int sem_init(sem_t*sem,int pshared,unsigned int value);
|
||||
int sem_post(sem_t*sem);
|
||||
int sem_trywait(sem_t*sem);
|
||||
int sem_wait(sem_t*sem);
|
||||
|
||||
sem_t*sem_open(const char*name,int oflag,...);
|
||||
int sem_close(sem_t*sem);
|
||||
int sem_unlink(const char*name);
|
||||
|
||||
int sem_timedwait(sem_t*sem,const struct timespec*abstime);
|
||||
|
||||
#endif /* SEMAPHORE_H_ */
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<name>cocos2dx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>libjpeg</project>
|
||||
<project>png</project>
|
||||
<project>zlib</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
<listOptionValue builtIn="false" value="../../../platform/third_party/bada/src/libjpeg/sdk2.0/.Target-Debug/libjpeg.a"/>
|
||||
<listOptionValue builtIn="false" value="../../../platform/third_party/bada/src/png/sdk2.0/.Target-Debug/libpng.a"/>
|
||||
<listOptionValue builtIn="false" value="../../../platform/third_party/bada/src/zlib/sdk2.0/.Target-Debug/libzlib.a"/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/pthread.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FOsp.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsOpengl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsEgl.so""/>
|
||||
|
@ -579,6 +580,7 @@
|
|||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FOsp.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsOpengl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsEgl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/pthread.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/StubDynCast.so""/>
|
||||
</option>
|
||||
<option id="osp.gnu.target.cpp.link.release.so.option.libs.paths.255541031" name="Library search path (-L)" superClass="osp.gnu.target.cpp.link.release.so.option.libs.paths" valueType="libPaths">
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<name>cocos2dx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>libjpeg</project>
|
||||
<project>png</project>
|
||||
<project>zlib</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
@ -211,7 +214,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\1.0.0</sdk>
|
||||
<sdk>C:\bada\1.0.0</sdk>
|
||||
<model>Wave_LP2</model>
|
||||
<properties/>
|
||||
</bada>
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
<name>TestCocos2dx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>Box2D</project>
|
||||
<project>chipmunk</project>
|
||||
<project>cocos2dx</project>
|
||||
<project>CocosDenshion</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bada>
|
||||
<type>0</type>
|
||||
<sdk>D:\programe\bada\2.0.2</sdk>
|
||||
<sdk>C:\bada\2.0.2</sdk>
|
||||
<model>WaveWVGA</model>
|
||||
<apiversioncheck>true</apiversioncheck>
|
||||
<priviligecheck>false</priviligecheck>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FOsp.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsOpengl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/FGraphicsEgl.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/pthread.so""/>
|
||||
<listOptionValue builtIn="false" value=""${TARGET_LIB_PATH}/StubDynCast.so""/>
|
||||
</option>
|
||||
<option id="osp.gnu.cpp.link.option.other.689865278" name="Other options (-Xlinker [option])" superClass="osp.gnu.cpp.link.option.other"/>
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
<name>TestCocos2dx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>Box2D</project>
|
||||
<project>chipmunk</project>
|
||||
<project>cocos2dx</project>
|
||||
<project>CocosDenshion</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
@ -100,7 +104,7 @@
|
|||
<variableList>
|
||||
<variable>
|
||||
<name>cocos2dx_root</name>
|
||||
<value>file:/E:/cocos2d-x</value>
|
||||
<value>file:/F:/Project/dumganhar/cocos2d-x</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
|
|
|
@ -16,7 +16,6 @@ _EXPORT_ int OspMain(int argc, char *pArgv[]);
|
|||
static Osp::App::Application* _CreateInstance(void)
|
||||
{
|
||||
// Create the instance through the constructor.
|
||||
AppLog("Create AppDelgate Instance ... size = %d", sizeof(AppDelegate));
|
||||
AppDelegate * pApp = new AppDelegate;
|
||||
do
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue